2007-07-25 20:21:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Riebeling
|
2007-07-29 18:09:41 +00:00
|
|
|
* $Id$
|
2007-07-25 20:21:06 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#include "configure.h"
|
2007-08-05 19:48:04 +00:00
|
|
|
#include "autodetection.h"
|
2007-07-25 20:21:06 +00:00
|
|
|
#include "ui_configurefrm.h"
|
2007-08-07 16:48:45 +00:00
|
|
|
#include "browsedirtree.h"
|
2007-07-25 20:21:06 +00:00
|
|
|
|
2007-07-29 18:41:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-09-03 14:37:00 +00:00
|
|
|
#define DEFAULT_LANG "English (C)"
|
2007-07-29 18:09:41 +00:00
|
|
|
|
2007-07-25 20:21:06 +00:00
|
|
|
Config::Config(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
2007-08-12 20:40:50 +00:00
|
|
|
programPath = qApp->applicationDirPath() + "/";
|
2007-07-25 20:21:06 +00:00
|
|
|
ui.setupUi(this);
|
|
|
|
ui.radioManualProxy->setChecked(true);
|
|
|
|
QRegExpValidator *proxyValidator = new QRegExpValidator(this);
|
|
|
|
QRegExp validate("[0-9]*");
|
|
|
|
proxyValidator->setRegExp(validate);
|
|
|
|
ui.proxyPort->setValidator(proxyValidator);
|
2007-07-29 18:41:15 +00:00
|
|
|
#ifndef __linux
|
|
|
|
ui.radioSystemProxy->setEnabled(false); // only on linux for now
|
|
|
|
#endif
|
2007-07-29 18:09:41 +00:00
|
|
|
// build language list and sort alphabetically
|
|
|
|
QStringList langs = findLanguageFiles();
|
|
|
|
for(int i = 0; i < langs.size(); ++i)
|
2007-09-03 14:37:00 +00:00
|
|
|
lang.insert(languageName(langs.at(i)) + tr(" (%1)").arg(langs.at(i)), langs.at(i));
|
2007-07-29 18:09:41 +00:00
|
|
|
lang.insert(DEFAULT_LANG, "");
|
|
|
|
QMap<QString, QString>::const_iterator i = lang.constBegin();
|
|
|
|
while (i != lang.constEnd()) {
|
|
|
|
ui.listLanguages->addItem(i.key());
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
|
2007-08-01 07:10:10 +00:00
|
|
|
ui.proxyPass->setEchoMode(QLineEdit::Password);
|
2007-08-12 19:18:11 +00:00
|
|
|
ui.treeDevices->setAlternatingRowColors(true);
|
|
|
|
ui.listLanguages->setAlternatingRowColors(true);
|
2007-07-29 18:09:41 +00:00
|
|
|
|
2007-07-30 19:35:48 +00:00
|
|
|
this->setModal(true);
|
|
|
|
|
2007-07-25 20:21:06 +00:00
|
|
|
connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
|
|
|
|
connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
|
2007-07-29 18:41:15 +00:00
|
|
|
connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
|
2007-08-02 21:29:31 +00:00
|
|
|
connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
|
2007-08-05 19:48:04 +00:00
|
|
|
connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
|
2007-08-27 17:40:35 +00:00
|
|
|
connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
|
|
|
|
connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
|
2007-08-28 23:10:42 +00:00
|
|
|
connect(ui.browseTts, SIGNAL(clicked()), this, SLOT(browseTts()));
|
2007-08-29 17:31:43 +00:00
|
|
|
connect(ui.browseEncoder, SIGNAL(clicked()), this, SLOT(browseEnc()));
|
2007-08-28 23:10:42 +00:00
|
|
|
connect(ui.comboEncoder, SIGNAL(currentIndexChanged(int)), this, SLOT(updateEncOpts(int)));
|
|
|
|
connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsOpts(int)));
|
2007-07-25 20:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-05 19:48:04 +00:00
|
|
|
|
2007-07-25 20:21:06 +00:00
|
|
|
void Config::accept()
|
|
|
|
{
|
|
|
|
qDebug() << "Config::accept()";
|
2007-07-29 18:09:41 +00:00
|
|
|
// proxy: save entered proxy values, not displayed.
|
2007-07-29 18:41:15 +00:00
|
|
|
if(ui.radioManualProxy->isChecked()) {
|
|
|
|
proxy.setScheme("http");
|
|
|
|
proxy.setUserName(ui.proxyUser->text());
|
|
|
|
proxy.setPassword(ui.proxyPass->text());
|
|
|
|
proxy.setHost(ui.proxyHost->text());
|
|
|
|
proxy.setPort(ui.proxyPort->text().toInt());
|
|
|
|
}
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("proxy", proxy.toString());
|
2007-07-25 20:21:06 +00:00
|
|
|
qDebug() << "new proxy:" << proxy;
|
2007-07-29 18:09:41 +00:00
|
|
|
// proxy type
|
2007-07-25 20:21:06 +00:00
|
|
|
QString proxyType;
|
|
|
|
if(ui.radioNoProxy->isChecked()) proxyType = "none";
|
|
|
|
else if(ui.radioSystemProxy->isChecked()) proxyType = "system";
|
|
|
|
else proxyType = "manual";
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("proxytype", proxyType);
|
2007-07-25 20:21:06 +00:00
|
|
|
|
2007-07-29 18:09:41 +00:00
|
|
|
// language
|
2007-09-03 14:37:00 +00:00
|
|
|
if(userSettings->value("lang").toString() != language)
|
2007-07-29 18:09:41 +00:00
|
|
|
QMessageBox::information(this, tr("Language changed"),
|
|
|
|
tr("You need to restart the application for the changed language to take effect."));
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("lang", language);
|
2007-07-29 18:09:41 +00:00
|
|
|
|
2007-08-03 16:55:27 +00:00
|
|
|
// mountpoint
|
|
|
|
QString mp = ui.mountPoint->text();
|
|
|
|
if(QFileInfo(mp).isDir())
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("mountpoint", mp);
|
2007-08-03 16:55:27 +00:00
|
|
|
|
|
|
|
// platform
|
|
|
|
QString nplat;
|
2007-08-10 00:01:44 +00:00
|
|
|
if(ui.treeDevices->selectedItems().size() != 0) {
|
|
|
|
nplat = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("platform", nplat);
|
2007-08-10 00:01:44 +00:00
|
|
|
}
|
2007-08-03 16:55:27 +00:00
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
// cache settings
|
|
|
|
if(QFileInfo(ui.cachePath->text()).isDir())
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("cachepath", ui.cachePath->text());
|
2007-08-27 17:40:35 +00:00
|
|
|
else // default to system temp path
|
2007-09-03 14:37:00 +00:00
|
|
|
userSettings->setValue("cachepath", QDir::tempPath());
|
|
|
|
userSettings->setValue("cachedisable", ui.cacheDisable->isChecked());
|
|
|
|
userSettings->setValue("offline", ui.cacheOfflineMode->isChecked());
|
2007-08-27 17:40:35 +00:00
|
|
|
|
2007-08-28 23:10:42 +00:00
|
|
|
// tts settings
|
|
|
|
if(QFileInfo(ui.ttsExecutable->text()).isExecutable())
|
|
|
|
userSettings->setValue("ttsbin", ui.ttsExecutable->text());
|
|
|
|
userSettings->setValue("ttsopts", ui.ttsOptions->text());
|
|
|
|
if(QFileInfo(ui.encoderExecutable->text()).isExecutable())
|
|
|
|
userSettings->setValue("encbin", ui.encoderExecutable->text());
|
|
|
|
userSettings->setValue("ttsopts", ui.ttsOptions->text());
|
|
|
|
QString preset;
|
|
|
|
preset = ui.comboEncoder->itemData(ui.comboEncoder->currentIndex(), Qt::UserRole).toString();
|
|
|
|
userSettings->setValue("encpreset", preset);
|
|
|
|
preset = ui.comboTts->itemData(ui.comboTts->currentIndex(), Qt::UserRole).toString();
|
|
|
|
userSettings->setValue("ttspreset", preset);
|
|
|
|
|
2007-07-29 18:09:41 +00:00
|
|
|
// sync settings
|
2007-07-25 20:21:06 +00:00
|
|
|
userSettings->sync();
|
|
|
|
this->close();
|
|
|
|
emit settingsUpdated();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::abort()
|
|
|
|
{
|
|
|
|
qDebug() << "Config::abort()";
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::setUserSettings(QSettings *user)
|
|
|
|
{
|
|
|
|
userSettings = user;
|
2007-08-02 21:29:31 +00:00
|
|
|
// set proxy
|
2007-09-03 14:37:00 +00:00
|
|
|
proxy = userSettings->value("proxy").toString();
|
2007-07-25 20:21:06 +00:00
|
|
|
|
2007-08-03 16:55:27 +00:00
|
|
|
if(proxy.port() > 0)
|
|
|
|
ui.proxyPort->setText(QString("%1").arg(proxy.port()));
|
|
|
|
else ui.proxyPort->setText("");
|
2007-07-29 18:09:41 +00:00
|
|
|
ui.proxyHost->setText(proxy.host());
|
|
|
|
ui.proxyUser->setText(proxy.userName());
|
|
|
|
ui.proxyPass->setText(proxy.password());
|
2007-07-25 20:21:06 +00:00
|
|
|
|
2007-09-03 14:37:00 +00:00
|
|
|
QString proxyType = userSettings->value("proxytype").toString();
|
2007-07-25 20:21:06 +00:00
|
|
|
if(proxyType == "manual") ui.radioManualProxy->setChecked(true);
|
|
|
|
else if(proxyType == "system") ui.radioSystemProxy->setChecked(true);
|
2007-08-09 16:01:02 +00:00
|
|
|
else ui.radioNoProxy->setChecked(true);
|
2007-07-25 20:21:06 +00:00
|
|
|
|
2007-07-29 18:09:41 +00:00
|
|
|
// set language selection
|
|
|
|
QList<QListWidgetItem*> a;
|
|
|
|
QString b;
|
|
|
|
// find key for lang value
|
|
|
|
QMap<QString, QString>::const_iterator i = lang.constBegin();
|
|
|
|
while (i != lang.constEnd()) {
|
2007-09-03 14:37:00 +00:00
|
|
|
if(i.value() == userSettings->value("lang").toString()) {
|
2007-07-29 18:09:41 +00:00
|
|
|
b = i.key();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
a = ui.listLanguages->findItems(b, Qt::MatchExactly);
|
|
|
|
if(a.size() <= 0)
|
|
|
|
a = ui.listLanguages->findItems(DEFAULT_LANG, Qt::MatchExactly);
|
|
|
|
if(a.size() > 0)
|
|
|
|
ui.listLanguages->setCurrentItem(a.at(0));
|
|
|
|
|
2007-08-02 21:29:31 +00:00
|
|
|
// devices tab
|
2007-09-03 14:37:00 +00:00
|
|
|
ui.mountPoint->setText(userSettings->value("mountpoint").toString());
|
2007-08-02 21:29:31 +00:00
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
// cache tab
|
2007-09-03 14:37:00 +00:00
|
|
|
if(!QFileInfo(userSettings->value("cachepath").toString()).isDir())
|
|
|
|
userSettings->setValue("cachepath", QDir::tempPath());
|
|
|
|
ui.cachePath->setText(userSettings->value("cachepath").toString());
|
|
|
|
ui.cacheDisable->setChecked(userSettings->value("cachedisable", true).toBool());
|
|
|
|
ui.cacheOfflineMode->setChecked(userSettings->value("offline").toBool());
|
|
|
|
QList<QFileInfo> fs = QDir(userSettings->value("cachepath").toString() + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
|
2007-08-27 17:40:35 +00:00
|
|
|
qint64 sz = 0;
|
|
|
|
for(int i = 0; i < fs.size(); i++) {
|
|
|
|
sz += fs.at(i).size();
|
|
|
|
qDebug() << fs.at(i).fileName() << fs.at(i).size();
|
|
|
|
}
|
|
|
|
ui.cacheSize->setText(tr("Current cache size is %1 kiB.")
|
|
|
|
.arg(sz/1024));
|
2007-08-28 23:10:42 +00:00
|
|
|
|
2007-08-02 21:29:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::setDevices(QSettings *dev)
|
|
|
|
{
|
|
|
|
devices = dev;
|
|
|
|
// setup devices table
|
|
|
|
qDebug() << "Config::setDevices()";
|
|
|
|
devices->beginGroup("platforms");
|
|
|
|
QStringList a = devices->childKeys();
|
|
|
|
devices->endGroup();
|
|
|
|
|
|
|
|
QMap <QString, QString> manuf;
|
|
|
|
QMap <QString, QString> devcs;
|
|
|
|
for(int it = 0; it < a.size(); it++) {
|
|
|
|
QString curdev;
|
|
|
|
devices->beginGroup("platforms");
|
|
|
|
curdev = devices->value(a.at(it), "null").toString();
|
|
|
|
devices->endGroup();
|
|
|
|
QString curname;
|
|
|
|
devices->beginGroup(curdev);
|
|
|
|
curname = devices->value("name", "null").toString();
|
|
|
|
QString curbrand = devices->value("brand", "").toString();
|
|
|
|
devices->endGroup();
|
|
|
|
manuf.insertMulti(curbrand, curdev);
|
|
|
|
devcs.insert(curdev, curname);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString platform;
|
2007-09-03 14:37:00 +00:00
|
|
|
platform = devcs.value(userSettings->value("platform").toString());
|
2007-08-02 21:29:31 +00:00
|
|
|
|
|
|
|
// set up devices table
|
|
|
|
ui.treeDevices->header()->hide();
|
|
|
|
ui.treeDevices->expandAll();
|
|
|
|
ui.treeDevices->setColumnCount(1);
|
|
|
|
QList<QTreeWidgetItem *> items;
|
|
|
|
|
|
|
|
// get manufacturers
|
|
|
|
QStringList brands = manuf.uniqueKeys();
|
|
|
|
QTreeWidgetItem *w;
|
|
|
|
QTreeWidgetItem *w2;
|
2007-08-03 16:30:37 +00:00
|
|
|
QTreeWidgetItem *w3 = 0;
|
2007-08-02 21:29:31 +00:00
|
|
|
for(int c = 0; c < brands.size(); c++) {
|
|
|
|
qDebug() << brands.at(c);
|
|
|
|
w = new QTreeWidgetItem();
|
|
|
|
w->setFlags(Qt::ItemIsEnabled);
|
|
|
|
w->setText(0, brands.at(c));
|
|
|
|
items.append(w);
|
|
|
|
|
|
|
|
// go through platforms again for sake of order
|
|
|
|
for(int it = 0; it < a.size(); it++) {
|
|
|
|
QString curdev;
|
|
|
|
devices->beginGroup("platforms");
|
|
|
|
curdev = devices->value(a.at(it), "null").toString();
|
|
|
|
devices->endGroup();
|
|
|
|
QString curname;
|
|
|
|
devices->beginGroup(curdev);
|
|
|
|
curname = devices->value("name", "null").toString();
|
|
|
|
QString curbrand = devices->value("brand", "").toString();
|
2007-09-03 14:37:00 +00:00
|
|
|
QString curicon = devices->value("icon", "").toString();
|
2007-08-02 21:29:31 +00:00
|
|
|
devices->endGroup();
|
|
|
|
if(curbrand != brands.at(c)) continue;
|
|
|
|
qDebug() << "adding:" << brands.at(c) << curname << curdev;
|
|
|
|
w2 = new QTreeWidgetItem(w, QStringList(curname));
|
|
|
|
w2->setData(0, Qt::UserRole, curdev);
|
2007-09-03 14:37:00 +00:00
|
|
|
// QIcon icon;
|
|
|
|
// icon.addFile(":/icons/devices/" + curicon + "-tiny.png");
|
|
|
|
// w2->setIcon(0, icon);
|
|
|
|
// ui.treeDevices->setIconSize(QSize(32, 32));
|
2007-08-02 21:29:31 +00:00
|
|
|
if(platform.contains(curname)) {
|
|
|
|
w2->setSelected(true);
|
|
|
|
w->setExpanded(true);
|
|
|
|
w3 = w2; // save pointer to hilight old selection
|
|
|
|
}
|
|
|
|
items.append(w2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.treeDevices->insertTopLevelItems(0, items);
|
2007-08-03 16:30:37 +00:00
|
|
|
if(w3 != 0)
|
|
|
|
ui.treeDevices->setCurrentItem(w3); // hilight old selection
|
2007-08-28 23:10:42 +00:00
|
|
|
|
|
|
|
// tts / encoder tab
|
|
|
|
QStringList keys;
|
|
|
|
|
|
|
|
devices->beginGroup("encoders");
|
|
|
|
keys = devices->allKeys();
|
|
|
|
for(int i=0; i < keys.size();i++)
|
|
|
|
ui.comboEncoder->addItem(devices->value(keys.at(i), "null").toString(),
|
|
|
|
keys.at(i));
|
|
|
|
devices->endGroup();
|
|
|
|
|
|
|
|
devices->beginGroup("tts");
|
|
|
|
keys = devices->allKeys();
|
|
|
|
for(int i=0; i < keys.size();i++)
|
|
|
|
ui.comboTts->addItem(devices->value(keys.at(i), "null").toString(), keys.at(i));
|
|
|
|
devices->endGroup();
|
|
|
|
|
|
|
|
int index;
|
|
|
|
index = ui.comboTts->findData(userSettings->value("ttspreset").toString(),
|
|
|
|
Qt::UserRole, Qt::MatchExactly);
|
2007-08-30 22:20:11 +00:00
|
|
|
if(index < 0) index = 0;
|
2007-08-28 23:10:42 +00:00
|
|
|
ui.comboTts->setCurrentIndex(index);
|
|
|
|
updateTtsOpts(index);
|
|
|
|
ui.ttsExecutable->setText(userSettings->value("ttsbin").toString());
|
|
|
|
|
|
|
|
index = ui.comboEncoder->findData(userSettings->value("encpreset").toString(),
|
|
|
|
Qt::UserRole, Qt::MatchExactly);
|
2007-08-30 22:20:11 +00:00
|
|
|
if(index < 0) index = 0;
|
2007-08-28 23:10:42 +00:00
|
|
|
ui.comboEncoder->setCurrentIndex(index);
|
|
|
|
updateEncOpts(index);
|
|
|
|
ui.encoderExecutable->setText(userSettings->value("encbin").toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::updateEncOpts(int index)
|
|
|
|
{
|
|
|
|
qDebug() << "updateEncOpts()";
|
2007-08-29 12:32:53 +00:00
|
|
|
QString e;
|
2007-08-29 10:09:17 +00:00
|
|
|
bool edit;
|
2007-08-28 23:10:42 +00:00
|
|
|
QString c = ui.comboEncoder->itemData(index, Qt::UserRole).toString();
|
|
|
|
devices->beginGroup(c);
|
|
|
|
ui.encoderOptions->setText(devices->value("options").toString());
|
2007-08-29 10:09:17 +00:00
|
|
|
edit = devices->value("edit").toBool();
|
|
|
|
ui.encoderOptions->setEnabled(edit);
|
2007-08-29 12:32:53 +00:00
|
|
|
e = devices->value("encoder").toString();
|
2007-08-28 23:10:42 +00:00
|
|
|
devices->endGroup();
|
2007-08-29 10:09:17 +00:00
|
|
|
|
|
|
|
// try to autodetect encoder
|
2007-08-29 12:32:53 +00:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
2007-08-29 10:09:17 +00:00
|
|
|
QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
|
2007-08-29 12:32:53 +00:00
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
|
|
|
|
#endif
|
2007-08-29 10:09:17 +00:00
|
|
|
qDebug() << path;
|
|
|
|
ui.encoderExecutable->setEnabled(true);
|
|
|
|
for(int i = 0; i < path.size(); i++) {
|
2007-08-29 12:32:53 +00:00
|
|
|
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + e;
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
executable += ".exe";
|
|
|
|
QStringList ex = executable.split("\"", QString::SkipEmptyParts);
|
|
|
|
executable = ex.join("");
|
|
|
|
#endif
|
2007-08-29 10:09:17 +00:00
|
|
|
if(QFileInfo(executable).isExecutable()) {
|
|
|
|
qDebug() << "found:" << executable;
|
2007-08-29 12:32:53 +00:00
|
|
|
ui.encoderExecutable->setText(QDir::toNativeSeparators(executable));
|
2007-08-29 10:09:17 +00:00
|
|
|
// disallow changing the detected path if non-customizable profile
|
|
|
|
if(!edit)
|
|
|
|
ui.encoderExecutable->setEnabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-08-28 23:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::updateTtsOpts(int index)
|
|
|
|
{
|
2007-08-29 10:09:17 +00:00
|
|
|
bool edit;
|
|
|
|
QString e;
|
2007-08-28 23:10:42 +00:00
|
|
|
QString c = ui.comboTts->itemData(index, Qt::UserRole).toString();
|
|
|
|
devices->beginGroup(c);
|
2007-08-29 10:09:17 +00:00
|
|
|
edit = devices->value("edit").toBool();
|
2007-08-28 23:10:42 +00:00
|
|
|
ui.ttsOptions->setText(devices->value("options").toString());
|
|
|
|
ui.ttsOptions->setEnabled(devices->value("edit").toBool());
|
2007-08-29 10:09:17 +00:00
|
|
|
e = devices->value("tts").toString();
|
2007-08-28 23:10:42 +00:00
|
|
|
devices->endGroup();
|
2007-08-29 10:09:17 +00:00
|
|
|
|
2007-08-29 12:32:53 +00:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
2007-08-29 10:09:17 +00:00
|
|
|
QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
|
2007-08-29 12:32:53 +00:00
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
|
|
|
|
#endif
|
2007-08-29 10:09:17 +00:00
|
|
|
qDebug() << path;
|
|
|
|
ui.ttsExecutable->setEnabled(true);
|
|
|
|
for(int i = 0; i < path.size(); i++) {
|
2007-08-29 12:32:53 +00:00
|
|
|
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + e;
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
executable += ".exe";
|
|
|
|
QStringList ex = executable.split("\"", QString::SkipEmptyParts);
|
|
|
|
executable = ex.join("");
|
|
|
|
#endif
|
|
|
|
qDebug() << executable;
|
2007-08-29 10:09:17 +00:00
|
|
|
if(QFileInfo(executable).isExecutable()) {
|
2007-08-29 12:32:53 +00:00
|
|
|
ui.ttsExecutable->setText(QDir::toNativeSeparators(executable));
|
2007-08-29 10:09:17 +00:00
|
|
|
// disallow changing the detected path if non-customizable profile
|
|
|
|
if(!edit)
|
|
|
|
ui.ttsExecutable->setEnabled(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-25 20:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::setNoProxy(bool checked)
|
|
|
|
{
|
|
|
|
bool i = !checked;
|
|
|
|
ui.proxyPort->setEnabled(i);
|
|
|
|
ui.proxyHost->setEnabled(i);
|
|
|
|
ui.proxyUser->setEnabled(i);
|
|
|
|
ui.proxyPass->setEnabled(i);
|
|
|
|
}
|
|
|
|
|
2007-07-29 18:09:41 +00:00
|
|
|
|
2007-07-29 18:41:15 +00:00
|
|
|
void Config::setSystemProxy(bool checked)
|
|
|
|
{
|
|
|
|
bool i = !checked;
|
|
|
|
ui.proxyPort->setEnabled(i);
|
|
|
|
ui.proxyHost->setEnabled(i);
|
|
|
|
ui.proxyUser->setEnabled(i);
|
|
|
|
ui.proxyPass->setEnabled(i);
|
|
|
|
if(checked) {
|
|
|
|
// save values in input box
|
|
|
|
proxy.setScheme("http");
|
|
|
|
proxy.setUserName(ui.proxyUser->text());
|
|
|
|
proxy.setPassword(ui.proxyPass->text());
|
|
|
|
proxy.setHost(ui.proxyHost->text());
|
|
|
|
proxy.setPort(ui.proxyPort->text().toInt());
|
|
|
|
// show system values in input box
|
|
|
|
#ifdef __linux
|
|
|
|
QUrl envproxy = QUrl(getenv("http_proxy"));
|
|
|
|
ui.proxyHost->setText(envproxy.host());
|
|
|
|
ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
|
|
|
|
ui.proxyUser->setText(envproxy.userName());
|
|
|
|
ui.proxyPass->setText(envproxy.password());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui.proxyHost->setText(proxy.host());
|
2007-08-03 16:55:27 +00:00
|
|
|
if(proxy.port() > 0)
|
|
|
|
ui.proxyPort->setText(QString("%1").arg(proxy.port()));
|
|
|
|
else ui.proxyPort->setText("");
|
2007-07-29 18:41:15 +00:00
|
|
|
ui.proxyUser->setText(proxy.userName());
|
|
|
|
ui.proxyPass->setText(proxy.password());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-29 18:09:41 +00:00
|
|
|
QStringList Config::findLanguageFiles()
|
|
|
|
{
|
2007-08-12 20:40:50 +00:00
|
|
|
QDir dir(programPath);
|
2007-07-29 18:09:41 +00:00
|
|
|
QStringList fileNames;
|
2007-09-03 14:37:00 +00:00
|
|
|
QStringList langs;
|
2007-07-29 18:09:41 +00:00
|
|
|
fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
|
|
|
|
|
|
|
|
QDir resDir(":/lang");
|
|
|
|
fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
|
|
|
|
|
2007-09-03 14:37:00 +00:00
|
|
|
QRegExp exp("^rbutil_(.*)\\.qm");
|
|
|
|
for(int i = 0; i < fileNames.size(); i++) {
|
|
|
|
QString a = fileNames.at(i);
|
|
|
|
a.replace(exp, "\\1");
|
|
|
|
langs.append(a);
|
|
|
|
}
|
|
|
|
langs.sort();
|
|
|
|
qDebug() << "Config::findLanguageFiles()" << langs;
|
2007-07-29 18:09:41 +00:00
|
|
|
|
2007-09-03 14:37:00 +00:00
|
|
|
return langs;
|
2007-07-29 18:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString Config::languageName(const QString &qmFile)
|
|
|
|
{
|
|
|
|
QTranslator translator;
|
|
|
|
|
2007-09-03 14:37:00 +00:00
|
|
|
QString file = "rbutil_" + qmFile;
|
|
|
|
if(!translator.load(file, programPath))
|
|
|
|
translator.load(file, ":/lang");
|
2007-07-29 18:09:41 +00:00
|
|
|
|
|
|
|
return translator.translate("Configure", "English");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Config::updateLanguage()
|
|
|
|
{
|
|
|
|
qDebug() << "updateLanguage()";
|
|
|
|
QList<QListWidgetItem*> a = ui.listLanguages->selectedItems();
|
|
|
|
if(a.size() > 0)
|
2007-09-03 14:37:00 +00:00
|
|
|
language = lang.value(a.at(0)->text());
|
|
|
|
qDebug() << language;
|
2007-07-29 18:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 21:29:31 +00:00
|
|
|
void Config::browseFolder()
|
|
|
|
{
|
2007-08-07 16:48:45 +00:00
|
|
|
browser = new BrowseDirtree(this);
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
|
|
|
browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
|
|
|
#elif defined(Q_OS_WIN32)
|
|
|
|
browser->setFilter(QDir::Drives);
|
|
|
|
#endif
|
|
|
|
QDir d(ui.mountPoint->text());
|
|
|
|
browser->setDir(d);
|
2007-09-14 14:37:43 +00:00
|
|
|
#if defined(Q_OS_MACX)
|
|
|
|
browser->setRoot("/Volumes");
|
|
|
|
#elif defined(Q_OS_LINUX)
|
2007-09-14 14:47:26 +00:00
|
|
|
browser->setRoot("/media");
|
2007-09-14 14:37:43 +00:00
|
|
|
#endif
|
2007-08-07 16:48:45 +00:00
|
|
|
browser->show();
|
|
|
|
connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
|
2007-08-02 21:29:31 +00:00
|
|
|
}
|
2007-08-05 19:48:04 +00:00
|
|
|
|
2007-08-07 16:48:45 +00:00
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
void Config::browseCache()
|
|
|
|
{
|
|
|
|
cbrowser = new BrowseDirtree(this);
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
|
|
|
|
cbrowser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
|
|
|
#elif defined(Q_OS_WIN32)
|
|
|
|
cbrowser->setFilter(QDir::Drives);
|
|
|
|
#endif
|
|
|
|
QDir d(ui.cachePath->text());
|
|
|
|
cbrowser->setDir(d);
|
|
|
|
cbrowser->show();
|
|
|
|
connect(cbrowser, SIGNAL(itemChanged(QString)), this, SLOT(setCache(QString)));
|
|
|
|
}
|
|
|
|
|
2007-08-07 16:48:45 +00:00
|
|
|
void Config::setMountpoint(QString m)
|
|
|
|
{
|
|
|
|
ui.mountPoint->setText(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
void Config::setCache(QString c)
|
|
|
|
{
|
|
|
|
ui.cachePath->setText(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-05 19:48:04 +00:00
|
|
|
void Config::autodetect()
|
|
|
|
{
|
|
|
|
Autodetection detector(this);
|
|
|
|
|
|
|
|
if(detector.detect()) //let it detect
|
|
|
|
{
|
|
|
|
QString devicename = detector.getDevice();
|
2007-08-30 18:14:56 +00:00
|
|
|
// deexpand all items
|
|
|
|
for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
|
|
|
|
ui.treeDevices->topLevelItem(a)->setExpanded(false);
|
|
|
|
//deselect the selected item(s)
|
|
|
|
for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
|
|
|
|
ui.treeDevices->selectedItems().at(a)->setSelected(false);
|
2007-08-05 19:48:04 +00:00
|
|
|
|
|
|
|
// find the new item
|
2007-08-30 16:55:04 +00:00
|
|
|
// enumerate all platform items
|
2007-08-05 19:48:04 +00:00
|
|
|
QList<QTreeWidgetItem*> itmList= ui.treeDevices->findItems("*",Qt::MatchWildcard);
|
|
|
|
for(int i=0; i< itmList.size();i++)
|
|
|
|
{
|
|
|
|
//enumerate device items
|
|
|
|
for(int j=0;j < itmList.at(i)->childCount();j++)
|
|
|
|
{
|
|
|
|
QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
|
|
|
|
|
2007-08-30 16:55:04 +00:00
|
|
|
if(devicename == data) // item found
|
2007-08-05 19:48:04 +00:00
|
|
|
{
|
|
|
|
itmList.at(i)->child(j)->setSelected(true); //select the item
|
|
|
|
itmList.at(i)->setExpanded(true); //expand the platform item
|
2007-09-03 14:37:00 +00:00
|
|
|
//ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
|
2007-08-05 19:48:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(detector.getMountPoint() != "" )
|
|
|
|
{
|
|
|
|
ui.mountPoint->setText(detector.getMountPoint());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Autodetection"),
|
|
|
|
tr("Could not detect a Mountpoint.\n"
|
|
|
|
"Select your Mountpoint manually."),
|
|
|
|
QMessageBox::Ok ,QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Autodetection"),
|
|
|
|
tr("Could not detect a device.\n"
|
|
|
|
"Select your device and Mountpoint manually."),
|
|
|
|
QMessageBox::Ok ,QMessageBox::Ok);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2007-08-07 16:48:45 +00:00
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
void Config::cacheClear()
|
|
|
|
{
|
|
|
|
if(QMessageBox::critical(this, tr("Really delete cache?"),
|
|
|
|
tr("Do you really want to delete the cache? "
|
|
|
|
"Make absolutely sure this setting is correct as it will "
|
|
|
|
"remove <b>all</b> files in this folder!").arg(ui.cachePath->text()),
|
|
|
|
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString cache = ui.cachePath->text() + "/rbutil-cache/";
|
|
|
|
if(!QFileInfo(cache).isDir()) {
|
|
|
|
QMessageBox::critical(this, tr("Path wrong!"),
|
|
|
|
tr("The cache path is invalid. Aborting."), QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDir dir(cache);
|
|
|
|
QStringList fn;
|
|
|
|
fn = dir.entryList(QStringList("*"), QDir::Files, QDir::Name);
|
|
|
|
qDebug() << fn;
|
|
|
|
|
|
|
|
for(int i = 0; i < fn.size(); i++) {
|
|
|
|
QString f = cache + fn.at(i);
|
|
|
|
QFile::remove(f);
|
|
|
|
qDebug() << "removed:" << f;
|
|
|
|
}
|
|
|
|
}
|
2007-08-28 23:10:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Config::browseTts()
|
|
|
|
{
|
|
|
|
BrowseDirtree browser(this);
|
|
|
|
browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
if(QFileInfo(ui.ttsExecutable->text()).isDir())
|
|
|
|
{
|
|
|
|
QDir d(ui.ttsExecutable->text());
|
|
|
|
browser.setDir(d);
|
|
|
|
}
|
|
|
|
if(browser.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
qDebug() << browser.getSelected();
|
|
|
|
QString exe = browser.getSelected();
|
|
|
|
if(!QFileInfo(exe).isExecutable())
|
|
|
|
return;
|
|
|
|
ui.ttsExecutable->setText(exe);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-08-29 17:31:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Config::browseEnc()
|
|
|
|
{
|
|
|
|
BrowseDirtree browser(this);
|
|
|
|
browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
if(QFileInfo(ui.encoderExecutable->text()).isDir())
|
|
|
|
{
|
|
|
|
QDir d(ui.encoderExecutable->text());
|
|
|
|
browser.setDir(d);
|
|
|
|
}
|
|
|
|
if(browser.exec() == QDialog::Accepted)
|
|
|
|
{
|
|
|
|
qDebug() << browser.getSelected();
|
|
|
|
QString exe = browser.getSelected();
|
|
|
|
if(!QFileInfo(exe).isExecutable())
|
|
|
|
return;
|
|
|
|
ui.encoderExecutable->setText(exe);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|