diff options
author | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-05-10 02:51:34 +0800 |
---|---|---|
committer | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-05-10 22:51:52 +0800 |
commit | 3d7ac0c0d325997b277a8ce55df206fc28cd1d1c (patch) | |
tree | 6e6dbcabd91f8ba7a1df08c13e3308b66b284f3b | |
parent | 376bd27843d83ee42e3d731f9856fff9d522aa3c (diff) | |
download | gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar.gz gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar.bz2 gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar.lz gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar.xz gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.tar.zst gsoc2013-empathy-3d7ac0c0d325997b277a8ce55df206fc28cd1d1c.zip |
empathy_contact_from_tpl_contact: set the TpContact
If available, so we get extra info like capabilities.
Based on a patch from Nicolas Dufresne.
-rw-r--r-- | libempathy/empathy-contact.c | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index dfe7c6fee..5f45ccbf6 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -70,6 +70,8 @@ typedef struct { */ GHashTable *location; GHashTable *groups; + + gboolean keep_tpcontact; } EmpathyContactPriv; static void contact_finalize (GObject *object); @@ -179,14 +181,15 @@ contact_dispose (GObject *object) { EmpathyContactPriv *priv = GET_PRIV (object); - if (priv->tp_contact) + if (priv->tp_contact != NULL) { - g_hash_table_remove (contacts_table, priv->tp_contact); + if (!priv->keep_tpcontact) + g_hash_table_remove (contacts_table, priv->tp_contact); + g_signal_handlers_disconnect_by_func (priv->tp_contact, tp_contact_notify_cb, object); - g_object_unref (priv->tp_contact); } - priv->tp_contact = NULL; + tp_clear_object (&priv->tp_contact); if (priv->account) g_object_unref (priv->account); @@ -616,23 +619,55 @@ empathy_contact_new (TpContact *tp_contact) NULL); } +static gboolean +contact_is_tpl_entity (gpointer key, + gpointer value, + gpointer user_data) +{ + TpContact *contact = key; + TplEntity *entity = user_data; + + return !tp_strdiff (tp_contact_get_identifier (contact), + tpl_entity_get_identifier (entity)); +} + EmpathyContact * empathy_contact_from_tpl_contact (TpAccount *account, TplEntity *tpl_entity) { EmpathyContact *retval; gboolean is_user; + EmpathyContact *existing_contact = NULL; g_return_val_if_fail (TPL_IS_ENTITY (tpl_entity), NULL); - is_user = (TPL_ENTITY_SELF == tpl_entity_get_entity_type (tpl_entity)); + if (contacts_table != NULL) + existing_contact = g_hash_table_find (contacts_table, + contact_is_tpl_entity, tpl_entity); - retval = g_object_new (EMPATHY_TYPE_CONTACT, - "id", tpl_entity_get_alias (tpl_entity), - "alias", tpl_entity_get_identifier (tpl_entity), - "account", account, - "is-user", is_user, - NULL); + if (existing_contact != NULL) + { + EmpathyContactPriv *priv; + + retval = g_object_new (EMPATHY_TYPE_CONTACT, + "tp-contact", empathy_contact_get_tp_contact (existing_contact), + "alias", tpl_entity_get_alias (tpl_entity), + NULL); + + priv = GET_PRIV (retval); + priv->keep_tpcontact = TRUE; + } + else + { + is_user = (TPL_ENTITY_SELF == tpl_entity_get_entity_type (tpl_entity)); + + retval = g_object_new (EMPATHY_TYPE_CONTACT, + "id", tpl_entity_get_alias (tpl_entity), + "alias", tpl_entity_get_identifier (tpl_entity), + "account", account, + "is-user", is_user, + NULL); + } if (!EMP_STR_EMPTY (tpl_entity_get_avatar_token (tpl_entity))) contact_load_avatar_cache (retval, @@ -672,16 +707,16 @@ const gchar * empathy_contact_get_alias (EmpathyContact *contact) { EmpathyContactPriv *priv; - const gchar *alias; + const gchar *alias = NULL; g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); priv = GET_PRIV (contact); - if (priv->tp_contact != NULL) - alias = tp_contact_get_alias (priv->tp_contact); - else + if (!EMP_STR_EMPTY (priv->alias)) alias = priv->alias; + else if (priv->tp_contact != NULL) + alias = tp_contact_get_alias (priv->tp_contact); if (!EMP_STR_EMPTY (alias)) return alias; |