Index: rbutil/rbutilqt/encoders.cpp =================================================================== --- rbutil/rbutilqt/encoders.cpp (revision 20569) +++ rbutil/rbutilqt/encoders.cpp (working copy) @@ -18,19 +18,18 @@ ****************************************************************************/ #include "encoders.h" +#include "utils.h" -#ifndef CONSOLE -#include "encodersgui.h" -#include "browsedirtree.h" -#else -#include "encodersguicli.h" -#endif +/********************************************************************* +* Encoder Base +**********************************************************************/ +QMap EncBase::encoderList; +EncBase::EncBase(QObject *parent): EncTTsSettingInterface(parent) +{ -QMap EncBase::encoderList; -QMap EncBase::encoderCache; +} - // initialize list of encoders void EncBase::initEncodernamesList() { @@ -51,21 +50,15 @@ // get a specific encoder object EncBase* EncBase::getEncoder(QString encoder) { - // check cache - if(encoderCache.contains(encoder)) - return encoderCache.value(encoder); - EncBase* enc; if(encoder == "lame") { enc = new EncExes(encoder); - encoderCache[encoder] = enc; return enc; } else // rbspeex is default { enc = new EncRbSpeex(); - encoderCache[encoder] = enc; return enc; } } @@ -80,14 +73,6 @@ /********************************************************************* -* Encoder Base -**********************************************************************/ -EncBase::EncBase(QObject *parent): QObject(parent) -{ - -} - -/********************************************************************* * GEneral Exe Encoder **********************************************************************/ EncExes::EncExes(QString name,QObject *parent) : EncBase(parent) @@ -95,8 +80,31 @@ m_name = name; m_TemplateMap["lame"] = "\"%exe\" %options \"%input\" \"%output\""; + } + + +QList EncExes::generateSettings() +{ + settingsList.clear(); + + QString exepath =settings->encoderPath(m_name); + if(exepath == "") exepath = findExecutable(m_name); + + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Path to Encoder:",exepath,EncTTsSetting::eBROWSEBTN)); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Encoder options:",settings->encoderOptions(m_name))); + + return settingsList; +} + +void EncExes::saveSettings() +{ + settings->setEncoderPath(m_name,settingsList.at(0)->current().toString()); + settings->setEncoderOptions(m_name,settingsList.at(1)->current().toString()); + settings->sync(); +} + bool EncExes::start() { m_EncExec = settings->encoderPath(m_name); @@ -130,18 +138,6 @@ } - -void EncExes::showCfg() -{ -#ifndef CONSOLE - EncExesGui gui; -#else - EncExesGuiCli gui; -#endif - gui.setCfg(settings); - gui.showCfg(m_name); -} - bool EncExes::configOk() { QString path = settings->encoderPath(m_name); @@ -152,21 +148,37 @@ return false; } - - /********************************************************************* * RB SPEEX ENCODER **********************************************************************/ EncRbSpeex::EncRbSpeex(QObject *parent) : EncBase(parent) { - defaultQuality = 8.f; - defaultVolume = 1.f; - defaultComplexity = 10; - defaultBand = false; } +QList EncRbSpeex::generateSettings() +{ + settingsList.clear(); + + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eDOUBLE,"Volume:",settings->encoderVolume("rbspeex"),1.0,10.0)); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eDOUBLE,"Quality:",settings->encoderQuality("rbspeex"),0,10.0)); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eINT,"Complexity:",settings->encoderComplexity("rbspeex"),0,10)); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eBOOL,"Use Narrowband:",settings->encoderNarrowband("rbspeex"))); + return settingsList; + +} +void EncRbSpeex::saveSettings() +{ + //save settings in user config + settings->setEncoderVolume("rbspeex",settingsList.at(0)->current().toDouble()); + settings->setEncoderQuality("rbspeex",settingsList.at(1)->current().toDouble()); + settings->setEncoderComplexity("rbspeex",settingsList.at(2)->current().toInt()); + settings->setEncoderNarrowband("rbspeex",settingsList.at(3)->current().toBool()); + + settings->sync(); +} + bool EncRbSpeex::start() { @@ -210,18 +222,6 @@ return true; } - -void EncRbSpeex::showCfg() -{ -#ifndef CONSOLE - EncRbSpeexGui gui; -#else - EncRbSpeexGuiCli gui; -#endif - gui.setCfg(settings); - gui.showCfg(defaultQuality,defaultVolume,defaultComplexity,defaultBand); -} - bool EncRbSpeex::configOk() { bool result=true; Index: rbutil/rbutilqt/encexescfgfrm.ui =================================================================== --- rbutil/rbutilqt/encexescfgfrm.ui (revision 20569) +++ rbutil/rbutilqt/encexescfgfrm.ui (working copy) @@ -1,158 +0,0 @@ - - EncExesCfgFrm - - - - 0 - 0 - 463 - 214 - - - - Configuration - - - - - - Configure Encoder - - - - - - - 0 - 255 - - - - Path to Encoder - - - - - - - - - - - - &Browse - - - - - - - - - Encoder options - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Reset - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Ok - - - :/icons/go-next.png - - - - - - - &Cancel - - - :/icons/process-stop.png - - - - - - - - - - - - - - - - buttonOk - clicked() - EncExesCfgFrm - accept() - - - 253 - 147 - - - 203 - 86 - - - - - buttonCancel - clicked() - EncExesCfgFrm - reject() - - - 352 - 147 - - - 203 - 86 - - - - - Index: rbutil/rbutilqt/ttsgui.cpp =================================================================== --- rbutil/rbutilqt/ttsgui.cpp (revision 20569) +++ rbutil/rbutilqt/ttsgui.cpp (working copy) @@ -1,339 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "ttsgui.h" - -#include "rbsettings.h" -#include "tts.h" -#include "browsedirtree.h" - -TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) -{ - m_sapi= sapi; - ui.setupUi(this); - this->hide(); - connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); - connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString))); - connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int))); -} - -void TTSSapiGui::showCfg() -{ - // try to get config from settings - ui.ttsoptions->setText(settings->ttsOptions("sapi")); - QString selLang = settings->ttsLang("sapi"); - QString selVoice = settings->ttsVoice("sapi"); - ui.speed->setValue(settings->ttsSpeed("sapi")); - if(settings->ttsUseSapi4()) - ui.usesapi4->setCheckState(Qt::Checked); - else - ui.usesapi4->setCheckState(Qt::Unchecked); - - // fill in language combobox - QStringList languages = settings->allLanguages(); - - languages.sort(); - ui.languagecombo->clear(); - ui.languagecombo->addItems(languages); - - // set saved lang - ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang)); - - // fill in voice combobox - updateVoices(selLang); - - // set saved lang - ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); - - //show dialog - this->exec(); - -} - - -void TTSSapiGui::reset() -{ - ui.ttsoptions->setText(""); - ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); -} - - - -void TTSSapiGui::accept(void) -{ - //save settings in user config - settings->setTTSOptions("sapi",ui.ttsoptions->text()); - settings->setTTSLang("sapi",ui.languagecombo->currentText()); - settings->setTTSVoice("sapi",ui.voicecombo->currentText()); - settings->setTTSSpeed("sapi",ui.speed->value()); - if(ui.usesapi4->checkState() == Qt::Checked) - settings->setTTSUseSapi4(true); - else - settings->setTTSUseSapi4(false); - // sync settings - settings->sync(); - - this->done(0); -} - -void TTSSapiGui::reject(void) -{ - this->done(0); -} - -void TTSSapiGui::updateVoices(QString language) -{ - QStringList Voices = m_sapi->getVoiceList(language); - ui.voicecombo->clear(); - ui.voicecombo->addItems(Voices); - -} - -void TTSSapiGui::useSapi4Changed(int) -{ - if(ui.usesapi4->checkState() == Qt::Checked) - settings->setTTSUseSapi4(true); - else - settings->setTTSUseSapi4(false); - // sync settings - settings->sync(); - updateVoices(ui.languagecombo->currentText()); - -} - -TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) -{ - ui.setupUi(this); - this->hide(); - connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); - connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse())); -} - - -void TTSExesGui::reset() -{ - ui.ttspath->setText(""); - ui.ttsoptions->setText(""); -} - -void TTSExesGui::showCfg(QString name) -{ - m_name = name; - // try to get config from settings - QString exepath =settings->ttsPath(m_name); - ui.ttsoptions->setText(settings->ttsOptions(m_name)); - ui.ttspath->setText(exepath); - - //show dialog - this->exec(); - -} - -void TTSExesGui::accept(void) -{ - //save settings in user config - settings->setTTSPath(m_name,ui.ttspath->text()); - settings->setTTSOptions(m_name,ui.ttsoptions->text()); - // sync settings - settings->sync(); - - this->done(0); -} - -void TTSExesGui::reject(void) -{ - this->done(0); -} - - -void TTSExesGui::browse() -{ - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - if(QFileInfo(ui.ttspath->text()).isDir()) - { - browser.setDir(ui.ttspath->text()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.ttspath->setText(exe); - } -} - -TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : - QDialog(parent), festival(api) -{ - ui.setupUi(this); - this->setModal(true); - this->setDisabled(true); - this->show(); - - connect(ui.clientButton, SIGNAL(clicked()), this, SLOT(onBrowseClient())); - connect(ui.serverButton, SIGNAL(clicked()), this, SLOT(onBrowseServer())); - - connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(onRefreshButton())); - connect(ui.voicesBox, SIGNAL(activated(QString)), this, SLOT(updateDescription(QString))); - connect(ui.showDescriptionCheckbox, SIGNAL(stateChanged(int)), this, SLOT(onShowDescription(int))); -} - -void TTSFestivalGui::showCfg() -{ - qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n" - << "\tvoice: " << settings->ttsVoice("festival"); - - // will populate the voices if the paths are correct, - // otherwise, it will require the user to press Refresh - updateVoices(); - - // try to get config from settings - QStringList paths = settings->ttsPath("festival").split(":"); - if(paths.size() == 2) - { - ui.serverPath->setText(paths[0]); - ui.clientPath->setText(paths[1]); - } - - this->setEnabled(true); - this->exec(); -} - -void TTSFestivalGui::accept(void) -{ - //save settings in user config - QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); - qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText(); - settings->setTTSPath("festival", newPath); - settings->setTTSVoice("festival", ui.voicesBox->currentText()); - - settings->sync(); - - this->done(0); -} - -void TTSFestivalGui::reject(void) -{ - this->done(0); -} - -void TTSFestivalGui::onBrowseClient() -{ - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - QFileInfo currentPath(ui.clientPath->text().trimmed()); - if(currentPath.isDir()) - { - browser.setDir(ui.clientPath->text()); - } - else if (currentPath.isFile()) - { - browser.setDir(currentPath.dir().absolutePath()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.clientPath->setText(exe); - } -} - -void TTSFestivalGui::onBrowseServer() -{ - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - QFileInfo currentPath(ui.serverPath->text().trimmed()); - if(currentPath.isDir()) - { - browser.setDir(ui.serverPath->text()); - } - else if (currentPath.isFile()) - { - browser.setDir(currentPath.dir().absolutePath()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.serverPath->setText(exe); - } -} - -void TTSFestivalGui::onRefreshButton() -{ - /* Temporarily commit the settings so that we get the new path when we check for voices */ - QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); - QString oldPath = settings->ttsPath("festival"); - qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath); - - if(newPath != oldPath) - { - qDebug() << "Using new paths for getVoiceList"; - settings->setTTSPath("festival", newPath); - settings->sync(); - } - - updateVoices(); - - if(newPath != oldPath) - { - settings->setTTSPath("festival", oldPath); - settings->sync(); - } -} - -void TTSFestivalGui::onShowDescription(int state) -{ - if(state == Qt::Unchecked) - ui.descriptionLabel->setText(""); - else - updateDescription(ui.voicesBox->currentText()); -} - -void TTSFestivalGui::updateVoices() -{ - ui.voicesBox->clear(); - ui.voicesBox->addItem(tr("Loading..")); - - QStringList voiceList = festival->getVoiceList(); - ui.voicesBox->clear(); - ui.voicesBox->addItems(voiceList); - - ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival"))); - - updateDescription(settings->ttsVoice("festival")); -} - -void TTSFestivalGui::updateDescription(QString value) -{ - if(ui.showDescriptionCheckbox->checkState() == Qt::Checked) - { - ui.descriptionLabel->setText(tr("Querying festival")); - ui.descriptionLabel->setText(festival->getVoiceInfo(value)); - } -} Index: rbutil/rbutilqt/rbsettings.cpp =================================================================== --- rbutil/rbutilqt/rbsettings.cpp (revision 20569) +++ rbutil/rbutilqt/rbsettings.cpp (working copy) @@ -304,7 +304,7 @@ } QString RbSettings::ttsVoice(QString tts) { - return userSettingsGroupGet(tts,"ttsvoice","Microsoft Sam").toString(); + return userSettingsGroupGet(tts,"ttsvoice","").toString(); } int RbSettings::ttsSpeed(QString tts) { Index: rbutil/rbutilqt/encoders.h =================================================================== --- rbutil/rbutilqt/encoders.h (revision 20569) +++ rbutil/rbutilqt/encoders.h (working copy) @@ -25,11 +25,11 @@ #include #include "rbsettings.h" - +#include "encttssettings.h" #include "rbspeex.h" -class EncBase : public QObject +class EncBase : public EncTTsSettingInterface { Q_OBJECT public: @@ -39,18 +39,21 @@ {(void)input; (void)output; return false;} virtual bool start(){return false;} virtual bool stop(){return false;} - virtual void showCfg(){} virtual bool configOk(){return false;} - - void setCfg(RbSettings *sett){settings = sett;} + + //! Child class should fill in the setttingsList + virtual QList generateSettings() = 0; + //! Chlid class should commit the from SettingsList to permanent storage + virtual void saveSettings() = 0; + + // static functions static QString getEncoderName(QString); static EncBase* getEncoder(QString); static QStringList getEncoderList(void); + + //set the config. users of Encoder classes, always have to call this first + void setCfg(RbSettings *sett){settings = sett;} - public slots: - virtual void accept(void){} - virtual void reject(void){} - virtual void reset(void){} private: static void initEncodernamesList(void); @@ -58,7 +61,6 @@ RbSettings* settings; static QMap encoderList; - static QMap encoderCache; }; @@ -71,9 +73,11 @@ virtual bool encode(QString input,QString output); virtual bool start(); virtual bool stop() {return true;} - virtual void showCfg(); virtual bool configOk(); + QList generateSettings(); + void saveSettings(); + private: QString m_name; QString m_EncExec; @@ -90,9 +94,12 @@ virtual bool encode(QString input,QString output); virtual bool start(); virtual bool stop() {return true;} - virtual void showCfg(); virtual bool configOk(); + // for settings view + QList generateSettings(); + void saveSettings(); + private: float quality; float volume; Index: rbutil/rbutilqt/ttsfestivalcfgform.ui =================================================================== --- rbutil/rbutilqt/ttsfestivalcfgform.ui (revision 20569) +++ rbutil/rbutilqt/ttsfestivalcfgform.ui (working copy) @@ -1,322 +0,0 @@ - - TTSFestivalCfgFrm - - - - 0 - 0 - 340 - 316 - - - - Configuration - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - false - - - - - - - - 1 - 0 - - - - Executables - - - - 0 - - - 0 - - - - - QLayout::SetMinimumSize - - - 6 - - - 0 - - - - - - 0 - 0 - - - - Path to Festival server - - - - - - - - 1 - 0 - - - - - 215 - 0 - - - - - - - - Browse - - - - - - - - 0 - 0 - - - - Path to Festival client - - - - - - - - 1 - 0 - - - - - 215 - 0 - - - - - - - - Browse - - - - - - - - - - - - Qt::Horizontal - - - - 70 - 20 - - - - - - - - Qt::Vertical - - - - 153 - 43 - - - - - - - - - 1 - 0 - - - - - 0 - 0 - - - - Server voice - - - - 6 - - - 6 - - - 6 - - - 6 - - - 0 - - - - - - 0 - 0 - - - - Select a voice - - - - - - - - 0 - 0 - - - - &Refresh - - - - :/icons/view-refresh.png:/icons/view-refresh.png - - - - - - - - 1 - 0 - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - - - - Show voice description - - - - - - - - buttonBox - execsBox - horizontalSpacer - verticalSpacer - groupBox2 - - - serverPath - serverButton - clientPath - clientButton - refreshButton - voicesBox - buttonBox - - - - - - - buttonBox - accepted() - TTSFestivalCfgFrm - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - TTSFestivalCfgFrm - reject() - - - 316 - 260 - - - 286 - 274 - - - - - Index: rbutil/rbutilqt/encodersgui.h =================================================================== --- rbutil/rbutilqt/encodersgui.h (revision 20569) +++ rbutil/rbutilqt/encodersgui.h (working copy) @@ -1,79 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef ENCODERSGUI_H -#define ENCODERSGUI_H - -#include - -class RbSettings; - -#include "ui_rbspeexcfgfrm.h" -#include "ui_encexescfgfrm.h" - - -class EncExesGui : public QDialog -{ - Q_OBJECT -public: - EncExesGui(QDialog* parent = NULL); - - void showCfg(QString m_name); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - void browse(void); - -private: - Ui::EncExesCfgFrm ui; - RbSettings* settings; - QString m_name; -}; - -class EncRbSpeexGui : public QDialog -{ - Q_OBJECT -public: - EncRbSpeexGui(QDialog* parent = NULL); - - void showCfg(float defQ,float defV,int defC, bool defB); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - -private: - Ui::RbSpeexCfgFrm ui; - RbSettings* settings; - float defaultQuality; - float defaultVolume; - int defaultComplexity; - bool defaultBand; -}; - - - -#endif Index: rbutil/rbutilqt/configure.cpp =================================================================== --- rbutil/rbutilqt/configure.cpp (revision 20569) +++ rbutil/rbutilqt/configure.cpp (working copy) @@ -27,6 +27,7 @@ #include "encoders.h" #include "tts.h" #include "detect.h" +#include "encttscfggui.h" #include #if defined(Q_OS_WIN32) @@ -665,7 +666,8 @@ TTSBase* tts = TTSBase::getTTS(ui.comboTts->itemData(index).toString()); tts->setCfg(settings); - tts->showCfg(); + EncTTsCfgGui gui(this,tts,TTSBase::getTTSName(settings->curTTS())); + gui.exec(); updateTtsState(ui.comboTts->currentIndex()); } @@ -675,6 +677,8 @@ EncBase* enc = EncBase::getEncoder(settings->curEncoder()); enc->setCfg(settings); - enc->showCfg(); + EncTTsCfgGui gui(this,enc,EncBase::getEncoderName(settings->curEncoder())); + gui.exec(); + updateEncState(); } Index: rbutil/rbutilqt/encttssettings.h =================================================================== --- rbutil/rbutilqt/encttssettings.h (revision 0) +++ rbutil/rbutilqt/encttssettings.h (revision 0) @@ -0,0 +1,126 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef ENCTTSSETTINGS_H +#define ENCTTSSETTINGS_H + +#include + +//! \brief This class stores everything needed for a Setting. +//! It is convertable into a QVariant, so it can be given to the gui via the model-view connection +//! +class EncTTsSetting : public QObject +{ + Q_OBJECT +public: + enum ESettingType + { + eBASE, + eBOOL, + eDOUBLE, + eINT, + eSTRING, + eREADONLYSTRING, + eSTRINGLIST, + }; + enum EButton + { + eNOBTN, + eBROWSEBTN, + eREFRESHBTN + }; + + //! constructor for a String or Bool setting + EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current,EButton btn = eNOBTN); + //! contructor for a Stringlist setting, ie a enumeration + EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current,QStringList list,EButton btn = eNOBTN); + //! constructor for a setting with a min-max range + EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current,QVariant min,QVariant max,EButton = eNOBTN); + + + //! get currentValue + QVariant current() {return m_currentValue;} + //! set currentValue + void setCurrent(QVariant current,bool noticeGui=true); + + //! get name of the Setting + QString name() {return m_name;} + //! get the type of the setting + ESettingType type() {return m_type;} + //! get what type of button this setting needs + EButton button() {return m_btn;} + //! get the minValue (only valid for a range setting, ie eDOUBLE or eINT) + QVariant min() {return m_minValue; } + //! get the maxValue (only valid for a range setting, ie eDOUBLE or eINT) + QVariant max() {return m_maxValue; } + //! get the enumerationlist (only valid for eSTRINGLIST settings) + QStringList list() {return m_list;} + //! set the enumeration list + void setList(QStringList list){m_list = list;} + + + //! emits the correct signal, so the gui updates the entry + void guiUpdate(); +signals: + //! connect to this signal if you want to get noticed when the data changes + void dataChanged(); + //! connect to this if you want to react on refresh button + void refresh(); + //! will be emited when the gui should update this setting + void updateGui(); +public slots: + +private: + ESettingType m_type; + EButton m_btn; + QString m_name; + QVariant m_currentValue; + QVariant m_minValue; + QVariant m_maxValue; + QStringList m_list; +}; +Q_DECLARE_METATYPE(EncTTsSetting*) + +//! \brief this class is the Interface for Encoder and TTS engines, to display settings +//! It wraps nearly everything needed, only updateModel() and commitModel() needs to be reimplemented +//! +class EncTTsSettingInterface : public QObject +{ + Q_OBJECT +public: + EncTTsSettingInterface(QObject* parent) : QObject(parent) {} + + //! Child class should fill in the setttingsList + virtual QList generateSettings() = 0; + //! Chlid class should commit the from SettingsList to permanent storage + virtual void saveSettings() = 0; + + +signals: + void busy(); // emit this if a operation takes time + void busyEnd(); // emit this at the end of a busy section + +protected: + //! The setting storage. + QList settingsList; + +}; +#endif Index: rbutil/rbutilqt/encttscfggui.h =================================================================== --- rbutil/rbutilqt/encttscfggui.h (revision 0) +++ rbutil/rbutilqt/encttscfggui.h (revision 0) @@ -0,0 +1,60 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef ENCTTSCFGGUI_H +#define ENCTTSCFGGUI_H + +#include +#include "rbsettings.h" +#include "encttssettings.h" + +class EncTTsCfgGui: public QDialog +{ + Q_OBJECT +public: + EncTTsCfgGui(QDialog* parent, EncTTsSettingInterface* interface,QString name); + +public slots: + void accept(void); + void reject(void); + void browse(QObject*); + +private slots: + void updateSetting(); + void updateWidget(); + +private: + void setUpWindow(); + QLayout* createWidgets(EncTTsSetting* setting); + QWidget* createButton(EncTTsSetting* setting); + + RbSettings* m_settings; + QString m_name; + EncTTsSettingInterface* m_settingInterface; + QProgressDialog* m_busyDlg; + QList m_settingsList; + QMap m_settingsWidgetsMap; + QSignalMapper m_browseBtnMap; +}; + + +#endif + Index: rbutil/rbutilqt/encodersgui.cpp =================================================================== --- rbutil/rbutilqt/encodersgui.cpp (revision 20569) +++ rbutil/rbutilqt/encodersgui.cpp (working copy) @@ -1,171 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "encodersgui.h" - -#include "rbsettings.h" -#include "browsedirtree.h" - -EncExesGui::EncExesGui(QDialog* parent) : QDialog(parent) -{ - ui.setupUi(this); - this->hide(); - connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); - connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse())); -} - -void EncExesGui::showCfg(QString name) -{ - m_name = name; - // try to get config from settings - QString exepath =settings->encoderPath(m_name); - ui.encoderoptions->setText(settings->encoderOptions(m_name)); - - if(exepath == "") - { - - // try to autodetect encoder -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) - QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts); -#elif defined(Q_OS_WIN) - QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); -#endif - qDebug() << path; - - for(int i = 0; i < path.size(); i++) - { - QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name; -#if defined(Q_OS_WIN) - executable += ".exe"; - QStringList ex = executable.split("\"", QString::SkipEmptyParts); - executable = ex.join(""); -#endif - if(QFileInfo(executable).isExecutable()) - { - qDebug() << "found:" << executable; - exepath = QDir::toNativeSeparators(executable); - break; - } - } - } - - ui.encoderpath->setText(exepath); - - //show dialog - this->exec(); - -} - -void EncExesGui::accept(void) -{ - //save settings in user config - settings->setEncoderPath(m_name,ui.encoderpath->text()); - settings->setEncoderOptions(m_name,ui.encoderoptions->text()); - - // sync settings - settings->sync(); - this->done(0); -} - -void EncExesGui::reject(void) -{ - this->done(0); -} - -void EncExesGui::reset() -{ - ui.encoderpath->setText(""); - ui.encoderoptions->setText(""); -} - -void EncExesGui::browse() -{ - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - if(QFileInfo(ui.encoderpath->text()).isDir()) - { - browser.setDir(ui.encoderpath->text()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.encoderpath->setText(exe); - } -} - - -EncRbSpeexGui::EncRbSpeexGui(QDialog* parent) : QDialog(parent) -{ - ui.setupUi(this); - this->hide(); - connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); - -} - -void EncRbSpeexGui::showCfg(float defQ,float defV,int defC, bool defB) -{ - defaultQuality =defQ; - defaultVolume = defV; - defaultComplexity = defC; - defaultBand =defB; - - //fill in the usersettings - ui.volume->setValue(settings->encoderVolume("rbspeex")); - ui.quality->setValue(settings->encoderQuality("rbspeex")); - ui.complexity->setValue(settings->encoderComplexity("rbspeex")); - - if(settings->encoderNarrowband("rbspeex")) - ui.narrowband->setCheckState(Qt::Checked); - else - ui.narrowband->setCheckState(Qt::Unchecked); - - //show dialog - this->exec(); -} - -void EncRbSpeexGui::accept(void) -{ - //save settings in user config - settings->setEncoderVolume("rbspeex",ui.volume->value()); - settings->setEncoderQuality("rbspeex",ui.quality->value()); - settings->setEncoderComplexity("rbspeex",ui.complexity->value()); - settings->setEncoderNarrowband("rbspeex",ui.narrowband->isChecked() ? true : false); - - // sync settings - settings->sync(); - this->done(0); -} - -void EncRbSpeexGui::reject(void) -{ - this->done(0); -} - -void EncRbSpeexGui::reset() -{ - ui.volume->setValue(defaultVolume); - ui.quality->setValue(defaultQuality); - ui.complexity->setValue(defaultComplexity); - ui.narrowband->setChecked(Qt::Unchecked); -} - Index: rbutil/rbutilqt/tts.cpp =================================================================== --- rbutil/rbutilqt/tts.cpp (revision 20569) +++ rbutil/rbutilqt/tts.cpp (working copy) @@ -18,11 +18,16 @@ ****************************************************************************/ #include "tts.h" +#include "utils.h" +/********************************************************************* +* TTS Base +**********************************************************************/ +QMap TTSBase::ttsList; +TTSBase::TTSBase(QObject* parent): EncTTsSettingInterface(parent) +{ -// static variables -QMap TTSBase::ttsList; -QMap TTSBase::ttsCache; +} // static functions void TTSBase::initTTSList() @@ -41,16 +46,12 @@ // function to get a specific encoder TTSBase* TTSBase::getTTS(QString ttsName) { - // check cache - if(ttsCache.contains(ttsName)) - return ttsCache.value(ttsName); - + TTSBase* tts; #if defined(Q_OS_WIN) if(ttsName == "sapi") { tts = new TTSSapi(); - ttsCache[ttsName] = tts; return tts; } else @@ -59,7 +60,6 @@ if (ttsName == "festival") { tts = new TTSFestival(); - ttsCache[ttsName] = tts; return tts; } else @@ -67,7 +67,6 @@ if (true) // fix for OS other than WIN or LINUX { tts = new TTSExes(ttsName); - ttsCache[ttsName] = tts; return tts; } } @@ -90,18 +89,11 @@ return ttsList.value(tts); } -/********************************************************************* -* TTS Base -**********************************************************************/ -TTSBase::TTSBase(): QObject() -{ -} - /********************************************************************* * General TTS Exes **********************************************************************/ -TTSExes::TTSExes(QString name) : TTSBase() +TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent) { m_name = name; @@ -111,43 +103,26 @@ } -void TTSExes::setCfg(RbSettings* sett) +QList TTSExes::generateSettings() { - // call function of base class - TTSBase::setCfg(sett); + settingsList.clear(); - // if the config isnt OK, try to autodetect - if(!configOk()) - { - QString exepath; - //try autodetect tts -#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) - QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts); -#elif defined(Q_OS_WIN) - QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); -#endif - qDebug() << path; - for(int i = 0; i < path.size(); i++) - { - QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name; -#if defined(Q_OS_WIN) - executable += ".exe"; - QStringList ex = executable.split("\"", QString::SkipEmptyParts); - executable = ex.join(""); -#endif - qDebug() << executable; - if(QFileInfo(executable).isExecutable()) - { - exepath= QDir::toNativeSeparators(executable); - break; - } - } - settings->setTTSPath(m_name,exepath); - settings->sync(); - } + QString exepath =settings->ttsPath(m_name); + if(exepath == "") exepath = findExecutable(m_name); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Path to TTS engine:",exepath,EncTTsSetting::eBROWSEBTN)); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"TTS enginge options:",settings->ttsOptions(m_name))); + + return settingsList; } +void TTSExes::saveSettings() +{ + settings->setTTSPath(m_name,settingsList.at(0)->current().toString()); + settings->setTTSOptions(m_name,settingsList.at(1)->current().toString()); + settings->sync(); +} + bool TTSExes::start(QString *errStr) { m_TTSexec = settings->ttsPath(m_name); @@ -182,17 +157,6 @@ } -void TTSExes::showCfg() -{ -#ifndef CONSOLE - TTSExesGui gui; -#else - TTSExesGuiCli gui; -#endif - gui.setCfg(settings); - gui.showCfg(m_name); -} - bool TTSExes::configOk() { QString path = settings->ttsPath(m_name); @@ -206,14 +170,54 @@ /********************************************************************* * TTS Sapi **********************************************************************/ -TTSSapi::TTSSapi() : TTSBase() +TTSSapi::TTSSapi(QObject* parent) : TTSBase(parent) { m_TTSTemplate = "cscript //nologo \"%exe\" /language:%lang /voice:\"%voice\" /speed:%speed \"%options\""; defaultLanguage ="english"; m_sapi4 =false; } +QList TTSSapi::generateSettings() +{ + settingsList.clear(); + // language + QStringList languages = settings->allLanguages(); + languages.sort(); + EncTTsSetting* setting =new EncTTsSetting(this,EncTTsSetting::eSTRINGLIST,"Language:",settings->ttsLang("sapi"),languages); + connect(setting,SIGNAL(dataChanged()),this,SLOT(updateVoiceList())); + settingsList.append(setting); + // voice + setting = new EncTTsSetting(this,EncTTsSetting::eSTRINGLIST,"Voice:",settings->ttsVoice("sapi"),getVoiceList(settings->ttsLang("sapi")),EncTTsSetting::eREFRESHBTN); + connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceList())); + settingsList.append(setting); + //speed + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eINT,"Speed:",settings->ttsSpeed("sapi"),-10,10)); + // options + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Options:",settings->ttsOptions("sapi"))); + + return settingsList; +} +void TTSSapi::saveSettings() +{ + //save settings in user config + settings->setTTSLang("sapi",settingsList.at(0)->current().toString()); + settings->setTTSVoice("sapi",settingsList.at(1)->current().toString()); + settings->setTTSSpeed("sapi",settingsList.at(2)->current().toInt()); + settings->setTTSOptions("sapi",settingsList.at(3)->current().toString()); + + settings->sync(); +} + +void TTSSapi::updateVoiceList() +{ + qDebug() << "update voiceList"; + QStringList voiceList = getVoiceList(settingsList.at(0)->current().toString()); + settingsList.at(1)->setList(voiceList); + if(voiceList.size() > 0) settingsList.at(1)->setCurrent(voiceList.at(0)); + else settingsList.at(1)->setCurrent(""); +} + bool TTSSapi::start(QString *errStr) { @@ -279,7 +283,7 @@ QFileInfo tts(m_TTSexec); if(!tts.exists()) return result; - + // create the voice process QString execstring = "cscript //nologo \"%exe\" /language:%lang /listvoices"; execstring.replace("%exe",m_TTSexec); @@ -299,21 +303,22 @@ QString dataRaw = voicescript->readAllStandardError().data(); result = dataRaw.split(",",QString::SkipEmptyParts); - result.sort(); - result.removeFirst(); - for(int i = 0; i< result.size();i++) + if(result.size() > 0) { - result[i] = result.at(i).simplified(); - } + result.sort(); + result.removeFirst(); + for(int i = 0; i< result.size();i++) + { + result[i] = result.at(i).simplified(); + } + } - delete voicescript; QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs",QFile::ReadOwner |QFile::WriteOwner|QFile::ExeOwner |QFile::ReadUser| QFile::WriteUser| QFile::ExeUser |QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther ); QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); - return result; } @@ -347,18 +352,6 @@ return true; } - -void TTSSapi::showCfg() -{ -#ifndef CONSOLE - TTSSapiGui gui(this); -#else - TTSSapiGuiCli gui(this); -#endif - gui.setCfg(settings); - gui.showCfg(); -} - bool TTSSapi::configOk() { if(settings->ttsVoice("sapi").isEmpty()) @@ -373,14 +366,72 @@ stop(); } -void TTSFestival::startServer() +QList TTSFestival::generateSettings() { + settingsList.clear(); + // server path + QString exepath = settings->ttsPath("festival-server"); + if(exepath == "" ) exepath = findExecutable("festival"); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Path to Festival server:",exepath,EncTTsSetting::eBROWSEBTN)); + + // client path + exepath = settings->ttsPath("festival-client"); + if(exepath == "" ) exepath = findExecutable("festival_client"); + settingsList.append(new EncTTsSetting(this,EncTTsSetting::eSTRING,"Path to Festival client:",exepath,EncTTsSetting::eBROWSEBTN)); + + // voice + EncTTsSetting* setting = new EncTTsSetting(this,EncTTsSetting::eSTRINGLIST,"Voice:",settings->ttsVoice("festival"),getVoiceList(),EncTTsSetting::eREFRESHBTN); + connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceList())); + connect(setting,SIGNAL(dataChanged()),this,SLOT(clearVoiceDescription())); + settingsList.append(setting); + + //voice description + setting = new EncTTsSetting(this,EncTTsSetting::eREADONLYSTRING,"Voice description:","",EncTTsSetting::eREFRESHBTN); + connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceDescription())); + settingsList.append(setting); + + return settingsList; +} + +void TTSFestival::saveSettings() +{ + //save settings in user config + settings->setTTSPath("festival-server",settingsList.at(0)->current().toString()); + settings->setTTSPath("festival-client",settingsList.at(1)->current().toString()); + settings->setTTSVoice("festival",settingsList.at(2)->current().toString()); + + settings->sync(); +} + +void TTSFestival::updateVoiceDescription() +{ + // get voice Info with current voice and path + QString info = getVoiceInfo(settingsList.at(2)->current().toString(),settingsList.at(0)->current().toString()); + settingsList.at(3)->setCurrent(info); +} + +void TTSFestival::clearVoiceDescription() +{ + settingsList.at(3)->setCurrent(""); +} + +void TTSFestival::updateVoiceList() +{ + QStringList voiceList = getVoiceList(settingsList.at(0)->current().toString()); + settingsList.at(2)->setList(voiceList); + if(voiceList.size() > 0) settingsList.at(2)->setCurrent(voiceList.at(0)); + else settingsList.at(2)->setCurrent(""); +} + +void TTSFestival::startServer(QString path) +{ if(!configOk()) return; - QStringList paths = settings->ttsPath("festival").split(":"); + if(path == "") + path = settings->ttsPath("festival-server"); - serverProcess.start(QString("%1 --server").arg(paths[0])); + serverProcess.start(QString("%1 --server").arg(path)); serverProcess.waitForStarted(); queryServer("(getpid)"); @@ -390,22 +441,16 @@ qDebug() << "Festival failed to start"; } -void TTSFestival::ensureServerRunning() +void TTSFestival::ensureServerRunning(QString path) { if(serverProcess.state() != QProcess::Running) { - // least common denominator for all the server startup code paths - QProgressDialog progressDialog(tr(""), tr(""), 0, 0); - progressDialog.setWindowTitle(tr("Starting festival")); - progressDialog.setModal(true); - progressDialog.setLabel(0); - progressDialog.setCancelButton(0); - progressDialog.show(); - - QApplication::processEvents(); // actually show the dialog - - startServer(); - } + // this operation could take some time + emit busy(); + QCoreApplication::processEvents(); // actually show the dialog + startServer(path); + emit busyEnd(); + } } bool TTSFestival::start(QString* errStr) @@ -430,8 +475,8 @@ { qDebug() << text << "->" << wavfile; - QStringList paths = settings->ttsPath("festival").split(":"); - QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(paths[1]).arg(wavfile); + QString path = settings->ttsPath("festival-client"); + QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(path).arg(wavfile); qDebug() << cmd; QProcess clientProcess; @@ -460,27 +505,18 @@ bool TTSFestival::configOk() { - QStringList paths = settings->ttsPath("festival").split(":"); - if(paths.size() != 2) - return false; - bool ret = QFileInfo(paths[0]).isExecutable() && - QFileInfo(paths[1]).isExecutable(); + QString serverPath = settings->ttsPath("festival-server"); + QString clientPath = settings->ttsPath("festival-client"); + + bool ret = QFileInfo(serverPath).isExecutable() && + QFileInfo(clientPath).isExecutable(); if(settings->ttsVoice("festival").size() > 0 && voices.size() > 0) ret = ret && (voices.indexOf(settings->ttsVoice("festival")) != -1); return ret; } -void TTSFestival::showCfg() +QStringList TTSFestival::getVoiceList(QString path) { -#ifndef CONSOLE - TTSFestivalGui gui(this); -#endif - gui.setCfg(settings); - gui.showCfg(); -} - -QStringList TTSFestival::getVoiceList() -{ if(!configOk()) return QStringList(); @@ -489,7 +525,8 @@ qDebug() << "Using voice cache"; return voices; } - QString response = queryServer("(voice.list)"); + + QString response = queryServer("(voice.list)",3000,path); // get the 2nd line. It should be (, ) response = response.mid(response.indexOf('\n') + 1, -1); @@ -504,10 +541,11 @@ qDebug() << "Voices: " << voices; else qDebug() << "No voices."; + return voices; } -QString TTSFestival::getVoiceInfo(QString voice) +QString TTSFestival::getVoiceInfo(QString voice,QString path) { if(!configOk()) return ""; @@ -517,9 +555,9 @@ if(voiceDescriptions.contains(voice)) return voiceDescriptions[voice]; + + QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000,path); - QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000); - if (response == "") { voiceDescriptions[voice]=tr("No description available"); @@ -551,15 +589,16 @@ } voiceDescriptions[voice] = description.trimmed(); } + return voiceDescriptions[voice]; } -QString TTSFestival::queryServer(QString query, int timeout) +QString TTSFestival::queryServer(QString query, int timeout,QString path) { if(!configOk()) return ""; - ensureServerRunning(); + ensureServerRunning(path); qDebug() << "queryServer with " << query; QString response; @@ -574,7 +613,7 @@ */ while(true) { - QApplication::processEvents(QEventLoop::AllEvents, 50); + QCoreApplication::processEvents(QEventLoop::AllEvents, 50); QTcpSocket socket; socket.connectToHost("localhost", 1314); @@ -600,7 +639,7 @@ /* make sure we wait a little as we don't want to flood the server with requests */ QDateTime tmpEndTime = QDateTime::currentDateTime().addMSecs(500); while(QDateTime::currentDateTime() < tmpEndTime) - QApplication::processEvents(QEventLoop::AllEvents); + QCoreApplication::processEvents(QEventLoop::AllEvents); } if(response == "nil") return ""; Index: rbutil/rbutilqt/ttsexescfgfrm.ui =================================================================== --- rbutil/rbutilqt/ttsexescfgfrm.ui (revision 20569) +++ rbutil/rbutilqt/ttsexescfgfrm.ui (working copy) @@ -1,158 +0,0 @@ - - TTSExesCfgFrm - - - - 0 - 0 - 463 - 214 - - - - Configuration - - - - - - Configure TTS Engine - - - - - - - 0 - 255 - - - - Path to TTS Engine - - - - - - - - - - - - &Browse - - - - - - - - - TTS options - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Reset - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Ok - - - :/icons/go-next.png - - - - - - - &Cancel - - - :/icons/process-stop.png - - - - - - - - - - - - - - - - buttonOk - clicked() - TTSExesCfgFrm - accept() - - - 253 - 147 - - - 203 - 86 - - - - - buttonCancel - clicked() - TTSExesCfgFrm - reject() - - - 352 - 147 - - - 203 - 86 - - - - - Index: rbutil/rbutilqt/encttssettings.cpp =================================================================== --- rbutil/rbutilqt/encttssettings.cpp (revision 0) +++ rbutil/rbutilqt/encttssettings.cpp (revision 0) @@ -0,0 +1,59 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "encttssettings.h" + + +EncTTsSetting::EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current, EButton btn) +{ + m_btn = btn; + m_name =name; + m_type =type; + m_currentValue = current; +} + +EncTTsSetting::EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current,QStringList list,EButton btn) +{ + m_btn = btn; + m_name =name; + m_type =type; + m_currentValue = current; + m_list = list; +} + +EncTTsSetting::EncTTsSetting(QObject* parent,ESettingType type,QString name,QVariant current,QVariant min,QVariant max, EButton btn) +{ + m_btn = btn; + m_name =name; + m_type =type; + m_currentValue = current; + m_minValue = min; + m_maxValue = max; +} + +void EncTTsSetting::setCurrent(QVariant current,bool noticeGui) +{ + m_currentValue = current; + emit dataChanged(); + + if(noticeGui) emit updateGui(); +} + Index: rbutil/rbutilqt/rbutilqt.pro =================================================================== --- rbutil/rbutilqt/rbutilqt.pro (revision 20569) +++ rbutil/rbutilqt/rbutilqt.pro (working copy) @@ -64,9 +64,9 @@ base/utils.cpp \ preview.cpp \ encoders.cpp \ - encodersgui.cpp \ + encttscfggui.cpp \ + encttssettings.cpp \ tts.cpp \ - ttsgui.cpp \ ../../tools/wavtrim.c \ ../../tools/voicefont.c \ voicefile.cpp \ @@ -116,9 +116,9 @@ base/utils.h \ preview.h \ encoders.h \ - encodersgui.h \ + encttscfggui.h \ + encttssettings.h \ tts.h \ - ttsgui.h \ ../../tools/wavtrim.h \ ../../tools/voicefont.h \ voicefile.h \ @@ -167,11 +167,6 @@ installthemesfrm.ui \ uninstallfrm.ui \ previewfrm.ui \ - rbspeexcfgfrm.ui \ - encexescfgfrm.ui \ - ttsexescfgfrm.ui \ - sapicfgfrm.ui \ - ttsfestivalcfgform.ui \ createvoicefrm.ui \ sysinfofrm.ui Index: rbutil/rbutilqt/encttscfggui.cpp =================================================================== --- rbutil/rbutilqt/encttscfggui.cpp (revision 0) +++ rbutil/rbutilqt/encttscfggui.cpp (revision 0) @@ -0,0 +1,331 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: encoders.h 17902 2008-06-30 22:09:45Z bluebrother $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "encttscfggui.h" +#include "browsedirtree.h" + +EncTTsCfgGui::EncTTsCfgGui(QDialog* parent,EncTTsSettingInterface* interface,QString name) : QDialog(parent) +{ + m_settingInterface = interface; + + // create a busy Dialog + m_busyDlg= new QProgressDialog(tr(""), tr(""), 0, 0,this); + m_busyDlg->setWindowTitle(tr("Waiting for engine...")); + m_busyDlg->setModal(true); + m_busyDlg->setLabel(0); + m_busyDlg->setCancelButton(0); + m_busyDlg->hide(); + connect(interface,SIGNAL(busy()),m_busyDlg,SLOT(show())); + connect(interface,SIGNAL(busyEnd()),m_busyDlg,SLOT(hide())); + + //setup the window + setWindowTitle(name); + setUpWindow(); +} + +void EncTTsCfgGui::setUpWindow() +{ + m_settingsList = m_settingInterface->generateSettings(); + + //layout + QVBoxLayout *mainLayout = new QVBoxLayout; + + // groupbox + QGroupBox *groupBox = new QGroupBox(this); + QFormLayout *formlayout = new QFormLayout; + // setting widgets + for(int i = 0; i < m_settingsList.size(); i++) + { + formlayout->addRow(m_settingsList.at(i)->name(),createWidgets(m_settingsList.at(i))); + } + groupBox->setLayout(formlayout); + mainLayout->addWidget(groupBox); + + // connect browse btn + connect(&m_browseBtnMap,SIGNAL(mapped(QObject*)),this,SLOT(browse(QObject*))); + + // ok - cancel buttons + QPushButton* okBtn = new QPushButton(tr("Ok")); + okBtn->setDefault(true); + okBtn->setIcon(QIcon(":icons/go-next.png")); + QPushButton* cancelBtn = new QPushButton(tr("Cancel")); + cancelBtn->setIcon(QIcon(":icons/process-stop.png")); + connect(okBtn,SIGNAL(clicked()),this,SLOT(accept())); + connect(cancelBtn,SIGNAL(clicked()),this,SLOT(reject())); + + QHBoxLayout *btnbox = new QHBoxLayout; + btnbox->addWidget(okBtn); + btnbox->addWidget(cancelBtn); + btnbox->insertStretch(0,1); + + mainLayout->addLayout(btnbox); + + this->setLayout(mainLayout); +} + +QLayout* EncTTsCfgGui::createWidgets(EncTTsSetting* setting) +{ + // value display + QWidget* value = NULL; + switch(setting->type()) + { + case EncTTsSetting::eDOUBLE: + { + QDoubleSpinBox *spinBox = new QDoubleSpinBox(this); + spinBox->setMinimum(setting->min().toDouble()); + spinBox->setMaximum(setting->max().toDouble()); + spinBox->setValue(setting->current().toDouble()); + connect(spinBox,SIGNAL(valueChanged(double)),this,SLOT(updateSetting())); + value = spinBox; + break; + } + case EncTTsSetting::eINT: + { + QSpinBox *spinBox = new QSpinBox(this); + spinBox->setMinimum(setting->min().toInt()); + spinBox->setMaximum(setting->max().toInt()); + spinBox->setValue(setting->current().toInt()); + connect(spinBox,SIGNAL(valueChanged(int)),this,SLOT(updateSetting())); + value = spinBox; + break; + } + case EncTTsSetting::eSTRING: + { + QLineEdit *lineEdit = new QLineEdit(this); + lineEdit->setText(setting->current().toString()); + connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(updateSetting())); + value = lineEdit; + break; + } + case EncTTsSetting::eREADONLYSTRING: + { + value = new QLabel(setting->current().toString()); + break; + } + case EncTTsSetting::eSTRINGLIST: + { + QComboBox *comboBox = new QComboBox(this); + comboBox->addItems(setting->list()); + int index = comboBox->findText(setting->current().toString()); + comboBox->setCurrentIndex(index); + connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateSetting())); + value = comboBox; + break; + } + case EncTTsSetting::eBOOL: + { + QCheckBox *checkbox = new QCheckBox(this); + checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked); + connect(checkbox,SIGNAL(stateChanged(int)),this,SLOT(updateSetting())); + value = checkbox; + break; + } + default: + { + break; + } + } + + // remeber widget + if(value != NULL) + { + m_settingsWidgetsMap.insert(setting,value); + connect(setting,SIGNAL(updateGui()),this,SLOT(updateWidget())); + } + + // buttons ? + QWidget* btn = createButton(setting); + + // add to layout + QHBoxLayout *hbox = new QHBoxLayout; + if(value != NULL)hbox->addWidget(value); + if(btn != NULL) hbox->addWidget(btn); + + return hbox; + +} + +QWidget* EncTTsCfgGui::createButton(EncTTsSetting* setting) +{ + if(setting->button() == EncTTsSetting::eBROWSEBTN) + { + QPushButton* browsebtn = new QPushButton(tr("Browse"),this); + m_browseBtnMap.setMapping(browsebtn,setting); + connect(browsebtn,SIGNAL(clicked()),&m_browseBtnMap,SLOT(map())); + return browsebtn; + } + else if(setting->button() == EncTTsSetting::eREFRESHBTN) + { + QPushButton* refreshbtn = new QPushButton(tr("Refresh"),this); + connect(refreshbtn,SIGNAL(clicked()),setting,SIGNAL(refresh())); + return refreshbtn; + } + else + return NULL; +} + +void EncTTsCfgGui::updateSetting() +{ + QWidget* widget = (QWidget*) QObject::sender(); + EncTTsSetting* setting = m_settingsWidgetsMap.key(widget); + + switch(setting->type()) + { + case EncTTsSetting::eDOUBLE: + { + setting->setCurrent(((QDoubleSpinBox*)widget)->value(),false); + break; + } + case EncTTsSetting::eINT: + { + setting->setCurrent(((QSpinBox*)widget)->value(),false); + break; + } + case EncTTsSetting::eSTRING: + { + setting->setCurrent(((QLineEdit*)widget)->text(),false); + break; + } + case EncTTsSetting::eREADONLYSTRING: + { + setting->setCurrent(((QLabel*)widget)->text(),false); + break; + } + case EncTTsSetting::eSTRINGLIST: + { + setting->setCurrent(((QComboBox*)widget)->currentText(),false); + break; + } + case EncTTsSetting::eBOOL: + { + setting->setCurrent(((QCheckBox*)widget)->isChecked(),false); + } + default: + { + break; + } + } + +} + +void EncTTsCfgGui::updateWidget() +{ + EncTTsSetting* setting = (EncTTsSetting*) QObject::sender(); + QWidget* widget = m_settingsWidgetsMap.value(setting); + + switch(setting->type()) + { + case EncTTsSetting::eDOUBLE: + { + QDoubleSpinBox* spinbox = (QDoubleSpinBox*) widget; + spinbox->setMinimum(setting->min().toDouble()); + spinbox->setMaximum(setting->max().toDouble()); + spinbox->blockSignals(true); + spinbox->setValue(setting->current().toDouble()); + spinbox->blockSignals(false); + break; + } + case EncTTsSetting::eINT: + { + QSpinBox* spinbox = (QSpinBox*) widget; + spinbox->setMinimum(setting->min().toInt()); + spinbox->setMaximum(setting->max().toInt()); + spinbox->blockSignals(true); + spinbox->setValue(setting->current().toInt()); + spinbox->blockSignals(false); + break; + } + case EncTTsSetting::eSTRING: + { + QLineEdit* lineedit = (QLineEdit*) widget; + + lineedit->blockSignals(true); + lineedit->setText(setting->current().toString()); + lineedit->blockSignals(false); + break; + } + case EncTTsSetting::eREADONLYSTRING: + { + QLabel* label = (QLabel*) widget; + + label->blockSignals(true); + label->setText(setting->current().toString()); + label->blockSignals(false); + break; + } + case EncTTsSetting::eSTRINGLIST: + { + QComboBox* combobox = (QComboBox*) widget; + + combobox->blockSignals(true); + combobox->clear(); + combobox->addItems(setting->list()); + int index = combobox->findText(setting->current().toString()); + combobox->setCurrentIndex(index); + combobox->blockSignals(false); + + break; + } + case EncTTsSetting::eBOOL: + { + QCheckBox* checkbox = (QCheckBox*) widget; + + checkbox->blockSignals(true); + checkbox->setCheckState(setting->current().toBool() == true ? Qt::Checked : Qt::Unchecked); + checkbox->blockSignals(false); + break; + } + default: + { + qDebug() << "unknown EncTTsSetting"; + break; + } + } +} + + +void EncTTsCfgGui::accept(void) +{ + m_settingInterface->saveSettings(); + this->done(0); +} + +void EncTTsCfgGui::reject(void) +{ + this->done(0); +} + + +void EncTTsCfgGui::browse(QObject* settingObj) +{ + EncTTsSetting* setting= (EncTTsSetting*) settingObj; + + QString curPath = setting->current().toString(); + + QString exe = QFileDialog::getOpenFileName(this, tr("Select excutable"), curPath, "*"); + if(!QFileInfo(exe).isExecutable()) + return; + + setting->setCurrent(exe); +} + + + Index: rbutil/rbutilqt/tts.h =================================================================== --- rbutil/rbutilqt/tts.h (revision 20569) +++ rbutil/rbutilqt/tts.h (working copy) @@ -26,44 +26,37 @@ #include "rbsettings.h" #include #include -#include #include #include #include -#ifndef CONSOLE -#include "ttsgui.h" -#else -#include "ttsguicli.h" -#endif +#include "encttssettings.h" enum TTSStatus{ FatalError, NoError, Warning }; -class TTSSapi; -#if defined(Q_OS_LINUX) -class TTSFestival; -#endif -class TTSBase : public QObject + +class TTSBase : public EncTTsSettingInterface { Q_OBJECT public: - TTSBase(); + TTSBase(QObject *parent); virtual TTSStatus voice(QString text,QString wavfile, QString* errStr) { (void) text; (void) wavfile; (void) errStr; return FatalError;} virtual bool start(QString *errStr) { (void)errStr; return false; } virtual bool stop() { return false; } - virtual void showCfg(){} virtual bool configOk() { return false; } - - virtual void setCfg(RbSettings* sett) { settings = sett; } + //! Child class should fill in the setttingsList + virtual QList generateSettings() = 0; + //! Chlid class should commit the from SettingsList to permanent storage + virtual void saveSettings() = 0; + + // static functions static TTSBase* getTTS(QString ttsname); static QStringList getTTSList(); - static QString getTTSName(QString tts); + static QString getTTSName(QString tts); - public slots: - virtual void accept(void){} - virtual void reject(void){} - virtual void reset(void){} + // sets the config. Users of TTS classes, always have to call this first + void setCfg(RbSettings* sett) { settings = sett; } private: //inits the tts List @@ -72,22 +65,28 @@ protected: RbSettings* settings; static QMap ttsList; - static QMap ttsCache; }; class TTSSapi : public TTSBase { Q_OBJECT public: - TTSSapi(); + TTSSapi(QObject* parent=NULL); virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); virtual bool start(QString *errStr); virtual bool stop(); - virtual void showCfg(); virtual bool configOk(); + // for settings view + QList generateSettings(); + void saveSettings(); + + private slots: + void updateVoiceList(); + + private: QStringList getVoiceList(QString language); - private: + QProcess* voicescript; QTextStream* voicestream; QString defaultLanguage; @@ -106,14 +105,15 @@ { Q_OBJECT public: - TTSExes(QString name); + TTSExes(QString name,QObject* parent=NULL); virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); virtual bool start(QString *errStr); virtual bool stop() {return true;} - virtual void showCfg(); virtual bool configOk(); - virtual void setCfg(RbSettings* sett); + // for settings view + QList generateSettings(); + void saveSettings(); private: QString m_name; @@ -127,19 +127,28 @@ { Q_OBJECT public: + TTSFestival(QObject* parent=NULL) :TTSBase(parent) {} ~TTSFestival(); virtual bool configOk(); virtual bool start(QString *errStr); virtual bool stop(); - virtual void showCfg(); virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); - QStringList getVoiceList(); - QString getVoiceInfo(QString voice); + // for settings view + QList generateSettings(); + void saveSettings(); + +private slots: + void updateVoiceList(); + void updateVoiceDescription(); + void clearVoiceDescription(); private: - inline void startServer(); - inline void ensureServerRunning(); - QString queryServer(QString query, int timeout = -1); + QStringList getVoiceList(QString path =""); + QString getVoiceInfo(QString voice,QString path =""); + + inline void startServer(QString path=""); + inline void ensureServerRunning(QString path=""); + QString queryServer(QString query, int timeout = -1,QString path=""); QProcess serverProcess; QStringList voices; QMap voiceDescriptions; Index: rbutil/rbutilqt/ttsgui.h =================================================================== --- rbutil/rbutilqt/ttsgui.h (revision 20569) +++ rbutil/rbutilqt/ttsgui.h (working copy) @@ -1,104 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * - * Copyright (C) 2007 by Dominik Wenger - * $Id$ - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef TTSGUI_H -#define TTSGUI_H - -#include - -#include "ui_ttsexescfgfrm.h" -#include "ui_sapicfgfrm.h" -#include "ui_ttsfestivalcfgform.h" - -class RbSettings; -class TTSSapi; -class TTSFestival; - -class TTSSapiGui : public QDialog -{ - Q_OBJECT -public: - TTSSapiGui(TTSSapi* sapi,QDialog* parent = NULL); - - void showCfg(); - void setCfg(RbSettings* sett){settings = sett;} -public slots: - - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - void updateVoices(QString language); - void useSapi4Changed(int); -private: - Ui::SapiCfgFrm ui; - RbSettings* settings; - TTSSapi* m_sapi; -}; - -class TTSExesGui : public QDialog -{ - Q_OBJECT -public: - TTSExesGui(QDialog* parent = NULL); - - void showCfg(QString m_name); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - void browse(void); -private: - Ui::TTSExesCfgFrm ui; - RbSettings* settings; - QString m_name; -}; - -class TTSFestivalGui : public QDialog -{ - Q_OBJECT -public: - TTSFestivalGui(TTSFestival* festival, QDialog* parent = NULL); - - void showCfg(); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - //virtual void reset(void); - - void onRefreshButton(); - void onShowDescription(int state); - void onBrowseServer(); - void onBrowseClient(); -private: - Ui::TTSFestivalCfgFrm ui; - RbSettings* settings; - TTSFestival* festival; - - void updateVoices(); -private slots: - void updateDescription(QString value); -}; - -#endif Index: rbutil/rbutilqt/base/utils.cpp =================================================================== --- rbutil/rbutilqt/base/utils.cpp (revision 20569) +++ rbutil/rbutilqt/base/utils.cpp (working copy) @@ -130,6 +130,35 @@ return size; } +//! \brief searches for a Executable in the Environement Path +QString findExecutable(QString name) +{ + QString exepath; + //try autodetect tts +#if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) + QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts); +#elif defined(Q_OS_WIN) + QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts); +#endif + qDebug() << path; + for(int i = 0; i < path.size(); i++) + { + QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + name; +#if defined(Q_OS_WIN) + executable += ".exe"; + QStringList ex = executable.split("\"", QString::SkipEmptyParts); + executable = ex.join(""); +#endif + qDebug() << executable; + if(QFileInfo(executable).isExecutable()) + { + return QDir::toNativeSeparators(executable); + } + } + return ""; +} + + RockboxInfo::RockboxInfo(QString mountpoint) { m_path = mountpoint +"/.rockbox/rockbox-info.txt"; Index: rbutil/rbutilqt/base/utils.h =================================================================== --- rbutil/rbutilqt/base/utils.h (revision 20569) +++ rbutil/rbutilqt/base/utils.h (working copy) @@ -29,6 +29,7 @@ bool recRmdir( const QString &dirName ); QString resolvePathCase(QString path); qulonglong filesystemFree(QString path); +QString findExecutable(QString name); class RockboxInfo {