0
|
1 /* BMP - Cross-platform multimedia player
|
|
2 * Copyright (C) 2003-2004 BMP development team.
|
|
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 as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
1459
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
0
|
17 */
|
|
18
|
|
19 #ifndef HAVE_CONFIG_H
|
|
20 # include "config.h"
|
|
21 #endif
|
|
22
|
|
23 #include <glib.h>
|
|
24 #include <glib/gi18n.h>
|
|
25 #include <gmodule.h>
|
|
26 #include <gtk/gtk.h>
|
|
27 #include <glade/glade.h>
|
|
28
|
|
29 #include <stdlib.h>
|
|
30
|
|
31 #include "glade.h"
|
|
32
|
|
33
|
|
34 GladeXML *
|
|
35 glade_xml_new_or_die(const gchar * name,
|
|
36 const gchar * path,
|
|
37 const gchar * root,
|
|
38 const gchar * domain)
|
|
39 {
|
|
40 const gchar *markup =
|
|
41 N_("<b><big>Unable to create %s.</big></b>\n"
|
|
42 "\n"
|
|
43 "Could not open glade file (%s). Please check your "
|
|
44 "installation.\n");
|
|
45
|
|
46 GladeXML *xml = glade_xml_new(path, root, domain);
|
|
47
|
|
48 if (!xml) {
|
|
49 GtkWidget *dialog =
|
|
50 gtk_message_dialog_new_with_markup(NULL,
|
|
51 GTK_DIALOG_MODAL,
|
|
52 GTK_MESSAGE_ERROR,
|
|
53 GTK_BUTTONS_CLOSE,
|
|
54 _(markup),
|
|
55 name, path);
|
|
56 gtk_dialog_run(GTK_DIALOG(dialog));
|
|
57 gtk_widget_destroy(dialog);
|
|
58
|
|
59 exit(EXIT_FAILURE);
|
|
60 }
|
|
61
|
|
62 return xml;
|
|
63 }
|
|
64
|
|
65 GtkWidget *
|
|
66 glade_xml_get_widget_warn(GladeXML * xml, const gchar * name)
|
|
67 {
|
|
68 GtkWidget *widget = glade_xml_get_widget(xml, name);
|
|
69
|
|
70 if (!widget) {
|
|
71 g_warning("Widget not found (%s)", name);
|
|
72 return NULL;
|
|
73 }
|
|
74
|
|
75 return widget;
|
|
76 }
|
|
77
|
|
78
|
|
79 static GCallback
|
|
80 self_symbol_lookup(const gchar * symbol_name)
|
|
81 {
|
|
82 static GModule *module = NULL;
|
|
83 gpointer symbol = NULL;
|
|
84
|
|
85 if (!module)
|
|
86 module = g_module_open(NULL, 0);
|
|
87
|
|
88 g_module_symbol(module, symbol_name, &symbol);
|
|
89 return (GCallback) symbol;
|
|
90 }
|
|
91
|
|
92 static GHashTable *
|
|
93 func_map_to_hash(FuncMap * map)
|
|
94 {
|
|
95 GHashTable *hash;
|
|
96 FuncMap *current;
|
|
97
|
|
98 g_return_val_if_fail(map != NULL, NULL);
|
|
99
|
|
100 hash = g_hash_table_new(g_str_hash, g_str_equal);
|
|
101
|
|
102 for (current = map; current->name; current++)
|
|
103 g_hash_table_insert(hash, current->name, (gpointer) current->function);
|
|
104
|
|
105 return hash;
|
|
106 }
|
|
107
|
|
108 static void
|
|
109 map_connect_func(const gchar * handler_name,
|
|
110 GObject * object,
|
|
111 const gchar * signal_name,
|
|
112 const gchar * signal_data,
|
|
113 GObject * connect_object,
|
|
114 gboolean after,
|
|
115 gpointer data)
|
|
116 {
|
|
117 GHashTable *hash = data;
|
|
118 GCallback callback;
|
|
119
|
|
120 g_return_if_fail(object != NULL);
|
|
121 g_return_if_fail(handler_name != NULL);
|
|
122 g_return_if_fail(signal_name != NULL);
|
|
123
|
|
124 if (!(callback = self_symbol_lookup(handler_name)))
|
|
125 callback = (GCallback) g_hash_table_lookup(hash, handler_name);
|
|
126
|
|
127 if (!callback) {
|
|
128 g_message("Signal handler (%s) not found", handler_name);
|
|
129 return;
|
|
130 }
|
|
131
|
|
132 if (connect_object) {
|
|
133 g_signal_connect_object(object, signal_name, callback,
|
|
134 connect_object,
|
|
135 (after ? G_CONNECT_AFTER : 0) |
|
|
136 G_CONNECT_SWAPPED);
|
|
137 }
|
|
138 else {
|
|
139 if (after)
|
|
140 g_signal_connect_after(object, signal_name, callback, NULL);
|
|
141 else
|
|
142 g_signal_connect(object, signal_name, callback, NULL);
|
|
143 }
|
|
144 }
|
|
145
|
|
146 void
|
|
147 glade_xml_signal_autoconnect_map(GladeXML * xml,
|
|
148 FuncMap * map)
|
|
149 {
|
|
150 GHashTable *hash;
|
|
151
|
|
152 g_return_if_fail(xml != NULL);
|
|
153 g_return_if_fail(map != NULL);
|
|
154
|
|
155 hash = func_map_to_hash(map);
|
|
156 glade_xml_signal_autoconnect_full(xml, map_connect_func, hash);
|
|
157 g_hash_table_destroy(hash);
|
|
158 }
|