1
/* Glade helper routines
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include <glade/glade.h>
32
#include "ve-miscui.h"
34
#include "glade-helper.h"
36
static void glade_helper_no_interface (const char *filename);
37
static void glade_helper_bad_interface (const char *filename,
40
static void glade_helper_bad_columns (const char *filename,
45
static GList *ve_glade_directories = NULL;
46
static gboolean ve_search_gnome_dirs = TRUE;
49
glade_helper_load (const char *file, const char *widget,
51
gboolean dump_on_destroy)
57
g_return_val_if_fail (file != NULL, NULL);
59
f = glade_helper_find_glade_file (file);
62
glade_helper_no_interface (file);
66
/* FIXME: eek use of PACKAGE */
67
xml = glade_xml_new (f, widget, GETTEXT_PACKAGE);
71
/* in case we can't load the interface, bail */
73
glade_helper_no_interface (file);
77
w = glade_xml_get_widget (xml, widget);
79
! G_TYPE_CHECK_INSTANCE_TYPE (w, expected_type)) {
80
glade_helper_bad_interface (xml->filename != NULL ?
88
if (dump_on_destroy) {
89
g_object_set_data_full (G_OBJECT (w),
92
(GtkDestroyNotify) g_object_unref);
99
glade_helper_load_widget (const char *file, const char *widget,
105
/* this is guaranteed to return non-NULL, otherwise we
106
* would have exited */
107
xml = glade_helper_load (file, widget, expected_type, FALSE);
109
w = glade_xml_get_widget (xml, widget);
111
! G_TYPE_CHECK_INSTANCE_TYPE (w, expected_type)) {
112
glade_helper_bad_interface (xml->filename != NULL ?
114
_("(memory buffer)"),
120
g_object_unref (G_OBJECT (xml));
126
glade_helper_get (GladeXML *xml, const char *widget, GType expected_type)
130
w = glade_xml_get_widget (xml, widget);
133
! G_TYPE_CHECK_INSTANCE_TYPE (w, expected_type)) {
134
glade_helper_bad_interface (xml->filename != NULL ?
136
_("(memory buffer)"),
146
glade_helper_bad_interface (const char *filename, const char *widget,
151
const char *typename;
155
typename = g_type_name (type);
159
if (typename == NULL)
160
typestring = g_strdup_printf (" (%s)", typename);
162
typestring = g_strdup ("");
164
tmp = ve_filename_to_utf8 (filename);
166
dlg = ve_hig_dialog_new (NULL /* parent */,
171
_("Cannot load user interface"),
172
_("An error occurred while loading user "
173
"interface element %s%s from file %s. "
174
"Possibly the glade interface description was "
176
"%s cannot continue and will exit now. "
177
"You should check your "
178
"installation of %s or reinstall %s."),
188
g_warning (_("Glade file is on crack! Make sure the correct "
189
"file is installed!\nfile: %s widget: %s"),
194
gtk_dialog_run (GTK_DIALOG (dlg));
195
gtk_widget_destroy (dlg);
199
glade_helper_bad_columns (const char *filename, const char *widget,
200
GType type, int columns)
204
const char *typename;
208
typename = g_type_name (type);
212
if (typename == NULL)
213
typestring = g_strdup_printf (" (%s)", typename);
215
typestring = g_strdup ("");
217
tmp = ve_filename_to_utf8 (filename);
219
dlg = ve_hig_dialog_new (NULL /* parent */,
224
_("Cannot load user interface"),
225
ngettext ("An error occurred while loading the "
226
"user interface element %s%s from "
227
"file %s. CList type widget should "
228
"have %d column. Possibly the glade "
229
"interface description was "
230
"corrupted. %s cannot continue and "
231
"will exit now. You should check "
232
"your installation of %s or "
234
"An error occurred while loading the "
235
"user interface element %s%s from "
236
"file %s. CList type widget should "
237
"have %d columns. Possibly the "
238
"glade interface description was "
239
"corrupted. %s cannot continue and "
240
"will exit now. You should check "
241
"your installation of %s or "
254
g_warning (_("Glade file is on crack! Make sure the correct "
255
"file is installed!\nfile: %s widget: %s "
256
"expected clist columns: %d"),
257
tmp, widget, columns);
261
gtk_dialog_run (GTK_DIALOG (dlg));
262
gtk_widget_destroy (dlg);
266
glade_helper_no_interface (const char *filename)
271
tmp = ve_filename_to_utf8 (filename);
273
dlg = ve_hig_dialog_new (NULL /* parent */,
278
_("Cannot load user interface"),
279
_("An error occurred while loading the user "
280
"interface from file %s. "
281
"Possibly the glade interface description was "
283
"%s cannot continue and will exit now. "
284
"You should check your "
285
"installation of %s or reinstall %s."),
290
gtk_dialog_set_has_separator (GTK_DIALOG (dlg), FALSE);
291
g_warning (_("No interface could be loaded. This is BAD! (file: %s)"),
296
gtk_dialog_run (GTK_DIALOG (dlg));
297
gtk_widget_destroy (dlg);
301
* glade_helper_find_glade_file:
302
* @file: glade filename
304
* Description: Finds a glade file in the same directories that
305
* glade_helper would look in. A utility if you use glade elsewhere in your
306
* application to make using glade simpler.
308
* Returns: Newly allocated string with the full path, or %NULL
312
glade_helper_find_glade_file (const char *file)
314
g_return_val_if_fail (file != NULL, NULL);
316
if (ve_search_gnome_dirs)
317
return ve_find_file (file, ve_glade_directories);
319
return ve_find_file_simple (file, ve_glade_directories);
323
* glade_helper_add_glade_directory:
324
* @directory: directory with glade files
326
* Description: Add a standard glade directory to search for
330
glade_helper_add_glade_directory (const char *directory)
332
ve_glade_directories = g_list_append (ve_glade_directories,
333
g_strdup (directory));
337
* glade_helper_seach_gnome_dirs:
338
* @search_gnome_dirs: boolean
340
* Description: Sets if the gnome directories are searched. Useful if
341
* your program does not use gnome_program_ and you don't want glade_helper
342
* to invoke gnome_program initialization by mistake. This is because
343
* it is possible for glade helper to try to use gnome_program_ routines
347
glade_helper_search_gnome_dirs (gboolean search_gnome_dirs)
349
ve_search_gnome_dirs = search_gnome_dirs;
352
/* Make label surrounded by tag (if tag = "tag" add <tag>text</tag>) */
354
glade_helper_tagify_label (GladeXML *xml,
360
GtkWidget *label = glade_helper_get (xml, name, GTK_TYPE_WIDGET);
361
if (GTK_IS_BUTTON (label)) {
362
label = GTK_BIN(label)->child;
364
if ( ! GTK_IS_LABEL (label)) {
365
glade_helper_bad_interface (xml->filename,
370
lbl = gtk_label_get_text (GTK_LABEL (label));
371
s = g_strdup_printf ("<%s>%s</%s>", tag, lbl, tag);
372
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
373
gtk_label_set_label (GTK_LABEL (label), s);