Update FSF address
[lttv.git] / lttv / modules / gui / lttvwindow / lttvwindow / support.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA.
17 */
18
19 /*
20 * DO NOT EDIT THIS FILE - it is generated by Glade.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <stdio.h>
32
33 #include <gtk/gtk.h>
34
35 #include <lttv/compiler.h>
36
37 #include "support.h"
38
39 __EXPORT GtkWidget*
40 lookup_widget (GtkWidget *widget,
41 const gchar *widget_name)
42 {
43 GtkWidget *parent, *found_widget;
44
45 for (;;)
46 {
47 if (GTK_IS_MENU (widget))
48 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
49 else
50 parent = widget->parent;
51 if (!parent)
52 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
53 if (parent == NULL)
54 break;
55 widget = parent;
56 }
57
58 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
59 widget_name);
60 if (!found_widget)
61 g_warning ("Widget not found: %s", widget_name);
62 return found_widget;
63 }
64
65 static GList *pixmaps_directories = NULL;
66
67 /* Use this function to set the directory containing installed pixmaps. */
68 void
69 add_pixmap_directory (const gchar *directory)
70 {
71 pixmaps_directories = g_list_prepend (pixmaps_directories,
72 g_strdup (directory));
73 }
74
75 /* This is an internally used function to find pixmap files. */
76 static gchar*
77 find_pixmap_file (const gchar *filename)
78 {
79 GList *elem;
80
81 /* We step through each of the pixmaps directory to find it. */
82 elem = pixmaps_directories;
83 while (elem)
84 {
85 gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
86 G_DIR_SEPARATOR_S, filename);
87 if (g_file_test (pathname, G_FILE_TEST_EXISTS))
88 return pathname;
89 g_free (pathname);
90 elem = elem->next;
91 }
92 return NULL;
93 }
94
95 /* This is an internally used function to create pixmaps. */
96 __EXPORT GtkWidget*
97 create_pixmap (GtkWidget *widget,
98 const gchar *filename)
99 {
100 gchar *pathname = NULL;
101 GtkWidget *pixmap;
102
103 if (!filename || !filename[0])
104 return gtk_image_new ();
105
106 pathname = find_pixmap_file (filename);
107
108 if (!pathname)
109 {
110 g_warning ("Couldn't find pixmap file: %s", filename);
111 return gtk_image_new ();
112 }
113
114 pixmap = gtk_image_new_from_file (pathname);
115 g_free (pathname);
116 return pixmap;
117 }
118
119 /* This is an internally used function to create pixmaps. */
120 GdkPixbuf*
121 create_pixbuf (const gchar *filename)
122 {
123 gchar *pathname = NULL;
124 GdkPixbuf *pixbuf;
125 GError *error = NULL;
126
127 if (!filename || !filename[0])
128 return NULL;
129
130 pathname = find_pixmap_file (filename);
131
132 if (!pathname)
133 {
134 g_warning ("Couldn't find pixmap file: %s", filename);
135 return NULL;
136 }
137
138 pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
139 if (!pixbuf)
140 {
141 fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
142 pathname, error->message);
143 g_error_free (error);
144 }
145 g_free (pathname);
146 return pixbuf;
147 }
148
149 /* This is used to set ATK action descriptions. */
150 void
151 glade_set_atk_action_description (AtkAction *action,
152 const gchar *action_name,
153 const gchar *description)
154 {
155 gint n_actions, i;
156
157 n_actions = atk_action_get_n_actions (action);
158 for (i = 0; i < n_actions; i++)
159 {
160 if (!strcmp (atk_action_get_name (action, i), action_name))
161 atk_action_set_description (action, i, description);
162 }
163 }
164
This page took 0.031973 seconds and 4 git commands to generate.