From 1888273e73eb56dd4e221845fd0dd39147af72e2 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 30 Nov 2007 12:21:07 +0000 Subject: Reimplement copy_move helper with _copy and _move Also support move to 2007-11-30 Alexander Larsson * libnautilus-private/nautilus-file-operations.[ch]: Reimplement copy_move helper with _copy and _move Also support move to trash as trash * src/file-manager/fm-directory-view.c: Use _copy_move again svn path=/branches/gio-branch/; revision=13463 --- ChangeLog | 9 +++ libnautilus-private/nautilus-file-operations.c | 70 +++++++++++++++++-- libnautilus-private/nautilus-file-operations.h | 4 +- src/file-manager/fm-directory-view.c | 94 ++------------------------ 4 files changed, 80 insertions(+), 97 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08044e624..5f960cb05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-11-30 Alexander Larsson + + * libnautilus-private/nautilus-file-operations.[ch]: + Reimplement copy_move helper with _copy and _move + Also support move to trash as trash + + * src/file-manager/fm-directory-view.c: + Use _copy_move again + 2007-11-30 Alexander Larsson * libnautilus-private/nautilus-file-changes-queue.[ch]: diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c index 519505202..cfef8376f 100644 --- a/libnautilus-private/nautilus-file-operations.c +++ b/libnautilus-private/nautilus-file-operations.c @@ -109,7 +109,7 @@ typedef struct { int n_icon_positions; int screen_num; GHashTable *debuting_files; - void (*done_callback) (GHashTable *debuting_uris, gpointer data); + NautilusCopyCallback done_callback; gpointer done_callback_data; } CopyMoveJob; @@ -3674,6 +3674,7 @@ static void delete_job_done (gpointer user_data) { DeleteJob *job = user_data; + GHashTable *debuting_uris; eel_g_object_list_free (job->files); if (job->parent_window) { @@ -3681,7 +3682,9 @@ delete_job_done (gpointer user_data) } if (job->done_callback) { - job->done_callback (/* TODO: debuting uris */NULL, job->done_callback_data); + debuting_uris = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL); + job->done_callback (debuting_uris, job->done_callback_data); + g_hash_table_unref (debuting_uris); } g_free (job); @@ -5721,7 +5724,7 @@ nautilus_file_operations_copy (GList *files, GArray *relative_item_points, GFile *target_dir, GtkWindow *parent_window, - void (*done_callback) (GHashTable *debuting_files, gpointer data), + NautilusCopyCallback done_callback, gpointer done_callback_data) { CopyMoveJob *job; @@ -6165,7 +6168,7 @@ nautilus_file_operations_move (GList *files, GArray *relative_item_points, GFile *target_dir, GtkWindow *parent_window, - void (*done_callback) (GHashTable *debuting_files, gpointer data), + NautilusCopyCallback done_callback, gpointer done_callback_data) { CopyMoveJob *job; @@ -6221,17 +6224,70 @@ nautilus_file_set_permissions_recursive (const char *directo not_supported_yet (); } +static GList * +location_list_from_uri_list (const GList *uris) +{ + const GList *l; + GList *files; + GFile *f; + + files = NULL; + for (l = uris; l != NULL; l = l->next) { + f = g_file_new_for_uri (l->data); + files = g_list_prepend (files, f); + } + + return g_list_reverse (files); +} + void nautilus_file_operations_copy_move (const GList *item_uris, GArray *relative_item_points, const char *target_dir, GdkDragAction copy_action, GtkWidget *parent_view, - void (*done_callback) (GHashTable *debuting_uris, gpointer data), + NautilusCopyCallback done_callback, gpointer done_callback_data) { - /* TODO-gio: Implement */ - not_supported_yet (); + GList *locations; + GFile *dest; + GtkWindow *parent_window; + + dest = g_file_new_for_uri (target_dir); + locations = location_list_from_uri_list (item_uris); + + parent_window = NULL; + if (parent_view) { + parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW); + } + + if (copy_action == GDK_ACTION_COPY) { + nautilus_file_operations_copy (locations, + relative_item_points, + dest, + parent_window, + done_callback, done_callback_data); + + } else if (copy_action == GDK_ACTION_MOVE) { + + if (g_file_has_uri_scheme (dest, "trash")) { + nautilus_file_operations_trash_or_delete (locations, + parent_window, + done_callback, done_callback_data); + } else { + nautilus_file_operations_move (locations, + relative_item_points, + dest, + parent_window, + done_callback, done_callback_data); + } + } else { + /* TODO-gio: Implement link */ + not_supported_yet (); + } + + eel_g_object_list_free (locations); + g_object_unref (dest); } void diff --git a/libnautilus-private/nautilus-file-operations.h b/libnautilus-private/nautilus-file-operations.h index 02ba0842b..98c3ee37f 100644 --- a/libnautilus-private/nautilus-file-operations.h +++ b/libnautilus-private/nautilus-file-operations.h @@ -99,14 +99,14 @@ void nautilus_file_operations_copy (GList *files, GArray *relative_item_points, GFile *target_dir, GtkWindow *parent_window, - void (*done_callback) (GHashTable *debuting_uris, gpointer data), + NautilusCopyCallback done_callback, gpointer done_callback_data); void nautilus_file_operations_move (GList *files, GArray *relative_item_points, GFile *target_dir, GtkWindow *parent_window, - void (*done_callback) (GHashTable *debuting_files, gpointer data), + NautilusCopyCallback done_callback, gpointer done_callback_data); #endif /* NAUTILUS_FILE_OPERATIONS_H */ diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index 0d92f5f43..3f8d05e45 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -1696,22 +1696,6 @@ file_list_from_uri_list (const GList *uri_list) return g_list_reverse (file_list); } -static GList * -location_list_from_uri_list (const GList *uris) -{ - const GList *l; - GList *files; - GFile *f; - - files = NULL; - for (l = uris; l != NULL; l = l->next) { - f = g_file_new_for_uri (l->data); - files = g_list_prepend (files, f); - } - - return g_list_reverse (files); -} - static void fm_directory_view_set_selection_uris (NautilusView *nautilus_view, GList *selection_uris) @@ -2526,31 +2510,6 @@ copy_move_done_callback (GHashTable *debuting_files, gpointer data) copy_move_done_data_free (copy_move_done_data); } -static void -key_uri_to_file (gpointer key, - gpointer value, - gpointer user_data) -{ - char *uri; - - uri = key; - -} - -static void -uri_copy_move_done_callback (GHashTable *debuting_uris, gpointer data) -{ - GHashTable *debuting_files; - - debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL); - g_hash_table_foreach (debuting_uris, key_uri_to_file, debuting_files); - g_hash_table_destroy (debuting_files); - - copy_move_done_callback (debuting_files, data); - - g_hash_table_unref (debuting_files); -} - static gboolean real_file_still_belongs (FMDirectoryView *view, NautilusFile *file, NautilusDirectory *directory) { @@ -3523,7 +3482,7 @@ fm_directory_view_create_links_for_files (FMDirectoryView *view, GList *files, copy_move_done_data = pre_copy_move (view); nautilus_file_operations_copy_move (uris, relative_item_points, NULL, GDK_ACTION_LINK, - GTK_WIDGET (view), uri_copy_move_done_callback, copy_move_done_data); + GTK_WIDGET (view), copy_move_done_callback, copy_move_done_data); eel_g_list_free_deep (uris); } @@ -3555,7 +3514,7 @@ fm_directory_view_duplicate_selection (FMDirectoryView *view, GList *files, copy_move_done_data = pre_copy_move (view); nautilus_file_operations_copy_move (uris, relative_item_points, NULL, GDK_ACTION_COPY, - GTK_WIDGET (view), uri_copy_move_done_callback, copy_move_done_data); + GTK_WIDGET (view), copy_move_done_callback, copy_move_done_data); eel_g_list_free_deep (uris); } @@ -8140,51 +8099,10 @@ fm_directory_view_move_copy_items (const GList *item_uris, return; } - if (eel_uri_is_trash (target_uri) && copy_action == GDK_ACTION_MOVE) { - GList *locations; - locations = location_list_from_uri_list (item_uris); - trash_or_delete_files (fm_directory_view_get_containing_window (view), locations, FALSE); - eel_g_object_list_free (locations); - } else { - if (copy_action == GDK_ACTION_COPY) { - GList *locations; - GFile *dest; - - dest = g_file_new_for_uri (target_uri); - locations = location_list_from_uri_list (item_uris); - - nautilus_file_operations_copy (locations, - relative_item_points, - dest, - fm_directory_view_get_containing_window (view), - copy_move_done_callback, - pre_copy_move (view)); - - eel_g_object_list_free (locations); - g_object_unref (dest); - } else if (copy_action == GDK_ACTION_MOVE) { - GList *locations; - GFile *dest; - - dest = g_file_new_for_uri (target_uri); - locations = location_list_from_uri_list (item_uris); - - nautilus_file_operations_move (locations, - relative_item_points, - dest, - fm_directory_view_get_containing_window (view), - copy_move_done_callback, - pre_copy_move (view)); - - eel_g_object_list_free (locations); - g_object_unref (dest); - } else { - nautilus_file_operations_copy_move - (item_uris, relative_item_points, - target_uri, copy_action, GTK_WIDGET (view), - uri_copy_move_done_callback, pre_copy_move (view)); - } - } + nautilus_file_operations_copy_move + (item_uris, relative_item_points, + target_uri, copy_action, GTK_WIDGET (view), + copy_move_done_callback, pre_copy_move (view)); } gboolean -- cgit v1.2.1