[gthumb] do not use g_ptr_array_copy to avoid a dependency on glib 2.62



commit 004b31741a920e4e9ca6af24c7358a635fbe5080
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Mar 8 12:53:16 2020 +0100

    do not use g_ptr_array_copy to avoid a dependency on glib 2.62

 extensions/list_tools/dlg-personalize-scripts.c |  8 ++++----
 gthumb/dlg-preferences-shortcuts.c              |  3 +--
 gthumb/glib-utils.c                             | 26 +++++++++++++++++++++++++
 gthumb/glib-utils.h                             |  3 +++
 4 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/extensions/list_tools/dlg-personalize-scripts.c b/extensions/list_tools/dlg-personalize-scripts.c
index 6737adcd..8c4977d0 100644
--- a/extensions/list_tools/dlg-personalize-scripts.c
+++ b/extensions/list_tools/dlg-personalize-scripts.c
@@ -372,9 +372,9 @@ script_editor_dialog__response_cb (GtkDialog *dialog,
 
        /* update the shortcuts */
 
-       shortcuts_v = g_ptr_array_copy (gth_window_get_shortcuts (GTH_WINDOW (data->browser)),
+       shortcuts_v = _g_ptr_array_dup (gth_window_get_shortcuts (GTH_WINDOW (data->browser)),
                                        (GCopyFunc) gth_shortcut_dup,
-                                       NULL);
+                                       (GDestroyNotify) gth_shortcut_free);
 
        /* If another shortcut has the same accelerator, reset the accelerator
         * for that shortcut. */
@@ -522,9 +522,9 @@ delete_script_cb (GtkButton  *button,
 
        /* update the shortcuts */
 
-       shortcuts_v = g_ptr_array_copy (gth_window_get_shortcuts (GTH_WINDOW (data->browser)),
+       shortcuts_v = _g_ptr_array_dup (gth_window_get_shortcuts (GTH_WINDOW (data->browser)),
                                        (GCopyFunc) gth_shortcut_dup,
-                                       NULL);
+                                       (GDestroyNotify) gth_shortcut_free);
 
        shortcut = gth_shortcut_array_find_by_action (shortcuts_v, gth_script_get_detailed_action (script));
        if (shortcut != NULL)
diff --git a/gthumb/dlg-preferences-shortcuts.c b/gthumb/dlg-preferences-shortcuts.c
index 80f8f437..6d635a59 100644
--- a/gthumb/dlg-preferences-shortcuts.c
+++ b/gthumb/dlg-preferences-shortcuts.c
@@ -529,8 +529,7 @@ shortcuts__dlg_preferences_construct_cb (GtkWidget  *dialog,
                GtkTreeIter   iter;
                int           i;
 
-               category_v = g_ptr_array_copy (gth_main_get_shortcut_categories (), NULL, NULL);
-               g_ptr_array_set_free_func (category_v, NULL);
+               category_v = _g_ptr_array_dup (gth_main_get_shortcut_categories (), NULL, NULL);
                g_ptr_array_sort (category_v, cmp_category);
 
                list_store = (GtkListStore *) gtk_builder_get_object (data->builder, "category_liststore");
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index 6dbbcd4d..31b91091 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -853,6 +853,32 @@ _g_string_array_join (GPtrArray  *array,
 }
 
 
+GPtrArray *
+_g_ptr_array_dup (GPtrArray     *array,
+                 GCopyFunc       copy_func,
+                 GDestroyNotify  free_func)
+{
+       GPtrArray *new_array;
+       int        i;
+
+       g_return_val_if_fail (array != NULL, NULL);
+
+       new_array = g_ptr_array_sized_new (array->len);
+       g_ptr_array_set_free_func (new_array, free_func);
+
+       if (copy_func != NULL)
+               for (i = 0; i < array->len; i++)
+                       new_array->pdata[i] = copy_func (array->pdata[i], NULL);
+       else
+               for (i = 0; i < array->len; i++)
+                       new_array->pdata[i] = array->pdata[i];
+
+       new_array->len = array->len;
+
+       return new_array;
+}
+
+
 /* Regexp utils */
 
 
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 7a8f6f4f..879187b7 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -213,6 +213,9 @@ GType               g_string_list_get_type          (void);
 
 char *         _g_string_array_join            (GPtrArray       *array,
                                                 const char      *separator);
+GPtrArray *    _g_ptr_array_dup                (GPtrArray       *array,
+                                                GCopyFunc        copy_func,
+                                                GDestroyNotify   free_func);
 
 /* Regexp utils */
 


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