comparison src/audacious/glade.c @ 2313:3149d4b1a9a9 trunk

[svn] - objective-make autodepend fixes - move all sourcecode into src/ and adjust Makefiles accordingly
author nenolod
date Fri, 12 Jan 2007 11:43:40 -0800
parents
children 7d3beedf1db8
comparison
equal deleted inserted replaced
2312:e1a5a66fb9cc 2313:3149d4b1a9a9
1 /* Audacious - Cross-platform multimedia player
2 * Copyright (C) 2005-2007 Audacious development team
3 *
4 * Based on BMP:
5 * Copyright (C) 2003-2004 BMP development team.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; under version 2 of the License.
10 *
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.
15 *
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.
19 */
20
21 #ifndef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gmodule.h>
28 #include <gtk/gtk.h>
29 #include <glade/glade.h>
30
31 #include <stdlib.h>
32
33 #include "glade.h"
34
35
36 GladeXML *
37 glade_xml_new_or_die(const gchar * name,
38 const gchar * path,
39 const gchar * root,
40 const gchar * domain)
41 {
42 const gchar *markup =
43 N_("<b><big>Unable to create %s.</big></b>\n"
44 "\n"
45 "Could not open glade file (%s). Please check your "
46 "installation.\n");
47
48 GladeXML *xml = glade_xml_new(path, root, domain);
49
50 if (!xml) {
51 GtkWidget *dialog =
52 gtk_message_dialog_new_with_markup(NULL,
53 GTK_DIALOG_MODAL,
54 GTK_MESSAGE_ERROR,
55 GTK_BUTTONS_CLOSE,
56 _(markup),
57 name, path);
58 gtk_dialog_run(GTK_DIALOG(dialog));
59 gtk_widget_destroy(dialog);
60
61 exit(EXIT_FAILURE);
62 }
63
64 return xml;
65 }
66
67 GtkWidget *
68 glade_xml_get_widget_warn(GladeXML * xml, const gchar * name)
69 {
70 GtkWidget *widget = glade_xml_get_widget(xml, name);
71
72 if (!widget) {
73 g_warning("Widget not found (%s)", name);
74 return NULL;
75 }
76
77 return widget;
78 }
79
80
81 static GCallback
82 self_symbol_lookup(const gchar * symbol_name)
83 {
84 static GModule *module = NULL;
85 gpointer symbol = NULL;
86
87 if (!module)
88 module = g_module_open(NULL, 0);
89
90 g_module_symbol(module, symbol_name, &symbol);
91 return (GCallback) symbol;
92 }
93
94 static GHashTable *
95 func_map_to_hash(FuncMap * map)
96 {
97 GHashTable *hash;
98 FuncMap *current;
99
100 g_return_val_if_fail(map != NULL, NULL);
101
102 hash = g_hash_table_new(g_str_hash, g_str_equal);
103
104 for (current = map; current->name; current++)
105 g_hash_table_insert(hash, current->name, (gpointer) current->function);
106
107 return hash;
108 }
109
110 static void
111 map_connect_func(const gchar * handler_name,
112 GObject * object,
113 const gchar * signal_name,
114 const gchar * signal_data,
115 GObject * connect_object,
116 gboolean after,
117 gpointer data)
118 {
119 GHashTable *hash = data;
120 GCallback callback;
121
122 g_return_if_fail(object != NULL);
123 g_return_if_fail(handler_name != NULL);
124 g_return_if_fail(signal_name != NULL);
125
126 if (!(callback = self_symbol_lookup(handler_name)))
127 callback = (GCallback) g_hash_table_lookup(hash, handler_name);
128
129 if (!callback) {
130 g_message("Signal handler (%s) not found", handler_name);
131 return;
132 }
133
134 if (connect_object) {
135 g_signal_connect_object(object, signal_name, callback,
136 connect_object,
137 (after ? G_CONNECT_AFTER : 0) |
138 G_CONNECT_SWAPPED);
139 }
140 else {
141 if (after)
142 g_signal_connect_after(object, signal_name, callback, NULL);
143 else
144 g_signal_connect(object, signal_name, callback, NULL);
145 }
146 }
147
148 void
149 glade_xml_signal_autoconnect_map(GladeXML * xml,
150 FuncMap * map)
151 {
152 GHashTable *hash;
153
154 g_return_if_fail(xml != NULL);
155 g_return_if_fail(map != NULL);
156
157 hash = func_map_to_hash(map);
158 glade_xml_signal_autoconnect_full(xml, map_connect_func, hash);
159 g_hash_table_destroy(hash);
160 }