26 #include "speechclient.h"
29 #include <dcopclient.h>
30 #include <tdeapplication.h>
31 #include <kcharsets.h>
32 #include <tdelocale.h>
34 #include <kstaticdeleter.h>
38 #include <tqvaluelist.h>
43 class SpeechClient::SpeechClientPrivate
47 bool isTextSpeechInstalled;
48 TQValueList<uint> pendingJobs;
51 SpeechClient* SpeechClient::m_self = 0;
53 static KStaticDeleter<SpeechClient> speechclsd;
55 SpeechClient* SpeechClient::self()
58 m_self = speechclsd.setObject(m_self,
new SpeechClient);
63 SpeechClient::SpeechClient() : DCOPStub(
"kttsd",
"KSpeech"), DCOPObject(
"akregatorpart_kspeechsink"), TQObject(), d(new SpeechClientPrivate)
65 d->isTextSpeechInstalled =
false;
69 SpeechClient::~SpeechClient()
75 void SpeechClient::slotSpeak(
const TQString& text,
const TQString& language)
77 if (!isTextToSpeechInstalled() || text.isEmpty())
79 uint jobNum = setText(text, language);
81 d->pendingJobs.append(jobNum);
82 if (d->pendingJobs.count() == 1)
84 emit signalJobsStarted();
85 emit signalActivated(
true);
89 void SpeechClient::slotSpeak(
const Article& article)
91 if (!isTextToSpeechInstalled() || article.isNull())
95 speakMe += KCharsets::resolveEntities(Utils::stripTags((article).title()))
97 + KCharsets::resolveEntities(Utils::stripTags((article).description()));
98 slotSpeak(speakMe,
"en");
101 void SpeechClient::slotSpeak(
const TQValueList<Article>& articles)
103 if (!isTextToSpeechInstalled() || articles.isEmpty())
108 for (TQValueList<Article>::ConstIterator it = articles.begin(); it != articles.end(); ++it)
110 if (!speakMe.isEmpty())
111 speakMe +=
". . . . . . " + i18n(
"Next Article: ");
112 speakMe += KCharsets::resolveEntities(Utils::stripTags((*it).title()))
114 + KCharsets::resolveEntities(Utils::stripTags((*it).description()));
117 SpeechClient::self()->slotSpeak(speakMe,
"en");
120 void SpeechClient::slotAbortJobs()
122 if (!d->pendingJobs.isEmpty())
124 for (TQValueList<uint>::ConstIterator it = d->pendingJobs.begin(); it != d->pendingJobs.end(); ++it)
129 d->pendingJobs.clear();
130 emit signalJobsDone();
131 emit signalActivated(
false);
135 ASYNC SpeechClient::textRemoved(
const TQCString& , uint jobNum)
137 kdDebug() <<
"SpeechClient::textRemoved() called" << endl;
138 if (d->pendingJobs.contains(jobNum))
140 d->pendingJobs.remove(jobNum);
141 if (d->pendingJobs.isEmpty())
143 emit signalJobsDone();
144 emit signalActivated(
false);
149 bool SpeechClient::isTextToSpeechInstalled()
const
151 return d->isTextSpeechInstalled;
154 void SpeechClient::setupSpeechSystem()
156 TDETrader::OfferList offers = TDETrader::self()->query(
"DCOP/Text-to-Speech",
"Name == 'KTTSD'");
157 if (offers.count() == 0)
159 kdDebug() <<
"KTTSD not installed, disable support" << endl;
160 d->isTextSpeechInstalled =
false;
164 DCOPClient* client = dcopClient();
166 if (client->isApplicationRegistered(
"kttsd"))
168 d->isTextSpeechInstalled =
true;
173 if (TDEApplication::startServiceByDesktopName(
"kttsd", TQStringList(), &error))
175 kdDebug() <<
"Starting KTTSD failed with message " << error << endl;
176 d->isTextSpeechInstalled =
false;
180 d->isTextSpeechInstalled =
true;
184 if (d->isTextSpeechInstalled)
187 bool c = connectDCOPSignal(
"kttsd",
"KSpeech",
188 "textRemoved(TQCString, uint)",
189 "textRemoved(TQCString, uint)",
192 kdDebug() <<
"SpeechClient::setupSpeechSystem(): connecting signals failed" << endl;
193 c = connectDCOPSignal(
"kttsd",
"KSpeech",
194 "textFinished(TQCString, uint)",
195 "textRemoved(TQCString, uint)",
203 #include "speechclient.moc"