[Telepathy-commits] [telepathy-qt4/master] Contact: add a concept of requested and actual Features

Olli Salli olli.salli at collabora.co.uk
Sun Feb 1 12:57:17 PST 2009


---
 TelepathyQt4/Client/contact-manager.cpp  |   10 +++++-----
 TelepathyQt4/Client/contact-manager.h    |    2 +-
 TelepathyQt4/Client/contact.cpp          |   26 +++++++++++++++++++++++---
 TelepathyQt4/Client/contact.h            |   11 ++++++-----
 TelepathyQt4/Client/pending-contacts.cpp |    2 +-
 tests/dbus/contacts.cpp                  |   15 ++++++++-------
 6 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index ed971a6..08e6195 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -115,13 +115,13 @@ PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
     foreach (uint handle, handles) {
         QSharedPointer<Contact> contact = mPriv->contacts[handle].toStrongRef();
         if (contact) {
-            if (true /* TODO: contact->hasFeatures(features) */) {
+            if ((features - contact->requestedFeatures()).isEmpty()) {
                 // Contact exists and has all the requested features
                 satisfyingContacts.insert(handle, contact);
             } else {
                 // Contact exists but is missing features
                 otherContacts.insert(handle);
-                missingFeatures.unite(features /* TODO:- contact->features() */);
+                missingFeatures.unite(features - contact->requestedFeatures());
             }
         } else {
             // Contact doesn't exist - we need to get all of the features (same as unite(features))
@@ -196,15 +196,15 @@ ContactManager::~ContactManager()
 }
 
 QSharedPointer<Contact> ContactManager::ensureContact(const ReferencedHandles &handle,
-        const QVariantMap &attributes) {
+        const QSet<Contact::Feature> &features, const QVariantMap &attributes) {
     uint bareHandle = handle[0];
     QSharedPointer<Contact> contact = mPriv->contacts.value(bareHandle).toStrongRef();
 
     if (!contact) {
-        contact = QSharedPointer<Contact>(new Contact(this, handle, attributes));
+        contact = QSharedPointer<Contact>(new Contact(this, handle, features, attributes));
         mPriv->contacts.insert(bareHandle, contact);
     } else {
-        contact->augment(attributes);
+        contact->augment(features, attributes);
     }
 
     return contact;
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index 786a4e0..0f4bd0b 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -66,7 +66,7 @@ class ContactManager : public QObject
         ~ContactManager();
 
         QSharedPointer<Contact> ensureContact(const ReferencedHandles &handle,
-                const QVariantMap &attributes);
+                const QSet<Contact::Feature> &features, const QVariantMap &attributes);
 
         struct Private;
         friend struct Private;
diff --git a/TelepathyQt4/Client/contact.cpp b/TelepathyQt4/Client/contact.cpp
index 5776130..ce9253f 100644
--- a/TelepathyQt4/Client/contact.cpp
+++ b/TelepathyQt4/Client/contact.cpp
@@ -43,6 +43,9 @@ struct Contact::Private
     ContactManager *manager;
     ReferencedHandles handle;
     QString id;
+
+    QSet<Feature> requestedFeatures;
+    QSet<Feature> actualFeatures;
 };
 
 ContactManager *Contact::manager() const
@@ -60,20 +63,37 @@ QString Contact::id() const
     return mPriv->id;
 }
 
+QSet<Contact::Feature> Contact::requestedFeatures() const
+{
+    return mPriv->requestedFeatures;
+}
+
+QSet<Contact::Feature> Contact::actualFeatures() const
+{
+    return mPriv->actualFeatures;
+}
+
 Contact::~Contact()
 {
     delete mPriv;
 }
 
 Contact::Contact(ContactManager *manager, const ReferencedHandles &handle,
-        const QVariantMap &attributes)
+        const QSet<Feature> &requestedFeatures, const QVariantMap &attributes)
     : QObject(0), mPriv(new Private(manager, handle))
 {
-    augment(attributes);
+    augment(requestedFeatures, attributes);
 }
 
-void Contact::augment(const QVariantMap &attributes) {
+void Contact::augment(const QSet<Feature> &requestedFeatures, const QVariantMap &attributes) {
+    mPriv->requestedFeatures.unite(requestedFeatures);
+
     mPriv->id = qdbus_cast<QString>(attributes["org.freedesktop.Telepathy.Connection/contact-id"]);
+
+    foreach (Feature feature, requestedFeatures) {
+        Q_UNUSED(feature);
+        // ...
+    }
 }
 
 } // Telepathy::Client
diff --git a/TelepathyQt4/Client/contact.h b/TelepathyQt4/Client/contact.h
index b34dc1e..40851fd 100644
--- a/TelepathyQt4/Client/contact.h
+++ b/TelepathyQt4/Client/contact.h
@@ -27,6 +27,7 @@
 #endif
 
 #include <QObject>
+#include <QSet>
 #include <QVariantMap>
 
 namespace Telepathy
@@ -44,22 +45,24 @@ public:
     enum Feature {
         _Padding = 0xFFFFFFFF
     };
-    Q_DECLARE_FLAGS(Features, Feature);
 
     ContactManager *manager() const;
 
     ReferencedHandles handle() const;
     QString id() const;
 
+    QSet<Feature> requestedFeatures() const;
+    QSet<Feature> actualFeatures() const;
+
     ~Contact();
 
 private:
     Q_DISABLE_COPY(Contact);
 
     Contact(ContactManager *manager, const ReferencedHandles &handle,
-            const QVariantMap &attributes);
+            const QSet<Feature> &requestedFeatures, const QVariantMap &attributes);
 
-    void augment(const QVariantMap &attributes);
+    void augment(const QSet<Feature> &requestedFeatures, const QVariantMap &attributes);
 
     struct Private;
     friend class ContactManager;
@@ -67,8 +70,6 @@ private:
     Private *mPriv;
 };
 
-Q_DECLARE_OPERATORS_FOR_FLAGS(Contact::Features)
-
 } // Telepathy::Client
 } // Telepathy
 
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index 6d8960e..45b460e 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -168,7 +168,7 @@ void PendingContacts::onAttributesFinished(PendingOperation *operation)
                 ReferencedHandles referencedHandle = validHandles.mid(indexInValid, 1);
                 QVariantMap handleAttributes = attributes[handle];
                 mPriv->satisfyingContacts.insert(handle, manager()->ensureContact(referencedHandle,
-                            handleAttributes));
+                            features(), handleAttributes));
             } else {
                 mPriv->invalidHandles.push_back(handle);
             }
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index 7a50575..b4e5164 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -221,13 +221,12 @@ void TestContacts::testForHandles()
     QCOMPARE(mInvalidHandles[1], handles[4]);
 
     // Check the contact contents
-    QVERIFY(mContacts[0] != NULL);
-    QVERIFY(mContacts[1] != NULL);
-    QVERIFY(mContacts[2] != NULL);
-
-    QCOMPARE(mContacts[0]->manager(), mConn->contactManager());
-    QCOMPARE(mContacts[1]->manager(), mConn->contactManager());
-    QCOMPARE(mContacts[2]->manager(), mConn->contactManager());
+    for (int i = 0; i < 3; i++) {
+        QVERIFY(mContacts[i] != NULL);
+        QCOMPARE(mContacts[i]->manager(), mConn->contactManager());
+        QCOMPARE(mContacts[i]->requestedFeatures(), QSet<Contact::Feature>());
+        QCOMPARE(mContacts[i]->actualFeatures(), QSet<Contact::Feature>());
+    }
 
     QCOMPARE(mContacts[0]->handle()[0], handles[0]);
     QCOMPARE(mContacts[1]->handle()[0], handles[1]);
@@ -325,6 +324,8 @@ void TestContacts::testForIdentifiers()
         QVERIFY(mContacts[i] != NULL);
         QCOMPARE(mContacts[i]->manager(), mConn->contactManager());
         QVERIFY(tp_handle_is_valid(serviceRepo, mContacts[i]->handle()[0], NULL));
+        QCOMPARE(mContacts[i]->requestedFeatures(), QSet<Contact::Feature>());
+        QCOMPARE(mContacts[i]->actualFeatures(), QSet<Contact::Feature>());
     }
 
     QCOMPARE(mContacts[0]->id(), QString("alice"));
-- 
1.5.6.5




More information about the Telepathy-commits mailing list