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"
39 main (int argc, char *argv[])
41 GtkIconTheme *icon_theme;
42 GtkIconInfo *icon_info;
43 GdkRectangle embedded_rect;
44 GdkPoint *attach_points;
46 const gchar *display_name;
53 gtk_init (&argc, &argv);
63 icon_theme = gtk_icon_theme_new ();
65 gtk_icon_theme_set_custom_theme (icon_theme, themename);
67 if (strcmp (argv[1], "display") == 0)
71 GtkWidget *window, *image;
76 g_object_unref (icon_theme);
82 size = atoi (argv[4]);
84 size = GTK_ICON_SIZE_BUTTON;
87 pixbuf = gtk_icon_theme_load_icon (icon_theme, argv[3], size,
88 GTK_ICON_LOOKUP_USE_BUILTIN, &error);
91 g_print ("%s\n", error->message);
95 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
96 image = gtk_image_new ();
97 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
98 g_object_unref (pixbuf);
99 gtk_container_add (GTK_CONTAINER (window), image);
100 g_signal_connect (window, "delete-event",
101 G_CALLBACK (gtk_main_quit), window);
102 gtk_widget_show_all (window);
106 else if (strcmp (argv[1], "list") == 0)
113 list = gtk_icon_theme_list_icons (icon_theme,
118 g_print ("%s\n", (char *)list->data);
122 else if (strcmp (argv[1], "contexts") == 0)
124 list = gtk_icon_theme_list_contexts (icon_theme);
128 g_print ("%s\n", (char *)list->data);
132 else if (strcmp (argv[1], "lookup") == 0)
136 g_object_unref (icon_theme);
142 size = atoi (argv[4]);
144 icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, GTK_ICON_LOOKUP_USE_BUILTIN);
145 g_print ("icon for %s at %dx%d is %s\n", argv[3], size, size,
146 icon_info ? (gtk_icon_info_get_builtin_pixbuf (icon_info) ? "<builtin>" : gtk_icon_info_get_filename (icon_info)) : "<none>");
150 if (gtk_icon_info_get_embedded_rect (icon_info, &embedded_rect))
152 g_print ("Embedded rect: %d,%d %dx%d\n",
153 embedded_rect.x, embedded_rect.y,
154 embedded_rect.width, embedded_rect.height);
157 if (gtk_icon_info_get_attach_points (icon_info, &attach_points, &n_attach_points))
159 g_print ("Attach Points: ");
160 for (i = 0; i < n_attach_points; i++)
164 g_free (attach_points);
168 display_name = gtk_icon_info_get_display_name (icon_info);
171 g_print ("Display name: %s\n", display_name);
173 gtk_icon_info_free (icon_info);
178 g_object_unref (icon_theme);
184 g_object_unref (icon_theme);