From c6a0d1411416f0cb3b90becd1f8be5bd20c2c7f0 Mon Sep 17 00:00:00 2001 From: bluebrother Date: Wed, 6 Feb 2008 21:51:35 +0000 Subject: [PATCH] Save the internal name for tts / encoder in the configuration file, not the displayed nice name. Additionally, kill a few warnings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16233 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/configure.cpp | 36 ++++++++++++++----------- rbutil/rbutilqt/createvoicewindow.cpp | 4 +-- rbutil/rbutilqt/encoders.cpp | 49 +++++++++++++++++------------------ rbutil/rbutilqt/encoders.h | 8 +++--- rbutil/rbutilqt/installtalkwindow.cpp | 4 +-- rbutil/rbutilqt/tts.cpp | 29 +++++++++------------ rbutil/rbutilqt/tts.h | 5 ++-- 7 files changed, 69 insertions(+), 66 deletions(-) diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp index f583433b8..0e8486c68 100644 --- a/rbutil/rbutilqt/configure.cpp +++ b/rbutil/rbutilqt/configure.cpp @@ -134,9 +134,11 @@ void Config::accept() settings->setCacheOffline(ui.cacheOfflineMode->isChecked()); // tts settings - settings->setCurTTS(ui.comboTts->currentText()); + int i = ui.comboTts->currentIndex(); + settings->setCurTTS(ui.comboTts->itemData(i).toString()); //encoder settings - settings->setCurEncoder(ui.comboEncoder->currentText()); + i = ui.comboEncoder->currentIndex(); + settings->setCurEncoder(ui.comboEncoder->itemData(i).toString()); // sync settings settings->sync(); @@ -286,20 +288,22 @@ void Config::setDevices() // tts / encoder tab //encoders - ui.comboEncoder->addItems(getEncoderList()); - + int index; + QStringList encoders = getEncoderList(); + for(int a = 0; a < encoders.size(); a++) + ui.comboEncoder->addItem(getEncoderName(encoders.at(a)), encoders.at(a)); //update index of combobox - int index = ui.comboEncoder->findText(settings->curEncoder(),Qt::MatchExactly); + index = ui.comboEncoder->findData(settings->curEncoder()); if(index < 0) index = 0; ui.comboEncoder->setCurrentIndex(index); updateEncState(index); - + //tts - ui.comboTts->addItems(getTTSList()); - - + QStringList ttslist = getTTSList(); + for(int a = 0; a < ttslist.size(); a++) + ui.comboTts->addItem(getTTSName(ttslist.at(a)), ttslist.at(a)); //update index of combobox - index = ui.comboTts->findText(settings->curTTS(),Qt::MatchExactly); + index = ui.comboTts->findData(settings->curTTS()); if(index < 0) index = 0; ui.comboTts->setCurrentIndex(index); updateTtsState(index); @@ -309,7 +313,7 @@ void Config::setDevices() void Config::updateTtsState(int index) { - QString ttsName = ui.comboTts->itemText(index); + QString ttsName = ui.comboTts->itemData(index).toString(); TTSBase* tts = getTTS(ttsName); tts->setCfg(settings); @@ -322,12 +326,12 @@ void Config::updateTtsState(int index) { ui.configTTSstatus->setText("Configuration INVALID"); ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/dialog-error.png"))); - } + } } void Config::updateEncState(int index) { - QString encoder = ui.comboEncoder->itemText(index); + QString encoder = ui.comboEncoder->itemData(index).toString(); EncBase* enc = getEncoder(encoder); enc->setCfg(settings); @@ -583,7 +587,8 @@ void Config::cacheClear() void Config::configTts() { - TTSBase* tts =getTTS(ui.comboTts->currentText()); + int index = ui.comboTts->currentIndex(); + TTSBase* tts = getTTS(ui.comboTts->itemData(index).toString()); tts->setCfg(settings); tts->showCfg(); @@ -593,7 +598,8 @@ void Config::configTts() void Config::configEnc() { - EncBase* enc =getEncoder(ui.comboEncoder->currentText()); + int index = ui.comboEncoder->currentIndex(); + EncBase* enc = getEncoder(ui.comboEncoder->itemData(index).toString()); enc->setCfg(settings); enc->showCfg(); diff --git a/rbutil/rbutilqt/createvoicewindow.cpp b/rbutil/rbutilqt/createvoicewindow.cpp index 6d760f14f..5375182fd 100644 --- a/rbutil/rbutilqt/createvoicewindow.cpp +++ b/rbutil/rbutilqt/createvoicewindow.cpp @@ -94,7 +94,7 @@ void CreateVoiceWindow::setSettings(RbSettings* sett) TTSBase* tts = getTTS(ttsName); tts->setCfg(settings); if(tts->configOk()) - ui.labelTtsProfile->setText(tr("Selected TTS engine : %1").arg(ttsName)); + ui.labelTtsProfile->setText(tr("Selected TTS engine : %1").arg(getTTSName(ttsName))); else ui.labelTtsProfile->setText(tr("Selected TTS Engine: %1").arg("Invalid TTS configuration!")); @@ -104,7 +104,7 @@ void CreateVoiceWindow::setSettings(RbSettings* sett) if(enc != NULL) { enc->setCfg(settings); if(enc->configOk()) - ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg(encoder)); + ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg(getEncoderName(encoder))); else ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg("Invalid encoder configuration!")); } diff --git a/rbutil/rbutilqt/encoders.cpp b/rbutil/rbutilqt/encoders.cpp index 1399ddff7..bb5474ce4 100644 --- a/rbutil/rbutilqt/encoders.cpp +++ b/rbutil/rbutilqt/encoders.cpp @@ -26,56 +26,55 @@ static QMap encoderList; static QMap encoderCache; - -void initEncoderList() + + +// initialize list of encoders +void initEncodernamesList() { encoderList["rbspeex"] = "Rockbox Speex Encoder"; encoderList["lame"] = "Lame Mp3 Encoder"; } -// function to get a specific encoder -EncBase* getEncoder(QString encname) + +// get nice name for a specific encoder +QString getEncoderName(QString encoder) +{ + if(encoderList.isEmpty()) + initEncodernamesList(); + return encoderList.value(encoder); +} + + +// get a specific encoder object +EncBase* getEncoder(QString encoder) { - // init list if its empty - if(encoderList.count() == 0) initEncoderList(); - - QString encoder = encoderList.key(encname); - // check cache if(encoderCache.contains(encoder)) return encoderCache.value(encoder); - - EncBase* enc; + + EncBase* enc; if(encoder == "rbspeex") { enc = new EncRbSpeex(); - encoderCache[encoder] = enc; + encoderCache[encoder] = enc; return enc; } else if(encoder == "lame") { enc = new EncExes(encoder); - encoderCache[encoder] = enc; + encoderCache[encoder] = enc; return enc; } else return NULL; } -// get the list of encoders, nice names + QStringList getEncoderList() { - // init list if its empty - if(encoderList.count() == 0) initEncoderList(); - - QStringList encList; - QMapIterator i(encoderList); - while (i.hasNext()) { - i.next(); - encList << i.value(); - } - - return encList; + if(encoderList.isEmpty()) + initEncodernamesList(); + return encoderList.keys(); } diff --git a/rbutil/rbutilqt/encoders.h b/rbutil/rbutilqt/encoders.h index 7a234a3b6..64d57b0ff 100644 --- a/rbutil/rbutilqt/encoders.h +++ b/rbutil/rbutilqt/encoders.h @@ -32,11 +32,12 @@ extern "C" class EncBase; //inits the encoder List -void initEncoderList(); +void initEncodernamesList(void); // function to get a specific encoder EncBase* getEncoder(QString encname); // get the list of encoders, nice names -QStringList getEncoderList(); +QString getEncoderName(QString encoder); +QStringList getEncoderList(void); class EncBase : public QDialog @@ -45,7 +46,8 @@ class EncBase : public QDialog public: EncBase(QWidget *parent ); - virtual bool encode(QString input,QString output){return false;} + virtual bool encode(QString input,QString output) + {(void)input; (void)output; return false;} virtual bool start(){return false;} virtual bool stop(){return false;} virtual void showCfg(){} diff --git a/rbutil/rbutilqt/installtalkwindow.cpp b/rbutil/rbutilqt/installtalkwindow.cpp index 2fa69b719..4fd1fb15f 100644 --- a/rbutil/rbutilqt/installtalkwindow.cpp +++ b/rbutil/rbutilqt/installtalkwindow.cpp @@ -114,7 +114,7 @@ void InstallTalkWindow::setSettings(RbSettings* sett) TTSBase* tts = getTTS(ttsName); tts->setCfg(settings); if(tts->configOk()) - ui.labelTtsProfile->setText(tr("Selected TTS engine : %1").arg(ttsName)); + ui.labelTtsProfile->setText(tr("Selected TTS engine : %1").arg(getTTSName(ttsName))); else ui.labelTtsProfile->setText(tr("Selected TTS Engine: %1").arg("Invalid TTS configuration!")); @@ -123,7 +123,7 @@ void InstallTalkWindow::setSettings(RbSettings* sett) if(enc != NULL) { enc->setCfg(settings); if(enc->configOk()) - ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg(encoder)); + ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg(getEncoderName(encoder))); else ui.labelEncProfile->setText(tr("Selected Encoder: %1").arg("Invalid encoder configuration!")); } diff --git a/rbutil/rbutilqt/tts.cpp b/rbutil/rbutilqt/tts.cpp index da15497c1..eb78f3100 100644 --- a/rbutil/rbutilqt/tts.cpp +++ b/rbutil/rbutilqt/tts.cpp @@ -36,18 +36,13 @@ void initTTSList() } // function to get a specific encoder -TTSBase* getTTS(QString ttsname) +TTSBase* getTTS(QString ttsName) { - // init list if its empty - if(ttsList.count() == 0) initTTSList(); - - QString ttsName = ttsList.key(ttsname); - // check cache if(ttsCache.contains(ttsName)) return ttsCache.value(ttsName); - - TTSBase* tts; + + TTSBase* tts; if(ttsName == "sapi") { tts = new TTSSapi(); @@ -66,18 +61,18 @@ TTSBase* getTTS(QString ttsname) QStringList getTTSList() { // init list if its empty - if(ttsList.count() == 0) initTTSList(); + if(ttsList.count() == 0) + initTTSList(); - QStringList ttsNameList; - QMapIterator i(ttsList); - while (i.hasNext()) { - i.next(); - ttsNameList << i.value(); - } - - return ttsNameList; + return ttsList.keys(); } +QString getTTSName(QString tts) +{ + if(ttsList.isEmpty()) + initTTSList(); + return ttsList.value(tts); +} /********************************************************************* * TTS Base diff --git a/rbutil/rbutilqt/tts.h b/rbutil/rbutilqt/tts.h index 9c73bfa5e..40fd4c727 100644 --- a/rbutil/rbutilqt/tts.h +++ b/rbutil/rbutilqt/tts.h @@ -37,6 +37,7 @@ void initTTSList(); TTSBase* getTTS(QString ttsname); // get the list of tts, nice names QStringList getTTSList(); +QString getTTSName(QString tts); class TTSBase : public QObject @@ -44,8 +45,8 @@ class TTSBase : public QObject Q_OBJECT public: TTSBase(); - virtual bool voice(QString text,QString wavfile) {return false;} - virtual bool start(QString *errStr){return false;} + virtual bool voice(QString text,QString wavfile) {(void)text; (void)wavfile; return false;} + virtual bool start(QString *errStr){(void)errStr; return false;} virtual bool stop(){return false;} virtual void showCfg(){} virtual bool configOk(){return false;} -- 2.11.4.GIT