+/* testicontheme.c
+ * Copyright (C) 2002, 2003 Red Hat, Inc.
+ * Authors: Alexander Larsson, Owen Taylor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
"usage: test-icon-theme list <theme name> [context]\n"
" or\n"
"usage: test-icon-theme display <theme name> <icon name> [size]\n"
+ " or\n"
+ "usage: test-icon-theme contexts <theme name>\n"
);
}
+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[])
if (strcmp (argv[1], "display") == 0)
{
+ GError *error;
+ GdkPixbuf *pixbuf;
GtkWidget *window, *image;
GtkIconSize size;
- GdkPixbuf *pixbuf;
if (argc < 4)
{
size = atoi (argv[4]);
else
size = GTK_ICON_SIZE_BUTTON;
-
+
+ error = NULL;
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, argv[3], size,
+ GTK_ICON_LOOKUP_USE_BUILTIN, &error);
+ if (!pixbuf)
+ {
+ g_print ("%s\n", error->message);
+ return 1;
+ }
+
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-#if 1
- pixbuf = gtk_icon_theme_load_icon (icon_theme, argv[3], size, 0, NULL);
- image = gtk_image_new_from_pixbuf (pixbuf);
-#else
- image = gtk_image_new_from_icon_name (argv[3], size);
-#endif
+ image = gtk_image_new ();
+ gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
+ g_object_unref (pixbuf);
gtk_container_add (GTK_CONTAINER (window), image);
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), window);
gtk_widget_show_all (window);
+ 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)
list = gtk_icon_theme_list_icons (icon_theme,
context);
+ while (list)
+ {
+ g_print ("%s\n", (char *)list->data);
+ list = list->next;
+ }
+ }
+ else if (strcmp (argv[1], "contexts") == 0)
+ {
+ list = gtk_icon_theme_list_contexts (icon_theme);
+
while (list)
{
g_print ("%s\n", (char *)list->data);
if (argc >= 5)
size = atoi (argv[4]);
- icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, 0);
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, GTK_ICON_LOOKUP_USE_BUILTIN);
g_print ("icon for %s at %dx%d is %s\n", argv[3], size, size,
- icon_info ? gtk_icon_info_get_filename (icon_info) : "<none>");
+ icon_info ? (gtk_icon_info_get_builtin_pixbuf (icon_info) ? "<builtin>" : gtk_icon_info_get_filename (icon_info)) : "<none>");
if (icon_info)
{
if (display_name)
g_print ("Display name: %s\n", display_name);
- gtk_icon_info_free (icon_info);
+ g_object_unref (icon_info);
}
}
else