aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>2009-05-27 23:45:32 +0800
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>2009-05-28 00:52:03 +0800
commit1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d (patch)
tree2788594f701f2c377222c7cb59f8d8ab1ea236ff
parent0df4d81f42b3657cd466df44ccffb78045e5d8c9 (diff)
downloadgsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar.gz
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar.bz2
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar.lz
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar.xz
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.tar.zst
gsoc2013-empathy-1d8091578b25a85b3d1d6d4c651a0c8e73c3fe2d.zip
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.
-rw-r--r--libempathy/empathy-tp-contact-factory.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c
index d8d9597ce..0ddf91b29 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