1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include "configure.h"
24 #include "autodetection.h"
25 #include "ui_configurefrm.h"
29 #include "encttscfggui.h"
30 #include "rbsettings.h"
31 #include "serverinfo.h"
32 #include "systeminfo.h"
34 #include "comboboxviewdelegate.h"
35 #if defined(Q_OS_WIN32)
43 #define DEFAULT_LANG "English (en)"
44 #define DEFAULT_LANG_CODE "en"
46 Config::Config(QWidget
*parent
,int index
) : QDialog(parent
)
48 programPath
= qApp
->applicationDirPath() + "/";
50 ui
.tabConfiguration
->setCurrentIndex(index
);
51 ui
.radioManualProxy
->setChecked(true);
52 QRegExpValidator
*proxyValidator
= new QRegExpValidator(this);
53 QRegExp
validate("[0-9]*");
54 proxyValidator
->setRegExp(validate
);
55 ui
.proxyPort
->setValidator(proxyValidator
);
57 // build language list and sort alphabetically
58 QStringList langs
= findLanguageFiles();
59 for(int i
= 0; i
< langs
.size(); ++i
)
60 lang
.insert(languageName(langs
.at(i
))
61 + QString(" (%1)").arg(langs
.at(i
)), langs
.at(i
));
62 lang
.insert(DEFAULT_LANG
, DEFAULT_LANG_CODE
);
63 QMap
<QString
, QString
>::const_iterator i
= lang
.constBegin();
64 while (i
!= lang
.constEnd()) {
65 ui
.listLanguages
->addItem(i
.key());
69 ComboBoxViewDelegate
*delegate
= new ComboBoxViewDelegate(this);
70 ui
.mountPoint
->setItemDelegate(delegate
);
72 ui
.mountPoint
->setEditable(false);
75 ui
.listLanguages
->setSelectionMode(QAbstractItemView::SingleSelection
);
76 ui
.proxyPass
->setEchoMode(QLineEdit::Password
);
77 ui
.treeDevices
->setAlternatingRowColors(true);
78 ui
.listLanguages
->setAlternatingRowColors(true);
80 /* Explicitly set some widgets to have left-to-right layout */
81 ui
.treeDevices
->setLayoutDirection(Qt::LeftToRight
);
82 ui
.mountPoint
->setLayoutDirection(Qt::LeftToRight
);
83 ui
.proxyHost
->setLayoutDirection(Qt::LeftToRight
);
84 ui
.proxyPort
->setLayoutDirection(Qt::LeftToRight
);
85 ui
.proxyUser
->setLayoutDirection(Qt::LeftToRight
);
86 ui
.proxyPass
->setLayoutDirection(Qt::LeftToRight
);
87 ui
.listLanguages
->setLayoutDirection(Qt::LeftToRight
);
88 ui
.cachePath
->setLayoutDirection(Qt::LeftToRight
);
89 ui
.comboTts
->setLayoutDirection(Qt::LeftToRight
);
93 connect(ui
.buttonOk
, SIGNAL(clicked()), this, SLOT(accept()));
94 connect(ui
.buttonCancel
, SIGNAL(clicked()), this, SLOT(abort()));
95 connect(ui
.radioNoProxy
, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
96 connect(ui
.radioSystemProxy
, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
97 connect(ui
.refreshMountPoint
, SIGNAL(clicked()), this, SLOT(refreshMountpoint()));
98 connect(ui
.buttonAutodetect
,SIGNAL(clicked()),this,SLOT(autodetect()));
99 connect(ui
.buttonCacheBrowse
, SIGNAL(clicked()), this, SLOT(browseCache()));
100 connect(ui
.buttonCacheClear
, SIGNAL(clicked()), this, SLOT(cacheClear()));
101 connect(ui
.configTts
, SIGNAL(clicked()), this, SLOT(configTts()));
102 connect(ui
.configEncoder
, SIGNAL(clicked()), this, SLOT(configEnc()));
103 connect(ui
.comboTts
, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
104 connect(ui
.treeDevices
, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
105 connect(ui
.testTTS
,SIGNAL(clicked()),this,SLOT(testTts()));
106 connect(ui
.showDisabled
, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool)));
107 connect(ui
.mountPoint
, SIGNAL(editTextChanged(QString
)), this, SLOT(updateMountpoint(QString
)));
108 connect(ui
.mountPoint
, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMountpoint(int)));
109 // delete this dialog after it finished automatically.
110 connect(this, SIGNAL(finished(int)), this, SLOT(deleteLater()));
117 void Config::accept()
119 qDebug() << "[Config] checking configuration";
120 QString errormsg
= tr("The following errors occurred:") + "<ul>";
123 // proxy: save entered proxy values, not displayed.
124 if(ui
.radioManualProxy
->isChecked()) {
125 proxy
.setScheme("http");
126 proxy
.setUserName(ui
.proxyUser
->text());
127 proxy
.setPassword(ui
.proxyPass
->text());
128 proxy
.setHost(ui
.proxyHost
->text());
129 proxy
.setPort(ui
.proxyPort
->text().toInt());
132 // QUrl::toEncoded() doesn't encode a colon in the password correctly,
133 // which will result in errors during parsing the string.
134 // QUrl::toPercentEncoding() does work as expected, so build the string to
135 // store in the configuration file manually.
136 QString proxystring
= "http://"
137 + QString(QUrl::toPercentEncoding(proxy
.userName())) + ":"
138 + QString(QUrl::toPercentEncoding(proxy
.password())) + "@"
140 + QString::number(proxy
.port());
141 RbSettings::setValue(RbSettings::Proxy
, proxystring
);
142 qDebug() << "[Config] setting proxy to:" << proxy
;
145 if(ui
.radioNoProxy
->isChecked()) proxyType
= "none";
146 else if(ui
.radioSystemProxy
->isChecked()) proxyType
= "system";
147 else proxyType
= "manual";
148 RbSettings::setValue(RbSettings::ProxyType
, proxyType
);
151 if(RbSettings::value(RbSettings::Language
).toString() != language
152 && !language
.isEmpty()) {
153 QMessageBox::information(this, tr("Language changed"),
154 tr("You need to restart the application for the changed language "
157 RbSettings::setValue(RbSettings::Language
, language
);
160 if(mountpoint
.isEmpty()) {
161 errormsg
+= "<li>" + tr("No mountpoint given") + "</li>";
164 else if(!QFileInfo(mountpoint
).exists()) {
165 errormsg
+= "<li>" + tr("Mountpoint does not exist") + "</li>";
168 else if(!QFileInfo(mountpoint
).isDir()) {
169 errormsg
+= "<li>" + tr("Mountpoint is not a directory.") + "</li>";
172 else if(!QFileInfo(mountpoint
).isWritable()) {
173 errormsg
+= "<li>" + tr("Mountpoint is not writeable") + "</li>";
177 RbSettings::setValue(RbSettings::Mountpoint
,
178 QDir::fromNativeSeparators(mountpoint
));
183 if(ui
.treeDevices
->selectedItems().size() != 0) {
184 nplat
= ui
.treeDevices
->selectedItems().at(0)->data(0, Qt::UserRole
).toString();
185 RbSettings::setValue(RbSettings::Platform
, nplat
);
188 errormsg
+= "<li>" + tr("No player selected") + "</li>";
193 if(QFileInfo(ui
.cachePath
->text()).isDir()) {
194 if(!QFileInfo(ui
.cachePath
->text()).isWritable()) {
195 errormsg
+= "<li>" + tr("Cache path not writeable. Leave path empty "
196 "to default to systems temporary path.") + "</li>";
200 RbSettings::setValue(RbSettings::CachePath
, ui
.cachePath
->text());
202 else // default to system temp path
203 RbSettings::setValue(RbSettings::CachePath
, QDir::tempPath());
204 RbSettings::setValue(RbSettings::CacheDisabled
, ui
.cacheDisable
->isChecked());
205 RbSettings::setValue(RbSettings::CacheOffline
, ui
.cacheOfflineMode
->isChecked());
208 int i
= ui
.comboTts
->currentIndex();
209 RbSettings::setValue(RbSettings::Tts
, ui
.comboTts
->itemData(i
).toString());
211 RbSettings::setValue(RbSettings::RbutilVersion
, PUREVERSION
);
214 errormsg
+= tr("You need to fix the above errors before you can continue.");
217 QMessageBox::critical(this, tr("Configuration error"), errormsg
);
223 emit
settingsUpdated();
230 qDebug() << "[Config] aborted.";
235 void Config::setUserSettings()
238 proxy
.setEncodedUrl(RbSettings::value(RbSettings::Proxy
).toByteArray());
241 ui
.proxyPort
->setText(QString("%1").arg(proxy
.port()));
242 else ui
.proxyPort
->setText("");
243 ui
.proxyHost
->setText(proxy
.host());
244 ui
.proxyUser
->setText(proxy
.userName());
245 ui
.proxyPass
->setText(proxy
.password());
247 QString proxyType
= RbSettings::value(RbSettings::ProxyType
).toString();
248 if(proxyType
== "manual") ui
.radioManualProxy
->setChecked(true);
249 else if(proxyType
== "system") ui
.radioSystemProxy
->setChecked(true);
250 else ui
.radioNoProxy
->setChecked(true);
252 // set language selection
253 QList
<QListWidgetItem
*> a
;
255 // find key for lang value
256 QMap
<QString
, QString
>::const_iterator i
= lang
.constBegin();
257 QString l
= RbSettings::value(RbSettings::Language
).toString();
259 l
= QLocale::system().name();
260 while (i
!= lang
.constEnd()) {
265 else if(l
.startsWith(i
.value(), Qt::CaseInsensitive
)) {
266 // check if there is a base language (en -> en_US, etc.)
272 a
= ui
.listLanguages
->findItems(b
, Qt::MatchExactly
);
274 ui
.listLanguages
->setCurrentItem(a
.at(0));
275 // don't connect before language list has been set up to prevent
276 // triggering the signal by selecting the saved language.
277 connect(ui
.listLanguages
, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
281 mountpoint
= QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint
).toString());
282 setMountpoint(mountpoint
);
285 if(!QFileInfo(RbSettings::value(RbSettings::CachePath
).toString()).isDir())
286 RbSettings::setValue(RbSettings::CachePath
, QDir::tempPath());
287 ui
.cachePath
->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::CachePath
).toString()));
288 ui
.cacheDisable
->setChecked(RbSettings::value(RbSettings::CacheDisabled
).toBool());
289 ui
.cacheOfflineMode
->setChecked(RbSettings::value(RbSettings::CacheOffline
).toBool());
290 updateCacheInfo(RbSettings::value(RbSettings::CachePath
).toString());
294 void Config::updateCacheInfo(QString path
)
297 fs
= QDir(path
+ "/rbutil-cache/").entryInfoList(QDir::Files
| QDir::NoDotAndDotDot
);
299 for(int i
= 0; i
< fs
.size(); i
++) {
300 sz
+= fs
.at(i
).size();
302 ui
.cacheSize
->setText(tr("Current cache size is %L1 kiB.")
307 void Config::showDisabled(bool show
)
309 qDebug() << "[Config] disabled targets shown:" << show
;
311 QMessageBox::warning(this, tr("Showing disabled targets"),
312 tr("You just enabled showing targets that are marked disabled. "
313 "Disabled targets are not recommended to end users. Please "
314 "use this option only if you know what you are doing."));
320 void Config::setDevices()
323 // setup devices table
324 qDebug() << "[Config] setting up devices list";
326 QStringList platformList
;
327 if(ui
.showDisabled
->isChecked())
328 platformList
= SystemInfo::platforms(SystemInfo::PlatformAllDisabled
);
330 platformList
= SystemInfo::platforms(SystemInfo::PlatformAll
);
332 QMap
<QString
, QString
> manuf
;
333 for(int it
= 0; it
< platformList
.size(); it
++)
335 QString curbrand
= SystemInfo::platformValue(platformList
.at(it
),
336 SystemInfo::CurBrand
).toString();
337 manuf
.insertMulti(curbrand
, platformList
.at(it
));
340 // set up devices table
341 ui
.treeDevices
->header()->hide();
342 ui
.treeDevices
->expandAll();
343 ui
.treeDevices
->setColumnCount(1);
344 QList
<QTreeWidgetItem
*> items
;
347 QStringList brands
= manuf
.uniqueKeys();
350 QTreeWidgetItem
*w3
= 0;
352 QString selected
= RbSettings::value(RbSettings::Platform
).toString();
353 for(int c
= 0; c
< brands
.size(); c
++) {
354 w
= new QTreeWidgetItem();
355 w
->setFlags(Qt::ItemIsEnabled
);
356 w
->setText(0, brands
.at(c
));
358 // go through platforms and add all players matching the current brand
359 for(int it
= 0; it
< platformList
.size(); it
++) {
360 // skip if not current brand
361 if(!manuf
.values(brands
.at(c
)).contains(platformList
.at(it
)))
363 // construct display name
364 QString curname
= SystemInfo::platformValue(platformList
.at(it
),
365 SystemInfo::CurName
).toString() +
366 " (" +ServerInfo::platformValue(platformList
.at(it
),
367 ServerInfo::CurStatus
).toString() +")";
368 qDebug() << "[Config] add supported device:" << brands
.at(c
) << curname
;
369 w2
= new QTreeWidgetItem(w
, QStringList(curname
));
370 w2
->setData(0, Qt::UserRole
, platformList
.at(it
));
372 if(platformList
.at(it
) == selected
) {
373 w2
->setSelected(true);
374 w
->setExpanded(true);
375 w3
= w2
; // save pointer to hilight old selection
380 // remove any old items in list
381 QTreeWidgetItem
* widgetitem
;
383 widgetitem
= ui
.treeDevices
->takeTopLevelItem(0);
388 ui
.treeDevices
->insertTopLevelItems(0, items
);
390 ui
.treeDevices
->setCurrentItem(w3
); // hilight old selection
391 ui
.treeDevices
->scrollToItem(w3
);
400 QStringList ttslist
= TTSBase::getTTSList();
401 for(int a
= 0; a
< ttslist
.size(); a
++)
402 ui
.comboTts
->addItem(TTSBase::getTTSName(ttslist
.at(a
)), ttslist
.at(a
));
403 //update index of combobox
404 int index
= ui
.comboTts
->findData(RbSettings::value(RbSettings::Tts
).toString());
405 if(index
< 0) index
= 0;
406 ui
.comboTts
->setCurrentIndex(index
);
407 updateTtsState(index
);
412 void Config::updateTtsState(int index
)
414 QString ttsName
= ui
.comboTts
->itemData(index
).toString();
415 TTSBase
* tts
= TTSBase::getTTS(this,ttsName
);
419 ui
.configTTSstatus
->setText(tr("Configuration OK"));
420 ui
.configTTSstatusimg
->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
421 ui
.testTTS
->setEnabled(true);
425 ui
.configTTSstatus
->setText(tr("Configuration INVALID"));
426 ui
.configTTSstatusimg
->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
427 ui
.testTTS
->setEnabled(false);
430 delete tts
; /* Config objects are never deleted (in fact, they are leaked..), so we can't rely on QObject,
431 since that would delete the TTSBase instance on application exit*/
434 void Config::updateEncState()
436 if(ui
.treeDevices
->selectedItems().size() == 0)
439 QString devname
= ui
.treeDevices
->selectedItems().at(0)->data(0, Qt::UserRole
).toString();
440 QString encoder
= SystemInfo::platformValue(devname
,
441 SystemInfo::CurEncoder
).toString();
442 ui
.encoderName
->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname
,
443 SystemInfo::CurEncoder
).toString()));
445 EncBase
* enc
= EncBase::getEncoder(this,encoder
);
449 ui
.configEncstatus
->setText(tr("Configuration OK"));
450 ui
.configEncstatusimg
->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
454 ui
.configEncstatus
->setText(tr("Configuration INVALID"));
455 ui
.configEncstatusimg
->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
460 void Config::setNoProxy(bool checked
)
463 ui
.proxyPort
->setEnabled(i
);
464 ui
.proxyHost
->setEnabled(i
);
465 ui
.proxyUser
->setEnabled(i
);
466 ui
.proxyPass
->setEnabled(i
);
470 void Config::setSystemProxy(bool checked
)
472 ui
.proxyPort
->setEnabled(!checked
);
473 ui
.proxyHost
->setEnabled(!checked
);
474 ui
.proxyUser
->setEnabled(!checked
);
475 ui
.proxyPass
->setEnabled(!checked
);
477 // save values in input box
478 proxy
.setScheme("http");
479 proxy
.setUserName(ui
.proxyUser
->text());
480 proxy
.setPassword(ui
.proxyPass
->text());
481 proxy
.setHost(ui
.proxyHost
->text());
482 proxy
.setPort(ui
.proxyPort
->text().toInt());
483 // show system values in input box
484 QUrl envproxy
= System::systemProxy();
485 qDebug() << "[Config] setting system proxy" << envproxy
;
487 ui
.proxyHost
->setText(envproxy
.host());
488 ui
.proxyPort
->setText(QString("%1").arg(envproxy
.port()));
489 ui
.proxyUser
->setText(envproxy
.userName());
490 ui
.proxyPass
->setText(envproxy
.password());
492 if(envproxy
.host().isEmpty() || envproxy
.port() == -1) {
493 qDebug() << "[Config] sytem proxy is invalid.";
494 QMessageBox::warning(this, tr("Proxy Detection"),
495 tr("The System Proxy settings are invalid!\n"
496 "Rockbox Utility can't work with this proxy settings. "
497 "Make sure the system proxy is set correctly. Note that "
498 "\"proxy auto-config (PAC)\" scripts are not supported by "
499 "Rockbox Utility. If your system uses this you need "
500 "to use manual proxy settings."),
501 QMessageBox::Ok
,QMessageBox::Ok
);
502 // the current proxy settings are invalid. Check the saved proxy
504 if(RbSettings::value(RbSettings::ProxyType
).toString() == "manual")
505 ui
.radioManualProxy
->setChecked(true);
507 ui
.radioNoProxy
->setChecked(true);
512 ui
.proxyHost
->setText(proxy
.host());
514 ui
.proxyPort
->setText(QString("%1").arg(proxy
.port()));
515 else ui
.proxyPort
->setText("");
516 ui
.proxyUser
->setText(proxy
.userName());
517 ui
.proxyPass
->setText(proxy
.password());
523 QStringList
Config::findLanguageFiles()
525 QDir
dir(programPath
);
526 QStringList fileNames
;
528 fileNames
= dir
.entryList(QStringList("*.qm"), QDir::Files
, QDir::Name
);
530 QDir
resDir(":/lang");
531 fileNames
+= resDir
.entryList(QStringList("*.qm"), QDir::Files
, QDir::Name
);
533 QRegExp
exp("^rbutil_(.*)\\.qm");
534 for(int i
= 0; i
< fileNames
.size(); i
++) {
535 QString a
= fileNames
.at(i
);
536 a
.replace(exp
, "\\1");
540 qDebug() << "[Config] available lang files:" << langs
;
546 QString
Config::languageName(const QString
&qmFile
)
548 QTranslator translator
;
550 QString file
= "rbutil_" + qmFile
;
551 if(!translator
.load(file
, programPath
))
552 translator
.load(file
, ":/lang");
554 return translator
.translate("Configure", "English",
555 "This is the localized language name, i.e. your language.");
559 void Config::updateLanguage()
561 qDebug() << "[Config] update selected language";
562 QList
<QListWidgetItem
*> a
= ui
.listLanguages
->selectedItems();
564 language
= lang
.value(a
.at(0)->text());
565 qDebug() << "[Config] new language:" << language
;
569 void Config::browseCache()
571 QString old
= ui
.cachePath
->text();
572 if(!QFileInfo(old
).isDir())
573 old
= QDir::tempPath();
574 QString c
= QFileDialog::getExistingDirectory(this, tr("Set Cache Path"), old
);
577 else if(!QFileInfo(c
).isDir())
578 c
= QDir::tempPath();
579 ui
.cachePath
->setText(QDir::toNativeSeparators(c
));
584 void Config::refreshMountpoint()
586 // avoid QComboBox to send signals during rebuild to avoid changing to an
588 ui
.mountPoint
->blockSignals(true);
589 ui
.mountPoint
->clear();
590 QStringList mps
= Utils::mountpoints();
591 for(int i
= 0; i
< mps
.size(); ++i
) {
592 // add mountpoint as user data so we can change the displayed string
593 // later (to include volume label or similar)
594 // Skip unwritable mountpoints, they are not useable for us.
595 if(QFileInfo(mps
.at(i
)).isWritable()) {
596 QString description
= QString("%1 (%2 GiB of %3 GiB free)")
597 .arg(Utils::filesystemName(mps
.at(i
)))
598 .arg((double)Utils::filesystemFree(mps
.at(i
))/(1<<30), 0, 'f', 2)
599 .arg((double)Utils::filesystemTotal(mps
.at(i
))/(1<<30), 0, 'f', 2);
600 ui
.mountPoint
->addItem(QDir::toNativeSeparators(mps
.at(i
)), description
);
603 if(!mountpoint
.isEmpty()) {
604 setMountpoint(mountpoint
);
606 ui
.mountPoint
->blockSignals(false);
610 void Config::updateMountpoint(QString m
)
613 mountpoint
= QDir::fromNativeSeparators(m
);
614 qDebug() << "[Config] Mountpoint set to" << mountpoint
;
619 void Config::updateMountpoint(int idx
)
624 QString mp
= ui
.mountPoint
->itemText(idx
);
626 mountpoint
= QDir::fromNativeSeparators(mp
);
627 qDebug() << "[Config] Mountpoint set to" << mountpoint
;
632 void Config::setMountpoint(QString m
)
637 int index
= ui
.mountPoint
->findText(QDir::toNativeSeparators(m
));
639 ui
.mountPoint
->setCurrentIndex(index
);
642 // keep a mountpoint that is not in the list for convenience (to allow
643 // easier development)
644 ui
.mountPoint
->addItem(QDir::toNativeSeparators(m
));
645 ui
.mountPoint
->setCurrentIndex(ui
.mountPoint
->findText(m
));
647 qDebug() << "[Config] Mountpoint set to" << mountpoint
;
651 void Config::autodetect()
653 Autodetection
detector(this);
654 // disable tree during detection as "working" feedback.
655 // TODO: replace the tree view with a splash screen during this time.
656 ui
.treeDevices
->setEnabled(false);
657 this->setCursor(Qt::WaitCursor
);
658 QCoreApplication::processEvents();
660 if(detector
.detect()) //let it detect
662 QString devicename
= detector
.getDevice();
663 // deexpand all items
664 for(int a
= 0; a
< ui
.treeDevices
->topLevelItemCount(); a
++)
665 ui
.treeDevices
->topLevelItem(a
)->setExpanded(false);
666 //deselect the selected item(s)
667 for(int a
= 0; a
< ui
.treeDevices
->selectedItems().size(); a
++)
668 ui
.treeDevices
->selectedItems().at(a
)->setSelected(false);
671 // enumerate all platform items
672 QList
<QTreeWidgetItem
*> itmList
673 = ui
.treeDevices
->findItems("*",Qt::MatchWildcard
);
674 for(int i
=0; i
< itmList
.size();i
++)
676 //enumerate device items
677 for(int j
=0;j
< itmList
.at(i
)->childCount();j
++)
679 QString data
= itmList
.at(i
)->child(j
)->data(0, Qt::UserRole
).toString();
681 QFont f
= itmList
.at(i
)->child(j
)->font(0);
683 itmList
.at(i
)->child(j
)->setFont(0, f
);
685 if(devicename
== data
) // item found
688 itmList
.at(i
)->child(j
)->setFont(0, f
);
689 itmList
.at(i
)->child(j
)->setSelected(true); //select the item
690 itmList
.at(i
)->setExpanded(true); //expand the platform item
691 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
692 ui
.treeDevices
->scrollToItem(itmList
.at(i
)->child(j
));
699 if(!detector
.errdev().isEmpty()) {
701 if(SystemInfo::platformValue(detector
.errdev(),
702 SystemInfo::CurBootloaderMethod
) == "ipod") {
703 text
= tr("%1 \"MacPod\" found!\n"
704 "Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
705 "to run. ").arg(SystemInfo::platformValue(
706 detector
.errdev(), SystemInfo::CurName
).toString());
708 // treat all other errors as MTP device for now.
710 text
= tr("%1 in MTP mode found!\n"
711 "You need to change your player to MSC mode for installation. ")
712 .arg(SystemInfo::platformValue(detector
.errdev(),
713 SystemInfo::CurName
).toString());
715 text
+= tr("Until you change this installation will fail!");
717 QMessageBox::critical(this, tr("Fatal error"), text
, QMessageBox::Ok
);
720 if(!detector
.incompatdev().isEmpty()) {
722 text
= tr("Detected an unsupported player:\n%1\n"
723 "Sorry, Rockbox doesn't run on your player.")
724 .arg(SystemInfo::platformValue(detector
.incompatdev(),
725 SystemInfo::CurName
).toString());
727 QMessageBox::critical(this, tr("Fatal: player incompatible"),
728 text
, QMessageBox::Ok
);
732 if(detector
.getMountPoint() != "" )
734 setMountpoint(detector
.getMountPoint());
738 QMessageBox::warning(this, tr("Autodetection"),
739 tr("Could not detect a Mountpoint.\n"
740 "Select your Mountpoint manually."),
741 QMessageBox::Ok
,QMessageBox::Ok
);
747 QMessageBox::warning(this, tr("Autodetection"),
748 tr("Could not detect a device.\n"
749 "Select your device and Mountpoint manually."),
750 QMessageBox::Ok
,QMessageBox::Ok
);
753 ui
.treeDevices
->setEnabled(true);
757 void Config::cacheClear()
759 if(QMessageBox::critical(this, tr("Really delete cache?"),
760 tr("Do you really want to delete the cache? "
761 "Make absolutely sure this setting is correct as it will "
762 "remove <b>all</b> files in this folder!").arg(ui
.cachePath
->text()),
763 QMessageBox::Yes
| QMessageBox::No
) != QMessageBox::Yes
)
766 QString cache
= ui
.cachePath
->text() + "/rbutil-cache/";
767 if(!QFileInfo(cache
).isDir()) {
768 QMessageBox::critical(this, tr("Path wrong!"),
769 tr("The cache path is invalid. Aborting."), QMessageBox::Ok
);
774 fn
= dir
.entryList(QStringList("*"), QDir::Files
, QDir::Name
);
776 for(int i
= 0; i
< fn
.size(); i
++) {
777 QString f
= cache
+ fn
.at(i
);
780 updateCacheInfo(RbSettings::value(RbSettings::CachePath
).toString());
784 void Config::configTts()
786 int index
= ui
.comboTts
->currentIndex();
787 TTSBase
* tts
= TTSBase::getTTS(this,ui
.comboTts
->itemData(index
).toString());
789 EncTtsCfgGui
gui(this,tts
,TTSBase::getTTSName(ui
.comboTts
->itemData(index
).toString()));
791 updateTtsState(ui
.comboTts
->currentIndex());
792 delete tts
; /* Config objects are never deleted (in fact, they are
793 leaked..), so we can't rely on QObject, since that would
794 delete the TTSBase instance on application exit */
797 void Config::testTts()
800 int index
= ui
.comboTts
->currentIndex();
803 ui
.testTTS
->setEnabled(false);
804 tts
= TTSBase::getTTS(this,ui
.comboTts
->itemData(index
).toString());
807 QMessageBox::warning(this,tr("TTS configuration invalid"),
808 tr("TTS configuration invalid. \n Please configure TTS engine."));
811 if(!tts
->start(&errstr
))
813 QMessageBox::warning(this,tr("Could not start TTS engine."),
814 tr("Could not start TTS engine.\n") + errstr
815 + tr("\nPlease configure TTS engine."));
816 ui
.testTTS
->setEnabled(true);
821 QTemporaryFile
file(this);
822 // keep filename empty if the TTS can do speaking for itself.
823 if(!(tts
->capabilities() & TTSBase::CanSpeak
)) {
825 filename
= file
.fileName();
829 if(tts
->voice(tr("Rockbox Utility Voice Test"),filename
,&errstr
) == FatalError
)
832 QMessageBox::warning(this,tr("Could not voice test string."),
833 tr("Could not voice test string.\n") + errstr
834 + tr("\nPlease configure TTS engine."));
835 ui
.testTTS
->setEnabled(false);
839 if(!filename
.isEmpty()) {
840 #if defined(Q_OS_LINUX)
841 QString exe
= Utils::findExecutable("aplay");
842 if(exe
== "") exe
= Utils::findExecutable("play");
845 QProcess::execute(exe
+" "+filename
);
848 QSound::play(filename
);
851 ui
.testTTS
->setEnabled(true);
852 delete tts
; /* Config objects are never deleted (in fact, they are
853 leaked..), so we can't rely on QObject, since that would
854 delete the TTSBase instance on application exit */
857 void Config::configEnc()
859 if(ui
.treeDevices
->selectedItems().size() == 0)
862 QString devname
= ui
.treeDevices
->selectedItems().at(0)->data(0, Qt::UserRole
).toString();
863 QString encoder
= SystemInfo::platformValue(devname
,
864 SystemInfo::CurEncoder
).toString();
865 ui
.encoderName
->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname
,
866 SystemInfo::CurEncoder
).toString()));
869 EncBase
* enc
= EncBase::getEncoder(this,encoder
);
871 EncTtsCfgGui
gui(this,enc
,EncBase::getEncoderName(encoder
));