diff options
Diffstat (limited to 'libempathy/empathy-tp-contact-factory.c')
-rw-r--r-- | libempathy/empathy-tp-contact-factory.c | 109 |
1 files changed, 48 insertions, 61 deletions
diff --git a/libempathy/empathy-tp-contact-factory.c b/libempathy/empathy-tp-contact-factory.c index c990b92f4..dd6b60586 100644 --- a/libempathy/empathy-tp-contact-factory.c +++ b/libempathy/empathy-tp-contact-factory.c @@ -237,60 +237,51 @@ tp_contact_factory_avatar_maybe_update (EmpathyTpContactFactory *tp_factory, return FALSE; } -typedef struct { - EmpathyTpContactFactory *tp_factory; - GArray *handles; -} TokensData; - static void -tp_contact_factory_avatar_tokens_foreach (gpointer key, - gpointer value, - gpointer user_data) -{ - TokensData *data = user_data; - const gchar *token = value; - guint handle = GPOINTER_TO_UINT (key); - - if (!tp_contact_factory_avatar_maybe_update (data->tp_factory, - handle, token)) { - g_array_append_val (data->handles, handle); - } -} - -static void -tp_contact_factory_got_known_avatar_tokens (EmpathyTpContactFactory *tp_factory, - GHashTable *tokens, - const GError *error) +tp_contact_factory_got_known_avatar_tokens (TpConnection *connection, + GHashTable *tokens, + const GError *error, + gpointer user_data, + GObject *weak_object) { + EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object); EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory); - TokensData data; + GArray *handles; + GHashTableIter iter; + gpointer key, value; if (error) { DEBUG ("Error: %s", error->message); return; } - data.tp_factory = tp_factory; - data.handles = g_array_new (FALSE, FALSE, sizeof (guint)); - g_hash_table_foreach (tokens, - tp_contact_factory_avatar_tokens_foreach, - &data); + handles = g_array_new (FALSE, FALSE, sizeof (guint)); + + g_hash_table_iter_init (&iter, tokens); + while (g_hash_table_iter_next (&iter, &key, &value)) { + guint handle = GPOINTER_TO_UINT (key); + const gchar *token = value; + + if (!tp_contact_factory_avatar_maybe_update (tp_factory, + handle, token)) { + g_array_append_val (handles, handle); + } + } DEBUG ("Got %d tokens, need to request %d avatars", - g_hash_table_size (tokens), data.handles->len); + g_hash_table_size (tokens), handles->len); /* Request needed avatars */ - if (data.handles->len > 0) { + if (handles->len > 0) { tp_cli_connection_interface_avatars_call_request_avatars (priv->connection, -1, - data.handles, + handles, tp_contact_factory_request_avatars_cb, NULL, NULL, G_OBJECT (tp_factory)); } - g_array_free (data.handles, TRUE); - g_hash_table_destroy (tokens); + g_array_free (handles, TRUE); } static void @@ -360,12 +351,17 @@ tp_contact_factory_update_capabilities (EmpathyTpContactFactory *tp_factory, } static void -tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory, - GPtrArray *capabilities, - const GError *error) +tp_contact_factory_got_capabilities (TpConnection *connection, + const GPtrArray *capabilities, + const GError *error, + gpointer user_data, + GObject *weak_object) { + EmpathyTpContactFactory *tp_factory; guint i; + tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object); + if (error) { DEBUG ("Error: %s", error->message); /* FIXME Should set the capabilities of the contacts for which this request @@ -391,11 +387,7 @@ tp_contact_factory_got_capabilities (EmpathyTpContactFactory *tp_factory, channel_type, generic, specific); - - g_value_array_free (values); } - - g_ptr_array_free (capabilities, TRUE); } #if HAVE_GEOCLUE @@ -740,9 +732,6 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory, TpHandle self_handle; TpHandle handle; GArray handles = {(gchar *) &handle, 1}; - GHashTable *tokens; - GPtrArray *capabilities; - GError *error = NULL; EmpathyCapabilities caps; /* Keep a weak ref to that contact */ @@ -778,23 +767,21 @@ tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory, empathy_contact_set_is_user (contact, self_handle == handle); /* FIXME: This should be done by TpContact */ - tp_cli_connection_interface_avatars_run_get_known_avatar_tokens (priv->connection, - -1, - &handles, - &tokens, - &error, - NULL); - tp_contact_factory_got_known_avatar_tokens (tp_factory, tokens, error); - g_clear_error (&error); - - tp_cli_connection_interface_capabilities_run_get_capabilities (priv->connection, - -1, - &handles, - &capabilities, - &error, - NULL); - tp_contact_factory_got_capabilities (tp_factory, capabilities, error); - g_clear_error (&error); + if (tp_proxy_has_interface_by_id (priv->connection, + TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) { + tp_cli_connection_interface_avatars_call_get_known_avatar_tokens ( + priv->connection, -1, &handles, + tp_contact_factory_got_known_avatar_tokens, NULL, NULL, + G_OBJECT (tp_factory)); + } + + if (tp_proxy_has_interface_by_id (priv->connection, + TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES)) { + tp_cli_connection_interface_capabilities_call_get_capabilities ( + priv->connection, -1, &handles, + tp_contact_factory_got_capabilities, NULL, NULL, + G_OBJECT (tp_factory)); + } if (tp_proxy_has_interface_by_id (TP_PROXY (priv->connection), TP_IFACE_QUARK_CONNECTION_INTERFACE_LOCATION)) { |