[Telepathy-commits] [telepathy-qt4/master] Make contact sharing work even with a) simultaneous requests b) features

Olli Salli olli.salli at collabora.co.uk
Sun Feb 1 10:24:20 PST 2009


---
 TelepathyQt4/Client/contact-manager.cpp  |   33 +++++++++++++++--------------
 TelepathyQt4/Client/contact-manager.h    |    7 +++--
 TelepathyQt4/Client/contact.cpp          |    4 ++-
 TelepathyQt4/Client/contact.h            |    4 ++-
 TelepathyQt4/Client/pending-contacts.cpp |   19 ++++++++++-------
 5 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 14bff60..ed971a6 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -142,10 +142,8 @@ PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
         interfaces.insert(featureToInterface(feature));
     }
 
-    PendingContacts *contacts = new PendingContacts(this, handles, features, satisfyingContacts);
-    connect(contacts,
-            SIGNAL(finished(Telepathy::Client::PendingOperation *)),
-            SLOT(onPendingContactsFinished(Telepathy::Client::PendingOperation *)));
+    PendingContacts *contacts =
+        new PendingContacts(this, handles, features, satisfyingContacts);
 
     if (!otherContacts.isEmpty()) {
         debug() << " Fetching" << interfaces.size() << "interfaces for"
@@ -186,18 +184,6 @@ PendingContacts *ContactManager::contactsForIdentifiers(const QStringList &ident
     return contacts;
 }
 
-void ContactManager::onPendingContactsFinished(Telepathy::Client::PendingOperation *operation)
-{
-    PendingContacts *contacts = qobject_cast<PendingContacts *>(operation);
-
-    if (contacts->isValid()) {
-        debug() << this << "Caching" << contacts->contacts().size() << "contacts";
-        foreach (QSharedPointer<Contact> contact, contacts->contacts()) {
-            mPriv->contacts.insert(contact->handle()[0], contact);
-        }
-    }
-}
-
 ContactManager::ContactManager(Connection *parent)
     : QObject(parent), mPriv(new Private)
 {
@@ -209,5 +195,20 @@ ContactManager::~ContactManager()
     delete mPriv;
 }
 
+QSharedPointer<Contact> ContactManager::ensureContact(const ReferencedHandles &handle,
+        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));
+        mPriv->contacts.insert(bareHandle, contact);
+    } else {
+        contact->augment(attributes);
+    }
+
+    return contact;
+}
+
 }
 }
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index dd1727d..786a4e0 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -61,16 +61,17 @@ class ContactManager : public QObject
         PendingContacts *contactsForIdentifiers(const QStringList &identifiers,
                 const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
 
-    private Q_SLOTS:
-        void onPendingContactsFinished(Telepathy::Client::PendingOperation *);
-
     private:
         ContactManager(Connection *parent);
         ~ContactManager();
 
+        QSharedPointer<Contact> ensureContact(const ReferencedHandles &handle,
+                const QVariantMap &attributes);
+
         struct Private;
         friend struct Private;
         friend class Connection;
+        friend class PendingContacts;
         Private *mPriv;
 };
 
diff --git a/TelepathyQt4/Client/contact.cpp b/TelepathyQt4/Client/contact.cpp
index f513f56..5776130 100644
--- a/TelepathyQt4/Client/contact.cpp
+++ b/TelepathyQt4/Client/contact.cpp
@@ -69,8 +69,10 @@ Contact::Contact(ContactManager *manager, const ReferencedHandles &handle,
         const QVariantMap &attributes)
     : QObject(0), mPriv(new Private(manager, handle))
 {
-    debug() << this << "initialized with" << attributes.size() << "attributes";
+    augment(attributes);
+}
 
+void Contact::augment(const QVariantMap &attributes) {
     mPriv->id = qdbus_cast<QString>(attributes["org.freedesktop.Telepathy.Connection/contact-id"]);
 }
 
diff --git a/TelepathyQt4/Client/contact.h b/TelepathyQt4/Client/contact.h
index 42f4bf7..b34dc1e 100644
--- a/TelepathyQt4/Client/contact.h
+++ b/TelepathyQt4/Client/contact.h
@@ -59,8 +59,10 @@ private:
     Contact(ContactManager *manager, const ReferencedHandles &handle,
             const QVariantMap &attributes);
 
+    void augment(const QVariantMap &attributes);
+
     struct Private;
-    friend class PendingContacts;
+    friend class ContactManager;
     friend struct Private;
     Private *mPriv;
 };
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index e927769..6d8960e 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -159,16 +159,19 @@ void PendingContacts::onAttributesFinished(PendingOperation *operation)
     ContactAttributesMap attributes = pendingAttributes->attributes();
 
     debug() << " Success:" << validHandles.size() << "valid and"
-                           << mPriv->invalidHandles.size() << "invalid handles";
+                           << pendingAttributes->invalidHandles().size() << "invalid handles";
 
     foreach (uint handle, mPriv->handles) {
-        int indexInValid = validHandles.indexOf(handle);
-        if (indexInValid >= 0) {
-            ReferencedHandles referenced = validHandles.mid(indexInValid, 1);
-            mPriv->satisfyingContacts.insert(handle, QSharedPointer<Contact>(new Contact(
-                            mPriv->manager, referenced, attributes[handle])));
-        } else if (!mPriv->satisfyingContacts.contains(handle)) {
-            mPriv->invalidHandles.push_back(handle);
+        if (!mPriv->satisfyingContacts.contains(handle)) {
+            int indexInValid = validHandles.indexOf(handle);
+            if (indexInValid >= 0) {
+                ReferencedHandles referencedHandle = validHandles.mid(indexInValid, 1);
+                QVariantMap handleAttributes = attributes[handle];
+                mPriv->satisfyingContacts.insert(handle, manager()->ensureContact(referencedHandle,
+                            handleAttributes));
+            } else {
+                mPriv->invalidHandles.push_back(handle);
+            }
         }
     }
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list