[nautilus/gnome-2-32: 17/283] Implement responses from the dialog back to the file operation.



commit ca224b76bb0f3c6aec26296d1ac7d74107f0fb06
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 3 13:27:48 2008 +0200

    Implement responses from the dialog back to the file operation.
    
    Add some API to get the response type from the conflict dialog back to
    the file operations code. Start using that API during the operations
    accordingly.

 .../nautilus-file-conflict-dialog.c                |   31 +++++++---
 .../nautilus-file-conflict-dialog.h                |   13 ++--
 libnautilus-private/nautilus-file-operations.c     |   61 +++++++++++++++-----
 3 files changed, 74 insertions(+), 31 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file-conflict-dialog.c b/libnautilus-private/nautilus-file-conflict-dialog.c
index cd7e7eb..49f9f0e 100644
--- a/libnautilus-private/nautilus-file-conflict-dialog.c
+++ b/libnautilus-private/nautilus-file-conflict-dialog.c
@@ -88,9 +88,7 @@ build_dialog_appearance (NautilusFileConflictDialog *fcd)
 	char *label_text;
 	char *size, *date, *type;
 	GdkPixbuf *pixbuf;
-	GtkWidget *image;
-	GtkWidget *label;
-	GtkWidget *rename_button;
+	GtkWidget *image, *label, *button;
 	NautilusFile *src, *dest, *dest_dir;
 	
 	dialog = GTK_DIALOG (fcd);
@@ -227,15 +225,15 @@ build_dialog_appearance (NautilusFileConflictDialog *fcd)
 	gtk_dialog_add_buttons (dialog,
 				GTK_STOCK_CANCEL,
 				GTK_RESPONSE_CANCEL,
-				_("S_kip"),
+				_("_Skip"),
 				CONFLICT_RESPONSE_SKIP,
 				NULL);
-	rename_button = gtk_dialog_add_button (dialog,
-					       _("Re_name"),
-					       CONFLICT_RESPONSE_RENAME);
-	gtk_widget_set_sensitive (rename_button,
+	button = gtk_dialog_add_button (dialog,
+					_("Re_name"),
+					CONFLICT_RESPONSE_RENAME);
+	gtk_widget_set_sensitive (button,
 				  FALSE);
-	details->rename_button = rename_button;
+	details->rename_button = button;
 	gtk_dialog_add_button (dialog,
 			       _("_Replace"),
 			       CONFLICT_RESPONSE_REPLACE);
@@ -348,6 +346,7 @@ nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
 	gtk_box_pack_start (GTK_BOX (vbox),
 			    widget, FALSE, FALSE, 0);
 	gtk_widget_show (widget);
+	details->checkbox = widget;
 	g_signal_connect (widget, "toggled",
 			  G_CALLBACK (checkbox_toggled_cb),
 			  dialog);
@@ -380,6 +379,20 @@ nautilus_file_conflict_dialog_class_init (NautilusFileConflictDialogClass *klass
 	g_type_class_add_private (klass, sizeof (NautilusFileConflictDialogDetails));
 }
 
+char *
+nautilus_file_conflict_dialog_get_new_name (NautilusFileConflictDialog *dialog)
+{
+	return g_strdup (gtk_entry_get_text
+			 (GTK_ENTRY (dialog->details->entry)));
+}
+
+gboolean
+nautilus_file_conflict_dialog_get_apply_to_all (NautilusFileConflictDialog *dialog)
+{
+	return gtk_toggle_button_get_active 
+		(GTK_TOGGLE_BUTTON (dialog->details->checkbox));
+}
+
 GtkWidget *
 nautilus_file_conflict_dialog_new (GtkWindow *parent,
 				   GFile *source,
diff --git a/libnautilus-private/nautilus-file-conflict-dialog.h b/libnautilus-private/nautilus-file-conflict-dialog.h
index d181a0e..452f742 100644
--- a/libnautilus-private/nautilus-file-conflict-dialog.h
+++ b/libnautilus-private/nautilus-file-conflict-dialog.h
@@ -55,16 +55,15 @@ enum
 	CONFLICT_RESPONSE_SKIP = 1,
 	CONFLICT_RESPONSE_REPLACE = 2,
 	CONFLICT_RESPONSE_RENAME = 3,
-	CONFLICT_RESPONSE_SKIP_ALL = 4,
-	CONFLICT_RESPONSE_REPLACE_ALL = 5
 };
 
 GType nautilus_file_conflict_dialog_get_type (void) G_GNUC_CONST;
 
-GtkWidget* nautilus_file_conflict_dialog_new (GtkWindow *parent,
-					      GFile *source,
-					      GFile *destination,
-					      GFile *dest_dir);
-char* nautilus_file_conflict_dialog_get_new_name (NautilusFileConflictDialog *dialog);					      
+GtkWidget* nautilus_file_conflict_dialog_new              (GtkWindow *parent,
+							   GFile *source,
+							   GFile *destination,
+							   GFile *dest_dir);
+char*      nautilus_file_conflict_dialog_get_new_name     (NautilusFileConflictDialog *dialog);
+gboolean   nautilus_file_conflict_dialog_get_apply_to_all (NautilusFileConflictDialog *dialog);
 
 #endif /* NAUTILUS_FILE_CONFLICT_DIALOG_H */
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index 0796e90..67d1ff2 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -3831,42 +3831,68 @@ is_trusted_desktop_file (GFile *file,
 }
 
 typedef struct {
+	int response;
+	char *new_name;
+	gboolean apply_to_all;
+} ConflictResponseData;
+
+typedef struct {
 	GFile *src;
 	GFile *dest;
 	GFile *dest_dir;
 	GtkWindow *parent;
-} MyData;
+	ConflictResponseData *resp_data;
+} ConflictDialogData;
 
 static gboolean
 do_run_my_dialog (gpointer _data)
 {
-	MyData *data = _data;
+	ConflictDialogData *data = _data;
 	GtkWidget *dialog;
+	int response;
 	
 	dialog = nautilus_file_conflict_dialog_new (data->parent,
 						    data->src,
 						    data->dest,
 						    data->dest_dir);
-	gtk_dialog_run (GTK_DIALOG (dialog));
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+	
+	if (response == CONFLICT_RESPONSE_RENAME) {
+		data->resp_data->new_name = 
+			nautilus_file_conflict_dialog_get_new_name (NAUTILUS_FILE_CONFLICT_DIALOG (dialog));
+	} else if (response != GTK_RESPONSE_CANCEL ||
+		   response != GTK_RESPONSE_NONE) {
+		   data->resp_data->apply_to_all =
+			   nautilus_file_conflict_dialog_get_apply_to_all 
+				(NAUTILUS_FILE_CONFLICT_DIALOG (dialog));
+	}
+	
+	data->resp_data->response = response;
+	
+	gtk_widget_destroy (dialog);
 	
 	return FALSE;
 }
 
-static void
-run_my_dialog (CommonJob *job,
-	       GFile *src,
-	       GFile *dest,
-	       GFile *dest_dir)
+static ConflictResponseData *
+run_conflict_dialog (CommonJob *job,
+		     GFile *src,
+		     GFile *dest,
+		     GFile *dest_dir)
 {
-	MyData *data;
-
+	ConflictDialogData *data;
+	ConflictResponseData *resp_data;
+	
 	g_timer_stop (job->time);
 	
-	data = g_new0 (MyData, 1);
+	data = g_slice_new0 (ConflictDialogData);
 	data->parent = job->parent_window;
 	data->src = src;
 	data->dest = dest;
 	data->dest_dir = dest_dir;
+
+	resp_data = g_slice_new0 (ConflictResponseData);
+	data->resp_data = resp_data;
 	
 	nautilus_progress_info_pause (job->progress);
 	g_io_scheduler_job_send_to_mainloop (job->io_job,
@@ -3874,10 +3900,12 @@ run_my_dialog (CommonJob *job,
 					     data,
 					     NULL);
 	nautilus_progress_info_resume (job->progress);
-
-	g_free (data);
-
+	
+	g_slice_free (ConflictDialogData, data);
+	
 	g_timer_continue (job->time);
+	
+	return resp_data;
 }
 
 /* Debuting files is non-NULL only for toplevel items */
@@ -4091,6 +4119,7 @@ copy_move_file (CopyMoveJob *copy_job,
 	if (!overwrite &&
 	    IS_IO_ERROR (error, EXISTS)) {
 		gboolean is_merge;
+		ConflictResponseData *response;
 
 		if (unique_names) {
 			g_object_unref (dest);
@@ -4099,7 +4128,9 @@ copy_move_file (CopyMoveJob *copy_job,
 			goto retry;
 		}
 		    
-		run_my_dialog (job, src, dest, dest_dir);	
+		response = run_conflict_dialog (job, src, dest, dest_dir);
+		g_print ("my response was: id %d, new name %s, apply all %d\n",
+			 response->response, response->new_name, (int) response->apply_to_all);
 		is_merge = FALSE;
 #if 0
 		    if (is_dir (dest)) {



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