Port QtDBus to QMetaMethod-based connectNotify()

The const char *-based API is deprecated and will be removed in Qt5.

Change-Id: I1c7f0e46149964367f42faccfff4b89acbf16511
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Kent Hansen 2012-04-22 15:05:56 +02:00 committed by Qt by Nokia
parent e525957253
commit a08e0fca27
6 changed files with 47 additions and 27 deletions

View 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);

View 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,

View 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);

View 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)));
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 (qstrcmp(signalName, SIGNAL(serviceUnregistered(QString))) == 0)
QDBusAbstractInterface::connectNotify(SIGNAL(NameLost(QString)));
else if (signal == serviceUnregisteredSignal)
QDBusAbstractInterface::connectNotify(NameLostSignal);
else if (qstrcmp(signalName, SIGNAL(serviceOwnerChanged(QString,QString,QString))) == 0) {
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)));
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 (qstrcmp(signalName, SIGNAL(serviceUnregistered(QString))) == 0)
QDBusAbstractInterface::disconnectNotify(SIGNAL(NameLost(QString)));
else if (signal == serviceUnregisteredSignal)
QDBusAbstractInterface::disconnectNotify(NameLostSignal);
else if (qstrcmp(signalName, SIGNAL(serviceOwnerChanged(QString,QString,QString))) == 0)
QDBusAbstractInterface::disconnectNotify(SIGNAL(NameOwnerChanged(QString,QString,QString)));
else if (signal == serviceOwnerChangedSignal)
QDBusAbstractInterface::disconnectNotify(NameOwnerChangedSignal);
}
// signals

View 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
};

View 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