GNOME Bugzilla – Bug 597669
Add convenience functions for retrieving object properties that have a fundamental C-type
Last modified: 2010-09-03 22:19:10 UTC
About to attach a patch for adding functions such as: g_object_get_int, g_object_get_char, g_object_get_double, etc. IOW, any type such that the return value doesn't require special handling.
Created attachment 144950 [details] [review] Patch against master to add convenience functions. The motivation behind this patch is to allow various types of objects implementing a property with a given name and identical semantics to be treated identically. For example, in GTK, the followings all have a _get_active() API: GtkToggleButton GtkCellRendererToggle GtkCheckMenuItem GtkToggleToolButton GtkToggleAction Unfortunately, if due to design changes a projects moves from one widget to another, all old_widget_get_active calls have to be sed-ed to new_widget_get_active calls. This is fine for upstream, but a downstream project does not have this luxury without introducing an enormous delta. The solution is to use these convenience functions, making those portions of the code widget-independent. A change such as this has a chance of making it upstream. My personal plight: Porting Pidgin to Maemo 5, replacing GtkCheckButton widgets with HildonCheckButton widgets.
I don't think this is a very strong argument for adding gobject api. You can just use g_object_get...
The problem with g_object_get is that it cannot be nested. All the *_get_active functions I listed return a boolean, which makes them very convenient for nesting. In fact, all the calls to gtk accessors could be replaced with these convenience functions, making all applications slightly less dependent on gtk and/or specific gtk widgets. For another example, look at gconf: gconf_client_get_bool, gconf_client_get_int, etc. Extremely convenient.
For slightly related reference: http://mail.gnome.org/archives/gtk-devel-list/2009-April/msg00150.html Especially: http://mail.gnome.org/archives/gtk-devel-list/2009-April/msg00152.html (The remark about int get_x()) What that thread misses is the potential for nesting simple function calls like this. This is the feature that in turn could drive widget-choice-independence.
*** This bug has been marked as a duplicate of bug 541569 ***