From 4ee7e811f1686d7a24d951269f46dd8be682ff84 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Tue, 10 May 2011 15:35:20 +0100 Subject: Use a weak ref to remove the tpcontact from the hashtable Conflicts: libempathy/empathy-contact.c --- libempathy/empathy-contact.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'libempathy/empathy-contact.c') diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c index 8150e9e67..5acf2ba34 100644 --- a/libempathy/empathy-contact.c +++ b/libempathy/empathy-contact.c @@ -72,8 +72,6 @@ typedef struct { GHashTable *location; GeeHashSet *groups; gchar **client_types; - - gboolean keep_tpcontact; } EmpathyContactPriv; static void contact_finalize (GObject *object); @@ -194,9 +192,6 @@ contact_dispose (GObject *object) if (priv->tp_contact != NULL) { - 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); } @@ -634,14 +629,27 @@ contact_set_property (GObject *object, }; } +static void +remove_tp_contact (gpointer data, + GObject *object) +{ + g_hash_table_remove (contacts_table, data); +} + static EmpathyContact * empathy_contact_new (TpContact *tp_contact) { + EmpathyContact *retval; + g_return_val_if_fail (TP_IS_CONTACT (tp_contact), NULL); - return g_object_new (EMPATHY_TYPE_CONTACT, + retval = g_object_new (EMPATHY_TYPE_CONTACT, "tp-contact", tp_contact, NULL); + + g_object_weak_ref (G_OBJECT (retval), remove_tp_contact, tp_contact); + + return retval; } static gboolean @@ -672,15 +680,10 @@ empathy_contact_from_tpl_contact (TpAccount *account, 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 { -- cgit v1.2.3