svn properties, late as usual
[kugel-rb.git] / rbutil / rbutilqt / configure.cpp
blobb4c71cf32a2118c93c49b111aeac396adae3d309
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 "tts.h"
29 #include "detect.h"
30 #include "encttscfggui.h"
31 #include "rbsettings.h"
32 #include "utils.h"
33 #include <stdio.h>
34 #if defined(Q_OS_WIN32)
35 #if defined(UNICODE)
36 #define _UNICODE
37 #endif
38 #include <tchar.h>
39 #include <windows.h>
40 #endif
42 #define DEFAULT_LANG "English (en)"
43 #define DEFAULT_LANG_CODE "en"
45 Config::Config(QWidget *parent,int index) : QDialog(parent)
47 programPath = qApp->applicationDirPath() + "/";
48 ui.setupUi(this);
49 ui.tabConfiguration->setCurrentIndex(index);
50 ui.radioManualProxy->setChecked(true);
51 QRegExpValidator *proxyValidator = new QRegExpValidator(this);
52 QRegExp validate("[0-9]*");
53 proxyValidator->setRegExp(validate);
54 ui.proxyPort->setValidator(proxyValidator);
55 #if !defined(Q_OS_LINUX) && !defined(Q_OS_WIN32)
56 ui.radioSystemProxy->setEnabled(false); // not on macox for now
57 #endif
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 this->setModal(true);
76 connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
77 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
78 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
79 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
80 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
81 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
82 connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
83 connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
84 connect(ui.configTts, SIGNAL(clicked()), this, SLOT(configTts()));
85 connect(ui.configEncoder, SIGNAL(clicked()), this, SLOT(configEnc()));
86 connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
87 connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
88 connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
89 setUserSettings();
90 setDevices();
93 void Config::accept()
95 qDebug() << "[Config] checking configuration";
96 QString errormsg = tr("The following errors occurred:") + "<ul>";
97 bool error = false;
99 // proxy: save entered proxy values, not displayed.
100 if(ui.radioManualProxy->isChecked()) {
101 proxy.setScheme("http");
102 proxy.setUserName(ui.proxyUser->text());
103 proxy.setPassword(ui.proxyPass->text());
104 proxy.setHost(ui.proxyHost->text());
105 proxy.setPort(ui.proxyPort->text().toInt());
108 RbSettings::setValue(RbSettings::Proxy, proxy.toString());
109 qDebug() << "[Config] setting proxy to:" << proxy;
110 // proxy type
111 QString proxyType;
112 if(ui.radioNoProxy->isChecked()) proxyType = "none";
113 else if(ui.radioSystemProxy->isChecked()) proxyType = "system";
114 else proxyType = "manual";
115 RbSettings::setValue(RbSettings::ProxyType, proxyType);
117 // language
118 if(RbSettings::value(RbSettings::Language).toString() != language && !language.isEmpty()) {
119 QMessageBox::information(this, tr("Language changed"),
120 tr("You need to restart the application for the changed language to take effect."));
121 RbSettings::setValue(RbSettings::Language, language);
124 // mountpoint
125 QString mp = ui.mountPoint->text();
126 if(mp.isEmpty()) {
127 errormsg += "<li>" + tr("No mountpoint given") + "</li>";
128 error = true;
130 else if(!QFileInfo(mp).exists()) {
131 errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>";
132 error = true;
134 else if(!QFileInfo(mp).isDir()) {
135 errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>";
136 error = true;
138 else if(!QFileInfo(mp).isWritable()) {
139 errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>";
140 error = true;
142 else {
143 RbSettings::setValue(RbSettings::Mountpoint, QDir::fromNativeSeparators(mp));
146 // platform
147 QString nplat;
148 if(ui.treeDevices->selectedItems().size() != 0) {
149 nplat = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
150 RbSettings::setValue(RbSettings::Platform, nplat);
152 else {
153 errormsg += "<li>" + tr("No player selected") + "</li>";
154 error = true;
157 // cache settings
158 if(QFileInfo(ui.cachePath->text()).isDir()) {
159 if(!QFileInfo(ui.cachePath->text()).isWritable()) {
160 errormsg += "<li>" + tr("Cache path not writeable. Leave path empty "
161 "to default to systems temporary path.") + "</li>";
162 error = true;
164 else
165 RbSettings::setValue(RbSettings::CachePath, ui.cachePath->text());
167 else // default to system temp path
168 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
169 RbSettings::setValue(RbSettings::CacheDisabled, ui.cacheDisable->isChecked());
170 RbSettings::setValue(RbSettings::CacheOffline, ui.cacheOfflineMode->isChecked());
172 // tts settings
173 int i = ui.comboTts->currentIndex();
174 RbSettings::setValue(RbSettings::Tts, ui.comboTts->itemData(i).toString());
176 RbSettings::setValue(RbSettings::RbutilVersion, PUREVERSION);
178 errormsg += "</ul>";
179 errormsg += tr("You need to fix the above errors before you can continue.");
181 if(error) {
182 QMessageBox::critical(this, tr("Configuration error"), errormsg);
184 else {
185 // sync settings
186 RbSettings::sync();
187 this->close();
188 emit settingsUpdated();
193 void Config::abort()
195 qDebug() << "[Config] aborted.";
196 this->close();
199 void Config::setUserSettings()
201 // set proxy
202 proxy = RbSettings::value(RbSettings::Proxy).toString();
204 if(proxy.port() > 0)
205 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
206 else ui.proxyPort->setText("");
207 ui.proxyHost->setText(proxy.host());
208 ui.proxyUser->setText(proxy.userName());
209 ui.proxyPass->setText(proxy.password());
211 QString proxyType = RbSettings::value(RbSettings::ProxyType).toString();
212 if(proxyType == "manual") ui.radioManualProxy->setChecked(true);
213 else if(proxyType == "system") ui.radioSystemProxy->setChecked(true);
214 else ui.radioNoProxy->setChecked(true);
216 // set language selection
217 QList<QListWidgetItem*> a;
218 QString b;
219 // find key for lang value
220 QMap<QString, QString>::const_iterator i = lang.constBegin();
221 QString l = RbSettings::value(RbSettings::Language).toString();
222 if(l.isEmpty())
223 l = QLocale::system().name();
224 while (i != lang.constEnd()) {
225 if(i.value() == l) {
226 b = i.key();
227 break;
229 else if(l.startsWith(i.value(), Qt::CaseInsensitive)) {
230 // check if there is a base language (en -> en_US, etc.)
231 b = i.key();
232 break;
234 i++;
236 a = ui.listLanguages->findItems(b, Qt::MatchExactly);
237 if(a.size() > 0)
238 ui.listLanguages->setCurrentItem(a.at(0));
239 // don't connect before language list has been set up to prevent
240 // triggering the signal by selecting the saved language.
241 connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
243 // devices tab
244 ui.mountPoint->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint).toString()));
246 // cache tab
247 if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir())
248 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
249 ui.cachePath->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::CachePath).toString()));
250 ui.cacheDisable->setChecked(RbSettings::value(RbSettings::CacheDisabled).toBool());
251 ui.cacheOfflineMode->setChecked(RbSettings::value(RbSettings::CacheOffline).toBool());
252 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
256 void Config::updateCacheInfo(QString path)
258 QList<QFileInfo> fs;
259 fs = QDir(path + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
260 qint64 sz = 0;
261 for(int i = 0; i < fs.size(); i++) {
262 sz += fs.at(i).size();
264 ui.cacheSize->setText(tr("Current cache size is %L1 kiB.")
265 .arg(sz/1024));
269 void Config::setDevices()
272 // setup devices table
273 qDebug() << "[Config] setting up devices list";
275 QStringList platformList = RbSettings::platforms();
277 QMap <QString, QString> manuf;
278 QMap <QString, QString> devcs;
279 for(int it = 0; it < platformList.size(); it++)
281 QString curname = RbSettings::name(platformList.at(it));
282 QString curbrand = RbSettings::brand(platformList.at(it));
283 manuf.insertMulti(curbrand, platformList.at(it));
284 devcs.insert(platformList.at(it), curname);
287 QString platform;
288 platform = devcs.value(RbSettings::value(RbSettings::Platform).toString());
290 // set up devices table
291 ui.treeDevices->header()->hide();
292 ui.treeDevices->expandAll();
293 ui.treeDevices->setColumnCount(1);
294 QList<QTreeWidgetItem *> items;
296 // get manufacturers
297 QStringList brands = manuf.uniqueKeys();
298 QTreeWidgetItem *w;
299 QTreeWidgetItem *w2;
300 QTreeWidgetItem *w3 = 0;
301 for(int c = 0; c < brands.size(); c++) {
302 w = new QTreeWidgetItem();
303 w->setFlags(Qt::ItemIsEnabled);
304 w->setText(0, brands.at(c));
305 items.append(w);
307 // go through platforms again for sake of order
308 for(int it = 0; it < platformList.size(); it++) {
310 QString curname = RbSettings::name(platformList.at(it));
311 QString curbrand = RbSettings::brand(platformList.at(it));
313 if(curbrand != brands.at(c)) continue;
314 qDebug() << "[Config] add supported device:" << brands.at(c) << curname;
315 w2 = new QTreeWidgetItem(w, QStringList(curname));
316 w2->setData(0, Qt::UserRole, platformList.at(it));
318 if(platform.contains(curname)) {
319 w2->setSelected(true);
320 w->setExpanded(true);
321 w3 = w2; // save pointer to hilight old selection
323 items.append(w2);
326 ui.treeDevices->insertTopLevelItems(0, items);
327 if(w3 != 0)
328 ui.treeDevices->setCurrentItem(w3); // hilight old selection
330 // tts / encoder tab
332 //encoders
333 updateEncState();
335 //tts
336 QStringList ttslist = TTSBase::getTTSList();
337 for(int a = 0; a < ttslist.size(); a++)
338 ui.comboTts->addItem(TTSBase::getTTSName(ttslist.at(a)), ttslist.at(a));
339 //update index of combobox
340 int index = ui.comboTts->findData(RbSettings::value(RbSettings::Tts).toString());
341 if(index < 0) index = 0;
342 ui.comboTts->setCurrentIndex(index);
343 updateTtsState(index);
348 void Config::updateTtsState(int index)
350 QString ttsName = ui.comboTts->itemData(index).toString();
351 TTSBase* tts = TTSBase::getTTS(this,ttsName);
353 if(tts->configOk())
355 ui.configTTSstatus->setText(tr("Configuration OK"));
356 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
358 else
360 ui.configTTSstatus->setText(tr("Configuration INVALID"));
361 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
365 void Config::updateEncState()
367 // FIXME: this is a workaround to make the encoder follow the device selection
368 // even with the settings (and thus the device) being saved. Needs to be redone
369 // properly later by extending the settings object
370 if(ui.treeDevices->selectedItems().size() == 0)
371 return;
373 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
374 QString olddevice = RbSettings::value(RbSettings::Platform).toString();
375 RbSettings::setValue(RbSettings::Platform, devname);
376 QString encoder = RbSettings::value(RbSettings::CurEncoder).toString();
377 ui.encoderName->setText(EncBase::getEncoderName(RbSettings::value(RbSettings::CurEncoder).toString()));
378 RbSettings::setValue(RbSettings::Platform, olddevice);
380 EncBase* enc = EncBase::getEncoder(this,encoder);
382 if(enc->configOk())
384 ui.configEncstatus->setText(tr("Configuration OK"));
385 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
387 else
389 ui.configEncstatus->setText(tr("Configuration INVALID"));
390 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
394 void Config::setNoProxy(bool checked)
396 bool i = !checked;
397 ui.proxyPort->setEnabled(i);
398 ui.proxyHost->setEnabled(i);
399 ui.proxyUser->setEnabled(i);
400 ui.proxyPass->setEnabled(i);
404 void Config::setSystemProxy(bool checked)
406 bool i = !checked;
407 ui.proxyPort->setEnabled(i);
408 ui.proxyHost->setEnabled(i);
409 ui.proxyUser->setEnabled(i);
410 ui.proxyPass->setEnabled(i);
411 if(checked) {
412 // save values in input box
413 proxy.setScheme("http");
414 proxy.setUserName(ui.proxyUser->text());
415 proxy.setPassword(ui.proxyPass->text());
416 proxy.setHost(ui.proxyHost->text());
417 proxy.setPort(ui.proxyPort->text().toInt());
418 // show system values in input box
419 QUrl envproxy = Detect::systemProxy();
421 ui.proxyHost->setText(envproxy.host());
423 ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
424 ui.proxyUser->setText(envproxy.userName());
425 ui.proxyPass->setText(envproxy.password());
428 else {
429 ui.proxyHost->setText(proxy.host());
430 if(proxy.port() > 0)
431 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
432 else ui.proxyPort->setText("");
433 ui.proxyUser->setText(proxy.userName());
434 ui.proxyPass->setText(proxy.password());
440 QStringList Config::findLanguageFiles()
442 QDir dir(programPath);
443 QStringList fileNames;
444 QStringList langs;
445 fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
447 QDir resDir(":/lang");
448 fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
450 QRegExp exp("^rbutil_(.*)\\.qm");
451 for(int i = 0; i < fileNames.size(); i++) {
452 QString a = fileNames.at(i);
453 a.replace(exp, "\\1");
454 langs.append(a);
456 langs.sort();
457 qDebug() << "[Config] available lang files:" << langs;
459 return langs;
463 QString Config::languageName(const QString &qmFile)
465 QTranslator translator;
467 QString file = "rbutil_" + qmFile;
468 if(!translator.load(file, programPath))
469 translator.load(file, ":/lang");
471 return translator.translate("Configure", "English",
472 "This is the localized language name, i.e. your language.");
476 void Config::updateLanguage()
478 qDebug() << "[Config] update selected language";
479 QList<QListWidgetItem*> a = ui.listLanguages->selectedItems();
480 if(a.size() > 0)
481 language = lang.value(a.at(0)->text());
482 qDebug() << "[Config] new language:" << language;
486 void Config::browseFolder()
488 browser = new BrowseDirtree(this,tr("Select your device"));
489 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
490 browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
491 #elif defined(Q_OS_WIN32)
492 browser->setFilter(QDir::Drives);
493 #endif
494 #if defined(Q_OS_MACX)
495 browser->setRoot("/Volumes");
496 #elif defined(Q_OS_LINUX)
497 browser->setDir("/media");
498 #endif
499 if( ui.mountPoint->text() != "" )
501 browser->setDir(ui.mountPoint->text());
503 browser->show();
504 connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
508 void Config::browseCache()
510 cbrowser = new BrowseDirtree(this);
511 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
512 cbrowser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
513 #elif defined(Q_OS_WIN32)
514 cbrowser->setFilter(QDir::Drives | QDir::AllDirs | QDir::NoDotAndDotDot);
515 #endif
516 cbrowser->setDir(ui.cachePath->text());
517 connect(cbrowser, SIGNAL(itemChanged(QString)), this, SLOT(setCache(QString)));
518 cbrowser->show();
522 void Config::setMountpoint(QString m)
524 ui.mountPoint->setText(m);
528 void Config::setCache(QString c)
530 ui.cachePath->setText(c);
531 updateCacheInfo(c);
535 void Config::autodetect()
537 Autodetection detector(this);
538 // disable tree during detection as "working" feedback.
539 // TODO: replace the tree view with a splash screen during this time.
540 ui.treeDevices->setEnabled(false);
541 this->setCursor(Qt::WaitCursor);
542 QCoreApplication::processEvents();
544 if(detector.detect()) //let it detect
546 QString devicename = detector.getDevice();
547 // deexpand all items
548 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
549 ui.treeDevices->topLevelItem(a)->setExpanded(false);
550 //deselect the selected item(s)
551 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
552 ui.treeDevices->selectedItems().at(a)->setSelected(false);
554 // find the new item
555 // enumerate all platform items
556 QList<QTreeWidgetItem*> itmList= ui.treeDevices->findItems("*",Qt::MatchWildcard);
557 for(int i=0; i< itmList.size();i++)
559 //enumerate device items
560 for(int j=0;j < itmList.at(i)->childCount();j++)
562 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
564 if(devicename == data) // item found
566 itmList.at(i)->child(j)->setSelected(true); //select the item
567 itmList.at(i)->setExpanded(true); //expand the platform item
568 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
569 break;
573 this->unsetCursor();
575 if(!detector.errdev().isEmpty()) {
576 QString text;
577 if(detector.errdev() == "sansae200")
578 text = tr("Sansa e200 in MTP mode found!\n"
579 "You need to change your player to MSC mode for installation. ");
580 if(detector.errdev() == "h10")
581 text = tr("H10 20GB in MTP mode found!\n"
582 "You need to change your player to UMS mode for installation. ");
583 text += tr("Unless you changed this installation will fail!");
585 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
586 return;
588 if(!detector.incompatdev().isEmpty()) {
589 QString text;
590 // we need to set the platform here to get the brand from the
591 // settings object
592 RbSettings::setValue(RbSettings::Platform, detector.incompatdev());
593 text = tr("Detected an unsupported %1 player variant. Sorry, "
594 "Rockbox doesn't run on your player.")
595 .arg(RbSettings::value(RbSettings::CurBrand).toString());
597 QMessageBox::critical(this, tr("Fatal error: incompatible player found"),
598 text, QMessageBox::Ok);
599 return;
602 if(detector.getMountPoint() != "" )
604 ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint()));
606 else
608 QMessageBox::warning(this, tr("Autodetection"),
609 tr("Could not detect a Mountpoint.\n"
610 "Select your Mountpoint manually."),
611 QMessageBox::Ok ,QMessageBox::Ok);
614 else
616 this->unsetCursor();
617 QMessageBox::warning(this, tr("Autodetection"),
618 tr("Could not detect a device.\n"
619 "Select your device and Mountpoint manually."),
620 QMessageBox::Ok ,QMessageBox::Ok);
623 ui.treeDevices->setEnabled(true);
626 void Config::cacheClear()
628 if(QMessageBox::critical(this, tr("Really delete cache?"),
629 tr("Do you really want to delete the cache? "
630 "Make absolutely sure this setting is correct as it will "
631 "remove <b>all</b> files in this folder!").arg(ui.cachePath->text()),
632 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
633 return;
635 QString cache = ui.cachePath->text() + "/rbutil-cache/";
636 if(!QFileInfo(cache).isDir()) {
637 QMessageBox::critical(this, tr("Path wrong!"),
638 tr("The cache path is invalid. Aborting."), QMessageBox::Ok);
639 return;
641 QDir dir(cache);
642 QStringList fn;
643 fn = dir.entryList(QStringList("*"), QDir::Files, QDir::Name);
645 for(int i = 0; i < fn.size(); i++) {
646 QString f = cache + fn.at(i);
647 QFile::remove(f);
649 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
653 void Config::configTts()
655 int index = ui.comboTts->currentIndex();
656 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
658 EncTtsCfgGui gui(this,tts,TTSBase::getTTSName(ui.comboTts->itemData(index).toString()));
659 gui.exec();
660 updateTtsState(ui.comboTts->currentIndex());
663 void Config::testTts()
665 QString errstr;
666 int index = ui.comboTts->currentIndex();
667 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
668 if(!tts->configOk())
670 QMessageBox::warning(this,tr("TTS configuration invalid"),tr("TTS configuration invalid. \n Please configure TTS engine."));
671 return;
674 if(!tts->start(&errstr))
676 QMessageBox::warning(this,tr("Could not start TTS engine"),tr("Could not start TTS engine.\n") + errstr
677 +tr("\nPlease configure TTS engine."));
678 return;
681 QTemporaryFile file(this);
682 file.open();
683 QString filename = file.fileName();
684 file.close();
686 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError)
688 tts->stop();
689 QMessageBox::warning(this,tr("Could not voice test string"),tr("Could not voice test string.\n") + errstr
690 +tr("\nPlease configure TTS engine."));
691 return;
693 tts->stop();
694 #if defined(Q_OS_LINUX)
695 QString exe = findExecutable("aplay");
696 if(exe == "") exe = findExecutable("play");
697 if(exe != "")
699 QProcess::execute(exe+" "+filename);
701 #else
702 QSound::play(filename);
703 #endif
706 void Config::configEnc()
708 // FIXME: this is a workaround to make the encoder follow the device selection
709 // even with the settings (and thus the device) being saved. Needs to be redone
710 // properly later by extending the settings object
711 if(ui.treeDevices->selectedItems().size() == 0)
712 return;
714 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
715 QString olddevice = RbSettings::value(RbSettings::CurrentPlatform).toString();
716 RbSettings::setValue(RbSettings::CurrentPlatform,devname);
717 QString encoder = RbSettings::value(RbSettings::CurEncoder).toString();
718 ui.encoderName->setText(EncBase::getEncoderName(RbSettings::value(RbSettings::CurEncoder).toString()));
719 RbSettings::setValue(RbSettings::CurrentPlatform,olddevice);
722 EncBase* enc = EncBase::getEncoder(this,encoder);
724 EncTtsCfgGui gui(this,enc,EncBase::getEncoderName(encoder));
725 gui.exec();
727 updateEncState();