[nautilus/undo-manager] undostack-actions: remove useless URI/GFile roundtrips



commit c83109a8a72df924ec2d69a0c4188b18b0fcedf9
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Dec 7 16:51:32 2010 +0100

    undostack-actions: remove useless URI/GFile roundtrips

 libnautilus-private/nautilus-undostack-actions.c |   73 ++++++----------------
 1 files changed, 20 insertions(+), 53 deletions(-)
---
diff --git a/libnautilus-private/nautilus-undostack-actions.c b/libnautilus-private/nautilus-undostack-actions.c
index c70fa23..55db010 100644
--- a/libnautilus-private/nautilus-undostack-actions.c
+++ b/libnautilus-private/nautilus-undostack-actions.c
@@ -52,11 +52,11 @@ nautilus_undo_stack_action_data_free (NautilusUndoStackActionData *action)
 	g_free (action->new_name);
 
 	if (action->sources) {
-		g_list_free_full (action->sources, g_free);
+		g_list_free_full (action->sources, g_object_unref);
 	}
 
 	if (action->destinations) {
-		g_list_free_full (action->destinations, g_free);
+		g_list_free_full (action->destinations, g_object_unref);
 	}
 
 	if (action->trashed) {
@@ -81,12 +81,14 @@ static char *
 get_first_target_short_name (NautilusUndoStackActionData *action)
 {
 	GList *targets_first;
-	char *file_name;
-
-	g_assert (action != NULL);
+	char *file_name = NULL;
 
 	targets_first = g_list_first (action->destinations);
-	file_name = g_strdup (targets_first->data);
+
+	if (targets_first != NULL &&
+	    targets_first->data != NULL) {
+		file_name = g_file_get_basename (targets_first->data);
+	}
 
 	return file_name;
 }
@@ -106,21 +108,6 @@ uri_list_to_gfile_list (GList * urilist)
 	return file_list;
 }
 
-static GList *
-construct_gfile_list (const GList * urilist, GFile * parent)
-{
-	const GList *l;
-	GList *file_list = NULL;
-	GFile *file;
-
-	for (l = urilist; l != NULL; l = l->next) {
-		file = g_file_get_child (parent, l->data);
-		file_list = g_list_append (file_list, file);
-	}
-
-	return file_list;
-}
-
 /* TODO: Synch-I/O, error handling */
 static GHashTable *
 retrieve_files_to_restore (GHashTable * trashed)
@@ -258,24 +245,19 @@ copy_or_link_undo_func (UndoData *action)
 {
 	GList *files;
 
-	files = construct_gfile_list (action->destinations, action->dest_dir);
+	files = g_list_copy (action->destinations);
 	files = g_list_reverse (files); /* Deleting must be done in reverse */
 
 	delete_files (action->manager, files, action);
 
-	g_list_free_full (files, g_object_unref);
+	g_list_free (files);
 }
 
 static void
 restore_undo_func (UndoData *action)
 {
-	GList *uris;
-
-	uris = construct_gfile_list (action->destinations, action->dest_dir);
-	nautilus_file_operations_trash_or_delete (uris, NULL,
+	nautilus_file_operations_trash_or_delete (action->destinations, NULL,
 						  undo_redo_done_delete_callback, action);
-
-	g_list_free_full (uris, g_object_unref);
 }
 
 static void
@@ -320,14 +302,9 @@ trash_undo_func (UndoData *action)
 static void
 move_undo_func (UndoData *action)
 {
-	GList *uris;
-
-	uris = construct_gfile_list (action->destinations, action->dest_dir);
-	nautilus_file_operations_move (uris, NULL,
+	nautilus_file_operations_move (action->destinations, NULL,
 				       action->src_dir, NULL,
 				       undo_redo_done_transfer_callback, action);
-
-	g_list_free_full (uris, g_object_unref);
 }
 
 static void
@@ -427,12 +404,10 @@ copy_redo_func (UndoData *action)
 {
 	GList *locations;
 
-	locations = construct_gfile_list (action->sources, action->src_dir);
+	locations = action->sources;
 	nautilus_file_operations_copy (locations, NULL,
 				       action->dest_dir, NULL,
 				       undo_redo_done_transfer_callback, action);
-
-	g_list_free_full (locations, g_object_unref);
 }
 
 static void
@@ -459,11 +434,9 @@ duplicate_redo_func (UndoData *action)
 {
 	GList *locations;
 
-	locations = construct_gfile_list (action->sources, action->src_dir);
+	locations = action->sources;
 	nautilus_file_operations_duplicate (locations, NULL, NULL,
 					    undo_redo_done_transfer_callback, action);
-
-	g_list_free_full (locations, g_object_unref);
 }
 
 static void
@@ -471,12 +444,10 @@ move_restore_redo_func (UndoData *action)
 {
 	GList *locations;
 
-	locations = construct_gfile_list (action->sources, action->src_dir);
+	locations = action->sources;
 	nautilus_file_operations_move (locations, NULL,
 				       action->dest_dir, NULL,
 				       undo_redo_done_transfer_callback, action);
-
-	g_list_free_full (locations, g_object_unref);
 }
 
 static void
@@ -549,11 +520,10 @@ create_link_redo_func (UndoData *action)
 {
 	GList *locations;
 
-	locations = construct_gfile_list (action->sources, action->src_dir);
+	locations = action->sources;
 	nautilus_file_operations_link (locations, NULL,
 				       action->dest_dir, NULL,
 				       undo_redo_done_transfer_callback, action);
-	g_list_free_full (locations, g_object_unref);
 }
 
 static void
@@ -1056,13 +1026,10 @@ nautilus_undo_stack_action_data_add_origin_target_pair (NautilusUndoStackActionD
                                                         GFile                       *origin,
                                                         GFile                       *target)
 {
-	char *src_relative;
-	char *dest_relative;
-
-	src_relative = g_file_get_relative_path (action_data->src_dir, origin);
-	action_data->sources = g_list_append (action_data->sources, src_relative);
-	dest_relative = g_file_get_relative_path (action_data->dest_dir, target);
-	action_data->destinations = g_list_append (action_data->destinations, dest_relative);
+	action_data->sources =
+		g_list_append (action_data->sources, g_object_ref (origin));
+	action_data->destinations =
+		g_list_append (action_data->destinations, g_object_ref (target));
 
 	action_data->is_valid = TRUE;
 }



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