rbutil: fix a bug in the new settings object. Seperate the config gui from tts and encoders. (in preparation for cli interface).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16183 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Wenger 2008-01-29 21:54:43 +00:00
parent 51f937c2e4
commit 0c66bdb2b0
10 changed files with 583 additions and 340 deletions

View file

@ -20,6 +20,9 @@
#include "encoders.h"
#include "browsedirtree.h"
#ifndef CONSOLE
#include "encodersgui.h"
#endif
static QMap<QString,QString> encoderList;
static QMap<QString,EncBase*> encoderCache;
@ -92,11 +95,6 @@ EncExes::EncExes(QString name,QWidget *parent) : EncBase(parent)
m_name = name;
m_TemplateMap["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
}
bool EncExes::start()
@ -131,67 +129,13 @@ bool EncExes::encode(QString input,QString output)
return true;
}
void EncExes::reset()
{
ui.encoderpath->setText("");
ui.encoderoptions->setText("");
}
void EncExes::showCfg()
{
// 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)
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 EncExes::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->close();
}
void EncExes::reject(void)
{
this->close();
EncExesGui gui;
gui.setCfg(settings);
gui.showCfg(m_name);
}
bool EncExes::configOk()
@ -204,33 +148,13 @@ bool EncExes::configOk()
return false;
}
void EncExes::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);
}
}
/*********************************************************************
* RB SPEEX ENCODER
**********************************************************************/
EncRbSpeex::EncRbSpeex(QWidget *parent) : EncBase(parent)
{
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
defaultQuality = 8.f;
defaultVolume = 1.f;
@ -282,49 +206,14 @@ bool EncRbSpeex::encode(QString input,QString output)
return true;
}
void EncRbSpeex::reset()
{
ui.volume->setValue(defaultVolume);
ui.quality->setValue(defaultQuality);
ui.complexity->setValue(defaultComplexity);
ui.narrowband->setChecked(Qt::Unchecked);
}
void EncRbSpeex::showCfg()
{
//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();
EncRbSpeexGui gui;
gui.setCfg(settings);
gui.showCfg(defaultQuality,defaultVolume,defaultComplexity,defaultBand);
}
void EncRbSpeex::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->close();
}
void EncRbSpeex::reject(void)
{
this->close();
}
bool EncRbSpeex::configOk()
{
bool result=true;

View file

@ -22,8 +22,6 @@
#include <QtGui>
#include "ui_rbspeexcfgfrm.h"
#include "ui_encexescfgfrm.h"
#include "rbsettings.h"
extern "C"
@ -78,14 +76,7 @@ public:
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
void browse(void);
private:
Ui::EncExesCfgFrm ui;
QString m_name;
QString m_EncExec;
QString m_EncOpts;
@ -104,13 +95,7 @@ public:
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
private:
Ui::RbSpeexCfgFrm ui;
float quality;
float volume;
int complexity;

View file

@ -0,0 +1,170 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: encodersgui.cpp 15212 2007-10-19 21:49:07Z domonoky $
*
* 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)
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->close();
}
void EncExesGui::reject(void)
{
this->close();
}
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,float 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->close();
}
void EncRbSpeexGui::reject(void)
{
this->close();
}
void EncRbSpeexGui::reset()
{
ui.volume->setValue(defaultVolume);
ui.quality->setValue(defaultQuality);
ui.complexity->setValue(defaultComplexity);
ui.narrowband->setChecked(Qt::Unchecked);
}

View file

@ -0,0 +1,77 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: encodersgui.h 15212 2007-10-19 21:49:07Z domonoky $
*
* 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.
*
****************************************************************************/
#ifndef ENCODERSGUI_H
#define ENCODERSGUI_H
#include <QtGui>
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,float 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

View file

@ -272,82 +272,82 @@ int RbSettings::wavtrimTh()
QString RbSettings::ttsPath(QString tts)
{
devices->beginGroup(tts);
QString path = devices->value("ttspath").toString();
devices->endGroup();
userSettings->beginGroup(tts);
QString path = userSettings->value("ttspath").toString();
userSettings->endGroup();
return path;
}
QString RbSettings::ttsOptions(QString tts)
{
devices->beginGroup(tts);
QString op = devices->value("ttsoptions").toString();
devices->endGroup();
userSettings->beginGroup(tts);
QString op = userSettings->value("ttsoptions").toString();
userSettings->endGroup();
return op;
}
QString RbSettings::ttsVoice(QString tts)
{
devices->beginGroup(tts);
QString op = devices->value("ttsvoice").toString();
devices->endGroup();
userSettings->beginGroup(tts);
QString op = userSettings->value("ttsvoice").toString();
userSettings->endGroup();
return op;
}
int RbSettings::ttsSpeed(QString tts)
{
devices->beginGroup(tts);
int sp = devices->value("ttsspeed",0).toInt();
devices->endGroup();
userSettings->beginGroup(tts);
int sp = userSettings->value("ttsspeed",0).toInt();
userSettings->endGroup();
return sp;
}
QString RbSettings::ttsLang(QString tts)
{
devices->beginGroup(tts);
QString op = devices->value("ttslanguage").toString();
devices->endGroup();
userSettings->beginGroup(tts);
QString op = userSettings->value("ttslanguage").toString();
userSettings->endGroup();
return op;
}
QString RbSettings::encoderPath(QString enc)
{
devices->beginGroup(enc);
QString path = devices->value("encoderpath").toString();
devices->endGroup();
userSettings->beginGroup(enc);
QString path = userSettings->value("encoderpath").toString();
userSettings->endGroup();
return path;
}
QString RbSettings::encoderOptions(QString enc)
{
devices->beginGroup(enc);
QString op = devices->value("encoderpath").toString();
devices->endGroup();
userSettings->beginGroup(enc);
QString op = userSettings->value("encoderpath").toString();
userSettings->endGroup();
return op;
}
double RbSettings::encoderQuality(QString enc)
{
devices->beginGroup(enc);
double q = devices->value("quality",8.f).toDouble();
devices->endGroup();
userSettings->beginGroup(enc);
double q =userSettings->value("quality",8.f).toDouble();
userSettings->endGroup();
return q;
}
int RbSettings::encoderComplexity(QString enc)
{
devices->beginGroup(enc);
int c = devices->value("complexity",1.f).toInt();
devices->endGroup();
userSettings->beginGroup(enc);
int c = userSettings->value("complexity",1.f).toInt();
userSettings->endGroup();
return c;
}
double RbSettings::encoderVolume(QString enc)
{
devices->beginGroup(enc);
double v = devices->value("volume",10).toDouble();
devices->endGroup();
userSettings->beginGroup(enc);
double v = userSettings->value("volume",10).toDouble();
userSettings->endGroup();
return v;
}
bool RbSettings::encoderNarrowband(QString enc)
{
devices->beginGroup(enc);
bool nb = devices->value("narrowband",false).toBool();
devices->endGroup();
userSettings->beginGroup(enc);
bool nb = userSettings->value("narrowband",false).toBool();
userSettings->endGroup();
return nb;
}

View file

@ -48,7 +48,9 @@ SOURCES += rbutilqt.cpp \
browseof.cpp \
preview.cpp \
encoders.cpp \
encodersgui.cpp \
tts.cpp \
ttsgui.cpp \
../../tools/wavtrim.c \
../../tools/voicefont.c \
voicefile.cpp \
@ -91,7 +93,9 @@ HEADERS += rbutilqt.h \
browseof.h \
preview.h \
encoders.h \
encodersgui.h \
tts.h \
ttsgui.h \
../../tools/wavtrim.h \
../../tools/voicefont.h \
voicefile.h \

View file

@ -19,7 +19,7 @@
#include "tts.h"
#include "browsedirtree.h"
static QMap<QString,QString> ttsList;
static QMap<QString,TTSBase*> ttsCache;
@ -82,7 +82,7 @@ QStringList getTTSList()
/*********************************************************************
* TTS Base
**********************************************************************/
TTSBase::TTSBase(QWidget *parent): QDialog(parent)
TTSBase::TTSBase(): QObject()
{
}
@ -90,7 +90,7 @@ TTSBase::TTSBase(QWidget *parent): QDialog(parent)
/*********************************************************************
* General TTS Exes
**********************************************************************/
TTSExes::TTSExes(QString name,QWidget *parent) : TTSBase(parent)
TTSExes::TTSExes(QString name) : TTSBase()
{
m_name = name;
@ -98,10 +98,6 @@ TTSExes::TTSExes(QString name,QWidget *parent) : TTSBase(parent)
m_TemplateMap["flite"] = "\"%exe\" \"%options\" -o \"%wavfile\" \"%text\"";
m_TemplateMap["swift"] = "\"%exe\" \"%options\" -o \"%wavfile\" \"%text\"";
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
}
bool TTSExes::start(QString *errStr)
@ -137,68 +133,11 @@ bool TTSExes::voice(QString text,QString wavfile)
}
void TTSExes::reset()
{
ui.ttspath->setText("");
ui.ttsoptions->setText("");
}
void TTSExes::showCfg()
{
// try to get config from settings
QString exepath =settings->ttsPath(m_name);
ui.ttsoptions->setText(settings->ttsOptions(m_name));
if(exepath == "")
{
//try autodetect tts
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
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;
}
}
}
ui.ttspath->setText(exepath);
//show dialog
this->exec();
}
void TTSExes::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->close();
}
void TTSExes::reject(void)
{
this->close();
TTSExesGui gui;
gui.setCfg(settings);
gui.showCfg(m_name);
}
bool TTSExes::configOk()
@ -211,36 +150,14 @@ bool TTSExes::configOk()
return false;
}
void TTSExes::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);
}
}
/*********************************************************************
* TTS Sapi
**********************************************************************/
TTSSapi::TTSSapi(QWidget *parent) : TTSBase(parent)
TTSSapi::TTSSapi() : TTSBase()
{
m_TTSTemplate = "cscript //nologo \"%exe\" /language:%lang /voice:\"%voice\" /speed:%speed \"%options\"";
defaultLanguage ="english";
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString)));
}
@ -329,15 +246,8 @@ QStringList TTSSapi::getVoiceList(QString language)
return result;
}
void TTSSapi::updateVoices(QString language)
{
QStringList Voices = getVoiceList(language);
ui.voicecombo->clear();
ui.voicecombo->addItems(Voices);
}
bool TTSSapi::voice(QString text,QString wavfile)
{
QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n";
@ -363,58 +273,11 @@ bool TTSSapi::stop()
}
void TTSSapi::reset()
{
ui.ttsoptions->setText("");
ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(defaultLanguage));
}
void TTSSapi::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"));
// 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 TTSSapi::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());
// sync settings
settings->sync();
this->close();
}
void TTSSapi::reject(void)
{
this->close();
TTSSapiGui gui(this);
gui.setCfg(settings);
gui.showCfg();
}
bool TTSSapi::configOk()

View file

@ -21,11 +21,13 @@
#ifndef TTS_H
#define TTS_H
#include "ui_ttsexescfgfrm.h"
#include "ui_sapicfgfrm.h"
#include "rbsettings.h"
#include <QtGui>
#ifndef CONSOLE
#include "ttsgui.h"
#endif
class TTSBase;
@ -37,11 +39,11 @@ TTSBase* getTTS(QString ttsname);
QStringList getTTSList();
class TTSBase : public QDialog
class TTSBase : public QObject
{
Q_OBJECT
public:
TTSBase(QWidget *parent );
TTSBase();
virtual bool voice(QString text,QString wavfile) {return false;}
virtual bool start(QString *errStr){return false;}
virtual bool stop(){return false;}
@ -63,23 +65,16 @@ class TTSSapi : public TTSBase
{
Q_OBJECT
public:
TTSSapi(QWidget *parent = NULL);
TTSSapi();
virtual bool voice(QString text,QString wavfile);
virtual bool start(QString *errStr);
virtual bool stop();
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
void updateVoices(QString language);
private:
QStringList getVoiceList(QString language);
private:
Ui::SapiCfgFrm ui;
QProcess* voicescript;
QString defaultLanguage;
@ -97,21 +92,17 @@ class TTSExes : public TTSBase
{
Q_OBJECT
public:
TTSExes(QString name,QWidget *parent = NULL);
TTSExes(QString name);
virtual bool voice(QString text,QString wavfile);
virtual bool start(QString *errStr);
virtual bool stop() {return true;}
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
void browse(void);
private:
Ui::TTSExesCfgFrm ui;
QString m_name;
QString m_TTSexec;
QString m_TTSOpts;

193
rbutil/rbutilqt/ttsgui.cpp Normal file
View file

@ -0,0 +1,193 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: tts.cpp 15212 2007-10-19 21:49:07Z domonoky $
*
* 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)));
}
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"));
// 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());
// sync settings
settings->sync();
this->close();
}
void TTSSapiGui::reject(void)
{
this->close();
}
void TTSSapiGui::updateVoices(QString language)
{
QStringList Voices = m_sapi->getVoiceList(language);
ui.voicecombo->clear();
ui.voicecombo->addItems(Voices);
}
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));
if(exepath == "")
{
//try autodetect tts
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
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;
}
}
}
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->close();
}
void TTSExesGui::reject(void)
{
this->close();
}
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);
}
}

71
rbutil/rbutilqt/ttsgui.h Normal file
View file

@ -0,0 +1,71 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: ttsgui.h 15212 2007-10-19 21:49:07Z domonoky $
*
* 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.
*
****************************************************************************/
#ifndef TTSGUI_H
#define TTSGUI_H
#include <QtGui>
#include "ui_ttsexescfgfrm.h"
#include "ui_sapicfgfrm.h"
class RbSettings;
class TTSSapi;
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);
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;
};
#endif