[gimp] libgimp, libgimpwidgets: more consistent API for widgets using a…



commit 8761d84aef6091bd8fbc91f6e0159f53160e24ad
Author: Jehan <jehan girinstud io>
Date:   Fri Jun 17 17:50:18 2022 +0200

    libgimp, libgimpwidgets: more consistent API for widgets using a…
    
    … GimpIntStore for value filling.
    
    GimpIntComboBox was not taking ownership of the value store whereas the
    newer GimpIntRadioFrame was taking ownership. As a more common practice,
    I decided to leave ownership to the caller (which will therefore have
    the responsibility to free the data) in the main class and property
    widget APIs.
    
    On the other hand, let's steal ownership of the store objects in the
    gimp_procedure_dialog_get_int_*() functions as these are really used for
    very quick and easy creation of dialogs by script writers. It would even
    allow to create a GimpIntStore inline within the widget creation
    function, if one wanted to.

 libgimp/gimpproceduredialog.c      | 28 ++++++++++++++++++++--------
 libgimpwidgets/gimpintradioframe.c |  5 ++---
 2 files changed, 22 insertions(+), 11 deletions(-)
---
diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c
index f92b919046..1e13c6b9cd 100644
--- a/libgimp/gimpproceduredialog.c
+++ b/libgimp/gimpproceduredialog.c
@@ -866,7 +866,7 @@ gimp_procedure_dialog_get_color_widget (GimpProcedureDialog *dialog,
  * @property: name of the int property to build a combo for. It must be
  *            a property of the #GimpProcedure @dialog has been created
  *            for.
- * @store:    the #GimpIntStore which will be used by the combo box.
+ * @store: (transfer full): the #GimpIntStore which will be used.
  *
  * Creates a new #GimpLabelIntWidget for @property which must
  * necessarily be an integer or boolean property.
@@ -888,20 +888,25 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
   GtkWidget  *widget = NULL;
   GParamSpec *pspec;
 
+  g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
   g_return_val_if_fail (property != NULL, NULL);
+  g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
 
   /* First check if it already exists. */
   widget = g_hash_table_lookup (dialog->priv->widgets, property);
 
   if (widget)
-    return widget;
+    {
+      g_object_unref (store);
+      return widget;
+    }
 
   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
                                         property);
   if (! pspec)
     {
-      g_warning ("%s: parameter %s does not exist.",
-                 G_STRFUNC, property);
+      g_warning ("%s: parameter %s does not exist.", G_STRFUNC, property);
+      g_object_unref (store);
       return NULL;
     }
 
@@ -915,6 +920,7 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
       widget = gimp_label_int_widget_new (_(g_param_spec_get_nick (pspec)),
                                           widget);
     }
+  g_object_unref (store);
 
   if (! widget)
     {
@@ -949,7 +955,7 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
  * @property: name of the int property to build radio buttons for. It
  *            must be a property of the #GimpProcedure @dialog has been
  *            created for.
- * @store: (transfer full): the #GimpIntStore which will be used..
+ * @store: (transfer full): the #GimpIntStore which will be used.
  *
  * Creates a new #GimpLabelIntRadioFrame for @property which must
  * necessarily be an integer, enum or boolean property.
@@ -972,20 +978,25 @@ gimp_procedure_dialog_get_int_radio (GimpProcedureDialog *dialog,
   GtkWidget  *widget = NULL;
   GParamSpec *pspec;
 
+  g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
   g_return_val_if_fail (property != NULL, NULL);
+  g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
 
   /* First check if it already exists. */
   widget = g_hash_table_lookup (dialog->priv->widgets, property);
 
   if (widget)
-    return widget;
+    {
+      g_object_unref (store);
+      return widget;
+    }
 
   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
                                         property);
   if (! pspec)
     {
-      g_warning ("%s: parameter %s does not exist.",
-                 G_STRFUNC, property);
+      g_warning ("%s: parameter %s does not exist.", G_STRFUNC, property);
+      g_object_unref (store);
       return NULL;
     }
 
@@ -997,6 +1008,7 @@ gimp_procedure_dialog_get_int_radio (GimpProcedureDialog *dialog,
       gtk_widget_set_vexpand (widget, FALSE);
       gtk_widget_set_hexpand (widget, TRUE);
     }
+  g_object_unref (store);
 
   if (! widget)
     {
diff --git a/libgimpwidgets/gimpintradioframe.c b/libgimpwidgets/gimpintradioframe.c
index 2e4eec3df0..4e0c1a826c 100644
--- a/libgimpwidgets/gimpintradioframe.c
+++ b/libgimpwidgets/gimpintradioframe.c
@@ -237,8 +237,7 @@ gimp_int_radio_frame_get_property (GObject    *object,
 /**
  * gimp_int_radio_frame_new_from_store:
  * @title: the frame label.
- * @store: (transfer full): the %GimpIntStore to generate radio buttons
- *                          from.
+ * @store: the %GimpIntStore to generate radio buttons from.
  *
  * Creates a %GimpIntRadioFrame containing radio buttons for each item
  * in the @store. The created widget takes ownership of @store.
@@ -704,7 +703,7 @@ gimp_int_radio_frame_set_store (GimpIntRadioFrame *frame,
       g_object_unref (priv->store);
     }
 
-  priv->store = store;
+  priv->store = g_object_ref (store);
 
   if (priv->store)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]