summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2007-11-22 16:32:22 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-11-22 16:32:22 +0000
commitfd85aae7112aa9db14fd2a226774656b3b6a9fcb (patch)
tree639ca7ed35a64195921c4db3c3750750b3c52488
parente9bca50870cd270d23e5c542091bdd1f0fee692d (diff)
downloadnautilus-fd85aae7112aa9db14fd2a226774656b3b6a9fcb.tar.gz
Handle debuting URIs in file copy op
2007-11-22 Alexander Larsson <alexl@redhat.com> * libnautilus-private/nautilus-file-operations.c: Handle debuting URIs in file copy op * src/file-manager/fm-directory-view.c: Use new nautilus_file_operations_copy for copy. Make debuting_uri hash into debuting_files in new API. Convert for old calls. svn path=/branches/gio-branch/; revision=13447
-rw-r--r--ChangeLog10
-rw-r--r--libnautilus-private/nautilus-file-operations.c81
-rw-r--r--src/file-manager/fm-directory-view.c137
3 files changed, 155 insertions, 73 deletions
diff --git a/ChangeLog b/ChangeLog
index 347d74cf8..938c683bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,16 @@
2007-11-22 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c:
+ Handle debuting URIs in file copy op
+
+ * src/file-manager/fm-directory-view.c:
+ Use new nautilus_file_operations_copy for copy.
+ Make debuting_uri hash into debuting_files in new
+ API. Convert for old calls.
+
+2007-11-22 Alexander Larsson <alexl@redhat.com>
+
+ * libnautilus-private/nautilus-file-operations.c:
Add run_warning and run_error to simplify the
code for error dialogs.
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 3592be11d..1cd55c3bd 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -81,6 +81,7 @@ static gboolean confirm_trash_auto_value;
* Use CommonJob in trash/delete code
* Queue changes and metadata ops in the copy code
* Copy needs to return debuting uris
+ * Set coords if passed in
*/
typedef struct {
@@ -4905,9 +4906,10 @@ static void copy_file (CommonJob *job,
GFile *dest_dir,
gboolean same_fs,
SourceInfo *source_info,
- TransferInfo *transfer_info);
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files);
-static void
+static gboolean
create_dest_dir (CommonJob *job,
GFile *src,
GFile *dest)
@@ -4951,7 +4953,9 @@ create_dest_dir (CommonJob *job,
} else {
g_assert_not_reached ();
}
+ return FALSE;
}
+ return TRUE;
}
static void
@@ -4961,7 +4965,8 @@ copy_directory (CommonJob *job,
gboolean same_fs,
gboolean create_dest,
SourceInfo *source_info,
- TransferInfo *transfer_info)
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files)
{
GFileInfo *info;
GError *error;
@@ -4972,10 +4977,13 @@ copy_directory (CommonJob *job,
gboolean skip_error;
if (create_dest) {
- create_dest_dir (job, src, dest);
- if (job->aborted) {
+ if (!create_dest_dir (job, src, dest)) {
return;
}
+ if (debuting_files) {
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
+ }
+
}
skip_error = should_skip_readdir_error (job, src);
@@ -4993,7 +5001,7 @@ copy_directory (CommonJob *job,
(info = g_file_enumerator_next_file (enumerator, job->cancellable, skip_error?NULL:&error)) != NULL) {
src_file = g_file_get_child (src,
g_file_info_get_name (info));
- copy_file (job, src_file, dest, same_fs, source_info, transfer_info);
+ copy_file (job, src_file, dest, same_fs, source_info, transfer_info, NULL);
g_object_unref (info);
}
g_file_enumerator_close (enumerator, job->cancellable, NULL);
@@ -5031,6 +5039,10 @@ copy_directory (CommonJob *job,
/* Count the copied directory as a file */
transfer_info->num_files ++;
report_copy_progress (job, source_info, transfer_info);
+
+ if (debuting_files) {
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (create_dest));
+ }
} else {
primary = f (_("Error while copying."));
details = NULL;
@@ -5218,7 +5230,8 @@ copy_file (CommonJob *job,
GFile *dest_dir,
gboolean same_fs,
SourceInfo *source_info,
- TransferInfo *transfer_info)
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files)
{
GFile *dest;
GError *error;
@@ -5256,7 +5269,10 @@ copy_file (CommonJob *job,
&error)) {
transfer_info->num_files ++;
report_copy_progress (job, source_info, transfer_info);
-
+
+ if (debuting_files) {
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
+ }
g_object_unref (dest);
return;
}
@@ -5396,7 +5412,8 @@ copy_file (CommonJob *job,
copy_directory (job, src, dest, same_fs,
would_recurse,
- source_info, transfer_info);
+ source_info, transfer_info,
+ debuting_files);
}
/* Other error */
@@ -5432,22 +5449,32 @@ copy_file (CommonJob *job,
g_object_unref (dest);
}
+typedef struct {
+ CommonJob common;
+ GList *files;
+ GFile *destination;
+ GHashTable *debuting_files;
+ void (*done_callback) (GHashTable *debuting_uris, gpointer data);
+ gpointer done_callback_data;
+} CopyJob;
+
static void
-copy_files (CommonJob *job,
- GList *files,
- GFile *dest_dir,
+copy_files (CopyJob *job,
const char *dest_fs_id,
SourceInfo *source_info,
TransferInfo *transfer_info)
{
+ CommonJob *common;
GList *l;
GFile *src;
gboolean same_fs;
- report_copy_progress (job, source_info, transfer_info);
+ common = &job->common;
+
+ report_copy_progress (common, source_info, transfer_info);
- for (l = files;
- l != NULL && !job->aborted ;
+ for (l = job->files;
+ l != NULL && !common->aborted ;
l = l->next) {
src = l->data;
@@ -5456,21 +5483,13 @@ copy_files (CommonJob *job,
same_fs = has_fs_id (src, dest_fs_id);
}
- copy_file (job, src, dest_dir,
+ copy_file (common, src, job->destination,
same_fs,
- source_info, transfer_info);
+ source_info, transfer_info,
+ job->debuting_files);
}
-
}
-typedef struct {
- CommonJob common;
- GList *files;
- GFile *destination;
- void (*done_callback) (GHashTable *debuting_uris, gpointer data);
- gpointer done_callback_data;
-} CopyJob;
-
static void
copy_job_done (gpointer user_data)
{
@@ -5478,11 +5497,12 @@ copy_job_done (gpointer user_data)
job = user_data;
if (job->done_callback) {
- job->done_callback (/* TODO: debuting uris */NULL, job->done_callback_data);
+ job->done_callback (job->debuting_files, job->done_callback_data);
}
eel_g_object_list_free (job->files);
g_object_unref (job->destination);
+ g_hash_table_unref (job->debuting_files);
finalize_common ((CommonJob *)job);
}
@@ -5532,7 +5552,7 @@ copy_job (GIOJob *io_job,
memset (&transfer_info, 0, sizeof (transfer_info));
transfer_info.dest = job->destination;
- copy_files (common, job->files, job->destination,
+ copy_files (job,
dest_fs_id,
&source_info, &transfer_info);
@@ -5553,14 +5573,17 @@ nautilus_file_operations_copy (GList *files,
GArray *relative_item_points,
GFile *target_dir,
GtkWindow *parent_window,
- void (*done_callback) (GHashTable *debuting_uris, gpointer data),
+ void (*done_callback) (GHashTable *debuting_files, gpointer data),
gpointer done_callback_data)
{
CopyJob *job;
job = op_job_new (CopyJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
job->files = eel_g_object_list_copy (files);
job->destination = g_object_ref (target_dir);
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
g_schedule_io_job (copy_job,
job,
diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c
index 1fc941080..a2e352393 100644
--- a/src/file-manager/fm-directory-view.c
+++ b/src/file-manager/fm-directory-view.c
@@ -2324,14 +2324,14 @@ done_loading (FMDirectoryView *view)
typedef struct {
- GHashTable *debuting_uris;
+ GHashTable *debuting_files;
GList *added_files;
-} DebutingUriData;
+} DebutingFilesData;
static void
-debuting_uri_data_free (DebutingUriData *data)
+debuting_files_data_free (DebutingFilesData *data)
{
- g_hash_table_destroy (data->debuting_uris);
+ g_hash_table_unref (data->debuting_files);
nautilus_file_list_free (data->added_files);
g_free (data);
}
@@ -2341,29 +2341,29 @@ debuting_uri_data_free (DebutingUriData *data)
* it selects and reveals them all.
*/
static void
-debuting_uri_add_file_callback (FMDirectoryView *view,
- NautilusFile *new_file,
- NautilusDirectory *directory,
- DebutingUriData *data)
+debuting_files_add_file_callback (FMDirectoryView *view,
+ NautilusFile *new_file,
+ NautilusDirectory *directory,
+ DebutingFilesData *data)
{
- char *uri;
+ GFile *location;
- uri = nautilus_file_get_uri (new_file);
+ location = nautilus_file_get_location (new_file);
- if (g_hash_table_remove (data->debuting_uris, uri)) {
+ if (g_hash_table_remove (data->debuting_files, location)) {
nautilus_file_ref (new_file);
data->added_files = g_list_prepend (data->added_files, new_file);
- if (g_hash_table_size (data->debuting_uris) == 0) {
+ if (g_hash_table_size (data->debuting_files) == 0) {
fm_directory_view_set_selection (view, data->added_files);
fm_directory_view_reveal_selection (view);
g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (debuting_uri_add_file_callback),
+ G_CALLBACK (debuting_files_add_file_callback),
data);
}
}
- g_free (uri);
+ g_object_unref (location);
}
typedef struct {
@@ -2382,16 +2382,19 @@ copy_move_done_data_free (CopyMoveDoneData *data)
}
static void
-pre_copy_move_add_file_callback (FMDirectoryView *view, NautilusFile *new_file, NautilusDirectory *directory, CopyMoveDoneData *data)
+pre_copy_move_add_file_callback (FMDirectoryView *view,
+ NautilusFile *new_file,
+ NautilusDirectory *directory,
+ CopyMoveDoneData *data)
{
- g_object_ref (new_file);
+ nautilus_file_ref (new_file);
data->added_files = g_list_prepend (data->added_files, new_file);
}
/* This needs to be called prior to nautilus_file_operations_copy_move.
* It hooks up a signal handler to catch any icons that get added before
* the copy_done_callback is invoked. The return value should be passed
- * as the data for copy_move_done_callback.
+ * as the data for uri_copy_move_done_callback.
*/
static CopyMoveDoneData *
pre_copy_move (FMDirectoryView *directory_view)
@@ -2419,12 +2422,12 @@ pre_copy_move (FMDirectoryView *directory_view)
static gboolean
copy_move_done_partition_func (gpointer data, gpointer callback_data)
{
- char *uri;
+ GFile *location;
gboolean result;
- uri = nautilus_file_get_uri (NAUTILUS_FILE (data));
- result = g_hash_table_remove ((GHashTable *) callback_data, uri);
- g_free (uri);
+ location = nautilus_file_get_location (NAUTILUS_FILE (data));
+ result = g_hash_table_remove ((GHashTable *) callback_data, location);
+ g_object_unref (location);
return result;
}
@@ -2435,6 +2438,9 @@ remove_not_really_moved_files (gpointer key,
gpointer callback_data)
{
GList **added_files;
+ GFile *loc;
+
+ loc = key;
if (GPOINTER_TO_INT (value)) {
return FALSE;
@@ -2442,7 +2448,7 @@ remove_not_really_moved_files (gpointer key,
added_files = callback_data;
*added_files = g_list_prepend (*added_files,
- nautilus_file_get_by_uri (key));
+ nautilus_file_get (loc));
return TRUE;
}
@@ -2455,11 +2461,11 @@ remove_not_really_moved_files (gpointer key,
* up a signal handler to await their arrival.
*/
static void
-copy_move_done_callback (GHashTable *debuting_uris, gpointer data)
+copy_move_done_callback (GHashTable *debuting_files, gpointer data)
{
FMDirectoryView *directory_view;
CopyMoveDoneData *copy_move_done_data;
- DebutingUriData *debuting_uri_data;
+ DebutingFilesData *debuting_files_data;
copy_move_done_data = (CopyMoveDoneData *) data;
directory_view = copy_move_done_data->directory_view;
@@ -2467,12 +2473,12 @@ copy_move_done_callback (GHashTable *debuting_uris, gpointer data)
if (directory_view != NULL) {
g_assert (FM_IS_DIRECTORY_VIEW (directory_view));
- debuting_uri_data = g_new (DebutingUriData, 1);
- debuting_uri_data->debuting_uris = debuting_uris;
- debuting_uri_data->added_files = eel_g_list_partition
+ debuting_files_data = g_new (DebutingFilesData, 1);
+ debuting_files_data->debuting_files = g_hash_table_ref (debuting_files);
+ debuting_files_data->added_files = eel_g_list_partition
(copy_move_done_data->added_files,
copy_move_done_partition_func,
- debuting_uris,
+ debuting_files,
&copy_move_done_data->added_files);
/* We're passed the same data used by pre_copy_move_add_file_callback, so disconnecting
@@ -2483,23 +2489,23 @@ copy_move_done_callback (GHashTable *debuting_uris, gpointer data)
G_CALLBACK (pre_copy_move_add_file_callback),
data);
- /* Any items in the debuting_uris hash table that have
+ /* Any items in the debuting_files hash table that have
* "FALSE" as their value aren't really being copied
* or moved, so we can't wait for an add_file signal
* to come in for those.
*/
- g_hash_table_foreach_remove (debuting_uris,
+ g_hash_table_foreach_remove (debuting_files,
remove_not_really_moved_files,
- &debuting_uri_data->added_files);
+ &debuting_files_data->added_files);
- if (g_hash_table_size (debuting_uris) == 0) {
+ if (g_hash_table_size (debuting_files) == 0) {
/* on the off-chance that all the icons have already been added */
- if (debuting_uri_data->added_files != NULL) {
+ if (debuting_files_data->added_files != NULL) {
fm_directory_view_set_selection (directory_view,
- debuting_uri_data->added_files);
+ debuting_files_data->added_files);
fm_directory_view_reveal_selection (directory_view);
}
- debuting_uri_data_free (debuting_uri_data);
+ debuting_files_data_free (debuting_files_data);
} else {
/* We need to run after the default handler adds the folder we want to
* operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
@@ -2507,9 +2513,9 @@ copy_move_done_callback (GHashTable *debuting_uris, gpointer data)
*/
g_signal_connect_data (GTK_OBJECT (directory_view),
"add_file",
- G_CALLBACK (debuting_uri_add_file_callback),
- debuting_uri_data,
- (GClosureNotify) debuting_uri_data_free,
+ G_CALLBACK (debuting_files_add_file_callback),
+ debuting_files_data,
+ (GClosureNotify) debuting_files_data_free,
G_CONNECT_AFTER);
}
}
@@ -2517,6 +2523,31 @@ copy_move_done_callback (GHashTable *debuting_uris, 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)
{
@@ -3489,7 +3520,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), copy_move_done_callback, copy_move_done_data);
+ GTK_WIDGET (view), uri_copy_move_done_callback, copy_move_done_data);
eel_g_list_free_deep (uris);
}
@@ -3521,7 +3552,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), copy_move_done_callback, copy_move_done_data);
+ GTK_WIDGET (view), uri_copy_move_done_callback, copy_move_done_data);
eel_g_list_free_deep (uris);
}
@@ -8112,10 +8143,28 @@ fm_directory_view_move_copy_items (const GList *item_uris,
trash_or_delete_files (fm_directory_view_get_containing_window (view), locations, FALSE);
eel_g_object_list_free (locations);
} else {
- 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));
+ 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 {
+ 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));
+ }
}
}