Redo my previous segfault fix in a better way.
[Rockbox.git] / rbutil / rbutilqt / ttsgui.cpp
blob76488c541130368f0db0bf803f364c0d179d32cf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: tts.cpp 15212 2007-10-19 21:49:07Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "ttsgui.h"
22 #include "rbsettings.h"
23 #include "tts.h"
24 #include "browsedirtree.h"
26 TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent)
28 m_sapi= sapi;
29 ui.setupUi(this);
30 this->hide();
31 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
32 connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString)));
36 void TTSSapiGui::showCfg()
38 // try to get config from settings
39 ui.ttsoptions->setText(settings->ttsOptions("sapi"));
40 QString selLang = settings->ttsLang("sapi");
41 QString selVoice = settings->ttsVoice("sapi");
42 ui.speed->setValue(settings->ttsSpeed("sapi"));
45 // fill in language combobox
46 QStringList languages = settings->allLanguages();
48 languages.sort();
49 ui.languagecombo->clear();
50 ui.languagecombo->addItems(languages);
52 // set saved lang
53 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang));
55 // fill in voice combobox
56 updateVoices(selLang);
58 // set saved lang
59 ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice));
61 //show dialog
62 this->exec();
67 void TTSSapiGui::reset()
69 ui.ttsoptions->setText("");
70 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english"));
75 void TTSSapiGui::accept(void)
77 //save settings in user config
78 settings->setTTSOptions("sapi",ui.ttsoptions->text());
79 settings->setTTSLang("sapi",ui.languagecombo->currentText());
80 settings->setTTSVoice("sapi",ui.voicecombo->currentText());
81 settings->setTTSSpeed("sapi",ui.speed->value());
82 // sync settings
83 settings->sync();
85 this->close();
88 void TTSSapiGui::reject(void)
90 this->close();
93 void TTSSapiGui::updateVoices(QString language)
95 QStringList Voices = m_sapi->getVoiceList(language);
96 ui.voicecombo->clear();
97 ui.voicecombo->addItems(Voices);
101 TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent)
103 ui.setupUi(this);
104 this->hide();
105 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
106 connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
110 void TTSExesGui::reset()
112 ui.ttspath->setText("");
113 ui.ttsoptions->setText("");
116 void TTSExesGui::showCfg(QString name)
118 m_name = name;
119 // try to get config from settings
120 QString exepath =settings->ttsPath(m_name);
121 ui.ttsoptions->setText(settings->ttsOptions(m_name));
123 if(exepath == "")
126 //try autodetect tts
127 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
128 QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
129 #elif defined(Q_OS_WIN)
130 QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
131 #endif
132 qDebug() << path;
133 for(int i = 0; i < path.size(); i++)
135 QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name;
136 #if defined(Q_OS_WIN)
137 executable += ".exe";
138 QStringList ex = executable.split("\"", QString::SkipEmptyParts);
139 executable = ex.join("");
140 #endif
141 qDebug() << executable;
142 if(QFileInfo(executable).isExecutable())
144 exepath= QDir::toNativeSeparators(executable);
145 break;
151 ui.ttspath->setText(exepath);
153 //show dialog
154 this->exec();
158 void TTSExesGui::accept(void)
160 //save settings in user config
161 settings->setTTSPath(m_name,ui.ttspath->text());
162 settings->setTTSOptions(m_name,ui.ttsoptions->text());
163 // sync settings
164 settings->sync();
166 this->close();
169 void TTSExesGui::reject(void)
171 this->close();
175 void TTSExesGui::browse()
177 BrowseDirtree browser(this);
178 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
180 if(QFileInfo(ui.ttspath->text()).isDir())
182 browser.setDir(ui.ttspath->text());
184 if(browser.exec() == QDialog::Accepted)
186 qDebug() << browser.getSelected();
187 QString exe = browser.getSelected();
188 if(!QFileInfo(exe).isExecutable())
189 return;
190 ui.ttspath->setText(exe);