cuikplay_support.c
Go to the documentation of this file.
1 
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <stdio.h>
17 
18 #include <gtk/gtk.h>
19 
20 #include "cuikplay_support.h"
21 
22 GtkWidget* lookup_widget(GtkWidget *widget,
23  const gchar *widget_name)
24 {
25  GtkWidget *parent, *found_widget;
26 
27  for (;;)
28  {
29  if (GTK_IS_MENU (widget))
30  parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
31  else
32  parent = widget->parent;
33  if (!parent)
34  parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
35  if (parent == NULL)
36  break;
37  widget = parent;
38  }
39 
40  found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
41  widget_name);
42  if (!found_widget)
43  g_warning ("Widget not found: %s", widget_name);
44  return found_widget;
45 }
46 
47 static GList *pixmaps_directories = NULL;
48 
49 /* Use this function to set the directory containing installed pixmaps. */
50 void add_pixmap_directory (const gchar *directory)
51 {
52  pixmaps_directories = g_list_prepend (pixmaps_directories,
53  g_strdup (directory));
54 }
55 
56 /* This is an internally used function to find pixmap files. */
57 static gchar* find_pixmap_file (const gchar *filename)
58 {
59  GList *elem;
60 
61  /* We step through each of the pixmaps directory to find it. */
62  elem = pixmaps_directories;
63  while (elem)
64  {
65  gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
66  G_DIR_SEPARATOR_S, filename);
67  if (g_file_test (pathname, G_FILE_TEST_EXISTS))
68  return pathname;
69  g_free (pathname);
70  elem = elem->next;
71  }
72  return NULL;
73 }
74 
75 /* This is an internally used function to create pixmaps. */
76 GtkWidget* create_pixmap (GtkWidget *widget,const gchar *filename)
77 {
78  gchar *pathname = NULL;
79  GtkWidget *pixmap;
80 
81  if (!filename || !filename[0])
82  return gtk_image_new ();
83 
84  pathname = find_pixmap_file (filename);
85 
86  if (!pathname)
87  {
88  g_warning (_("Couldn't find pixmap file: %s"), filename);
89  return gtk_image_new ();
90  }
91 
92  pixmap = gtk_image_new_from_file (pathname);
93  g_free (pathname);
94  return pixmap;
95 }
96 
97 /* This is an internally used function to create pixmaps. */
98 GdkPixbuf* create_pixbuf(const gchar *filename)
99 {
100  gchar *pathname = NULL;
101  GdkPixbuf *pixbuf;
102  GError *error = NULL;
103 
104  if (!filename || !filename[0])
105  return NULL;
106 
107  pathname = find_pixmap_file (filename);
108 
109  if (!pathname)
110  {
111  g_warning (_("Couldn't find pixmap file: %s"), filename);
112  return NULL;
113  }
114 
115  pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
116  if (!pixbuf)
117  {
118  fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
119  pathname, error->message);
120  g_error_free (error);
121  }
122  g_free (pathname);
123  return pixbuf;
124 }
125 
126 /* This is used to set ATK action descriptions. */
127 void glade_set_atk_action_description(AtkAction *action,
128  const gchar *action_name,
129  const gchar *description)
130 {
131  gint n_actions, i;
132 
133  n_actions = atk_action_get_n_actions (action);
134  for (i = 0; i < n_actions; i++)
135  {
136  if (!strcmp (atk_action_get_name (action, i), action_name))
137  atk_action_set_description (action, i, description);
138  }
139 }
140 
Headers of the GTK support functions for cuikplay.