annotate audacious/glade.c @ 1635:a3a6f657f895 trunk

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