After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 326511 - Patch to add glade_xml_construct_from_buffer method
Patch to add glade_xml_construct_from_buffer method
Status: RESOLVED FIXED
Product: libglade
Classification: Deprecated
Component: general
CVS HEAD
Other Linux
: Normal enhancement
: ---
Assigned To: James Henstridge
James Henstridge
: 101367 (view as bug list)
Depends on:
Blocks: 326512
 
 
Reported: 2006-01-10 20:15 UTC by Doug
Modified: 2007-07-04 14:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A revised patch to remove code duplication between glade_xml_new_from_buffer (2.47 KB, patch)
2006-10-31 14:37 UTC, Doug
none Details | Review
The third version of the patch, revised to include the additional test and comments, as requested. (2.64 KB, patch)
2006-12-20 18:44 UTC, Doug
none Details | Review

Description Doug 2006-01-10 20:15:15 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);
Comment 1 Murray Cumming 2006-01-11 11:23:58 UTC
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. 
Comment 2 Murray Cumming 2006-03-22 12:49:35 UTC
Doug, what do you think?
Comment 3 Doug 2006-03-23 15:02:39 UTC
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.
Comment 4 Murray Cumming 2006-03-23 16:04:44 UTC
> 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.
Comment 5 Murray Cumming 2006-10-31 09:46:52 UTC
Doug, it's hard enough to get patches committed to libglade. You can make that more likely by improving the patch like I suggested.
Comment 6 Doug 2006-10-31 14:37:09 UTC
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.
Comment 7 Murray Cumming 2006-11-29 08:40:36 UTC
If nobody else, does I might just go ahead and commit this myself sometime soon.
Comment 8 Tristan Van Berkom 2006-12-20 17:14:57 UTC
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 ... ;-)
Comment 9 Doug 2006-12-20 18:44:50 UTC
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.
Comment 10 Murray Cumming 2007-01-29 16:13:03 UTC
I'm going to apply this soon. It's unacceptable for the maintainer to ingore patches for so long.
Comment 11 Doug 2007-04-12 21:20:32 UTC
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.
Comment 12 Murray Cumming 2007-04-16 08:59:04 UTC
Applied to svn trunk, after creating a gnome-2-18 branch.
Comment 13 Murray Cumming 2007-07-04 14:05:50 UTC
*** Bug 101367 has been marked as a duplicate of this bug. ***