From efcd020e2a0458af4c835ad51c2487f34c8fc511 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 14 Aug 2010 13:18:55 +0000 Subject: [PATCH] port TTS to QDBusServiceWatcher svn path=/trunk/KDE/kdegraphics/okular/; revision=1163584 --- ui/tts.cpp | 21 +++++++-------------- ui/tts.h | 1 - 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/ui/tts.cpp b/ui/tts.cpp index d02d77e2e..3195ca3f8 100644 --- a/ui/tts.cpp +++ b/ui/tts.cpp @@ -9,6 +9,7 @@ #include "tts.h" +#include #include #include @@ -23,6 +24,7 @@ class OkularTTS::Private public: Private( OkularTTS *qq ) : q( qq ), kspeech( 0 ) + , watcher( "org.kde.kttsd", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration ) { } @@ -32,6 +34,7 @@ public: OkularTTS *q; org::kde::KSpeech* kspeech; QSet< int > jobs; + QDBusServiceWatcher watcher; }; void OkularTTS::Private::setupIface() @@ -64,17 +67,11 @@ void OkularTTS::Private::setupIface() 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 & ) ), - q, SLOT( slotServiceOwnerChanged( const QString &, const QString &, const QString & ) ) ); } } void OkularTTS::Private::teardownIface() { - disconnect( QDBusConnection::sessionBus().interface(), 0, q, 0 ); - delete kspeech; kspeech = 0; } @@ -83,10 +80,14 @@ void OkularTTS::Private::teardownIface() OkularTTS::OkularTTS( QObject *parent ) : QObject( parent ), d( new Private( this ) ) { + connect( &d->watcher, SIGNAL( serviceUnregistered( const QString & ) ), + this, SLOT( slotServiceUnregistered( const QString & ) ) ); } OkularTTS::~OkularTTS() { + disconnect( &d->watcher, 0, this, 0 ); + delete d; } @@ -123,14 +124,6 @@ void OkularTTS::slotServiceUnregistered( const QString &service ) } } -void OkularTTS::slotServiceOwnerChanged( const QString &service, const QString &, const QString &newOwner ) -{ - if ( service == QLatin1String( "org.kde.kttsd" ) && newOwner.isEmpty() ) - { - d->teardownIface(); - } -} - void OkularTTS::slotJobStateChanged( const QString &appId, int jobNum, int state ) { // discard non ours job diff --git a/ui/tts.h b/ui/tts.h index d9eb59324..cb990e97b 100644 --- a/ui/tts.h +++ b/ui/tts.h @@ -28,7 +28,6 @@ class OkularTTS : public QObject private slots: void slotServiceUnregistered( const QString& ); - void slotServiceOwnerChanged( const QString&, const QString&, const QString& ); void slotJobStateChanged( const QString &appId, int jobNum, int state ); private: