[Telepathy-commits] [telepathy-qt4/master] Add and test ContactManager::supportedFeatures()
Olli Salli
olli.salli at collabora.co.uk
Wed Feb 4 11:24:13 PST 2009
---
TelepathyQt4/Client/contact-manager.cpp | 38 ++++++++++++++++++++++++++++--
TelepathyQt4/Client/contact-manager.h | 1 +
TelepathyQt4/Client/contact.cpp | 26 +++++++++++++--------
tests/dbus/contacts.cpp | 8 +++++-
4 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index eb7ed7b..5a428c3 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -72,6 +72,8 @@ struct ContactManager::Private
QMap<Contact::Feature, bool> tracking;
void ensureTracking(Contact::Feature feature);
+
+ QSet<Contact::Feature> supportedFeatures;
};
Connection *ContactManager::connection() const
@@ -111,6 +113,33 @@ QString featureToInterface(Contact::Feature feature)
}
}
+QSet<Contact::Feature> ContactManager::supportedFeatures() const
+{
+ if (!isSupported()) {
+ warning() << "ContactManager::supportedFeatures() used with the entire ContactManager"
+ << "functionality being unsupported, returning an empty set";
+ return QSet<Contact::Feature>();
+ }
+
+ if (mPriv->supportedFeatures.isEmpty()) {
+ QList<Contact::Feature> allFeatures = QList<Contact::Feature>()
+ << Contact::FeatureAlias
+ << Contact::FeatureAvatarToken
+ << Contact::FeatureSimplePresence;
+ QStringList interfaces = mPriv->conn->contactAttributeInterfaces();
+
+ foreach (Contact::Feature feature, allFeatures) {
+ if (interfaces.contains(featureToInterface(feature))) {
+ mPriv->supportedFeatures.insert(feature);
+ }
+ }
+
+ debug() << mPriv->supportedFeatures.size() << "contact features supported using" << this;
+ }
+
+ return mPriv->supportedFeatures;
+}
+
PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
const QSet<Contact::Feature> &features)
{
@@ -143,13 +172,16 @@ PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
<< otherContacts.size() << "other contacts";
debug() << " " << missingFeatures.size() << "features missing";
+ QSet<Contact::Feature> supported = supportedFeatures();
QSet<QString> interfaces;
foreach (Contact::Feature feature, missingFeatures) {
- interfaces.insert(featureToInterface(feature));
mPriv->ensureTracking(feature);
- }
- // TODO: filter using conn->contactAttributeInterfaces() when I add that
+ if (supported.contains(feature)) {
+ // Only query interfaces which are reported as supported to not get an error
+ interfaces.insert(featureToInterface(feature));
+ }
+ }
PendingContacts *contacts =
new PendingContacts(this, handles, features, satisfyingContacts);
diff --git a/TelepathyQt4/Client/contact-manager.h b/TelepathyQt4/Client/contact-manager.h
index a7b43ca..917136c 100644
--- a/TelepathyQt4/Client/contact-manager.h
+++ b/TelepathyQt4/Client/contact-manager.h
@@ -53,6 +53,7 @@ class ContactManager : public QObject
Connection *connection() const;
bool isSupported() const;
+ QSet<Contact::Feature> supportedFeatures() const;
PendingContacts *contactsForHandles(const UIntList &handles,
const QSet<Contact::Feature> &features = QSet<Contact::Feature>());
diff --git a/TelepathyQt4/Client/contact.cpp b/TelepathyQt4/Client/contact.cpp
index 62d512f..d10d654 100644
--- a/TelepathyQt4/Client/contact.cpp
+++ b/TelepathyQt4/Client/contact.cpp
@@ -121,7 +121,7 @@ QString Contact::presenceStatus() const
if (!mPriv->requestedFeatures.contains(FeatureSimplePresence)) {
warning() << "Contact::presenceStatus() used on" << this
<< "for which FeatureSimplePresence hasn't been requested - returning \"unknown\"";
- return QString("");
+ return QString("unknown");
}
return mPriv->simplePresence.status;
@@ -158,10 +158,6 @@ Contact::Contact(ContactManager *manager, const ReferencedHandles &handle,
const QSet<Feature> &requestedFeatures, const QVariantMap &attributes)
: QObject(0), mPriv(new Private(manager, handle))
{
- mPriv->simplePresence.type = ConnectionPresenceTypeUnknown;
- mPriv->simplePresence.status = "unknown";
- mPriv->simplePresence.statusMessage = "";
-
augment(requestedFeatures, attributes);
}
@@ -181,6 +177,8 @@ void Contact::augment(const QSet<Feature> &requestedFeatures, const QVariantMap
if (!maybeAlias.isEmpty()) {
receiveAlias(maybeAlias);
+ } else if (mPriv->alias.isEmpty()) {
+ mPriv->alias = mPriv->id;
}
break;
@@ -189,11 +187,15 @@ void Contact::augment(const QSet<Feature> &requestedFeatures, const QVariantMap
TELEPATHY_INTERFACE_CONNECTION_INTERFACE_AVATARS "/token")) {
receiveAvatarToken(qdbus_cast<QString>(attributes.value(
TELEPATHY_INTERFACE_CONNECTION_INTERFACE_AVATARS "/token")));
- } else if (mPriv->requestedFeatures.contains(FeatureAvatarToken)) {
- // TODO: When Conn::CAI and ContactManager::featuresSupported are added, check
- // for those (probably only the latter) here to decide whether to set this or
- // not
- mPriv->actualFeatures.insert(FeatureAvatarToken);
+ } else {
+ if (manager()->supportedFeatures().contains(FeatureAvatarToken)) {
+ // AvatarToken being supported but not included in the mapping indicates
+ // that the avatar token is not known - however, the feature is working fine
+ mPriv->actualFeatures.insert(FeatureAvatarToken);
+ }
+ // In either case, the avatar token can't be known
+ mPriv->isAvatarTokenKnown = false;
+ mPriv->avatarToken = "";
}
break;
@@ -203,6 +205,10 @@ void Contact::augment(const QSet<Feature> &requestedFeatures, const QVariantMap
if (!maybePresence.status.isEmpty()) {
receiveSimplePresence(maybePresence);
+ } else {
+ mPriv->simplePresence.type = ConnectionPresenceTypeUnknown;
+ mPriv->simplePresence.status = "unknown";
+ mPriv->simplePresence.statusMessage = "";
}
break;
diff --git a/tests/dbus/contacts.cpp b/tests/dbus/contacts.cpp
index c437aed..172d41f 100644
--- a/tests/dbus/contacts.cpp
+++ b/tests/dbus/contacts.cpp
@@ -192,6 +192,12 @@ void TestContacts::testSupport()
TELEPATHY_INTERFACE_CONNECTION_INTERFACE_AVATARS));
QVERIFY(mConn->contactAttributeInterfaces().contains(
TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE));
+
+ QSet<Contact::Feature> supportedFeatures = mConn->contactManager()->supportedFeatures();
+ QVERIFY(!supportedFeatures.isEmpty());
+ QVERIFY(supportedFeatures.contains(Contact::FeatureAlias));
+ QVERIFY(supportedFeatures.contains(Contact::FeatureAvatarToken));
+ QVERIFY(supportedFeatures.contains(Contact::FeatureSimplePresence));
}
void TestContacts::testForHandles()
@@ -561,7 +567,7 @@ void TestContacts::testFeaturesNotRequested()
QVERIFY(!contact->isAvatarTokenKnown());
QCOMPARE(contact->avatarToken(), QString(""));
- QCOMPARE(contact->presenceStatus(), QString(""));
+ QCOMPARE(contact->presenceStatus(), QString("unknown"));
QCOMPARE(contact->presenceType(), uint(Telepathy::ConnectionPresenceTypeUnknown));
QCOMPARE(contact->presenceMessage(), QString(""));
}
--
1.5.6.5
More information about the telepathy-commits
mailing list