X-Git-Url: https://git.0d.be/?p=empathy.git;a=blobdiff_plain;f=libempathy%2Fempathy-contact.c;h=69861257235869da416c1ce2fe0ec8290d6eba69;hp=221b06e1720a61f880df326bc3b0df80a920db51;hb=a17ae72f50370e70a8f231b4d24361d448402b20;hpb=d3e46f8c3570d2486eeab6255899daaaf308b036 diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 221b06e1..69861257 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -29,6 +29,8 @@ #include +#include + #include "empathy-contact.h" #include "empathy-utils.h" #include "empathy-debug.h" @@ -45,7 +47,8 @@ struct _EmpathyContactPriv { gchar *name; EmpathyAvatar *avatar; McAccount *account; - EmpathyPresence *presence; + McPresence presence; + gchar *presence_message; guint handle; EmpathyCapabilities capabilities; gboolean is_user; @@ -72,6 +75,7 @@ enum { PROP_AVATAR, PROP_ACCOUNT, PROP_PRESENCE, + PROP_PRESENCE_MESSAGE, PROP_GROUPS, PROP_SUBSCRIPTION, PROP_HANDLE, @@ -124,12 +128,21 @@ empathy_contact_class_init (EmpathyContactClass *class) g_object_class_install_property (object_class, PROP_PRESENCE, - g_param_spec_object ("presence", - "Contact presence", - "Presence of contact", - EMPATHY_TYPE_PRESENCE, - G_PARAM_READWRITE)); + g_param_spec_uint ("presence", + "Contact presence", + "Presence of contact", + MC_PRESENCE_UNSET, + LAST_MC_PRESENCE, + MC_PRESENCE_UNSET, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_PRESENCE_MESSAGE, + g_param_spec_string ("presence-message", + "Contact presence message", + "Presence message of contact", + NULL, + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_HANDLE, g_param_spec_uint ("handle", @@ -146,7 +159,7 @@ empathy_contact_class_init (EmpathyContactClass *class) "Contact Capabilities", "Capabilities of the contact", EMPATHY_TYPE_CAPABILITIES, - 0, + EMPATHY_CAPABILITIES_UNKNOWN, G_PARAM_READWRITE)); g_object_class_install_property (object_class, @@ -176,15 +189,12 @@ contact_finalize (GObject *object) g_free (priv->name); g_free (priv->id); + g_free (priv->presence_message); if (priv->avatar) { empathy_avatar_unref (priv->avatar); } - if (priv->presence) { - g_object_unref (priv->presence); - } - if (priv->account) { g_object_unref (priv->account); } @@ -218,7 +228,10 @@ contact_get_property (GObject *object, g_value_set_object (value, priv->account); break; case PROP_PRESENCE: - g_value_set_object (value, priv->presence); + g_value_set_uint (value, priv->presence); + break; + case PROP_PRESENCE_MESSAGE: + g_value_set_string (value, priv->presence_message); break; case PROP_HANDLE: g_value_set_uint (value, priv->handle); @@ -264,7 +277,11 @@ contact_set_property (GObject *object, break; case PROP_PRESENCE: empathy_contact_set_presence (EMPATHY_CONTACT (object), - EMPATHY_PRESENCE (g_value_get_object (value))); + g_value_get_uint (value)); + break; + case PROP_PRESENCE_MESSAGE: + empathy_contact_set_presence_message (EMPATHY_CONTACT (object), + g_value_get_string (value)); break; case PROP_HANDLE: empathy_contact_set_handle (EMPATHY_CONTACT (object), @@ -451,12 +468,12 @@ empathy_contact_set_account (EmpathyContact *contact, g_object_notify (G_OBJECT (contact), "account"); } -EmpathyPresence * +McPresence empathy_contact_get_presence (EmpathyContact *contact) { EmpathyContactPriv *priv; - g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), MC_PRESENCE_UNSET); priv = GET_PRIV (contact); @@ -464,8 +481,8 @@ empathy_contact_get_presence (EmpathyContact *contact) } void -empathy_contact_set_presence (EmpathyContact *contact, - EmpathyPresence *presence) +empathy_contact_set_presence (EmpathyContact *contact, + McPresence presence) { EmpathyContactPriv *priv; @@ -477,16 +494,39 @@ empathy_contact_set_presence (EmpathyContact *contact, return; } - if (priv->presence) { - g_object_unref (priv->presence); - priv->presence = NULL; - } + priv->presence = presence; + + g_object_notify (G_OBJECT (contact), "presence"); +} + +const gchar * +empathy_contact_get_presence_message (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + priv = GET_PRIV (contact); + + return priv->presence_message; +} + +void +empathy_contact_set_presence_message (EmpathyContact *contact, + const gchar *message) +{ + EmpathyContactPriv *priv = GET_PRIV (contact); - if (presence) { - priv->presence = g_object_ref (presence); + g_return_if_fail (EMPATHY_IS_CONTACT (contact)); + + if (!tp_strdiff (message, priv->presence_message)) { + return; } - g_object_notify (G_OBJECT (contact), "presence"); + g_free (priv->presence_message); + priv->presence_message = g_strdup (message); + + g_object_notify (G_OBJECT (contact), "presence-message"); } guint @@ -591,11 +631,7 @@ empathy_contact_is_online (EmpathyContact *contact) priv = GET_PRIV (contact); - if (!priv->presence) { - return FALSE; - } - - return (empathy_presence_get_state (priv->presence) > MC_PRESENCE_OFFLINE); + return (priv->presence > MC_PRESENCE_OFFLINE); } const gchar * @@ -607,21 +643,24 @@ empathy_contact_get_status (EmpathyContact *contact) priv = GET_PRIV (contact); - if (priv->presence) { - const gchar *status; + if (priv->presence_message) { + return priv->presence_message; + } - status = empathy_presence_get_status (priv->presence); - if (!status) { - McPresence state; + return empathy_presence_get_default_message (priv->presence); +} - state = empathy_presence_get_state (priv->presence); - status = empathy_presence_state_get_default_status (state); - } +gboolean +empathy_contact_can_voip (EmpathyContact *contact) +{ + EmpathyContactPriv *priv; - return status; - } + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), FALSE); + + priv = GET_PRIV (contact); - return empathy_presence_state_get_default_status (MC_PRESENCE_OFFLINE); + return priv->capabilities & (EMPATHY_CAPABILITIES_AUDIO | + EMPATHY_CAPABILITIES_VIDEO); } gboolean