[Telepathy-commits] [telepathy-qt4/master] ReadinessHelper/ReadyObject: Support non DBusProxy objects.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Thu Mar 19 16:26:36 PDT 2009


Added support for non DBusProxy objects to use ReadyObject/ReadinessHelper.
This is useful in classes that do not inherit DBusProxy but want to use
ReadinessHelper machinery.
---
 TelepathyQt4/Client/readiness-helper.cpp |   33 ++++++++++++++++++-----------
 TelepathyQt4/Client/readiness-helper.h   |    3 +-
 TelepathyQt4/Client/ready-object.cpp     |   27 ++++++++++++++++++------
 TelepathyQt4/Client/ready-object.h       |    7 +++++-
 4 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/TelepathyQt4/Client/readiness-helper.cpp b/TelepathyQt4/Client/readiness-helper.cpp
index 4115e85..87c747c 100644
--- a/TelepathyQt4/Client/readiness-helper.cpp
+++ b/TelepathyQt4/Client/readiness-helper.cpp
@@ -39,6 +39,7 @@ namespace Client
 struct ReadinessHelper::Private
 {
     Private(ReadinessHelper *parent,
+            QObject *object,
             DBusProxy *proxy,
             uint currentStatus,
             const Introspectables &introspectables);
@@ -53,6 +54,7 @@ struct ReadinessHelper::Private
     void abortOperations(const QString &errorName, const QString &errorMessage);
 
     ReadinessHelper *parent;
+    QObject *object;
     DBusProxy *proxy;
     uint currentStatus;
     QStringList interfaces;
@@ -73,10 +75,12 @@ struct ReadinessHelper::Private
 
 ReadinessHelper::Private::Private(
         ReadinessHelper *parent,
+        QObject *object,
         DBusProxy *proxy,
         uint currentStatus,
         const Introspectables &introspectables)
     : parent(parent),
+      object(object),
       proxy(proxy),
       currentStatus(currentStatus),
       introspectables(introspectables),
@@ -169,7 +173,7 @@ void ReadinessHelper::Private::setIntrospectCompleted(const Feature &feature,
 
 void ReadinessHelper::Private::iterateIntrospection()
 {
-    if (!proxy->isValid()) {
+    if (proxy && !proxy->isValid()) {
         return;
     }
 
@@ -279,16 +283,19 @@ void ReadinessHelper::Private::abortOperations(const QString &errorName,
     }
 }
 
-ReadinessHelper::ReadinessHelper(DBusProxy *proxy,
+ReadinessHelper::ReadinessHelper(QObject *object,
+        DBusProxy *proxy,
         uint currentStatus,
         const Introspectables &introspectables,
         QObject *parent)
     : QObject(parent),
-      mPriv(new Private(this, proxy, currentStatus, introspectables))
+      mPriv(new Private(this, object, proxy, currentStatus, introspectables))
 {
-    connect(proxy,
-            SIGNAL(invalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)),
-            SLOT(onProxyInvalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)));
+    if (proxy) {
+        connect(proxy,
+                SIGNAL(invalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)),
+                SLOT(onProxyInvalidated(Telepathy::Client::DBusProxy *, const QString &, const QString &)));
+    }
 }
 
 ReadinessHelper::~ReadinessHelper()
@@ -360,7 +367,7 @@ Features ReadinessHelper::missingFeatures() const
 bool ReadinessHelper::isReady(const Feature &feature,
         QString *errorName, QString *errorMessage) const
 {
-    if (!mPriv->proxy->isValid()) {
+    if (mPriv->proxy && !mPriv->proxy->isValid()) {
         if (errorName) {
             *errorName = mPriv->proxy->invalidationReason();
         }
@@ -410,7 +417,7 @@ bool ReadinessHelper::isReady(const Feature &feature,
 
 bool ReadinessHelper::isReady(const Features &features, QString *errorName, QString *errorMessage) const
 {
-    if (!mPriv->proxy->isValid()) {
+    if (mPriv->proxy && !mPriv->proxy->isValid()) {
         if (errorName) {
             *errorName = mPriv->proxy->invalidationReason();
         }
@@ -439,16 +446,16 @@ PendingReady *ReadinessHelper::becomeReady(const Features &requestedFeatures)
         debug() << "ReadinessHelper::becomeReady called with invalid features: requestedFeatures =" <<
             requestedFeatures << "- supportedFeatures =" << mPriv->supportedFeatures;
         PendingReady *operation =
-            new PendingReady(requestedFeatures, mPriv->proxy);
+            new PendingReady(requestedFeatures, mPriv->object);
         operation->setFinishedWithError(
                 QLatin1String(TELEPATHY_ERROR_INVALID_ARGUMENT),
                 QLatin1String("Requested features contains unsupported feature"));
         return operation;
     }
 
-    if (!mPriv->proxy->isValid()) {
+    if (mPriv->proxy && !mPriv->proxy->isValid()) {
         PendingReady *operation =
-            new PendingReady(requestedFeatures, mPriv->proxy);
+            new PendingReady(requestedFeatures, mPriv->object);
         operation->setFinishedWithError(mPriv->proxy->invalidationReason(),
                 mPriv->proxy->invalidationMessage());
         return operation;
@@ -465,7 +472,7 @@ PendingReady *ReadinessHelper::becomeReady(const Features &requestedFeatures)
     // it will be updated on iterateIntrospection
     mPriv->pendingFeatures += requestedFeatures;
 
-    operation = new PendingReady(requestedFeatures, mPriv->proxy);
+    operation = new PendingReady(requestedFeatures, mPriv->object);
     mPriv->pendingOperations.append(operation);
 
     QTimer::singleShot(0, this, SLOT(iterateIntrospection()));
@@ -476,7 +483,7 @@ PendingReady *ReadinessHelper::becomeReady(const Features &requestedFeatures)
 void ReadinessHelper::setIntrospectCompleted(const Feature &feature, bool success,
         const QString &errorName, const QString &errorMessage)
 {
-    if (!mPriv->proxy->isValid()) {
+    if (mPriv->proxy && !mPriv->proxy->isValid()) {
         // proxy became invalid, ignore here
         return;
     }
diff --git a/TelepathyQt4/Client/readiness-helper.h b/TelepathyQt4/Client/readiness-helper.h
index 1ee9861..e9dae1a 100644
--- a/TelepathyQt4/Client/readiness-helper.h
+++ b/TelepathyQt4/Client/readiness-helper.h
@@ -84,7 +84,8 @@ public:
     };
     typedef QMap<Feature, Introspectable> Introspectables;
 
-    ReadinessHelper(DBusProxy *proxy,
+    ReadinessHelper(QObject *object,
+            DBusProxy *proxy,
             uint currentStatus = 0,
             const Introspectables &introspectables = Introspectables(),
             QObject *parent = 0);
diff --git a/TelepathyQt4/Client/ready-object.cpp b/TelepathyQt4/Client/ready-object.cpp
index 5e3af3c..d30b20f 100644
--- a/TelepathyQt4/Client/ready-object.cpp
+++ b/TelepathyQt4/Client/ready-object.cpp
@@ -33,22 +33,20 @@ namespace Client
 
 struct ReadyObject::Private
 {
-    Private(ReadyObject *parent, DBusProxy *proxy,
+    Private(ReadyObject *parent, QObject *object, DBusProxy *proxy,
             Feature featureCore);
     ~Private();
 
     ReadyObject *parent;
-    DBusProxy *proxy;
     Feature featureCore;
     ReadinessHelper *readinessHelper;
 };
 
-ReadyObject::Private::Private(ReadyObject *parent, DBusProxy *proxy,
-        Feature featureCore)
+ReadyObject::Private::Private(ReadyObject *parent, QObject *object,
+        DBusProxy *proxy, Feature featureCore)
     : parent(parent),
-      proxy(proxy),
       featureCore(featureCore),
-      readinessHelper(new ReadinessHelper(proxy))
+      readinessHelper(new ReadinessHelper(object, proxy))
 {
 }
 
@@ -66,11 +64,26 @@ ReadyObject::Private::~Private()
 /**
  * Construct a new ReadyObject object.
  *
+ * \param object The QObject the object refers to.
+ * \param proxy The DBusProxy the object refers to.
+ * \param featureCore The core feature of the object.
+ */
+ReadyObject::ReadyObject(QObject *object, DBusProxy *proxy,
+        const Feature &featureCore)
+    : mPriv(new Private(this, object, proxy, featureCore))
+{
+}
+
+/**
+ * Construct a new ReadyObject object.
+ *
+ * The object will be same as proxy.
+ *
  * \param proxy The DBusProxy the object refers to.
  * \param featureCore The core feature of the object.
  */
 ReadyObject::ReadyObject(DBusProxy *proxy, const Feature &featureCore)
-    : mPriv(new Private(this, proxy, featureCore))
+    : mPriv(new Private(this, proxy, proxy, featureCore))
 {
 }
 
diff --git a/TelepathyQt4/Client/ready-object.h b/TelepathyQt4/Client/ready-object.h
index c8e8349..b9629b0 100644
--- a/TelepathyQt4/Client/ready-object.h
+++ b/TelepathyQt4/Client/ready-object.h
@@ -28,6 +28,8 @@
 
 #include <TelepathyQt4/Client/Feature>
 
+#include <QObject>
+
 namespace Telepathy
 {
 namespace Client
@@ -42,7 +44,10 @@ class ReadyObject
     Q_DISABLE_COPY(ReadyObject)
 
 public:
-    ReadyObject(DBusProxy *proxy, const Feature &featureCore);
+    ReadyObject(QObject *object, DBusProxy *proxy,
+            const Feature &featureCore);
+    ReadyObject(DBusProxy *proxy,
+            const Feature &featureCore);
     ~ReadyObject();
 
     virtual bool isReady(const Features &features = Features()) const;
-- 
1.5.6.5




More information about the telepathy-commits mailing list