[nautilus/wip/oholy/extraction-fixes: 12/14] file-operations: Do not offer skipping when extracting one file




commit 713ed864b7005ce63b84e396d867db6385228270
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Sep 24 09:42:54 2021 +0200

    file-operations: Do not offer skipping when extracting one file
    
    In case of extraction failure, the "Skip" and "Cancel" actions are offered
    everytime, but skipping doesn't make sense when extracting one file only.
    Let's use the same approach as it is used also for other operations, which
    is based on total number of files and remaining files. Also the "Skip All"
    action will be offered as a side-effect of this change.

 src/nautilus-file-operations.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index fb5168c2e..d9aaace36 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -210,6 +210,7 @@ typedef struct
 
     guint64 archive_compressed_size;
     guint64 total_compressed_size;
+    gint total_files;
 
     NautilusExtractCallback done_callback;
     gpointer done_callback_data;
@@ -8327,6 +8328,7 @@ extract_job_on_error (AutoarExtractor *extractor,
     GFile *source_file;
     GFile *destination;
     gint response_id;
+    gint remaining_files;
     g_autofree gchar *basename = NULL;
 
     source_file = autoar_extractor_get_source_file (extractor);
@@ -8348,25 +8350,35 @@ extract_job_on_error (AutoarExtractor *extractor,
         g_object_unref (destination);
     }
 
+    if (extract_job->common.skip_all_error)
+    {
+        return;
+    }
+
     basename = get_basename (source_file);
     nautilus_progress_info_take_status (extract_job->common.progress,
                                         g_strdup_printf (_("Error extracting “%s”"),
                                                          basename));
 
-    response_id = run_warning ((CommonJob *) extract_job,
-                               g_strdup_printf (_("There was an error while extracting “%s”."),
-                                                basename),
-                               g_strdup (error->message),
-                               NULL,
-                               FALSE,
-                               CANCEL,
-                               SKIP,
-                               NULL);
+    remaining_files = g_list_length (g_list_find_custom (extract_job->source_files,
+                                                         source_file,
+                                                         (GCompareFunc) g_file_equal)) - 1;
+    response_id = run_cancel_or_skip_warning ((CommonJob *) extract_job,
+                                              g_strdup_printf (_("There was an error while extracting 
“%s”."),
+                                                               basename),
+                                              g_strdup (error->message),
+                                              NULL,
+                                              extract_job->total_files,
+                                              remaining_files);
 
     if (response_id == 0 || response_id == GTK_RESPONSE_DELETE_EVENT)
     {
         abort_job ((CommonJob *) extract_job);
     }
+    else if (response_id == 1)
+    {
+        extract_job->common.skip_all_error = TRUE;
+    }
 }
 
 static void
@@ -8598,7 +8610,6 @@ extract_task_thread_func (GTask        *task,
 {
     ExtractJob *extract_job = task_data;
     GList *l;
-    gint total_files;
     g_autofree guint64 *archive_compressed_sizes = NULL;
     gint i;
 
@@ -8609,9 +8620,10 @@ extract_task_thread_func (GTask        *task,
     nautilus_progress_info_set_details (extract_job->common.progress,
                                         _("Preparing to extract"));
 
-    total_files = g_list_length (extract_job->source_files);
+    extract_job->total_files = g_list_length (extract_job->source_files);
 
-    archive_compressed_sizes = g_malloc0_n (total_files, sizeof (guint64));
+    archive_compressed_sizes = g_malloc0_n (extract_job->total_files,
+                                            sizeof (guint64));
     extract_job->total_compressed_size = 0;
 
     for (l = extract_job->source_files, i = 0;
@@ -8682,7 +8694,7 @@ extract_task_thread_func (GTask        *task,
 
     if (!job_aborted ((CommonJob *) extract_job))
     {
-        report_extract_final_progress (extract_job, total_files);
+        report_extract_final_progress (extract_job, extract_job->total_files);
     }
 
     if (extract_job->common.undo_info)


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