[Xfce4-commits] <thunar:master> Uniform the deep copy function.
Nick Schermer
noreply at xfce.org
Mon Oct 22 20:42:03 CEST 2012
Updating branch refs/heads/master
to 5a0fd479b4a6e87ff9dea1597386ba935bf2aa6d (commit)
from 7012c86e217454141e24f7d819c4a93178a01c1f (commit)
commit 5a0fd479b4a6e87ff9dea1597386ba935bf2aa6d
Author: Nick Schermer <nick at xfce.org>
Date: Mon Oct 22 20:38:58 2012 +0200
Uniform the deep copy function.
There were 2 versions used. Use the one in thunarx
and use marcos for deep appending/prepending.
thunar/thunar-application.c | 8 ++--
thunar/thunar-dbus-service.c | 2 +-
thunar/thunar-file.h | 23 ---------------
thunar/thunar-folder.c | 10 +++---
thunar/thunar-gio-extensions.c | 60 ----------------------------------------
thunar/thunar-gio-extensions.h | 12 ++++----
thunar/thunar-io-jobs.c | 2 +-
thunar/thunar-launcher.c | 12 ++++----
thunar/thunar-misc-jobs.c | 2 +-
thunar/thunar-shortcuts-pane.c | 8 ++--
thunar/thunar-standard-view.c | 12 ++++----
thunarx/thunarx-file-info.c | 16 +++++-----
12 files changed, 42 insertions(+), 125 deletions(-)
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index c2d499b..f31a277 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -248,7 +248,7 @@ thunar_application_finalize (GObject *object)
GList *lp;
/* unqueue all files waiting to be processed */
- thunar_file_list_free (application->files_to_launch);
+ thunar_g_file_list_free (application->files_to_launch);
/* save the current accel map */
path = xfce_resource_save_location (XFCE_RESOURCE_CONFIG, "Thunar/accels.scm", TRUE);
@@ -1040,7 +1040,7 @@ thunar_application_bulk_rename (ThunarApplication *application,
/* cleanup */
g_object_unref (G_OBJECT (current_directory));
- thunar_file_list_free (file_list);
+ thunar_g_file_list_free (file_list);
return result;
}
@@ -1102,7 +1102,7 @@ thunar_application_process_files_finish (ThunarBrowser *browser,
}
/* stop processing files */
- thunar_file_list_free (application->files_to_launch);
+ thunar_g_file_list_free (application->files_to_launch);
application->files_to_launch = NULL;
}
else
@@ -1230,7 +1230,7 @@ thunar_application_process_filenames (ThunarApplication *application,
_("Failed to open \"%s\": %s"), filenames[n], derror->message);
g_error_free (derror);
- thunar_file_list_free (file_list);
+ thunar_g_file_list_free (file_list);
return FALSE;
}
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index 2e81061..30eba1b 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -1297,7 +1297,7 @@ thunar_dbus_service_unlink_files (ThunarDBusService *dbus_service,
}
/* cleanup */
- thunar_file_list_free (file_list);
+ thunar_g_file_list_free (file_list);
g_object_unref (screen);
}
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 1238084..be742a9 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -307,29 +307,6 @@ G_STMT_START{ \
thunarx_file_info_changed (THUNARX_FILE_INFO ((file))); \
}G_STMT_END
-/**
- * thunar_file_list_copy:
- * @file_list : a list of #ThunarFile<!---->s.
- *
- * Returns a deep-copy of @file_list, which must be
- * freed using thunar_file_list_free().
- *
- * Return value: a deep copy of @file_list.
- **/
-#define thunar_file_list_copy(file_list) (thunarx_file_info_list_copy ((file_list)))
-
-/**
- * thunar_file_list_free:
- * @file_list : a list of #ThunarFile<!---->s.
- *
- * Unrefs the #ThunarFile<!---->s contained in @file_list
- * and frees the list itself.
- **/
-#define thunar_file_list_free(file_list) \
-G_STMT_START{ \
- thunarx_file_info_list_free ((file_list)); \
-}G_STMT_END
-
G_END_DECLS;
diff --git a/thunar/thunar-folder.c b/thunar/thunar-folder.c
index 7faaa23..5cbadb5 100644
--- a/thunar/thunar-folder.c
+++ b/thunar/thunar-folder.c
@@ -300,10 +300,10 @@ thunar_folder_finalize (GObject *object)
}
/* release references to the new files */
- thunar_file_list_free (folder->new_files);
+ thunar_g_file_list_free (folder->new_files);
/* release references to the current files */
- thunar_file_list_free (folder->files);
+ thunar_g_file_list_free (folder->files);
(*G_OBJECT_CLASS (thunar_folder_parent_class)->finalize) (object);
}
@@ -467,11 +467,11 @@ thunar_folder_finished (ExoJob *job,
g_signal_emit (G_OBJECT (folder), folder_signals[FILES_REMOVED], 0, files);
/* release the removed files list */
- thunar_file_list_free (files);
+ thunar_g_file_list_free (files);
}
/* drop the temporary new_files list */
- thunar_file_list_free (folder->new_files);
+ thunar_g_file_list_free (folder->new_files);
folder->new_files = NULL;
}
else
@@ -832,7 +832,7 @@ thunar_folder_reload (ThunarFolder *folder)
}
/* reset the new_files list */
- thunar_file_list_free (folder->new_files);
+ thunar_g_file_list_free (folder->new_files);
folder->new_files = NULL;
/* start a new job */
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 9968feb..65f3f53 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -428,66 +428,6 @@ thunar_g_file_list_to_stringv (GList *list)
-GList *
-thunar_g_file_list_append (GList *list,
- GFile *file)
-{
- return g_list_append (list, g_object_ref (file));
-}
-
-
-
-GList *
-thunar_g_file_list_prepend (GList *list,
- GFile *file)
-{
- return g_list_prepend (list, g_object_ref (file));
-}
-
-
-
-/**
- * thunar_g_file_list_copy:
- * @list : a list of #GFile<!---->s.
- *
- * Takes a deep copy of @list and returns the
- * result. The caller is responsible to free the
- * returned list using thunar_g_file_list_free().
- *
- * Return value: a deep copy of @list.
- **/
-GList*
-thunar_g_file_list_copy (GList *list)
-{
- GList *copy = NULL;
- GList *lp;
-
- for (lp = g_list_last (list); lp != NULL; lp = lp->prev)
- copy = g_list_prepend (copy, g_object_ref (lp->data));
-
- return copy;
-}
-
-
-
-/**
- * thunar_g_file_list_free:
- * @list : a list of #GFile<!---->s.
- *
- * Frees the #GFile<!---->s in @list and
- * the @list itself.
- **/
-void
-thunar_g_file_list_free (GList *list)
-{
- GList *lp;
- for (lp = list; lp != NULL; lp = lp->next)
- g_object_unref (lp->data);
- g_list_free (list);
-}
-
-
-
gboolean
thunar_g_app_info_launch (GAppInfo *info,
GFile *working_directory,
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 4fa79d4..f27832e 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -64,12 +64,12 @@ GType thunar_g_file_list_get_type (void);
GList *thunar_g_file_list_new_from_string (const gchar *string);
gchar **thunar_g_file_list_to_stringv (GList *list);
gchar *thunar_g_file_list_to_string (GList *list);
-GList *thunar_g_file_list_append (GList *list,
- GFile *file);
-GList *thunar_g_file_list_prepend (GList *list,
- GFile *file);
-GList *thunar_g_file_list_copy (GList *list);
-void thunar_g_file_list_free (GList *list);
+
+/* deep copy jobs for GLists */
+#define thunar_g_file_list_append(list,object) g_list_append (list, g_object_ref (G_OBJECT (object)))
+#define thunar_g_file_list_prepend(list,object) g_list_prepend (list, g_object_ref (G_OBJECT (object)))
+#define thunar_g_file_list_copy thunarx_file_info_list_copy
+#define thunar_g_file_list_free thunarx_file_info_list_free
gboolean thunar_g_app_info_launch (GAppInfo *info,
GFile *working_directory,
diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c
index 4f2d540..d5350f7 100644
--- a/thunar/thunar-io-jobs.c
+++ b/thunar/thunar-io-jobs.c
@@ -1229,7 +1229,7 @@ _thunar_io_jobs_ls (ThunarJob *job,
{
/* none of the handlers took over the file list, so it's up to us
* to destroy it */
- thunar_file_list_free (file_list);
+ thunar_g_file_list_free (file_list);
}
}
diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c
index 644b7b6..b63407b 100644
--- a/thunar/thunar-launcher.c
+++ b/thunar/thunar-launcher.c
@@ -282,7 +282,7 @@ thunar_launcher_dispose (GObject *object)
thunar_launcher_set_widget (THUNAR_LAUNCHER (launcher), NULL);
/* disconnect from the currently selected files */
- thunar_file_list_free (launcher->selected_files);
+ thunar_g_file_list_free (launcher->selected_files);
launcher->selected_files = NULL;
(*G_OBJECT_CLASS (thunar_launcher_parent_class)->dispose) (object);
@@ -438,10 +438,10 @@ thunar_launcher_set_selected_files (ThunarComponent *component,
if (G_UNLIKELY (np != NULL || op != NULL))
{
/* disconnect from the previously selected files */
- thunar_file_list_free (launcher->selected_files);
+ thunar_g_file_list_free (launcher->selected_files);
/* connect to the new selected files list */
- launcher->selected_files = thunar_file_list_copy (selected_files);
+ launcher->selected_files = thunar_g_file_list_copy (selected_files);
/* update the launcher actions */
thunar_launcher_update (launcher);
@@ -1299,7 +1299,7 @@ thunar_launcher_poke_data_new (GList *files)
ThunarLauncherPokeData *data;
data = g_slice_new0 (ThunarLauncherPokeData);
- data->files = thunar_file_list_copy (files);
+ data->files = thunar_g_file_list_copy (files);
data->resolved_files = NULL;
return data;
@@ -1312,8 +1312,8 @@ thunar_launcher_poke_data_free (ThunarLauncherPokeData *data)
{
_thunar_return_if_fail (data != NULL);
- thunar_file_list_free (data->files);
- thunar_file_list_free (data->resolved_files);
+ thunar_g_file_list_free (data->files);
+ thunar_g_file_list_free (data->resolved_files);
g_slice_free (ThunarLauncherPokeData, data);
}
diff --git a/thunar/thunar-misc-jobs.c b/thunar/thunar-misc-jobs.c
index a541803..7938606 100644
--- a/thunar/thunar-misc-jobs.c
+++ b/thunar/thunar-misc-jobs.c
@@ -88,7 +88,7 @@ _thunar_misc_jobs_load_templates (ThunarJob *job,
else
{
if (!thunar_job_files_ready (job, files))
- thunar_file_list_free (files);
+ thunar_g_file_list_free (files);
return TRUE;
}
diff --git a/thunar/thunar-shortcuts-pane.c b/thunar/thunar-shortcuts-pane.c
index cbc545c..4f02ae6 100644
--- a/thunar/thunar-shortcuts-pane.c
+++ b/thunar/thunar-shortcuts-pane.c
@@ -331,10 +331,10 @@ thunar_shortcuts_pane_set_selected_files (ThunarComponent *component,
gint n;
/* disconnect from the previously selected files... */
- thunar_file_list_free (shortcuts_pane->selected_files);
+ thunar_g_file_list_free (shortcuts_pane->selected_files);
/* ...and take a copy of the newly selected files */
- shortcuts_pane->selected_files = thunar_file_list_copy (selected_files);
+ shortcuts_pane->selected_files = thunar_g_file_list_copy (selected_files);
/* check if the selection contains only folders */
for (lp = selected_files, n = 0; lp != NULL; lp = lp->next, ++n)
@@ -457,8 +457,8 @@ thunar_shortcuts_pane_action_shortcuts_add (GtkAction *action,
}
/* update the user interface to reflect the new action state */
- lp = thunar_file_list_copy (shortcuts_pane->selected_files);
+ lp = thunar_g_file_list_copy (shortcuts_pane->selected_files);
thunar_component_set_selected_files (THUNAR_COMPONENT (shortcuts_pane), lp);
- thunar_file_list_free (lp);
+ thunar_g_file_list_free (lp);
}
}
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 4677f8c..f04e2cf 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -753,7 +753,7 @@ thunar_standard_view_finalize (GObject *object)
g_object_unref (G_OBJECT (standard_view->priv->scroll_to_file));
/* release the selected_files list (if any) */
- thunar_file_list_free (standard_view->priv->selected_files);
+ thunar_g_file_list_free (standard_view->priv->selected_files);
/* release our reference on the provider factory */
g_object_unref (G_OBJECT (standard_view->priv->provider_factory));
@@ -1008,7 +1008,7 @@ thunar_standard_view_set_selected_files (ThunarComponent *component,
/* release the previous selected files list (if any) */
if (G_UNLIKELY (standard_view->priv->selected_files != NULL))
{
- thunar_file_list_free (standard_view->priv->selected_files);
+ thunar_g_file_list_free (standard_view->priv->selected_files);
standard_view->priv->selected_files = NULL;
}
@@ -1016,7 +1016,7 @@ thunar_standard_view_set_selected_files (ThunarComponent *component,
if (thunar_view_get_loading (THUNAR_VIEW (standard_view)))
{
/* remember a copy of the list for later */
- standard_view->priv->selected_files = thunar_file_list_copy (selected_files);
+ standard_view->priv->selected_files = thunar_g_file_list_copy (selected_files);
}
else
{
@@ -1313,7 +1313,7 @@ thunar_standard_view_set_loading (ThunarStandardView *standard_view,
thunar_component_set_selected_files (THUNAR_COMPONENT (standard_view), selected_files);
/* cleanup */
- thunar_file_list_free (selected_files);
+ thunar_g_file_list_free (selected_files);
}
/* check if we're done loading and a thumbnail timeout or idle was requested */
@@ -1742,7 +1742,7 @@ thunar_standard_view_merge_custom_actions (ThunarStandardView *standard_view,
/* cleanup the selected files list (if any) */
if (G_LIKELY (files != NULL))
- thunar_file_list_free (files);
+ thunar_g_file_list_free (files);
}
/* remove the previously determined menu actions from the UI manager */
@@ -3506,7 +3506,7 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view)
}
/* release the previously selected files */
- thunar_file_list_free (standard_view->priv->selected_files);
+ thunar_g_file_list_free (standard_view->priv->selected_files);
/* determine the new list of selected files (replacing GtkTreePath's with ThunarFile's) */
selected_files = (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->get_selected_items) (standard_view);
diff --git a/thunarx/thunarx-file-info.c b/thunarx/thunarx-file-info.c
index 60c8dcf..623560a 100644
--- a/thunarx/thunarx-file-info.c
+++ b/thunarx/thunarx-file-info.c
@@ -418,16 +418,16 @@ thunarx_file_info_list_get_type (void)
GList*
thunarx_file_info_list_copy (GList *file_infos)
{
- GList *list = NULL;
- GList *lp;
+#if GLIB_CHECK_VERSION (2, 34, 0)
+ return g_list_copy_deep (file_infos, (GCopyFunc) g_object_ref, NULL);
+#else
+ GList *copy;
- if (file_infos != NULL)
- {
- for (lp = g_list_last (file_infos); lp != NULL; lp = lp->prev)
- list = g_list_prepend (list, g_object_ref (G_OBJECT (lp->data)));
- }
+ copy = g_list_copy (file_infos);
+ g_list_foreach (copy, (GFunc) g_object_ref, NULL);
- return list;
+ return copy;
+#endif
}
More information about the Xfce4-commits
mailing list