Mercurial > audlegacy
annotate src/audacious/glade.c @ 3223:963dfcfdc851 trunk
don't carry GdkGC around
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Thu, 02 Aug 2007 16:51:17 +0200 |
parents | f1c756f39e6c |
children |
rev | line source |
---|---|
2896
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
1 /* Audacious - Cross-platform multimedia player |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
2 * Copyright (C) 2005-2007 Audacious development team |
2313 | 3 * |
2896
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
4 * Based on BMP: |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
5 * Copyright (C) 2003-2004 BMP development team. |
2313 | 6 * |
2896
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2896
diff
changeset
|
9 * the Free Software Foundation; under version 3 of the License. |
2313 | 10 * |
2896
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
14 * GNU General Public License for more details. |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
15 * |
51dda959be4d
Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents:
2861
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2896
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
18 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
19 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
20 * Audacious or using our public API to be a derived work. |
2313 | 21 */ |
22 | |
23 #ifndef HAVE_CONFIG_H | |
24 # include "config.h" | |
25 #endif | |
26 | |
27 #include <glib.h> | |
28 #include <glib/gi18n.h> | |
29 #include <gmodule.h> | |
30 #include <gtk/gtk.h> | |
31 #include <glade/glade.h> | |
32 | |
33 #include <stdlib.h> | |
34 | |
35 #include "glade.h" | |
36 | |
37 | |
38 GladeXML * | |
39 glade_xml_new_or_die(const gchar * name, | |
40 const gchar * path, | |
41 const gchar * root, | |
42 const gchar * domain) | |
43 { | |
44 const gchar *markup = | |
45 N_("<b><big>Unable to create %s.</big></b>\n" | |
46 "\n" | |
47 "Could not open glade file (%s). Please check your " | |
48 "installation.\n"); | |
49 | |
50 GladeXML *xml = glade_xml_new(path, root, domain); | |
51 | |
52 if (!xml) { | |
53 GtkWidget *dialog = | |
54 gtk_message_dialog_new_with_markup(NULL, | |
55 GTK_DIALOG_MODAL, | |
56 GTK_MESSAGE_ERROR, | |
57 GTK_BUTTONS_CLOSE, | |
58 _(markup), | |
59 name, path); | |
60 gtk_dialog_run(GTK_DIALOG(dialog)); | |
61 gtk_widget_destroy(dialog); | |
62 | |
63 exit(EXIT_FAILURE); | |
64 } | |
65 | |
66 return xml; | |
67 } | |
68 | |
69 GtkWidget * | |
70 glade_xml_get_widget_warn(GladeXML * xml, const gchar * name) | |
71 { | |
72 GtkWidget *widget = glade_xml_get_widget(xml, name); | |
73 | |
74 if (!widget) { | |
75 g_warning("Widget not found (%s)", name); | |
76 return NULL; | |
77 } | |
78 | |
79 return widget; | |
80 } | |
81 | |
82 | |
83 static GCallback | |
84 self_symbol_lookup(const gchar * symbol_name) | |
85 { | |
86 static GModule *module = NULL; | |
87 gpointer symbol = NULL; | |
88 | |
89 if (!module) | |
90 module = g_module_open(NULL, 0); | |
91 | |
92 g_module_symbol(module, symbol_name, &symbol); | |
93 return (GCallback) symbol; | |
94 } | |
95 | |
96 static GHashTable * | |
97 func_map_to_hash(FuncMap * map) | |
98 { | |
99 GHashTable *hash; | |
100 FuncMap *current; | |
101 | |
102 g_return_val_if_fail(map != NULL, NULL); | |
103 | |
104 hash = g_hash_table_new(g_str_hash, g_str_equal); | |
105 | |
106 for (current = map; current->name; current++) | |
107 g_hash_table_insert(hash, current->name, (gpointer) current->function); | |
108 | |
109 return hash; | |
110 } | |
111 | |
112 static void | |
113 map_connect_func(const gchar * handler_name, | |
114 GObject * object, | |
115 const gchar * signal_name, | |
116 const gchar * signal_data, | |
117 GObject * connect_object, | |
118 gboolean after, | |
119 gpointer data) | |
120 { | |
121 GHashTable *hash = data; | |
122 GCallback callback; | |
123 | |
124 g_return_if_fail(object != NULL); | |
125 g_return_if_fail(handler_name != NULL); | |
126 g_return_if_fail(signal_name != NULL); | |
127 | |
128 if (!(callback = self_symbol_lookup(handler_name))) | |
129 callback = (GCallback) g_hash_table_lookup(hash, handler_name); | |
130 | |
131 if (!callback) { | |
132 g_message("Signal handler (%s) not found", handler_name); | |
133 return; | |
134 } | |
135 | |
136 if (connect_object) { | |
137 g_signal_connect_object(object, signal_name, callback, | |
138 connect_object, | |
139 (after ? G_CONNECT_AFTER : 0) | | |
140 G_CONNECT_SWAPPED); | |
141 } | |
142 else { | |
143 if (after) | |
144 g_signal_connect_after(object, signal_name, callback, NULL); | |
145 else | |
146 g_signal_connect(object, signal_name, callback, NULL); | |
147 } | |
148 } | |
149 | |
150 void | |
151 glade_xml_signal_autoconnect_map(GladeXML * xml, | |
152 FuncMap * map) | |
153 { | |
154 GHashTable *hash; | |
155 | |
156 g_return_if_fail(xml != NULL); | |
157 g_return_if_fail(map != NULL); | |
158 | |
159 hash = func_map_to_hash(map); | |
160 glade_xml_signal_autoconnect_full(xml, map_connect_func, hash); | |
161 g_hash_table_destroy(hash); | |
162 } |