[Telepathy-commits] [telepathy-qt4/master] Moved ConnectionManager slots to ConnectionManager::Private class.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Jan 6 11:53:38 PST 2009


Moved ConnectionManager slots to ConnectionManager::Private class and make
ConnectionManager::Private a QObject.
---
 TelepathyQt4/Client/connection-manager-internal.h |   28 ++-
 TelepathyQt4/Client/connection-manager.cpp        |  204 +++++++++++----------
 TelepathyQt4/Client/connection-manager.h          |   10 +-
 3 files changed, 123 insertions(+), 119 deletions(-)

diff --git a/TelepathyQt4/Client/connection-manager-internal.h b/TelepathyQt4/Client/connection-manager-internal.h
index f5537b7..b6d706b 100644
--- a/TelepathyQt4/Client/connection-manager-internal.h
+++ b/TelepathyQt4/Client/connection-manager-internal.h
@@ -37,17 +37,11 @@ namespace Client
 class ConnectionManager;
 class ConnectionManagerInterface;
 
-struct ConnectionManager::Private
+class ConnectionManager::Private : public QObject
 {
-    ConnectionManager *parent;
-    ConnectionManagerInterface* baseInterface;
-    bool ready;
-    QQueue<void (Private::*)()> introspectQueue;
-    QQueue<QString> getParametersQueue;
-    QQueue<QString> protocolQueue;
-    QStringList interfaces;
-    ProtocolInfoList protocols;
+    Q_OBJECT
 
+public:
     Private(ConnectionManager *parent);
     ~Private();
 
@@ -63,9 +57,23 @@ struct ConnectionManager::Private
     void callListProtocols();
 
     class PendingReady;
+    class PendingNames;
+
+    ConnectionManager *parent;
+    ConnectionManagerInterface* baseInterface;
+    bool ready;
+    QQueue<void (Private::*)()> introspectQueue;
+    QQueue<QString> getParametersQueue;
+    QQueue<QString> protocolQueue;
+    QStringList interfaces;
+    ProtocolInfoList protocols;
     PendingReady *pendingReady;
 
-    class PendingNames;
+private Q_SLOTS:
+    void onGetParametersReturn(QDBusPendingCallWatcher*);
+    void onListProtocolsReturn(QDBusPendingCallWatcher*);
+    void onGetAllConnectionManagerReturn(QDBusPendingCallWatcher*);
+    void continueIntrospection();
 };
 
 class ConnectionManager::Private::PendingReady : public PendingOperation
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index 8942a73..ddd0015 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -226,7 +226,8 @@ void ConnectionManager::Private::PendingNames::parseResult(const QStringList &na
 
 
 ConnectionManager::Private::Private(ConnectionManager *parent)
-    : parent(parent),
+    : QObject(parent),
+      parent(parent),
       baseInterface(new ConnectionManagerInterface(parent->dbusConnection(),
                     parent->busName(), parent->objectPath(), parent)),
       ready(false),
@@ -235,7 +236,7 @@ ConnectionManager::Private::Private(ConnectionManager *parent)
     debug() << "Creating new ConnectionManager:" << parent->busName();
 
     introspectQueue.enqueue(&Private::callReadConfig);
-    QTimer::singleShot(0, parent, SLOT(continueIntrospection()));
+    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
 }
 
 
@@ -312,7 +313,7 @@ void ConnectionManager::Private::callReadConfig()
         introspectQueue.enqueue(&Private::callListProtocols);
     }
 
-    parent->continueIntrospection();
+    continueIntrospection();
 }
 
 
@@ -322,7 +323,7 @@ void ConnectionManager::Private::callGetAll()
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
             parent->propertiesInterface()->GetAll(
                 TELEPATHY_INTERFACE_CONNECTION_MANAGER), parent);
-    parent->connect(watcher,
+    connect(watcher,
             SIGNAL(finished(QDBusPendingCallWatcher*)),
             SLOT(onGetAllConnectionManagerReturn(QDBusPendingCallWatcher*)));
 }
@@ -336,7 +337,7 @@ void ConnectionManager::Private::callGetParameters()
         protocol << ")";
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
             baseInterface->GetParameters(protocol), parent);
-    parent->connect(watcher,
+    connect(watcher,
             SIGNAL(finished(QDBusPendingCallWatcher*)),
             SLOT(onGetParametersReturn(QDBusPendingCallWatcher*)));
 }
@@ -347,12 +348,108 @@ void ConnectionManager::Private::callListProtocols()
     debug() << "Calling ConnectionManager::ListProtocols";
     QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
             baseInterface->ListProtocols(), parent);
-    parent->connect(watcher,
+    connect(watcher,
             SIGNAL(finished(QDBusPendingCallWatcher*)),
             SLOT(onListProtocolsReturn(QDBusPendingCallWatcher*)));
 }
 
 
+void ConnectionManager::Private::onGetAllConnectionManagerReturn(
+        QDBusPendingCallWatcher* watcher)
+{
+    QDBusPendingReply<QVariantMap> reply = *watcher;
+    QVariantMap props;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to Properties.GetAll(ConnectionManager)";
+        props = reply.value();
+    } else {
+        warning().nospace() <<
+            "Properties.GetAll(ConnectionManager) failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+    }
+
+    // If Interfaces is not supported, the spec says to assume it's
+    // empty, so keep the empty list mPriv was initialized with
+    if (props.contains("Interfaces")) {
+        interfaces = qdbus_cast<QStringList>(props["Interfaces"]);
+    }
+    continueIntrospection();
+}
+
+
+void ConnectionManager::Private::onListProtocolsReturn(
+        QDBusPendingCallWatcher* watcher)
+{
+    QDBusPendingReply<QStringList> reply = *watcher;
+    QStringList protocolsNames;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to ConnectionManager.ListProtocols";
+        protocolsNames = reply.value();
+    } else {
+        warning().nospace() <<
+            "ConnectionManager.ListProtocols failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+    }
+
+    Q_FOREACH (const QString &protocolName, protocolsNames) {
+        protocols.append(new ProtocolInfo(parent->name(),
+                                          protocolName));
+
+        getParametersQueue.enqueue(protocolName);
+        introspectQueue.enqueue(&Private::callGetParameters);
+    }
+    continueIntrospection();
+}
+
+
+void ConnectionManager::Private::onGetParametersReturn(
+        QDBusPendingCallWatcher* watcher)
+{
+    QDBusPendingReply<ParamSpecList> reply = *watcher;
+    ParamSpecList parameters;
+    QString protocolName = protocolQueue.dequeue();
+    ProtocolInfo *info = protocol(protocolName);
+
+    if (!reply.isError()) {
+        debug() << "Got reply to ConnectionManager.GetParameters";
+        parameters = reply.value();
+    } else {
+        warning().nospace() <<
+            "ConnectionManager.GetParameters failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+    }
+
+    Q_FOREACH (const ParamSpec& spec, parameters) {
+        debug() << "Parameter" << spec.name << "has flags" << spec.flags
+            << "and signature" << spec.signature;
+
+        info->addParameter(spec);
+    }
+    continueIntrospection();
+}
+
+
+void ConnectionManager::Private::continueIntrospection()
+{
+    if (!ready) {
+        if (introspectQueue.isEmpty()) {
+            debug() << "ConnectionManager is ready";
+            ready = true;
+
+            if (pendingReady) {
+                pendingReady->setFinished();
+                // it will delete itself later
+                pendingReady = 0;
+            }
+        } else {
+            (this->*(introspectQueue.dequeue()))();
+        }
+    }
+}
+
+
 ConnectionManager::ConnectionManager(const QString& name, QObject* parent)
     : StatelessDBusProxy(QDBusConnection::sessionBus(),
             Private::makeBusName(name), Private::makeObjectPath(name),
@@ -434,100 +531,5 @@ ConnectionManagerInterface* ConnectionManager::baseInterface() const
     return mPriv->baseInterface;
 }
 
-
-void ConnectionManager::onGetAllConnectionManagerReturn(
-        QDBusPendingCallWatcher* watcher)
-{
-    QDBusPendingReply<QVariantMap> reply = *watcher;
-    QVariantMap props;
-
-    if (!reply.isError()) {
-        debug() << "Got reply to Properties.GetAll(ConnectionManager)";
-        props = reply.value();
-    } else {
-        warning().nospace() <<
-            "Properties.GetAll(ConnectionManager) failed: " <<
-            reply.error().name() << ": " << reply.error().message();
-    }
-
-    // If Interfaces is not supported, the spec says to assume it's
-    // empty, so keep the empty list mPriv was initialized with
-    if (props.contains("Interfaces")) {
-        mPriv->interfaces = qdbus_cast<QStringList>(props["Interfaces"]);
-    }
-    continueIntrospection();
-}
-
-
-void ConnectionManager::onListProtocolsReturn(
-        QDBusPendingCallWatcher* watcher)
-{
-    QDBusPendingReply<QStringList> reply = *watcher;
-    QStringList protocols;
-
-    if (!reply.isError()) {
-        debug() << "Got reply to ConnectionManager.ListProtocols";
-        protocols = reply.value();
-    } else {
-        warning().nospace() <<
-            "ConnectionManager.ListProtocols failed: " <<
-            reply.error().name() << ": " << reply.error().message();
-    }
-
-    Q_FOREACH (const QString &protocolName, protocols) {
-        mPriv->protocols.append(new ProtocolInfo(mName,
-                                                 protocolName));
-
-        mPriv->getParametersQueue.enqueue(protocolName);
-        mPriv->introspectQueue.enqueue(&Private::callGetParameters);
-    }
-    continueIntrospection();
-}
-
-
-void ConnectionManager::onGetParametersReturn(
-        QDBusPendingCallWatcher* watcher)
-{
-    QDBusPendingReply<ParamSpecList> reply = *watcher;
-    ParamSpecList parameters;
-    QString protocolName = mPriv->protocolQueue.dequeue();
-    ProtocolInfo *info = mPriv->protocol(protocolName);
-
-    if (!reply.isError()) {
-        debug() << "Got reply to ConnectionManager.GetParameters";
-        parameters = reply.value();
-    } else {
-        warning().nospace() <<
-            "ConnectionManager.GetParameters failed: " <<
-            reply.error().name() << ": " << reply.error().message();
-    }
-
-    Q_FOREACH (const ParamSpec& spec, parameters) {
-        debug() << "Parameter" << spec.name << "has flags" << spec.flags
-            << "and signature" << spec.signature;
-
-        info->addParameter(spec);
-    }
-    continueIntrospection();
-}
-
-void ConnectionManager::continueIntrospection()
-{
-    if (!mPriv->ready) {
-        if (mPriv->introspectQueue.isEmpty()) {
-            debug() << "ConnectionManager is ready";
-            mPriv->ready = true;
-
-            if (mPriv->pendingReady) {
-                mPriv->pendingReady->setFinished();
-                // it will delete itself later
-                mPriv->pendingReady = 0;
-            }
-        } else {
-            (mPriv->*(mPriv->introspectQueue.dequeue()))();
-        }
-    }
-}
-
 } // Telepathy::Client
 } // Telepathy
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index 86d7caf..ca310b5 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -241,17 +241,11 @@ protected:
      */
     ConnectionManagerInterface* baseInterface() const;
 
-private Q_SLOTS:
-    void onGetParametersReturn(QDBusPendingCallWatcher*);
-    void onListProtocolsReturn(QDBusPendingCallWatcher*);
-    void onGetAllConnectionManagerReturn(QDBusPendingCallWatcher*);
-    void continueIntrospection();
-
 private:
     Q_DISABLE_COPY(ConnectionManager);
 
-    struct Private;
-    friend struct Private;
+    class Private;
+    friend class Private;
     Private *mPriv;
     QString mName;
 };
-- 
1.5.6.5




More information about the Telepathy-commits mailing list