SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / kttsd / libkttsd / filterconf.cpp
blobb505b33a4d8177f68d20a53a518eacda3b482c6e
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Filter Configuration class.
3 This is the interface definition for text filter configuration dialogs.
4 -------------------
5 Copyright:
6 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
7 -------------------
8 Original author: Gary Cramblitt <garycramblitt@comcast.net>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************************************************************************/
25 // PluginConf includes.
26 #include "filterconf.h"
27 #include "filterconf.moc"
29 // C++ library includes.
30 #include <stdlib.h>
31 #include <sys/param.h>
33 // Qt includes.
34 #include <QtCore/QFile>
35 #include <QtCore/QFileInfo>
37 // KDE includes.
38 #include <kglobal.h>
39 #include <klocale.h>
41 /**
42 * Constructor
44 KttsFilterConf::KttsFilterConf( QWidget *parent, const QVariantList &) : QWidget(parent){
45 //setObjectName(name);
46 // kDebug() << "KttsFilterConf::KttsFilterConf: Running";
47 QString systemPath(qgetenv("PATH"));
48 // kDebug() << "Path is " << systemPath;
49 m_path = systemPath.split( ':');
52 /**
53 * Destructor.
55 KttsFilterConf::~KttsFilterConf(){
56 // kDebug() << "KttsFilterConf::~KttsFilterConf: Running";
59 /**
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 KttsFilterConf::load(KConfig* /*config*/, const QString& /*configGroup*/){
73 // kDebug() << "KttsFilterConf::load: Running";
76 /**
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 KttsFilterConf::save(KConfig* /*config*/, const QString& /*configGroup*/){
87 // kDebug() << "KttsFilterConf::save: Running";
90 /**
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 KttsFilterConf::defaults(){
98 // kDebug() << "KttsFilterConf::defaults: Running";
102 * Indicates whether the plugin supports multiple instances. Return
103 * False if only one instance of the plugin can be configured.
104 * @return True if multiple instances are possible.
106 bool KttsFilterConf::supportsMultiInstance() { return false; }
109 * Returns the name of the plugin. Displayed in Filters tab of KTTSMgr.
110 * If there can be more than one instance of a filter, it should return
111 * a unique name for each instance. The name should be translated for
112 * the user if possible. If the plugin is not correctly configured,
113 * return an empty string.
114 * @return Filter instance name.
116 QString KttsFilterConf::userPlugInName() { return QString(); }
119 * Returns True if this filter is a Sentence Boundary Detector.
120 * @return True if this filter is a SBD.
122 bool KttsFilterConf::isSBD() { return false; }
125 * Return the full path to any program in the $PATH environmental variable
126 * @param name The name of the file to search for.
127 * @returns The path to the file on success, a blank QString
128 * if it is not found.
130 QString KttsFilterConf::getLocation(const QString &name) {
131 // Iterate over the path and see if 'name' exists in it. Return the
132 // full path to it if it does. Else return an empty QString.
133 if (QFile::exists(name)) return name;
134 // kDebug() << "KttsFilterConf::getLocation: Searching for " << name << " in the path..";
135 // kDebug() << m_path;
136 for(QStringList::iterator it = m_path.begin(); it != m_path.end(); ++it) {
137 QString fullName = *it;
138 fullName += '/';
139 fullName += name;
140 // The user either has the directory of the file in the path...
141 if(QFile::exists(fullName)) {
142 // kDebug() << "KttsFilterConf:getLocation: " << fullName;
143 return fullName;
145 // ....Or the file itself
146 else if(QFileInfo(*it).baseName().append(QString(".").append(QFileInfo(*it).suffix())) == name) {
147 // kDebug() << "KttsFilterConf:getLocation: " << fullName;
148 return fullName;
151 return "";
154 /*static*/ QString KttsFilterConf::realFilePath(const QString &filename)
156 char realpath_buffer[MAXPATHLEN + 1];
157 memset(realpath_buffer, 0, MAXPATHLEN + 1);
159 /* If the path contains symlinks, get the real name */
160 if (realpath( QFile::encodeName(filename).data(), realpath_buffer) != 0) {
161 //succes, use result from realpath
162 return QFile::decodeName(realpath_buffer);
164 return filename;