[Telepathy-commits] [telepathy-qt4/master] Add contactsForHandles(Referenced) and contactsForIdentifiers(QStringList) to ContactManager
Olli Salli
olli.salli at collabora.co.uk
Wed Jan 28 13:24:17 PST 2009
---
TelepathyQt4/Client/contact-manager.cpp | 24 +++++++
TelepathyQt4/Client/contact-manager.h | 5 ++
TelepathyQt4/Client/pending-contacts.cpp | 102 +++++++++++++++++++++++++++---
TelepathyQt4/Client/pending-contacts.h | 12 +++-
4 files changed, 133 insertions(+), 10 deletions(-)
diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 178d9b5..dda2a0d 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -27,6 +27,8 @@
#include <TelepathyQt4/Client/Connection>
#include <TelepathyQt4/Client/PendingContactAttributes>
#include <TelepathyQt4/Client/PendingContacts>
+#include <TelepathyQt4/Client/PendingHandles>
+#include <TelepathyQt4/Client/ReferencedHandles>
#include "TelepathyQt4/debug-internal.h"
/**
@@ -106,6 +108,28 @@ PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
return contacts;
}
+PendingContacts *ContactManager::contactsForHandles(const ReferencedHandles &handles,
+ const QSet<Contact::Feature> &features)
+{
+ return contactsForHandles(handles.toList(), features);
+}
+
+PendingContacts *ContactManager::contactsForIdentifiers(const QStringList &identifiers,
+ const QSet<Contact::Feature> &features)
+{
+ debug() << "Building contacts for" << identifiers.size() << "identifiers" << "with" << features.size()
+ << "features";
+
+ PendingHandles *handles = mPriv->conn->requestHandles(HandleTypeContact, identifiers);
+
+ PendingContacts *contacts = new PendingContacts(mPriv->conn, identifiers, features);
+ contacts->connect(handles,
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(onHandlesFinished(Telepathy::Client::PendingOperation*)));
+
+ return contacts;
+}
+
ContactManager::ContactManager(Connection *parent)
: mPriv(new Private)
{
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index 2d631f1..0d1938d 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -48,6 +48,11 @@ class ContactManager
PendingContacts *contactsForHandles(const UIntList &handles,
const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
+ PendingContacts *contactsForHandles(const ReferencedHandles &handles,
+ const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
+
+ PendingContacts *contactsForIdentifiers(const QStringList &identifiers,
+ const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
private:
ContactManager(Connection *parent);
diff --git a/TelepathyQt4/Client/pending-contacts.cpp b/TelepathyQt4/Client/pending-contacts.cpp
index b455397..e242873 100644
--- a/TelepathyQt4/Client/pending-contacts.cpp
+++ b/TelepathyQt4/Client/pending-contacts.cpp
@@ -23,7 +23,9 @@
#include "TelepathyQt4/Client/_gen/pending-contacts.moc.hpp"
#include <TelepathyQt4/Client/Connection>
+#include <TelepathyQt4/Client/ContactManager>
#include <TelepathyQt4/Client/PendingContactAttributes>
+#include <TelepathyQt4/Client/PendingHandles>
#include <TelepathyQt4/Client/ReferencedHandles>
#include "TelepathyQt4/debug-internal.h"
@@ -35,24 +37,35 @@ namespace Client
struct PendingContacts::Private
{
Private(Connection *connection, const UIntList &handles, const QSet<Contact::Feature> &features)
- : connection(connection), handles(handles), features(features)
+ : connection(connection),
+ features(features),
+ isForIdentifiers(false),
+ handles(handles),
+ nested(0)
+ {
+ }
+
+ Private(Connection *connection, const QStringList &identifiers,
+ const QSet<Contact::Feature> &features)
+ : connection(connection),
+ features(features),
+ isForIdentifiers(true),
+ identifiers(identifiers),
+ nested(0)
{
}
Connection *connection;
- UIntList handles;
QSet<Contact::Feature> features;
+ bool isForIdentifiers;
+ UIntList handles;
+ QStringList identifiers;
+ PendingContacts *nested;
+
QList<QSharedPointer<Contact> > contacts;
};
-PendingContacts::PendingContacts(Connection *connection,
- const UIntList &handles, const QSet<Contact::Feature> &features)
- : PendingOperation(connection),
- mPriv(new Private(connection, handles, features))
-{
-}
-
/**
* Class destructor.
*/
@@ -76,6 +89,25 @@ QSet<Contact::Feature> PendingContacts::features() const
return mPriv->features;
}
+bool PendingContacts::isForHandles() const
+{
+ return !isForIdentifiers();
+}
+
+bool PendingContacts::isForIdentifiers() const
+{
+ return mPriv->isForIdentifiers;
+}
+
+QStringList PendingContacts::identifiers() const
+{
+ if (!isForIdentifiers()) {
+
+ }
+
+ return mPriv->identifiers;
+}
+
QList<QSharedPointer<Contact> > PendingContacts::contacts() const
{
if (!isFinished()) {
@@ -115,5 +147,57 @@ void PendingContacts::onAttributesFinished(PendingOperation *operation)
setFinished();
}
+void PendingContacts::onHandlesFinished(PendingOperation *operation)
+{
+ PendingHandles *pendingHandles = qobject_cast<PendingHandles *>(operation);
+
+ debug() << "Handles finished for" << this;
+
+ if (pendingHandles->isError()) {
+ debug() << " error" << operation->errorName()
+ << "message" << operation->errorMessage();
+ setFinishedWithError(operation->errorName(), operation->errorMessage());
+ return;
+ }
+
+ debug() << " Success - doing nested contact query";
+
+ mPriv->nested = contactManager()->contactsForHandles(pendingHandles->handles(), features());
+ connect(mPriv->nested,
+ SIGNAL(finished(Telepathy::Client::PendingOperation*)),
+ SLOT(onNestedFinished(Telepathy::Client::PendingOperation*)));
+}
+
+void PendingContacts::onNestedFinished(PendingOperation *operation)
+{
+ Q_ASSERT(operation == mPriv->nested);
+
+ debug() << "Nested PendingContacts finished for" << this;
+
+ if (operation->isError()) {
+ debug() << " error" << operation->errorName()
+ << "message" << operation->errorMessage();
+ setFinishedWithError(operation->errorName(), operation->errorMessage());
+ return;
+ }
+
+ mPriv->contacts = mPriv->nested->contacts();
+ mPriv->nested = 0;
+ setFinished();
+}
+
+PendingContacts::PendingContacts(Connection *connection,
+ const UIntList &handles, const QSet<Contact::Feature> &features)
+ : PendingOperation(connection),
+ mPriv(new Private(connection, handles, features))
+{
+}
+
+PendingContacts::PendingContacts(Connection *connection,
+ const QStringList &identifiers, const QSet<Contact::Feature> &features)
+ : PendingOperation(connection), mPriv(new Private(connection, identifiers, features))
+{
+}
+
} // Telepathy::Client
} // Telepathy
diff --git a/TelepathyQt4/Client/pending-contacts.h b/TelepathyQt4/Client/pending-contacts.h
index 86f38bb..a2717a8 100644
--- a/TelepathyQt4/Client/pending-contacts.h
+++ b/TelepathyQt4/Client/pending-contacts.h
@@ -31,6 +31,7 @@
#include <QList>
#include <QSet>
#include <QSharedPointer>
+#include <QStringList>
#include <TelepathyQt4/Types>
#include <TelepathyQt4/Client/Contact>
@@ -51,18 +52,27 @@ public:
~PendingContacts();
ContactManager *contactManager() const;
- UIntList handles() const;
QSet<Contact::Feature> features() const;
+ bool isForHandles() const;
+ UIntList handles() const;
+
+ bool isForIdentifiers() const;
+ QStringList identifiers() const;
+
QList<QSharedPointer<Contact> > contacts() const;
private Q_SLOTS:
void onAttributesFinished(PendingOperation *);
+ void onHandlesFinished(PendingOperation *);
+ void onNestedFinished(PendingOperation *);
private:
Q_DISABLE_COPY(PendingContacts);
PendingContacts(Connection *connection, const UIntList &handles,
const QSet<Contact::Feature> &features);
+ PendingContacts(Connection *connection, const QStringList &identifiers,
+ const QSet<Contact::Feature> &features);
struct Private;
friend struct Private;
--
1.5.6.5
More information about the telepathy-commits
mailing list