Updated Spanish translation
[anjuta-git-plugin.git] / libanjuta / resources.c
blob1054605c717f3316a8128adb849bdb8b4dd2274a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * resources.h
4 * Copyright (C) Naba Kumar <naba@gnome.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /**
22 * SECTION:resources
23 * @title: Program resources
24 * @short_description: Application resource management
25 * @see_also:
26 * @stability: Unstable
27 * @include: libanjuta/resources.h
31 #ifdef HAVE_CONFIG_H
32 # include <config.h>
33 #endif
35 #include <gnome.h>
37 #include <libanjuta/resources.h>
39 GtkWidget *
40 anjuta_res_lookup_widget (GtkWidget * widget, const gchar * widget_name)
42 GtkWidget *parent, *found_widget;
44 for (;;)
46 if (GTK_IS_MENU (widget))
47 parent =
48 gtk_menu_get_attach_widget (GTK_MENU
49 (widget));
50 else
51 parent = widget->parent;
52 if (parent == NULL)
53 break;
54 widget = parent;
57 found_widget = (GtkWidget *) g_object_get_data (G_OBJECT (widget),
58 widget_name);
59 if (!found_widget)
60 g_warning (_("Widget not found: %s"), widget_name);
61 return found_widget;
64 GtkWidget *
65 anjuta_res_get_image (const gchar * pixfile)
67 GtkWidget *pixmap;
68 gchar *pathname;
70 if (!pixfile || !pixfile[0])
71 return gtk_image_new ();
73 pathname = anjuta_res_get_pixmap_file (pixfile);
74 if (!pathname)
76 g_warning (_("Could not find application pixmap file: %s"),
77 pixfile);
78 return gtk_image_new ();
80 pixmap = gtk_image_new_from_file (pathname);
81 g_free (pathname);
82 return pixmap;
85 GtkWidget *
86 anjuta_res_get_image_sized (const gchar * pixfile, gint width, gint height)
88 GtkWidget *pixmap;
89 GdkPixbuf *pixbuf;
90 gchar *pathname;
92 if (!pixfile || !pixfile[0])
93 return gtk_image_new ();
95 pathname = anjuta_res_get_pixmap_file (pixfile);
96 if (!pathname)
98 g_warning (_("Could not find application pixmap file: %s"),
99 pixfile);
100 return gtk_image_new ();
102 pixbuf = gdk_pixbuf_new_from_file_at_size (pathname, width, height, NULL);
103 pixmap = gtk_image_new_from_pixbuf (pixbuf);
104 gdk_pixbuf_unref (pixbuf);
105 g_free (pathname);
106 return pixmap;
109 /* All the return strings MUST be freed */
110 gchar *
111 anjuta_res_get_pixmap_dir ()
113 gchar* path;
114 path = g_strdup (PACKAGE_PIXMAPS_DIR);
115 if (g_file_test (path, G_FILE_TEST_IS_DIR))
116 return path;
117 g_free (path);
118 return NULL;
121 gchar *
122 anjuta_res_get_data_dir ()
124 gchar* path;
125 path = g_strdup (PACKAGE_DATA_DIR);
126 if (g_file_test (path, G_FILE_TEST_IS_DIR))
127 return path;
128 g_free (path);
129 return NULL;
132 gchar *
133 anjuta_res_get_help_dir ()
135 gchar* path;
136 path = g_strdup (PACKAGE_HELP_DIR);
137 if (g_file_test (path, G_FILE_TEST_IS_DIR))
138 return path;
139 g_free (path);
140 return NULL;
143 gchar *
144 anjuta_res_get_help_dir_locale (const gchar * locale)
146 gchar* path;
147 if (locale)
148 path = g_strconcat (PACKAGE_HELP_DIR, "/", locale, NULL);
149 else
150 path = g_strdup (PACKAGE_HELP_DIR);
151 if (g_file_test (path, G_FILE_TEST_IS_DIR))
152 return path;
153 g_free (path);
154 return NULL;
157 gchar *
158 anjuta_res_get_doc_dir ()
160 gchar* path;
161 path = g_strdup (PACKAGE_DOC_DIR);
162 if (g_file_test (path, G_FILE_TEST_IS_DIR))
163 return path;
164 g_free (path);
165 return NULL;
168 /* All the return strings MUST be freed */
169 gchar *
170 anjuta_res_get_pixmap_file (const gchar * pixfile)
172 gchar* path;
173 g_return_val_if_fail (pixfile != NULL, NULL);
174 path = g_strconcat (PACKAGE_PIXMAPS_DIR, "/", pixfile, NULL);
175 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
176 return path;
177 g_warning ("Pixmap file not found: %s", path);
178 g_free (path);
179 return NULL;
182 gchar *
183 anjuta_res_get_data_file (const gchar * datafile)
185 gchar* path;
186 g_return_val_if_fail (datafile != NULL, NULL);
187 path = g_strconcat (PACKAGE_DATA_DIR, "/", datafile, NULL);
188 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
189 return path;
190 g_free (path);
191 return NULL;
194 gchar *
195 anjuta_res_get_help_file (const gchar * helpfile)
197 gchar* path;
198 g_return_val_if_fail (helpfile != NULL, NULL);
199 path = g_strconcat (PACKAGE_HELP_DIR, "/", helpfile, NULL);
200 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
201 return path;
202 g_free (path);
203 return NULL;
206 gchar *
207 anjuta_res_get_help_file_locale (const gchar * helpfile, const gchar * locale)
209 gchar* path;
210 g_return_val_if_fail (helpfile != NULL, NULL);
211 if (locale)
212 path = g_strconcat (PACKAGE_HELP_DIR, "/", locale, "/",
213 helpfile, NULL);
214 else
215 path = g_strconcat (PACKAGE_HELP_DIR, "/", helpfile, NULL);
216 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
217 return path;
218 g_free (path);
219 return NULL;
222 gchar *
223 anjuta_res_get_doc_file (const gchar * docfile)
225 gchar* path;
226 g_return_val_if_fail (docfile != NULL, NULL);
227 path = g_strconcat (PACKAGE_DOC_DIR, "/", docfile, NULL);
228 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
229 return path;
230 g_free (path);
231 return NULL;
234 #if 0
235 /* File type icons 16x16 */
236 GdkPixbuf *
237 anjuta_res_get_icon_for_file (PropsID props, const gchar *filename)
239 gchar *value;
240 GdkPixbuf *pixbuf;
241 gchar *file;
243 g_return_val_if_fail (filename != NULL, NULL);
244 file = g_path_get_basename (filename);
245 value = prop_get_new_expand (props, "icon.", file);
246 if (value == NULL)
247 value = g_strdup ("file_text.png");
248 pixbuf = anjuta_res_get_pixbuf (value);
249 g_free (value);
250 g_free (file);
251 return pixbuf;
253 #endif
255 void
256 anjuta_res_help_search (const gchar * word)
258 if(word)
260 fprintf(stderr, "Word is %s\n", word);
261 if(fork()==0)
263 execlp("devhelp", "devhelp", "-s", word, NULL);
264 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
265 _exit(1);
268 else
270 if(fork()==0)
272 execlp("devhelp", "devhelp", NULL);
273 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
274 _exit(1);
279 void anjuta_res_url_show (const char *url)
281 GError *error = NULL;
282 gnome_url_show (url, &error);