diff options
author | Travis Reitter <treitter@gmail.com> | 2010-07-09 02:01:02 +0800 |
---|---|---|
committer | Travis Reitter <treitter@gmail.com> | 2010-07-21 07:12:36 +0800 |
commit | ebea339331d9c7a8eb69c125bd261ab60b3781eb (patch) | |
tree | ef2d14e34193dfcc16882d19f13f9486bd56043d | |
parent | c922fe784e177fa328f987e0a8cd84b0de10f019 (diff) | |
download | gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar.gz gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar.bz2 gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar.lz gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar.xz gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.tar.zst gsoc2013-empathy-ebea339331d9c7a8eb69c125bd261ab60b3781eb.zip |
Use the gio async pattern for fetching Individuals' avatars
-rw-r--r-- | libempathy-gtk/empathy-individual-store.c | 37 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.c | 80 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.h | 14 |
3 files changed, 92 insertions, 39 deletions
diff --git a/libempathy-gtk/empathy-individual-store.c b/libempathy-gtk/empathy-individual-store.c index 4a3b68653..e97b94e88 100644 --- a/libempathy-gtk/empathy-individual-store.c +++ b/libempathy-gtk/empathy-individual-store.c @@ -524,20 +524,36 @@ individual_store_contact_active_cb (ShowActiveData *data) } static void -individual_avatar_pixbuf_received_cb (FolksIndividual *individual, - GdkPixbuf *pixbuf, +individual_avatar_pixbuf_received_cb (GObject *object, + GAsyncResult *result, gpointer user_data) { + FolksIndividual *individual = FOLKS_INDIVIDUAL (object); EmpathyIndividualStore *self = user_data; - GList *iters, *l; + GError *error = NULL; + GdkPixbuf *pixbuf; - iters = individual_store_find_contact (self, individual); + pixbuf = empathy_pixbuf_avatar_from_individual_scaled_finish (individual, + result, &error); - for (l = iters; l; l = l->next) + if (error != NULL) { - gtk_tree_store_set (GTK_TREE_STORE (self), l->data, - EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf, - -1); + DEBUG ("failed to retrieve pixbuf for individual %s: %s", + folks_individual_get_alias (individual), + error->message); + g_clear_error (&error); + } + else + { + GList *iters, *l; + + iters = individual_store_find_contact (self, individual); + for (l = iters; l; l = l->next) + { + gtk_tree_store_set (GTK_TREE_STORE (self), l->data, + EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, pixbuf, + -1); + } } } @@ -671,8 +687,9 @@ individual_store_contact_update (EmpathyIndividualStore *self, show_avatar = TRUE; } - empathy_pixbuf_avatar_from_individual_scaled_async (individual, 32, 32, - individual_avatar_pixbuf_received_cb, self); + empathy_pixbuf_avatar_from_individual_scaled_async (individual, + individual_avatar_pixbuf_received_cb, 32, 32, self); + pixbuf_status = empathy_individual_store_get_individual_status_icon (self, individual); diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index fe363bc75..f2a1b00ac 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -522,27 +522,25 @@ empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact, typedef struct { FolksIndividual *individual; - EmpathyPixbufAvatarFromIndividualCb callback; - gpointer user_data; + GSimpleAsyncResult *result; guint width; guint height; } PixbufAvatarFromIndividualClosure; static PixbufAvatarFromIndividualClosure * -pixbuf_avatar_from_individual_closure_new (FolksIndividual *individual, - gint width, - gint height, - EmpathyPixbufAvatarFromIndividualCb callback, - gpointer user_data) +pixbuf_avatar_from_individual_closure_new (FolksIndividual *individual, + GSimpleAsyncResult *result, + gint width, + gint height) { PixbufAvatarFromIndividualClosure *closure; g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL); + g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL); closure = g_new0 (PixbufAvatarFromIndividualClosure, 1); closure->individual = g_object_ref (individual); - closure->callback = callback; - closure->user_data = user_data; + closure->result = g_object_ref (result); closure->width = width; closure->height = height; @@ -554,6 +552,7 @@ pixbuf_avatar_from_individual_closure_free ( PixbufAvatarFromIndividualClosure *closure) { g_object_unref (closure->individual); + g_object_unref (closure->result); g_free (closure); } @@ -569,12 +568,12 @@ avatar_file_load_contents_cb (GObject *object, struct SizeData size_data; GError *error = NULL; GdkPixbufLoader *loader = NULL; - GdkPixbuf *pixbuf = NULL; if (!g_file_load_contents_finish (file, result, &data, &data_size, NULL, &error)) { DEBUG ("failed to load avatar from file: %s", error->message); + g_simple_async_result_set_from_error (closure->result, error); goto out; } @@ -592,19 +591,22 @@ avatar_file_load_contents_cb (GObject *object, &error)) { DEBUG ("Failed to write to pixbuf loader: %s", error ? error->message : "No error given"); + g_simple_async_result_set_from_error (closure->result, error); goto out; } if (!gdk_pixbuf_loader_close (loader, &error)) { DEBUG ("Failed to close pixbuf loader: %s", error ? error->message : "No error given"); + g_simple_async_result_set_from_error (closure->result, error); goto out; } - pixbuf = avatar_pixbuf_from_loader (loader); - - closure->callback (closure->individual, pixbuf, closure->user_data); + g_simple_async_result_set_op_res_gpointer (closure->result, + avatar_pixbuf_from_loader (loader), NULL); out: + g_simple_async_result_complete (closure->result); + g_clear_error (&error); g_free (data); tp_clear_object (&loader); @@ -613,33 +615,63 @@ out: void empathy_pixbuf_avatar_from_individual_scaled_async ( - FolksIndividual *individual, - gint width, - gint height, - EmpathyPixbufAvatarFromIndividualCb callback, - gpointer user_data) + FolksIndividual *individual, + GAsyncReadyCallback callback, + gint width, + gint height, + gpointer user_data) { GFile *avatar_file; + GSimpleAsyncResult *result; PixbufAvatarFromIndividualClosure *closure; + result = g_simple_async_result_new (G_OBJECT (individual), + callback, user_data, + empathy_pixbuf_avatar_from_individual_scaled_finish); + avatar_file = folks_avatar_get_avatar (FOLKS_AVATAR (individual)); - if (avatar_file == NULL) { + if (avatar_file == NULL) goto out; - } - closure = pixbuf_avatar_from_individual_closure_new (individual, width, - height, callback, - user_data); + closure = pixbuf_avatar_from_individual_closure_new (individual, result, + width, height); if (closure == NULL) goto out; g_file_load_contents_async (avatar_file, NULL, avatar_file_load_contents_cb, closure); + g_object_unref (result); + return; out: - callback (individual, NULL, user_data); + g_simple_async_result_set_op_res_gpointer (result, NULL, NULL); + g_simple_async_result_complete (result); + g_object_unref (result); +} + +GdkPixbuf * +empathy_pixbuf_avatar_from_individual_scaled_finish ( + FolksIndividual *individual, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result); + gboolean result_valid; + + g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (simple), NULL); + + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + + result_valid = g_simple_async_result_is_valid (result, + G_OBJECT (individual), + empathy_pixbuf_avatar_from_individual_scaled_finish); + g_return_val_if_fail (result_valid, NULL); + + return g_simple_async_result_get_op_res_gpointer (simple); } GdkPixbuf * diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 3e9a8434e..87c17b333 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -76,11 +76,15 @@ GdkPixbuf * empathy_pixbuf_from_data (gchar *data, GdkPixbuf * empathy_pixbuf_from_data_and_mime (gchar *data, gsize data_size, gchar **mime_type); -void empathy_pixbuf_avatar_from_individual_scaled_async (FolksIndividual *individual, - gint width, - gint height, - EmpathyPixbufAvatarFromIndividualCb callback, - gpointer user_data); +void empathy_pixbuf_avatar_from_individual_scaled_async (FolksIndividual *individual, + GAsyncReadyCallback callback, + gint width, + gint height, + gpointer user_data); +GdkPixbuf * empathy_pixbuf_avatar_from_individual_scaled_finish ( + FolksIndividual *individual, + GAsyncResult *result, + GError **error); GdkPixbuf * empathy_pixbuf_from_avatar_scaled (EmpathyAvatar *avatar, gint width, gint height); |