telepathy-qt: Contact: expose information from Conn.I.ClientTypes

Dario Freddi drf at kemper.freedesktop.org
Thu Jul 5 06:06:01 PDT 2012


Module: telepathy-qt
Branch: master
Commit: c8dc3548e0eee04517c0cef7eb4cfe38bd5bcf07
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=c8dc3548e0eee04517c0cef7eb4cfe38bd5bcf07

Author: George Kiagiadakis <george.kiagiadakis at collabora.com>
Date:   Wed Jul  4 18:33:10 2012 +0300

Contact: expose information from Conn.I.ClientTypes

---

 TelepathyQt/contact-manager.cpp |   23 +++++++++++++++-
 TelepathyQt/contact-manager.h   |    1 +
 TelepathyQt/contact.cpp         |   58 +++++++++++++++++++++++++++++++++++++++
 TelepathyQt/contact.h           |    8 +++++
 4 files changed, 89 insertions(+), 1 deletions(-)

diff --git a/TelepathyQt/contact-manager.cpp b/TelepathyQt/contact-manager.cpp
index 20ec927..a67e736 100644
--- a/TelepathyQt/contact-manager.cpp
+++ b/TelepathyQt/contact-manager.cpp
@@ -252,7 +252,8 @@ Features ContactManager::supportedFeatures() const
             << Contact::FeatureLocation
             << Contact::FeatureInfo
             << Contact::FeatureRosterGroups
-            << Contact::FeatureAddresses;
+            << Contact::FeatureAddresses
+            << Contact::FeatureClientTypes;
         QStringList interfaces = connection()->lowlevel()->contactAttributeInterfaces();
         foreach (const Feature &feature, allFeatures) {
             if (interfaces.contains(featureToInterface(feature))) {
@@ -1408,6 +1409,17 @@ void ContactManager::onContactInfoChanged(uint handle, const Tp::ContactInfoFiel
     }
 }
 
+void ContactManager::onClientTypesUpdated(uint handle, const QStringList &clientTypes)
+{
+    debug() << "Got ClientTypesUpdated for contact with handle" << handle;
+
+    ContactPtr contact = lookupContactByHandle(handle);
+
+    if (contact) {
+        contact->receiveClientTypes(clientTypes);
+    }
+}
+
 void ContactManager::doRefreshInfo()
 {
     PendingRefreshContactInfo *op = mPriv->refreshInfoOp;
@@ -1472,6 +1484,8 @@ QString ContactManager::featureToInterface(const Feature &feature)
         return TP_QT_IFACE_CONNECTION_INTERFACE_CONTACT_GROUPS;
     } else if (feature == Contact::FeatureAddresses) {
         return TP_QT_IFACE_CONNECTION_INTERFACE_ADDRESSING;
+    } else if (feature == Contact::FeatureClientTypes) {
+        return TP_QT_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES;
     } else {
         warning() << "ContactManager doesn't know which interface corresponds to feature"
             << feature;
@@ -1536,6 +1550,13 @@ void ContactManager::ensureTracking(const Feature &feature)
         connect(simplePresenceInterface,
                 SIGNAL(PresencesChanged(Tp::SimpleContactPresences)),
                 SLOT(onPresencesChanged(Tp::SimpleContactPresences)));
+    } else if (feature == Contact::FeatureClientTypes) {
+        Client::ConnectionInterfaceClientTypesInterface *clientTypesInterface =
+            conn->interface<Client::ConnectionInterfaceClientTypesInterface>();
+
+        connect(clientTypesInterface,
+                SIGNAL(ClientTypesUpdated(uint,QStringList)),
+                SLOT(onClientTypesUpdated(uint,QStringList)));
     } else if (feature == Contact::FeatureRosterGroups || feature == Contact::FeatureAddresses) {
         // nothing to do here, but we don't want to warn
         ;
diff --git a/TelepathyQt/contact-manager.h b/TelepathyQt/contact-manager.h
index 6ba8c97..3d703bc 100644
--- a/TelepathyQt/contact-manager.h
+++ b/TelepathyQt/contact-manager.h
@@ -156,6 +156,7 @@ private Q_SLOTS:
     TP_QT_NO_EXPORT void onCapabilitiesChanged(const Tp::ContactCapabilitiesMap &);
     TP_QT_NO_EXPORT void onLocationUpdated(uint, const QVariantMap &);
     TP_QT_NO_EXPORT void onContactInfoChanged(uint, const Tp::ContactInfoFieldList &);
+    TP_QT_NO_EXPORT void onClientTypesUpdated(uint, const QStringList &);
     TP_QT_NO_EXPORT void doRefreshInfo();
 
 private:
diff --git a/TelepathyQt/contact.cpp b/TelepathyQt/contact.cpp
index fe7ffa7..117b1c6 100644
--- a/TelepathyQt/contact.cpp
+++ b/TelepathyQt/contact.cpp
@@ -35,6 +35,7 @@
 #include <TelepathyQt/ContactManager>
 #include <TelepathyQt/LocationInfo>
 #include <TelepathyQt/PendingContactInfo>
+#include <TelepathyQt/PendingStringList>
 #include <TelepathyQt/PendingVoid>
 #include <TelepathyQt/Presence>
 #include <TelepathyQt/ReferencedHandles>
@@ -90,6 +91,8 @@ struct TP_QT_NO_EXPORT Contact::Private
     bool blocked;
 
     QSet<QString> groups;
+
+    QStringList clientTypes;
 };
 
 void Contact::Private::updateAvatarData()
@@ -299,6 +302,13 @@ const Feature Contact::FeatureRosterGroups = Feature(QLatin1String(Contact::stat
 const Feature Contact::FeatureAddresses = Feature(QLatin1String(Contact::staticMetaObject.className()), 8, false);
 
 /**
+ * Feature used in order to access contact client types info.
+ *
+ * \sa clientTypes(), clientTypesChanged()
+ */
+const Feature Contact::FeatureClientTypes = Feature(QLatin1String(Contact::staticMetaObject.className()), 9, false);
+
+/**
  * Construct a new Contact object.
  *
  * \param manager ContactManager owning this contact.
@@ -918,6 +928,25 @@ PendingOperation *Contact::removeFromGroup(const QString &group)
     return manager()->removeContactsFromGroup(group, QList<ContactPtr>() << ContactPtr(this));
 }
 
+/**
+ */
+QStringList Contact::clientTypes() const
+{
+    return mPriv->clientTypes;
+}
+
+/**
+ */
+PendingStringList *Contact::requestClientTypes()
+{
+    Client::ConnectionInterfaceClientTypesInterface *clientTypesInterface =
+        manager()->connection()->interface<Client::ConnectionInterfaceClientTypesInterface>();
+
+    return new PendingStringList(
+            clientTypesInterface->RequestClientTypes(mPriv->handle.at(0)),
+            ContactPtr(this));
+}
+
 void Contact::augment(const Features &requestedFeatures, const QVariantMap &attributes)
 {
     mPriv->requestedFeatures.unite(requestedFeatures);
@@ -1042,6 +1071,21 @@ void Contact::augment(const Features &requestedFeatures, const QVariantMap &attr
             QStringList uris = qdbus_cast<QStringList>(attributes.value(
                         TP_QT_IFACE_CONNECTION_INTERFACE_ADDRESSING + QLatin1String("/uris")));
             receiveAddresses(addresses, uris);
+        } else if (feature == FeatureClientTypes) {
+            QStringList maybeClientTypes = qdbus_cast<QStringList>(attributes.value(
+                        TP_QT_IFACE_CONNECTION_INTERFACE_CLIENT_TYPES + QLatin1String("/client-types")));
+
+            if (!maybeClientTypes.isEmpty()) {
+                receiveClientTypes(maybeClientTypes);
+            } else {
+                if (manager()->supportedFeatures().contains(FeatureClientTypes) &&
+                    mPriv->requestedFeatures.contains(FeatureClientTypes)) {
+                    // ClientTypes being supported but not updated in the
+                    // mapping indicates that the info is not known -
+                    // however, the feature is working fine
+                    mPriv->actualFeatures.insert(FeatureClientTypes);
+                }
+            }
         } else {
             warning() << "Unknown feature" << feature << "encountered when augmenting Contact";
         }
@@ -1164,6 +1208,20 @@ void Contact::receiveAddresses(const QMap<QString, QString> &addresses,
     mPriv->uris = uris;
 }
 
+void Contact::receiveClientTypes(const QStringList &clientTypes)
+{
+    if (!mPriv->requestedFeatures.contains(FeatureClientTypes)) {
+        return;
+    }
+
+    mPriv->actualFeatures.insert(FeatureClientTypes);
+
+    if (mPriv->clientTypes != clientTypes) {
+        mPriv->clientTypes = clientTypes;
+        emit clientTypesChanged(mPriv->clientTypes);
+    }
+}
+
 Contact::PresenceState Contact::subscriptionStateToPresenceState(uint subscriptionState)
 {
     switch (subscriptionState) {
diff --git a/TelepathyQt/contact.h b/TelepathyQt/contact.h
index aa44644..dd26a0e 100644
--- a/TelepathyQt/contact.h
+++ b/TelepathyQt/contact.h
@@ -44,6 +44,7 @@ class LocationInfo;
 class ContactManager;
 class PendingContactInfo;
 class PendingOperation;
+class PendingStringList;
 class Presence;
 class ReferencedHandles;
 
@@ -61,6 +62,7 @@ public:
     static const Feature FeatureLocation;
     static const Feature FeatureSimplePresence;
     static const Feature FeatureAddresses;
+    static const Feature FeatureClientTypes;
 
     enum PresenceState {
          PresenceStateNo,
@@ -168,6 +170,9 @@ public:
     PendingOperation *addToGroup(const QString &group);
     PendingOperation *removeFromGroup(const QString &group);
 
+    QStringList clientTypes() const;
+    PendingStringList *requestClientTypes();
+
 Q_SIGNALS:
     void aliasChanged(const QString &alias);
 
@@ -191,6 +196,8 @@ Q_SIGNALS:
     void addedToGroup(const QString &group);
     void removedFromGroup(const QString &group);
 
+    void clientTypesChanged(const QStringList &clientTypes);
+
     // TODO: consider how the Renaming interface should work and map to Contacts
     // I guess it would be something like:
     // void renamedTo(Tp::ContactPtr)
@@ -216,6 +223,7 @@ private:
     TP_QT_NO_EXPORT void receiveInfo(const ContactInfoFieldList &info);
     TP_QT_NO_EXPORT void receiveAddresses(const QMap<QString, QString> &addresses,
             const QStringList &uris);
+    TP_QT_NO_EXPORT void receiveClientTypes(const QStringList &clientTypes);
 
     TP_QT_NO_EXPORT static PresenceState subscriptionStateToPresenceState(uint subscriptionState);
     TP_QT_NO_EXPORT void setSubscriptionState(SubscriptionState state);



More information about the telepathy-commits mailing list