global typo fix
[kdeaccessibility.git] / kttsd / libkttsd / pluginconf.h
blob2dd6ef2e43d36817659d560e1e80bc9e982f76d9
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 This file is the template for the configuration 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 #ifndef PLUGINCONF_H
20 #define PLUGINCONF_H
22 // Qt includes.
23 #include <QtGui/QWidget>
25 // KDE includes.
26 #include <kconfig.h>
27 #include <kdebug.h>
28 #include <kdemacros.h>
30 // KTTS includes.
31 #include "testplayer.h"
33 /**
34 * @interface PlugInConf
36 * pluginconf - the KDE Text-to-Speech Daemon Plugin Configuration API.
38 * @version 1.0 Draft 2
40 * This class defines the interface that plugins to KTTSMGR must implement.
42 * @warning The pluginconf interface is still being developed and is likely
43 * to change in the future.
45 * A KTTSD Plugin interfaces between KTTSD and a speech engine.
46 * A PlugInConf provides an on-screen widget for configuring the plugin for use
47 * with KTTSD.
49 * @section guidelines General Guidelines
51 * - The configuration widget should be no larger than TODO pixels.
52 * - Do not supply Load, Save, Cancel, or OK buttons. Those are provided by KTTSMGR.
53 * - Try to supply a Test button so that users can test the configuration before
54 * saving it.
55 * - Your configuration widget will be running inside a KPart.
56 * - Whenever the user changes something in your on-screen widget, emit the
57 * @ref changed signal.
58 * - If a plugin can automatically configure itself, i.e., locate voice files,
59 * set default values, etc., it should do so when it is first added to KTTSMGR.
61 * @section multiinstance Multiple Instances
63 * If it is possible to run multiple simultaneous instances of your synthesis engine,
64 * return True from the @ref supportsMultiInstance method. The user will be able to
65 * configure multiple instances of your plugin, each with a different set of
66 * talker attributes.
68 * If you cannot run multiple simultaneous instances of your synthesis engine,
69 * or your plugin has a fixed set of talker attributes (only one language, voice,
70 * gender, volume, and speed), return False from @ref supportsMultiInstance.
72 * @section language Language Support
74 * Some plugins support only one language. For them, return the appropriate language
75 * code when @ref getSupportedLanguages is called.
77 * If your plugin can support multiple languages, your task is a little more
78 * complicated. The best way to handle this is to install a @e voices file with
79 * your plugin that lists all the supported languages, voice files, genders, etc.
80 * that are possible. When your plugin is added to KTTSMGR,
81 * @ref getSupportedLanguages will be called. Return a list of all the possible
82 * languages supported, even if the user hasn't yet picked a voice file in your
83 * configuration, or even told your where the voice files are.
85 * There are three ways that users and applications pick a language code for your
86 * plugin:
87 * - The user picks a code from among the languages you returned in
88 * @ref getSupportedLanguages, or
89 * - The user picks your plugin and uses your configuration widget to pick a voice
90 * file or other configuration option that determines the language, or
91 * - An application requests a plugin with specific language support.
93 * If possible, avoid making the user pick a language code in your plugin.
95 * In the first and third cases, the chosen language code will be passed to your
96 * plugin when @ref setDesiredLanguage is called. If you can satisfy this
97 * language code, good, but it is possible that once the user has begun
98 * configuring your plugin, you find that you cannot support the desired
99 * language. Perhaps a needed voice file is missing. That is OK.
100 * You'll inform KTTSMGR of the actual language code when KTTSMGR
101 * calls @ref getTalkerCode (see below). Note that you should not limit the
102 * users choices based on the @ref setDesiredLanguage. A user might start
103 * out configuring your plugin for one language, and then change his or her
104 * mind to a different language.
106 * Also note that language codes may also include an appended country code.
107 * For example, "en_GB" for British English. When @ref getSupportedLanguages is
108 * called, you should return as specific a list as possible. For example,
109 * if your plugin supports both American and British English, your returned
110 * list would include "en_GB" and "en_US". When @ref setDesiredLanguage is
111 * called, a country code may or may not be included. If included and your
112 * plugin supports the language, but not the specific country variant,
113 * your plugin should nevertheless attempt to satisfy the request, returning
114 * the actual supported language and country when @ref getTalkerCode is called.
116 * @section talkercodes Talker Codes
118 * Review the section on Talkers in kspeech.h.
120 * When your plugin is added to the KTTSMGR, @ref getSupportedLanguages
121 * will be called followed by @ref setDesiredLanguage and @ref load.
122 * Note that the configuration file will most likely be empty when
123 * @ref load is called.
125 * Next, @ref getTalkerCode
126 * will be called. If your plugin can automatically configure itself to the desired
127 * language, it should do so and return a fully-specified talker code. If your
128 * plugin is not yet ready and requires user help, return QString(). Note that
129 * @ref setDesiredLanguage may be Null, in which case, you should allow the
130 * user to configure your plugin to any of your supported languages.
132 * When your plugin has been configured enough to begin synthesis, return a
133 * fully-specified talker code in @ref getTalkerCode().
135 * Here is guidance for what you should return for each of the talker attributes
136 * when @ref getTalkerCode is called:
138 * - @e lang. If user has completed configuring your plugin, i.e., it is
139 * ready to begin synthesizing, return the ISO 639-1 language code
140 * for the language it can synthesize. If your plugin is not yet
141 * fully configured, you should return QString() for the entire
142 * talker code. If your plugin supports a specific national version
143 * of a language, that should also be included using the ISO 3166
144 * country code separated from the language code by underscore (_).
145 * For example, if your plugin synthesizes American English, you would
146 * return "en_US". If British English, "en_BR". And if
147 * non-specific English, just "en".
148 * - @e synthesizer. The name of your plugin. Keep short, but long enough to
149 * distinquish different implementations. For example,
150 * Festival Int, Flite, Hadifix. Use only letters, numbers
151 * spaces, and underscores (_) in your plugin name.
152 * - @e gender. May be "male", "female", or "neutral".
153 * - @e name. The voice code. If your plugin does not support voices,
154 * return "fixed".
155 * - @e volume. May be "medium", "loud", or "soft". If your plugin does not support
156 * configurable volume, return "medium".
157 * - @e rate. May be "medium", "fast", or "slow". If your plugin does not support
158 * configurable speed, return "medium".
160 * The order of the attributes you return does not matter. Here is an example of
161 * a fully-specified talker code.
163 * lang="en" name="Kal" gender="male" volume="soft" rate="fast"
164 * synthesizer="Festival Interactive"
166 * Do not return translated values for the Talker Code attributes. All English.
168 * Each time your plugin emits the @ref changed signal, @ref getTalkerCode will be called.
169 * The configuration dialog OK button will be disabled until you return a non-null
170 * Talker Code.
172 * It is possible that your plugin does not know the language supported. The generic
173 * Command plugin is example of such a case, since the user enters an arbitrary command.
174 * In this case, return the value from the @ref setDesiredLanguage call. It is possible
175 * that @ref setDesiredLanguage is Null. That is OK. In this case, KTTSMGR will prompt
176 * the user for the language code.
178 * @section loadandsavemethods Load and Save Methods
180 * The @ref load and @ref save methods are called by KTTSMGR so that your plugin
181 * can load and save configuration options from the configuration file.
182 * These methods have two parameters, a @e config object and a @e configGroup string.
184 * Plugins that do not support multiple instances (return False from
185 * @ref supportsMultiInstance), should simply call config->setGroup(configGroup)
186 * before loading or saving their configuration.
188 * If your plugin supports multiple instances, it is slightly more complicated.
189 * Typically, there will be configuration options that apply to all instances
190 * of the plugin and there will be options that apply only to the specific
191 * configured instance of the plugin. To load or save the instance-specific
192 * options, call config->setGroup(configGroup). For options that apply
193 * to all instances of the plugin, call config->setGroup() with a group name
194 * that contains your plugin's name. For example,
195 * config->setGroup("Festival Defaults").
197 * For example, when first added to KTTSMGR, the Festival plugin needs to know the path to
198 * the directory containing all the installed voice files. It is best for a plugin
199 * to try to locate these resources automatically, but if it can't find them,
200 * when the user has told it where they are, it is a good idea to save this information
201 * in the all-instances group. In this way, the next time the plugin
202 * is added to KTTSMGR, or another instance is added, it will be able to find them
203 * automatically.
205 * @ref setDesiredLanguage is always called just prior to @ref load, therefore
206 * it is not necessary to save the language code, unless your plugin needs it in
207 * order to synthesize speech.
210 class KDE_EXPORT PlugInConf : public QWidget{
211 Q_OBJECT
213 public:
215 * Constructor
217 explicit PlugInConf( QWidget *parent = 0, const char *name = 0);
220 * Destructor
222 virtual ~PlugInConf();
225 * This method is invoked whenever the module should read its
226 * configuration (most of the times from a config file) and update the
227 * user interface. This happens when the user clicks the "Reset" button in
228 * the control center, to undo all of his changes and restore the currently
229 * valid settings. Note that KTTSMGR calls this when the plugin is
230 * loaded, so it not necessary to call it in your constructor.
231 * The plugin should read its configuration from the specified group
232 * in the specified config file.
233 * @param config Pointer to a KConfig object.
234 * @param configGroup Call config->setGroup with this argument before
235 * loading your configuration.
237 * When a plugin is first added to KTTSMGR, @e load will be called with
238 * a Null @e configGroup. In this case, the plugin will not have
239 * any instance-specific parameters to load, but it may still wish
240 * to load parameters that apply to all instances of the plugin.
242 * @see loadandsavemethods
244 virtual void load(KConfig *config, const QString &configGroup);
247 * This function gets called when the user wants to save the settings in
248 * the user interface, updating the config files or wherever the
249 * configuration is stored. The method is called when the user clicks "Apply"
250 * or "Ok". The plugin should save its configuration in the specified
251 * group of the specified config file.
252 * @param config Pointer to a KConfig object.
253 * @param configGroup Call config->setGroup with this argument before
254 * saving your configuration.
256 * @ref setDesiredLanguage is always called just prior to @ref load, therefore
257 * it is not necessary to save the language code, unless your plugin needs it in
258 * order to synthesize speech.
260 virtual void save(KConfig *config, const QString &configGroup);
262 /**
263 * This function is called to set the settings in the module to sensible
264 * default values. It gets called when hitting the "Default" button. The
265 * default values should probably be the same as the ones the application
266 * uses when started without a config file. Note that defaults should
267 * be applied to the on-screen widgets; not to the config file.
269 virtual void defaults();
272 * Indicates whether the plugin supports multiple instances. Return
273 * False if only one instance of the plugin can run at a time, or
274 * if your plugin is limited to a single language, voice, gender, volume,
275 * and speed.
276 * @return True if multiple instances are possible.
278 virtual bool supportsMultiInstance();
281 * This function informs the plugin of the desired language to be spoken
282 * by the plugin. The plugin should attempt to adapt itself to the
283 * specified language code, choosing sensible defaults if necessary.
284 * If the passed-in code is QString(), no specific language has
285 * been chosen.
286 * @param lang The desired language code or Null if none.
288 * If the plugin is unable to support the desired language, that is OK.
289 * Language codes are given by ISO 639-1 and are in lowercase.
290 * The code may also include an ISO 3166 country code in uppercase
291 * separated from the language code by underscore (_). For
292 * example, en_GB. If your plugin supports the given language, but
293 * not the given country, treat it as though the country
294 * code were not specified, i.e., adapt to the given language.
296 virtual void setDesiredLanguage(const QString &lang);
299 * Return fully-specified talker code for the configured plugin. This code
300 * uniquely identifies the configured instance of the plugin and distinquishes
301 * one instance from another. If the plugin has not been fully configured,
302 * i.e., cannot yet synthesize, return QString().
303 * @return Fully-specified talker code.
305 virtual QString getTalkerCode();
308 * Return a list of all the languages possibly supported by the plugin.
309 * If your plugin can support any language, return Null.
310 * @return A QStringList of supported language and optional country
311 * codes, or Null if any.
313 * The languge codes are given in ISO 639-1. Lowercase should be used.
314 * If your plugin supports various national forms of a language, ISO 3166
315 * country codes should also be include in upperase and separated from
316 * the language code with underscore (_). Examples:
317 * en
318 * en_US
319 * en_GB
320 * es
321 * es_CL
322 * The list you return should be as specific as practicable.
324 virtual QStringList getSupportedLanguages();
327 * Player object that can be used by the plugin for testing playback of synthed files.
329 void setPlayer(TestPlayer* player);
330 TestPlayer* getPlayer();
332 static QString realFilePath(const QString &filename);
334 static QString testMessage(const QString& languageCode);
336 public slots:
338 * This slot is used internally when the configuration is changed. It is
339 * typically connected to signals from the widgets of the configuration
340 * and should emit the @ref changed signal.
342 void configChanged(){
343 kDebug() << "PlugInConf::configChanged: Running";
344 emit changed(true);
347 signals:
349 * This signal indicates that the configuration has been changed.
350 * It should be emitted whenever user changes something in the configuration widget.
352 void changed(bool);
354 protected:
356 * Searches the $PATH variable for any file. If that file exists in the PATH, or
357 * is contained in any directory in the PATH, it returns the full path to it.
358 * @param name The name of the file to search for.
359 * @returns The path to the file on success, a blank QString
360 * if it is not found.
362 QString getLocation(const QString &name);
365 * Breaks a language code into the language code and country code (if any).
366 * @param languageCode Language code.
367 * @return countryCode Just the country code part (if any).
368 * @return Just the language code part.
370 QString splitLanguageCode(const QString& languageCode, QString& countryCode);
372 /// The system path in a QStringList.
373 QStringList m_path;
375 TestPlayer* m_player;
378 #endif //PLUGINCONF_H