src/dbus/qdbusabstractinterface.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/dbus/qdbusabstractinterface.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/dbus/qdbusabstractinterface.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -279,9 +279,17 @@
     : QDBusAbstractInterfaceBase(d, parent)
 {
     // keep track of the service owner
-    if (!d_func()->currentOwner.isEmpty())
-        QObject::connect(d_func()->connectionPrivate(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
-                         this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+    if (d.isValid &&
+        d.connection.isConnected()
+        && !d.service.isEmpty()
+        && !d.service.startsWith(QLatin1Char(':')))
+        d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
+                                     QString(), // path
+                                     QLatin1String(DBUS_INTERFACE_DBUS), // interface
+                                     QLatin1String("NameOwnerChanged"),
+                                     QStringList() << d.service,
+                                     QString(), // signature
+                                     this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
 }
 
 /*!
@@ -296,9 +304,17 @@
                                                  con, false), parent)
 {
     // keep track of the service owner
-    if (d_func()->connection.isConnected())
-        QObject::connect(d_func()->connectionPrivate(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
-                         this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+    if (d_func()->isValid &&
+        d_func()->connection.isConnected()
+        && !service.isEmpty()
+        && !service.startsWith(QLatin1Char(':')))
+        d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
+                                     QString(), // path
+                                     QLatin1String(DBUS_INTERFACE_DBUS), // interface
+                                     QLatin1String("NameOwnerChanged"),
+                                     QStringList() << service,
+                                     QString(), //signature
+                                     this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
 }
 
 /*!
@@ -544,9 +560,16 @@
         return;
 
     QDBusConnectionPrivate *conn = d->connectionPrivate();
-    if (conn)
-        conn->connectRelay(d->service, d->currentOwner, d->path, d->interface,
+    if (conn) {
+        // do we know what our owner is?
+        QString owner;
+        if (!d->service.isEmpty() && d->currentOwner.isNull())
+            owner = QLatin1String("");
+        else
+            owner = d->currentOwner;
+        conn->connectRelay(d->service, owner, d->path, d->interface,
                            this, signal);
+    }
 }
 
 /*!