Fix header
[kdeaccessibility.git] / ksayit / KTTSD_Lib / kttsdlib.cpp
blob87267923e8dd94a5f19afc761557d09a148a6fef
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
15 #include <QString>
16 #include <QStringList>
17 //Added by qt3to4:
18 #include <QFrame>
20 // KDE includes
21 #include <kglobal.h>
22 #include <klocale.h>
23 #include <kstandarddirs.h>
24 #include <kprocess.h>
25 #include <kmessagebox.h>
26 #include <kdebug.h>
28 // App specific includes
29 #include "kttsdlib.h"
30 #include "kttsdlibtalker2.h"
31 // #include "kttsdlibsetupimpl.h"
34 KTTSDLib::KTTSDLib(QObject *parent, const char *name, KApplication *Appl)
35 : QObject(parent), m_Appl(Appl), m_gui(NULL)
37 setObjectName(name);
38 KGlobal::locale()->insertCatalog("libKTTSD");
39 m_talker = new kttsdlibtalker2(static_cast<QObject*>(this), "kttsdlibtalker");
40 connect(m_talker, SIGNAL(signalTextFinished(const uint)),
41 this, SLOT(slotTextFinished(const uint)) );
42 connect(m_talker, SIGNAL(signalTextStopped(const uint)),
43 this, SLOT(slotTextStopped(const uint)) );
44 connect(m_talker, SIGNAL(signalTextStarted(const uint)),
45 this, SLOT(slotTextStarted(const uint)) );
47 // reset list of currently processed jobs
48 while ( !jobList.empty() ){
49 jobList.pop();
52 // initialize the talker
53 m_talker->KTTSD_init(m_Appl);
55 // some presets
56 // m_config = new KSimpleConfig("ksayit_kttsdpluginrc");
57 // m_usersetupimpl = NULL;
61 KTTSDLib::~KTTSDLib()
63 // delete m_config;
67 QString KTTSDLib::getName() const
69 return "KDE KTTSD";
73 QString KTTSDLib::getDescription() const
75 QString str;
76 str = i18n("<qt><big><u>Description:</u></big><br>");
77 str += i18n("This plugin uses the KDE TTS Daemon for speech output.");
79 return str;
83 int KTTSDLib::getActions()
85 return ACTIONS::PLAY | ACTIONS::STOP | ACTIONS::PAUSE | ACTIONS::FFWD | ACTIONS::FREV;
89 int KTTSDLib::getStatus() const
91 return TTS::AUDIOFILE;
95 const QWidget* KTTSDLib::getGUI(QFrame *frame)
97 kDebug(100200) << "KTTSDLib::getGUI()" << endl;
98 QWidget *w = new QWidget(frame);
99 m_gui = new Ui::KTTSDlibSetup();
100 m_gui->setupUi(w);
101 connect(m_gui->kcm_Button, SLOT(clicked()),
102 this, SLOT(slotLaunchControlcenter()));
103 return w;
107 void KTTSDLib::reloadConfiguration()
109 kDebug(100200) << "KTTSDLib::reloadConfiguration()" << endl;
110 // N.A.
114 bool KTTSDLib::saveWasClicked() const
116 kDebug(100200) << "KTTSDLib::saveWasClicked()" << endl;
117 // N.A.
119 return true;
122 void KTTSDLib::slotLaunchControlcenter()
124 kDebug(100200) << "KTTSDlibSetupImpl::slotLaunchControlCenter()" << endl;
126 // check if controllcenter module for KTTSD exists
127 FILE *fp;
128 char cmdresult[20];
130 // TODO: Don't launch kcmshell kcmkttsd if already active.
131 // bool configActive = (QDBus::sessionBus().busService()->nameHasOwner("org.kde.kcmshell_kcmkttsd"));
133 // if ( (fp = popen("kcmshell --list | grep kcmkttsmgr", "r")) != NULL){
134 if ( (fp = popen("kcmshell --list | grep kcmkttsd", "r")) != NULL){
135 fgets(cmdresult, 18, fp);
136 pclose(fp);
138 if ( !QByteArray(cmdresult).contains("kcmkttsd") ){
139 QString error = i18n("Control Center Module for KTTSD not found.");
140 KMessageBox::sorry(m_Appl->activeWindow(), error, i18n("Problem"));
141 return;
144 // invoke the Control Center Module
145 KProcess *kcmproc = new KProcess();
146 connect(kcmproc, SIGNAL(processExited(KProcess*)),
147 this, SLOT(slotKCMProcessExited(KProcess*)) );
148 (*kcmproc) << "kcmshell";
149 (*kcmproc) << "kcmkttsd";
150 (*kcmproc) << "--caption" << i18n("KDE Text-to-Speech");
151 kcmproc->start(KProcess::NotifyOnExit);
153 m_gui->kcm_Button->setEnabled(false);
157 void KTTSDLib::slotKCMProcessExited(KProcess *p)
159 Q_UNUSED(p);
160 kDebug(100200) << "slotKCMProcessExited()" << endl;
161 m_gui->kcm_Button->setEnabled(true);
165 void KTTSDLib::setText(const QString &text)
167 kDebug(100200) << "KTTSDLib::setText()" << endl;
169 uint jobNum = m_talker->KTTSD_setText(text, "");
170 jobList.push(jobNum);
175 void KTTSDLib::sayText()
177 kDebug(100200) << "KTTSDLib::sayText()" << endl;
179 if( !jobList.empty() ){
180 m_curJobNum = jobList.front();
181 jobList.pop();
182 kDebug(100200) << " Starting job No.: " << m_curJobNum << endl;
183 m_talker->KTTSD_startText( m_curJobNum );
188 void KTTSDLib::removeAllJobsFromList()
190 kDebug(100200) << "KTTSDLib::removeAllJobsFromList()" << endl;
192 m_talker->KTTSD_removeText(m_curJobNum);
194 while( !jobList.empty() ){
195 uint job = jobList.front();
196 jobList.pop();
197 kDebug(100200) << "*** removing... " << job << endl;
198 m_talker->KTTSD_removeText( job );
202 void KTTSDLib::stop()
204 kDebug(100200) << "***** KTTSDLib::stop(" << m_curJobNum << ")" << endl;
205 m_talker->KTTSD_stopText(m_curJobNum);
206 removeAllJobsFromList();
207 emit signalFinished();
211 void KTTSDLib::pause()
213 kDebug(100200) << "void KTTSDLib::pause(" << m_curJobNum << ")" << endl;
215 m_talker->KTTSD_pauseText( m_curJobNum );
219 void KTTSDLib::resume()
221 kDebug(100200) << "void KTTSDLib::resume(" << m_curJobNum << ")" << endl;
223 m_talker->KTTSD_resumeText( m_curJobNum );
227 void KTTSDLib::ffwd()
229 kDebug(100200) << "void KTTSDLib::ffwd(" << m_curJobNum << ")" << endl;
230 m_talker->KTTSD_moveRelTextSentence(1, m_curJobNum);
234 void KTTSDLib::frev()
236 kDebug(100200) << "void KTTSDLib::frev(" << m_curJobNum << ")" << endl;
237 m_talker->KTTSD_moveRelTextSentence(-1, m_curJobNum);
241 //////////////////////////////////////
242 // Signals from the talker
243 //////////////////////////////////////
245 void KTTSDLib::slotTextFinished(const uint job)
247 kDebug(100200) << "---- KTTSDLib::slotTextFinished(" << job << ")" << endl;
249 // check if List is empty. If yes, send signalFinished().
250 if ( jobList.empty() ){
251 kDebug(100200) << " All jobs processed." << endl;
252 emit signalFinished();
253 } else {
254 sayText();
258 void KTTSDLib::slotTextStopped(const uint job)
260 kDebug(100200) << "---- KTTSDLib::slotTextStopped(" << job << ")" << endl;
261 // removeAllJobsFromList();
262 // emit signalFinished();
266 void KTTSDLib::slotTextStarted(const uint job)
268 kDebug(100200) << "---- KTTSDLib::slotTextStarted(" << job << ")" << endl;
269 // m_curJobNum = job;
272 #include "kttsdlib.moc"