1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Naba Kumar <naba@gnome.org>
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
23 * @title: Program resources
24 * @short_description: Application resource management
26 * @stability: Unstable
27 * @include: libanjuta/resources.h
36 #include <glib/gi18n.h>
39 #include <libanjuta/anjuta-utils.h>
40 #include <libanjuta/resources.h>
43 anjuta_res_lookup_widget (GtkWidget
* widget
, const gchar
* widget_name
)
45 GtkWidget
*parent
, *found_widget
;
49 if (GTK_IS_MENU (widget
))
51 gtk_menu_get_attach_widget (GTK_MENU
54 parent
= widget
->parent
;
60 found_widget
= (GtkWidget
*) g_object_get_data (G_OBJECT (widget
),
63 g_warning (_("Widget not found: %s"), widget_name
);
68 anjuta_res_get_image (const gchar
* pixfile
)
73 if (!pixfile
|| !pixfile
[0])
74 return gtk_image_new ();
76 pathname
= anjuta_res_get_pixmap_file (pixfile
);
79 g_warning (_("Could not find application pixmap file: %s"),
81 return gtk_image_new ();
83 pixmap
= gtk_image_new_from_file (pathname
);
89 anjuta_res_get_image_sized (const gchar
* pixfile
, gint width
, gint height
)
95 if (!pixfile
|| !pixfile
[0])
96 return gtk_image_new ();
98 pathname
= anjuta_res_get_pixmap_file (pixfile
);
101 g_warning (_("Could not find application pixmap file: %s"),
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
);
112 /* All the return strings MUST be freed */
114 anjuta_res_get_pixmap_dir ()
117 path
= g_strdup (PACKAGE_PIXMAPS_DIR
);
118 if (g_file_test (path
, G_FILE_TEST_IS_DIR
))
125 anjuta_res_get_data_dir ()
128 path
= g_strdup (PACKAGE_DATA_DIR
);
129 if (g_file_test (path
, G_FILE_TEST_IS_DIR
))
136 anjuta_res_get_help_dir ()
139 path
= g_strdup (PACKAGE_HELP_DIR
);
140 if (g_file_test (path
, G_FILE_TEST_IS_DIR
))
147 anjuta_res_get_help_dir_locale (const gchar
* locale
)
151 path
= g_strconcat (PACKAGE_HELP_DIR
, "/", locale
, NULL
);
153 path
= g_strdup (PACKAGE_HELP_DIR
);
154 if (g_file_test (path
, G_FILE_TEST_IS_DIR
))
161 anjuta_res_get_doc_dir ()
164 path
= g_strdup (PACKAGE_DOC_DIR
);
165 if (g_file_test (path
, G_FILE_TEST_IS_DIR
))
171 /* All the return strings MUST be freed */
173 anjuta_res_get_pixmap_file (const gchar
* pixfile
)
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
))
180 g_warning ("Pixmap file not found: %s", path
);
186 anjuta_res_get_data_file (const gchar
* datafile
)
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
))
198 anjuta_res_get_help_file (const gchar
* helpfile
)
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
))
210 anjuta_res_get_help_file_locale (const gchar
* helpfile
, const gchar
* locale
)
213 g_return_val_if_fail (helpfile
!= NULL
, NULL
);
215 path
= g_strconcat (PACKAGE_HELP_DIR
, "/", locale
, "/",
218 path
= g_strconcat (PACKAGE_HELP_DIR
, "/", helpfile
, NULL
);
219 if (g_file_test (path
, G_FILE_TEST_IS_REGULAR
))
226 anjuta_res_get_doc_file (const gchar
* docfile
)
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
))
238 /* File type icons 16x16 */
240 anjuta_res_get_icon_for_file (PropsID props
, const gchar
*filename
)
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
);
250 value
= g_strdup ("file_text.png");
251 pixbuf
= anjuta_res_get_pixbuf (value
);
259 anjuta_res_help_search (const gchar
* word
)
263 fprintf(stderr
, "Word is %s\n", word
);
266 execlp("devhelp", "devhelp", "-s", word
, NULL
);
267 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
275 execlp("devhelp", "devhelp", NULL
);
276 g_warning (_("Cannot execute command: \"%s\""), "devhelp");
283 anjuta_res_url_show (const gchar
*url
)
287 if (!anjuta_util_prog_is_installed ("xdg-open", TRUE
))
290 open
[0] = "xdg-open";
291 open
[1] = (gchar
*)url
;
294 gdk_spawn_on_screen (gdk_screen_get_default (), NULL
, open
, NULL
,
295 G_SPAWN_SEARCH_PATH
, NULL
, NULL
, NULL
, NULL
);