[nautilus] Move restore_from_trash() in nautilus-file-utilities.



commit b87911c0caf3d957fc4e9575fd905493829f787c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Apr 28 16:30:44 2010 +0200

    Move restore_from_trash() in nautilus-file-utilities.
    
    This is needed so we will be able to use the function from the trash bar
    later.

 libnautilus-private/nautilus-file-utilities.c |  121 ++++++++++++++++++++++
 libnautilus-private/nautilus-file-utilities.h |    6 +
 src/file-manager/fm-directory-view.c          |  134 +------------------------
 3 files changed, 132 insertions(+), 129 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-utilities.c b/libnautilus-private/nautilus-file-utilities.c
index a5bf182..b52b657 100644
--- a/libnautilus-private/nautilus-file-utilities.c
+++ b/libnautilus-private/nautilus-file-utilities.c
@@ -29,9 +29,11 @@
 #include "nautilus-lib-self-check-functions.h"
 #include "nautilus-metadata.h"
 #include "nautilus-file.h"
+#include "nautilus-file-operations.h"
 #include "nautilus-search-directory.h"
 #include "nautilus-signaller.h"
 #include <eel/eel-glib-extensions.h>
+#include <eel/eel-stock-dialogs.h>
 #include <eel/eel-string.h>
 #include <eel/eel-debug.h>
 #include <glib.h>
@@ -1159,6 +1161,125 @@ nautilus_is_in_system_dir (GFile *file)
 	return res;
 }
 
+GHashTable *
+nautilus_trashed_files_get_original_directories (GList *files,
+						 GList **unhandled_files)
+{
+	GHashTable *directories;
+	NautilusFile *file, *original_file, *original_dir;
+	GList *l, *m;
+
+	directories = NULL;
+
+	if (unhandled_files != NULL) {
+		*unhandled_files = NULL;
+	}
+
+	for (l = files; l != NULL; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		original_file = nautilus_file_get_trash_original_file (file);
+
+		original_dir = NULL;
+		if (original_file != NULL) {
+			original_dir = nautilus_file_get_parent (original_file);
+		}
+
+		if (original_dir != NULL) {
+			if (directories == NULL) {
+				directories = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+								     (GDestroyNotify) nautilus_file_unref,
+								     (GDestroyNotify) nautilus_file_list_unref);
+			}
+			nautilus_file_ref (original_dir);
+			m = g_hash_table_lookup (directories, original_dir);
+			if (m != NULL) {
+				g_hash_table_steal (directories, original_dir);
+				nautilus_file_unref (original_dir);
+			}
+			m = g_list_append (m, nautilus_file_ref (file));
+			g_hash_table_insert (directories, original_dir, m);
+		} else if (unhandled_files != NULL) {
+			*unhandled_files = g_list_append (*unhandled_files, nautilus_file_ref (file));
+		}
+
+		if (original_file != NULL) {
+			nautilus_file_unref (original_file);
+		}
+
+		if (original_dir != NULL) {
+			nautilus_file_unref (original_dir);
+		}
+	}
+
+	return directories;
+}
+
+static GList *
+locations_from_file_list (GList *file_list)
+{
+	NautilusFile *file;
+	GList *l, *ret;
+
+	ret = NULL;
+
+	for (l = file_list; l != NULL; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		ret = g_list_prepend (ret, nautilus_file_get_location (file));
+	}
+
+	return g_list_reverse (ret);
+}
+
+void
+nautilus_restore_files_from_trash (GList *files,
+				   GtkWindow *parent_window)
+{
+	NautilusFile *file, *original_dir;
+	GHashTable *original_dirs_hash;
+	GList *original_dirs, *unhandled_files;
+	GFile *original_dir_location;
+	GList *locations, *l;
+	char *message, *file_name;
+
+	original_dirs_hash = nautilus_trashed_files_get_original_directories (files, &unhandled_files);
+
+	for (l = unhandled_files; l != NULL; l = l->next) {
+		file = NAUTILUS_FILE (l->data);
+		file_name = nautilus_file_get_display_name (file);
+		message = g_strdup_printf (_("Could not determine original location of \"%s\" "), file_name);
+		g_free (file_name);
+
+		eel_show_warning_dialog (message,
+					 _("The item cannot be restored from trash"),
+					 parent_window);
+		g_free (message);
+	}
+
+	if (original_dirs_hash != NULL) {
+		original_dirs = g_hash_table_get_keys (original_dirs_hash);
+		for (l = original_dirs; l != NULL; l = l->next) {
+			original_dir = NAUTILUS_FILE (l->data);
+			original_dir_location = nautilus_file_get_location (original_dir);
+
+			files = g_hash_table_lookup (original_dirs_hash, original_dir);
+			locations = locations_from_file_list (files);
+
+			nautilus_file_operations_move
+				(locations, NULL, 
+				 original_dir_location,
+				 parent_window,
+				 NULL, NULL);
+
+			eel_g_object_list_free (locations);
+			g_object_unref (original_dir_location);
+		}
+
+		g_list_free (original_dirs);
+		g_hash_table_destroy (original_dirs_hash);
+	}
+
+	nautilus_file_list_unref (unhandled_files);
+}
 
 #if !defined (NAUTILUS_OMIT_SELF_CHECK)
 
diff --git a/libnautilus-private/nautilus-file-utilities.h b/libnautilus-private/nautilus-file-utilities.h
index d6cb8c1..340ffae 100644
--- a/libnautilus-private/nautilus-file-utilities.h
+++ b/libnautilus-private/nautilus-file-utilities.h
@@ -26,6 +26,7 @@
 #define NAUTILUS_FILE_UTILITIES_H
 
 #include <gio/gio.h>
+#include <gtk/gtk.h>
 
 #define NAUTILUS_SAVED_SEARCH_EXTENSION ".savedSearch"
 #define NAUTILUS_SAVED_SEARCH_MIMETYPE "application/x-gnome-saved-search"
@@ -102,4 +103,9 @@ nautilus_find_file_insensitive (GFile *parent, const gchar *name);
 
 char * nautilus_get_accel_map_file (void);
 
+GHashTable * nautilus_trashed_files_get_original_directories (GList *files,
+							      GList **unhandled_files);
+void nautilus_restore_files_from_trash (GList *files,
+					GtkWindow *parent_window);
+
 #endif /* NAUTILUS_FILE_UTILITIES_H */
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 6096aed..0c45f53 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -281,10 +281,6 @@ static void     trash_or_delete_files                          (GtkWindow
 								const GList          *files,
 								gboolean              delete_if_all_already_in_trash,
 								FMDirectoryView      *view);
-static void     restore_from_trash                             (GList                *files,
-								FMDirectoryView      *view);
-static GHashTable * get_original_directories                   (GList *files,
-								GList **unhandled_files);
 static void     load_directory                                 (FMDirectoryView      *view,
 								NautilusDirectory    *directory);
 static void     fm_directory_view_merge_menus                  (FMDirectoryView      *view);
@@ -1035,7 +1031,8 @@ action_restore_from_trash_callback (GtkAction *action,
 	view = FM_DIRECTORY_VIEW (callback_data);
 
 	selection = fm_directory_view_get_selection_for_file_transfer (view);
-	restore_from_trash (selection, view);
+	nautilus_restore_files_from_trash (selection,
+					   fm_directory_view_get_containing_window (view));
 
 	nautilus_file_list_free (selection);
 
@@ -7077,75 +7074,6 @@ action_location_delete_callback (GtkAction *action,
 	eel_g_object_list_free (files);
 }
 
-static GList *
-locations_from_file_list (GList *file_list)
-{
-	NautilusFile *file;
-	GList *l, *ret;
-
-	ret = NULL;
-
-	for (l = file_list; l != NULL; l = l->next) {
-		file = NAUTILUS_FILE (l->data);
-		ret = g_list_prepend (ret, nautilus_file_get_location (file));
-	}
-
-	return g_list_reverse (ret);
-}
-
-static void
-restore_from_trash (GList *files,
-		    FMDirectoryView *view)
-{
-	NautilusFile *file, *original_dir;
-	GHashTable *original_dirs_hash;
-	GList *original_dirs, *unhandled_files;
-	GFile *original_dir_location;
-	GList *locations, *l;
-	char *message, *file_name;
-
-	g_assert (FM_IS_DIRECTORY_VIEW (view));
-
-	original_dirs_hash = get_original_directories (files, &unhandled_files);
-
-	for (l = unhandled_files; l != NULL; l = l->next) {
-		file = NAUTILUS_FILE (l->data);
-		file_name = nautilus_file_get_display_name (file);
-		message = g_strdup_printf (_("Could not determine original location of \"%s\" "), file_name);
-		g_free (file_name);
-
-		eel_show_warning_dialog (message,
-					 _("The item cannot be restored from trash"),
-					 fm_directory_view_get_containing_window (view));
-		g_free (message);
-	}
-
-	if (original_dirs_hash != NULL) {
-		original_dirs = g_hash_table_get_keys (original_dirs_hash);
-		for (l = original_dirs; l != NULL; l = l->next) {
-			original_dir = NAUTILUS_FILE (l->data);
-			original_dir_location = nautilus_file_get_location (original_dir);
-
-			files = g_hash_table_lookup (original_dirs_hash, original_dir);
-			locations = locations_from_file_list (files);
-
-			nautilus_file_operations_move
-				(locations, NULL, 
-				 original_dir_location,
-				 (GtkWindow *) view->details->window,
-				 NULL, NULL);
-
-			eel_g_object_list_free (locations);
-			g_object_unref (original_dir_location);
-		}
-
-		g_list_free (original_dirs);
-		g_hash_table_destroy (original_dirs_hash);
-	}
-
-	nautilus_file_list_unref (unhandled_files);
-}
-
 static void
 action_location_restore_from_trash_callback (GtkAction *action,
 					     gpointer callback_data)
@@ -7160,7 +7088,8 @@ action_location_restore_from_trash_callback (GtkAction *action,
 	l.prev = NULL;
 	l.next = NULL;
 	l.data = file;
-	restore_from_trash (&l, view);
+	nautilus_restore_files_from_trash (&l,
+					   fm_directory_view_get_containing_window (view));
 }
 
 static void
@@ -7912,59 +7841,6 @@ file_should_show_self (NautilusFile        *file,
 
 }
 
-static GHashTable *
-get_original_directories (GList *files,
-			  GList **unhandled_files)
-{
-	GHashTable *directories;
-	NautilusFile *file, *original_file, *original_dir;
-	GList *l, *m;
-
-	directories = NULL;
-
-	if (unhandled_files != NULL) {
-		*unhandled_files = NULL;
-	}
-
-	for (l = files; l != NULL; l = l->next) {
-		file = NAUTILUS_FILE (l->data);
-		original_file = nautilus_file_get_trash_original_file (file);
-
-		original_dir = NULL;
-		if (original_file != NULL) {
-			original_dir = nautilus_file_get_parent (original_file);
-		}
-
-		if (original_dir != NULL) {
-			if (directories == NULL) {
-				directories = g_hash_table_new_full (g_direct_hash, g_direct_equal,
-								     (GDestroyNotify) nautilus_file_unref,
-								     (GDestroyNotify) nautilus_file_list_unref);
-			}
-			nautilus_file_ref (original_dir);
-			m = g_hash_table_lookup (directories, original_dir);
-			if (m != NULL) {
-				g_hash_table_steal (directories, original_dir);
-				nautilus_file_unref (original_dir);
-			}
-			m = g_list_append (m, nautilus_file_ref (file));
-			g_hash_table_insert (directories, original_dir, m);
-		} else if (unhandled_files != NULL) {
-			*unhandled_files = g_list_append (*unhandled_files, nautilus_file_ref (file));
-		}
-
-		if (original_file != NULL) {
-			nautilus_file_unref (original_file);
-		}
-
-		if (original_dir != NULL) {
-			nautilus_file_unref (original_dir);
-		}
-	}
-
-	return directories;
-}
-
 static gboolean
 files_are_all_directories (GList *files)
 {
@@ -8022,7 +7898,7 @@ update_restore_from_trash_action (GtkAction *action,
 		if (g_list_length (files) == 1) {
 			original_file = nautilus_file_get_trash_original_file (files->data);
 		} else {
-			original_dirs_hash = get_original_directories (files, NULL);
+			original_dirs_hash = nautilus_trashed_files_get_original_directories (files, NULL);
 			if (original_dirs_hash != NULL) {
 				original_dirs = g_hash_table_get_keys (original_dirs_hash);
 				if (g_list_length (original_dirs) == 1) {



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