2 * Copyright (C) 2002, 2003 Red Hat, Inc.
3 * Authors: Alexander Larsson, Owen Taylor
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
27 g_print ("usage: test-icon-theme lookup <theme name> <icon name> [size]]\n"
29 "usage: test-icon-theme list <theme name> [context]\n"
31 "usage: test-icon-theme display <theme name> <icon name> [size]\n"
33 "usage: test-icon-theme contexts <theme name>\n"
38 icon_loaded_cb (GObject *source_object,
46 pixbuf = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object),
51 g_print ("%s\n", error->message);
55 gtk_image_set_from_pixbuf (GTK_IMAGE (user_data), pixbuf);
56 g_object_unref (pixbuf);
61 main (int argc, char *argv[])
63 GtkIconTheme *icon_theme;
64 GtkIconInfo *icon_info;
65 GdkRectangle embedded_rect;
66 GdkPoint *attach_points;
68 const gchar *display_name;
75 gtk_init (&argc, &argv);
85 icon_theme = gtk_icon_theme_new ();
87 gtk_icon_theme_set_custom_theme (icon_theme, themename);
89 if (strcmp (argv[1], "display") == 0)
93 GtkWidget *window, *image;
98 g_object_unref (icon_theme);
104 size = atoi (argv[4]);
106 size = GTK_ICON_SIZE_BUTTON;
109 pixbuf = gtk_icon_theme_load_icon (icon_theme, argv[3], size,
110 GTK_ICON_LOOKUP_USE_BUILTIN, &error);
113 g_print ("%s\n", error->message);
117 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
118 image = gtk_image_new ();
119 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
120 g_object_unref (pixbuf);
121 gtk_container_add (GTK_CONTAINER (window), image);
122 g_signal_connect (window, "delete-event",
123 G_CALLBACK (gtk_main_quit), window);
124 gtk_widget_show_all (window);
128 else if (strcmp (argv[1], "display-async") == 0)
130 GtkWidget *window, *image;
136 g_object_unref (icon_theme);
142 size = atoi (argv[4]);
144 size = GTK_ICON_SIZE_BUTTON;
146 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
147 image = gtk_image_new ();
148 gtk_container_add (GTK_CONTAINER (window), image);
149 g_signal_connect (window, "delete-event",
150 G_CALLBACK (gtk_main_quit), window);
151 gtk_widget_show_all (window);
153 info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size,
154 GTK_ICON_LOOKUP_USE_BUILTIN);
158 g_print ("Icon not found\n");
162 gtk_icon_info_load_icon_async (info,
163 NULL, icon_loaded_cb, image);
167 else if (strcmp (argv[1], "list") == 0)
174 list = gtk_icon_theme_list_icons (icon_theme,
179 g_print ("%s\n", (char *)list->data);
183 else if (strcmp (argv[1], "contexts") == 0)
185 list = gtk_icon_theme_list_contexts (icon_theme);
189 g_print ("%s\n", (char *)list->data);
193 else if (strcmp (argv[1], "lookup") == 0)
197 g_object_unref (icon_theme);
203 size = atoi (argv[4]);
205 icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, GTK_ICON_LOOKUP_USE_BUILTIN);
206 g_print ("icon for %s at %dx%d is %s\n", argv[3], size, size,
207 icon_info ? (gtk_icon_info_get_builtin_pixbuf (icon_info) ? "<builtin>" : gtk_icon_info_get_filename (icon_info)) : "<none>");
211 if (gtk_icon_info_get_embedded_rect (icon_info, &embedded_rect))
213 g_print ("Embedded rect: %d,%d %dx%d\n",
214 embedded_rect.x, embedded_rect.y,
215 embedded_rect.width, embedded_rect.height);
218 if (gtk_icon_info_get_attach_points (icon_info, &attach_points, &n_attach_points))
220 g_print ("Attach Points: ");
221 for (i = 0; i < n_attach_points; i++)
225 g_free (attach_points);
229 display_name = gtk_icon_info_get_display_name (icon_info);
232 g_print ("Display name: %s\n", display_name);
234 g_object_unref (icon_info);
239 g_object_unref (icon_theme);
245 g_object_unref (icon_theme);