Merge branch 'master' into pandora-port
[maemo-rb.git] / rbutil / rbutilqt / configure.cpp
blobd775eec172c1d6795bd203f2d888d1bb9114d20d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
20 #include <QtGui>
22 #include "version.h"
23 #include "configure.h"
24 #include "autodetection.h"
25 #include "ui_configurefrm.h"
26 #include "browsedirtree.h"
27 #include "encoders.h"
28 #include "ttsbase.h"
29 #include "system.h"
30 #include "encttscfggui.h"
31 #include "rbsettings.h"
32 #include "serverinfo.h"
33 #include "systeminfo.h"
34 #include "utils.h"
35 #include <stdio.h>
36 #if defined(Q_OS_WIN32)
37 #if defined(UNICODE)
38 #define _UNICODE
39 #endif
40 #include <tchar.h>
41 #include <windows.h>
42 #endif
44 #define DEFAULT_LANG "English (en)"
45 #define DEFAULT_LANG_CODE "en"
47 Config::Config(QWidget *parent,int index) : QDialog(parent)
49 programPath = qApp->applicationDirPath() + "/";
50 ui.setupUi(this);
51 ui.tabConfiguration->setCurrentIndex(index);
52 ui.radioManualProxy->setChecked(true);
53 QRegExpValidator *proxyValidator = new QRegExpValidator(this);
54 QRegExp validate("[0-9]*");
55 proxyValidator->setRegExp(validate);
56 ui.proxyPort->setValidator(proxyValidator);
58 // build language list and sort alphabetically
59 QStringList langs = findLanguageFiles();
60 for(int i = 0; i < langs.size(); ++i)
61 lang.insert(languageName(langs.at(i))
62 + QString(" (%1)").arg(langs.at(i)), langs.at(i));
63 lang.insert(DEFAULT_LANG, DEFAULT_LANG_CODE);
64 QMap<QString, QString>::const_iterator i = lang.constBegin();
65 while (i != lang.constEnd()) {
66 ui.listLanguages->addItem(i.key());
67 i++;
69 ui.listLanguages->setSelectionMode(QAbstractItemView::SingleSelection);
70 ui.proxyPass->setEchoMode(QLineEdit::Password);
71 ui.treeDevices->setAlternatingRowColors(true);
72 ui.listLanguages->setAlternatingRowColors(true);
74 /* Explicitly set some widgets to have left-to-right layout */
75 ui.treeDevices->setLayoutDirection(Qt::LeftToRight);
76 ui.mountPoint->setLayoutDirection(Qt::LeftToRight);
77 ui.proxyHost->setLayoutDirection(Qt::LeftToRight);
78 ui.proxyPort->setLayoutDirection(Qt::LeftToRight);
79 ui.proxyUser->setLayoutDirection(Qt::LeftToRight);
80 ui.proxyPass->setLayoutDirection(Qt::LeftToRight);
81 ui.listLanguages->setLayoutDirection(Qt::LeftToRight);
82 ui.cachePath->setLayoutDirection(Qt::LeftToRight);
83 ui.comboTts->setLayoutDirection(Qt::LeftToRight);
85 this->setModal(true);
87 connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
88 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
89 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
90 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
91 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
92 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
93 connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
94 connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
95 connect(ui.configTts, SIGNAL(clicked()), this, SLOT(configTts()));
96 connect(ui.configEncoder, SIGNAL(clicked()), this, SLOT(configEnc()));
97 connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
98 connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
99 connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
100 connect(ui.showDisabled, SIGNAL(toggled(bool)), this, SLOT(showDisabled(bool)));
101 setUserSettings();
102 setDevices();
106 void Config::accept()
108 qDebug() << "[Config] checking configuration";
109 QString errormsg = tr("The following errors occurred:") + "<ul>";
110 bool error = false;
112 // proxy: save entered proxy values, not displayed.
113 if(ui.radioManualProxy->isChecked()) {
114 proxy.setScheme("http");
115 proxy.setUserName(ui.proxyUser->text());
116 proxy.setPassword(ui.proxyPass->text());
117 proxy.setHost(ui.proxyHost->text());
118 proxy.setPort(ui.proxyPort->text().toInt());
121 RbSettings::setValue(RbSettings::Proxy, proxy.toString());
122 qDebug() << "[Config] setting proxy to:" << proxy;
123 // proxy type
124 QString proxyType;
125 if(ui.radioNoProxy->isChecked()) proxyType = "none";
126 else if(ui.radioSystemProxy->isChecked()) proxyType = "system";
127 else proxyType = "manual";
128 RbSettings::setValue(RbSettings::ProxyType, proxyType);
130 // language
131 if(RbSettings::value(RbSettings::Language).toString() != language
132 && !language.isEmpty()) {
133 QMessageBox::information(this, tr("Language changed"),
134 tr("You need to restart the application for the changed language "
135 "to take effect."));
137 RbSettings::setValue(RbSettings::Language, language);
139 // mountpoint
140 QString mp = ui.mountPoint->text();
141 if(mp.isEmpty()) {
142 errormsg += "<li>" + tr("No mountpoint given") + "</li>";
143 error = true;
145 else if(!QFileInfo(mp).exists()) {
146 errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>";
147 error = true;
149 else if(!QFileInfo(mp).isDir()) {
150 errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>";
151 error = true;
153 else if(!QFileInfo(mp).isWritable()) {
154 errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>";
155 error = true;
157 else {
158 RbSettings::setValue(RbSettings::Mountpoint, QDir::fromNativeSeparators(mp));
161 // platform
162 QString nplat;
163 if(ui.treeDevices->selectedItems().size() != 0) {
164 nplat = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
165 RbSettings::setValue(RbSettings::Platform, nplat);
167 else {
168 errormsg += "<li>" + tr("No player selected") + "</li>";
169 error = true;
172 // cache settings
173 if(QFileInfo(ui.cachePath->text()).isDir()) {
174 if(!QFileInfo(ui.cachePath->text()).isWritable()) {
175 errormsg += "<li>" + tr("Cache path not writeable. Leave path empty "
176 "to default to systems temporary path.") + "</li>";
177 error = true;
179 else
180 RbSettings::setValue(RbSettings::CachePath, ui.cachePath->text());
182 else // default to system temp path
183 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
184 RbSettings::setValue(RbSettings::CacheDisabled, ui.cacheDisable->isChecked());
185 RbSettings::setValue(RbSettings::CacheOffline, ui.cacheOfflineMode->isChecked());
187 // tts settings
188 int i = ui.comboTts->currentIndex();
189 RbSettings::setValue(RbSettings::Tts, ui.comboTts->itemData(i).toString());
191 RbSettings::setValue(RbSettings::RbutilVersion, PUREVERSION);
193 errormsg += "</ul>";
194 errormsg += tr("You need to fix the above errors before you can continue.");
196 if(error) {
197 QMessageBox::critical(this, tr("Configuration error"), errormsg);
199 else {
200 // sync settings
201 RbSettings::sync();
202 this->close();
203 emit settingsUpdated();
208 void Config::abort()
210 qDebug() << "[Config] aborted.";
211 this->close();
215 void Config::setUserSettings()
217 // set proxy
218 proxy = RbSettings::value(RbSettings::Proxy).toString();
220 if(proxy.port() > 0)
221 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
222 else ui.proxyPort->setText("");
223 ui.proxyHost->setText(proxy.host());
224 ui.proxyUser->setText(proxy.userName());
225 ui.proxyPass->setText(proxy.password());
227 QString proxyType = RbSettings::value(RbSettings::ProxyType).toString();
228 if(proxyType == "manual") ui.radioManualProxy->setChecked(true);
229 else if(proxyType == "system") ui.radioSystemProxy->setChecked(true);
230 else ui.radioNoProxy->setChecked(true);
232 // set language selection
233 QList<QListWidgetItem*> a;
234 QString b;
235 // find key for lang value
236 QMap<QString, QString>::const_iterator i = lang.constBegin();
237 QString l = RbSettings::value(RbSettings::Language).toString();
238 if(l.isEmpty())
239 l = QLocale::system().name();
240 while (i != lang.constEnd()) {
241 if(i.value() == l) {
242 b = i.key();
243 break;
245 else if(l.startsWith(i.value(), Qt::CaseInsensitive)) {
246 // check if there is a base language (en -> en_US, etc.)
247 b = i.key();
248 break;
250 i++;
252 a = ui.listLanguages->findItems(b, Qt::MatchExactly);
253 if(a.size() > 0)
254 ui.listLanguages->setCurrentItem(a.at(0));
255 // don't connect before language list has been set up to prevent
256 // triggering the signal by selecting the saved language.
257 connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
259 // devices tab
260 ui.mountPoint->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint).toString()));
262 // cache tab
263 if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir())
264 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
265 ui.cachePath->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::CachePath).toString()));
266 ui.cacheDisable->setChecked(RbSettings::value(RbSettings::CacheDisabled).toBool());
267 ui.cacheOfflineMode->setChecked(RbSettings::value(RbSettings::CacheOffline).toBool());
268 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
272 void Config::updateCacheInfo(QString path)
274 QList<QFileInfo> fs;
275 fs = QDir(path + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
276 qint64 sz = 0;
277 for(int i = 0; i < fs.size(); i++) {
278 sz += fs.at(i).size();
280 ui.cacheSize->setText(tr("Current cache size is %L1 kiB.")
281 .arg(sz/1024));
285 void Config::showDisabled(bool show)
287 qDebug() << "[Config] disabled targets shown:" << show;
288 if(show)
289 QMessageBox::warning(this, tr("Showing disabled targets"),
290 tr("You just enabled showing targets that are marked disabled. "
291 "Disabled targets are not recommended to end users. Please "
292 "use this option only if you know what you are doing."));
293 setDevices();
298 void Config::setDevices()
301 // setup devices table
302 qDebug() << "[Config] setting up devices list";
304 QStringList platformList;
305 if(ui.showDisabled->isChecked())
306 platformList = SystemInfo::platforms(SystemInfo::PlatformAllDisabled);
307 else
308 platformList = SystemInfo::platforms(SystemInfo::PlatformAll);
310 QMap <QString, QString> manuf;
311 for(int it = 0; it < platformList.size(); it++)
313 QString curbrand = SystemInfo::platformValue(platformList.at(it),
314 SystemInfo::CurBrand).toString();
315 manuf.insertMulti(curbrand, platformList.at(it));
318 // set up devices table
319 ui.treeDevices->header()->hide();
320 ui.treeDevices->expandAll();
321 ui.treeDevices->setColumnCount(1);
322 QList<QTreeWidgetItem *> items;
324 // get manufacturers
325 QStringList brands = manuf.uniqueKeys();
326 QTreeWidgetItem *w;
327 QTreeWidgetItem *w2;
328 QTreeWidgetItem *w3 = 0;
330 QString selected = RbSettings::value(RbSettings::Platform).toString();
331 for(int c = 0; c < brands.size(); c++) {
332 w = new QTreeWidgetItem();
333 w->setFlags(Qt::ItemIsEnabled);
334 w->setText(0, brands.at(c));
335 items.append(w);
336 // go through platforms and add all players matching the current brand
337 for(int it = 0; it < platformList.size(); it++) {
338 // skip if not current brand
339 if(!manuf.values(brands.at(c)).contains(platformList.at(it)))
340 continue;
341 // construct display name
342 QString curname = SystemInfo::platformValue(platformList.at(it),
343 SystemInfo::CurName).toString() +
344 " (" +ServerInfo::platformValue(platformList.at(it),
345 ServerInfo::CurStatus).toString() +")";
346 qDebug() << "[Config] add supported device:" << brands.at(c) << curname;
347 w2 = new QTreeWidgetItem(w, QStringList(curname));
348 w2->setData(0, Qt::UserRole, platformList.at(it));
350 if(platformList.at(it) == selected) {
351 w2->setSelected(true);
352 w->setExpanded(true);
353 w3 = w2; // save pointer to hilight old selection
355 items.append(w2);
358 // remove any old items in list
359 QTreeWidgetItem* widgetitem;
360 do {
361 widgetitem = ui.treeDevices->takeTopLevelItem(0);
362 delete widgetitem;
364 while(widgetitem);
365 // add new items
366 ui.treeDevices->insertTopLevelItems(0, items);
367 if(w3 != 0) {
368 ui.treeDevices->setCurrentItem(w3); // hilight old selection
369 ui.treeDevices->scrollToItem(w3);
372 // tts / encoder tab
374 //encoders
375 updateEncState();
377 //tts
378 QStringList ttslist = TTSBase::getTTSList();
379 for(int a = 0; a < ttslist.size(); a++)
380 ui.comboTts->addItem(TTSBase::getTTSName(ttslist.at(a)), ttslist.at(a));
381 //update index of combobox
382 int index = ui.comboTts->findData(RbSettings::value(RbSettings::Tts).toString());
383 if(index < 0) index = 0;
384 ui.comboTts->setCurrentIndex(index);
385 updateTtsState(index);
390 void Config::updateTtsState(int index)
392 QString ttsName = ui.comboTts->itemData(index).toString();
393 TTSBase* tts = TTSBase::getTTS(this,ttsName);
395 if(tts->configOk())
397 ui.configTTSstatus->setText(tr("Configuration OK"));
398 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
399 ui.testTTS->setEnabled(true);
401 else
403 ui.configTTSstatus->setText(tr("Configuration INVALID"));
404 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
405 ui.testTTS->setEnabled(false);
408 delete tts; /* Config objects are never deleted (in fact, they are leaked..), so we can't rely on QObject,
409 since that would delete the TTSBase instance on application exit*/
412 void Config::updateEncState()
414 if(ui.treeDevices->selectedItems().size() == 0)
415 return;
417 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
418 QString encoder = SystemInfo::platformValue(devname,
419 SystemInfo::CurEncoder).toString();
420 ui.encoderName->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname,
421 SystemInfo::CurEncoder).toString()));
423 EncBase* enc = EncBase::getEncoder(this,encoder);
425 if(enc->configOk())
427 ui.configEncstatus->setText(tr("Configuration OK"));
428 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
430 else
432 ui.configEncstatus->setText(tr("Configuration INVALID"));
433 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
438 void Config::setNoProxy(bool checked)
440 bool i = !checked;
441 ui.proxyPort->setEnabled(i);
442 ui.proxyHost->setEnabled(i);
443 ui.proxyUser->setEnabled(i);
444 ui.proxyPass->setEnabled(i);
448 void Config::setSystemProxy(bool checked)
450 ui.proxyPort->setEnabled(!checked);
451 ui.proxyHost->setEnabled(!checked);
452 ui.proxyUser->setEnabled(!checked);
453 ui.proxyPass->setEnabled(!checked);
454 if(checked) {
455 // save values in input box
456 proxy.setScheme("http");
457 proxy.setUserName(ui.proxyUser->text());
458 proxy.setPassword(ui.proxyPass->text());
459 proxy.setHost(ui.proxyHost->text());
460 proxy.setPort(ui.proxyPort->text().toInt());
461 // show system values in input box
462 QUrl envproxy = System::systemProxy();
463 qDebug() << "[Config] setting system proxy" << envproxy;
465 ui.proxyHost->setText(envproxy.host());
466 ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
467 ui.proxyUser->setText(envproxy.userName());
468 ui.proxyPass->setText(envproxy.password());
470 if(envproxy.host().isEmpty() || envproxy.port() == -1) {
471 qDebug() << "[Config] sytem proxy is invalid.";
472 QMessageBox::warning(this, tr("Proxy Detection"),
473 tr("The System Proxy settings are invalid!\n"
474 "Rockbox Utility can't work with this proxy settings. "
475 "Make sure the system proxy is set correctly. Note that "
476 "\"proxy auto-config (PAC)\" scripts are not supported by "
477 "Rockbox Utility. If your system uses this you need "
478 "to use manual proxy settings."),
479 QMessageBox::Ok ,QMessageBox::Ok);
480 // the current proxy settings are invalid. Check the saved proxy
481 // type again.
482 if(RbSettings::value(RbSettings::ProxyType).toString() == "manual")
483 ui.radioManualProxy->setChecked(true);
484 else
485 ui.radioNoProxy->setChecked(true);
489 else {
490 ui.proxyHost->setText(proxy.host());
491 if(proxy.port() > 0)
492 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
493 else ui.proxyPort->setText("");
494 ui.proxyUser->setText(proxy.userName());
495 ui.proxyPass->setText(proxy.password());
501 QStringList Config::findLanguageFiles()
503 QDir dir(programPath);
504 QStringList fileNames;
505 QStringList langs;
506 fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
508 QDir resDir(":/lang");
509 fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
511 QRegExp exp("^rbutil_(.*)\\.qm");
512 for(int i = 0; i < fileNames.size(); i++) {
513 QString a = fileNames.at(i);
514 a.replace(exp, "\\1");
515 langs.append(a);
517 langs.sort();
518 qDebug() << "[Config] available lang files:" << langs;
520 return langs;
524 QString Config::languageName(const QString &qmFile)
526 QTranslator translator;
528 QString file = "rbutil_" + qmFile;
529 if(!translator.load(file, programPath))
530 translator.load(file, ":/lang");
532 return translator.translate("Configure", "English",
533 "This is the localized language name, i.e. your language.");
537 void Config::updateLanguage()
539 qDebug() << "[Config] update selected language";
540 QList<QListWidgetItem*> a = ui.listLanguages->selectedItems();
541 if(a.size() > 0)
542 language = lang.value(a.at(0)->text());
543 qDebug() << "[Config] new language:" << language;
547 void Config::browseFolder()
549 browser = new BrowseDirtree(this,tr("Select your device"));
550 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
551 browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
552 #elif defined(Q_OS_WIN32)
553 browser->setFilter(QDir::Drives);
554 #endif
555 #if defined(Q_OS_MACX)
556 browser->setRoot("/Volumes");
557 #elif defined(Q_OS_LINUX)
558 browser->setDir("/media");
559 #endif
560 if( ui.mountPoint->text() != "" )
562 browser->setDir(ui.mountPoint->text());
564 browser->show();
565 connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
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);
575 if(c.isEmpty())
576 c = old;
577 else if(!QFileInfo(c).isDir())
578 c = QDir::tempPath();
579 ui.cachePath->setText(QDir::toNativeSeparators(c));
580 updateCacheInfo(c);
584 void Config::setMountpoint(QString m)
586 ui.mountPoint->setText(m);
590 void Config::autodetect()
592 Autodetection detector(this);
593 // disable tree during detection as "working" feedback.
594 // TODO: replace the tree view with a splash screen during this time.
595 ui.treeDevices->setEnabled(false);
596 this->setCursor(Qt::WaitCursor);
597 QCoreApplication::processEvents();
599 if(detector.detect()) //let it detect
601 QString devicename = detector.getDevice();
602 // deexpand all items
603 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
604 ui.treeDevices->topLevelItem(a)->setExpanded(false);
605 //deselect the selected item(s)
606 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
607 ui.treeDevices->selectedItems().at(a)->setSelected(false);
609 // find the new item
610 // enumerate all platform items
611 QList<QTreeWidgetItem*> itmList
612 = ui.treeDevices->findItems("*",Qt::MatchWildcard);
613 for(int i=0; i< itmList.size();i++)
615 //enumerate device items
616 for(int j=0;j < itmList.at(i)->childCount();j++)
618 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
620 if(devicename == data) // item found
622 itmList.at(i)->child(j)->setSelected(true); //select the item
623 itmList.at(i)->setExpanded(true); //expand the platform item
624 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
625 ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
626 break;
630 this->unsetCursor();
632 if(!detector.errdev().isEmpty()) {
633 QString text;
634 if(detector.errdev() == "sansae200")
635 text = tr("Sansa e200 in MTP mode found!\n"
636 "You need to change your player to MSC mode for installation. ");
637 if(detector.errdev() == "h10")
638 text = tr("H10 20GB in MTP mode found!\n"
639 "You need to change your player to UMS mode for installation. ");
640 if(SystemInfo::platformValue(detector.errdev(),
641 SystemInfo::CurBootloaderMethod) == "ipod")
642 text = tr("%1 \"MacPod\" found!\n"
643 "Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
644 "to run. ").arg(SystemInfo::platformValue(
645 detector.errdev(), SystemInfo::CurName).toString());
646 text += tr("Unless you changed this installation will fail!");
648 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
649 return;
651 if(!detector.incompatdev().isEmpty()) {
652 QString text;
653 text = tr("Detected an unsupported player:\n%1\n"
654 "Sorry, Rockbox doesn't run on your player.")
655 .arg(SystemInfo::platformValue(detector.incompatdev(),
656 SystemInfo::CurName).toString());
658 QMessageBox::critical(this, tr("Fatal: player incompatible"),
659 text, QMessageBox::Ok);
660 return;
663 if(detector.getMountPoint() != "" )
665 ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint()));
667 else
669 QMessageBox::warning(this, tr("Autodetection"),
670 tr("Could not detect a Mountpoint.\n"
671 "Select your Mountpoint manually."),
672 QMessageBox::Ok ,QMessageBox::Ok);
675 else
677 this->unsetCursor();
678 QMessageBox::warning(this, tr("Autodetection"),
679 tr("Could not detect a device.\n"
680 "Select your device and Mountpoint manually."),
681 QMessageBox::Ok ,QMessageBox::Ok);
684 ui.treeDevices->setEnabled(true);
688 void Config::cacheClear()
690 if(QMessageBox::critical(this, tr("Really delete cache?"),
691 tr("Do you really want to delete the cache? "
692 "Make absolutely sure this setting is correct as it will "
693 "remove <b>all</b> files in this folder!").arg(ui.cachePath->text()),
694 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
695 return;
697 QString cache = ui.cachePath->text() + "/rbutil-cache/";
698 if(!QFileInfo(cache).isDir()) {
699 QMessageBox::critical(this, tr("Path wrong!"),
700 tr("The cache path is invalid. Aborting."), QMessageBox::Ok);
701 return;
703 QDir dir(cache);
704 QStringList fn;
705 fn = dir.entryList(QStringList("*"), QDir::Files, QDir::Name);
707 for(int i = 0; i < fn.size(); i++) {
708 QString f = cache + fn.at(i);
709 QFile::remove(f);
711 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
715 void Config::configTts()
717 int index = ui.comboTts->currentIndex();
718 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
720 EncTtsCfgGui gui(this,tts,TTSBase::getTTSName(ui.comboTts->itemData(index).toString()));
721 gui.exec();
722 updateTtsState(ui.comboTts->currentIndex());
723 delete tts; /* Config objects are never deleted (in fact, they are
724 leaked..), so we can't rely on QObject, since that would
725 delete the TTSBase instance on application exit */
728 void Config::testTts()
730 QString errstr;
731 int index = ui.comboTts->currentIndex();
732 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
733 if(!tts->configOk())
735 QMessageBox::warning(this,tr("TTS configuration invalid"),
736 tr("TTS configuration invalid. \n Please configure TTS engine."));
737 return;
739 ui.testTTS->setEnabled(false);
740 if(!tts->start(&errstr))
742 QMessageBox::warning(this,tr("Could not start TTS engine."),
743 tr("Could not start TTS engine.\n") + errstr
744 + tr("\nPlease configure TTS engine."));
745 ui.testTTS->setEnabled(true);
746 return;
749 QTemporaryFile file(this);
750 file.open();
751 QString filename = file.fileName();
752 file.close();
754 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError)
756 tts->stop();
757 QMessageBox::warning(this,tr("Could not voice test string."),
758 tr("Could not voice test string.\n") + errstr
759 + tr("\nPlease configure TTS engine."));
760 ui.testTTS->setEnabled(false);
761 return;
763 tts->stop();
764 #if defined(Q_OS_LINUX)
765 QString exe = Utils::findExecutable("aplay");
766 if(exe == "") exe = Utils::findExecutable("play");
767 if(exe != "")
769 QProcess::execute(exe+" "+filename);
771 #else
772 QSound::play(filename);
773 #endif
774 ui.testTTS->setEnabled(true);
775 delete tts; /* Config objects are never deleted (in fact, they are
776 leaked..), so we can't rely on QObject, since that would
777 delete the TTSBase instance on application exit */
780 void Config::configEnc()
782 if(ui.treeDevices->selectedItems().size() == 0)
783 return;
785 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
786 QString encoder = SystemInfo::platformValue(devname,
787 SystemInfo::CurEncoder).toString();
788 ui.encoderName->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname,
789 SystemInfo::CurEncoder).toString()));
792 EncBase* enc = EncBase::getEncoder(this,encoder);
794 EncTtsCfgGui gui(this,enc,EncBase::getEncoderName(encoder));
795 gui.exec();
797 updateEncState();