GNOME Bugzilla – Bug 326511
Patch to add glade_xml_construct_from_buffer method
Last modified: 2007-07-04 14:05:50 UTC
libglademm requires a glade_xml_construct_from_buffer method in order to correctly load a glade file. The current method of using new_from_buffer does not attach the new objects to the correct base object, resulting in being unable to override the base object to catch mouse movements. The following patch adds a new glade_xml_construct_from_buffer method to glade-xml.c and glade-xml.h --- glade-xml.c 2006-01-09 16:07:08.000000000 -0500 +++ glade-xml.c_new 2006-01-09 16:05:34.000000000 -0500 @@ -195,6 +195,42 @@ } /** + * glade_xml_construct_from_buffer: + * @self: the GladeXML object + * @buffer: the memory buffer containing the XML document. + * @size: the size of the buffer. + * @root: the root widget node (or %NULL for none) + * @domain: the translation domain (or %NULL for the default) + * + * This routine can be used by bindings (such as gtk--) to help construct + * a GladeXML object from a buffer, if it is needed. + * + * Returns: TRUE if the construction succeeded. + */ +gboolean +glade_xml_construct_from_buffer (GladeXML *self, const char *buffer, int size, + const char *root, + const char *domain) +{ + GladeInterface *iface; + + g_return_val_if_fail(self != NULL, FALSE); + + iface = glade_parser_parse_buffer(buffer, size, domain); + + if (!iface) + return FALSE; + + self->priv->tree = iface; + if (self->filename) + g_free(self->filename); + self->filename = NULL; + glade_xml_build_interface(self, iface, root); + + return TRUE; +} + +/** * glade_xml_new_from_buffer: * @buffer: the memory buffer containing the XML document. * @size: the size of the buffer. --- glade-xml.h 2006-01-09 15:45:57.000000000 -0500 +++ glade-xml.h_new 2006-01-09 15:57:52.000000000 -0500 @@ -66,6 +66,10 @@ const char *root, const char *domain); +gboolean glade_xml_construct_from_buffer (GladeXML *self, const char *buffer, int size, + const char *root, + const char *domain); + void glade_xml_signal_connect (GladeXML *self, const char *handlername, GCallback func);
This seems to be for language bindings, because glade_xml_new_from_buffer() does more than just call g_object_new(), which doesn't allow us to instantiated derived GTypes instead. I guess that glade_xml_new_from_buffer() should use this function instead of duplicating code.
Doug, what do you think?
I don't understand the first paragraph for comment #1. I agree that glade_xml_new_from_buffer() could use this new function to do the work, after it creates a new base object. I was more worried about making the patch as low risk as possible to hopefully speed its inclusion (pure addition instead of changing existing code), so didn't consider that optimization.
> I don't understand the first paragraph for comment #1. "This seems to be for language bindings, because glade_xml_new_from_buffer() does more than just call g_object_new(), which doesn't allow us to instantiated derived GTypes instead." is a message to the maintainer, so he knows why he might want to apply this, because you didn't tell him. > didn't consider that optimization I guess that the maintainer would prefer not to have code duplication. If I was the maintainer that's what I'd want to avoid.
Doug, it's hard enough to get patches committed to libglade. You can make that more likely by improving the patch like I suggested.
Created attachment 75724 [details] [review] A revised patch to remove code duplication between glade_xml_new_from_buffer The patch has been revised as requested.
If nobody else, does I might just go ahead and commit this myself sometime soon.
Maybe a good final touch to this would be to add: gboolean glade_xml_construct_from_buffer (GladeXML *self, const char *buffer, int size, const char *root, const char *domain) { GladeInterface *iface; g_return_val_if_fail(self != NULL, FALSE); + g_return_val_if_fail(self->priv->tree == NULL, FALSE); It should probably also be mentioned in the comment that using this function means you somehow managed to create a GladeXML object without parsing a buffer (i.e. g_object_new () ?), and that this two-step pass of creating a GladeXML is typically needed from language bindings. ... just me rambling on ... ;-)
Created attachment 78703 [details] [review] The third version of the patch, revised to include the additional test and comments, as requested. As requested, the patch has been revised to include the additional safety check and the additional comments were added to the method description.
I'm going to apply this soon. It's unacceptable for the maintainer to ingore patches for so long.
It has been over a year now. Is there any hope of this making it into the next release? It is becoming tedious to keep using patched versions of the library.
Applied to svn trunk, after creating a gnome-2-18 branch.
*** Bug 101367 has been marked as a duplicate of this bug. ***