From 64e1be94cb303f1e5802c91c1dedb98138e932a7 Mon Sep 17 00:00:00 2001 From: Morten Mjelva Date: Fri, 11 Jun 2010 19:04:56 +0200 Subject: [PATCH] Make TpContact emit a presence-changed signal This adds a signal to TpContact that is issued whenever the PresencesChanged signal on org.freedesktop.Telepathy.Connection.SimplePresence is issued for the contact in question. The signal holds the new presence information for the contact. --- telepathy-glib/contact.c | 52 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 45 insertions(+), 7 deletions(-) diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 78afe54..5d07be7 100644 --- a/telepathy-glib/contact.c +++ b/telepathy-glib/contact.c @@ -32,6 +32,8 @@ #include "telepathy-glib/connection-internal.h" #include "telepathy-glib/debug-internal.h" +#include "telepathy-glib/_gen/signals-marshal.h" + /** * SECTION:contact * @title: TpContact @@ -135,6 +137,13 @@ enum { N_PROPS }; +enum { + SIGNAL_PRESENCE_CHANGED, + N_SIGNALS +}; + +static guint signals[N_SIGNALS] = {0}; + /* The API allows for more than 32 features, but this implementation does * not. We can easily expand this later. */ typedef enum { @@ -858,6 +867,24 @@ tp_contact_class_init (TpContactClass *klass) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_CAPABILITIES, param_spec); + + + /** + * TpContact::presence-changed: + * @contact: A #TpContact + * @type: The new value of #TpContact:presence-type + * @status: The new value of #TpContact:presence-status + * @message: The new value of #TpContact:presence-message + * + * Emitted when this contact's presence changes. + */ + signals[SIGNAL_PRESENCE_CHANGED] = g_signal_new ("presence-changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + _tp_marshal_VOID__UINT_STRING_STRING, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); } @@ -1636,21 +1663,32 @@ static void contact_maybe_set_simple_presence (TpContact *contact, GValueArray *presence) { + guint type; + const gchar *status; + const gchar *message; + if (contact == NULL || presence == NULL) return; contact->priv->has_features |= CONTACT_FEATURE_FLAG_PRESENCE; - contact->priv->presence_type = g_value_get_uint (presence->values + 0); - g_free (contact->priv->presence_status); - contact->priv->presence_status = g_value_dup_string ( - presence->values + 1); - g_free (contact->priv->presence_message); - contact->priv->presence_message = g_value_dup_string ( - presence->values + 2); + tp_value_array_unpack (presence, 3, &type, &status, &message); + + contact->priv->presence_type = type; g_object_notify ((GObject *) contact, "presence-type"); + + g_free (contact->priv->presence_status); + contact->priv->presence_status = g_strdup (status); g_object_notify ((GObject *) contact, "presence-status"); + + g_free (contact->priv->presence_message); + contact->priv->presence_message = g_strdup (message); g_object_notify ((GObject *) contact, "presence-message"); + + g_signal_emit (contact, signals[SIGNAL_PRESENCE_CHANGED], 0, + contact->priv->presence_type, + contact->priv->presence_status, + contact->priv->presence_message); } static void -- 1.7.0.4