[Telepathy-commits] [telepathy-qt4/master] Add ContactManager::upgradeContacts()

Olli Salli olli.salli at collabora.co.uk
Mon Feb 2 02:16:51 PST 2009


---
 TelepathyQt4/Client/contact-manager.cpp  |    9 ++++
 TelepathyQt4/Client/contact-manager.h    |    4 ++
 TelepathyQt4/Client/pending-contacts.cpp |   64 ++++++++++++++++++++++++++---
 TelepathyQt4/Client/pending-contacts.h   |    5 ++
 tests/dbus/contacts.cpp                  |    2 +
 5 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 08e6195..051a2c5 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -184,6 +184,15 @@ PendingContacts *ContactManager::contactsForIdentifiers(const QStringList &ident
     return contacts;
 }
 
+PendingContacts *ContactManager::upgradeContacts(const QList<QSharedPointer<Contact> > &contacts,
+        const QSet<Contact::Feature> &features)
+{
+    debug() << "Upgrading" << contacts.size() << "contacts to have at least"
+                           << features.size() << "features";
+
+    return new PendingContacts(this, contacts, features);
+}
+
 ContactManager::ContactManager(Connection *parent)
     : QObject(parent), mPriv(new Private)
 {
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index 0f4bd0b..9c12198 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -28,6 +28,7 @@
 
 #include <QObject>
 
+#include <QList>
 #include <QSet>
 #include <QSharedPointer>
 
@@ -61,6 +62,9 @@ class ContactManager : public QObject
         PendingContacts *contactsForIdentifiers(const QStringList &identifiers,
                 const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
 
+        PendingContacts *upgradeContacts(const QList<QSharedPointer<Contact> > &contacts,
+                const QSet<Contact::Feature> &features);
+
     private:
         ContactManager(Connection *parent);
         ~ContactManager();
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index 45b460e..009b2b5 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -36,13 +36,20 @@ namespace Client
 
 struct PendingContacts::Private
 {
+    enum RequestType
+    {
+        ForHandles,
+        ForIdentifiers,
+        Upgrade
+    };
+
     Private(ContactManager *manager, const UIntList &handles,
             const QSet<Contact::Feature> &features,
             const QMap<uint, QSharedPointer<Contact> > &satisfyingContacts)
         : manager(manager),
           features(features),
           satisfyingContacts(satisfyingContacts),
-          isForIdentifiers(false),
+          requestType(ForHandles),
           handles(handles),
           nested(0)
     {
@@ -52,21 +59,35 @@ struct PendingContacts::Private
             const QSet<Contact::Feature> &features)
         : manager(manager),
           features(features),
-          isForIdentifiers(true),
+          requestType(ForIdentifiers),
           identifiers(identifiers),
           nested(0)
     {
     }
 
+    Private(ContactManager *manager, const QList<QSharedPointer<Contact> > &contactsToUpgrade,
+            const QSet<Contact::Feature> &features)
+        : manager(manager),
+          features(features),
+          requestType(Upgrade),
+          contactsToUpgrade(contactsToUpgrade),
+          nested(0)
+    {
+    }
+
+    // Generic parameters
     ContactManager *manager;
     QSet<Contact::Feature> features;
     QMap<uint, QSharedPointer<Contact> > satisfyingContacts;
 
-    bool isForIdentifiers;
+    // Request type specific parameters
+    RequestType requestType;
     UIntList handles;
     QStringList identifiers;
+    QList<QSharedPointer<Contact> > contactsToUpgrade;
     PendingContacts *nested;
 
+    // Results
     QList<QSharedPointer<Contact> > contacts;
     UIntList invalidHandles;
 };
@@ -91,13 +112,13 @@ QSet<Contact::Feature> PendingContacts::features() const
 
 bool PendingContacts::isForHandles() const
 {
-    return !isForIdentifiers();
+    return mPriv->requestType == Private::ForHandles;
 }
 
 UIntList PendingContacts::handles() const
 {
     if (!isForHandles()) {
-        warning() << "Tried to get handles from" << this << "which is for identifiers!";
+        warning() << "Tried to get handles from" << this << "which is not for handles!";
     }
 
     return mPriv->handles;
@@ -105,18 +126,32 @@ UIntList PendingContacts::handles() const
 
 bool PendingContacts::isForIdentifiers() const
 {
-    return mPriv->isForIdentifiers;
+    return mPriv->requestType == Private::ForIdentifiers;
 }
 
 QStringList PendingContacts::identifiers() const
 {
     if (!isForIdentifiers()) {
-        warning() << "Tried to get identifiers from" << this << "which is for handles!";
+        warning() << "Tried to get identifiers from" << this << "which is not for identifiers!";
     }
 
     return mPriv->identifiers;
 }
 
+QList<QSharedPointer<Contact> > PendingContacts::contactsToUpgrade() const
+{
+    if (!isUpgrade()) {
+        warning() << "Tried to get contacts to upgrade from" << this << "which is not an upgrade!";
+    }
+
+    return mPriv->contactsToUpgrade;
+}
+
+bool PendingContacts::isUpgrade() const
+{
+    return mPriv->requestType == Private::Upgrade;
+}
+
 QList<QSharedPointer<Contact> > PendingContacts::contacts() const
 {
     if (!isFinished()) {
@@ -231,6 +266,21 @@ PendingContacts::PendingContacts(ContactManager *manager,
 {
 }
 
+PendingContacts::PendingContacts(ContactManager *manager,
+        const QList<QSharedPointer<Contact> > &contacts, const QSet<Contact::Feature> &features)
+    : PendingOperation(manager), mPriv(new Private(manager, contacts, features))
+{
+    UIntList handles;
+    foreach (QSharedPointer<Contact> contact, contacts) {
+        handles.push_back(contact->handle()[0]);
+    }
+
+    mPriv->nested = manager->contactsForHandles(handles, features);
+    connect(mPriv->nested,
+            SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+            SLOT(onNestedFinished(Telepathy::Client::PendingOperation*)));
+}
+
 void PendingContacts::allAttributesFetched()
 {
     foreach (uint handle, mPriv->handles) {
diff --git a/TelepathyQt4/Client/pending-contacts.h b/TelepathyQt4/Client/pending-contacts.h
index 361645c..cd3aa22 100644
--- a/TelepathyQt4/Client/pending-contacts.h
+++ b/TelepathyQt4/Client/pending-contacts.h
@@ -60,6 +60,9 @@ public:
     bool isForIdentifiers() const;
     QStringList identifiers() const;
 
+    bool isUpgrade() const;
+    QList<QSharedPointer<Contact> > contactsToUpgrade() const;
+
     QList<QSharedPointer<Contact> > contacts() const;
     UIntList invalidHandles() const;
 
@@ -76,6 +79,8 @@ private:
             const QMap<uint, QSharedPointer<Contact> > &satisfyingContacts);
     PendingContacts(ContactManager *manager, const QStringList &identifiers,
             const QSet<Contact::Feature> &features);
+    PendingContacts(ContactManager *manager, const QList<QSharedPointer<Contact> > &contacts,
+            const QSet<Contact::Feature> &features);
 
     void allAttributesFetched();
 
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index b4e5164..b362eee 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -204,6 +204,7 @@ void TestContacts::testForHandles()
 
     QVERIFY(pending->isForHandles());
     QVERIFY(!pending->isForIdentifiers());
+    QVERIFY(!pending->isUpgrade());
 
     QCOMPARE(pending->handles(), handles);
 
@@ -308,6 +309,7 @@ void TestContacts::testForIdentifiers()
 
     QVERIFY(!pending->isForHandles());
     QVERIFY(pending->isForIdentifiers());
+    QVERIFY(!pending->isUpgrade());
 
     QCOMPARE(pending->identifiers(), validIDs);
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list