Support "eject" on OS X.
[maemo-rb.git] / rbutil / rbutilqt / base / ttsexes.cpp
blob5d06d6c1e630f473e4298eee8ac41b401b0ff2af
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include "ttsexes.h"
20 #include "utils.h"
21 #include "rbsettings.h"
23 TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent)
25 m_name = name;
27 m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
28 m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\"";
29 m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" -- \"%text\"";
33 TTSBase::Capabilities TTSExes::capabilities()
35 return RunInParallel;
38 void TTSExes::generateSettings()
40 loadSettings();
41 insertSetting(eEXEPATH, new EncTtsSetting(this, EncTtsSetting::eSTRING,
42 tr("Path to TTS engine:"), m_TTSexec, EncTtsSetting::eBROWSEBTN));
43 insertSetting(eOPTIONS, new EncTtsSetting(this, EncTtsSetting::eSTRING,
44 tr("TTS engine options:"), m_TTSOpts));
47 void TTSExes::saveSettings()
49 RbSettings::setSubValue(m_name,RbSettings::TtsPath,
50 getSetting(eEXEPATH)->current().toString());
51 RbSettings::setSubValue(m_name,RbSettings::TtsOptions,
52 getSetting(eOPTIONS)->current().toString());
53 RbSettings::sync();
57 void TTSExes::loadSettings(void)
59 m_TTSexec = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
60 if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
61 m_TTSOpts = RbSettings::subValue(m_name,RbSettings::TtsOptions).toString();
65 bool TTSExes::start(QString *errStr)
67 loadSettings();
68 m_TTSTemplate = m_TemplateMap.value(m_name);
70 QFileInfo tts(m_TTSexec);
71 if(tts.exists())
73 return true;
75 else
77 *errStr = tr("TTS executable not found");
78 return false;
82 TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
84 (void) errStr;
85 QString execstring = m_TTSTemplate;
87 execstring.replace("%exe",m_TTSexec);
88 execstring.replace("%options",m_TTSOpts);
89 execstring.replace("%wavfile",wavfile);
90 execstring.replace("%text",text);
92 QProcess::execute(execstring);
94 if(!QFileInfo(wavfile).isFile()) {
95 qDebug() << "[TTSExes] output file does not exist:" << wavfile;
96 return FatalError;
98 return NoError;
102 bool TTSExes::configOk()
104 loadSettings();
105 if (QFileInfo(m_TTSexec).exists())
106 return true;
107 else
108 return false;