2 // C++ Implementation: kttsdplugin
7 // Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
12 // #include <time.h> // nanosleep
15 #include <QtGui/QFrame>
20 #include <kstandarddirs.h>
21 #include <k3process.h>
22 #include <kmessagebox.h>
25 // App specific includes
27 #include "kttsdlibtalker2.h"
28 // #include "kttsdlibsetupimpl.h"
30 KTTSDLib::KTTSDLib(QObject
*parent
, const char *name
, KApplication
*Appl
)
31 : QObject(parent
), m_Appl(Appl
), m_gui(NULL
)
34 KGlobal::locale()->insertCatalog("libKTTSD");
35 m_talker
= new kttsdlibtalker2(static_cast<QObject
*>(this), "kttsdlibtalker");
36 connect(m_talker
, SIGNAL(signalTextFinished(const uint
)),
37 this, SLOT(slotTextFinished(const uint
)) );
38 connect(m_talker
, SIGNAL(signalTextStopped(const uint
)),
39 this, SLOT(slotTextStopped(const uint
)) );
40 connect(m_talker
, SIGNAL(signalTextStarted(const uint
)),
41 this, SLOT(slotTextStarted(const uint
)) );
43 // reset list of currently processed jobs
44 while ( !jobList
.empty() ){
48 // initialize the talker
49 m_talker
->KTTSD_init(m_Appl
);
52 // m_config = new KSimpleConfig("ksayit_kttsdpluginrc");
53 // m_usersetupimpl = NULL;
63 QString
KTTSDLib::getName() const
69 QString
KTTSDLib::getDescription() const
72 str
= i18n("<qt><big><u>Description:</u></big><br>");
73 str
+= i18n("This plugin uses the KDE TTS Daemon for speech output.");
79 int KTTSDLib::getActions()
81 return ACTIONS::PLAY
| ACTIONS::STOP
| ACTIONS::PAUSE
| ACTIONS::FFWD
| ACTIONS::FREV
;
85 int KTTSDLib::getStatus() const
87 return TTS::AUDIOFILE
;
91 const QWidget
* KTTSDLib::getGUI(QFrame
*frame
)
93 kDebug(100200) << "KTTSDLib::getGUI()";
94 QWidget
*w
= new QWidget(frame
);
95 m_gui
= new Ui::KTTSDlibSetup();
97 connect(m_gui
->kcm_Button
, SLOT(clicked()),
98 this, SLOT(slotLaunchControlcenter()));
103 void KTTSDLib::reloadConfiguration()
105 kDebug(100200) << "KTTSDLib::reloadConfiguration()";
110 bool KTTSDLib::saveWasClicked() const
112 kDebug(100200) << "KTTSDLib::saveWasClicked()";
118 void KTTSDLib::slotLaunchControlcenter()
120 kDebug(100200) << "KTTSDlibSetupImpl::slotLaunchControlCenter()";
122 // check if controllcenter module for KTTSD exists
126 // TODO: Don't launch kcmshell4 kcmkttsd if already active.
127 // bool configActive = (QDBus::sessionBus().busService()->nameHasOwner("org.kde.kcmshell_kcmkttsd"));
129 // if ( (fp = popen("kcmshell4 --list | grep kcmkttsmgr", "r")) != NULL){
130 if ( (fp
= popen("kcmshell4 --list | grep kcmkttsd", "r")) != NULL
){
131 fgets(cmdresult
, 18, fp
);
134 if ( !QByteArray(cmdresult
).contains("kcmkttsd") ){
135 QString error
= i18n("Control Center Module for KTTSD not found.");
136 KMessageBox::sorry(m_Appl
->activeWindow(), error
, i18n("Problem"));
140 // invoke the Control Center Module
141 K3Process
*kcmproc
= new K3Process();
142 connect(kcmproc
, SIGNAL(processExited(K3Process
*)),
143 this, SLOT(slotKCMProcessExited(K3Process
*)) );
144 (*kcmproc
) << "kcmshell4";
145 (*kcmproc
) << "kcmkttsd";
146 (*kcmproc
) << "--caption" << i18n("KDE Text-to-Speech");
147 kcmproc
->start(K3Process::NotifyOnExit
);
149 m_gui
->kcm_Button
->setEnabled(false);
153 void KTTSDLib::slotKCMProcessExited(K3Process
*p
)
156 kDebug(100200) << "slotKCMProcessExited()";
157 m_gui
->kcm_Button
->setEnabled(true);
161 void KTTSDLib::setText(const QString
&text
)
163 kDebug(100200) << "KTTSDLib::setText()";
165 uint jobNum
= m_talker
->KTTSD_setText(text
, "");
166 jobList
.push(jobNum
);
171 void KTTSDLib::sayText()
173 kDebug(100200) << "KTTSDLib::sayText()";
175 if( !jobList
.empty() ){
176 m_curJobNum
= jobList
.front();
178 kDebug(100200) << " Starting job No.: " << m_curJobNum
;
179 m_talker
->KTTSD_startText( m_curJobNum
);
184 void KTTSDLib::removeAllJobsFromList()
186 kDebug(100200) << "KTTSDLib::removeAllJobsFromList()";
188 m_talker
->KTTSD_removeText(m_curJobNum
);
190 while( !jobList
.empty() ){
191 uint job
= jobList
.front();
193 kDebug(100200) << "*** removing... " << job
;
194 m_talker
->KTTSD_removeText( job
);
198 void KTTSDLib::stop()
200 kDebug(100200) << "***** KTTSDLib::stop(" << m_curJobNum
<< ")";
201 m_talker
->KTTSD_stopText(m_curJobNum
);
202 removeAllJobsFromList();
203 emit
signalFinished();
207 void KTTSDLib::pause()
209 kDebug(100200) << "void KTTSDLib::pause(" << m_curJobNum
<< ")";
211 m_talker
->KTTSD_pauseText( m_curJobNum
);
215 void KTTSDLib::resume()
217 kDebug(100200) << "void KTTSDLib::resume(" << m_curJobNum
<< ")";
219 m_talker
->KTTSD_resumeText( m_curJobNum
);
223 void KTTSDLib::ffwd()
225 kDebug(100200) << "void KTTSDLib::ffwd(" << m_curJobNum
<< ")";
226 m_talker
->KTTSD_moveRelTextSentence(1, m_curJobNum
);
230 void KTTSDLib::frev()
232 kDebug(100200) << "void KTTSDLib::frev(" << m_curJobNum
<< ")";
233 m_talker
->KTTSD_moveRelTextSentence(-1, m_curJobNum
);
237 //////////////////////////////////////
238 // Signals from the talker
239 //////////////////////////////////////
241 void KTTSDLib::slotTextFinished(const uint job
)
243 kDebug(100200) << "---- KTTSDLib::slotTextFinished(" << job
<< ")";
245 // check if List is empty. If yes, send signalFinished().
246 if ( jobList
.empty() ){
247 kDebug(100200) << " All jobs processed.";
248 emit
signalFinished();
254 void KTTSDLib::slotTextStopped(const uint job
)
256 kDebug(100200) << "---- KTTSDLib::slotTextStopped(" << job
<< ")";
257 // removeAllJobsFromList();
258 // emit signalFinished();
262 void KTTSDLib::slotTextStarted(const uint job
)
264 kDebug(100200) << "---- KTTSDLib::slotTextStarted(" << job
<< ")";
265 // m_curJobNum = job;
268 #include "kttsdlib.moc"