Fix include
[kdeaccessibility.git] / ksayit / KTTSD_Lib / kttsdlib.cpp
blob23c9353f2acb9a4c36ce5c8d26efd65279ef1141
1 //
2 // C++ Implementation: kttsdplugin
3 //
4 // Description:
5 //
6 //
7 // Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
12 // #include <time.h> // nanosleep
14 // Qt includes
16 //Added by qt3to4:
17 #include <QFrame>
19 // KDE includes
20 #include <kglobal.h>
21 #include <klocale.h>
22 #include <kstandarddirs.h>
23 #include <k3process.h>
24 #include <kmessagebox.h>
25 #include <kdebug.h>
27 // App specific includes
28 #include "kttsdlib.h"
29 #include "kttsdlibtalker2.h"
30 // #include "kttsdlibsetupimpl.h"
33 KTTSDLib::KTTSDLib(QObject *parent, const char *name, KApplication *Appl)
34 : QObject(parent), m_Appl(Appl), m_gui(NULL)
36 setObjectName(name);
37 KGlobal::locale()->insertCatalog("libKTTSD");
38 m_talker = new kttsdlibtalker2(static_cast<QObject*>(this), "kttsdlibtalker");
39 connect(m_talker, SIGNAL(signalTextFinished(const uint)),
40 this, SLOT(slotTextFinished(const uint)) );
41 connect(m_talker, SIGNAL(signalTextStopped(const uint)),
42 this, SLOT(slotTextStopped(const uint)) );
43 connect(m_talker, SIGNAL(signalTextStarted(const uint)),
44 this, SLOT(slotTextStarted(const uint)) );
46 // reset list of currently processed jobs
47 while ( !jobList.empty() ){
48 jobList.pop();
51 // initialize the talker
52 m_talker->KTTSD_init(m_Appl);
54 // some presets
55 // m_config = new KSimpleConfig("ksayit_kttsdpluginrc");
56 // m_usersetupimpl = NULL;
60 KTTSDLib::~KTTSDLib()
62 // delete m_config;
66 QString KTTSDLib::getName() const
68 return "KDE KTTSD";
72 QString KTTSDLib::getDescription() const
74 QString str;
75 str = i18n("<qt><big><u>Description:</u></big><br>");
76 str += i18n("This plugin uses the KDE TTS Daemon for speech output.");
78 return str;
82 int KTTSDLib::getActions()
84 return ACTIONS::PLAY | ACTIONS::STOP | ACTIONS::PAUSE | ACTIONS::FFWD | ACTIONS::FREV;
88 int KTTSDLib::getStatus() const
90 return TTS::AUDIOFILE;
94 const QWidget* KTTSDLib::getGUI(QFrame *frame)
96 kDebug(100200) << "KTTSDLib::getGUI()" << endl;
97 QWidget *w = new QWidget(frame);
98 m_gui = new Ui::KTTSDlibSetup();
99 m_gui->setupUi(w);
100 connect(m_gui->kcm_Button, SLOT(clicked()),
101 this, SLOT(slotLaunchControlcenter()));
102 return w;
106 void KTTSDLib::reloadConfiguration()
108 kDebug(100200) << "KTTSDLib::reloadConfiguration()" << endl;
109 // N.A.
113 bool KTTSDLib::saveWasClicked() const
115 kDebug(100200) << "KTTSDLib::saveWasClicked()" << endl;
116 // N.A.
118 return true;
121 void KTTSDLib::slotLaunchControlcenter()
123 kDebug(100200) << "KTTSDlibSetupImpl::slotLaunchControlCenter()" << endl;
125 // check if controllcenter module for KTTSD exists
126 FILE *fp;
127 char cmdresult[20];
129 // TODO: Don't launch kcmshell kcmkttsd if already active.
130 // bool configActive = (QDBus::sessionBus().busService()->nameHasOwner("org.kde.kcmshell_kcmkttsd"));
132 // if ( (fp = popen("kcmshell --list | grep kcmkttsmgr", "r")) != NULL){
133 if ( (fp = popen("kcmshell --list | grep kcmkttsd", "r")) != NULL){
134 fgets(cmdresult, 18, fp);
135 pclose(fp);
137 if ( !QByteArray(cmdresult).contains("kcmkttsd") ){
138 QString error = i18n("Control Center Module for KTTSD not found.");
139 KMessageBox::sorry(m_Appl->activeWindow(), error, i18n("Problem"));
140 return;
143 // invoke the Control Center Module
144 K3Process *kcmproc = new K3Process();
145 connect(kcmproc, SIGNAL(processExited(K3Process*)),
146 this, SLOT(slotKCMProcessExited(K3Process*)) );
147 (*kcmproc) << "kcmshell";
148 (*kcmproc) << "kcmkttsd";
149 (*kcmproc) << "--caption" << i18n("KDE Text-to-Speech");
150 kcmproc->start(K3Process::NotifyOnExit);
152 m_gui->kcm_Button->setEnabled(false);
156 void KTTSDLib::slotKCMProcessExited(K3Process *p)
158 Q_UNUSED(p);
159 kDebug(100200) << "slotKCMProcessExited()" << endl;
160 m_gui->kcm_Button->setEnabled(true);
164 void KTTSDLib::setText(const QString &text)
166 kDebug(100200) << "KTTSDLib::setText()" << endl;
168 uint jobNum = m_talker->KTTSD_setText(text, "");
169 jobList.push(jobNum);
174 void KTTSDLib::sayText()
176 kDebug(100200) << "KTTSDLib::sayText()" << endl;
178 if( !jobList.empty() ){
179 m_curJobNum = jobList.front();
180 jobList.pop();
181 kDebug(100200) << " Starting job No.: " << m_curJobNum << endl;
182 m_talker->KTTSD_startText( m_curJobNum );
187 void KTTSDLib::removeAllJobsFromList()
189 kDebug(100200) << "KTTSDLib::removeAllJobsFromList()" << endl;
191 m_talker->KTTSD_removeText(m_curJobNum);
193 while( !jobList.empty() ){
194 uint job = jobList.front();
195 jobList.pop();
196 kDebug(100200) << "*** removing... " << job << endl;
197 m_talker->KTTSD_removeText( job );
201 void KTTSDLib::stop()
203 kDebug(100200) << "***** KTTSDLib::stop(" << m_curJobNum << ")" << endl;
204 m_talker->KTTSD_stopText(m_curJobNum);
205 removeAllJobsFromList();
206 emit signalFinished();
210 void KTTSDLib::pause()
212 kDebug(100200) << "void KTTSDLib::pause(" << m_curJobNum << ")" << endl;
214 m_talker->KTTSD_pauseText( m_curJobNum );
218 void KTTSDLib::resume()
220 kDebug(100200) << "void KTTSDLib::resume(" << m_curJobNum << ")" << endl;
222 m_talker->KTTSD_resumeText( m_curJobNum );
226 void KTTSDLib::ffwd()
228 kDebug(100200) << "void KTTSDLib::ffwd(" << m_curJobNum << ")" << endl;
229 m_talker->KTTSD_moveRelTextSentence(1, m_curJobNum);
233 void KTTSDLib::frev()
235 kDebug(100200) << "void KTTSDLib::frev(" << m_curJobNum << ")" << endl;
236 m_talker->KTTSD_moveRelTextSentence(-1, m_curJobNum);
240 //////////////////////////////////////
241 // Signals from the talker
242 //////////////////////////////////////
244 void KTTSDLib::slotTextFinished(const uint job)
246 kDebug(100200) << "---- KTTSDLib::slotTextFinished(" << job << ")" << endl;
248 // check if List is empty. If yes, send signalFinished().
249 if ( jobList.empty() ){
250 kDebug(100200) << " All jobs processed." << endl;
251 emit signalFinished();
252 } else {
253 sayText();
257 void KTTSDLib::slotTextStopped(const uint job)
259 kDebug(100200) << "---- KTTSDLib::slotTextStopped(" << job << ")" << endl;
260 // removeAllJobsFromList();
261 // emit signalFinished();
265 void KTTSDLib::slotTextStarted(const uint job)
267 kDebug(100200) << "---- KTTSDLib::slotTextStarted(" << job << ")" << endl;
268 // m_curJobNum = job;
271 #include "kttsdlib.moc"