Here is the last one. (NepmukServer)

The problem with the complete patch is that I had no way of testing when a
service wasn't attached and un-registers. However the
slotServiceUnregistered is called so I think everything should work. :-)

- Vishesh Handa
Index: servicecontroller.cpp
===================================================================
--- servicecontroller.cpp	(revision 1114727)
+++ servicecontroller.cpp	(working copy)
@@ -24,6 +24,8 @@
 #include <QtCore/QEventLoop>
 #include <QtCore/QTimer>
 
+#include <QtDBus/QDBusServiceWatcher>
+
 #include <KStandardDirs>
 #include <KConfigGroup>
 #include <KDebug>
@@ -175,7 +177,11 @@
                      this, SLOT( slotProcessFinished( bool ) ) );
         }
 
-        connect( QDBusConnection::sessionBus().interface(),
+        QDBusServiceWatcher * watcher = new QDBusServiceWatcher( dbusServiceName(name()),
+                                                                 QDBusConnection::sessionBus(),
+                                                                 QDBusServiceWatcher::WatchForOwnerChange,
+                                                                 this );
+        connect( watcher,
                  SIGNAL( serviceOwnerChanged( const QString&, const QString&, const QString& ) ),
                  this,
                  SLOT( slotServiceOwnerChanged( const QString&, const QString&, const QString& ) ) );
Index: servicecontroller.cpp
===================================================================
--- servicecontroller.cpp	(revision 1114727)
+++ servicecontroller.cpp	(working copy)
@@ -24,6 +24,8 @@
 #include <QtCore/QEventLoop>
 #include <QtCore/QTimer>
 
+#include <QtDBus/QDBusServiceWatcher>
+
 #include <KStandardDirs>
 #include <KConfigGroup>
 #include <KDebug>
@@ -175,10 +177,14 @@
                      this, SLOT( slotProcessFinished( bool ) ) );
         }
 
-        connect( QDBusConnection::sessionBus().interface(),
-                 SIGNAL( serviceOwnerChanged( const QString&, const QString&, const QString& ) ),
-                 this,
-                 SLOT( slotServiceOwnerChanged( const QString&, const QString&, const QString& ) ) );
+        QDBusServiceWatcher * watcher = new QDBusServiceWatcher( dbusServiceName(name()),
+                                                                 QDBusConnection::sessionBus(),
+                                                                 QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration,
+                                                                 this );
+        connect( watcher, SIGNAL( serviceRegistered( const QString& ) ),
+                 this, SLOT( slotServiceRegistered( const QString& ) ) );
+        connect( watcher, SIGNAL( serviceUnregistered( const QString& ) ),
+                 this, SLOT( slotServiceUnregistered( const QString& ) ) );
 
         d->processControl->setCrashPolicy( ProcessControl::RestartOnCrash );
         return d->processControl->start( KGlobal::dirs()->locate( "exe", "nepomukservicestub" ),
@@ -265,19 +271,19 @@
 }
 
 
-void Nepomuk::ServiceController::slotServiceOwnerChanged( const QString& serviceName,
-                                                          const QString& oldOwner,
-                                                          const QString& newOwner )
+void Nepomuk::ServiceController::slotServiceRegistered( const QString& serviceName )
 {
-    if( !newOwner.isEmpty() && serviceName == dbusServiceName( name() ) ) {
+    if( serviceName == dbusServiceName( name() ) ) {
         createServiceControlInterface();
     }
+}
 
+void Nepomuk::ServiceController::slotServiceUnregistered( const QString& serviceName )
+{
     // an attached service was not started through ProcessControl. Thus, we cannot rely
     // on its restart-on-crash feature and have to do it manually. Afterwards it is back
     // to normals
-    else if( d->attached &&
-             oldOwner == dbusServiceName( name() ) ) {
+    if( d->attached && serviceName == dbusServiceName( name() ) ) {
         kDebug() << "Attached service" << name() << "went down. Restarting ourselves.";
         d->attached = false;
         start();
Index: servicecontroller.h
===================================================================
--- servicecontroller.h	(revision 1114727)
+++ servicecontroller.h	(working copy)
@@ -80,9 +80,8 @@
         
     private Q_SLOTS:
         void slotProcessFinished( bool );
-        void slotServiceOwnerChanged( const QString& serviceName,
-                                      const QString&,
-                                      const QString& newOwner );
+        void slotServiceRegistered( const QString& serviceName );
+        void slotServiceUnregistered( const QString& serviceName );
         void slotServiceInitialized( bool success );
         
     private:
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to