1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 This file is the templates for the configuration 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 or *
15 * (at your option) version 3. *
17 ***************************************************************************/
19 // PluginConf includes.
20 #include "pluginconf.h"
21 #include "pluginconf.moc"
23 // C++ library includes.
25 #include <sys/param.h>
32 #include <QTextStream>
37 #include <kstandarddirs.h>
42 PlugInConf::PlugInConf( QWidget
*parent
, const char *name
) : QWidget(parent
){
44 kDebug() << "PlugInConf::PlugInConf: Running";
45 QString
systemPath(qgetenv("PATH"));
46 // kDebug() << "Path is " << systemPath;
47 m_path
= systemPath
.split( ':');
54 PlugInConf::~PlugInConf(){
55 kDebug() << "PlugInConf::~PlugInConf: Running";
60 * This method is invoked whenever the module should read its
61 * configuration (most of the times from a config file) and update the
62 * user interface. This happens when the user clicks the "Reset" button in
63 * the control center, to undo all of his changes and restore the currently
64 * valid settings. Note that kttsmgr calls this when the plugin is
65 * loaded, so it not necessary to call it in your constructor.
66 * The plugin should read its configuration from the specified group
67 * in the specified config file.
68 * @param config Pointer to a KConfig object.
69 * @param configGroup Call config->setGroup with this argument before
70 * loading your configuration.
72 void PlugInConf::load(KConfig
* /*config*/, const QString
& /*configGroup*/){
73 kDebug() << "PlugInConf::load: Running";
77 * This function gets called when the user wants to save the settings in
78 * the user interface, updating the config files or wherever the
79 * configuration is stored. The method is called when the user clicks "Apply"
80 * or "Ok". The plugin should save its configuration in the specified
81 * group of the specified config file.
82 * @param config Pointer to a KConfig object.
83 * @param configGroup Call config->setGroup with this argument before
84 * saving your configuration.
86 void PlugInConf::save(KConfig
* /*config*/, const QString
& /*configGroup*/){
87 kDebug() << "PlugInConf::save: Running";
91 * This function is called to set the settings in the module to sensible
92 * default values. It gets called when hitting the "Default" button. The
93 * default values should probably be the same as the ones the application
94 * uses when started without a config file. Note that defaults should
95 * be applied to the on-screen widgets; not to the config file.
97 void PlugInConf::defaults(){
98 kDebug() << "PlugInConf::defaults: Running";
102 * Indicates whether the plugin supports multiple instances. Return
103 * False if only one instance of the plugin can run at a time.
104 * @return True if multiple instances are possible.
106 * It is assumed that most plugins can support multiple instances.
107 * A plugin must override this method and return false if it
108 * cannot support multiple instances.
110 bool PlugInConf::supportsMultiInstance() { return true; }
113 * This function informs the plugin of the desired language to be spoken
114 * by the plugin. The plugin should attempt to adapt itself to the
115 * specified language code, choosing sensible defaults if necessary.
116 * If the passed-in code is QString(), no specific language has
118 * @param lang The desired language code or Null if none.
120 * If the plugin is unable to support the desired language, that is OK.
122 void PlugInConf::setDesiredLanguage(const QString
& /*lang*/ ) { }
125 * Return fully-specified talker code for the configured plugin. This code
126 * uniquely identifies the configured instance of the plugin and distinquishes
127 * one instance from another. If the plugin has not been fully configured,
128 * i.e., cannot yet synthesize, return QString().
129 * @return Fully-specified talker code.
131 QString
PlugInConf::getTalkerCode() { return QString(); }
134 * Return a list of all the languages currently supported by the plugin.
135 * Note that as the user configures your plugin, the language choices may become
136 * narrower. For example, once the user has picked a voice file, the language
137 * may be determined. If your plugin has just been added and no configuration
138 * choices have yet been made, return a list of all possible languages the
139 * plugin might support.
140 * If your plugin cannot yet determine the languages supported, return Null.
141 * If your plugin can support any language, return Null.
142 * @return A QStringList of supported language codes, or Null if unknown.
144 QStringList
PlugInConf::getSupportedLanguages() { return QStringList(); }
147 * Return the full path to any program in the $PATH environmental variable
148 * @param name The name of the file to search for.
149 * @returns The path to the file on success, a blank QString
150 * if it is not found.
152 QString
PlugInConf::getLocation(const QString
&name
) {
153 // Iterate over the path and see if 'name' exists in it. Return the
154 // full path to it if it does. Else return an empty QString.
156 // If it's a file or a symlink pointing to a file, that's cool.
157 QFileInfo
fileinfo(name
);
158 if (fileinfo
.isFile() || (fileinfo
.isSymLink() && QFileInfo(fileinfo
.readLink()).isFile()))
160 kDebug() << "PluginConf::getLocation: Searching for " << name
<< " in the path..";
162 for(QStringList::iterator it
= m_path
.begin(); it
!= m_path
.end(); ++it
) {
163 QString fullName
= *it
;
167 fileinfo
.setFile(fullName
);
168 // The user either has the directory of the file in the path...
169 if(fileinfo
.isFile() || fileinfo
.isSymLink() && QFileInfo(fileinfo
.readLink()).isFile()) {
171 // kDebug() << "PluginConf:getLocation: " << fullName;
173 // ....Or the file itself in the path (slightly freaky but hey.)
174 else if(QFileInfo(*it
).baseName().append(QString(".").append(QFileInfo(*it
).suffix())) == name
) {
176 // kDebug() << "PluginConf:getLocation: " << fullName;
183 * Breaks a language code into the language code and country code (if any).
184 * @param languageCode Language code.
185 * @return countryCode Just the country code part (if any).
186 * @return Just the language code part.
188 QString
PlugInConf::splitLanguageCode(const QString
& languageCode
, QString
& countryCode
)
190 QString locale
= languageCode
;
194 KGlobal::locale()->splitLocale(locale
, langCode
, countryCode
, modifier
, charSet
);
198 /*static*/ QString
PlugInConf::realFilePath(const QString
&filename
)
200 char realpath_buffer
[MAXPATHLEN
+ 1];
201 memset(realpath_buffer
, 0, MAXPATHLEN
+ 1);
203 /* If the path contains symlinks, get the real name */
204 if (realpath( QFile::encodeName(filename
).data(), realpath_buffer
) != 0) {
205 // succes, use result from realpath
206 return QFile::decodeName(realpath_buffer
);
211 /*static*/ QString
PlugInConf::testMessage(const QString
& languageCode
)
213 QString key
= "Name[" + languageCode
+ ']';
216 QFile
file(KStandardDirs::locate("data", "kttsd/kcmkttsd_testmessage.desktop"));
217 if (file
.open(QIODevice::ReadOnly
))
219 QTextStream
stream(&file
);
220 stream
.setCodec("UTF-8");
221 while ( !stream
.atEnd() ) {
222 QString line
= stream
.readLine(); // line of text excluding '\n'
223 QStringList keyAndValue
= line
.split( '=');
224 if (keyAndValue
.count() == 2)
226 if (keyAndValue
[0] == key
)
228 result
= keyAndValue
[1];
231 if (keyAndValue
[0] == "Name") def
= keyAndValue
[1];
236 if (result
.isEmpty())
239 if (result
.isEmpty()) result
= "The text-to-speech system seems to be functioning properly.";
245 * Player object that can be used by the plugin for testing playback of synthed files.
247 void PlugInConf::setPlayer(TestPlayer
* player
) { m_player
= player
; }
248 TestPlayer
* PlugInConf::getPlayer() { return m_player
; }