[gnome-commander] Respect the users choice what to do if a file which should be copied already exists



commit 28ef68ebf843aa1de3fac0e0515e4c06954f0724
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Wed Sep 8 22:13:50 2021 +0200

    Respect the users choice what to do if a file which should be copied already exists
    
    For this to work I first added a new entry in the Gnome Commander options dialog for
    automatically renaming a copied file if it's filename already exists in the target
    directory (see gnome-cmd-types.h).
    
    The selection is used as a preselected radio button in the copy preparation dialog
    in the GUI. Technically, the selection is forwarded through the overwriteMode member
    of the XferData object over to the methods in gnome-cmd-xfer.cc.
    
    In this file I also introduced a couple of new functions, which are actually only
    extracts of source code from other places. But in these functions itself, the
    overwriteMode is also processed, to decide what to do if a file would be overwritten
    by the copy.

 src/cap.cc                                   |   4 +-
 src/dialogs/gnome-cmd-make-copy-dialog.cc    |   2 +-
 src/dialogs/gnome-cmd-options-dialog.cc      |  23 ++-
 src/dialogs/gnome-cmd-prepare-copy-dialog.cc |  33 ++--
 src/dialogs/gnome-cmd-prepare-move-dialog.cc |   6 +-
 src/dialogs/gnome-cmd-prepare-xfer-dialog.cc |   2 +-
 src/dialogs/gnome-cmd-prepare-xfer-dialog.h  |   4 +-
 src/gnome-cmd-file-list.cc                   |   6 +-
 src/gnome-cmd-types.h                        |   7 +-
 src/gnome-cmd-xfer.cc                        | 229 ++++++++++++++++-----------
 src/gnome-cmd-xfer.h                         |  12 +-
 11 files changed, 197 insertions(+), 131 deletions(-)
---
diff --git a/src/cap.cc b/src/cap.cc
index 10b252fe..331357dd 100644
--- a/src/cap.cc
+++ b/src/cap.cc
@@ -62,7 +62,7 @@ inline void cut_and_paste (GnomeCmdDir *to)
                           _fl,
                           NULL,
                           G_FILE_COPY_NONE,
-                          true,
+                          gnome_cmd_data.options.confirm_move_overwrite,
                           GTK_SIGNAL_FUNC (on_xfer_done), _files);
     _files = NULL;
     _fl = NULL;
@@ -77,7 +77,7 @@ inline void copy_and_paste (GnomeCmdDir *to)
                           _fl,
                           NULL,
                           G_FILE_COPY_NONE,
-                          true,
+                          gnome_cmd_data.options.confirm_copy_overwrite,
                           GTK_SIGNAL_FUNC (on_xfer_done), _files);
     _files = NULL;
     _fl = NULL;
diff --git a/src/dialogs/gnome-cmd-make-copy-dialog.cc b/src/dialogs/gnome-cmd-make-copy-dialog.cc
index a4039860..a3a21bd4 100644
--- a/src/dialogs/gnome-cmd-make-copy-dialog.cc
+++ b/src/dialogs/gnome-cmd-make-copy-dialog.cc
@@ -48,7 +48,7 @@ inline void copy_file (GnomeCmdFile *f, GnomeCmdDir *dir, const gchar *filename)
                           NULL,
                           g_strdup (filename),
                           G_FILE_COPY_NONE,
-                          true,
+                          GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
                           NULL,
                           NULL);
 }
diff --git a/src/dialogs/gnome-cmd-options-dialog.cc b/src/dialogs/gnome-cmd-options-dialog.cc
index a2d583ad..5b9fd16f 100644
--- a/src/dialogs/gnome-cmd-options-dialog.cc
+++ b/src/dialogs/gnome-cmd-options-dialog.cc
@@ -1053,21 +1053,25 @@ static GtkWidget *create_confirmation_tab (GtkWidget *parent, GnomeCmdData::Opti
     /* Copy overwrite options
      */
     cat_box = create_vbox (parent, FALSE, 0);
-    cat = create_category (parent, cat_box, _("Copy overwrite"));
+    cat = create_category (parent, cat_box, _("Preselected overwride action in copy dialog"));
     gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, TRUE, 0);
 
-    radio = create_radio (parent, NULL, _("Silently"), "copy_overwrite_silently");
-    gtk_box_pack_start (GTK_BOX (cat_box), radio, FALSE, TRUE, 0);
-    if (cfg.confirm_copy_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY)
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
-    radio = create_radio (parent, get_radio_group (radio), _("Query first"), "copy_overwrite_query");
+    radio = create_radio (parent, NULL, _("Query first"), "copy_overwrite_query");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
     if (cfg.confirm_copy_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_QUERY)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
-    radio = create_radio (parent, get_radio_group (radio), _("Skip all"), "copy_overwrite_skip_all");
+    radio = create_radio (parent, get_radio_group (radio), _("Rename"), "copy_rename_all");
+    gtk_container_add (GTK_CONTAINER (cat_box), radio);
+    if (cfg.confirm_copy_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL)
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+    radio = create_radio (parent, get_radio_group (radio), _("Skip"), "copy_overwrite_skip_all");
     gtk_container_add (GTK_CONTAINER (cat_box), radio);
     if (cfg.confirm_copy_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+    radio = create_radio (parent, get_radio_group (radio), _("Overwrite silently"), 
"copy_overwrite_silently");
+    gtk_box_pack_start (GTK_BOX (cat_box), radio, FALSE, TRUE, 0);
+    if (cfg.confirm_copy_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY)
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
 
     /* Move overwrite options
@@ -1076,7 +1080,7 @@ static GtkWidget *create_confirmation_tab (GtkWidget *parent, GnomeCmdData::Opti
     cat = create_category (parent, cat_box, _("Move overwrite"));
     gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, TRUE, 0);
 
-    radio = create_radio (parent, NULL, _("Silently"), "move_overwrite_silently");
+    radio = create_radio (parent, NULL, _("Overwrite silently"), "move_overwrite_silently");
     gtk_box_pack_start (GTK_BOX (cat_box), radio, FALSE, TRUE, 0);
     if (cfg.confirm_move_overwrite==GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
@@ -1111,6 +1115,7 @@ void store_confirmation_options (GtkWidget *dialog, GnomeCmdData::Options &cfg)
     GtkWidget *delete_default_check = lookup_widget (dialog, "delete_default_check");
     GtkWidget *confirm_copy_silent = lookup_widget (dialog, "copy_overwrite_silently");
     GtkWidget *confirm_copy_query = lookup_widget (dialog, "copy_overwrite_query");
+    GtkWidget *confirm_copy_rename_all = lookup_widget (dialog, "copy_rename_all");
     GtkWidget *confirm_copy_skip_all = lookup_widget (dialog, "copy_overwrite_skip_all");
     GtkWidget *confirm_move_silent = lookup_widget (dialog, "move_overwrite_silently");
     GtkWidget *confirm_move_query = lookup_widget (dialog, "move_overwrite_query");
@@ -1125,6 +1130,8 @@ void store_confirmation_options (GtkWidget *dialog, GnomeCmdData::Options &cfg)
         cfg.confirm_copy_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY;
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_copy_query)))
         cfg.confirm_copy_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
+    else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_copy_rename_all)))
+        cfg.confirm_copy_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL;
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_copy_skip_all)))
         cfg.confirm_copy_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL;
 
diff --git a/src/dialogs/gnome-cmd-prepare-copy-dialog.cc b/src/dialogs/gnome-cmd-prepare-copy-dialog.cc
index 0a394364..89bb9fa2 100644
--- a/src/dialogs/gnome-cmd-prepare-copy-dialog.cc
+++ b/src/dialogs/gnome-cmd-prepare-copy-dialog.cc
@@ -39,6 +39,7 @@ typedef struct
     GnomeCmdPrepareXferDialog *dialog;
     GtkWidget *silent;
     GtkWidget *query;
+    GtkWidget *rename;
     GtkWidget *skip;
 
     GtkWidget *follow_links;
@@ -55,14 +56,17 @@ static void on_ok (GtkButton *button, gpointer user_data)
 
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->silent)))
     {
-        dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
+        dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY;
         gFileCopyFlags |= G_FILE_COPY_OVERWRITE;
     }
     else
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->query)))
-            dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_QUERY;
+            dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
         else
-            dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_SKIP;
+            if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->rename)))
+                dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL;
+            else
+                dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL;
 
     guint xferOptions = GNOME_VFS_XFER_RECURSIVE;
 
@@ -99,13 +103,6 @@ void gnome_cmd_prepare_copy_dialog_show (GnomeCmdFileSelector *from, GnomeCmdFil
 
     // Create prepare copy specific widgets
 
-    data->silent = gtk_radio_button_new_with_label (group, _("Silently"));
-    group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (data->silent));
-    gtk_widget_ref (data->silent);
-    g_object_set_data_full (G_OBJECT (data->dialog), "silent", data->silent, g_object_unref);
-    gtk_widget_show (data->silent);
-    gtk_box_pack_start (GTK_BOX (data->dialog->left_vbox), data->silent, FALSE, FALSE, 0);
-
     data->query = gtk_radio_button_new_with_label (group, _("Query First"));
     group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (data->query));
     gtk_widget_ref (data->query);
@@ -113,13 +110,27 @@ void gnome_cmd_prepare_copy_dialog_show (GnomeCmdFileSelector *from, GnomeCmdFil
     gtk_widget_show (data->query);
     gtk_box_pack_start (GTK_BOX (data->dialog->left_vbox), data->query, FALSE, FALSE, 0);
 
-    data->skip = gtk_radio_button_new_with_label (group, _("Skip All"));
+    data->rename = gtk_radio_button_new_with_label (group, _("Rename"));
+    group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (data->rename));
+    gtk_widget_ref (data->rename);
+    g_object_set_data_full (G_OBJECT (data->dialog), "rename", data->rename, g_object_unref);
+    gtk_widget_show (data->rename);
+    gtk_box_pack_start (GTK_BOX (data->dialog->left_vbox), data->rename, FALSE, FALSE, 0);
+
+    data->skip = gtk_radio_button_new_with_label (group, _("Skip"));
     group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (data->skip));
     gtk_widget_ref (data->skip);
     g_object_set_data_full (G_OBJECT (data->dialog), "skip", data->skip, g_object_unref);
     gtk_widget_show (data->skip);
     gtk_box_pack_start (GTK_BOX (data->dialog->left_vbox), data->skip, FALSE, FALSE, 0);
 
+    data->silent = gtk_radio_button_new_with_label (group, _("Overwrite silently"));
+    group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (data->silent));
+    gtk_widget_ref (data->silent);
+    g_object_set_data_full (G_OBJECT (data->dialog), "silent", data->silent, g_object_unref);
+    gtk_widget_show (data->silent);
+    gtk_box_pack_start (GTK_BOX (data->dialog->left_vbox), data->silent, FALSE, FALSE, 0);
+
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (g_slist_nth_data (group, 
gnome_cmd_data.options.confirm_copy_overwrite)), TRUE);
 
 
diff --git a/src/dialogs/gnome-cmd-prepare-move-dialog.cc b/src/dialogs/gnome-cmd-prepare-move-dialog.cc
index ad9ab2cd..bce059de 100644
--- a/src/dialogs/gnome-cmd-prepare-move-dialog.cc
+++ b/src/dialogs/gnome-cmd-prepare-move-dialog.cc
@@ -50,12 +50,12 @@ static void on_ok (GtkButton *button, gpointer user_data)
     GnomeCmdPrepareXferDialog *dlg = data->dialog;
 
     if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->silent)))
-        dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE;
+        dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY;
     else
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->query)))
-            dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_QUERY;
+            dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
         else
-            dlg->xferOverwriteMode = GNOME_VFS_XFER_OVERWRITE_MODE_SKIP;
+            dlg->overwriteMode = GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL;
 
     dlg->xferOptions = GNOME_VFS_XFER_REMOVESOURCE;
 }
diff --git a/src/dialogs/gnome-cmd-prepare-xfer-dialog.cc b/src/dialogs/gnome-cmd-prepare-xfer-dialog.cc
index 01bfc0ca..eb41c479 100644
--- a/src/dialogs/gnome-cmd-prepare-xfer-dialog.cc
+++ b/src/dialogs/gnome-cmd-prepare-xfer-dialog.cc
@@ -230,7 +230,7 @@ static void on_ok (GtkButton *button, GnomeCmdPrepareXferDialog *dialog)
                           dialog->src_fs->file_list(),
                           dest_fn,
                           dialog->gFileCopyFlags,
-                          dialog->xferOverwriteMode,
+                          dialog->overwriteMode,
                           NULL, NULL);
 //    gnome_cmd_move_start (dialog->src_files,
 //                          dest_dir,
diff --git a/src/dialogs/gnome-cmd-prepare-xfer-dialog.h b/src/dialogs/gnome-cmd-prepare-xfer-dialog.h
index b5887d3f..ec0cfb66 100644
--- a/src/dialogs/gnome-cmd-prepare-xfer-dialog.h
+++ b/src/dialogs/gnome-cmd-prepare-xfer-dialog.h
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file gnome-cmd-prepare-xfer-dialog.h
  * @copyright (C) 2001-2006 Marcus Bjurman\n
  * @copyright (C) 2007-2012 Piotr Eljasiak\n
@@ -46,7 +46,7 @@ struct GnomeCmdPrepareXferDialog
 
     GFileCopyFlags gFileCopyFlags;
     GnomeVFSXferOptions xferOptions;
-    GnomeVFSXferOverwriteMode xferOverwriteMode;
+    GnomeCmdConfirmOverwriteMode overwriteMode;
 
     GList *src_files;
     GnomeCmdFileSelector *src_fs;
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index d6ed0e1e..2cc88346 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -3276,7 +3276,7 @@ void GnomeCmdFileList::drop_files(DndMode dndMode, GFileCopyFlags gFileCopyFlags
                                          nullptr,
                                          g_list_length (gFileGlist) == 1 ? g_file_get_basename ((GFile *) 
gFileGlist->data) : nullptr,
                                          gFileCopyFlags,
-                                         true,
+                                         GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
                                          nullptr,
                                          nullptr);
             break;
@@ -3287,7 +3287,7 @@ void GnomeCmdFileList::drop_files(DndMode dndMode, GFileCopyFlags gFileCopyFlags
                                          nullptr,
                                          g_list_length (gFileGlist) == 1 ? g_file_get_basename ((GFile *) 
gFileGlist->data) : nullptr,
                                          gFileCopyFlags,
-                                         true,
+                                         GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
                                          nullptr,
                                          nullptr);
             break;
@@ -3298,7 +3298,7 @@ void GnomeCmdFileList::drop_files(DndMode dndMode, GFileCopyFlags gFileCopyFlags
                                          nullptr,
                                          g_list_length (gFileGlist) == 1 ? g_file_get_basename ((GFile *) 
gFileGlist->data) : nullptr,
                                          gFileCopyFlags,
-                                         true,
+                                         GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
                                          nullptr,
                                          nullptr);
             break;
diff --git a/src/gnome-cmd-types.h b/src/gnome-cmd-types.h
index b505b844..dd8ac744 100644
--- a/src/gnome-cmd-types.h
+++ b/src/gnome-cmd-types.h
@@ -85,11 +85,12 @@ typedef enum // Watch out for the usage of GNOME_CMD_COLOR_CUSTOM in gnome-cmd-d
 }GnomeCmdColorMode;
 
 
-typedef enum // The (reversed) order of following enums is significant
+typedef enum // The (reversed) order of following enums compared to the occurence in the GUI is significant
 {
+    GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY,
     GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL,
-    GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
-    GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY
+    GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL,
+    GNOME_CMD_CONFIRM_OVERWRITE_QUERY
 }GnomeCmdConfirmOverwriteMode;
 
 
diff --git a/src/gnome-cmd-xfer.cc b/src/gnome-cmd-xfer.cc
index 02f255a3..3b502035 100644
--- a/src/gnome-cmd-xfer.cc
+++ b/src/gnome-cmd-xfer.cc
@@ -61,6 +61,7 @@ inline void free_xfer_data (XferData *xferData)
 static XferData *
 create_xfer_data (GFileCopyFlags copyFlags, GList *srcGFileList, GList *destGFileList,
                   GnomeCmdDir *to_dir, GnomeCmdFileList *src_fl, GList *src_files,
+                  GnomeCmdConfirmOverwriteMode overwriteMode,
                   GFunc on_completed_func, gpointer on_completed_data)
 {
     XferData *xferData = g_new0 (XferData, 1);
@@ -84,6 +85,7 @@ create_xfer_data (GFileCopyFlags copyFlags, GList *srcGFileList, GList *destGFil
     xferData->problem_action = COPY_ERROR_ACTION_NO_ACTION_YET;
     xferData->thread = nullptr;
     xferData->error = nullptr;
+    xferData->overwriteMode = overwriteMode;
 
     return xferData;
 }
@@ -134,10 +136,112 @@ static void run_simple_error_dialog(const char *msg, XferData *xferData)
     }
 }
 
-static void update_transfer_gui_error_copy (XferData *xferData)
+
+static void run_directory_copy_overwrite_dialog(const char *msg, XferData *xferData)
 {
     gint guiResponse = -1;
+    g_list_length(xferData->srcGFileList) > 1
+    ? guiResponse = run_simple_dialog (
+        *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
+        -1, _("Abort"), _("Retry"), _("Copy into"), _("Rename"), _("Rename all"), _("Skip"), _("Skip all"), 
NULL)
+    : guiResponse = run_simple_dialog (
+        *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
+        -1, _("Abort"), _("Retry"), _("Copy into"), _("Rename"), NULL);
+
+    switch (guiResponse)
+    {
+        case 0:
+            xferData->problem_action = COPY_ERROR_ACTION_ABORT;
+            break;
+        case 1:
+            xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+            break;
+        case 2:
+            xferData->problem_action = COPY_ERROR_ACTION_COPY_INTO;
+            break;
+        case 3:
+            xferData->problem_action = COPY_ERROR_ACTION_RENAME;
+            break;
+        case 4:
+            xferData->problem_action = COPY_ERROR_ACTION_RENAME_ALL;
+            break;
+        case 5:
+            xferData->problem_action = COPY_ERROR_ACTION_SKIP;
+            break;
+        case 6:
+            xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
+            break;
+        default:
+            xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+            break;
+    }
+}
+
+
+static void run_file_copy_overwrite_dialog(XferData *xferData)
+{
+    gint guiResponse = -1;
+    auto problemSrcBasename = get_gfile_attribute_string(xferData->problemSrcGFile, 
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+    auto problemDestBasename = get_gfile_attribute_string(xferData->problemDestGFile, 
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+    auto sourceDetails = get_file_details_string (xferData->problemSrcGFile);
+    auto targetDetails = get_file_details_string (xferData->problemDestGFile);
+
+    auto msg = g_strdup_printf (_("Overwrite file:\n\n<b>%s</b>\n<span color='dimgray' 
size='smaller'>%s</span>\n\nWith:\n\n<b>%s</b>\n<span color='dimgray' size='smaller'>%s</span>"),
+                                problemDestBasename,
+                                targetDetails,
+                                problemSrcBasename,
+                                sourceDetails);
+
+    g_free (problemSrcBasename);
+    g_free (problemDestBasename);
+    g_free (sourceDetails);
+    g_free (targetDetails);
+
+    gdk_threads_enter ();
+    xferData->filesTotal > 1
+    ? guiResponse = run_simple_dialog (
+        *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
+        -1, _("Abort"), _("Retry"), _("Replace"), _("Rename"), _("Skip"), _("Replace all"), _("Rename all"), 
_("Skip all"), NULL)
+    : guiResponse = run_simple_dialog (
+        *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
+        -1, _("Abort"), _("Retry"), _("Replace"), _("Rename"), NULL);
+    gdk_threads_leave ();
+
+    switch (guiResponse)
+    {
+        case 0:
+            xferData->problem_action = COPY_ERROR_ACTION_ABORT;
+            break;
+        case 1:
+            xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+            break;
+        case 2:
+            xferData->problem_action = COPY_ERROR_ACTION_REPLACE;
+            break;
+        case 3:
+            xferData->problem_action = COPY_ERROR_ACTION_RENAME;
+            break;
+        case 4:
+            xferData->problem_action = COPY_ERROR_ACTION_SKIP;
+            break;
+        case 5:
+            xferData->problem_action = COPY_ERROR_ACTION_REPLACE_ALL;
+            break;
+        case 6:
+            xferData->problem_action = COPY_ERROR_ACTION_RENAME_ALL;
+            break;
+        case 7:
+            xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
+            break;
+        default:
+            xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+            break;
+    }
+    g_free (msg);
+}
 
+static void update_transfer_gui_error_copy (XferData *xferData)
+{
     gchar *msg = g_strdup_printf (_("Error while transferring ā€œ%sā€\n\n%s"),
                                     g_file_peek_path(xferData->problemSrcGFile),
                                     xferData->error->message);
@@ -151,97 +255,40 @@ static void update_transfer_gui_error_copy (XferData *xferData)
         if (xferData->currentFileType == G_FILE_TYPE_DIRECTORY)
         {
             gdk_threads_enter ();
-            g_list_length(xferData->srcGFileList) > 1
-            ? guiResponse = run_simple_dialog (
-                *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
-                -1, _("Abort"), _("Retry"), _("Copy into"), _("Rename"), _("Rename all"), _("Skip"), _("Skip 
all"), NULL)
-            : guiResponse = run_simple_dialog (
-                *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
-                -1, _("Abort"), _("Retry"), _("Copy into"), _("Rename"), NULL);
-            gdk_threads_leave ();
-            switch (guiResponse)
+            switch(xferData->overwriteMode)
             {
-                case 0:
-                    xferData->problem_action = COPY_ERROR_ACTION_ABORT;
-                    break;
-                case 1:
-                    xferData->problem_action = COPY_ERROR_ACTION_RETRY;
-                    break;
-                case 2:
-                    xferData->problem_action = COPY_ERROR_ACTION_COPY_INTO;
-                    break;
-                case 3:
-                    xferData->problem_action = COPY_ERROR_ACTION_RENAME;
+                case GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL:
+                    xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
                     break;
-                case 4:
+                case GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL:
                     xferData->problem_action = COPY_ERROR_ACTION_RENAME_ALL;
                     break;
-                case 5:
-                    xferData->problem_action = COPY_ERROR_ACTION_SKIP;
-                    break;
-                case 6:
-                    xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
+                case GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY:
+                    xferData->problem_action = COPY_ERROR_ACTION_COPY_INTO;
                     break;
+                case GNOME_CMD_CONFIRM_OVERWRITE_QUERY:
                 default:
-                    xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+                    run_directory_copy_overwrite_dialog(msg, xferData);
                     break;
             }
+            gdk_threads_leave ();
         }
         if (xferData->currentFileType == G_FILE_TYPE_REGULAR)
         {
-            auto problemSrcBasename = get_gfile_attribute_string(xferData->problemSrcGFile,
-                                                        G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
-            auto problemDestBasename = get_gfile_attribute_string(xferData->problemDestGFile,
-                                                        G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
-            auto sourceDetails = get_file_details_string (xferData->problemSrcGFile);
-            auto targetDetails = get_file_details_string (xferData->problemDestGFile);
-            g_free(msg);
-            msg = g_strdup_printf (_("Overwrite file:\n\n<b>%s</b>\n<span color='dimgray' 
size='smaller'>%s</span>\n\nWith:\n\n<b>%s</b>\n<span color='dimgray' size='smaller'>%s</span>"),
-                    problemDestBasename,
-                    targetDetails,
-                    problemSrcBasename,
-                    sourceDetails);
-            g_free (problemSrcBasename);
-            g_free (problemDestBasename);
-            g_free (sourceDetails);
-            g_free (targetDetails);
-            gdk_threads_enter ();
-            xferData->filesTotal > 1
-            ? guiResponse = run_simple_dialog (
-                *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
-                -1, _("Abort"), _("Retry"), _("Replace"), _("Rename"), _("Skip"), _("Replace all"), 
_("Rename all"), _("Skip all"), NULL)
-            : guiResponse = run_simple_dialog (
-                *main_win, TRUE, GTK_MESSAGE_ERROR, msg, _("Copy problem"),
-                -1, _("Abort"), _("Retry"), _("Replace"), _("Rename"), NULL);
-            gdk_threads_leave ();
-            switch (guiResponse)
+            switch(xferData->overwriteMode)
             {
-                case 0:
-                    xferData->problem_action = COPY_ERROR_ACTION_ABORT;
-                    break;
-                case 1:
-                    xferData->problem_action = COPY_ERROR_ACTION_RETRY;
-                    break;
-                case 2:
-                    xferData->problem_action = COPY_ERROR_ACTION_REPLACE;
-                    break;
-                case 3:
-                    xferData->problem_action = COPY_ERROR_ACTION_RENAME;
-                    break;
-                case 4:
-                    xferData->problem_action = COPY_ERROR_ACTION_SKIP;
-                    break;
-                case 5:
-                    xferData->problem_action = COPY_ERROR_ACTION_REPLACE_ALL;
+                case GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL:
+                    xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
                     break;
-                case 6:
+                case GNOME_CMD_CONFIRM_OVERWRITE_RENAME_ALL:
                     xferData->problem_action = COPY_ERROR_ACTION_RENAME_ALL;
                     break;
-                case 7:
-                    xferData->problem_action = COPY_ERROR_ACTION_SKIP_ALL;
+                case GNOME_CMD_CONFIRM_OVERWRITE_SILENTLY:
+                    xferData->problem_action = COPY_ERROR_ACTION_REPLACE_ALL;
                     break;
+                case GNOME_CMD_CONFIRM_OVERWRITE_QUERY:
                 default:
-                    xferData->problem_action = COPY_ERROR_ACTION_RETRY;
+                    run_file_copy_overwrite_dialog(xferData);
                     break;
             }
         }
@@ -601,7 +648,7 @@ gnome_cmd_copy_gfiles_start (GList *srcGFileGList,
                              GList *srcFilesGList,
                              gchar *destFileName,
                              GFileCopyFlags copyFlags,
-                             gboolean skipAsk,
+                             GnomeCmdConfirmOverwriteMode overwriteMode,
                              GtkSignalFunc on_completed_func,
                              gpointer on_completed_data)
 {
@@ -633,7 +680,7 @@ gnome_cmd_copy_gfiles_start (GList *srcGFileGList,
     }
 
     XferData *xferData = create_xfer_data (copyFlags, srcGFileGList, nullptr,
-                            destGnomeCmdDir, srcGnomeCmdFileList, srcFilesGList,
+                            destGnomeCmdDir, srcGnomeCmdFileList, srcFilesGList, overwriteMode,
                             (GFunc) on_completed_func, on_completed_data);
     xferData->transferType = COPY;
 
@@ -681,7 +728,7 @@ gnome_cmd_move_gfiles_start (GList *srcGFileGList,
                              GList *srcGnomeCmdFileGList,
                              gchar *destFileName,
                              GFileCopyFlags copyFlags,
-                             gboolean skipAsk,
+                             GnomeCmdConfirmOverwriteMode overwriteMode,
                              GtkSignalFunc on_completed_func,
                              gpointer on_completed_data)
 {
@@ -714,7 +761,7 @@ gnome_cmd_move_gfiles_start (GList *srcGFileGList,
 
     XferData *xferData = create_xfer_data (copyFlags, srcGFileGList, nullptr,
                             destGnomeCmdDir, srcGnomeCmdFileList, srcGnomeCmdFileGList,
-                            (GFunc) on_completed_func, on_completed_data);
+                            overwriteMode, (GFunc) on_completed_func, on_completed_data);
     xferData->transferType = MOVE;
 
     if (g_list_length (srcGFileGList) == 1 && destFileName != nullptr)
@@ -762,7 +809,7 @@ gnome_cmd_link_gfiles_start (GList *srcGFileGList,
                              GList *srcGnomeCmdFileGList,
                              gchar *destFileName,
                              GFileCopyFlags copyFlags,
-                             gboolean skipAsk,
+                             GnomeCmdConfirmOverwriteMode overwriteMode,
                              GtkSignalFunc on_completed_func,
                              gpointer on_completed_data)
 {
@@ -795,7 +842,7 @@ gnome_cmd_link_gfiles_start (GList *srcGFileGList,
 
     XferData *xferData = create_xfer_data (copyFlags, srcGFileGList, nullptr,
                             destGnomeCmdDir, srcGnomeCmdFileList, srcGnomeCmdFileGList,
-                            (GFunc) on_completed_func, on_completed_data);
+                            overwriteMode, (GFunc) on_completed_func, on_completed_data);
     xferData->transferType = LINK;
 
     if (g_list_length (srcGFileGList) == 1 && destFileName != nullptr)
@@ -851,7 +898,7 @@ gnome_cmd_tmp_download (GFile *srcGFile,
     auto destGFileList = g_list_append (nullptr, destGFile);
 
     auto xferData = create_xfer_data (copyFlags, srcGFileList, destGFileList,
-                             nullptr, nullptr, nullptr,
+                             nullptr, nullptr, nullptr, GNOME_CMD_CONFIRM_OVERWRITE_QUERY,
                              (GFunc) on_completed_func, on_completed_data);
     xferData->transferType = COPY;
 
@@ -1152,6 +1199,7 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
         case G_FILE_TYPE_DIRECTORY:
         {
             xferData->currentFileType = G_FILE_TYPE_DIRECTORY;
+
             switch (xferData->problem_action)
             {
                 case COPY_ERROR_ACTION_NO_ACTION_YET:
@@ -1210,6 +1258,7 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                     return false;
             }
 
+            // After processing the user response above, we are looping through the directory now.
             auto enumerator = g_file_enumerate_children(srcGFile, "*", G_FILE_QUERY_INFO_NONE, NULL, 
&tmpError);
             if (tmpError)
             {
@@ -1221,8 +1270,6 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                 return false;
             }
 
-            // Loop through the items of the directory.
-            // Probably this can be extracted into an own function.
             auto gFileInfoChildFile = g_file_enumerator_next_file(enumerator, nullptr, &tmpError);
             while(gFileInfoChildFile != nullptr && !tmpError)
             {
@@ -1246,7 +1293,6 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                     auto srcChildGFile = g_file_get_child(g_file_enumerator_get_container(enumerator), 
fileNameChildGFile);
                     auto targetPath = g_strdup_printf("%s%s%s", g_file_peek_path(destGFile), 
G_DIR_SEPARATOR_S, fileNameChildGFile);
                     auto targetGFile = g_file_new_for_path(targetPath);
-
                     do_the_copy(srcChildGFile, targetGFile, copyFlags, xferDataPointer);
                     switch (xferData->problem_action)
                     {
@@ -1304,7 +1350,6 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                 g_propagate_error(&(xferData->error), tmpError);
                 xfer_progress_update(xferData);
             }
-
             g_file_enumerator_close (enumerator, nullptr, nullptr);
             break;
         }
@@ -1324,7 +1369,7 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                 case COPY_ERROR_ACTION_RENAME:
                     xferData->problem_action = COPY_ERROR_ACTION_NO_ACTION_YET;
                     set_new_nonexisting_dest_gfile(srcGFile, &destGFile, xferData);
-                    gnome_cmd_copy_gfile_recursive(srcGFile, destGFile, copyFlags, xferData);
+                    do_the_copy(srcGFile, destGFile, copyFlags, xferDataPointer);
                     break;
                 case COPY_ERROR_ACTION_SKIP:
                     xferData->problem_action = COPY_ERROR_ACTION_NO_ACTION_YET;
@@ -1336,7 +1381,7 @@ gnome_cmd_copy_gfile_recursive (GFile *srcGFile,
                     return true;
                 case COPY_ERROR_ACTION_RENAME_ALL:
                     set_new_nonexisting_dest_gfile(srcGFile, &destGFile, xferData);
-                    gnome_cmd_copy_gfile_recursive(srcGFile, destGFile, copyFlags, xferData);
+                    do_the_copy(srcGFile, destGFile, copyFlags, xferDataPointer);
                     break;
                 case COPY_ERROR_ACTION_COPY_INTO: // This is not handled for files when copying
                 case COPY_ERROR_ACTION_ABORT:
@@ -1371,7 +1416,7 @@ gnome_cmd_copy_start (GList *srcGnomeCmdFileGList,
                       GnomeCmdFileList *srcGnomeCmdFileList,
                       gchar *destFileName,
                       GFileCopyFlags copyFlags,
-                      gboolean skipAsk,
+                      GnomeCmdConfirmOverwriteMode overwriteMode,
                       GtkSignalFunc on_completed_func,
                       gpointer on_completed_data)
 {
@@ -1386,7 +1431,7 @@ gnome_cmd_copy_start (GList *srcGnomeCmdFileGList,
                                srcGnomeCmdFileGList,
                                destFileName,
                                copyFlags,
-                               skipAsk,
+                               overwriteMode,
                                on_completed_func,
                                on_completed_data);
 }
@@ -1397,7 +1442,7 @@ gnome_cmd_move_start (GList *srcGnomeCmdFileGList,
                       GnomeCmdFileList *srcGnomeCmdFileList,
                       gchar *destFileName,
                       GFileCopyFlags copyFlags,
-                      gboolean skipAsk,
+                      GnomeCmdConfirmOverwriteMode overwriteMode,
                       GtkSignalFunc on_completed_func,
                       gpointer on_completed_data)
 {
@@ -1412,7 +1457,7 @@ gnome_cmd_move_start (GList *srcGnomeCmdFileGList,
                                  srcGnomeCmdFileGList,
                                  destFileName,
                                  copyFlags,
-                                 skipAsk,
+                                 overwriteMode,
                                  on_completed_func,
                                  on_completed_data);
 }
diff --git a/src/gnome-cmd-xfer.h b/src/gnome-cmd-xfer.h
index 355048e7..7b35d54c 100644
--- a/src/gnome-cmd-xfer.h
+++ b/src/gnome-cmd-xfer.h
@@ -21,6 +21,7 @@
 
 #pragma once
 
+#include "gnome-cmd-types.h"
 #include "gnome-cmd-dir.h"
 #include "gnome-cmd-file-list.h"
 #include "gnome-cmd-xfer-progress-win.h"
@@ -49,6 +50,7 @@ enum TRANSFER_TYPE
 struct XferData
 {
     GFileCopyFlags copyFlags;
+    GnomeCmdConfirmOverwriteMode overwriteMode;
     GnomeVFSXferOptions xferOptions;
     GnomeVFSAsyncHandle *handle;
     TRANSFER_TYPE transferType{COPY};
@@ -96,7 +98,7 @@ gnome_cmd_copy_start (GList *src_files,
                       GnomeCmdFileList *src_fl,
                       gchar *dest_fn,
                       GFileCopyFlags copyFlags,
-                      gboolean skipAsk,
+                      GnomeCmdConfirmOverwriteMode overwriteMode,
                       GtkSignalFunc on_completed_func,
                       gpointer on_completed_data);
 
@@ -106,7 +108,7 @@ gnome_cmd_move_start (GList *src_files,
                       GnomeCmdFileList *src_fl,
                       gchar *dest_fn,
                       GFileCopyFlags copyFlags,
-                      gboolean skipAsk,
+                      GnomeCmdConfirmOverwriteMode overwriteMode,
                       GtkSignalFunc on_completed_func,
                       gpointer on_completed_data);
 
@@ -117,7 +119,7 @@ gnome_cmd_copy_gfiles_start (GList *src_uri_list,
                            GList *src_files,
                            gchar *dest_fn,
                            GFileCopyFlags copyFlags,
-                           gboolean skipAsk,
+                           GnomeCmdConfirmOverwriteMode overwriteMode,
                            GtkSignalFunc on_completed_func,
                            gpointer on_completed_data);
 
@@ -128,7 +130,7 @@ gnome_cmd_move_gfiles_start (GList *src_uri_list,
                            GList *src_files,
                            gchar *dest_fn,
                            GFileCopyFlags copyFlags,
-                           gboolean skipAsk,
+                           GnomeCmdConfirmOverwriteMode overwriteMode,
                            GtkSignalFunc on_completed_func,
                            gpointer on_completed_data);
 
@@ -139,7 +141,7 @@ gnome_cmd_link_gfiles_start (GList *src_uri_list,
                            GList *src_files,
                            gchar *dest_fn,
                            GFileCopyFlags copyFlags,
-                           gboolean skipAsk,
+                           GnomeCmdConfirmOverwriteMode overwriteMode,
                            GtkSignalFunc on_completed_func,
                            gpointer on_completed_data);
 


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