Don't set the layout direction twice in a row, one time is enough.
[kugel-rb.git] / rbutil / rbutilqt / configure.cpp
blob3c31ab75ddbce173ab40f680e639320d8b0f1a3d
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 "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 /* 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);
84 this->setModal(true);
86 connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
87 connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(abort()));
88 connect(ui.radioNoProxy, SIGNAL(toggled(bool)), this, SLOT(setNoProxy(bool)));
89 connect(ui.radioSystemProxy, SIGNAL(toggled(bool)), this, SLOT(setSystemProxy(bool)));
90 connect(ui.browseMountPoint, SIGNAL(clicked()), this, SLOT(browseFolder()));
91 connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
92 connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
93 connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
94 connect(ui.configTts, SIGNAL(clicked()), this, SLOT(configTts()));
95 connect(ui.configEncoder, SIGNAL(clicked()), this, SLOT(configEnc()));
96 connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
97 connect(ui.treeDevices, SIGNAL(itemSelectionChanged()), this, SLOT(updateEncState()));
98 connect(ui.testTTS,SIGNAL(clicked()),this,SLOT(testTts()));
99 setUserSettings();
100 setDevices();
104 void Config::accept()
106 qDebug() << "[Config] checking configuration";
107 QString errormsg = tr("The following errors occurred:") + "<ul>";
108 bool error = false;
110 // proxy: save entered proxy values, not displayed.
111 if(ui.radioManualProxy->isChecked()) {
112 proxy.setScheme("http");
113 proxy.setUserName(ui.proxyUser->text());
114 proxy.setPassword(ui.proxyPass->text());
115 proxy.setHost(ui.proxyHost->text());
116 proxy.setPort(ui.proxyPort->text().toInt());
119 RbSettings::setValue(RbSettings::Proxy, proxy.toString());
120 qDebug() << "[Config] setting proxy to:" << proxy;
121 // proxy type
122 QString proxyType;
123 if(ui.radioNoProxy->isChecked()) proxyType = "none";
124 else if(ui.radioSystemProxy->isChecked()) proxyType = "system";
125 else proxyType = "manual";
126 RbSettings::setValue(RbSettings::ProxyType, proxyType);
128 // language
129 if(RbSettings::value(RbSettings::Language).toString() != language
130 && !language.isEmpty()) {
131 QMessageBox::information(this, tr("Language changed"),
132 tr("You need to restart the application for the changed language to take effect."));
133 RbSettings::setValue(RbSettings::Language, language);
136 // mountpoint
137 QString mp = ui.mountPoint->text();
138 if(mp.isEmpty()) {
139 errormsg += "<li>" + tr("No mountpoint given") + "</li>";
140 error = true;
142 else if(!QFileInfo(mp).exists()) {
143 errormsg += "<li>" + tr("Mountpoint does not exist") + "</li>";
144 error = true;
146 else if(!QFileInfo(mp).isDir()) {
147 errormsg += "<li>" + tr("Mountpoint is not a directory.") + "</li>";
148 error = true;
150 else if(!QFileInfo(mp).isWritable()) {
151 errormsg += "<li>" + tr("Mountpoint is not writeable") + "</li>";
152 error = true;
154 else {
155 RbSettings::setValue(RbSettings::Mountpoint, QDir::fromNativeSeparators(mp));
158 // platform
159 QString nplat;
160 if(ui.treeDevices->selectedItems().size() != 0) {
161 nplat = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
162 RbSettings::setValue(RbSettings::Platform, nplat);
164 else {
165 errormsg += "<li>" + tr("No player selected") + "</li>";
166 error = true;
169 // cache settings
170 if(QFileInfo(ui.cachePath->text()).isDir()) {
171 if(!QFileInfo(ui.cachePath->text()).isWritable()) {
172 errormsg += "<li>" + tr("Cache path not writeable. Leave path empty "
173 "to default to systems temporary path.") + "</li>";
174 error = true;
176 else
177 RbSettings::setValue(RbSettings::CachePath, ui.cachePath->text());
179 else // default to system temp path
180 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
181 RbSettings::setValue(RbSettings::CacheDisabled, ui.cacheDisable->isChecked());
182 RbSettings::setValue(RbSettings::CacheOffline, ui.cacheOfflineMode->isChecked());
184 // tts settings
185 int i = ui.comboTts->currentIndex();
186 RbSettings::setValue(RbSettings::Tts, ui.comboTts->itemData(i).toString());
188 RbSettings::setValue(RbSettings::RbutilVersion, PUREVERSION);
190 errormsg += "</ul>";
191 errormsg += tr("You need to fix the above errors before you can continue.");
193 if(error) {
194 QMessageBox::critical(this, tr("Configuration error"), errormsg);
196 else {
197 // sync settings
198 RbSettings::sync();
199 this->close();
200 emit settingsUpdated();
205 void Config::abort()
207 qDebug() << "[Config] aborted.";
208 this->close();
212 void Config::setUserSettings()
214 // set proxy
215 proxy = RbSettings::value(RbSettings::Proxy).toString();
217 if(proxy.port() > 0)
218 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
219 else ui.proxyPort->setText("");
220 ui.proxyHost->setText(proxy.host());
221 ui.proxyUser->setText(proxy.userName());
222 ui.proxyPass->setText(proxy.password());
224 QString proxyType = RbSettings::value(RbSettings::ProxyType).toString();
225 if(proxyType == "manual") ui.radioManualProxy->setChecked(true);
226 else if(proxyType == "system") ui.radioSystemProxy->setChecked(true);
227 else ui.radioNoProxy->setChecked(true);
229 // set language selection
230 QList<QListWidgetItem*> a;
231 QString b;
232 // find key for lang value
233 QMap<QString, QString>::const_iterator i = lang.constBegin();
234 QString l = RbSettings::value(RbSettings::Language).toString();
235 if(l.isEmpty())
236 l = QLocale::system().name();
237 while (i != lang.constEnd()) {
238 if(i.value() == l) {
239 b = i.key();
240 break;
242 else if(l.startsWith(i.value(), Qt::CaseInsensitive)) {
243 // check if there is a base language (en -> en_US, etc.)
244 b = i.key();
245 break;
247 i++;
249 a = ui.listLanguages->findItems(b, Qt::MatchExactly);
250 if(a.size() > 0)
251 ui.listLanguages->setCurrentItem(a.at(0));
252 // don't connect before language list has been set up to prevent
253 // triggering the signal by selecting the saved language.
254 connect(ui.listLanguages, SIGNAL(itemSelectionChanged()), this, SLOT(updateLanguage()));
256 // devices tab
257 ui.mountPoint->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::Mountpoint).toString()));
259 // cache tab
260 if(!QFileInfo(RbSettings::value(RbSettings::CachePath).toString()).isDir())
261 RbSettings::setValue(RbSettings::CachePath, QDir::tempPath());
262 ui.cachePath->setText(QDir::toNativeSeparators(RbSettings::value(RbSettings::CachePath).toString()));
263 ui.cacheDisable->setChecked(RbSettings::value(RbSettings::CacheDisabled).toBool());
264 ui.cacheOfflineMode->setChecked(RbSettings::value(RbSettings::CacheOffline).toBool());
265 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
269 void Config::updateCacheInfo(QString path)
271 QList<QFileInfo> fs;
272 fs = QDir(path + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
273 qint64 sz = 0;
274 for(int i = 0; i < fs.size(); i++) {
275 sz += fs.at(i).size();
277 ui.cacheSize->setText(tr("Current cache size is %L1 kiB.")
278 .arg(sz/1024));
282 void Config::setDevices()
285 // setup devices table
286 qDebug() << "[Config] setting up devices list";
288 QStringList platformList = RbSettings::platforms();
290 QMap <QString, QString> manuf;
291 QMap <QString, QString> devcs;
292 for(int it = 0; it < platformList.size(); it++)
294 QString curname = RbSettings::name(platformList.at(it));
295 QString curbrand = RbSettings::brand(platformList.at(it));
296 manuf.insertMulti(curbrand, platformList.at(it));
297 devcs.insert(platformList.at(it), curname);
300 QString platform;
301 platform = devcs.value(RbSettings::value(RbSettings::Platform).toString());
303 // set up devices table
304 ui.treeDevices->header()->hide();
305 ui.treeDevices->expandAll();
306 ui.treeDevices->setColumnCount(1);
307 QList<QTreeWidgetItem *> items;
309 // get manufacturers
310 QStringList brands = manuf.uniqueKeys();
311 QTreeWidgetItem *w;
312 QTreeWidgetItem *w2;
313 QTreeWidgetItem *w3 = 0;
314 for(int c = 0; c < brands.size(); c++) {
315 w = new QTreeWidgetItem();
316 w->setFlags(Qt::ItemIsEnabled);
317 w->setText(0, brands.at(c));
318 items.append(w);
320 // go through platforms again for sake of order
321 for(int it = 0; it < platformList.size(); it++) {
323 QString curname = RbSettings::name(platformList.at(it));
324 QString curbrand = RbSettings::brand(platformList.at(it));
326 if(curbrand != brands.at(c)) continue;
327 qDebug() << "[Config] add supported device:" << brands.at(c) << curname;
328 w2 = new QTreeWidgetItem(w, QStringList(curname));
329 w2->setData(0, Qt::UserRole, platformList.at(it));
331 if(platform.contains(curname)) {
332 w2->setSelected(true);
333 w->setExpanded(true);
334 w3 = w2; // save pointer to hilight old selection
336 items.append(w2);
339 ui.treeDevices->insertTopLevelItems(0, items);
340 if(w3 != 0)
341 ui.treeDevices->setCurrentItem(w3); // hilight old selection
343 // tts / encoder tab
345 //encoders
346 updateEncState();
348 //tts
349 QStringList ttslist = TTSBase::getTTSList();
350 for(int a = 0; a < ttslist.size(); a++)
351 ui.comboTts->addItem(TTSBase::getTTSName(ttslist.at(a)), ttslist.at(a));
352 //update index of combobox
353 int index = ui.comboTts->findData(RbSettings::value(RbSettings::Tts).toString());
354 if(index < 0) index = 0;
355 ui.comboTts->setCurrentIndex(index);
356 updateTtsState(index);
361 void Config::updateTtsState(int index)
363 QString ttsName = ui.comboTts->itemData(index).toString();
364 TTSBase* tts = TTSBase::getTTS(this,ttsName);
366 if(tts->configOk())
368 ui.configTTSstatus->setText(tr("Configuration OK"));
369 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
371 else
373 ui.configTTSstatus->setText(tr("Configuration INVALID"));
374 ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
378 void Config::updateEncState()
380 if(ui.treeDevices->selectedItems().size() == 0)
381 return;
383 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
384 QString encoder = RbSettings::platformValue(devname,
385 RbSettings::CurEncoder).toString();
386 ui.encoderName->setText(EncBase::getEncoderName(RbSettings::platformValue(devname,
387 RbSettings::CurEncoder).toString()));
389 EncBase* enc = EncBase::getEncoder(this,encoder);
391 if(enc->configOk())
393 ui.configEncstatus->setText(tr("Configuration OK"));
394 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/go-next.png")));
396 else
398 ui.configEncstatus->setText(tr("Configuration INVALID"));
399 ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/dialog-error.png")));
404 void Config::setNoProxy(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);
414 void Config::setSystemProxy(bool checked)
416 bool i = !checked;
417 ui.proxyPort->setEnabled(i);
418 ui.proxyHost->setEnabled(i);
419 ui.proxyUser->setEnabled(i);
420 ui.proxyPass->setEnabled(i);
421 if(checked) {
422 // save values in input box
423 proxy.setScheme("http");
424 proxy.setUserName(ui.proxyUser->text());
425 proxy.setPassword(ui.proxyPass->text());
426 proxy.setHost(ui.proxyHost->text());
427 proxy.setPort(ui.proxyPort->text().toInt());
428 // show system values in input box
429 QUrl envproxy = System::systemProxy();
431 ui.proxyHost->setText(envproxy.host());
433 ui.proxyPort->setText(QString("%1").arg(envproxy.port()));
434 ui.proxyUser->setText(envproxy.userName());
435 ui.proxyPass->setText(envproxy.password());
438 else {
439 ui.proxyHost->setText(proxy.host());
440 if(proxy.port() > 0)
441 ui.proxyPort->setText(QString("%1").arg(proxy.port()));
442 else ui.proxyPort->setText("");
443 ui.proxyUser->setText(proxy.userName());
444 ui.proxyPass->setText(proxy.password());
450 QStringList Config::findLanguageFiles()
452 QDir dir(programPath);
453 QStringList fileNames;
454 QStringList langs;
455 fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
457 QDir resDir(":/lang");
458 fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
460 QRegExp exp("^rbutil_(.*)\\.qm");
461 for(int i = 0; i < fileNames.size(); i++) {
462 QString a = fileNames.at(i);
463 a.replace(exp, "\\1");
464 langs.append(a);
466 langs.sort();
467 qDebug() << "[Config] available lang files:" << langs;
469 return langs;
473 QString Config::languageName(const QString &qmFile)
475 QTranslator translator;
477 QString file = "rbutil_" + qmFile;
478 if(!translator.load(file, programPath))
479 translator.load(file, ":/lang");
481 return translator.translate("Configure", "English",
482 "This is the localized language name, i.e. your language.");
486 void Config::updateLanguage()
488 qDebug() << "[Config] update selected language";
489 QList<QListWidgetItem*> a = ui.listLanguages->selectedItems();
490 if(a.size() > 0)
491 language = lang.value(a.at(0)->text());
492 qDebug() << "[Config] new language:" << language;
496 void Config::browseFolder()
498 browser = new BrowseDirtree(this,tr("Select your device"));
499 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
500 browser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
501 #elif defined(Q_OS_WIN32)
502 browser->setFilter(QDir::Drives);
503 #endif
504 #if defined(Q_OS_MACX)
505 browser->setRoot("/Volumes");
506 #elif defined(Q_OS_LINUX)
507 browser->setDir("/media");
508 #endif
509 if( ui.mountPoint->text() != "" )
511 browser->setDir(ui.mountPoint->text());
513 browser->show();
514 connect(browser, SIGNAL(itemChanged(QString)), this, SLOT(setMountpoint(QString)));
518 void Config::browseCache()
520 cbrowser = new BrowseDirtree(this);
521 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
522 cbrowser->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
523 #elif defined(Q_OS_WIN32)
524 cbrowser->setFilter(QDir::Drives | QDir::AllDirs | QDir::NoDotAndDotDot);
525 #endif
526 cbrowser->setDir(ui.cachePath->text());
527 connect(cbrowser, SIGNAL(itemChanged(QString)), this, SLOT(setCache(QString)));
528 cbrowser->show();
533 void Config::setMountpoint(QString m)
535 ui.mountPoint->setText(m);
539 void Config::setCache(QString c)
541 ui.cachePath->setText(c);
542 updateCacheInfo(c);
546 void Config::autodetect()
548 Autodetection detector(this);
549 // disable tree during detection as "working" feedback.
550 // TODO: replace the tree view with a splash screen during this time.
551 ui.treeDevices->setEnabled(false);
552 this->setCursor(Qt::WaitCursor);
553 QCoreApplication::processEvents();
555 if(detector.detect()) //let it detect
557 QString devicename = detector.getDevice();
558 // deexpand all items
559 for(int a = 0; a < ui.treeDevices->topLevelItemCount(); a++)
560 ui.treeDevices->topLevelItem(a)->setExpanded(false);
561 //deselect the selected item(s)
562 for(int a = 0; a < ui.treeDevices->selectedItems().size(); a++)
563 ui.treeDevices->selectedItems().at(a)->setSelected(false);
565 // find the new item
566 // enumerate all platform items
567 QList<QTreeWidgetItem*> itmList= ui.treeDevices->findItems("*",Qt::MatchWildcard);
568 for(int i=0; i< itmList.size();i++)
570 //enumerate device items
571 for(int j=0;j < itmList.at(i)->childCount();j++)
573 QString data = itmList.at(i)->child(j)->data(0, Qt::UserRole).toString();
575 if(devicename == data) // item found
577 itmList.at(i)->child(j)->setSelected(true); //select the item
578 itmList.at(i)->setExpanded(true); //expand the platform item
579 //ui.treeDevices->indexOfTopLevelItem(itmList.at(i)->child(j));
580 break;
584 this->unsetCursor();
586 if(!detector.errdev().isEmpty()) {
587 QString text;
588 if(detector.errdev() == "sansae200")
589 text = tr("Sansa e200 in MTP mode found!\n"
590 "You need to change your player to MSC mode for installation. ");
591 if(detector.errdev() == "h10")
592 text = tr("H10 20GB in MTP mode found!\n"
593 "You need to change your player to UMS mode for installation. ");
594 text += tr("Unless you changed this installation will fail!");
596 QMessageBox::critical(this, tr("Fatal error"), text, QMessageBox::Ok);
597 return;
599 if(!detector.incompatdev().isEmpty()) {
600 QString text;
601 text = tr("Detected an unsupported player:\n%1\n"
602 "Sorry, Rockbox doesn't run on your player.")
603 .arg(RbSettings::platformValue(detector.incompatdev(),
604 RbSettings::CurName).toString());
606 QMessageBox::critical(this, tr("Fatal: player incompatible"),
607 text, QMessageBox::Ok);
608 return;
611 if(detector.getMountPoint() != "" )
613 ui.mountPoint->setText(QDir::toNativeSeparators(detector.getMountPoint()));
615 else
617 QMessageBox::warning(this, tr("Autodetection"),
618 tr("Could not detect a Mountpoint.\n"
619 "Select your Mountpoint manually."),
620 QMessageBox::Ok ,QMessageBox::Ok);
623 else
625 this->unsetCursor();
626 QMessageBox::warning(this, tr("Autodetection"),
627 tr("Could not detect a device.\n"
628 "Select your device and Mountpoint manually."),
629 QMessageBox::Ok ,QMessageBox::Ok);
632 ui.treeDevices->setEnabled(true);
636 void Config::cacheClear()
638 if(QMessageBox::critical(this, tr("Really delete cache?"),
639 tr("Do you really want to delete the cache? "
640 "Make absolutely sure this setting is correct as it will "
641 "remove <b>all</b> files in this folder!").arg(ui.cachePath->text()),
642 QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
643 return;
645 QString cache = ui.cachePath->text() + "/rbutil-cache/";
646 if(!QFileInfo(cache).isDir()) {
647 QMessageBox::critical(this, tr("Path wrong!"),
648 tr("The cache path is invalid. Aborting."), QMessageBox::Ok);
649 return;
651 QDir dir(cache);
652 QStringList fn;
653 fn = dir.entryList(QStringList("*"), QDir::Files, QDir::Name);
655 for(int i = 0; i < fn.size(); i++) {
656 QString f = cache + fn.at(i);
657 QFile::remove(f);
659 updateCacheInfo(RbSettings::value(RbSettings::CachePath).toString());
663 void Config::configTts()
665 int index = ui.comboTts->currentIndex();
666 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
668 EncTtsCfgGui gui(this,tts,TTSBase::getTTSName(ui.comboTts->itemData(index).toString()));
669 gui.exec();
670 updateTtsState(ui.comboTts->currentIndex());
673 void Config::testTts()
675 QString errstr;
676 int index = ui.comboTts->currentIndex();
677 TTSBase* tts = TTSBase::getTTS(this,ui.comboTts->itemData(index).toString());
678 if(!tts->configOk())
680 QMessageBox::warning(this,tr("TTS configuration invalid"),
681 tr("TTS configuration invalid. \n Please configure TTS engine."));
682 return;
685 if(!tts->start(&errstr))
687 QMessageBox::warning(this,tr("Could not start TTS engine."),
688 tr("Could not start TTS engine.\n") + errstr
689 + tr("\nPlease configure TTS engine."));
690 return;
693 QTemporaryFile file(this);
694 file.open();
695 QString filename = file.fileName();
696 file.close();
698 if(tts->voice(tr("Rockbox Utility Voice Test"),filename,&errstr) == FatalError)
700 tts->stop();
701 QMessageBox::warning(this,tr("Could not voice test string."),
702 tr("Could not voice test string.\n") + errstr
703 + tr("\nPlease configure TTS engine."));
704 return;
706 tts->stop();
707 #if defined(Q_OS_LINUX)
708 QString exe = findExecutable("aplay");
709 if(exe == "") exe = findExecutable("play");
710 if(exe != "")
712 QProcess::execute(exe+" "+filename);
714 #else
715 QSound::play(filename);
716 #endif
719 void Config::configEnc()
721 if(ui.treeDevices->selectedItems().size() == 0)
722 return;
724 QString devname = ui.treeDevices->selectedItems().at(0)->data(0, Qt::UserRole).toString();
725 QString encoder = RbSettings::platformValue(devname,
726 RbSettings::CurEncoder).toString();
727 ui.encoderName->setText(EncBase::getEncoderName(RbSettings::platformValue(devname,
728 RbSettings::CurEncoder).toString()));
731 EncBase* enc = EncBase::getEncoder(this,encoder);
733 EncTtsCfgGui gui(this,enc,EncBase::getEncoderName(encoder));
734 gui.exec();
736 updateEncState();