Let qmake generate an install Makefile target to install the binary. Doesn't handle...
[Rockbox.git] / rbutil / rbutilqt / ttsgui.cpp
blob3ed2e87f0e75b6497f37811cface9d835d46b42c
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)));
33 connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int)));
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"));
43 if(settings->ttsUseSapi4())
44 ui.usesapi4->setCheckState(Qt::Checked);
45 else
46 ui.usesapi4->setCheckState(Qt::Unchecked);
48 // fill in language combobox
49 QStringList languages = settings->allLanguages();
51 languages.sort();
52 ui.languagecombo->clear();
53 ui.languagecombo->addItems(languages);
55 // set saved lang
56 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang));
58 // fill in voice combobox
59 updateVoices(selLang);
61 // set saved lang
62 ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice));
64 //show dialog
65 this->exec();
70 void TTSSapiGui::reset()
72 ui.ttsoptions->setText("");
73 ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english"));
78 void TTSSapiGui::accept(void)
80 //save settings in user config
81 settings->setTTSOptions("sapi",ui.ttsoptions->text());
82 settings->setTTSLang("sapi",ui.languagecombo->currentText());
83 settings->setTTSVoice("sapi",ui.voicecombo->currentText());
84 settings->setTTSSpeed("sapi",ui.speed->value());
85 if(ui.usesapi4->checkState() == Qt::Checked)
86 settings->setTTSUseSapi4(true);
87 else
88 settings->setTTSUseSapi4(false);
89 // sync settings
90 settings->sync();
92 this->close();
95 void TTSSapiGui::reject(void)
97 this->close();
100 void TTSSapiGui::updateVoices(QString language)
102 QStringList Voices = m_sapi->getVoiceList(language);
103 ui.voicecombo->clear();
104 ui.voicecombo->addItems(Voices);
108 void TTSSapiGui::useSapi4Changed(int)
110 if(ui.usesapi4->checkState() == Qt::Checked)
111 settings->setTTSUseSapi4(true);
112 else
113 settings->setTTSUseSapi4(false);
114 // sync settings
115 settings->sync();
116 updateVoices(ui.languagecombo->currentText());
120 TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent)
122 ui.setupUi(this);
123 this->hide();
124 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
125 connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
129 void TTSExesGui::reset()
131 ui.ttspath->setText("");
132 ui.ttsoptions->setText("");
135 void TTSExesGui::showCfg(QString name)
137 m_name = name;
138 // try to get config from settings
139 QString exepath =settings->ttsPath(m_name);
140 ui.ttsoptions->setText(settings->ttsOptions(m_name));
142 if(exepath == "")
145 //try autodetect tts
146 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
147 QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
148 #elif defined(Q_OS_WIN)
149 QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
150 #endif
151 qDebug() << path;
152 for(int i = 0; i < path.size(); i++)
154 QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name;
155 #if defined(Q_OS_WIN)
156 executable += ".exe";
157 QStringList ex = executable.split("\"", QString::SkipEmptyParts);
158 executable = ex.join("");
159 #endif
160 qDebug() << executable;
161 if(QFileInfo(executable).isExecutable())
163 exepath= QDir::toNativeSeparators(executable);
164 break;
170 ui.ttspath->setText(exepath);
172 //show dialog
173 this->exec();
177 void TTSExesGui::accept(void)
179 //save settings in user config
180 settings->setTTSPath(m_name,ui.ttspath->text());
181 settings->setTTSOptions(m_name,ui.ttsoptions->text());
182 // sync settings
183 settings->sync();
185 this->close();
188 void TTSExesGui::reject(void)
190 this->close();
194 void TTSExesGui::browse()
196 BrowseDirtree browser(this);
197 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
199 if(QFileInfo(ui.ttspath->text()).isDir())
201 browser.setDir(ui.ttspath->text());
203 if(browser.exec() == QDialog::Accepted)
205 qDebug() << browser.getSelected();
206 QString exe = browser.getSelected();
207 if(!QFileInfo(exe).isExecutable())
208 return;
209 ui.ttspath->setText(exe);