1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 This file is the template for the processing plug ins.
4 Copyright : (C) 2002-2003 by José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
6 Original author: José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
7 Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
8 ******************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; version 2 of the License. *
16 ***************************************************************************/
18 // PlugInProc includes.
19 #include "pluginproc.h"
20 #include "pluginproc.moc"
23 #include <QtCore/QTextCodec>
27 #include <kstandarddirs.h>
33 PlugInProc::PlugInProc( QObject
*parent
, const char *name
) : QObject(parent
){
35 // kDebug() << "PlugInProc::PlugInProc: Running";
41 PlugInProc::~PlugInProc(){
42 // kDebug() << "PlugInProc::~PlugInProc: Running";
46 * Initializate the speech plugin.
48 bool PlugInProc::init(KConfig
* /*config*/, const QString
& /*configGroup*/){
49 // kDebug() << "PlugInProc::init: Running";
54 * Say a text. Synthesize and audibilize it.
55 * @param text The text to be spoken.
57 * If the plugin supports asynchronous operation, it should return immediately.
59 void PlugInProc::sayText(const QString
& /*text*/){
60 // kDebug() << "PlugInProc::sayText: Running";
64 * Synthesize text into an audio file, but do not send to the audio device.
65 * @param text The text to be synthesized.
66 * @param suggestedFilename Full pathname of file to create. The plugin
67 * may ignore this parameter and choose its own
68 * filename. KTTSD will query the generated
69 * filename using getFilename().
71 * If the plugin supports asynchronous operation, it should return immediately.
73 void PlugInProc::synthText(const QString
& /*text*/, const QString
& /*suggestedFilename*/) { }
76 * Get the generated audio filename from synthText.
77 * @return Name of the audio file the plugin generated.
78 * Null if no such file.
80 * The plugin must not re-use the filename.
82 QString
PlugInProc::getFilename() { return QString(); }
85 * Stop current operation (saying or synthesizing text).
86 * This function only makes sense in asynchronus modes.
87 * The plugin should return to the psIdle state.
89 void PlugInProc::stopText(){
90 // kDebug() << "PlugInProc::stopText: Running";
94 * Return the current state of the plugin.
95 * This function only makes sense in asynchronous mode.
96 * @return The pluginState of the plugin.
100 pluginState
PlugInProc::getState() { return psIdle
; }
103 * Acknowledges a finished state and resets the plugin state to psIdle.
105 * If the plugin is not in state psFinished, nothing happens.
106 * The plugin may use this call to do any post-processing cleanup,
107 * for example, blanking the stored filename (but do not delete the file).
108 * Calling program should call getFilename prior to ackFinished.
110 void PlugInProc::ackFinished() { }
113 * Returns True if the plugin supports asynchronous processing,
114 * i.e., returns immediately from sayText or synthText.
115 * @return True if this plugin supports asynchronous processing.
117 bool PlugInProc::supportsAsync() { return false; }
120 * Returns True if the plugin supports synthText method,
121 * i.e., is able to synthesize text to a sound file without
122 * audibilizing the text.
123 * @return True if this plugin supports synthText method.
125 bool PlugInProc::supportsSynth() { return false; }
128 * Returns the name of an XSLT stylesheet that will convert a valid SSML file
129 * into a format that can be processed by the synth. For example,
130 * The Festival plugin returns a stylesheet that will convert SSML into
131 * SABLE. Any tags the synth cannot handle should be stripped (leaving
132 * their text contents though). The default stylesheet strips all
133 * tags and converts the file to plain text.
134 * @return Name of the XSLT file.
136 QString
PlugInProc::getSsmlXsltFilename()
138 return KGlobal::dirs()->resourceDirs("data").last() + "kttsd/xslt/SSMLtoPlainText.xsl";
142 * Given the name of a codec, returns the QTextCodec for the name.
143 * Handles the following "special" codec names:
144 * Local The user's current Locale codec.
145 * Latin1 Latin1 (ISO 8859-1)
147 * @param codecName Name of desired codec.
148 * @return The codec object. Calling program must not delete this object
149 * as it is a reference to an existing QTextCodec object.
151 * Caution: Do not pass translated codec names to this routine.
153 /*static*/ QTextCodec
* PlugInProc::codecNameToCodec(const QString
&codecName
)
155 QTextCodec
* codec
= 0;
156 if (codecName
== "Local")
157 codec
= QTextCodec::codecForLocale();
158 else if (codecName
== "Latin1")
159 codec
= QTextCodec::codecForName("ISO8859-1");
160 else if (codecName
== "Unicode")
161 codec
= QTextCodec::codecForName("utf16");
163 codec
= QTextCodec::codecForName(codecName
.toLatin1());
166 kDebug() << "PluginProc::codecNameToCodec: Invalid codec name " << codecName
;
167 kDebug() << "PluginProc::codecNameToCodec: Defaulting to ISO 8859-1";
168 codec
= QTextCodec::codecForName("ISO8859-1");
174 * Builds a list of codec names, suitable for display in a QComboBox.
175 * The list includes the 3 special codec names (translated) at the top:
176 * Local The user's current Locale codec.
177 * Latin1 Latin1 (ISO 8859-1)
180 /*static*/ QStringList
PlugInProc::buildCodecList()
182 // kDebug() << "PlugInConf::buildCodecList: Running";
183 QStringList codecList
;
184 QString local
= i18n("Local")+" (";
185 local
+= QTextCodec::codecForLocale()->name();
187 codecList
.append(local
);
188 codecList
.append(i18n("Latin1"));
189 codecList
.append(i18n("Unicode"));
190 QList
<QByteArray
> availableCodecs
= QTextCodec::availableCodecs();
191 for (int i
= 0; i
< availableCodecs
.size(); ++i
)
192 codecList
.append(availableCodecs
.at(i
));
197 * Given the name of a codec, returns index into the codec list.
198 * Handles the following "special" codec names:
199 * Local The user's current Locale codec.
200 * Latin1 Latin1 (ISO 8859-1)
202 * @param codecName Name of the codec.
203 * @param codecList List of codec names. The first 3 entries may be translated names.
204 * @return QTextCodec object. Caller must not delete this object.
206 * Caution: Do not pass translated codec names to this routine in codecName parameter.
208 /*static*/ int PlugInProc::codecNameToListIndex(const QString
&codecName
, const QStringList
&codecList
)
211 if (codecName
== "Local")
212 codec
= PlugInProc::Local
;
213 else if (codecName
== "Latin1")
214 codec
= PlugInProc::Latin1
;
215 else if (codecName
== "Unicode")
216 codec
= PlugInProc::Unicode
;
218 codec
= PlugInProc::Local
;
219 const uint codecListCount
= codecList
.count();
220 for (uint i
= PlugInProc::UseCodec
; i
< codecListCount
; ++i
)
221 if (codecName
== codecList
[i
])
228 * Given index into codec list, returns the codec object.
229 * @param codecNum Index of the codec.
230 * @param codecList List of codec names. The first 3 entries may be translated names.
231 * @return QTextCodec object. Caller must not delete this object.
233 /*static*/ QTextCodec
* PlugInProc::codecIndexToCodec(int codecNum
, const QStringList
&codecList
)
235 QTextCodec
* codec
= 0;
237 case PlugInProc::Local
:
238 codec
= QTextCodec::codecForLocale();
240 case PlugInProc::Latin1
:
241 codec
= QTextCodec::codecForName("ISO8859-1");
243 case PlugInProc::Unicode
:
244 codec
= QTextCodec::codecForName("utf16");
247 codec
= QTextCodec::codecForName(codecList
[codecNum
].toLatin1());
252 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum
;
253 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
254 codec
= QTextCodec::codecForName("ISO8859-1");
260 * Given index into codec list, returns the codec Name.
261 * Handles the following "special" codec names:
262 * Local The user's current Locale codec.
263 * Latin1 Latin1 (ISO 8859-1)
265 * @param codecNum Index of the codec.
266 * @param codecList List of codec names. The first 3 entries may be translated names.
267 * @return Untranslated name of the codec.
269 /*static*/ QString
PlugInProc::codecIndexToCodecName(int codecNum
, const QStringList
&codecList
)
273 case PlugInProc::Local
:
276 case PlugInProc::Latin1
:
277 codecName
= "Latin1";
279 case PlugInProc::Unicode
:
280 codecName
= "Unicode";
283 if (codecNum
< codecList
.count())
284 codecName
= codecList
[codecNum
];
287 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum
;
288 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
289 codecName
= "ISO8859-1";