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

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Tue Jan 13 13:21:05 PST 2009


---
 TelepathyQt4/Client/connection-manager-internal.h |   24 +--
 TelepathyQt4/Client/connection-manager.cpp        |  369 +++++++++++----------
 TelepathyQt4/Client/connection-manager.h          |   16 +-
 3 files changed, 203 insertions(+), 206 deletions(-)

diff --git a/TelepathyQt4/Client/connection-manager-internal.h b/TelepathyQt4/Client/connection-manager-internal.h
index a44c721..d1a5aaa 100644
--- a/TelepathyQt4/Client/connection-manager-internal.h
+++ b/TelepathyQt4/Client/connection-manager-internal.h
@@ -37,11 +37,8 @@ namespace Client
 class ConnectionManager;
 class ConnectionManagerInterface;
 
-class ConnectionManager::Private : public QObject
+struct ConnectionManager::Private
 {
-    Q_OBJECT
-
-public:
     Private(const QString &name, ConnectionManager *parent);
     ~Private();
 
@@ -50,37 +47,24 @@ public:
 
     ProtocolInfo *protocol(const QString &protocolName);
 
-    bool checkConfigFile();
-    void callReadConfig();
-    void callGetAll();
-    void callGetParameters();
-    void callListProtocols();
-
     class PendingReady;
     class PendingNames;
 
     ConnectionManagerInterface *baseInterface;
     QString name;
     bool ready;
-    QQueue<void (Private::*)()> introspectQueue;
+    QQueue<void (ConnectionManager::*)()> introspectQueue;
     QQueue<QString> getParametersQueue;
     QQueue<QString> protocolQueue;
     QStringList interfaces;
     ProtocolInfoList protocols;
     PendingReady *pendingReady;
-
-private Q_SLOTS:
-    void onGetParametersReturn(QDBusPendingCallWatcher *);
-    void onListProtocolsReturn(QDBusPendingCallWatcher *);
-    void onGetAllConnectionManagerReturn(QDBusPendingCallWatcher *);
-    void continueIntrospection();
 };
 
-
 class ConnectionManager::Private::PendingReady : public PendingOperation
 {
-    // ConnectionManager::Private is a friend so it can call finished() etc.
-    friend class ConnectionManager::Private;
+    // ConnectionManager is a friend so it can call finished() etc.
+    friend class ConnectionManager;
 
 public:
     PendingReady(ConnectionManager *parent);
diff --git a/TelepathyQt4/Client/connection-manager.cpp b/TelepathyQt4/Client/connection-manager.cpp
index a42a7ef..c209760 100644
--- a/TelepathyQt4/Client/connection-manager.cpp
+++ b/TelepathyQt4/Client/connection-manager.cpp
@@ -286,17 +286,13 @@ void ConnectionManager::Private::PendingNames::parseResult(const QStringList &na
 }
 
 ConnectionManager::Private::Private(const QString &name, ConnectionManager *parent)
-    : QObject(parent),
-      baseInterface(new ConnectionManagerInterface(parent->dbusConnection(),
+    : baseInterface(new ConnectionManagerInterface(parent->dbusConnection(),
                             parent->busName(), parent->objectPath(), parent)),
       name(name),
       ready(false),
       pendingReady(0)
 {
     debug() << "Creating new ConnectionManager:" << parent->busName();
-
-    introspectQueue.enqueue(&Private::callReadConfig);
-    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
 }
 
 ConnectionManager::Private::~Private()
@@ -329,185 +325,6 @@ ProtocolInfo *ConnectionManager::Private::protocol(const QString &protocolName)
     return NULL;
 }
 
-bool ConnectionManager::Private::checkConfigFile()
-{
-    ManagerFile f(name);
-    if (!f.isValid()) {
-        return false;
-    }
-
-    Q_FOREACH (QString protocol, f.protocols()) {
-        ProtocolInfo *info = new ProtocolInfo(name,
-                                              protocol);
-        protocols.append(info);
-
-        Q_FOREACH (ParamSpec spec, f.parameters(protocol)) {
-            info->addParameter(spec);
-        }
-    }
-
-#if 0
-    Q_FOREACH (ProtocolInfo *info, protocols) {
-        qDebug() << "protocol name   :" << info->name();
-        qDebug() << "protocol cn name:" << info->cmName();
-        Q_FOREACH (ProtocolParameter *param, info->parameters()) {
-            qDebug() << "\tparam name:       " << param->name();
-            qDebug() << "\tparam is required:" << param->isRequired();
-            qDebug() << "\tparam is secret:  " << param->isSecret();
-            qDebug() << "\tparam value:      " << param->defaultValue();
-        }
-    }
-#endif
-
-    return true;
-}
-
-void ConnectionManager::Private::callReadConfig()
-{
-    if (!checkConfigFile()) {
-        warning() << "error parsing config file for connection manager" << name;
-        introspectQueue.enqueue(&Private::callGetAll);
-        introspectQueue.enqueue(&Private::callListProtocols);
-    }
-
-    continueIntrospection();
-}
-
-void ConnectionManager::Private::callGetAll()
-{
-    debug() << "Calling Properties::GetAll(ConnectionManager)";
-    ConnectionManager *cm = static_cast<ConnectionManager *>(parent());
-    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
-            cm->propertiesInterface()->GetAll(
-                TELEPATHY_INTERFACE_CONNECTION_MANAGER), this);
-    connect(watcher,
-            SIGNAL(finished(QDBusPendingCallWatcher *)),
-            SLOT(onGetAllConnectionManagerReturn(QDBusPendingCallWatcher *)));
-}
-
-void ConnectionManager::Private::callGetParameters()
-{
-    QString protocol = getParametersQueue.dequeue();
-    protocolQueue.enqueue(protocol);
-    debug() << "Calling ConnectionManager::GetParameters(" << protocol << ")";
-    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
-            baseInterface->GetParameters(protocol), this);
-    connect(watcher,
-            SIGNAL(finished(QDBusPendingCallWatcher *)),
-            SLOT(onGetParametersReturn(QDBusPendingCallWatcher *)));
-}
-
-void ConnectionManager::Private::callListProtocols()
-{
-    debug() << "Calling ConnectionManager::ListProtocols";
-    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
-            baseInterface->ListProtocols(), this);
-    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();
-
-    watcher->deleteLater();
-}
-
-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(name,
-                                          protocolName));
-
-        getParametersQueue.enqueue(protocolName);
-        introspectQueue.enqueue(&Private::callGetParameters);
-    }
-
-    continueIntrospection();
-
-    watcher->deleteLater();
-}
-
-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();
-
-    watcher->deleteLater();
-}
-
-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()))();
-        }
-    }
-}
-
 /**
  * \class ConnectionManager
  * \ingroup clientcm
@@ -533,6 +350,8 @@ ConnectionManager::ConnectionManager(const QString &name, QObject *parent)
             parent),
       mPriv(new Private(name, this))
 {
+    mPriv->introspectQueue.enqueue(&ConnectionManager::callReadConfig);
+    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
 }
 
 /**
@@ -548,6 +367,8 @@ ConnectionManager::ConnectionManager(const QDBusConnection &bus,
             Private::makeObjectPath(name), parent),
       mPriv(new Private(name, this))
 {
+    mPriv->introspectQueue.enqueue(&ConnectionManager::callReadConfig);
+    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
 }
 
 /**
@@ -674,5 +495,185 @@ ConnectionManagerInterface *ConnectionManager::baseInterface() const
     return mPriv->baseInterface;
 }
 
+/**** Private ****/
+bool ConnectionManager::checkConfigFile()
+{
+    ManagerFile f(mPriv->name);
+    if (!f.isValid()) {
+        return false;
+    }
+
+    Q_FOREACH (QString protocol, f.protocols()) {
+        ProtocolInfo *info = new ProtocolInfo(mPriv->name,
+                                              protocol);
+        mPriv->protocols.append(info);
+
+        Q_FOREACH (ParamSpec spec, f.parameters(protocol)) {
+            info->addParameter(spec);
+        }
+    }
+
+#if 0
+    Q_FOREACH (ProtocolInfo *info, mPriv->protocols) {
+        qDebug() << "protocol name   :" << info->name();
+        qDebug() << "protocol cn name:" << info->cmName();
+        Q_FOREACH (ProtocolParameter *param, info->parameters()) {
+            qDebug() << "\tparam name:       " << param->name();
+            qDebug() << "\tparam is required:" << param->isRequired();
+            qDebug() << "\tparam is secret:  " << param->isSecret();
+            qDebug() << "\tparam value:      " << param->defaultValue();
+        }
+    }
+#endif
+
+    return true;
+}
+
+void ConnectionManager::callReadConfig()
+{
+    if (!checkConfigFile()) {
+        warning() << "error parsing config file for connection manager"
+                  << mPriv->name;
+        mPriv->introspectQueue.enqueue(&ConnectionManager::callGetAll);
+        mPriv->introspectQueue.enqueue(&ConnectionManager::callListProtocols);
+    }
+
+    continueIntrospection();
+}
+
+void ConnectionManager::callGetAll()
+{
+    debug() << "Calling Properties::GetAll(ConnectionManager)";
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+            propertiesInterface()->GetAll(
+                TELEPATHY_INTERFACE_CONNECTION_MANAGER), this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onGetAllConnectionManagerReturn(QDBusPendingCallWatcher *)));
+}
+
+void ConnectionManager::callGetParameters()
+{
+    QString protocol = mPriv->getParametersQueue.dequeue();
+    mPriv->protocolQueue.enqueue(protocol);
+    debug() << "Calling ConnectionManager::GetParameters(" << protocol << ")";
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+            mPriv->baseInterface->GetParameters(protocol), this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onGetParametersReturn(QDBusPendingCallWatcher *)));
+}
+
+void ConnectionManager::callListProtocols()
+{
+    debug() << "Calling ConnectionManager::ListProtocols";
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+            mPriv->baseInterface->ListProtocols(), this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onListProtocolsReturn(QDBusPendingCallWatcher *)));
+}
+
+void ConnectionManager::onGetAllConnectionManagerReturn(
+        QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QVariantMap> reply = *watcher;
+    QVariantMap props;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to Properties.GetAll(ConnectionManager)";
+        props = reply.value();
+
+        // 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"]);
+        }
+    } else {
+        warning().nospace() <<
+            "Properties.GetAll(ConnectionManager) failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+    }
+
+    continueIntrospection();
+
+    watcher->deleteLater();
+}
+
+void ConnectionManager::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) {
+        mPriv->protocols.append(new ProtocolInfo(mPriv->name,
+                    protocolName));
+
+        mPriv->getParametersQueue.enqueue(protocolName);
+        mPriv->introspectQueue.enqueue(&ConnectionManager::callGetParameters);
+    }
+
+    continueIntrospection();
+
+    watcher->deleteLater();
+}
+
+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();
+
+    watcher->deleteLater();
+}
+
+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 {
+            (this->*(mPriv->introspectQueue.dequeue()))();
+        }
+    }
+}
+
 } // Telepathy::Client
 } // Telepathy
diff --git a/TelepathyQt4/Client/connection-manager.h b/TelepathyQt4/Client/connection-manager.h
index b4e33a4..d8d9225 100644
--- a/TelepathyQt4/Client/connection-manager.h
+++ b/TelepathyQt4/Client/connection-manager.h
@@ -145,11 +145,23 @@ public:
 protected:
     ConnectionManagerInterface *baseInterface() const;
 
+private Q_SLOTS:
+    void onGetParametersReturn(QDBusPendingCallWatcher *);
+    void onListProtocolsReturn(QDBusPendingCallWatcher *);
+    void onGetAllConnectionManagerReturn(QDBusPendingCallWatcher *);
+    void continueIntrospection();
+
 private:
     Q_DISABLE_COPY(ConnectionManager);
 
-    class Private;
-    friend class Private;
+    bool checkConfigFile();
+    void callReadConfig();
+    void callGetAll();
+    void callGetParameters();
+    void callListProtocols();
+
+    struct Private;
+    friend struct Private;
     Private *mPriv;
 };
 
-- 
1.5.6.5



More information about the Telepathy-commits mailing list