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
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 // C++ library includes.
20 #include <sys/param.h>
24 #include <qfileinfo.h>
27 #include <QTextStream>
32 #include <kstandarddirs.h>
34 // PluginConf includes.
35 #include "pluginconf.h"
36 #include "pluginconf.moc"
41 PlugInConf::PlugInConf( QWidget
*parent
, const char *name
) : QWidget(parent
, name
){
42 kdDebug() << "PlugInConf::PlugInConf: Running" << endl
;
43 QString
systemPath(getenv("PATH"));
44 // kdDebug() << "Path is " << systemPath << endl;
45 m_path
= QStringList::split(":", systemPath
);
52 PlugInConf::~PlugInConf(){
53 kdDebug() << "PlugInConf::~PlugInConf: Running" << endl
;
58 * This method is invoked whenever the module should read its
59 * configuration (most of the times from a config file) and update the
60 * user interface. This happens when the user clicks the "Reset" button in
61 * the control center, to undo all of his changes and restore the currently
62 * valid settings. Note that kttsmgr calls this when the plugin is
63 * loaded, so it not necessary to call it in your constructor.
64 * The plugin should read its configuration from the specified group
65 * in the specified config file.
66 * @param config Pointer to a KConfig object.
67 * @param configGroup Call config->setGroup with this argument before
68 * loading your configuration.
70 void PlugInConf::load(KConfig
* /*config*/, const QString
& /*configGroup*/){
71 kdDebug() << "PlugInConf::load: Running" << endl
;
75 * This function gets called when the user wants to save the settings in
76 * the user interface, updating the config files or wherever the
77 * configuration is stored. The method is called when the user clicks "Apply"
78 * or "Ok". The plugin should save its configuration in the specified
79 * group of the specified config file.
80 * @param config Pointer to a KConfig object.
81 * @param configGroup Call config->setGroup with this argument before
82 * saving your configuration.
84 void PlugInConf::save(KConfig
* /*config*/, const QString
& /*configGroup*/){
85 kdDebug() << "PlugInConf::save: Running" << endl
;
89 * This function is called to set the settings in the module to sensible
90 * default values. It gets called when hitting the "Default" button. The
91 * default values should probably be the same as the ones the application
92 * uses when started without a config file. Note that defaults should
93 * be applied to the on-screen widgets; not to the config file.
95 void PlugInConf::defaults(){
96 kdDebug() << "PlugInConf::defaults: Running" << endl
;
100 * Indicates whether the plugin supports multiple instances. Return
101 * False if only one instance of the plugin can run at a time.
102 * @return True if multiple instances are possible.
104 * It is assumed that most plugins can support multiple instances.
105 * A plugin must override this method and return false if it
106 * cannot support multiple instances.
108 bool PlugInConf::supportsMultiInstance() { return true; }
111 * This function informs the plugin of the desired language to be spoken
112 * by the plugin. The plugin should attempt to adapt itself to the
113 * specified language code, choosing sensible defaults if necessary.
114 * If the passed-in code is QString::null, no specific language has
116 * @param lang The desired language code or Null if none.
118 * If the plugin is unable to support the desired language, that is OK.
120 void PlugInConf::setDesiredLanguage(const QString
& /*lang*/ ) { }
123 * Return fully-specified talker code for the configured plugin. This code
124 * uniquely identifies the configured instance of the plugin and distinquishes
125 * one instance from another. If the plugin has not been fully configured,
126 * i.e., cannot yet synthesize, return QString::null.
127 * @return Fully-specified talker code.
129 QString
PlugInConf::getTalkerCode() { return QString::null
; }
132 * Return a list of all the languages currently supported by the plugin.
133 * Note that as the user configures your plugin, the language choices may become
134 * narrower. For example, once the user has picked a voice file, the language
135 * may be determined. If your plugin has just been added and no configuration
136 * choices have yet been made, return a list of all possible languages the
137 * plugin might support.
138 * If your plugin cannot yet determine the languages supported, return Null.
139 * If your plugin can support any language, return Null.
140 * @return A QStringList of supported language codes, or Null if unknown.
142 QStringList
PlugInConf::getSupportedLanguages() { return QStringList(); }
145 * Return the full path to any program in the $PATH environmental variable
146 * @param name The name of the file to search for.
147 * @returns The path to the file on success, a blank QString
150 QString
PlugInConf::getLocation(const QString
&name
) {
151 // Iterate over the path and see if 'name' exists in it. Return the
152 // full path to it if it does. Else return an empty QString.
154 // If it's a file or a symlink pointing to a file, that's cool.
155 QFileInfo
fileinfo(name
);
156 if (fileinfo
.isFile() || (fileinfo
.isSymLink() && QFileInfo(fileinfo
.readLink()).isFile()))
158 kdDebug() << "PluginConf::getLocation: Searching for " << name
<< " in the path.." << endl
;
159 kdDebug() << m_path
<< endl
;
160 for(QStringList::iterator it
= m_path
.begin(); it
!= m_path
.end(); ++it
) {
161 QString fullName
= *it
;
165 fileinfo
.setFile(fullName
);
166 // The user either has the directory of the file in the path...
167 if(fileinfo
.isFile() || fileinfo
.isSymLink() && QFileInfo(fileinfo
.readLink()).isFile()) {
169 // kdDebug() << "PluginConf:getLocation: " << fullName << endl;
171 // ....Or the file itself in the path (slightly freaky but hey.)
172 else if(QFileInfo(*it
).baseName().append(QString(".").append(QFileInfo(*it
).extension())) == name
) {
174 // kdDebug() << "PluginConf:getLocation: " << fullName << endl;
181 * Breaks a language code into the language code and country code (if any).
182 * @param languageCode Language code.
183 * @return countryCode Just the country code part (if any).
184 * @return Just the language code part.
186 QString
PlugInConf::splitLanguageCode(const QString
& languageCode
, QString
& countryCode
)
188 QString locale
= languageCode
;
191 KGlobal::locale()->splitLocale(locale
, langCode
, countryCode
, charSet
);
195 /*static*/ QString
PlugInConf::realFilePath(const QString
&filename
)
197 char realpath_buffer
[MAXPATHLEN
+ 1];
198 memset(realpath_buffer
, 0, MAXPATHLEN
+ 1);
200 /* If the path contains symlinks, get the real name */
201 if (realpath( QFile::encodeName(filename
).data(), realpath_buffer
) != 0) {
202 // succes, use result from realpath
203 return QFile::decodeName(realpath_buffer
);
208 /*static*/ QString
PlugInConf::testMessage(const QString
& languageCode
)
210 QString key
= "Name[" + languageCode
+ "]";
213 QFile
file(locate("data", "kttsd/kcmkttsd_testmessage.desktop"));
214 if (file
.open(QIODevice::ReadOnly
))
216 QTextStream
stream(&file
);
217 stream
.setEncoding(QTextStream::UnicodeUTF8
);
218 while ( !stream
.atEnd() ) {
219 QString line
= stream
.readLine(); // line of text excluding '\n'
220 QStringList keyAndValue
= QStringList::split("=", line
);
221 if (keyAndValue
.count() == 2)
223 if (keyAndValue
[0] == key
)
225 result
= keyAndValue
[1];
228 if (keyAndValue
[0] == "Name") def
= keyAndValue
[1];
233 if (result
.isEmpty())
236 if (result
.isEmpty()) result
= "The text-to-speech system seems to be functioning properly.";
242 * Player object that can be used by the plugin for testing playback of synthed files.
244 void PlugInConf::setPlayer(TestPlayer
* player
) { m_player
= player
; }
245 TestPlayer
* PlugInConf::getPlayer() { return m_player
; }