diff options
Diffstat (limited to 'rbutil/rbutilqt/ttsgui.cpp')
-rw-r--r-- | rbutil/rbutilqt/ttsgui.cpp | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/ttsgui.cpp b/rbutil/rbutilqt/ttsgui.cpp new file mode 100644 index 0000000000..76488c5411 --- /dev/null +++ b/rbutil/rbutilqt/ttsgui.cpp | |||
@@ -0,0 +1,193 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Wenger | ||
10 | * $Id: tts.cpp 15212 2007-10-19 21:49:07Z domonoky $ | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "ttsgui.h" | ||
21 | |||
22 | #include "rbsettings.h" | ||
23 | #include "tts.h" | ||
24 | #include "browsedirtree.h" | ||
25 | |||
26 | TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) | ||
27 | { | ||
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 | |||
34 | } | ||
35 | |||
36 | void TTSSapiGui::showCfg() | ||
37 | { | ||
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 | |||
44 | |||
45 | // fill in language combobox | ||
46 | QStringList languages = settings->allLanguages(); | ||
47 | |||
48 | languages.sort(); | ||
49 | ui.languagecombo->clear(); | ||
50 | ui.languagecombo->addItems(languages); | ||
51 | |||
52 | // set saved lang | ||
53 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang)); | ||
54 | |||
55 | // fill in voice combobox | ||
56 | updateVoices(selLang); | ||
57 | |||
58 | // set saved lang | ||
59 | ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); | ||
60 | |||
61 | //show dialog | ||
62 | this->exec(); | ||
63 | |||
64 | } | ||
65 | |||
66 | |||
67 | void TTSSapiGui::reset() | ||
68 | { | ||
69 | ui.ttsoptions->setText(""); | ||
70 | ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); | ||
71 | } | ||
72 | |||
73 | |||
74 | |||
75 | void TTSSapiGui::accept(void) | ||
76 | { | ||
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(); | ||
84 | |||
85 | this->close(); | ||
86 | } | ||
87 | |||
88 | void TTSSapiGui::reject(void) | ||
89 | { | ||
90 | this->close(); | ||
91 | } | ||
92 | |||
93 | void TTSSapiGui::updateVoices(QString language) | ||
94 | { | ||
95 | QStringList Voices = m_sapi->getVoiceList(language); | ||
96 | ui.voicecombo->clear(); | ||
97 | ui.voicecombo->addItems(Voices); | ||
98 | |||
99 | } | ||
100 | |||
101 | TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) | ||
102 | { | ||
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())); | ||
107 | } | ||
108 | |||
109 | |||
110 | void TTSExesGui::reset() | ||
111 | { | ||
112 | ui.ttspath->setText(""); | ||
113 | ui.ttsoptions->setText(""); | ||
114 | } | ||
115 | |||
116 | void TTSExesGui::showCfg(QString name) | ||
117 | { | ||
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)); | ||
122 | |||
123 | if(exepath == "") | ||
124 | { | ||
125 | |||
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++) | ||
134 | { | ||
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()) | ||
143 | { | ||
144 | exepath= QDir::toNativeSeparators(executable); | ||
145 | break; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | } | ||
150 | |||
151 | ui.ttspath->setText(exepath); | ||
152 | |||
153 | //show dialog | ||
154 | this->exec(); | ||
155 | |||
156 | } | ||
157 | |||
158 | void TTSExesGui::accept(void) | ||
159 | { | ||
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(); | ||
165 | |||
166 | this->close(); | ||
167 | } | ||
168 | |||
169 | void TTSExesGui::reject(void) | ||
170 | { | ||
171 | this->close(); | ||
172 | } | ||
173 | |||
174 | |||
175 | void TTSExesGui::browse() | ||
176 | { | ||
177 | BrowseDirtree browser(this); | ||
178 | browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); | ||
179 | |||
180 | if(QFileInfo(ui.ttspath->text()).isDir()) | ||
181 | { | ||
182 | browser.setDir(ui.ttspath->text()); | ||
183 | } | ||
184 | if(browser.exec() == QDialog::Accepted) | ||
185 | { | ||
186 | qDebug() << browser.getSelected(); | ||
187 | QString exe = browser.getSelected(); | ||
188 | if(!QFileInfo(exe).isExecutable()) | ||
189 | return; | ||
190 | ui.ttspath->setText(exe); | ||
191 | } | ||
192 | } | ||
193 | |||