Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / libanjuta / resources.c
blob6d6a29120cf8c135b6df213e361fc909c253d47d
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 <unistd.h>
36 #include <glib/gi18n.h>
37 #include <gtk/gtk.h>
39 #include <libanjuta/anjuta-utils.h>
40 #include <libanjuta/resources.h>
42 GtkWidget *
43 anjuta_res_lookup_widget (GtkWidget * widget, const gchar * widget_name)
45 GtkWidget *parent, *found_widget;
47 for (;;)
49 if (GTK_IS_MENU (widget))
50 parent =
51 gtk_menu_get_attach_widget (GTK_MENU
52 (widget));
53 else
54 parent = widget->parent;
55 if (parent == NULL)
56 break;
57 widget = parent;
60 found_widget = (GtkWidget *) g_object_get_data (G_OBJECT (widget),
61 widget_name);
62 if (!found_widget)
63 g_warning (_("Widget not found: %s"), widget_name);
64 return found_widget;
67 GtkWidget *
68 anjuta_res_get_image (const gchar * pixfile)
70 GtkWidget *pixmap;
71 gchar *pathname;
73 if (!pixfile || !pixfile[0])
74 return gtk_image_new ();
76 pathname = anjuta_res_get_pixmap_file (pixfile);
77 if (!pathname)
79 g_warning (_("Could not find application pixmap file: %s"),
80 pixfile);
81 return gtk_image_new ();
83 pixmap = gtk_image_new_from_file (pathname);
84 g_free (pathname);
85 return pixmap;
88 GtkWidget *
89 anjuta_res_get_image_sized (const gchar * pixfile, gint width, gint height)
91 GtkWidget *pixmap;
92 GdkPixbuf *pixbuf;
93 gchar *pathname;
95 if (!pixfile || !pixfile[0])
96 return gtk_image_new ();
98 pathname = anjuta_res_get_pixmap_file (pixfile);
99 if (!pathname)
101 g_warning (_("Could not find application pixmap file: %s"),
102 pixfile);
103 return gtk_image_new ();
105 pixbuf = gdk_pixbuf_new_from_file_at_size (pathname, width, height, NULL);
106 pixmap = gtk_image_new_from_pixbuf (pixbuf);
107 gdk_pixbuf_unref (pixbuf);
108 g_free (pathname);
109 return pixmap;
112 /* All the return strings MUST be freed */
113 gchar *
114 anjuta_res_get_pixmap_dir ()
116 gchar* path;
117 path = g_strdup (PACKAGE_PIXMAPS_DIR);
118 if (g_file_test (path, G_FILE_TEST_IS_DIR))
119 return path;
120 g_free (path);
121 return NULL;
124 gchar *
125 anjuta_res_get_data_dir ()
127 gchar* path;
128 path = g_strdup (PACKAGE_DATA_DIR);
129 if (g_file_test (path, G_FILE_TEST_IS_DIR))
130 return path;
131 g_free (path);
132 return NULL;
135 gchar *
136 anjuta_res_get_help_dir ()
138 gchar* path;
139 path = g_strdup (PACKAGE_HELP_DIR);
140 if (g_file_test (path, G_FILE_TEST_IS_DIR))
141 return path;
142 g_free (path);
143 return NULL;
146 gchar *
147 anjuta_res_get_help_dir_locale (const gchar * locale)
149 gchar* path;
150 if (locale)
151 path = g_strconcat (PACKAGE_HELP_DIR, "/", locale, NULL);
152 else
153 path = g_strdup (PACKAGE_HELP_DIR);
154 if (g_file_test (path, G_FILE_TEST_IS_DIR))
155 return path;
156 g_free (path);
157 return NULL;
160 gchar *
161 anjuta_res_get_doc_dir ()
163 gchar* path;
164 path = g_strdup (PACKAGE_DOC_DIR);
165 if (g_file_test (path, G_FILE_TEST_IS_DIR))
166 return path;
167 g_free (path);
168 return NULL;
171 /* All the return strings MUST be freed */
172 gchar *
173 anjuta_res_get_pixmap_file (const gchar * pixfile)
175 gchar* path;
176 g_return_val_if_fail (pixfile != NULL, NULL);
177 path = g_strconcat (PACKAGE_PIXMAPS_DIR, "/", pixfile, NULL);
178 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
179 return path;
180 g_warning ("Pixmap file not found: %s", path);
181 g_free (path);
182 return NULL;
185 gchar *
186 anjuta_res_get_data_file (const gchar * datafile)
188 gchar* path;
189 g_return_val_if_fail (datafile != NULL, NULL);
190 path = g_strconcat (PACKAGE_DATA_DIR, "/", datafile, NULL);
191 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
192 return path;
193 g_free (path);
194 return NULL;
197 gchar *
198 anjuta_res_get_help_file (const gchar * helpfile)
200 gchar* path;
201 g_return_val_if_fail (helpfile != NULL, NULL);
202 path = g_strconcat (PACKAGE_HELP_DIR, "/", helpfile, NULL);
203 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
204 return path;
205 g_free (path);
206 return NULL;
209 gchar *
210 anjuta_res_get_help_file_locale (const gchar * helpfile, const gchar * locale)
212 gchar* path;
213 g_return_val_if_fail (helpfile != NULL, NULL);
214 if (locale)
215 path = g_strconcat (PACKAGE_HELP_DIR, "/", locale, "/",
216 helpfile, NULL);
217 else
218 path = g_strconcat (PACKAGE_HELP_DIR, "/", helpfile, NULL);
219 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
220 return path;
221 g_free (path);
222 return NULL;
225 gchar *
226 anjuta_res_get_doc_file (const gchar * docfile)
228 gchar* path;
229 g_return_val_if_fail (docfile != NULL, NULL);
230 path = g_strconcat (PACKAGE_DOC_DIR, "/", docfile, NULL);
231 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
232 return path;
233 g_free (path);
234 return NULL;
237 #if 0
238 /* File type icons 16x16 */
239 GdkPixbuf *
240 anjuta_res_get_icon_for_file (PropsID props, const gchar *filename)
242 gchar *value;
243 GdkPixbuf *pixbuf;
244 gchar *file;
246 g_return_val_if_fail (filename != NULL, NULL);
247 file = g_path_get_basename (filename);
248 value = prop_get_new_expand (props, "icon.", file);
249 if (value == NULL)
250 value = g_strdup ("file_text.png");
251 pixbuf = anjuta_res_get_pixbuf (value);
252 g_free (value);
253 g_free (file);
254 return pixbuf;
256 #endif
258 void
259 anjuta_res_help_search (const gchar * word)
261 if(word)
263 fprintf(stderr, "Word is %s\n", word);
264 if(fork()==0)
266 execlp("devhelp", "devhelp", "-s", word, NULL);
267 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
268 _exit(1);
271 else
273 if(fork()==0)
275 execlp("devhelp", "devhelp", NULL);
276 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
277 _exit(1);
282 void
283 anjuta_res_url_show (const gchar *url)
285 gchar *open[3];
287 if (!anjuta_util_prog_is_installed ("xdg-open", TRUE))
288 return;
290 open[0] = "xdg-open";
291 open[1] = (gchar *)url;
292 open[2] = NULL;
294 gdk_spawn_on_screen (gdk_screen_get_default (), NULL, open, NULL,
295 G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);