[Telepathy-commits] [telepathy-qt4/master] Make Connection::getContactAttributes fail for non-ready and/or non-connected Connections

Olli Salli olli.salli at collabora.co.uk
Thu Jan 29 09:18:40 PST 2009


---
 TelepathyQt4/Client/connection.cpp                 |   24 +++++++++++++++-----
 TelepathyQt4/Client/pending-contact-attributes.cpp |    5 +--
 TelepathyQt4/Client/pending-contact-attributes.h   |    2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 666279b..fa41f63 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -1426,6 +1426,10 @@ PendingOperation *Connection::requestDisconnect()
  * PendingContactAttributes instance will fail instantly with the error
  * TELEPATHY_ERROR_NOT_IMPLEMENTED.
  *
+ * Similarly, if the connection isn't both connected and ready (<code>status() == StatusConnected &&
+ * isReady()</code>), the returned PendingContactAttributes instance will fail instantly with the
+ * error TELEPATHY_ERROR_NOT_AVAILABLE.
+ *
  * \sa PendingContactAttributes
  *
  * \param contacts Passed to ConnectionInterfaceContactsInterface::GetContactAttributes().
@@ -1439,12 +1443,22 @@ PendingContactAttributes *Connection::getContactAttributes(const UIntList &handl
 {
     debug() << "Request for attributes for" << handles.size() << "contacts";
 
-    if (!this->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
+    PendingContactAttributes *pending =
+        new PendingContactAttributes(this, handles, interfaces, reference);
+    if (!isReady()) {
+        warning() << "Connection::getContactAttributes() used when not ready";
+        pending->failImmediately(TELEPATHY_ERROR_NOT_AVAILABLE, "The connection isn't ready");
+        return pending;
+    } else if (status() != StatusConnected) {
+        warning() << "Connection::getContactAttributes() used with status" << status() << "!= StatusConnected";
+        pending->failImmediately(TELEPATHY_ERROR_NOT_AVAILABLE,
+                "The connection isn't Connected");
+        return pending;
+    } else if (!this->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
         warning() << "Connection::getContactAttributes() used without the remote object supporting"
                   << "the Contacts interface";
-        PendingContactAttributes *pending =
-            new PendingContactAttributes(this, handles, interfaces, reference);
-        pending->setUnsupported();
+        pending->failImmediately(TELEPATHY_ERROR_NOT_IMPLEMENTED,
+                "The connection doesn't support the Contacts interface");
         return pending;
     }
 
@@ -1454,8 +1468,6 @@ PendingContactAttributes *Connection::getContactAttributes(const UIntList &handl
         handleContext->types[HandleTypeContact].requestsInFlight++;
     }
 
-    PendingContactAttributes *pending =
-        new PendingContactAttributes(this, handles, interfaces, reference);
     ConnectionInterfaceContactsInterface *contactsInterface =
         optionalInterface<ConnectionInterfaceContactsInterface>();
     QDBusPendingCallWatcher *watcher =
diff --git a/TelepathyQt4/Client/pending-contact-attributes.cpp b/TelepathyQt4/Client/pending-contact-attributes.cpp
index 9ce74db..fe8db81 100644
--- a/TelepathyQt4/Client/pending-contact-attributes.cpp
+++ b/TelepathyQt4/Client/pending-contact-attributes.cpp
@@ -232,10 +232,9 @@ void PendingContactAttributes::onCallFinished(QDBusPendingCallWatcher* watcher)
     watcher->deleteLater();
 }
 
-void PendingContactAttributes::setUnsupported()
+void PendingContactAttributes::failImmediately(const QString &error, const QString &errorMessage)
 {
-    setFinishedWithError(TELEPATHY_ERROR_NOT_IMPLEMENTED,
-            "The remote object doesn't report the Contacts interface as supported");
+    setFinishedWithError(error, errorMessage);
 }
 
 } // Telepathy::Client
diff --git a/TelepathyQt4/Client/pending-contact-attributes.h b/TelepathyQt4/Client/pending-contact-attributes.h
index 3061d1e..2869d05 100644
--- a/TelepathyQt4/Client/pending-contact-attributes.h
+++ b/TelepathyQt4/Client/pending-contact-attributes.h
@@ -66,7 +66,7 @@ private:
 
     PendingContactAttributes(Connection *connection, const UIntList &handles,
             const QStringList &interfaces, bool reference);
-    void setUnsupported();
+    void failImmediately(const QString &error, const QString &errorMessage);
 
     struct Private;
     friend struct Private;
-- 
1.5.6.5




More information about the telepathy-commits mailing list