SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / libkttsd / pluginproc.cpp
blob86c747980c5030b16f776f71c4dd0d346147fbb0
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 This file is the template for the processing plug ins.
3 -------------------
4 Copyright : (C) 2002-2003 by José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
5 -------------------
6 Original author: José Pablo Ezequiel "Pupeno" Fernández <pupeno@kde.org>
7 Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
8 ******************************************************************************/
10 /***************************************************************************
11 * *
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 or *
15 * (at your option) version 3. *
16 * *
17 ***************************************************************************/
19 // PlugInProc includes.
20 #include "pluginproc.h"
21 #include "pluginproc.moc"
23 // Qt includes.
24 #include <QtCore/QTextCodec>
26 // KDE includes.
27 #include <kdebug.h>
28 #include <kstandarddirs.h>
29 #include <klocale.h>
31 /**
32 * Constructor
34 PlugInProc::PlugInProc( QObject *parent, const char *name) : QObject(parent){
35 setObjectName(name);
36 // kDebug() << "PlugInProc::PlugInProc: Running";
39 /**
40 * Destructor
42 PlugInProc::~PlugInProc(){
43 // kDebug() << "PlugInProc::~PlugInProc: Running";
46 /**
47 * Initializate the speech plugin.
49 bool PlugInProc::init(KConfig* /*config*/, const QString& /*configGroup*/){
50 // kDebug() << "PlugInProc::init: Running";
51 return false;
54 /**
55 * Say a text. Synthesize and audibilize it.
56 * @param text The text to be spoken.
58 * If the plugin supports asynchronous operation, it should return immediately.
60 void PlugInProc::sayText(const QString& /*text*/){
61 // kDebug() << "PlugInProc::sayText: Running";
64 /**
65 * Synthesize text into an audio file, but do not send to the audio device.
66 * @param text The text to be synthesized.
67 * @param suggestedFilename Full pathname of file to create. The plugin
68 * may ignore this parameter and choose its own
69 * filename. KTTSD will query the generated
70 * filename using getFilename().
72 * If the plugin supports asynchronous operation, it should return immediately.
74 void PlugInProc::synthText(const QString& /*text*/, const QString& /*suggestedFilename*/) { }
76 /**
77 * Get the generated audio filename from synthText.
78 * @return Name of the audio file the plugin generated.
79 * Null if no such file.
81 * The plugin must not re-use the filename.
83 QString PlugInProc::getFilename() { return QString(); }
85 /**
86 * Stop current operation (saying or synthesizing text).
87 * This function only makes sense in asynchronus modes.
88 * The plugin should return to the psIdle state.
90 void PlugInProc::stopText(){
91 // kDebug() << "PlugInProc::stopText: Running";
94 /**
95 * Return the current state of the plugin.
96 * This function only makes sense in asynchronous mode.
97 * @return The pluginState of the plugin.
99 * @ref pluginState
101 pluginState PlugInProc::getState() { return psIdle; }
104 * Acknowledges a finished state and resets the plugin state to psIdle.
106 * If the plugin is not in state psFinished, nothing happens.
107 * The plugin may use this call to do any post-processing cleanup,
108 * for example, blanking the stored filename (but do not delete the file).
109 * Calling program should call getFilename prior to ackFinished.
111 void PlugInProc::ackFinished() { }
114 * Returns True if the plugin supports asynchronous processing,
115 * i.e., returns immediately from sayText or synthText.
116 * @return True if this plugin supports asynchronous processing.
118 bool PlugInProc::supportsAsync() { return false; }
121 * Returns True if the plugin supports synthText method,
122 * i.e., is able to synthesize text to a sound file without
123 * audibilizing the text.
124 * @return True if this plugin supports synthText method.
126 bool PlugInProc::supportsSynth() { return false; }
129 * Returns the name of an XSLT stylesheet that will convert a valid SSML file
130 * into a format that can be processed by the synth. For example,
131 * The Festival plugin returns a stylesheet that will convert SSML into
132 * SABLE. Any tags the synth cannot handle should be stripped (leaving
133 * their text contents though). The default stylesheet strips all
134 * tags and converts the file to plain text.
135 * @return Name of the XSLT file.
137 QString PlugInProc::getSsmlXsltFilename()
139 return KGlobal::dirs()->resourceDirs("data").last() + "kttsd/xslt/SSMLtoPlainText.xsl";
143 * Given the name of a codec, returns the QTextCodec for the name.
144 * Handles the following "special" codec names:
145 * Local The user's current Locale codec.
146 * Latin1 Latin1 (ISO 8859-1)
147 * Unicode UTF-16
148 * @param codecName Name of desired codec.
149 * @return The codec object. Calling program must not delete this object
150 * as it is a reference to an existing QTextCodec object.
152 * Caution: Do not pass translated codec names to this routine.
154 /*static*/ QTextCodec* PlugInProc::codecNameToCodec(const QString &codecName)
156 QTextCodec* codec = 0;
157 if (codecName == "Local")
158 codec = QTextCodec::codecForLocale();
159 else if (codecName == "Latin1")
160 codec = QTextCodec::codecForName("ISO8859-1");
161 else if (codecName == "Unicode")
162 codec = QTextCodec::codecForName("utf16");
163 else
164 codec = QTextCodec::codecForName(codecName.toLatin1());
165 if (!codec)
167 kDebug() << "PluginProc::codecNameToCodec: Invalid codec name " << codecName;
168 kDebug() << "PluginProc::codecNameToCodec: Defaulting to ISO 8859-1";
169 codec = QTextCodec::codecForName("ISO8859-1");
171 return codec;
175 * Builds a list of codec names, suitable for display in a QComboBox.
176 * The list includes the 3 special codec names (translated) at the top:
177 * Local The user's current Locale codec.
178 * Latin1 Latin1 (ISO 8859-1)
179 * Unicode UTF-16
181 /*static*/ QStringList PlugInProc::buildCodecList()
183 // kDebug() << "PlugInConf::buildCodecList: Running";
184 QStringList codecList;
185 QString local = i18nc("Local charset", "Local")+" (";
186 local += QTextCodec::codecForLocale()->name();
187 local += ')';
188 codecList.append(local);
189 codecList.append(i18nc("Latin charset", "Latin1"));
190 codecList.append(i18n("Unicode"));
191 QList<QByteArray> availableCodecs = QTextCodec::availableCodecs();
192 for (int i = 0; i < availableCodecs.size(); ++i )
193 codecList.append(availableCodecs.at(i));
194 return codecList;
198 * Given the name of a codec, returns index into the codec list.
199 * Handles the following "special" codec names:
200 * Local The user's current Locale codec.
201 * Latin1 Latin1 (ISO 8859-1)
202 * Unicode UTF-16
203 * @param codecName Name of the codec.
204 * @param codecList List of codec names. The first 3 entries may be translated names.
205 * @return QTextCodec object. Caller must not delete this object.
207 * Caution: Do not pass translated codec names to this routine in codecName parameter.
209 /*static*/ int PlugInProc::codecNameToListIndex(const QString &codecName, const QStringList &codecList)
211 int codec;
212 if (codecName == "Local")
213 codec = PlugInProc::Local;
214 else if (codecName == "Latin1")
215 codec = PlugInProc::Latin1;
216 else if (codecName == "Unicode")
217 codec = PlugInProc::Unicode;
218 else {
219 codec = PlugInProc::Local;
220 const uint codecListCount = codecList.count();
221 for (uint i = PlugInProc::UseCodec; i < codecListCount; ++i )
222 if (codecName == codecList[i])
223 codec = i;
225 return codec;
229 * Given index into codec list, returns the codec object.
230 * @param codecNum Index of the codec.
231 * @param codecList List of codec names. The first 3 entries may be translated names.
232 * @return QTextCodec object. Caller must not delete this object.
234 /*static*/ QTextCodec* PlugInProc::codecIndexToCodec(int codecNum, const QStringList &codecList)
236 QTextCodec* codec = 0;
237 switch (codecNum) {
238 case PlugInProc::Local:
239 codec = QTextCodec::codecForLocale();
240 break;
241 case PlugInProc::Latin1:
242 codec = QTextCodec::codecForName("ISO8859-1");
243 break;
244 case PlugInProc::Unicode:
245 codec = QTextCodec::codecForName("utf16");
246 break;
247 default:
248 codec = QTextCodec::codecForName(codecList[codecNum].toLatin1());
249 break;
251 if (!codec)
253 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum;
254 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
255 codec = QTextCodec::codecForName("ISO8859-1");
257 return codec;
261 * Given index into codec list, returns the codec Name.
262 * Handles the following "special" codec names:
263 * Local The user's current Locale codec.
264 * Latin1 Latin1 (ISO 8859-1)
265 * Unicode UTF-16
266 * @param codecNum Index of the codec.
267 * @param codecList List of codec names. The first 3 entries may be translated names.
268 * @return Untranslated name of the codec.
270 /*static*/ QString PlugInProc::codecIndexToCodecName(int codecNum, const QStringList &codecList)
272 QString codecName;
273 switch (codecNum) {
274 case PlugInProc::Local:
275 codecName = "Local";
276 break;
277 case PlugInProc::Latin1:
278 codecName = "Latin1";
279 break;
280 case PlugInProc::Unicode:
281 codecName = "Unicode";
282 break;
283 default:
284 if (codecNum < codecList.count())
285 codecName = codecList[codecNum];
286 else
288 kDebug() << "PlugInProc::codecIndexToCodec: Invalid codec index " << codecNum;
289 kDebug() << "PlugInProc::codecIndexToCodec: Defaulting to ISO 8859-1";
290 codecName = "ISO8859-1";
293 return codecName;