I have a new function to add to libglade it basically just makes it
easier to use glade for things such as the following:
I define a struct that contains my application state.
then i normally using gtk would just pass this via
g_signal_connect to each callback. using
glade_xml_signal_autoconnect I have no way of doing this.
I believe I can accomplish what I want using
glade_xml_signal_autoconnect_full
however, this function requires quiet a bit of understanding more
then I the casual user cares to understand. So, the solution to
my problem was to add the following function:
glade_xml_signal_autoconnect_with_data (GladeXML *self, gpointer user_data);
which works just like glade_xml_signal_autoconnect just passes along
the user_data to the g_signal_connect functions.
the patch provided is for what's currently in cvs.
hope this patch is useful
-todd
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
? data.diff
Index: glade/glade-xml.c
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-xml.c,v
retrieving revision 1.104
diff -u -r1.104 glade-xml.c
--- glade/glade-xml.c 23 Jul 2003 14:48:48 -0000 1.104
+++ glade/glade-xml.c 24 Dec 2003 18:42:04 -0000
@@ -271,15 +271,21 @@
}
}
+/* used for passing both the module symbols and user data to each signal
+ * handler */
+typedef struct SymbolData{
+ GModule *allsymbols;
+ gpointer user_data;
+}SymbolData;
+
static void
autoconnect_foreach(const char *signal_handler, GList *signals,
- GModule *allsymbols)
+ SymbolData *symdata)
{
GCallback func;
-
- if (!g_module_symbol(allsymbols, signal_handler, (gpointer *)&func))
+ if (!g_module_symbol(symdata->allsymbols, signal_handler, (gpointer *)&func))
g_warning("could not find signal handler '%s'.", signal_handler);
- else
+ else{
for (; signals != NULL; signals = signals->next) {
GladeSignalData *data = signals->data;
if (data->connect_object) {
@@ -296,12 +302,16 @@
* be helpful for someone */
if (data->signal_after)
g_signal_connect_after(data->signal_object,
- data->signal_name, func, NULL);
- else
- g_signal_connect(data->signal_object, data->signal_name,
- func, NULL);
+ data->signal_name, func,
+ symdata->user_data );
+ else{
+ g_signal_connect(data->signal_object,
+ data->signal_name,
+ func, symdata->user_data );
+ }
}
}
+ }
}
/**
@@ -317,19 +327,28 @@
* Note that this function will not work correctly if gmodule is not
* supported on the platform.
*/
+
void
-glade_xml_signal_autoconnect (GladeXML *self)
+glade_xml_signal_autoconnect_with_data (GladeXML *self, gpointer user_data)
{
- GModule *allsymbols;
+ SymbolData sym_data;
g_return_if_fail(self != NULL);
if (!g_module_supported())
g_error("glade_xml_signal_autoconnect requires working gmodule");
/* get a handle on the main executable -- use this to find symbols */
- allsymbols = g_module_open(NULL, 0);
- g_hash_table_foreach(self->priv->signals, (GHFunc)autoconnect_foreach,
- allsymbols);
+ sym_data.allsymbols = g_module_open(NULL, 0);
+ g_return_if_fail(sym_data.allsymbols != NULL);
+
+ sym_data.user_data = user_data;
+ g_hash_table_foreach( self->priv->signals, (GHFunc)autoconnect_foreach,
+ &sym_data );
+}
+void
+glade_xml_signal_autoconnect (GladeXML *self)
+{
+ glade_xml_signal_autoconnect_with_data( self, NULL );
}
Index: glade/glade-xml.h
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-xml.h,v
retrieving revision 1.31
diff -u -r1.31 glade-xml.h
--- glade/glade-xml.h 26 Apr 2002 14:55:31 -0000 1.31
+++ glade/glade-xml.h 24 Dec 2003 18:42:04 -0000
@@ -81,6 +81,15 @@
*/
void glade_xml_signal_autoconnect (GladeXML *self);
+/*
+ * basically the same as glade_xml_signal_autoconnect but passes
+ * a user data variable which gets connected to each signal handler
+ * useful if you'd like to maintain a single struct accross all
+ * callback funtions.
+ */
+void glade_xml_signal_autoconnect_with_data (GladeXML *self,
+ gpointer user_data);
+
/* if the gtk_signal_connect_object behaviour is required, connect_object
* will point to the object, otherwise it will be NULL.
*/