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

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


---
 TelepathyQt4/Client/account-manager-internal.h |   22 +--
 TelepathyQt4/Client/account-manager.cpp        |  252 +++++++++++-------------
 TelepathyQt4/Client/account-manager.h          |   12 +-
 TelepathyQt4/Makefile.am                       |    1 -
 4 files changed, 133 insertions(+), 154 deletions(-)

diff --git a/TelepathyQt4/Client/account-manager-internal.h b/TelepathyQt4/Client/account-manager-internal.h
index 8752fc9..a216c48 100644
--- a/TelepathyQt4/Client/account-manager-internal.h
+++ b/TelepathyQt4/Client/account-manager-internal.h
@@ -36,15 +36,12 @@ namespace Client
 class AccountManager;
 class AccountManagerInterface;
 
-class AccountManager::Private : public QObject
+struct AccountManager::Private
 {
-    Q_OBJECT
-
 public:
     Private(AccountManager *parent);
     ~Private();
 
-    void callGetAll();
     void setAccountPaths(QSet<QString> &set, const QVariant &variant);
 
     class PendingReady;
@@ -52,28 +49,17 @@ public:
     AccountManagerInterface *baseInterface;
     bool ready;
     PendingReady *pendingReady;
-    QQueue<void (Private::*)()> introspectQueue;
+    QQueue<void (AccountManager::*)()> introspectQueue;
     QStringList interfaces;
     AccountManager::Features features;
     QSet<QString> validAccountPaths;
     QSet<QString> invalidAccountPaths;
-
-Q_SIGNALS:
-    void accountCreated(const QString &path);
-    void accountRemoved(const QString &path);
-    void accountValidityChanged(const QString &path, bool valid);
-
-private Q_SLOTS:
-    void onGetAllAccountManagerReturn(QDBusPendingCallWatcher *);
-    void onAccountValidityChanged(const QDBusObjectPath &, bool);
-    void onAccountRemoved(const QDBusObjectPath &);
-    void continueIntrospection();
 };
 
 class AccountManager::Private::PendingReady : public PendingOperation
 {
-    // AccountManager::Private is a friend so it can call finished() etc.
-    friend class AccountManager::Private;
+    // AccountManager is a friend so it can call finished() etc.
+    friend class AccountManager;
 
 public:
     PendingReady(AccountManager *parent);
diff --git a/TelepathyQt4/Client/account-manager.cpp b/TelepathyQt4/Client/account-manager.cpp
index c109353..6d423b2 100644
--- a/TelepathyQt4/Client/account-manager.cpp
+++ b/TelepathyQt4/Client/account-manager.cpp
@@ -23,7 +23,6 @@
 #include "TelepathyQt4/Client/account-manager-internal.h"
 
 #include "TelepathyQt4/Client/_gen/account-manager.moc.hpp"
-#include "TelepathyQt4/Client/_gen/account-manager-internal.moc.hpp"
 #include "TelepathyQt4/_gen/cli-account-manager.moc.hpp"
 #include "TelepathyQt4/_gen/cli-account-manager-body.hpp"
 
@@ -68,24 +67,13 @@ AccountManager::Private::PendingReady::PendingReady(AccountManager *parent)
 }
 
 AccountManager::Private::Private(AccountManager *parent)
-    : QObject(parent),
-      baseInterface(new AccountManagerInterface(parent->dbusConnection(),
+    : baseInterface(new AccountManagerInterface(parent->dbusConnection(),
                             parent->busName(), parent->objectPath(), parent)),
       ready(false),
       pendingReady(0),
       features(0)
 {
     debug() << "Creating new AccountManager:" << parent->busName();
-
-    connect(baseInterface,
-            SIGNAL(AccountValidityChanged(const QDBusObjectPath &, bool)),
-            SLOT(onAccountValidityChanged(const QDBusObjectPath &, bool)));
-    connect(baseInterface,
-            SIGNAL(AccountRemoved(const QDBusObjectPath &)),
-            SLOT(onAccountRemoved(const QDBusObjectPath &)));
-
-    introspectQueue.enqueue(&Private::callGetAll);
-    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
 }
 
 AccountManager::Private::~Private()
@@ -93,18 +81,6 @@ AccountManager::Private::~Private()
     delete baseInterface;
 }
 
-void AccountManager::Private::callGetAll()
-{
-    debug() << "Calling Properties::GetAll(AccountManager)";
-    AccountManager *am = static_cast<AccountManager *>(parent());
-    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
-            am->propertiesInterface()->GetAll(
-                TELEPATHY_INTERFACE_ACCOUNT_MANAGER), this);
-    connect(watcher,
-            SIGNAL(finished(QDBusPendingCallWatcher *)),
-            SLOT(onGetAllAccountManagerReturn(QDBusPendingCallWatcher *)));
-}
-
 void AccountManager::Private::setAccountPaths(QSet<QString> &set,
         const QVariant &variant)
 {
@@ -131,105 +107,6 @@ void AccountManager::Private::setAccountPaths(QSet<QString> &set,
     }
 }
 
-void AccountManager::Private::onGetAllAccountManagerReturn(
-        QDBusPendingCallWatcher *watcher)
-{
-    QDBusPendingReply<QVariantMap> reply = *watcher;
-    QVariantMap props;
-
-    if (!reply.isError()) {
-        debug() << "Got reply to Properties.GetAll(AccountManager)";
-        props = reply.value();
-    } else {
-        warning().nospace() <<
-            "GetAll(AccountManager) failed: " <<
-            reply.error().name() << ": " << reply.error().message();
-    }
-
-    if (props.contains("Interfaces")) {
-        interfaces = qdbus_cast<QStringList>(props["Interfaces"]);
-    }
-
-    if (props.contains("ValidAccounts")) {
-        setAccountPaths(validAccountPaths,
-                props["ValidAccounts"]);
-    }
-
-    if (props.contains("InvalidAccounts")) {
-        setAccountPaths(invalidAccountPaths,
-                props["InvalidAccounts"]);
-    }
-
-    continueIntrospection();
-
-    watcher->deleteLater();
-}
-
-void AccountManager::Private::onAccountValidityChanged(const QDBusObjectPath &objectPath,
-        bool nowValid)
-{
-    QString path = objectPath.path();
-    bool newAccount = false;
-
-    if (!validAccountPaths.contains(path) &&
-        !invalidAccountPaths.contains(path)) {
-        newAccount = true;
-    }
-
-    if (nowValid) {
-        debug() << "Account created or became valid:" << path;
-        invalidAccountPaths.remove(path);
-        validAccountPaths.insert(path);
-    }
-    else {
-        debug() << "Account became invalid:" << path;
-        validAccountPaths.remove(path);
-        invalidAccountPaths.insert(path);
-    }
-
-    if (newAccount) {
-        Q_EMIT accountCreated(path);
-        // if the newly created account is invalid (shouldn't be the case)
-        // emit also accountValidityChanged indicating this
-        if (!nowValid) {
-            Q_EMIT accountValidityChanged(path, nowValid);
-        }
-    }
-    else {
-        Q_EMIT accountValidityChanged(path, nowValid);
-    }
-}
-
-void AccountManager::Private::onAccountRemoved(const QDBusObjectPath &objectPath)
-{
-    QString path = objectPath.path();
-
-    debug() << "Account removed:" << path;
-    validAccountPaths.remove(path);
-    invalidAccountPaths.remove(path);
-
-    Q_EMIT accountRemoved(path);
-}
-
-void AccountManager::Private::continueIntrospection()
-{
-    if (!ready) {
-        if (introspectQueue.isEmpty()) {
-            debug() << "AccountManager is ready";
-            ready = true;
-
-            if (pendingReady) {
-                pendingReady->setFinished();
-                // it will delete itself later
-                pendingReady = 0;
-            }
-        }
-        else {
-            (this->*(introspectQueue.dequeue()))();
-        }
-    }
-}
-
 /**
  * \class AccountManager
  * \ingroup clientaccount
@@ -494,15 +371,124 @@ AccountManagerInterface *AccountManager::baseInterface() const
 
 void AccountManager::init()
 {
-    connect(mPriv,
-            SIGNAL(accountCreated(const QString &)),
-            SIGNAL(accountCreated(const QString &)));
-    connect(mPriv,
-            SIGNAL(accountRemoved(const QString &)),
-            SIGNAL(accountRemoved(const QString &)));
-    connect(mPriv,
-            SIGNAL(accountValidityChanged(const QString &, bool)),
-            SIGNAL(accountValidityChanged(const QString &, bool)));
+    connect(mPriv->baseInterface,
+            SIGNAL(AccountValidityChanged(const QDBusObjectPath &, bool)),
+            SLOT(onAccountValidityChanged(const QDBusObjectPath &, bool)));
+    connect(mPriv->baseInterface,
+            SIGNAL(AccountRemoved(const QDBusObjectPath &)),
+            SLOT(onAccountRemoved(const QDBusObjectPath &)));
+
+    mPriv->introspectQueue.enqueue(&AccountManager::callGetAll);
+    QTimer::singleShot(0, this, SLOT(continueIntrospection()));
+}
+
+/**** Private ****/
+void AccountManager::callGetAll()
+{
+    debug() << "Calling Properties::GetAll(AccountManager)";
+    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+            propertiesInterface()->GetAll(
+                TELEPATHY_INTERFACE_ACCOUNT_MANAGER), this);
+    connect(watcher,
+            SIGNAL(finished(QDBusPendingCallWatcher *)),
+            SLOT(onGetAllAccountManagerReturn(QDBusPendingCallWatcher *)));
+}
+
+void AccountManager::onGetAllAccountManagerReturn(
+        QDBusPendingCallWatcher *watcher)
+{
+    QDBusPendingReply<QVariantMap> reply = *watcher;
+    QVariantMap props;
+
+    if (!reply.isError()) {
+        debug() << "Got reply to Properties.GetAll(AccountManager)";
+        props = reply.value();
+
+        if (props.contains("Interfaces")) {
+            mPriv->interfaces = qdbus_cast<QStringList>(props["Interfaces"]);
+        }
+        if (props.contains("ValidAccounts")) {
+            mPriv->setAccountPaths(mPriv->validAccountPaths,
+                    props["ValidAccounts"]);
+        }
+        if (props.contains("InvalidAccounts")) {
+            mPriv->setAccountPaths(mPriv->invalidAccountPaths,
+                    props["InvalidAccounts"]);
+        }
+    } else {
+        warning().nospace() <<
+            "GetAll(AccountManager) failed: " <<
+            reply.error().name() << ": " << reply.error().message();
+    }
+
+    continueIntrospection();
+
+    watcher->deleteLater();
+}
+
+void AccountManager::onAccountValidityChanged(const QDBusObjectPath &objectPath,
+        bool nowValid)
+{
+    QString path = objectPath.path();
+    bool newAccount = false;
+
+    if (!mPriv->validAccountPaths.contains(path) &&
+        !mPriv->invalidAccountPaths.contains(path)) {
+        newAccount = true;
+    }
+
+    if (nowValid) {
+        debug() << "Account created or became valid:" << path;
+        mPriv->invalidAccountPaths.remove(path);
+        mPriv->validAccountPaths.insert(path);
+    }
+    else {
+        debug() << "Account became invalid:" << path;
+        mPriv->validAccountPaths.remove(path);
+        mPriv->invalidAccountPaths.insert(path);
+    }
+
+    if (newAccount) {
+        Q_EMIT accountCreated(path);
+        // if the newly created account is invalid (shouldn't be the case)
+        // emit also accountValidityChanged indicating this
+        if (!nowValid) {
+            Q_EMIT accountValidityChanged(path, nowValid);
+        }
+    }
+    else {
+        Q_EMIT accountValidityChanged(path, nowValid);
+    }
+}
+
+void AccountManager::onAccountRemoved(const QDBusObjectPath &objectPath)
+{
+    QString path = objectPath.path();
+
+    debug() << "Account removed:" << path;
+    mPriv->validAccountPaths.remove(path);
+    mPriv->invalidAccountPaths.remove(path);
+
+    Q_EMIT accountRemoved(path);
+}
+
+void AccountManager::continueIntrospection()
+{
+    if (!mPriv->ready) {
+        if (mPriv->introspectQueue.isEmpty()) {
+            debug() << "AccountManager 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
diff --git a/TelepathyQt4/Client/account-manager.h b/TelepathyQt4/Client/account-manager.h
index fae2df9..e0e6ad0 100644
--- a/TelepathyQt4/Client/account-manager.h
+++ b/TelepathyQt4/Client/account-manager.h
@@ -32,6 +32,7 @@
 #include <TelepathyQt4/Client/DBusProxy>
 #include <TelepathyQt4/Client/OptionalInterfaceFactory>
 
+#include <QDBusObjectPath>
 #include <QString>
 #include <QVariantMap>
 
@@ -98,11 +99,18 @@ Q_SIGNALS:
 protected:
     AccountManagerInterface *baseInterface() const;
 
+private Q_SLOTS:
+    void onGetAllAccountManagerReturn(QDBusPendingCallWatcher *);
+    void onAccountValidityChanged(const QDBusObjectPath &, bool);
+    void onAccountRemoved(const QDBusObjectPath &);
+    void continueIntrospection();
+
 private:
     void init();
+    void callGetAll();
 
-    class Private;
-    friend class Private;
+    struct Private;
+    friend struct Private;
     friend class PendingAccount;
     Private *mPriv;
 };
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 293ef14..fbceb94 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -82,7 +82,6 @@ nodist_libtelepathy_qt4_la_SOURCES = \
     _gen/types-body.hpp \
     Client/_gen/account.moc.hpp \
     Client/_gen/account-manager.moc.hpp \
-    Client/_gen/account-manager-internal.moc.hpp \
     Client/_gen/channel.moc.hpp \
     Client/_gen/connection.moc.hpp \
     Client/_gen/connection-manager.moc.hpp \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list