]> Pileus Git - ~andy/gtk/blob - tests/testicontheme.c
Add a test program from gnome-desktop.
[~andy/gtk] / tests / testicontheme.c
1 #include <gtk/gtkicontheme.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 static void
6 usage (void)
7 {
8   g_print ("usage: test-icon-theme lookup <theme name> <icon name> [size]]\n"
9            " or\n"
10            "usage: test-icon-theme list <theme name> [context]\n");
11 }
12
13
14 int
15 main (int argc, char *argv[])
16 {
17   GtkIconTheme *icon_theme;
18   GtkIconInfo *icon_info;
19   GdkRectangle embedded_rect;
20   GdkPoint *attach_points;
21   int n_attach_points;
22   const gchar *display_name;
23   char *context;
24   char *themename;
25   GList *list;
26   int size = 48;
27   int i;
28   
29   g_type_init ();
30
31   if (argc < 3)
32     {
33       usage ();
34       return 1;
35     }
36
37   themename = argv[2];
38   
39   icon_theme = gtk_icon_theme_new ();
40   
41   gtk_icon_theme_set_custom_theme (icon_theme, themename);
42
43   if (strcmp (argv[1], "list") == 0)
44     {
45       if (argc >= 4)
46         context = argv[3];
47       else
48         context = NULL;
49
50       list = gtk_icon_theme_list_icons (icon_theme,
51                                            context);
52       
53       while (list)
54         {
55           g_print ("%s\n", (char *)list->data);
56           list = list->next;
57         }
58     }
59   else if (strcmp (argv[1], "lookup") == 0)
60     {
61       if (argc < 4)
62         {
63           g_object_unref (icon_theme);
64           usage ();
65           return 1;
66         }
67       
68       if (argc >= 5)
69         size = atoi (argv[4]);
70       
71       icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, 0);
72       g_print ("icon for %s at %dx%d is %s\n", argv[3], size, size,
73                icon_info ? gtk_icon_info_get_filename (icon_info) : "<none>");
74
75       if (gtk_icon_info_get_embedded_rect (icon_info, &embedded_rect))
76         {
77           g_print ("Embedded rect: %d,%d %dx%d\n",
78                    embedded_rect.x, embedded_rect.y,
79                    embedded_rect.width, embedded_rect.height);
80         }
81
82       if (gtk_icon_info_get_attach_points (icon_info, &attach_points, &n_attach_points))
83         {
84           g_print ("Attach Points: ");
85           for (i = 0; i < n_attach_points; i++)
86             g_print ("%d, %d; ",
87                      attach_points[i].x,
88                      attach_points[i].y);
89           g_free (attach_points);
90         }
91
92       display_name = gtk_icon_info_get_display_name (icon_info);
93
94       if (display_name)
95         g_print ("Display name: %s\n", display_name);
96       
97       gtk_icon_info_free (icon_info);
98     }
99   else
100     {
101       g_object_unref (icon_theme);
102       usage ();
103       return 1;
104     }
105  
106
107   g_object_unref (icon_theme);
108   
109   return 0;
110 }