[Telepathy-commits] [telepathy-qt4/master] Add Contact::FeatureSimplePresence
Olli Salli
olli.salli at collabora.co.uk
Mon Feb 2 04:31:51 PST 2009
---
TelepathyQt4/Client/contact-manager.cpp | 5 ++-
TelepathyQt4/Client/contact.cpp | 61 +++++++++++++++++++++++++++++--
TelepathyQt4/Client/contact.h | 7 ++++
3 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/TelepathyQt4/Client/contact-manager.cpp b/TelepathyQt4/Client/contact-manager.cpp
index 051a2c5..1a459ad 100644
--- a/TelepathyQt4/Client/contact-manager.cpp
+++ b/TelepathyQt4/Client/contact-manager.cpp
@@ -93,7 +93,8 @@ namespace
QString featureToInterface(Contact::Feature feature)
{
switch (feature) {
- // TODO: when more features are added, add the translation here too
+ case Contact::FeatureSimplePresence:
+ return TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE;
default:
warning() << "ContactManager doesn't know which interface corresponds to feature"
<< feature;
@@ -142,6 +143,8 @@ PendingContacts *ContactManager::contactsForHandles(const UIntList &handles,
interfaces.insert(featureToInterface(feature));
}
+ // TODO: filter using conn->contactAttributeInterfaces() when I add that
+
PendingContacts *contacts =
new PendingContacts(this, handles, features, satisfyingContacts);
diff --git a/TelepathyQt4/Client/contact.cpp b/TelepathyQt4/Client/contact.cpp
index ce9253f..4a4c976 100644
--- a/TelepathyQt4/Client/contact.cpp
+++ b/TelepathyQt4/Client/contact.cpp
@@ -25,6 +25,7 @@
#include <TelepathyQt4/Client/Connection>
#include <TelepathyQt4/Client/ContactManager>
#include <TelepathyQt4/Client/ReferencedHandles>
+#include <TelepathyQt4/Constants>
#include "TelepathyQt4/debug-internal.h"
@@ -46,6 +47,8 @@ struct Contact::Private
QSet<Feature> requestedFeatures;
QSet<Feature> actualFeatures;
+
+ SimplePresence simplePresence;
};
ContactManager *Contact::manager() const
@@ -73,6 +76,39 @@ QSet<Contact::Feature> Contact::actualFeatures() const
return mPriv->actualFeatures;
}
+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 mPriv->simplePresence.status;
+}
+
+uint Contact::presenceType() const
+{
+ if (!mPriv->requestedFeatures.contains(FeatureSimplePresence)) {
+ warning() << "Contact::presenceType() used on" << this
+ << "for which FeatureSimplePresence hasn't been requested - returning Unknown";
+ return ConnectionPresenceTypeUnknown;
+ }
+
+ return mPriv->simplePresence.type;
+}
+
+QString Contact::presenceMessage() const
+{
+ if (!mPriv->requestedFeatures.contains(FeatureSimplePresence)) {
+ warning() << "Contact::presenceMessage() used on" << this
+ << "for which FeatureSimplePresence hasn't been requested - returning \"\"";
+ return QString("");
+ }
+
+ return mPriv->simplePresence.statusMessage;
+}
+
Contact::~Contact()
{
delete mPriv;
@@ -82,17 +118,36 @@ 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);
}
void Contact::augment(const QSet<Feature> &requestedFeatures, const QVariantMap &attributes) {
mPriv->requestedFeatures.unite(requestedFeatures);
- mPriv->id = qdbus_cast<QString>(attributes["org.freedesktop.Telepathy.Connection/contact-id"]);
+ mPriv->id = qdbus_cast<QString>(attributes[TELEPATHY_INTERFACE_CONNECTION "/contact-id"]);
foreach (Feature feature, requestedFeatures) {
- Q_UNUSED(feature);
- // ...
+ SimplePresence maybePresence;
+
+ switch (feature) {
+ case FeatureSimplePresence:
+ maybePresence = qdbus_cast<SimplePresence>(attributes.value(
+ TELEPATHY_INTERFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE "/presence"));
+
+ if (!maybePresence.status.isEmpty()) {
+ mPriv->simplePresence = maybePresence;
+ mPriv->actualFeatures.insert(FeatureSimplePresence);
+ }
+ break;
+
+ default:
+ warning() << "Unknown feature" << feature << "encountered when augmenting Contact";
+ break;
+ }
}
}
diff --git a/TelepathyQt4/Client/contact.h b/TelepathyQt4/Client/contact.h
index 40851fd..f1593e3 100644
--- a/TelepathyQt4/Client/contact.h
+++ b/TelepathyQt4/Client/contact.h
@@ -30,6 +30,8 @@
#include <QSet>
#include <QVariantMap>
+#include <TelepathyQt4/Types>
+
namespace Telepathy
{
namespace Client
@@ -43,6 +45,7 @@ class Contact : public QObject
public:
enum Feature {
+ FeatureSimplePresence,
_Padding = 0xFFFFFFFF
};
@@ -54,6 +57,10 @@ public:
QSet<Feature> requestedFeatures() const;
QSet<Feature> actualFeatures() const;
+ QString presenceStatus() const;
+ uint presenceType() const;
+ QString presenceMessage() const;
+
~Contact();
private:
--
1.5.6.5
More information about the Telepathy-commits
mailing list