[nautilus/undo-manager: 97/98] undo-actions: fix some refcounting issues



commit 181d523c52b04c1bf24086023eb3beb02b2ba056
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Dec 7 13:03:41 2010 +0100

    undo-actions: fix some refcounting issues
    
    And simplify the code a bit.

 libnautilus-private/nautilus-undostack-actions.c |   65 ++++++----------------
 1 files changed, 18 insertions(+), 47 deletions(-)
---
diff --git a/libnautilus-private/nautilus-undostack-actions.c b/libnautilus-private/nautilus-undostack-actions.c
index 8eaf2b4..c70fa23 100644
--- a/libnautilus-private/nautilus-undostack-actions.c
+++ b/libnautilus-private/nautilus-undostack-actions.c
@@ -107,18 +107,6 @@ uri_list_to_gfile_list (GList * urilist)
 }
 
 static GList *
-construct_gfile_list_from_uri (char *uri)
-{
-	GList *file_list = NULL;
-	GFile *file;
-
-	file = g_file_new_for_uri (uri);
-	file_list = g_list_append (file_list, file);
-
-	return file_list;
-}
-
-static GList *
 construct_gfile_list (const GList * urilist, GFile * parent)
 {
 	const GList *l;
@@ -246,53 +234,36 @@ undo_redo_op_callback (gpointer callback_data)
 /* undo helpers */
 
 static void
-delete_uris (NautilusUndoStackManager *self,
-	     GList *uris,
-	     UndoData *action)
+delete_files (NautilusUndoStackManager *self,
+	      GList *files,
+	      UndoData *action)
 {
-	if (self->priv->confirm_delete) {
-		nautilus_file_operations_delete (uris, NULL,
-						 undo_redo_done_delete_callback, action);
-	} else {
-		self->priv->undo_redo_flag = FALSE;
-
-		/* We skip the confirmation message */
-		GList *f;
-		for (f = uris; f != NULL; f = f->next) {
-			g_file_delete (f->data, NULL, NULL);
-		}
-
-		/* Here we must do what's necessary for the callback */
-		undo_redo_done_transfer_callback (NULL, action);
-	}
+	nautilus_file_operations_delete (files, NULL,
+					 undo_redo_done_delete_callback, action);
 }
 
 static void
 create_undo_func (UndoData *action)
 {
-	GList *uris;
-	gchar *uri;
-
-	uri = g_file_get_uri (action->target_file);
-	uris = construct_gfile_list_from_uri (uri);
+	GList *files = NULL;
 
-	delete_uris (action->manager, uris, action);
+	files = g_list_append (files, g_object_ref (action->target_file));
+	delete_files (action->manager, files, action);
 
-	g_free (uri);
-	g_list_free_full (uris, g_object_unref);
+	g_list_free_full (files, g_object_unref);
 }
 
 static void
 copy_or_link_undo_func (UndoData *action)
 {
-	GList *uris;
+	GList *files;
 
-	uris = construct_gfile_list (action->destinations, action->dest_dir);
-	uris = g_list_reverse (uris); /* Deleting must be done in reverse */
+	files = construct_gfile_list (action->destinations, action->dest_dir);
+	files = g_list_reverse (files); /* Deleting must be done in reverse */
 
-	delete_uris (action->manager, uris, action);
+	delete_files (action->manager, files, action);
 
-	g_list_free_full (uris, g_object_unref);
+	g_list_free_full (files, g_object_unref);
 }
 
 static void
@@ -852,12 +823,12 @@ trash_description_func (UndoData *action,
 		g_free (name);
 		g_free (orig_path);
 		g_list_free (keys);
-		g_object_unref (file);
 
-		name = g_file_get_parse_name (action->target_file);
+		name = g_file_get_parse_name (file);
 		descriptions[1] = g_strdup_printf (_("Move '%s' to trash"), name);
 
 		g_free (name);
+		g_object_unref (file);
 
 		labels[0] = g_strdup (_("_Undo Trash"));
 		labels[1] = g_strdup (_("_Redo Trash"));
@@ -1070,14 +1041,14 @@ void
 nautilus_undo_stack_action_data_set_src_dir (NautilusUndoStackActionData *action_data,
                                              GFile                       *src)
 {
-	action_data->src_dir = src;
+	action_data->src_dir = g_object_ref (src);
 }
 
 void
 nautilus_undo_stack_action_data_set_dest_dir (NautilusUndoStackActionData *action_data,
                                               GFile                       *dest)
 {
-	action_data->dest_dir = dest;
+	action_data->dest_dir = g_object_ref (dest);
 }
 
 void



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