summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/ttsgui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/ttsgui.cpp')
-rw-r--r--rbutil/rbutilqt/ttsgui.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/ttsgui.cpp b/rbutil/rbutilqt/ttsgui.cpp
index 0a59b25d86..45dd3a86ef 100644
--- a/rbutil/rbutilqt/ttsgui.cpp
+++ b/rbutil/rbutilqt/ttsgui.cpp
@@ -181,3 +181,159 @@ void TTSExesGui::browse()
181 } 181 }
182} 182}
183 183
184TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) :
185 QDialog(parent), festival(api)
186{
187 ui.setupUi(this);
188 this->setModal(true);
189 this->setDisabled(true);
190 this->show();
191
192 connect(ui.clientButton, SIGNAL(clicked()), this, SLOT(onBrowseClient()));
193 connect(ui.serverButton, SIGNAL(clicked()), this, SLOT(onBrowseServer()));
194
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)));
198}
199
200void TTSFestivalGui::showCfg()
201{
202 qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n"
203 << "\tvoice: " << settings->ttsVoice("festival");
204
205 // will populate the voices if the paths are correct,
206 // otherwise, it will require the user to press Refresh
207 updateVoices();
208
209 // try to get config from settings
210 QStringList paths = settings->ttsPath("festival").split(":");
211 if(paths.size() == 2)
212 {
213 ui.serverPath->setText(paths[0]);
214 ui.clientPath->setText(paths[1]);
215 }
216
217 this->setEnabled(true);
218 this->exec();
219}
220
221void TTSFestivalGui::accept(void)
222{
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());
228
229 settings->sync();
230
231 this->done(0);
232}
233
234void TTSFestivalGui::reject(void)
235{
236 this->done(0);
237}
238
239void TTSFestivalGui::onBrowseClient()
240{
241 BrowseDirtree browser(this);
242 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
243
244 QFileInfo currentPath(ui.clientPath->text().trimmed());
245 if(currentPath.isDir())
246 {
247 browser.setDir(ui.clientPath->text());
248 }
249 else if (currentPath.isFile())
250 {
251 browser.setDir(currentPath.dir().absolutePath());
252 }
253 if(browser.exec() == QDialog::Accepted)
254 {
255 qDebug() << browser.getSelected();
256 QString exe = browser.getSelected();
257 if(!QFileInfo(exe).isExecutable())
258 return;
259 ui.clientPath->setText(exe);
260 }
261}
262
263void TTSFestivalGui::onBrowseServer()
264{
265 BrowseDirtree browser(this);
266 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
267
268 QFileInfo currentPath(ui.serverPath->text().trimmed());
269 if(currentPath.isDir())
270 {
271 browser.setDir(ui.serverPath->text());
272 }
273 else if (currentPath.isFile())
274 {
275 browser.setDir(currentPath.dir().absolutePath());
276 }
277 if(browser.exec() == QDialog::Accepted)
278 {
279 qDebug() << browser.getSelected();
280 QString exe = browser.getSelected();
281 if(!QFileInfo(exe).isExecutable())
282 return;
283 ui.serverPath->setText(exe);
284 }
285}
286
287void TTSFestivalGui::onRefreshButton()
288{
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);
293
294 if(newPath != oldPath)
295 {
296 qDebug() << "Using new paths for getVoiceList";
297 settings->setTTSPath("festival", newPath);
298 settings->sync();
299 }
300
301 updateVoices();
302
303 if(newPath != oldPath)
304 {
305 settings->setTTSPath("festival", oldPath);
306 settings->sync();
307 }
308}
309
310void TTSFestivalGui::onShowDescription(int state)
311{
312 if(state == Qt::Unchecked)
313 ui.descriptionLabel->setText("");
314 else
315 updateDescription(ui.voicesBox->currentText());
316}
317
318void TTSFestivalGui::updateVoices()
319{
320 ui.voicesBox->clear();
321 ui.voicesBox->addItem(tr("Loading.."));
322
323 QStringList voiceList = festival->getVoiceList();
324 ui.voicesBox->clear();
325 ui.voicesBox->addItems(voiceList);
326
327 ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival")));
328
329 updateDescription(settings->ttsVoice("festival"));
330}
331
332void TTSFestivalGui::updateDescription(QString value)
333{
334 if(ui.showDescriptionCheckbox->checkState() == Qt::Checked)
335 {
336 ui.descriptionLabel->setText(tr("Querying festival"));
337 ui.descriptionLabel->setText(festival->getVoiceInfo(value));
338 }
339}