Fix a bug where the conditional use of %C (i.e. %?C) caused the album art to draw...
[kugel-rb.git] / rbutil / rbutilqt / createvoicewindow.cpp
blobe5514ac3e1c7caf294a6ef9d1bb2c195b1e545e4
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 "createvoicewindow.h"
21 #include "ui_createvoicefrm.h"
23 #include "browsedirtree.h"
24 #include "configure.h"
25 #include "rbsettings.h"
27 CreateVoiceWindow::CreateVoiceWindow(QWidget *parent) : QDialog(parent)
29 ui.setupUi(this);
30 voicecreator = new VoiceFileCreator(this);
31 updateSettings();
32 connect(ui.change,SIGNAL(clicked()),this,SLOT(change()));
35 void CreateVoiceWindow::change()
37 Config *cw = new Config(this,4);
38 connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
39 cw->show();
42 void CreateVoiceWindow::accept()
44 logger = new ProgressLoggerGui(this);
45 connect(logger,SIGNAL(closed()),this,SLOT(close()));
46 logger->show();
48 QString lang = ui.comboLanguage->currentText();
49 int wvThreshold = ui.wavtrimthreshold->value();
51 //safe selected language
52 RbSettings::setValue(RbSettings::Language, lang);
53 RbSettings::setValue(RbSettings::WavtrimThreshold, wvThreshold);
54 RbSettings::sync();
56 //configure voicecreator
57 voicecreator->setMountPoint(RbSettings::value(RbSettings::Mountpoint).toString());
58 voicecreator->setLang(lang);
59 voicecreator->setWavtrimThreshold(wvThreshold);
61 //start creating
62 connect(voicecreator, SIGNAL(done(bool)), logger, SLOT(setFinished()));
63 connect(voicecreator, SIGNAL(logItem(QString, int)), logger, SLOT(addItem(QString, int)));
64 connect(voicecreator, SIGNAL(logProgress(int, int)), logger, SLOT(setProgress(int, int)));
65 connect(logger,SIGNAL(aborted()),voicecreator,SLOT(abort()));
66 voicecreator->createVoiceFile();
70 /** @brief update displayed settings
72 void CreateVoiceWindow::updateSettings(void)
74 // fill in language combobox
75 QStringList languages = RbSettings::languages();
76 languages.sort();
77 ui.comboLanguage->addItems(languages);
78 // set saved lang
79 int sel = ui.comboLanguage->findText(RbSettings::value(RbSettings::VoiceLanguage).toString());
80 // if no saved language is found try to figure the language from the UI lang
81 if(sel == -1) {
82 QString f = RbSettings::value(RbSettings::Language).toString();
83 // if no language is set default to english. Make sure not to check an empty string.
84 if(f.isEmpty()) f = "english";
85 sel = ui.comboLanguage->findText(f, Qt::MatchStartsWith);
86 qDebug() << "sel =" << sel;
87 // still nothing found?
88 if(sel == -1)
89 sel = ui.comboLanguage->findText("english", Qt::MatchStartsWith);
91 ui.comboLanguage->setCurrentIndex(sel);
93 QString ttsName = RbSettings::value(RbSettings::Tts).toString();
94 TTSBase* tts = TTSBase::getTTS(this,ttsName);
95 if(tts->configOk())
96 ui.labelTtsProfile->setText(tr("Selected TTS engine: <b>%1</b>")
97 .arg(TTSBase::getTTSName(ttsName)));
98 else
99 ui.labelTtsProfile->setText(tr("Selected TTS engine: <b>%1</b>")
100 .arg("Invalid TTS configuration!"));
102 QString encoder = RbSettings::value(RbSettings::CurEncoder).toString();
103 // only proceed if encoder setting is set
104 EncBase* enc = EncBase::getEncoder(this,encoder);
105 if(enc != NULL) {
106 if(enc->configOk())
107 ui.labelEncProfile->setText(tr("Selected encoder: <b>%1</b>")
108 .arg(EncBase::getEncoderName(encoder)));
109 else
110 ui.labelEncProfile->setText(tr("Selected encoder: <b>%1</b>")
111 .arg("Invalid encoder configuration!"));
113 else
114 ui.labelEncProfile->setText(tr("Selected encoder: <b>%1</b>")
115 .arg("Invalid encoder configuration!"));
116 ui.wavtrimthreshold->setValue(RbSettings::value(RbSettings::WavtrimThreshold).toInt());
117 emit settingsUpdated();