[empathy] Copy GHashTable received from Dbus and refactor



commit 1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Wed May 27 11:45:32 2009 -0400

    Copy GHashTable received from Dbus and refactor
    
    This makes the GHashTable's structure explicit and less error prone
    when inserting later on.
    
    Move the copied code over to a new function.
---
 libempathy/empathy-tp-contact-factory.c |   37 ++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c
index d8d9597..0ddf91b 100644
--- a/libempathy/empathy-tp-contact-factory.c
+++ b/libempathy/empathy-tp-contact-factory.c
@@ -25,6 +25,7 @@
 
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/dbus.h>
 
 #include <extensions/extensions.h>
 
@@ -391,6 +392,27 @@ tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory,
 }
 
 static void
+tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory,
+				    guint handle,
+				    GHashTable *location)
+{
+	EmpathyContact *contact;
+	GHashTable     *new_location;
+
+	contact = tp_contact_factory_find_by_handle (tp_factory, handle);
+
+	if (contact == NULL)
+		return;
+
+	new_location = g_hash_table_new_full (g_str_hash, g_str_equal,
+		(GDestroyNotify) g_free, (GDestroyNotify) tp_g_value_slice_free);
+	tp_g_hash_table_update (new_location, location, (GBoxedCopyFunc) g_strdup,
+		(GBoxedCopyFunc) tp_g_value_slice_dup);
+	empathy_contact_set_location (contact, new_location);
+	g_hash_table_unref (new_location);
+}
+
+static void
 tp_contact_factory_got_locations (TpProxy                 *tp_proxy,
 				  GHashTable              *locations,
 				  const GError            *error,
@@ -411,12 +433,8 @@ tp_contact_factory_got_locations (TpProxy                 *tp_proxy,
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
 		guint           handle = GPOINTER_TO_INT (key);
 		GHashTable     *location = value;
-		EmpathyContact *contact;
 
-		contact = tp_contact_factory_find_by_handle (tp_factory, handle);
-		if (contact != NULL) {
-			empathy_contact_set_location (contact, location);
-		}
+		tp_contact_factory_update_location (tp_factory, handle, location);
 	}
 }
 
@@ -458,14 +476,7 @@ tp_contact_factory_location_updated_cb (TpProxy      *proxy,
 					GObject      *weak_object)
 {
 	EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
-	EmpathyContact          *contact;
-
-	contact = tp_contact_factory_find_by_handle (tp_factory, handle);
-
-	if (contact == NULL)
-		return;
-
-	empathy_contact_set_location (contact, location);
+	tp_contact_factory_update_location (tp_factory, handle, location);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]