rbutil: commit FS#9983 by Delyan Kratunov. It adds support for the Festival TTS on...
[kugel-rb.git] / rbutil / rbutilqt / ttsgui.cpp
blob45dd3a86ef1b96d8e8f6eacd01b7372fe41dbbb9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
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 "ttsgui.h"
22 #include "rbsettings.h"
23 #include "tts.h"
24 #include "browsedirtree.h"
26 TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent)
28 m_sapi= sapi;
29 ui.setupUi(this);
30 this->hide();
31 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
32 connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString)));
33 connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int)));
36 void TTSSapiGui::showCfg()
38 // try to get config from settings
39 ui.ttsoptions->setText(settings->ttsOptions("sapi"));
40 QString selLang = settings->ttsLang("sapi");
41 QString selVoice = settings->ttsVoice("sapi");
42 ui.speed->setValue(settings->ttsSpeed("sapi"));
43 if(settings->ttsUseSapi4())
44 ui.usesapi4->setCheckState(Qt::Checked);
45 else
46 ui.usesapi4->setCheckState(Qt::Unchecked);
48 // fill in language combobox
49 QStringList languages = settings->allLanguages();
51 languages.sort();
52 ui.languagecombo->clear();
53 ui.languagecombo->addItems(languages);
55 // set saved lang
56 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang));
58 // fill in voice combobox
59 updateVoices(selLang);
61 // set saved lang
62 ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice));
64 //show dialog
65 this->exec();
70 void TTSSapiGui::reset()
72 ui.ttsoptions->setText("");
73 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english"));
78 void TTSSapiGui::accept(void)
80 //save settings in user config
81 settings->setTTSOptions("sapi",ui.ttsoptions->text());
82 settings->setTTSLang("sapi",ui.languagecombo->currentText());
83 settings->setTTSVoice("sapi",ui.voicecombo->currentText());
84 settings->setTTSSpeed("sapi",ui.speed->value());
85 if(ui.usesapi4->checkState() == Qt::Checked)
86 settings->setTTSUseSapi4(true);
87 else
88 settings->setTTSUseSapi4(false);
89 // sync settings
90 settings->sync();
92 this->done(0);
95 void TTSSapiGui::reject(void)
97 this->done(0);
100 void TTSSapiGui::updateVoices(QString language)
102 QStringList Voices = m_sapi->getVoiceList(language);
103 ui.voicecombo->clear();
104 ui.voicecombo->addItems(Voices);
108 void TTSSapiGui::useSapi4Changed(int)
110 if(ui.usesapi4->checkState() == Qt::Checked)
111 settings->setTTSUseSapi4(true);
112 else
113 settings->setTTSUseSapi4(false);
114 // sync settings
115 settings->sync();
116 updateVoices(ui.languagecombo->currentText());
120 TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent)
122 ui.setupUi(this);
123 this->hide();
124 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
125 connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
129 void TTSExesGui::reset()
131 ui.ttspath->setText("");
132 ui.ttsoptions->setText("");
135 void TTSExesGui::showCfg(QString name)
137 m_name = name;
138 // try to get config from settings
139 QString exepath =settings->ttsPath(m_name);
140 ui.ttsoptions->setText(settings->ttsOptions(m_name));
141 ui.ttspath->setText(exepath);
143 //show dialog
144 this->exec();
148 void TTSExesGui::accept(void)
150 //save settings in user config
151 settings->setTTSPath(m_name,ui.ttspath->text());
152 settings->setTTSOptions(m_name,ui.ttsoptions->text());
153 // sync settings
154 settings->sync();
156 this->done(0);
159 void TTSExesGui::reject(void)
161 this->done(0);
165 void TTSExesGui::browse()
167 BrowseDirtree browser(this);
168 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
170 if(QFileInfo(ui.ttspath->text()).isDir())
172 browser.setDir(ui.ttspath->text());
174 if(browser.exec() == QDialog::Accepted)
176 qDebug() << browser.getSelected();
177 QString exe = browser.getSelected();
178 if(!QFileInfo(exe).isExecutable())
179 return;
180 ui.ttspath->setText(exe);
184 TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) :
185 QDialog(parent), festival(api)
187 ui.setupUi(this);
188 this->setModal(true);
189 this->setDisabled(true);
190 this->show();
192 connect(ui.clientButton, SIGNAL(clicked()), this, SLOT(onBrowseClient()));
193 connect(ui.serverButton, SIGNAL(clicked()), this, SLOT(onBrowseServer()));
195 connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(onRefreshButton()));
196 connect(ui.voicesBox, SIGNAL(activated(QString)), this, SLOT(updateDescription(QString)));
197 connect(ui.showDescriptionCheckbox, SIGNAL(stateChanged(int)), this, SLOT(onShowDescription(int)));
200 void TTSFestivalGui::showCfg()
202 qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n"
203 << "\tvoice: " << settings->ttsVoice("festival");
205 // will populate the voices if the paths are correct,
206 // otherwise, it will require the user to press Refresh
207 updateVoices();
209 // try to get config from settings
210 QStringList paths = settings->ttsPath("festival").split(":");
211 if(paths.size() == 2)
213 ui.serverPath->setText(paths[0]);
214 ui.clientPath->setText(paths[1]);
217 this->setEnabled(true);
218 this->exec();
221 void TTSFestivalGui::accept(void)
223 //save settings in user config
224 QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed());
225 qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText();
226 settings->setTTSPath("festival", newPath);
227 settings->setTTSVoice("festival", ui.voicesBox->currentText());
229 settings->sync();
231 this->done(0);
234 void TTSFestivalGui::reject(void)
236 this->done(0);
239 void TTSFestivalGui::onBrowseClient()
241 BrowseDirtree browser(this);
242 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
244 QFileInfo currentPath(ui.clientPath->text().trimmed());
245 if(currentPath.isDir())
247 browser.setDir(ui.clientPath->text());
249 else if (currentPath.isFile())
251 browser.setDir(currentPath.dir().absolutePath());
253 if(browser.exec() == QDialog::Accepted)
255 qDebug() << browser.getSelected();
256 QString exe = browser.getSelected();
257 if(!QFileInfo(exe).isExecutable())
258 return;
259 ui.clientPath->setText(exe);
263 void TTSFestivalGui::onBrowseServer()
265 BrowseDirtree browser(this);
266 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
268 QFileInfo currentPath(ui.serverPath->text().trimmed());
269 if(currentPath.isDir())
271 browser.setDir(ui.serverPath->text());
273 else if (currentPath.isFile())
275 browser.setDir(currentPath.dir().absolutePath());
277 if(browser.exec() == QDialog::Accepted)
279 qDebug() << browser.getSelected();
280 QString exe = browser.getSelected();
281 if(!QFileInfo(exe).isExecutable())
282 return;
283 ui.serverPath->setText(exe);
287 void TTSFestivalGui::onRefreshButton()
289 /* Temporarily commit the settings so that we get the new path when we check for voices */
290 QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed());
291 QString oldPath = settings->ttsPath("festival");
292 qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath);
294 if(newPath != oldPath)
296 qDebug() << "Using new paths for getVoiceList";
297 settings->setTTSPath("festival", newPath);
298 settings->sync();
301 updateVoices();
303 if(newPath != oldPath)
305 settings->setTTSPath("festival", oldPath);
306 settings->sync();
310 void TTSFestivalGui::onShowDescription(int state)
312 if(state == Qt::Unchecked)
313 ui.descriptionLabel->setText("");
314 else
315 updateDescription(ui.voicesBox->currentText());
318 void TTSFestivalGui::updateVoices()
320 ui.voicesBox->clear();
321 ui.voicesBox->addItem(tr("Loading.."));
323 QStringList voiceList = festival->getVoiceList();
324 ui.voicesBox->clear();
325 ui.voicesBox->addItems(voiceList);
327 ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival")));
329 updateDescription(settings->ttsVoice("festival"));
332 void TTSFestivalGui::updateDescription(QString value)
334 if(ui.showDescriptionCheckbox->checkState() == Qt::Checked)
336 ui.descriptionLabel->setText(tr("Querying festival"));
337 ui.descriptionLabel->setText(festival->getVoiceInfo(value));