[gimp] app: get rid of GParameter and g_object_newv() (deprecated in GLib 2.54)
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: get rid of GParameter and g_object_newv() (deprecated in GLib 2.54)
- Date: Mon, 1 Jan 2018 14:22:30 +0000 (UTC)
commit 8df06eb5cd03c4d474a7e8c140d1c8c56ffc8e95
Author: Michael Natterer <mitch gimp org>
Date: Mon Jan 1 15:20:05 2018 +0100
app: get rid of GParameter and g_object_newv() (deprecated in GLib 2.54)
Replace gimp_parameter_*() utility functions with equivalent
gimp_properties_*() functions which deal with separate arrays of names
and values, and use g_object_new_with_properties() instead of
g_object_newv().
app/core/gimp-utils.c | 78 +++++++++++++++++++++++++++------------------
app/core/gimp-utils.h | 19 ++++++-----
app/core/gimpimage-undo.c | 35 ++++++++++++--------
app/gui/gui-vtable.c | 50 ++++++++++++++++-------------
4 files changed, 107 insertions(+), 75 deletions(-)
---
diff --git a/app/core/gimp-utils.c b/app/core/gimp-utils.c
index 0414cb9..836db20 100644
--- a/app/core/gimp-utils.c
+++ b/app/core/gimp-utils.c
@@ -236,37 +236,42 @@ gimp_get_default_unit (void)
return GIMP_UNIT_MM;
}
-GParameter *
-gimp_parameters_append (GType object_type,
- GParameter *params,
- gint *n_params,
+gchar **
+gimp_properties_append (GType object_type,
+ gint *n_properties,
+ gchar **names,
+ GValue **values,
...)
{
va_list args;
g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
- g_return_val_if_fail (n_params != NULL, NULL);
- g_return_val_if_fail (params != NULL || *n_params == 0, NULL);
+ g_return_val_if_fail (n_properties != NULL, NULL);
+ g_return_val_if_fail (names != NULL || *n_properties == 0, NULL);
+ g_return_val_if_fail (values != NULL || *n_properties == 0, NULL);
- va_start (args, n_params);
- params = gimp_parameters_append_valist (object_type, params, n_params, args);
+ va_start (args, values);
+ names = gimp_properties_append_valist (object_type, n_properties,
+ names, values, args);
va_end (args);
- return params;
+ return names;
}
-GParameter *
-gimp_parameters_append_valist (GType object_type,
- GParameter *params,
- gint *n_params,
- va_list args)
+gchar **
+gimp_properties_append_valist (GType object_type,
+ gint *n_properties,
+ gchar **names,
+ GValue **values,
+ va_list args)
{
GObjectClass *object_class;
gchar *param_name;
g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
- g_return_val_if_fail (n_params != NULL, NULL);
- g_return_val_if_fail (params != NULL || *n_params == 0, NULL);
+ g_return_val_if_fail (n_properties != NULL, NULL);
+ g_return_val_if_fail (names != NULL || *n_properties == 0, NULL);
+ g_return_val_if_fail (values != NULL || *n_properties == 0, NULL);
object_class = g_type_class_ref (object_type);
@@ -274,6 +279,7 @@ gimp_parameters_append_valist (GType object_type,
while (param_name)
{
+ GValue *value;
gchar *error = NULL;
GParamSpec *pspec = g_object_class_find_property (object_class,
param_name);
@@ -285,47 +291,57 @@ gimp_parameters_append_valist (GType object_type,
break;
}
- params = g_renew (GParameter, params, *n_params + 1);
+ names = g_renew (gchar *, names, *n_properties + 1);
+ *values = g_renew (GValue, *values, *n_properties + 1);
- params[*n_params].name = param_name;
- params[*n_params].value.g_type = 0;
+ value = &((*values)[*n_properties]);
- g_value_init (¶ms[*n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+ names[*n_properties] = g_strdup (param_name);
+ value->g_type = 0;
- G_VALUE_COLLECT (¶ms[*n_params].value, args, 0, &error);
+ g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+
+ G_VALUE_COLLECT (value, args, 0, &error);
if (error)
{
g_warning ("%s: %s", G_STRFUNC, error);
g_free (error);
- g_value_unset (¶ms[*n_params].value);
+ g_free (names[*n_properties]);
+ g_value_unset (value);
break;
}
- *n_params = *n_params + 1;
+ *n_properties = *n_properties + 1;
param_name = va_arg (args, gchar *);
}
g_type_class_unref (object_class);
- return params;
+ return names;
}
void
-gimp_parameters_free (GParameter *params,
- gint n_params)
+gimp_properties_free (gint n_properties,
+ gchar **names,
+ GValue *values)
{
- g_return_if_fail (params != NULL || n_params == 0);
+ g_return_if_fail (names != NULL || n_properties == 0);
+ g_return_if_fail (values != NULL || n_properties == 0);
- if (params)
+ if (names && values)
{
gint i;
- for (i = 0; i < n_params; i++)
- g_value_unset (¶ms[i].value);
+ for (i = 0; i < n_properties; i++)
+ {
+ g_free (names[i]);
+ g_value_unset (&values[i]);
+ }
- g_free (params);
+ g_free (names);
+ g_free (values);
}
}
diff --git a/app/core/gimp-utils.h b/app/core/gimp-utils.h
index 4c87949..ec5f604 100644
--- a/app/core/gimp-utils.h
+++ b/app/core/gimp-utils.h
@@ -38,16 +38,19 @@ gchar * gimp_get_backtrace (void);
gchar * gimp_get_default_language (const gchar *category);
GimpUnit gimp_get_default_unit (void);
-GParameter * gimp_parameters_append (GType object_type,
- GParameter *params,
- gint *n_params,
+gchar ** gimp_properties_append (GType object_type,
+ gint *n_properties,
+ gchar **names,
+ GValue **values,
...) G_GNUC_NULL_TERMINATED;
-GParameter * gimp_parameters_append_valist (GType object_type,
- GParameter *params,
- gint *n_params,
+gchar ** gimp_properties_append_valist (GType object_type,
+ gint *n_properties,
+ gchar **names,
+ GValue **values,
va_list args);
-void gimp_parameters_free (GParameter *params,
- gint n_params);
+void gimp_properties_free (gint n_properties,
+ gchar **names,
+ GValue *values);
gchar * gimp_markup_extract_text (const gchar *markup);
diff --git a/app/core/gimpimage-undo.c b/app/core/gimpimage-undo.c
index f1d5cb1..f570b68 100644
--- a/app/core/gimpimage-undo.c
+++ b/app/core/gimpimage-undo.c
@@ -360,11 +360,12 @@ gimp_image_undo_push (GimpImage *image,
GimpDirtyMask dirty_mask,
...)
{
- GimpImagePrivate *private;
- GParameter *params = NULL;
- gint n_params = 0;
- va_list args;
- GimpUndo *undo;
+ GimpImagePrivate *private;
+ gint n_properties = 0;
+ gchar **names = NULL;
+ GValue *values = NULL;
+ va_list args;
+ GimpUndo *undo;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (g_type_is_a (object_type, GIMP_TYPE_UNDO), NULL);
@@ -384,20 +385,26 @@ gimp_image_undo_push (GimpImage *image,
if (! name)
name = gimp_undo_type_to_name (undo_type);
- params = gimp_parameters_append (object_type, params, &n_params,
- "name", name,
- "image", image,
- "undo-type", undo_type,
- "dirty-mask", dirty_mask,
- NULL);
+ names = gimp_properties_append (object_type,
+ &n_properties, names, &values,
+ "name", name,
+ "image", image,
+ "undo-type", undo_type,
+ "dirty-mask", dirty_mask,
+ NULL);
va_start (args, dirty_mask);
- params = gimp_parameters_append_valist (object_type, params, &n_params, args);
+ names = gimp_properties_append_valist (object_type,
+ &n_properties, names, &values,
+ args);
va_end (args);
- undo = g_object_newv (object_type, n_params, params);
+ undo = (GimpUndo *) g_object_new_with_properties (object_type,
+ n_properties,
+ (const gchar **) names,
+ (const GValue *) values);
- gimp_parameters_free (params, n_params);
+ gimp_properties_free (n_properties, names, values);
/* nuke the redo stack */
gimp_image_undo_free_redo (image);
diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c
index faad737..e333c3d 100644
--- a/app/gui/gui-vtable.c
+++ b/app/gui/gui-vtable.c
@@ -519,31 +519,37 @@ gui_pdb_dialog_new (Gimp *gimp,
if (object)
{
- GParameter *params = NULL;
- gint n_params = 0;
+ gint n_properties = 0;
+ gchar **names = NULL;
+ GValue *values = NULL;
GtkWidget *dialog;
GtkWidget *view;
- params = gimp_parameters_append (dialog_type, params, &n_params,
- "title", title,
- "role", dialog_role,
- "help-func", gimp_standard_help_func,
- "help-id", help_id,
- "pdb", gimp->pdb,
- "context", context,
- "select-type", gimp_container_get_children_type (container),
- "initial-object", object,
- "callback-name", callback_name,
- "menu-factory", global_menu_factory,
- NULL);
-
- params = gimp_parameters_append_valist (dialog_type,
- params, &n_params,
- args);
-
- dialog = g_object_newv (dialog_type, n_params, params);
-
- gimp_parameters_free (params, n_params);
+ names = gimp_properties_append (dialog_type,
+ &n_properties, names, &values,
+ "title", title,
+ "role", dialog_role,
+ "help-func", gimp_standard_help_func,
+ "help-id", help_id,
+ "pdb", gimp->pdb,
+ "context", context,
+ "select-type", gimp_container_get_children_type (container),
+ "initial-object", object,
+ "callback-name", callback_name,
+ "menu-factory", global_menu_factory,
+ NULL);
+
+ names = gimp_properties_append_valist (dialog_type,
+ &n_properties, names, &values,
+ args);
+
+ dialog = (GtkWidget *)
+ g_object_new_with_properties (dialog_type,
+ n_properties,
+ (const gchar **) names,
+ (const GValue *) values);
+
+ gimp_properties_free (n_properties, names, values);
view = GIMP_PDB_DIALOG (dialog)->view;
if (view)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]