update the website url
[gmidimonitor.git] / glade.c
blob244fdb1023eb2fb904ba60ad15f3a24233157a26
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * libglade helpers
6 * This file is part of gmidimonitor
8 * Copyright (C) 2005,2006,2007,2008,2011 Nedko Arnaudov <nedko@arnaudov.name>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 *****************************************************************************/
25 #include <stdlib.h>
26 #include <gtk/gtk.h>
27 #include <glade/glade.h>
29 #include "glade.h"
30 #include "path.h"
32 static void
33 glade_signal_connect_func(
34 const gchar *cb_name, GObject *obj,
35 const gchar *signal_name, const gchar *signal_data,
36 GObject *conn_obj, gboolean conn_after,
37 gpointer user_data)
39 /** Module with all the symbols of the program */
40 static GModule *mod_self = NULL;
41 gpointer handler_func;
43 /* initialize gmodule */
44 if (mod_self == NULL)
46 mod_self = g_module_open(NULL, 0);
47 g_assert(mod_self != NULL);
48 /* g_warning("%p", mod_self); */
51 /* g_print("glade_signal_connect_func:" */
52 /* " cb_name = '%s', signal_name = '%s', " */
53 /* "signal_data = '%s', obj = 0x%08X, conn_after = %s\n", */
54 /* cb_name, signal_name, */
55 /* signal_data, (unsigned int)obj, conn_after?"true":"false"); */
57 /* g_warning("%s", g_module_name(mod_self)); */
59 if (!g_module_symbol(mod_self, cb_name, &handler_func))
61 g_warning("callback function not found: %s", cb_name);
62 return;
65 /* found callback */
66 if (conn_obj)
68 if (conn_after)
70 g_signal_connect_object(
71 obj,
72 signal_name,
73 handler_func,
74 conn_obj,
75 G_CONNECT_AFTER);
77 else
79 g_signal_connect_object(
80 obj,
81 signal_name,
82 handler_func,
83 conn_obj,
84 G_CONNECT_SWAPPED);
87 else
89 /* no conn_obj; use standard connect */
90 gpointer data = NULL;
92 data = user_data;
94 if (conn_after)
96 g_signal_connect_after(
97 obj,
98 signal_name,
99 handler_func,
100 data);
102 else
104 g_signal_connect(
105 obj,
106 signal_name,
107 handler_func,
108 data);
113 GtkWidget *
114 construct_glade_widget(
115 const gchar * id)
117 gchar * glade_filename;
118 GtkWidget * widget;
119 GladeXML * xml;
121 glade_filename = path_get_data_filename("gmidimonitor.glade");
122 if (glade_filename == NULL)
124 g_warning("Cannot find glade UI description file.");
125 exit(1);
128 /* load the interface */
129 xml = glade_xml_new(glade_filename, id, NULL);
131 g_free(glade_filename);
133 widget = glade_xml_get_widget(xml, id);
135 /* connect the signals in the interface */
136 glade_xml_signal_autoconnect_full(
137 xml,
138 (GladeXMLConnectFunc)glade_signal_connect_func,
139 widget);
141 return widget;
144 GtkWidget *
145 get_glade_widget_child(
146 GtkWidget * root,
147 const gchar * id)
149 GladeXML * xml;
150 GtkWidget * widget;
152 xml = glade_get_widget_tree(root);
154 widget = glade_xml_get_widget(xml, id);
156 return widget;