libglade helpers.
[mediadatabase.git] / gtk / glade.c
blob1c6893b17c5f128ef3902929c82c1e2bf9d48f4e
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: glade.c,v 1.1 2005/02/18 02:13:35 nedko Exp $
6 * DESCRIPTION:
7 *
9 * NOTES:
12 *****************************************************************************/
14 #include <stdlib.h>
15 #include <gtk/gtk.h>
16 #include <glade/glade.h>
18 #include "glade.h"
19 #include "path.h"
21 static GladeXML *xml = NULL;
23 static void
24 glade_signal_connect_func (
25 const gchar *cb_name, GObject *obj,
26 const gchar *signal_name, const gchar *signal_data,
27 GObject *conn_obj, gboolean conn_after,
28 gpointer user_data)
30 /** Module with all the symbols of the program */
31 static GModule *mod_self = NULL;
32 gpointer handler_func;
34 /* initialize gmodule */
35 if (mod_self == NULL)
37 mod_self = g_module_open (NULL, 0);
38 g_assert (mod_self != NULL);
41 /*g_print( "glade_signal_connect_func: cb_name = '%s', signal_name = '%s', signal_data = '%s'\n",
42 cb_name, signal_name, signal_data ); */
44 if (g_module_symbol (mod_self, cb_name, &handler_func))
46 /* found callback */
47 if (conn_obj)
49 if (conn_after)
51 g_signal_connect_object
52 (obj, signal_name,
53 handler_func, conn_obj,
54 G_CONNECT_AFTER);
56 else
58 g_signal_connect_object
59 (obj, signal_name,
60 handler_func, conn_obj,
61 G_CONNECT_SWAPPED);
64 else
66 /* no conn_obj; use standard connect */
67 gpointer data = NULL;
69 data = user_data;
71 if (conn_after)
73 g_signal_connect_after
74 (obj, signal_name,
75 handler_func, data);
77 else
79 g_signal_connect
80 (obj, signal_name,
81 handler_func, data);
85 else
87 g_warning("callback function not found: %s", cb_name);
91 GtkWidget *
92 construct_glade_widget(
93 const gchar * id)
95 gchar * glade_filename;
96 GtkWidget * widget;
98 if (xml == NULL)
100 glade_filename = path_get_data_filename("mediadatabase.glade");
101 if (glade_filename == NULL)
103 g_warning("Cannot find glade UI description file.");
104 exit(1);
107 /* load the interface */
108 xml = glade_xml_new(glade_filename, id, NULL);
110 g_free(glade_filename);
113 widget = glade_xml_get_widget(xml, id);
115 /* connect the signals in the interface */
116 glade_xml_signal_autoconnect_full(
117 xml,
118 (GladeXMLConnectFunc)glade_signal_connect_func,
119 widget);
121 return widget;
124 GtkWidget *
125 get_glade_widget(
126 const gchar * id)
128 return glade_xml_get_widget(
129 xml,
130 id);
133 /*****************************************************************************
135 * Modifications log:
137 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
139 * $Log: glade.c,v $
140 * Revision 1.1 2005/02/18 02:13:35 nedko
141 * libglade helpers.
143 *****************************************************************************/