1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QMessageBox>
20 #include "createvoicewindow.h"
21 #include "ui_createvoicefrm.h"
23 #include "configure.h"
24 #include "rbsettings.h"
25 #include "systeminfo.h"
27 CreateVoiceWindow::CreateVoiceWindow(QWidget
*parent
) : QDialog(parent
)
30 voicecreator
= new VoiceFileCreator(this);
32 connect(ui
.change
,SIGNAL(clicked()),this,SLOT(change()));
35 void CreateVoiceWindow::change()
37 // save window settings
40 // call configuration dialog
41 Config
*cw
= new Config(this,4);
42 connect(cw
, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
46 void CreateVoiceWindow::accept()
48 logger
= new ProgressLoggerGui(this);
49 connect(logger
,SIGNAL(closed()),this,SLOT(close()));
54 //configure voicecreator
55 voicecreator
->setMountPoint(RbSettings::value(RbSettings::Mountpoint
).toString());
56 voicecreator
->setLang(ui
.comboLanguage
->itemData(ui
.comboLanguage
->currentIndex()).toString());
57 voicecreator
->setWavtrimThreshold(ui
.wavtrimthreshold
->value());
60 connect(voicecreator
, SIGNAL(done(bool)), logger
, SLOT(setFinished()));
61 connect(voicecreator
, SIGNAL(logItem(QString
, int)), logger
, SLOT(addItem(QString
, int)));
62 connect(voicecreator
, SIGNAL(logProgress(int, int)), logger
, SLOT(setProgress(int, int)));
63 connect(logger
,SIGNAL(aborted()),voicecreator
,SLOT(abort()));
64 voicecreator
->createVoiceFile();
68 /** @brief update displayed settings
70 void CreateVoiceWindow::updateSettings(void)
72 // fill in language combobox
73 QMap
<QString
, QStringList
> languages
= SystemInfo::languages();
75 for(int i
= 0; i
< languages
.keys().size(); i
++) {
76 QString key
= languages
.keys().at(i
);
77 ui
.comboLanguage
->addItem(languages
.value(key
).at(1), languages
.value(key
).at(0));
80 int sel
= ui
.comboLanguage
->findData(
81 RbSettings::value(RbSettings::VoiceLanguage
).toString());
82 // if no saved language is found try to figure the language from the UI lang
84 QString uilang
= RbSettings::value(RbSettings::Language
).toString();
85 // if no language is set default to english. Make sure not to check an empty string.
86 QString f
= "english";
87 if(!uilang
.isEmpty() && languages
.contains(uilang
)) {
88 f
= languages
.value(uilang
).at(0);
90 sel
= ui
.comboLanguage
->findData(f
);
91 qDebug() << "[CreateVoiceWindow] Selected language index:" << sel
;
93 ui
.comboLanguage
->setCurrentIndex(sel
);
95 QString ttsName
= RbSettings::value(RbSettings::Tts
).toString();
96 TTSBase
* tts
= TTSBase::getTTS(this,ttsName
);
99 QMessageBox::critical(this, tr("TTS error"),
100 tr("The selected TTS failed to initialize. You can't use this TTS."));
104 ui
.labelTtsProfile
->setText(tr("Engine: <b>%1</b>")
105 .arg(TTSBase::getTTSName(ttsName
)));
107 ui
.labelTtsProfile
->setText(tr("Engine: <b>%1</b>")
108 .arg("Invalid TTS configuration!"));
110 ui
.wavtrimthreshold
->setValue(RbSettings::value(RbSettings::WavtrimThreshold
).toInt());
111 emit
settingsUpdated();
115 /** @brief save options
117 void CreateVoiceWindow::saveSettings(void)
119 // save selected language
120 RbSettings::setValue(RbSettings::VoiceLanguage
,
121 ui
.comboLanguage
->itemData(ui
.comboLanguage
->currentIndex()).toString());
122 // save wavtrim threshold value
123 RbSettings::setValue(RbSettings::WavtrimThreshold
,
124 ui
.wavtrimthreshold
->value());
128 void CreateVoiceWindow::changeEvent(QEvent
*e
)
130 if(e
->type() == QEvent::LanguageChange
) {
131 ui
.retranslateUi(this);
134 QWidget::changeEvent(e
);