From b5f052380c8c458dd54153840ab22b5733f14712 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Wed, 31 Dec 2008 15:16:38 -0500 Subject: Move get_location to the right place This will make the location requested upon contact creation --- libempathy/empathy-tp-contact-factory.c | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c index 5c861a716..fad4625d6 100644 --- a/libempathy/empathy-tp-contact-factory.c +++ b/libempathy/empathy-tp-contact-factory.c @@ -314,6 +314,21 @@ tp_contact_factory_avatar_updated_cb (TpConnection *connection, g_array_free (handles, TRUE); } +static void +tp_contact_factory_update_location (EmpathyTpContactFactory *tp_factory, + guint handle, + GHashTable *location) +{ + EmpathyContact *contact; + + contact = tp_contact_factory_find_by_handle (tp_factory, handle); + if (!contact) { + return; + } + + empathy_contact_set_location (contact, location); +} + static void tp_contact_factory_update_capabilities (EmpathyTpContactFactory *tp_factory, guint handle, @@ -390,6 +405,35 @@ tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory, g_ptr_array_free (capabilities, TRUE); } +static void +tp_contact_factory_got_locations (EmpathyTpContactFactory *tp_factory, + GHashTable *locations, + const GError *error) +{ + GHashTableIter iter; + gpointer key, value; + + if (error) { + DEBUG ("Error: %s", error->message); + /* FIXME Should set the capabilities of the contacts for which this request + * originated to NONE */ + return; + } + + g_hash_table_iter_init (&iter, locations); + while (g_hash_table_iter_next (&iter, &key, &value)) { + /* do something with key and value */ + guint handle = GPOINTER_TO_INT (key); + GHashTable *location = value; + + tp_contact_factory_update_location (tp_factory, + handle, + location); + } + + g_hash_table_unref (locations); +} + static void tp_contact_factory_capabilities_changed_cb (TpConnection *connection, const GPtrArray *capabilities, @@ -548,6 +592,7 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory, GArray handles = {(gchar*) &handle, 1}; GHashTable *tokens; GPtrArray *capabilities; + GHashTable *locations; GError *error = NULL; /* Keep a weak ref to that contact */ @@ -595,6 +640,14 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory, &error, NULL); tp_contact_factory_got_capabilities (tp_factory, capabilities, error); + + emp_cli_connection_interface_location_run_get_locations (TP_PROXY (priv->connection), + -1, + &handles, + &locations, + &error, + NULL); + tp_contact_factory_got_locations (tp_factory, locations, error); g_clear_error (&error); DEBUG ("Contact added: %s (%d)", -- cgit v1.2.3