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 447969 - Add a simpler API to create, parse and fetch objects
Add a simpler API to create, parse and fetch objects
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks: 450635 454244
 
 
Reported: 2007-06-15 18:09 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2015-03-07 23:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (12.12 KB, patch)
2007-06-24 20:46 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review

Description Johan (not receiving bugmail) Dahlin 2007-06-15 18:09:49 UTC
As suggested by Havoc on gtk-devel:

This makes sense to me, since pretty much every app would tend to have 
the builder_new()/add_from_file() sequence, so why not save some typing 
there. new_from_file() is also a common GTK convention. Adding multiple 
files seems like a relatively unusual thing to do.

For the other stuff:
  - set_translation_domain - is for libraries mostly right?
    (if it's for apps it seems a gtk-wide or glib-wide way to
     do this could make sense, vs. gtkbuilder-specific)
  - connect_signals - for apps who will use this feature, they're
    going to type this line every time... new_from_file_and_connect()?
    kinda clunky. But it sucks to have a boilerplate line everyone
    has to type.
  - get_object - getting multiple objects seems like the normal case,
    so piling one object name it into the convenience function seems
    wrong

A possible convenience API could be to have a global singleton builder 
or a hash of per-file builders and then something like:

  GtkWindow *window;
  GtkWindow *other_window;

  if (!gtk_builder_load_objects (DATADIR "/filename.glade",
                                 GTK_BUILDER_FLAGS_CONNECT_SIGNALS,
                                 "main-window", &window,
                                 "other-window", &other_window,
                                 NULL))
     g_error("My files are missing!");
Comment 1 Johan (not receiving bugmail) Dahlin 2007-06-24 20:46:27 UTC
Created attachment 90584 [details] [review]
patch

This patch adds an initial implementation of the suggested API. It also converts the demo to use it and some of the tests in buildertest.
Comment 2 Bastien Nocera 2007-06-27 09:28:48 UTC
Comment on attachment 90584 [details] [review]
patch

<snip>
>+ *                                 "fnobricator",

Should be frobnicator I believe.
Comment 3 Xavier Claessens 2007-10-13 22:16:25 UTC
Gossip has such helper functions internally and it's really useful!
Comment 4 Jaap A. Haitsma 2008-04-30 15:33:00 UTC
This seems a really useful addition. Any change of getting the patch in SVN?
Comment 5 Jaap A. Haitsma 2008-05-26 06:13:30 UTC
Ping. Johan is there something keeping you from committing this patch. It seems really useful to me
Comment 6 Johan (not receiving bugmail) Dahlin 2008-05-26 12:14:05 UTC
(In reply to comment #5)
> Ping. Johan is there something keeping you from committing this patch. It seems
> really useful to me

Yes, a couple of things are missing, these are on top of my head:
- refcounting needs to be figured, It's complicated since the factory function will return no references to a builder object, mainly documentation
- what about the use case of connecting signals with arguments? perhaps split into load_objects() and load_objects_and_connect()
- use it in the tests and write unittests specific for the load_objects() function.


Comment 7 Jaap A. Haitsma 2008-05-26 18:47:51 UTC
Johan, In your current patch you try to do everything in gtk_builder_load_objects. 

In the current implementation I think most of the pain is in having to call gtk_builder_get_object for every single widget.

Why not just implement a gtk_builder_get_objects function which calls gtk_builder_get_object over all the widgets you list in the arguments gtk_builder_get_objects. Most of the time the use of gtk_builder is something like this

builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, "blah.ui, &err);
gtk_builder_get_objects (builder, &err, 
                         "window1", &window, 
                         "button1", &button, 
                         NULL);
                         
connecting signals and setting translation domain people can do in the functions which they are used to use.


I think this solves the first two issues you mention and gtk_builder_get_objects would be really easy to cover with unit tests because it's a pretty simple function.

What do you think?
Comment 8 Matthias Clasen 2015-03-07 23:44:51 UTC
I think this has been superseded by template functionality, which is a more organized way to get objects out of ui files.