API change and refactoring. Major breakage. Best to stay out of kdeaccessibility...
[kdeaccessibility.git] / kttsd / filters / talkerchooser / talkerchooserproc.cpp
bloba37171ee5ddfa51d256c60c64227b71be2d155ec
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Generic Talker Chooser Filter Configuration class.
3 -------------------
4 Copyright:
5 (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6 -------------------
7 Original author: Gary Cramblitt <garycramblitt@comcast.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ******************************************************************************/
24 // Qt includes.
25 #include <QRegExp>
27 // KDE includes.
28 #include <kdebug.h>
29 #include <kconfig.h>
31 // KTTS includes.
32 #include "talkercode.h"
34 // Talker Chooser includes.
35 #include "talkerchooserproc.h"
36 #include "talkerchooserproc.moc"
38 /**
39 * Constructor.
41 TalkerChooserProc::TalkerChooserProc( QObject *parent, const QStringList& args ) :
42 KttsFilterProc(parent)
44 Q_UNUSED(args);
45 // kDebug() << "TalkerChooserProc::TalkerChooserProc: Running" << endl;
48 /**
49 * Destructor.
51 TalkerChooserProc::~TalkerChooserProc()
53 // kDebug() << "TalkerChooserProc::~TalkerChooserProc: Running" << endl;
56 /**
57 * Initialize the filter.
58 * @param config Settings object.
59 * @param configGroup Settings Group.
60 * @return False if filter is not ready to filter.
62 * Note: The parameters are for reading from kttsdrc file. Plugins may wish to maintain
63 * separate configuration files of their own.
65 bool TalkerChooserProc::init(KConfig* config, const QString& configGroup){
66 // kDebug() << "PlugInProc::init: Running" << endl;
67 config->setGroup( configGroup );
68 m_re = config->readEntry( "MatchRegExp" );
69 m_appIdList = config->readEntry( "AppIDs", QStringList(), ',' );
70 m_chosenTalkerCode = TalkerCode(config->readEntry("TalkerCode"), false);
71 // Legacy settings.
72 QString s = config->readEntry( "LanguageCode" );
73 if (!s.isEmpty()) m_chosenTalkerCode.setFullLanguageCode(s);
74 s = config->readEntry( "SynthInName" );
75 if (!s.isEmpty()) m_chosenTalkerCode.setPlugInName(s);
76 s = config->readEntry( "Gender" );
77 if (!s.isEmpty()) m_chosenTalkerCode.setGender(s);
78 s = config->readEntry( "Volume" );
79 if (!s.isEmpty()) m_chosenTalkerCode.setVolume(s);
80 s = config->readEntry( "Rate" );
81 if (!s.isEmpty()) m_chosenTalkerCode.setRate(s);
82 return true;
85 /**
86 * Returns True if the plugin supports asynchronous processing,
87 * i.e., supports asyncConvert method.
88 * @return True if this plugin supports asynchronous processing.
90 * If the plugin returns True, it must also implement @ref getState .
91 * It must also emit @ref filteringFinished when filtering is completed.
92 * If the plugin returns True, it must also implement @ref stopFiltering .
93 * It must also emit @ref filteringStopped when filtering has been stopped.
95 /*virtual*/ bool TalkerChooserProc::supportsAsync() { return false; }
97 /**
98 * Convert input, returning output. Runs synchronously.
99 * @param inputText Input text.
100 * @param talkerCode TalkerCode structure for the talker that KTTSD intends to
101 * use for synthing the text. Useful for extracting hints about
102 * how to filter the text. For example, languageCode.
103 * @param appId The DCOP appId of the application that queued the text.
104 * Also useful for hints about how to do the filtering.
106 /*virtual*/ QString TalkerChooserProc::convert(const QString& inputText, TalkerCode* talkerCode,
107 const QString& appId)
109 if ( !m_re.isEmpty() )
111 int pos = inputText.indexOf( QRegExp(m_re) );
112 if ( pos < 0 ) return inputText;
114 // If appId doesn't match, return input unmolested.
115 if ( !m_appIdList.isEmpty() )
117 // kDebug() << "TalkerChooserProc::convert: converting " << inputText << " if appId "
118 // << appId << " matches " << m_appIdList << endl;
119 bool found = false;
120 QString appIdStr = appId;
121 for (int ndx=0; ndx < m_appIdList.count(); ++ndx )
123 if ( appIdStr.contains(m_appIdList[ndx]) )
125 found = true;
126 break;
129 if ( !found )
131 // kDebug() << "TalkerChooserProc::convert: appId not found" << endl;
132 return inputText;
136 // Set the talker.
137 // kDebug() << "TalkerChooserProc::convert: setting lang " << m_languageCode <<
138 // " gender " << m_gender << " synth " << m_synth <<
139 // " volume " << m_volume << " rate " << m_rate << endl;
140 // Only override the language if user specified a language code.
141 if (!m_chosenTalkerCode.fullLanguageCode().isEmpty())
142 talkerCode->setFullLanguageCode(m_chosenTalkerCode.fullLanguageCode());
143 talkerCode->setVoice(m_chosenTalkerCode.voice());
144 talkerCode->setGender(m_chosenTalkerCode.gender());
145 talkerCode->setPlugInName(m_chosenTalkerCode.plugInName());
146 talkerCode->setVolume(m_chosenTalkerCode.volume());
147 talkerCode->setRate(m_chosenTalkerCode.rate());
148 return inputText;