[Xfce4-commits] [xfce/thunar] 01/01: When move to trash fails, ask whether to delete files (Bug #15975)

noreply at xfce.org noreply at xfce.org
Mon Dec 23 16:30:37 CET 2019


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/thunar.

commit 3d377f91b84cfd01b6526ea733bd4f568faf59ec
Author: Andre Miranda <andreldm at xfce.org>
Date:   Mon Dec 23 12:29:17 2019 -0300

    When move to trash fails, ask whether to delete files (Bug #15975)
---
 thunar/thunar-io-jobs.c | 14 ++++++++++++
 thunar/thunar-job.c     | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-job.h     |  3 +++
 3 files changed, 76 insertions(+)

diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c
index f118f55..23941d2 100644
--- a/thunar/thunar-io-jobs.c
+++ b/thunar/thunar-io-jobs.c
@@ -805,6 +805,7 @@ _thunar_io_jobs_trash (ThunarJob  *job,
 {
   ThunarThumbnailCache *thumbnail_cache;
   ThunarApplication    *application;
+  ThunarJobResponse     response;
   GError               *err = NULL;
   GList                *file_list;
   GList                *lp;
@@ -831,6 +832,19 @@ _thunar_io_jobs_trash (ThunarJob  *job,
       /* trash the file or folder */
       g_file_trash (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err);
 
+      if (err != NULL)
+        {
+          response = thunar_job_ask_delete (job, "%s", err->message);
+
+          g_clear_error (&err);
+
+          if (response == THUNAR_JOB_RESPONSE_CANCEL)
+            break;
+
+          if (response == THUNAR_JOB_RESPONSE_YES)
+            g_file_delete (lp->data, exo_job_get_cancellable (EXO_JOB (job)), &err);
+        }
+
       /* update the thumbnail cache */
       thunar_thumbnail_cache_cleanup_file (thumbnail_cache, lp->data);
     }
diff --git a/thunar/thunar-job.c b/thunar/thunar-job.c
index e6cbe01..88cc36d 100644
--- a/thunar/thunar-job.c
+++ b/thunar/thunar-job.c
@@ -64,6 +64,7 @@ struct _ThunarJobPrivate
 {
   ThunarJobResponse earlier_ask_create_response;
   ThunarJobResponse earlier_ask_overwrite_response;
+  ThunarJobResponse earlier_ask_delete_response;
   ThunarJobResponse earlier_ask_skip_response;
   GList            *total_files;
   guint             n_total_files;
@@ -206,6 +207,7 @@ thunar_job_init (ThunarJob *job)
   job->priv = thunar_job_get_instance_private (job);
   job->priv->earlier_ask_create_response = 0;
   job->priv->earlier_ask_overwrite_response = 0;
+  job->priv->earlier_ask_delete_response = 0;
   job->priv->earlier_ask_skip_response = 0;
   job->priv->n_total_files = 0;
 }
@@ -358,6 +360,63 @@ thunar_job_ask_overwrite (ThunarJob   *job,
 
 
 ThunarJobResponse
+thunar_job_ask_delete (ThunarJob   *job,
+                       const gchar *format,
+                       ...)
+{
+  ThunarJobResponse response;
+  va_list           var_args;
+
+  _thunar_return_val_if_fail (THUNAR_IS_JOB (job), THUNAR_JOB_RESPONSE_CANCEL);
+  _thunar_return_val_if_fail (format != NULL, THUNAR_JOB_RESPONSE_CANCEL);
+
+  /* check if the user already cancelled the job */
+  if (G_UNLIKELY (exo_job_is_cancelled (EXO_JOB (job))))
+    return THUNAR_JOB_RESPONSE_CANCEL;
+
+  /* check if the user said "Delete All" earlier */
+  if (G_UNLIKELY (job->priv->earlier_ask_delete_response == THUNAR_JOB_RESPONSE_YES_ALL))
+    return THUNAR_JOB_RESPONSE_YES;
+
+  /* check if the user said "Delete None" earlier */
+  if (G_UNLIKELY (job->priv->earlier_ask_delete_response == THUNAR_JOB_RESPONSE_NO_ALL))
+    return THUNAR_JOB_RESPONSE_NO;
+
+  /* ask the user what he wants to do */
+  va_start (var_args, format);
+  response = _thunar_job_ask_valist (job, format, var_args,
+                                     _("Do you want to permanently delete it?"),
+                                     THUNAR_JOB_RESPONSE_YES
+                                     | THUNAR_JOB_RESPONSE_YES_ALL
+                                     | THUNAR_JOB_RESPONSE_NO
+                                     | THUNAR_JOB_RESPONSE_NO_ALL
+                                     | THUNAR_JOB_RESPONSE_CANCEL);
+  va_end (var_args);
+
+  /* remember response for later */
+  job->priv->earlier_ask_delete_response = response;
+
+  /* translate response */
+  switch (response)
+    {
+    case THUNAR_JOB_RESPONSE_YES_ALL:
+      response = THUNAR_JOB_RESPONSE_YES;
+      break;
+
+    case THUNAR_JOB_RESPONSE_NO_ALL:
+      response = THUNAR_JOB_RESPONSE_NO;
+      break;
+
+    default:
+      break;
+    }
+
+  return response;
+}
+
+
+
+ThunarJobResponse
 thunar_job_ask_create (ThunarJob   *job,
                        const gchar *format,
                        ...)
diff --git a/thunar/thunar-job.h b/thunar/thunar-job.h
index c28e33d..9c0a7b4 100644
--- a/thunar/thunar-job.h
+++ b/thunar/thunar-job.h
@@ -78,6 +78,9 @@ ThunarJobResponse thunar_job_ask_create             (ThunarJob       *job,
 ThunarJobResponse thunar_job_ask_overwrite          (ThunarJob       *job,
                                                      const gchar     *format,
                                                      ...);
+ThunarJobResponse thunar_job_ask_delete             (ThunarJob       *job,
+                                                     const gchar     *format,
+                                                     ...);
 ThunarJobResponse thunar_job_ask_replace            (ThunarJob       *job,
                                                      GFile           *source_path,
                                                      GFile           *target_path,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list