diff options
author | Morten Mjelva <morten.mjelva@gmail.com> | 2010-06-11 19:04:56 +0200 |
---|---|---|
committer | Morten Mjelva <morten.mjelva@gmail.com> | 2010-06-14 12:52:31 +0200 |
commit | 65522cc143c32ed23bf789c143a95131c4c3c780 (patch) | |
tree | 695ea32b1e731b646be64252f6c9242e42336190 | |
parent | c119cd79de81c0069343c61c1dcffd0fd64f7918 (diff) |
Make TpContact emit a presence-changed signalpresence-changed
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.
-rw-r--r-- | telepathy-glib/contact.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c index 78afe546..c0c605ae 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,33 @@ 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); + + tp_value_array_unpack (presence, 3, &type, &status, &message); + + contact->priv->presence_type = type; + g_free (contact->priv->presence_status); - contact->priv->presence_status = g_value_dup_string ( - presence->values + 1); + contact->priv->presence_status = g_strdup (status); + g_free (contact->priv->presence_message); - contact->priv->presence_message = g_value_dup_string ( - presence->values + 2); + contact->priv->presence_message = g_strdup (message); g_object_notify ((GObject *) contact, "presence-type"); g_object_notify ((GObject *) contact, "presence-status"); 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 |