• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • jovie
talkermgr.cpp
Go to the documentation of this file.
1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2  Manages all the Talker (synth) plugins.
3  -------------------
4  Copyright:
5  (C) 2004-2005 by Gary Cramblitt <garycramblitt@comcast.net>
6  -------------------
7  Original author: Gary Cramblitt <garycramblitt@comcast.net>
8 
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.
13 
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.
18 
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  ******************************************************************************/
23 
24 #include "talkermgr.h"
25 
26 // Qt includes.
27 
28 // KDE includes.
29 #include <kdebug.h>
30 #include <kstandarddirs.h>
31 #include <kservicetypetrader.h>
32 #include <kconfiggroup.h>
33 
34 TalkerMgr * TalkerMgr::m_instance = NULL;
35 
36 TalkerMgr * TalkerMgr::Instance()
37 {
38  if (m_instance == NULL)
39  {
40  m_instance = new TalkerMgr(NULL);
41  }
42  return m_instance;
43 }
44 
48 TalkerMgr::TalkerMgr(QObject *parent) :
49  QObject( parent )
50 {
51 }
52 
56 TalkerMgr::~TalkerMgr()
57 {
58  //while (!m_loadedPlugIns.isEmpty()) delete m_loadedPlugIns.takeFirst();
59 }
60 
65 void TalkerMgr::loadTalkers(KConfig* c)
66 {
67  m_loadedTalkerCodes.clear();
68  m_loadedTalkerIds.clear();
69  KConfigGroup config(c, "General");
70  QStringList talkerIDsList = config.readEntry("TalkerIDs", QStringList());
71  if (!talkerIDsList.isEmpty())
72  {
73  QStringList::ConstIterator itEnd(talkerIDsList.constEnd());
74  for( QStringList::ConstIterator it = talkerIDsList.constBegin(); it != itEnd; ++it )
75  {
76  // kDebug() << "Loading plugInProc for Talker ID " << *it;
77 
78  // Talker ID.
79  QString talkerID = *it;
80 
81  // Set the group for the talker to load
82  KConfigGroup talkerConfig(c, "Talkers");
83 
84  // Get the DesktopEntryName of the plugin we will try to load.
85  //QString desktopEntryName = talkerConfig.readEntry("DesktopEntryName", QString());
86 
87 // // If a DesktopEntryName is not in the config file, it was configured before
88 // // we started using them, when we stored translated plugin names instead.
89 // // Try to convert the translated plugin name to a DesktopEntryName.
90 // // DesktopEntryNames are better because user can change their desktop language
91 // // and DesktopEntryName won't change.
92 // if (desktopEntryName.isEmpty())
93 // {
94 // QString synthName = talkerConfig.readEntry("PlugIn", QString());
95 // // See if the translated name will untranslate. If not, well, sorry.
96 // desktopEntryName = TalkerCode::TalkerNameToDesktopEntryName(synthName);
97 // // Record the DesktopEntryName from now on.
98 // if (!desktopEntryName.isEmpty()) talkerConfig.writeEntry("DesktopEntryName", desktopEntryName);
99 // }
100 
101  // Get the talker code.
102  QString talkerCode = talkerConfig.readEntry(talkerID, QString());
103 
104  // Normalize the talker code.
105  //QString fullLanguageCode;
106  //talkerCode = TalkerCode::normalizeTalkerCode(talkerCode, fullLanguageCode);
107 
108  m_loadedTalkerCodes.append(TalkerCode(talkerCode));
109  m_loadedTalkerIds.append(talkerID);
110  }
111  }
112 }
113 
114 
116 // * Load all the configured synth plugins, populating loadedPlugIns structure.
117 // */
118 //int TalkerMgr::loadPlugIns(KConfig* c)
119 //{
120 // // kDebug() << "Running: TalkerMgr::loadPlugIns()";
121 // int good = 0;
122 // int bad = 0;
123 
124 // m_talkerToPlugInCache.clear();
125 // //while (!m_loadedPlugIns.isEmpty()) delete m_loadedPlugIns.takeFirst();
126 // m_loadedTalkerCodes.clear();
127 // m_loadedTalkerIds.clear();
128 
129 // KConfigGroup config(c, "General");
130 // QStringList talkerIDsList = config.readEntry("TalkerIDs", QStringList());
131 // if (!talkerIDsList.isEmpty())
132 // {
133 // KLibFactory *factory;
134 // QStringList::ConstIterator itEnd(talkerIDsList.constEnd());
135 // for( QStringList::ConstIterator it = talkerIDsList.constBegin(); it != itEnd; ++it )
136 // {
137 // // kDebug() << "Loading plugInProc for Talker ID " << *it;
138 
139 // // Talker ID.
140 // QString talkerID = *it;
141 
142 // // Set the group for the language we're loading
143 // KConfigGroup talkerConfig(c, "Talker_" + talkerID);
144 
145 // // Get the DesktopEntryName of the plugin we will try to load.
146 // QString desktopEntryName = talkerConfig.readEntry("DesktopEntryName", QString());
147 
148 // // If a DesktopEntryName is not in the config file, it was configured before
149 // // we started using them, when we stored translated plugin names instead.
150 // // Try to convert the translated plugin name to a DesktopEntryName.
151 // // DesktopEntryNames are better because user can change their desktop language
152 // // and DesktopEntryName won't change.
153 // if (desktopEntryName.isEmpty())
154 // {
155 // QString synthName = talkerConfig.readEntry("PlugIn", QString());
156 // // See if the translated name will untranslate. If not, well, sorry.
157 // desktopEntryName = TalkerCode::TalkerNameToDesktopEntryName(synthName);
158 // // Record the DesktopEntryName from now on.
159 // if (!desktopEntryName.isEmpty()) talkerConfig.writeEntry("DesktopEntryName", desktopEntryName);
160 // }
161 
162 // // Get the talker code.
163 // QString talkerCode = talkerConfig.readEntry("TalkerCode", QString());
164 
165 // // Normalize the talker code.
166 // QString fullLanguageCode;
167 // talkerCode = TalkerCode::normalizeTalkerCode(talkerCode, fullLanguageCode);
168 
169 // // Find the KTTSD SynthPlugin.
170 // KService::List offers = KServiceTypeTrader::self()->query(
171 // "KTTSD/SynthPlugin", QString("DesktopEntryName == '%1'").arg(desktopEntryName));
172 
173 // if(offers.count() > 1){
174 // ++bad;
175 // kDebug() << "More than 1 plug in doesn't make any sense, well, let's use any";
176 // } else if(offers.count() < 1){
177 // ++bad;
178 // kDebug() << "Less than 1 plug in, nothing can be done";
179 // } else {
180 // kDebug() << "Loading " << offers[0]->library();
181 // factory = KLibLoader::self()->factory(offers[0]->library().toLatin1());
182 // if(factory){
183 // //PlugInProc *speech =
184 // // KLibLoader::createInstance<PlugInProc>(
185 // // offers[0]->library().toLatin1(), this, QStringList(offers[0]->library().toLatin1()));
186 // if(!speech){
187 // kDebug() << "Couldn't create the speech object from " << offers[0]->library();
188 // ++bad;
189 // } else {
190 // if (speech->supportsAsync())
191 // {
192 // speech->init(c, "Talker_" + talkerID);
193 // // kDebug() << "Plug in " << desktopEntryName << " created successfully.";
194 // //m_loadedPlugIns.append(speech);
195 // } else {
196 // // Synchronous plugins are run in a separate thread.
197 // // Init will start the thread and it will immediately go to sleep.
198 // //QString threadedPlugInName = QString::fromLatin1("threaded") + desktopEntryName;
199 // //ThreadedPlugIn* speechThread = new ThreadedPlugIn(speech,
200 // // this, threadedPlugInName.toLatin1());
201 // //speechThread->init(c, "Talker_" + talkerCode);
202 // //// kDebug() << "Threaded Plug in " << desktopEntryName << " for language " << (*it).right((*it).length()-5) << " created successfully.";
203 // //m_loadedPlugIns.append(speechThread);
204 // }
205 // ++good;
206 // m_loadedTalkerCodes.append(TalkerCode(talkerCode));
207 // m_loadedTalkerIds.append(talkerID);
208 // }
209 // } else {
210 // kDebug() << "Couldn't create the factory object from " << offers[0]->library();
211 // ++bad;
212 // }
213 // }
214 // }
215 // }
216 // if(bad > 0){
217 // if(good == 0){
218 // // No plugin could be loaded.
219 // return -1;
220 // } else {
221 // // At least one plugin was loaded and one failed.
222 // return 0;
223 // }
224 // } else {
225 // if (good == 0)
226 // // No plugin could be loaded.
227 // return -1;
228 // else
229 // // All the plug in were loaded perfectly
230 // return 1;
231 // }
232 //}
233 
239 QStringList TalkerMgr::getTalkers()
240 {
241  QStringList talkerList;
242  //for (int ndx = 0; ndx < int(m_loadedPlugIns.count()); ++ndx)
243  //{
244  // talkerList.append(m_loadedTalkerCodes[ndx].getTalkerCode());
245  //}
246  return talkerList;
247 }
248 
252 //PlugInList TalkerMgr::getLoadedPlugIns()
253 //{
254 // return m_loadedPlugIns;
255 //}
256 
265 //int TalkerMgr::talkerToPluginIndex(const QString& talker) const
266 //{
267 // // kDebug() << "TalkerMgr::talkerToPluginIndex: matching talker " << talker << " to closest matching plugin.";
268 // // If we have a cached match, return that.
269 // if (m_talkerToPlugInCache.contains(talker))
270 // return m_talkerToPlugInCache[talker];
271 // else
272 // {
273 // int winner = TalkerCode::findClosestMatchingTalker(m_loadedTalkerCodes, talker, true);
274 // m_talkerToPlugInCache[talker] = winner;
275 // return winner;
276 // }
277 //}
278 
292 //PlugInProc* TalkerMgr::talkerToPlugin(const QString& talker) const
293 //{
294 // int talkerNdx = talkerToPluginIndex(talker);
295 // return const_cast< PlugInList* >(&m_loadedPlugIns)->at(talkerNdx);
296 //}
297 
313 TalkerCode* TalkerMgr::talkerToTalkerCode(const QString& talker)
314 {
315 // int talkerNdx = talkerToPluginIndex(talker);
316 // return new TalkerCode(&m_loadedTalkerCodes[talkerNdx]);
317  return NULL;
318 }
319 
326 QString TalkerMgr::talkerCodeToTalkerId(const QString& talkerCode)
327 {
328 // int talkerNdx = talkerToPluginIndex(talkerCode);
329 // return m_loadedTalkerIds[talkerNdx];
330  return QString();
331 }
332 
340 QString TalkerMgr::userDefaultTalker() const
341 {
342  return m_loadedTalkerCodes[0].getTalkerCode();
343 }
344 
345 bool TalkerMgr::autoconfigureTalker(const QString& langCode, KConfig* config)
346 {
348  return false;
349 
350  //QString languageCode = langCode;
351 
353  //KConfigGroup generalConfig(config, "General");
354  //QStringList talkerIDsList = generalConfig.readEntry("TalkerIDs", QStringList());
355  //int lastTalkerID = 0;
356  //for (int talkerIdNdx = 0; talkerIdNdx < talkerIDsList.count(); ++talkerIdNdx)
357  //{
358  // int id = talkerIDsList[talkerIdNdx].toInt();
359  // if (id > lastTalkerID) lastTalkerID = id;
360  //}
361 
363  //QString talkerID = QString::number(lastTalkerID + 1);
364 
366  //KService::List offers = KServiceTypeTrader::self()->query("KTTSD/SynthPlugin");
367 
369  //for(int i=0; i < offers.count() ; ++i)
370  //{
371  // // See if this plugin supports the desired language.
372  // QStringList languageCodes = offers[i]->property("X-KDE-Languages").toStringList();
373  // if (languageCodes.contains(languageCode))
374  // {
375  // QString desktopEntryName = offers[i]->desktopEntryName();
376 
377  // // Load the plugin.
378  // KLibFactory *factory = KLibLoader::self()->factory(offers[0]->library().toLatin1());
379  // if (factory)
380  // {
381  // // If the factory is created successfully, instantiate the PlugInConf class for the
382  // // specific plug in to get the plug in configuration object.
383  // PlugInConf* loadedTalkerPlugIn =
384  // KLibLoader::createInstance<PlugInConf>(
385  // offers[0]->library().toLatin1(), NULL, QStringList(offers[0]->library().toLatin1()));
386  // if (loadedTalkerPlugIn)
387  // {
388  // // Give plugin the language code and permit plugin to autoconfigure itself.
389  // loadedTalkerPlugIn->setDesiredLanguage(languageCode);
390  // loadedTalkerPlugIn->load(config, QString("Talker_")+talkerID);
391 
392  // // If plugin was able to configure itself, it returns a full talker code.
393  // QString talkerCode = loadedTalkerPlugIn->getTalkerCode();
394 
395  // if (!talkerCode.isEmpty())
396  // {
397  // // Erase extraneous Talker configuration entries that might be there.
398  // config->deleteGroup(QString("Talker_")+talkerID);
399 
400  // // Let plugin save its configuration.
401  // loadedTalkerPlugIn->save(config, QString("Talker_"+talkerID));
402 
403  // // Record configuration data.
404  // KConfigGroup talkerConfig(config, QString("Talker_")+talkerID);
405  // talkerConfig.writeEntry("DesktopEntryName", desktopEntryName);
406  // talkerCode = TalkerCode::normalizeTalkerCode(talkerCode, languageCode);
407  // talkerConfig.writeEntry("TalkerCode", talkerCode);
408 
409  // // Add TalkerID to configured list.
410  // talkerIDsList.append(talkerID);
411  // generalConfig.writeEntry("TalkerIDs", talkerIDsList.join(","));
412  // config->sync();
413 
414  // // TODO: Now that we have modified the config, need a way to inform
415  // // other apps, including KTTSMgr. As this routine is likely called
416  // // when KTTSMgr is not running, is not a serious problem.
417 
418  // // Success!
419  // delete loadedTalkerPlugIn;
420  // return true;
421  // }
422 
423  // // Plugin no longer needed.
424  // delete loadedTalkerPlugIn;
425  // }
426  // }
427  // }
428  //}
429 
430  //return false;
431 }
TalkerMgr::talkerCodeToTalkerId
QString talkerCodeToTalkerId(const QString &talkerCode)
Given a Talker Code, returns the Talker ID of the talker that would speak a text job with that Talker...
Definition: talkermgr.cpp:326
TalkerMgr::autoconfigureTalker
bool autoconfigureTalker(const QString &langCode, KConfig *config)
Try to automatically configure a Talker in the specified language.
Definition: talkermgr.cpp:345
TalkerMgr::~TalkerMgr
~TalkerMgr()
Destructor.
Definition: talkermgr.cpp:56
QObject
talkermgr.h
TalkerMgr::loadTalkers
void loadTalkers(KConfig *c)
load the talkers from the given config object
Definition: talkermgr.cpp:65
TalkerCode
Definition: talkercode.h:38
TalkerMgr::getTalkers
QStringList getTalkers()
Get a list of the talkers configured in Speech Dispatcher.
Definition: talkermgr.cpp:239
TalkerMgr::talkerToTalkerCode
TalkerCode * talkerToTalkerCode(const QString &talker)
Given a talker code, returns the parsed TalkerCode of the closest matching Talker.
Definition: talkermgr.cpp:313
TalkerMgr::userDefaultTalker
QString userDefaultTalker() const
Get the user's default talker.
Definition: talkermgr.cpp:340
TalkerMgr::Instance
static TalkerMgr * Instance()
singleton accessor
Definition: talkermgr.cpp:36
TalkerMgr
Definition: talkermgr.h:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal