Port QtDBus to QMetaMethod-based connectNotify()
authorKent Hansen <kent.hansen@nokia.com>
Sun, 22 Apr 2012 13:05:56 +0000 (15:05 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 30 Apr 2012 23:18:03 +0000 (01:18 +0200)
The const char *-based API is deprecated and will be removed in Qt5.

Change-Id: I1c7f0e46149964367f42faccfff4b89acbf16511
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/dbus/qdbusabstractinterface.cpp
src/dbus/qdbusabstractinterface.h
src/dbus/qdbusconnection_p.h
src/dbus/qdbusconnectioninterface.cpp
src/dbus/qdbusconnectioninterface.h
src/dbus/qdbusintegrator.cpp

index 79c607e..76089f2 100644 (file)
@@ -577,7 +577,7 @@ bool QDBusAbstractInterface::callWithCallback(const QString &method,
     \internal
     Catch signal connections.
 */
-void QDBusAbstractInterface::connectNotify(const char *signal)
+void QDBusAbstractInterface::connectNotify(const QMetaMethod &signal)
 {
     // someone connecting to one of our signals
     Q_D(QDBusAbstractInterface);
@@ -585,7 +585,8 @@ void QDBusAbstractInterface::connectNotify(const char *signal)
         return;
 
     // we end up recursing here, so optimize away
-    if (qstrcmp(signal + 1, "destroyed(QObject*)") == 0)
+    static const QMetaMethod destroyedSignal = QMetaMethod::fromSignal(&QDBusAbstractInterface::destroyed);
+    if (signal == destroyedSignal)
         return;
 
     QDBusConnectionPrivate *conn = d->connectionPrivate();
@@ -599,7 +600,7 @@ void QDBusAbstractInterface::connectNotify(const char *signal)
     \internal
     Catch signal disconnections.
 */
-void QDBusAbstractInterface::disconnectNotify(const char *signal)
+void QDBusAbstractInterface::disconnectNotify(const QMetaMethod &signal)
 {
     // someone disconnecting from one of our signals
     Q_D(QDBusAbstractInterface);
index 648229c..2752458 100644 (file)
@@ -146,8 +146,8 @@ protected:
                            const QDBusConnection &connection, QObject *parent);
     QDBusAbstractInterface(QDBusAbstractInterfacePrivate &, QObject *parent);
 
-    void connectNotify(const char *signal);
-    void disconnectNotify(const char *signal);
+    void connectNotify(const QMetaMethod &signal);
+    void disconnectNotify(const QMetaMethod &signal);
     QVariant internalPropGet(const char *propname) const;
     void internalPropSet(const char *propname, const QVariant &value);
     QDBusMessage internalConstCall(QDBus::CallMode mode,
index fb53f3e..d249789 100644 (file)
@@ -210,10 +210,10 @@ public:
     void registerObject(const ObjectTreeNode *node);
     void connectRelay(const QString &service,
                       const QString &path, const QString &interface,
-                      QDBusAbstractInterface *receiver, const char *signal);
+                      QDBusAbstractInterface *receiver, const QMetaMethod &signal);
     void disconnectRelay(const QString &service,
                          const QString &path, const QString &interface,
-                         QDBusAbstractInterface *receiver, const char *signal);
+                         QDBusAbstractInterface *receiver, const QMetaMethod &signal);
     void registerService(const QString &serviceName);
     void unregisterService(const QString &serviceName);
 
index 0f85f90..1b7b699 100644 (file)
@@ -44,6 +44,7 @@
 #include <QtCore/QByteArray>
 #include <QtCore/QList>
 #include <QtCore/QMap>
+#include <QtCore/QMetaMethod>
 #include <QtCore/QString>
 #include <QtCore/QStringList>
 #include <QtCore/QVariant>
@@ -328,41 +329,53 @@ QDBusConnectionInterface::unregisterService(const QString &serviceName)
 /*!
     \internal
 */
-void QDBusConnectionInterface::connectNotify(const char *signalName)
+void QDBusConnectionInterface::connectNotify(const QMetaMethod &signal)
 {
     // translate the signal names to what we really want
     // this avoids setting hooks for signals that don't exist on the bus
-    if (qstrcmp(signalName, SIGNAL(serviceRegistered(QString))) == 0)
-        QDBusAbstractInterface::connectNotify(SIGNAL(NameAcquired(QString)));
-
-    else if (qstrcmp(signalName, SIGNAL(serviceUnregistered(QString))) == 0)
-        QDBusAbstractInterface::connectNotify(SIGNAL(NameLost(QString)));
-
-    else if (qstrcmp(signalName, SIGNAL(serviceOwnerChanged(QString,QString,QString))) == 0) {
+    static const QMetaMethod serviceRegisteredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceRegistered);
+    static const QMetaMethod serviceUnregisteredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceUnregistered);
+    static const QMetaMethod serviceOwnerChangedSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceOwnerChanged);
+    static const QMetaMethod NameAcquiredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameAcquired);
+    static const QMetaMethod NameLostSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameLost);
+    static const QMetaMethod NameOwnerChangedSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameOwnerChanged);
+    if (signal == serviceRegisteredSignal)
+        QDBusAbstractInterface::connectNotify(NameAcquiredSignal);
+
+    else if (signal == serviceUnregisteredSignal)
+        QDBusAbstractInterface::connectNotify(NameLostSignal);
+
+    else if (signal == serviceOwnerChangedSignal) {
         static bool warningPrinted = false;
         if (!warningPrinted) {
             qWarning("Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)");
             warningPrinted = true;
         }
-        QDBusAbstractInterface::connectNotify(SIGNAL(NameOwnerChanged(QString,QString,QString)));
+        QDBusAbstractInterface::connectNotify(NameOwnerChangedSignal);
     }
 }
 
 /*!
     \internal
 */
-void QDBusConnectionInterface::disconnectNotify(const char *signalName)
+void QDBusConnectionInterface::disconnectNotify(const QMetaMethod &signal)
 {
     // translate the signal names to what we really want
     // this avoids setting hooks for signals that don't exist on the bus
-    if (qstrcmp(signalName, SIGNAL(serviceRegistered(QString))) == 0)
-        QDBusAbstractInterface::disconnectNotify(SIGNAL(NameAcquired(QString)));
-
-    else if (qstrcmp(signalName, SIGNAL(serviceUnregistered(QString))) == 0)
-        QDBusAbstractInterface::disconnectNotify(SIGNAL(NameLost(QString)));
-
-    else if (qstrcmp(signalName, SIGNAL(serviceOwnerChanged(QString,QString,QString))) == 0)
-        QDBusAbstractInterface::disconnectNotify(SIGNAL(NameOwnerChanged(QString,QString,QString)));
+    static const QMetaMethod serviceRegisteredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceRegistered);
+    static const QMetaMethod serviceUnregisteredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceUnregistered);
+    static const QMetaMethod serviceOwnerChangedSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::serviceOwnerChanged);
+    static const QMetaMethod NameAcquiredSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameAcquired);
+    static const QMetaMethod NameLostSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameLost);
+    static const QMetaMethod NameOwnerChangedSignal = QMetaMethod::fromSignal(&QDBusConnectionInterface::NameOwnerChanged);
+    if (signal == serviceRegisteredSignal)
+        QDBusAbstractInterface::disconnectNotify(NameAcquiredSignal);
+
+    else if (signal == serviceUnregisteredSignal)
+        QDBusAbstractInterface::disconnectNotify(NameLostSignal);
+
+    else if (signal == serviceOwnerChangedSignal)
+        QDBusAbstractInterface::disconnectNotify(NameOwnerChangedSignal);
 }
 
 // signals
index b3651c8..e822edd 100644 (file)
@@ -116,8 +116,8 @@ Q_SIGNALS:
     void NameLost(const QString &);
     void NameOwnerChanged(const QString &, const QString &, const QString &);
 protected:
-    void connectNotify(const char *);
-    void disconnectNotify(const char *);
+    void connectNotify(const QMetaMethod &);
+    void disconnectNotify(const QMetaMethod &);
 #endif
 };
 
index 5bdd0ee..35b40a1 100644 (file)
@@ -2236,14 +2236,17 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
 void QDBusConnectionPrivate::connectRelay(const QString &service,
                                           const QString &path, const QString &interface,
                                           QDBusAbstractInterface *receiver,
-                                          const char *signal)
+                                          const QMetaMethod &signal)
 {
     // this function is called by QDBusAbstractInterface when one of its signals is connected
     // we set up a relay from D-Bus into it
     SignalHook hook;
     QString key;
 
-    if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal,
+    QByteArray sig;
+    sig.append(QSIGNAL_CODE + '0');
+    sig.append(signal.methodSignature());
+    if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, sig,
                      QDBusAbstractInterface::staticMetaObject.methodCount(), true))
         return;                 // don't connect
 
@@ -2267,14 +2270,17 @@ void QDBusConnectionPrivate::connectRelay(const QString &service,
 void QDBusConnectionPrivate::disconnectRelay(const QString &service,
                                              const QString &path, const QString &interface,
                                              QDBusAbstractInterface *receiver,
-                                             const char *signal)
+                                             const QMetaMethod &signal)
 {
     // this function is called by QDBusAbstractInterface when one of its signals is disconnected
     // we remove relay from D-Bus into it
     SignalHook hook;
     QString key;
 
-    if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal,
+    QByteArray sig;
+    sig.append(QSIGNAL_CODE + '0');
+    sig.append(signal.methodSignature());
+    if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, sig,
                      QDBusAbstractInterface::staticMetaObject.methodCount(), true))
         return;                 // don't connect