testicontheme.c 2.33 KB
Newer Older
1
#include <config.h>
2
3
4
#include <gtk/gtkicontheme.h>
#include <stdlib.h>
#include <string.h>
5
#include <locale.h>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

static void
usage (void)
{
  g_print ("usage: test-icon-theme lookup <theme name> <icon name> [size]]\n"
	   " or\n"
	   "usage: test-icon-theme list <theme name> [context]\n");
}


int
main (int argc, char *argv[])
{
  GtkIconTheme *icon_theme;
  GtkIconInfo *icon_info;
  GdkRectangle embedded_rect;
  GdkPoint *attach_points;
  int n_attach_points;
  const gchar *display_name;
  char *context;
  char *themename;
  GList *list;
  int size = 48;
  int i;
  
  g_type_init ();
32
  setlocale (LC_ALL, "");
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

  if (argc < 3)
    {
      usage ();
      return 1;
    }

  themename = argv[2];
  
  icon_theme = gtk_icon_theme_new ();
  
  gtk_icon_theme_set_custom_theme (icon_theme, themename);

  if (strcmp (argv[1], "list") == 0)
    {
      if (argc >= 4)
	context = argv[3];
      else
	context = NULL;

      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], "lookup") == 0)
    {
      if (argc < 4)
	{
	  g_object_unref (icon_theme);
	  usage ();
	  return 1;
	}
      
      if (argc >= 5)
	size = atoi (argv[4]);
      
      icon_info = gtk_icon_theme_lookup_icon (icon_theme, argv[3], size, 0);
      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>");

78
      if (icon_info) 
79
	{
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	  if (gtk_icon_info_get_embedded_rect (icon_info, &embedded_rect))
	    {
	      g_print ("Embedded rect: %d,%d %dx%d\n",
		       embedded_rect.x, embedded_rect.y,
		       embedded_rect.width, embedded_rect.height);
	    }
	  
	  if (gtk_icon_info_get_attach_points (icon_info, &attach_points, &n_attach_points))
	    {
	      g_print ("Attach Points: ");
	      for (i = 0; i < n_attach_points; i++)
		g_print ("%d, %d; ",
			 attach_points[i].x,
			 attach_points[i].y);
	      g_free (attach_points);
	      g_print ("\n");
	    }
	  
	  display_name = gtk_icon_info_get_display_name (icon_info);
	  
	  if (display_name)
	    g_print ("Display name: %s\n", display_name);
	  
	  gtk_icon_info_free (icon_info);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	}
    }
  else
    {
      g_object_unref (icon_theme);
      usage ();
      return 1;
    }
 

  g_object_unref (icon_theme);
  
  return 0;
}