[nautilus] file-operations: add nautilus_file_operations_copy_file



commit 4be5d548a438b2b3c02f3e7e7e0265f4c8b641fe
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Dec 6 19:44:00 2010 +0100

    file-operations: add nautilus_file_operations_copy_file
    
    Copies a single file to a target directory, allowing to specify a custom
    target display name, and a custom source display name, which will be
    shown in the FileOperations dialog instead of the actual file name.

 libnautilus-private/nautilus-file-operations.c |   81 +++++++++++++++++++++---
 libnautilus-private/nautilus-file-operations.h |    7 ++
 2 files changed, 80 insertions(+), 8 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 2aab84f..a000b67 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -89,9 +89,11 @@ typedef struct {
 	GList *files;
 	GFile *destination;
 	GFile *desktop_location;
+	GFile *fake_display_source;
 	GdkPoint *icon_positions;
 	int n_icon_positions;
 	GHashTable *debuting_files;
+	gchar *target_name;
 	NautilusCopyCallback  done_callback;
 	gpointer done_callback_data;
 } CopyMoveJob;
@@ -2868,6 +2870,8 @@ report_copy_progress (CopyMoveJob *copy_job,
 								    f (is_move ?
 								       _("Moving \"%B\" to \"%B\""):
 								       _("Copying \"%B\" to \"%B\""),
+								       copy_job->fake_display_source != NULL ?
+								       copy_job->fake_display_source :
 								       (GFile *)copy_job->files->data,
 								       copy_job->destination));
 			} else {
@@ -3164,10 +3168,11 @@ get_target_file_for_link (GFile *src,
 }
 
 static GFile *
-get_target_file (GFile *src,
-		 GFile *dest_dir,
-		 const char *dest_fs_type,
-		 gboolean same_fs)
+get_target_file_with_custom_name (GFile *src,
+				  GFile *dest_dir,
+				  const char *dest_fs_type,
+				  gboolean same_fs,
+				  const gchar *custom_name)
 {
 	char *basename;
 	GFile *dest;
@@ -3175,7 +3180,16 @@ get_target_file (GFile *src,
 	char *copyname;
 
 	dest = NULL;
-	if (!same_fs) {
+
+	if (custom_name != NULL) {
+		copyname = g_strdup (custom_name);
+		make_file_name_valid_for_dest_fs (copyname, dest_fs_type);
+		dest = g_file_get_child_for_display_name (dest_dir, copyname, NULL);
+
+		g_free (copyname);
+	}
+
+	if (dest == NULL && !same_fs) {
 		info = g_file_query_info (src,
 					  G_FILE_ATTRIBUTE_STANDARD_COPY_NAME,
 					  0, NULL, NULL);
@@ -3203,6 +3217,15 @@ get_target_file (GFile *src,
 	return dest;
 }
 
+static GFile *
+get_target_file (GFile *src,
+		 GFile *dest_dir,
+		 const char *dest_fs_type,
+		 gboolean same_fs)
+{
+	return get_target_file_with_custom_name (src, dest_dir, dest_fs_type, same_fs, NULL);
+}
+
 static gboolean
 has_fs_id (GFile *file, const char *fs_id)
 {
@@ -3910,10 +3933,10 @@ conflict_response_data_free (ConflictResponseData *data)
 
 static GFile *
 get_target_file_for_display_name (GFile *dir,
-				  char *name)
+				  const gchar *name)
 {
 	GFile *dest;
-	
+
 	dest = NULL;
 	dest = g_file_get_child_for_display_name (dir, name, NULL);
 
@@ -3968,11 +3991,13 @@ copy_move_file (CopyMoveJob *copy_job,
 
 	if (unique_names) {
 		dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
+	} else if (copy_job->target_name != NULL) {
+		dest = get_target_file_with_custom_name (src, dest_dir, *dest_fs_type, same_fs,
+							 copy_job->target_name);
 	} else {
 		dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
 	}
 
-
 	/* Don't allow recursive move/copy into itself.  
 	 * (We would get a file system error if we proceeded but it is nicer to 
 	 * detect and report it at this level) */
@@ -4423,6 +4448,9 @@ copy_job_done (gpointer user_data)
 	}
 	g_hash_table_unref (job->debuting_files);
 	g_free (job->icon_positions);
+	g_free (job->target_name);
+
+	g_clear_object (&job->fake_display_source);
 	
 	finalize_common ((CommonJob *)job);
 
@@ -4496,6 +4524,43 @@ copy_job (GIOSchedulerJob *io_job,
 }
 
 void
+nautilus_file_operations_copy_file (GFile *source_file,
+				    GFile *target_dir,
+				    const gchar *source_display_name,
+				    const gchar *new_name,
+				    GtkWindow *parent_window,
+				    NautilusCopyCallback done_callback,
+				    gpointer done_callback_data)
+{
+	CopyMoveJob *job;
+
+	job = op_job_new (CopyMoveJob, parent_window);
+	job->done_callback = done_callback;
+	job->done_callback_data = done_callback_data;
+	job->files = g_list_append (NULL, g_object_ref (source_file));
+	job->destination = g_object_ref (target_dir);
+	job->target_name = g_strdup (new_name);
+	job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
+
+	if (source_display_name != NULL) {
+		gchar *path;
+
+		path = g_build_filename ("/", source_display_name, NULL);
+		job->fake_display_source = g_file_new_for_path (path);
+
+		g_free (path);
+	}
+
+	inhibit_power_manager ((CommonJob *)job, _("Copying Files"));
+
+	g_io_scheduler_push_job (copy_job,
+			   job,
+			   NULL, /* destroy notify */
+			   0,
+			   job->common.cancellable);
+}
+
+void
 nautilus_file_operations_copy (GList *files,
 			       GArray *relative_item_points,
 			       GFile *target_dir,
diff --git a/libnautilus-private/nautilus-file-operations.h b/libnautilus-private/nautilus-file-operations.h
index c2ef34c..96e908b 100644
--- a/libnautilus-private/nautilus-file-operations.h
+++ b/libnautilus-private/nautilus-file-operations.h
@@ -51,6 +51,13 @@ void nautilus_file_operations_copy_move   (const GList               *item_uris,
 					   GtkWidget                 *parent_view,
 					   NautilusCopyCallback       done_callback,
 					   gpointer                   done_callback_data);
+void nautilus_file_operations_copy_file (GFile *source_file,
+					 GFile *target_dir,
+					 const gchar *source_display_name,
+					 const gchar *new_name,
+					 GtkWindow *parent_window,
+					 NautilusCopyCallback done_callback,
+					 gpointer done_callback_data);
 void nautilus_file_operations_empty_trash (GtkWidget                 *parent_view);
 void nautilus_file_operations_new_folder  (GtkWidget                 *parent_view,
 					   GdkPoint                  *target_point,



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