[Telepathy-commits] [telepathy-qt4/master] Add and test Connection::contactAttributeInterfaces
Olli Salli
olli.salli at collabora.co.uk
Wed Feb 4 10:52:04 PST 2009
This is quite a lousy hack to intertwine CAI with the other "essential"
properties of the Connection - when Connection is otherwise sanitized,
this code should be nicer too.
---
TelepathyQt4/Client/connection.cpp | 73 +++++++++++++++++++++++++++++++++--
TelepathyQt4/Client/connection.h | 2 +
tests/dbus/contacts.cpp | 10 ++++-
3 files changed, 79 insertions(+), 6 deletions(-)
diff --git a/TelepathyQt4/Client/connection.cpp b/TelepathyQt4/Client/connection.cpp
index 283f06f..ec82be2 100644
--- a/TelepathyQt4/Client/connection.cpp
+++ b/TelepathyQt4/Client/connection.cpp
@@ -114,6 +114,7 @@ struct Connection::Private
void startIntrospection();
void introspectMain();
+ void introspectContacts();
void introspectSimplePresence();
void introspectSelfPresence();
void introspectSelfHandle();
@@ -160,6 +161,7 @@ struct Connection::Private
bool haveInitialStatus;
SimpleStatusSpecMap simplePresenceStatuses;
SimplePresence selfPresence;
+ QStringList contactAttributeInterfaces;
uint selfHandle;
@@ -321,6 +323,24 @@ void Connection::Private::introspectMain()
SLOT(gotInterfaces(QDBusPendingCallWatcher *)));
}
+void Connection::Private::introspectContacts()
+{
+ if (!properties) {
+ properties = parent->propertiesInterface();
+ Q_ASSERT(properties != 0);
+ }
+
+ debug() << "Getting available interfaces for GetContactAttributes";
+ QDBusPendingCall call =
+ properties->Get(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS,
+ "ContactAttributeInterfaces");
+ QDBusPendingCallWatcher *watcher =
+ new QDBusPendingCallWatcher(call, parent);
+ parent->connect(watcher,
+ SIGNAL(finished(QDBusPendingCallWatcher *)),
+ SLOT(gotContactAttributeInterfaces(QDBusPendingCallWatcher *)));
+}
+
void Connection::Private::introspectSimplePresence()
{
if (!properties) {
@@ -331,12 +351,12 @@ void Connection::Private::introspectSimplePresence()
debug() << "Getting available SimplePresence statuses";
QDBusPendingCall call =
properties->Get(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE,
- "Statuses");
+ "Statuses");
QDBusPendingCallWatcher *watcher =
new QDBusPendingCallWatcher(call, parent);
parent->connect(watcher,
- SIGNAL(finished(QDBusPendingCallWatcher *)),
- SLOT(gotSimpleStatuses(QDBusPendingCallWatcher *)));
+ SIGNAL(finished(QDBusPendingCallWatcher *)),
+ SLOT(gotSimpleStatuses(QDBusPendingCallWatcher *)));
}
void Connection::Private::introspectSelfPresence()
@@ -946,6 +966,7 @@ void Connection::gotStatus(QDBusPendingCallWatcher *watcher)
}
mPriv->introspectQueue.enqueue(&Private::introspectMain);
+
continueIntrospection();
watcher->deleteLater();
@@ -956,11 +977,17 @@ void Connection::gotInterfaces(QDBusPendingCallWatcher *watcher)
QDBusPendingReply<QStringList> reply = *watcher;
if (!reply.isError()) {
- debug() << "Connection basic functionality is ready";
- mPriv->ready = true;
debug() << "Got reply to GetInterfaces():" << mPriv->interfaces;
mPriv->interfaces = reply.value();
+ if (mPriv->pendingStatus == ConnectionStatusConnected
+ && mPriv->interfaces.contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
+ mPriv->introspectQueue.enqueue(&Private::introspectContacts);
+ } else {
+ debug() << "Connection basic functionality is ready";
+ mPriv->ready = true;
+ }
+
// if FeatureSelfPresence was requested and the interface exists and
// the introspect func is not already enqueued, enqueue it.
if (mPriv->pendingFeatures & FeatureSelfPresence &&
@@ -980,6 +1007,27 @@ void Connection::gotInterfaces(QDBusPendingCallWatcher *watcher)
watcher->deleteLater();
}
+void Connection::gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher)
+{
+ debug() << "Connection basic functionality is ready (Got CAI)";
+ mPriv->ready = true;
+
+ QDBusPendingReply<QDBusVariant> reply = *watcher;
+
+ if (!reply.isError()) {
+ mPriv->contactAttributeInterfaces = qdbus_cast<QStringList>(reply.value().variant());
+ debug() << "Got" << mPriv->contactAttributeInterfaces.size() << "contact attribute interfaces";
+ }
+ else {
+ warning().nospace() << "Getting contact attribute interfaces failed with " <<
+ reply.error().name() << ":" << reply.error().message();
+ }
+
+ continueIntrospection();
+
+ watcher->deleteLater();
+}
+
void Connection::gotSimpleStatuses(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QDBusVariant> reply = *watcher;
@@ -1476,6 +1524,21 @@ PendingContactAttributes *Connection::getContactAttributes(const UIntList &handl
return pending;
}
+QStringList Connection::contactAttributeInterfaces() const
+{
+ if (!isReady()) {
+ warning() << "Connection::contactAttributeInterfaces() used when not ready";
+ } else if (status() != StatusConnected) {
+ warning() << "Connection::contactAttributeInterfaces() used with status"
+ << status() << "!= StatusConnected";
+ } else if (!this->interfaces().contains(TELEPATHY_INTERFACE_CONNECTION_INTERFACE_CONTACTS)) {
+ warning() << "Connection::contactAttributeInterfaces() used without the remote object supporting"
+ << "the Contacts interface";
+ }
+
+ return mPriv->contactAttributeInterfaces;
+}
+
ContactManager *Connection::contactManager() const
{
return mPriv->contactManager;
diff --git a/TelepathyQt4/Client/connection.h b/TelepathyQt4/Client/connection.h
index 6bda2ca..306d694 100644
--- a/TelepathyQt4/Client/connection.h
+++ b/TelepathyQt4/Client/connection.h
@@ -162,6 +162,7 @@ public:
PendingContactAttributes *getContactAttributes(const UIntList &contacts,
const QStringList &interfaces, bool reference = true);
+ QStringList contactAttributeInterfaces() const;
ContactManager *contactManager() const;
bool isReady(Features features = 0) const;
@@ -180,6 +181,7 @@ private Q_SLOTS:
void onStatusChanged(uint, uint);
void gotStatus(QDBusPendingCallWatcher *watcher);
void gotInterfaces(QDBusPendingCallWatcher *watcher);
+ void gotContactAttributeInterfaces(QDBusPendingCallWatcher *watcher);
void gotSimpleStatuses(QDBusPendingCallWatcher *watcher);
void gotSelfPresence(QDBusPendingCallWatcher *watcher);
void gotSelfHandle(QDBusPendingCallWatcher *watcher);
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index 64d00a5..c437aed 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -183,7 +183,15 @@ void TestContacts::testSupport()
QCOMPARE(mConn->contactManager()->connection(), mConn);
QVERIFY(mConn->contactManager()->isSupported());
- // TODO: when Connection::CAI and ContactManager::featureSupported() are added, test them here
+ QVERIFY(!mConn->contactAttributeInterfaces().isEmpty());
+
+ QVERIFY(mConn->contactAttributeInterfaces().contains(TELEPATHY_INTERFACE_CONNECTION));
+ QVERIFY(mConn->contactAttributeInterfaces().contains(
+ TELEPATHY_INTERFACE_CONNECTION_INTERFACE_ALIASING));
+ QVERIFY(mConn->contactAttributeInterfaces().contains(
+ TELEPATHY_INTERFACE_CONNECTION_INTERFACE_AVATARS));
+ QVERIFY(mConn->contactAttributeInterfaces().contains(
+ TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE));
}
void TestContacts::testForHandles()
--
1.5.6.5
More information about the telepathy-commits
mailing list