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 588238 - Also support the requires glade option
Also support the requires glade option
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
2.16.x
Other Linux
: Normal enhancement
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks:
 
 
Reported: 2009-07-10 11:45 UTC by Nick Schermer
Modified: 2018-04-15 00:00 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement



Description Nick Schermer 2009-07-10 11:45:09 UTC
Currently GtkBuilder only fully supports widgets in the Gtk+ library, but it is not 100% capable for extending with custom widgets/libraries.

Looking in the gtkbuilder code it only searches for *_get_type function in the local (gtk) library if the type is not already initialized, but for external libraries this obviously fails.

It looks like the "requires" xml is parsed and stored in the parser code, but not used. So if (in our Xfce case) the following line is in the glade file:

<requires lib="libxfce4ui-1" version="4.7.0"/> and the object XfceTitedDialog is using.

_gtk_builder_resolve_type_lazily should, after is fails looking for the xfce_titled_dialog_get_type in the gtk library, traverse the "requires" libraries, link them and look through them for the symbol.

This is a regression compared to libglade so hopefully this can be fixed. Right now we work around this problem calling xfce_titled_dialog_get_type() before parsing the glade file, so g_type_from_name returns a valid type.
Comment 1 Matthias Clasen 2009-07-10 15:02:17 UTC
Would you be willing to work on a patch for this ?
Comment 2 Nick Schermer 2009-07-10 16:10:52 UTC
Sure, will take a look at this if you think this is a good solution for the problem. 
Comment 3 Tristan Van Berkom 2009-07-10 16:38:40 UTC
I always thought the libglade method method to include
widget types was a little clunky, if only because it makes
it difficult for people who are not interested in distributing
a widget kit and building a separate module.

In the hope this is not too quickly spoken, I think a good
and easy solution for this would be to just expose a "requires"
signal (possibly a boolean return with a major/minor version
argument and a signal detail describing the required catalog).

This would allow a few use cases with little effort I think:
   - When linking against libxfce4ui-1, you just connect
     to "requires::libxfce4ui-1" and return TRUE or FALSE
     depending on the version.
   - If libxfce4ui-1 is for any reason a dynamic module
     (like in libglade days), then you can do the above
     but just load the module in the signal callback and
     return FALSE if it fails.
   - If the user has custom widgets in his application, he
     will be using a custom catalog and the "requires" field
     will reflect that (I think thats correct since that file
     will will be unsafe to load for any other application),
     in which case the user should connect to the signal and 
     just return TRUE for his own catalog.

Thoughts ?
Comment 4 Nick Schermer 2009-07-10 16:55:03 UTC
For custom widgets: if g_type_from_name() failes if looks for the *_get_type function in GModule g_module_open (NULL, 0), the glib manual says this is "a GModule representing the main program itself", so that would mean this only failes if the specific library (containing the widget) is not linked? Right?

The signal is not very convient, since you have to implement it for each gtkbuilder or write an object on top of gtkbuilder that implements it (not cool).
Comment 5 Tristan Van Berkom 2009-07-10 17:25:32 UTC
(In reply to comment #4)
> For custom widgets: if g_type_from_name() failes if looks for the *_get_type
> function in GModule g_module_open (NULL, 0), the glib manual says this is "a
> GModule representing the main program itself", so that would mean this only
> failes if the specific library (containing the widget) is not linked? Right?
> 
> The signal is not very convient, since you have to implement it for each
> gtkbuilder or write an object on top of gtkbuilder that implements it (not
> cool).
> 

Right, when the library has been linked, there is no need to
load a module, assuming you've loaded your modules into memory
GtkBuilder will "just work", which is a step up from libglade
which required that you write initialization stubs for your
library and register your widgets by hand.

The "requires" tag is primarily an assertion that the widget 
catalogs described in the GtkBuilder xml file are indeed available 
at runtime - and that they are versioned correctly.

So it will intentionally fail with an error message if for instance
your glade file uses a widget or property in libxfce4ui-1 from a 
version not yet installed on your system.

On the Glade side of things, this also ensures that if you use 
custom widgets in your app, and you sent the Glade
file to someone else, they will immediately know that they
also need your catalog and your widget code to operate with
that Glade file (which also should transparently work with
widget libraries that install catalogs to integrate with the 
Glade palette).

Comment 6 Tristan Van Berkom 2009-07-10 17:49:14 UTC
(In reply to comment #0)
> It looks like the "requires" xml is parsed and stored in the parser code, but
> not used. So if (in our Xfce case) the following line is in the glade file:

Ahhh sorry I did not read this part.

Yes, its there, I put it there intentionally and its used, but we
still never extended it to check other catalogs than the base "gtk+"
catalog.

If you are porting from libglade to GtkBuilder, I would suggest
that if you can - just link against the widget library you need
directly, and until this bug is fixed the version just wont
be checked.

On the other hand... there is probably some value to implicitly
pulling in a library completely via GtkBuilder and a dependancy
in the Glade file - the <requires> tag could be extended to
add a property describing the actual library to look up in
the linker path, since now it only takes a toolkit identifier string.

But that still leaves one problem: how do you check
the version of toolkit 'x' (if only all libraries implemented
a common interface ?) ?

Maybe an optional module entry point ? 
  gboolean gtkbuilder_init_module (gint major, gint minor); 

Is all that really worth the trouble just to load ui toolkit 
libraries on demand ? I mean, if you distributed the Glade file
and your app uses it, you depend on that toolkit anyway, you
cannot fallback, so why spend more time loading the toolkit
with the runtime linker ?

Comment 7 Nick Schermer 2009-07-11 20:58:57 UTC
All true, I worked around the problem by making sure the library is linked so for now to problem is solved for us. I just could imaging people expect this to happen automagically. The module entry point is an idea, because you most likely also added support for glade-3 for the library.
Comment 8 Tristan Van Berkom 2009-07-11 21:21:16 UTC
Currently you dont need to make any special entry point for
a module that provides widgets for GtkBuilder, its just types.

Only libglade required that, if we go and add such possible
entry point for a loadable library, it would be something completely
new, but I wouldnt object, on the other hand we still also need a way
for the user to tell GtkBuilder about widgets in their project
that come from their own custom catalog, which could be done
with a gtk_builder_provide_catalog (builder, "catalog-name", major, minor)
api instead of a signal (even a "silent" attribute could be added to
cause builder to "assume" the dependancy all together, and you could
go and control that in Glade... all possible options).

On the other hand exposing a signal simplifies the whole implementation
for us, at the cost of strictly educating the GTK+ user about what
catalogs are involved in his load process.

The option out of these options I prefer personally is 
 "I would really just like it to be done"
I guess I dont really mind how... if it really gets done ;-)
Comment 9 Matthias Clasen 2018-02-10 05:13:04 UTC
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
Comment 10 Matthias Clasen 2018-04-15 00:00:15 UTC
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla.

If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab:

https://gitlab.gnome.org/GNOME/gtk/issues/new