Add "elfzip" target to make which creates a zip of all elf files, as mapzip does...
[maemo-rb.git] / rbutil / rbutilqt / configure.cpp
blobe5ea699257bf62c8ccd76d015b4a1b18abebd8f5
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")));
400 else
402 ui.configTTSstatus->setText(tr("Configuration INVALID"));
403 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
406 delete tts; /* Config objects are never deleted (in fact, they are leaked..), so we can't rely on QObject,
407 since that would delete the TTSBase instance on application exit*/
410 void Config::updateEncState()
412 if(ui.treeDevices->selectedItems().size() == 0)
413 return;
415 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
416 QString encoder = SystemInfo::platformValue(devname,
417 SystemInfo::CurEncoder).toString();
418 ui.encoderName->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname,
419 SystemInfo::CurEncoder).toString()));
421 EncBase* enc = EncBase::getEncoder(this,encoder);
423 if(enc->configOk())
425 ui.configEncstatus->setText(tr("Configuration OK"));
426 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
428 else
430 ui.configEncstatus->setText(tr("Configuration INVALID"));
431 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
436 void Config::setNoProxy(bool checked)
438 bool i = !checked;
439 ui.proxyPort->setEnabled(i);
440 ui.proxyHost->setEnabled(i);
441 ui.proxyUser->setEnabled(i);
442 ui.proxyPass->setEnabled(i);
446 void Config::setSystemProxy(bool checked)
448 ui.proxyPort->setEnabled(!checked);
449 ui.proxyHost->setEnabled(!checked);
450 ui.proxyUser->setEnabled(!checked);
451 ui.proxyPass->setEnabled(!checked);
452 if(checked) {
453 // save values in input box
454 proxy.setScheme("http");
455 proxy.setUserName(ui.proxyUser->text());
456 proxy.setPassword(ui.proxyPass->text());
457 proxy.setHost(ui.proxyHost->text());
458 proxy.setPort(ui.proxyPort->text().toInt());
459 // show system values in input box
460 QUrl envproxy = System::systemProxy();
461 qDebug() << "[Config] setting system proxy" << envproxy;
463 ui.proxyHost->setText(envproxy.host());
464 ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
465 ui.proxyUser->setText(envproxy.userName());
466 ui.proxyPass->setText(envproxy.password());
468 if(envproxy.host().isEmpty() || envproxy.port() == -1) {
469 qDebug() << "[Config] sytem proxy is invalid.";
470 QMessageBox::warning(this, tr("Proxy Detection"),
471 tr("The System Proxy settings are invalid!\n"
472 "Rockbox Utility can't work with this proxy settings. "
473 "Make sure the system proxy is set correctly. Note that "
474 "\"proxy auto-config (PAC)\" scripts are not supported by "
475 "Rockbox Utility. If your system uses this you need "
476 "to use manual proxy settings."),
477 QMessageBox::Ok ,QMessageBox::Ok);
478 // the current proxy settings are invalid. Check the saved proxy
479 // type again.
480 if(RbSettings::value(RbSettings::ProxyType).toString() == "manual")
481 ui.radioManualProxy->setChecked(true);
482 else
483 ui.radioNoProxy->setChecked(true);
487 else {
488 ui.proxyHost->setText(proxy.host());
489 if(proxy.port() > 0)
490 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
491 else ui.proxyPort->setText("");
492 ui.proxyUser->setText(proxy.userName());
493 ui.proxyPass->setText(proxy.password());
499 QStringList Config::findLanguageFiles()
501 QDir dir(programPath);
502 QStringList fileNames;
503 QStringList langs;
504 fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
506 QDir resDir(":/lang");
507 fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
509 QRegExp exp("^rbutil_(.*)\\.qm");
510 for(int i = 0; i < fileNames.size(); i++) {
511 QString a = fileNames.at(i);
512 a.replace(exp, "\\1");
513 langs.append(a);
515 langs.sort();
516 qDebug() << "[Config] available lang files:" << langs;
518 return langs;
522 QString Config::languageName(const QString &qmFile)
524 QTranslator translator;
526 QString file = "rbutil_" + qmFile;
527 if(!translator.load(file, programPath))
528 translator.load(file, ":/lang");
530 return translator.translate("Configure", "English",
531 "This is the localized language name, i.e. your language.");
535 void Config::updateLanguage()
537 qDebug() << "[Config] update selected language";
538 QList<QListWidgetItem*> a = ui.listLanguages->selectedItems();
539 if(a.size() > 0)
540 language = lang.value(a.at(0)->text());
541 qDebug() << "[Config] new language:" << language;
545 void Config::browseFolder()
547 browser = new BrowseDirtree(this,tr("Select your device"));
548 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
549 browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
550 #elif defined(Q_OS_WIN32)
551 browser->setFilter(QDir::Drives);
552 #endif
553 #if defined(Q_OS_MACX)
554 browser->setRoot("/Volumes");
555 #elif defined(Q_OS_LINUX)
556 browser->setDir("/media");
557 #endif
558 if( ui.mountPoint->text() != "" )
560 browser->setDir(ui.mountPoint->text());
562 browser->show();
563 connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
567 void Config::browseCache()
569 QString old = ui.cachePath->text();
570 if(!QFileInfo(old).isDir())
571 old = QDir::tempPath();
572 QString c = QFileDialog::getExistingDirectory(this, tr("Set Cache Path"), old);
573 if(c.isEmpty())
574 c = old;
575 else if(!QFileInfo(c).isDir())
576 c = QDir::tempPath();
577 ui.cachePath->setText(QDir::toNativeSeparators(c));
578 updateCacheInfo(c);
582 void Config::setMountpoint(QString m)
584 ui.mountPoint->setText(m);
588 void Config::autodetect()
590 Autodetection detector(this);
591 // disable tree during detection as "working" feedback.
592 // TODO: replace the tree view with a splash screen during this time.
593 ui.treeDevices->setEnabled(false);
594 this->setCursor(Qt::WaitCursor);
595 QCoreApplication::processEvents();
597 if(detector.detect()) //let it detect
599 QString devicename = detector.getDevice();
600 // deexpand all items
601 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
602 ui.treeDevices->topLevelItem(a)->setExpanded(false);
603 //deselect the selected item(s)
604 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
605 ui.treeDevices->selectedItems().at(a)->setSelected(false);
607 // find the new item
608 // enumerate all platform items
609 QList<QTreeWidgetItem*> itmList
610 = ui.treeDevices->findItems("*",Qt::MatchWildcard);
611 for(int i=0; i< itmList.size();i++)
613 //enumerate device items
614 for(int j=0;j < itmList.at(i)->childCount();j++)
616 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
618 if(devicename == data) // item found
620 itmList.at(i)->child(j)->setSelected(true); //select the item
621 itmList.at(i)->setExpanded(true); //expand the platform item
622 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
623 ui.treeDevices->scrollToItem(itmList.at(i)->child(j));
624 break;
628 this->unsetCursor();
630 if(!detector.errdev().isEmpty()) {
631 QString text;
632 if(detector.errdev() == "sansae200")
633 text = tr("Sansa e200 in MTP mode found!\n"
634 "You need to change your player to MSC mode for installation. ");
635 if(detector.errdev() == "h10")
636 text = tr("H10 20GB in MTP mode found!\n"
637 "You need to change your player to UMS mode for installation. ");
638 if(SystemInfo::platformValue(detector.errdev(),
639 SystemInfo::CurBootloaderMethod) == "ipod")
640 text = tr("%1 \"MacPod\" found!\n"
641 "Rockbox needs a FAT formatted Ipod (so-called \"WinPod\") "
642 "to run. ").arg(SystemInfo::platformValue(
643 detector.errdev(), SystemInfo::CurName).toString());
644 text += tr("Unless you changed this installation will fail!");
646 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
647 return;
649 if(!detector.incompatdev().isEmpty()) {
650 QString text;
651 text = tr("Detected an unsupported player:\n%1\n"
652 "Sorry, Rockbox doesn't run on your player.")
653 .arg(SystemInfo::platformValue(detector.incompatdev(),
654 SystemInfo::CurName).toString());
656 QMessageBox::critical(this, tr("Fatal: player incompatible"),
657 text, QMessageBox::Ok);
658 return;
661 if(detector.getMountPoint() != "" )
663 ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint()));
665 else
667 QMessageBox::warning(this, tr("Autodetection"),
668 tr("Could not detect a Mountpoint.\n"
669 "Select your Mountpoint manually."),
670 QMessageBox::Ok ,QMessageBox::Ok);
673 else
675 this->unsetCursor();
676 QMessageBox::warning(this, tr("Autodetection"),
677 tr("Could not detect a device.\n"
678 "Select your device and Mountpoint manually."),
679 QMessageBox::Ok ,QMessageBox::Ok);
682 ui.treeDevices->setEnabled(true);
686 void Config::cacheClear()
688 if(QMessageBox::critical(this, tr("Really delete cache?"),
689 tr("Do you really want to delete the cache? "
690 "Make absolutely sure this setting is correct as it will "
691 "remove <b>all</b> files in this folder!").arg(ui.cachePath->text()),
692 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
693 return;
695 QString cache = ui.cachePath->text() + "/rbutil-cache/";
696 if(!QFileInfo(cache).isDir()) {
697 QMessageBox::critical(this, tr("Path wrong!"),
698 tr("The cache path is invalid. Aborting."), QMessageBox::Ok);
699 return;
701 QDir dir(cache);
702 QStringList fn;
703 fn = dir.entryList(QStringList("*"), QDir::Files, QDir::Name);
705 for(int i = 0; i < fn.size(); i++) {
706 QString f = cache + fn.at(i);
707 QFile::remove(f);
709 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
713 void Config::configTts()
715 int index = ui.comboTts->currentIndex();
716 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
718 EncTtsCfgGui gui(this,tts,TTSBase::getTTSName(ui.comboTts->itemData(index).toString()));
719 gui.exec();
720 updateTtsState(ui.comboTts->currentIndex());
721 delete tts; /* Config objects are never deleted (in fact, they are leaked..), so we can't rely on QObject,
722 since that would delete the TTSBase instance on application exit*/
725 void Config::testTts()
727 QString errstr;
728 int index = ui.comboTts->currentIndex();
729 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
730 if(!tts->configOk())
732 QMessageBox::warning(this,tr("TTS configuration invalid"),
733 tr("TTS configuration invalid. \n Please configure TTS engine."));
734 return;
737 if(!tts->start(&errstr))
739 QMessageBox::warning(this,tr("Could not start TTS engine."),
740 tr("Could not start TTS engine.\n") + errstr
741 + tr("\nPlease configure TTS engine."));
742 return;
745 QTemporaryFile file(this);
746 file.open();
747 QString filename = file.fileName();
748 file.close();
750 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError)
752 tts->stop();
753 QMessageBox::warning(this,tr("Could not voice test string."),
754 tr("Could not voice test string.\n") + errstr
755 + tr("\nPlease configure TTS engine."));
756 return;
758 tts->stop();
759 #if defined(Q_OS_LINUX)
760 QString exe = Utils::findExecutable("aplay");
761 if(exe == "") exe = Utils::findExecutable("play");
762 if(exe != "")
764 QProcess::execute(exe+" "+filename);
766 #else
767 QSound::play(filename);
768 #endif
770 delete tts; /* Config objects are never deleted (in fact, they are leaked..), so we can't rely on QObject,
771 since that would delete the TTSBase instance on application exit*/
774 void Config::configEnc()
776 if(ui.treeDevices->selectedItems().size() == 0)
777 return;
779 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
780 QString encoder = SystemInfo::platformValue(devname,
781 SystemInfo::CurEncoder).toString();
782 ui.encoderName->setText(EncBase::getEncoderName(SystemInfo::platformValue(devname,
783 SystemInfo::CurEncoder).toString()));
786 EncBase* enc = EncBase::getEncoder(this,encoder);
788 EncTtsCfgGui gui(this,enc,EncBase::getEncoderName(encoder));
789 gui.exec();
791 updateEncState();