Commit 32baca86 authored by Pino Toscano's avatar Pino Toscano

- keep track of the speech jobs we started

- remove each job when it's finished
- add a signal to notify whether we have jobs

svn path=/trunk/KDE/kdegraphics/okular/; revision=782504
parent 69179e25
......@@ -9,7 +9,10 @@
#include "tts.h"
#include <qset.h>
#include <klocale.h>
#include <kspeech.h>
#include <ktoolinvocation.h>
#include "pageviewutils.h"
......@@ -30,6 +33,7 @@ public:
OkularTTS *q;
PageViewMessage *messageWindow;
org::kde::KSpeech* kspeech;
QSet< int > jobs;
};
void OkularTTS::Private::setupIface()
......@@ -59,6 +63,8 @@ void OkularTTS::Private::setupIface()
// creating the connection to the kspeech interface
kspeech = new org::kde::KSpeech( "org.kde.kttsd", "/KSpeech", QDBusConnection::sessionBus() );
kspeech->setApplicationName( "Okular" );
connect( kspeech, SIGNAL( jobStateChanged( const QString &, int, int ) ),
q, SLOT( slotJobStateChanged( const QString &, int, int ) ) );
connect( QDBusConnection::sessionBus().interface(), SIGNAL( serviceUnregistered( const QString & ) ),
q, SLOT( slotServiceUnregistered( const QString & ) ) );
connect( QDBusConnection::sessionBus().interface(), SIGNAL( serviceOwnerChanged( const QString &, const QString &, const QString & ) ),
......@@ -94,10 +100,23 @@ void OkularTTS::say( const QString &text )
d->setupIface();
if ( d->kspeech )
{
d->kspeech->say( text, 0 );
QDBusReply< int > reply = d->kspeech->say( text, KSpeech::soPlainText );
if ( reply.isValid() )
{
d->jobs.insert( reply.value() );
emit hasSpeechs( true );
}
}
}
void OkularTTS::stopAllSpeechs()
{
if ( !d->kspeech )
return;
d->kspeech->removeAllJobs();
}
void OkularTTS::slotServiceUnregistered( const QString &service )
{
if ( service == QLatin1String( "org.kde.kttsd" ) )
......@@ -114,4 +133,22 @@ void OkularTTS::slotServiceOwnerChanged( const QString &service, const QString &
}
}
void OkularTTS::slotJobStateChanged( const QString &appId, int jobNum, int state )
{
// discard non ours job
if ( appId != QDBusConnection::sessionBus().baseService() || !d->kspeech )
return;
switch ( state )
{
case KSpeech::jsDeleted:
d->jobs.remove( jobNum );
emit hasSpeechs( !d->jobs.isEmpty() );
break;
case KSpeech::jsFinished:
d->kspeech->removeJob( jobNum );
break;
}
}
#include "tts.moc"
......@@ -22,10 +22,15 @@ class OkularTTS : public QObject
~OkularTTS();
void say( const QString &text );
void stopAllSpeechs();
signals:
void hasSpeechs( bool has );
private slots:
void slotServiceUnregistered( const QString& );
void slotServiceOwnerChanged( const QString&, const QString&, const QString& );
void slotJobStateChanged( const QString &appId, int jobNum, int state );
private:
// private storage
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment