diff options
author | Alexander Larsson <alexl@redhat.com> | 2013-02-14 13:32:30 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2013-02-14 22:10:09 +0100 |
commit | 7690846c3f18ff94c4d1213f722cab102cd7506a (patch) | |
tree | 296254a97a0e69d88d09f36a73aa2a10ccc63ca9 /tests/testicontheme.c | |
parent | e2d0846386ed65efce5018e09a5196005dbedf16 (diff) | |
download | gtk+-7690846c3f18ff94c4d1213f722cab102cd7506a.tar.gz |
Add gtk_icon_info_load_icon_async
This lets you asynchronously load icons. We need this for gnome-shell
to replace its current non-threadsafe use of GtkIconTheme.
https://bugzilla.gnome.org/show_bug.cgi?id=693802
Diffstat (limited to 'tests/testicontheme.c')
-rw-r--r-- | tests/testicontheme.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/testicontheme.c b/tests/testicontheme.c index ad9a459e05..bc0ee6959f 100644 --- a/tests/testicontheme.c +++ b/tests/testicontheme.c @@ -34,6 +34,28 @@ usage (void) ); } +static void +icon_loaded_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GdkPixbuf *pixbuf; + GError *error; + + error = NULL; + pixbuf = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object), + res, &error); + + if (pixbuf == NULL) + { + g_print ("%s\n", error->message); + exit (1); + } + + gtk_image_set_from_pixbuf (GTK_IMAGE (user_data), pixbuf); + g_object_unref (pixbuf); +} + int main (int argc, char *argv[]) @@ -103,6 +125,45 @@ main (int argc, char *argv[]) gtk_main (); } + else if (strcmp (argv[1], "display-async") == 0) + { + GtkWidget *window, *image; + GtkIconSize size; + GtkIconInfo *info; + + if (argc < 4) + { + g_object_unref (icon_theme); + usage (); + return 1; + } + + if (argc >= 5) + size = atoi (argv[4]); + else + size = GTK_ICON_SIZE_BUTTON; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + image = gtk_image_new (); + gtk_container_add (GTK_CONTAINER (window), image); + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_main_quit), window); + gtk_widget_show_all (window); + + info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, + GTK_ICON_LOOKUP_USE_BUILTIN); + + if (info == NULL) + { + g_print ("Icon not found\n"); + return 1; + } + + gtk_icon_info_load_icon_async (info, + NULL, icon_loaded_cb, image); + + gtk_main (); + } else if (strcmp (argv[1], "list") == 0) { if (argc >= 4) |