Release version 1.0
[gmidimonitor.git] / glade.c
blob04e40a17b6f60fc88eb4af1130af13200827937f
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * DESCRIPTION:
5 * libglade helpers
7 * LICENSE:
8 * GNU GENERAL PUBLIC LICENSE version 2
10 *****************************************************************************/
12 #include <stdlib.h>
13 #include <gtk/gtk.h>
14 #include <glade/glade.h>
16 #include "glade.h"
17 #include "path.h"
19 static void
20 glade_signal_connect_func(
21 const gchar *cb_name, GObject *obj,
22 const gchar *signal_name, const gchar *signal_data,
23 GObject *conn_obj, gboolean conn_after,
24 gpointer user_data)
26 /** Module with all the symbols of the program */
27 static GModule *mod_self = NULL;
28 gpointer handler_func;
30 /* initialize gmodule */
31 if (mod_self == NULL)
33 mod_self = g_module_open(NULL, 0);
34 g_assert(mod_self != NULL);
37 /* g_print("glade_signal_connect_func:" */
38 /* " cb_name = '%s', signal_name = '%s', " */
39 /* "signal_data = '%s', obj = 0x%08X, conn_after = %s\n", */
40 /* cb_name, signal_name, */
41 /* signal_data, (unsigned int)obj, conn_after?"true":"false"); */
43 if (g_module_symbol(mod_self, cb_name, &handler_func))
45 /* found callback */
46 if (conn_obj)
48 if (conn_after)
50 g_signal_connect_object(
51 obj,
52 signal_name,
53 handler_func,
54 conn_obj,
55 G_CONNECT_AFTER);
57 else
59 g_signal_connect_object(
60 obj,
61 signal_name,
62 handler_func,
63 conn_obj,
64 G_CONNECT_SWAPPED);
67 else
69 /* no conn_obj; use standard connect */
70 gpointer data = NULL;
72 data = user_data;
74 if (conn_after)
76 g_signal_connect_after(
77 obj,
78 signal_name,
79 handler_func,
80 data);
82 else
84 g_signal_connect(
85 obj,
86 signal_name,
87 handler_func,
88 data);
92 else
94 g_warning("callback function not found: %s", cb_name);
98 GtkWidget *
99 construct_glade_widget(
100 const gchar * id)
102 gchar * glade_filename;
103 GtkWidget * widget;
104 GladeXML * xml;
106 glade_filename = path_get_data_filename("gmidimonitor.glade");
107 if (glade_filename == NULL)
109 g_warning("Cannot find glade UI description file.");
110 exit(1);
113 /* load the interface */
114 xml = glade_xml_new(glade_filename, id, NULL);
116 g_free(glade_filename);
118 widget = glade_xml_get_widget(xml, id);
120 /* connect the signals in the interface */
121 glade_xml_signal_autoconnect_full(
122 xml,
123 (GladeXMLConnectFunc)glade_signal_connect_func,
124 widget);
126 return widget;
129 GtkWidget *
130 get_glade_widget_child(
131 GtkWidget * root,
132 const gchar * id)
134 GladeXML * xml;
135 GtkWidget * widget;
137 xml = glade_get_widget_tree(root);
139 widget = glade_xml_get_widget(xml, id);
141 return widget;