[Xfce4-commits] [xfce/thunar] 01/02: thunar-job: callee should keep track of the number of processed files (Bug #16117)

noreply at xfce.org noreply at xfce.org
Sun Nov 3 23:57:23 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       x   f   c   e   -   4   .   1   4   
   in repository xfce/thunar.

commit 00188732fc51aa40c29a4a13ff29b1a930a4d124
Author: Andre Miranda <andreldm at xfce.org>
Date:   Sun Nov 3 13:36:25 2019 -0300

    thunar-job: callee should keep track of the number of processed files (Bug #16117)
---
 thunar/thunar-io-jobs.c | 32 ++++++++++++++++++++------------
 thunar/thunar-job.c     | 29 +++++++++++------------------
 thunar/thunar-job.h     |  3 ++-
 3 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c
index a6e2dc2..f118f55 100644
--- a/thunar/thunar-io-jobs.c
+++ b/thunar/thunar-io-jobs.c
@@ -96,6 +96,7 @@ _thunar_io_jobs_create (ThunarJob  *job,
   GList             *lp;
   gchar             *base_name;
   gchar             *display_name;
+  guint              n_processed = 0;
   GFile             *template_file;
   GFileInputStream  *template_stream = NULL;
 
@@ -126,12 +127,12 @@ _thunar_io_jobs_create (ThunarJob  *job,
   /* iterate over all files in the list */
   for (lp = file_list;
        err == NULL && lp != NULL && !exo_job_is_cancelled (EXO_JOB (job));
-       lp = lp->next)
+       lp = lp->next, n_processed++)
     {
       g_assert (G_IS_FILE (lp->data));
 
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), lp);
+      thunar_job_processing_file (THUNAR_JOB (job), lp, n_processed);
 
 again:
       /* try to create the file */
@@ -272,6 +273,7 @@ _thunar_io_jobs_mkdir (ThunarJob  *job,
   GList            *lp;
   gchar            *base_name;
   gchar            *display_name;
+  guint             n_processed = 0;
 
   _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
   _thunar_return_val_if_fail (param_values != NULL, FALSE);
@@ -285,12 +287,12 @@ _thunar_io_jobs_mkdir (ThunarJob  *job,
 
   for (lp = file_list;
        err == NULL && lp != NULL && !exo_job_is_cancelled (EXO_JOB (job));
-       lp = lp->next)
+       lp = lp->next,  n_processed++)
     {
       g_assert (G_IS_FILE (lp->data));
 
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), lp);
+      thunar_job_processing_file (THUNAR_JOB (job), lp, n_processed);
 
 again:
       /* try to create the directory */
@@ -410,6 +412,7 @@ _thunar_io_jobs_unlink (ThunarJob  *job,
   GList                *lp;
   gchar                *base_name;
   gchar                *display_name;
+  guint                 n_processed = 0;
 
   _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
   _thunar_return_val_if_fail (param_values != NULL, FALSE);
@@ -446,7 +449,9 @@ _thunar_io_jobs_unlink (ThunarJob  *job,
   g_object_unref (application);
 
   /* remove all the files */
-  for (lp = file_list; lp != NULL && !exo_job_is_cancelled (EXO_JOB (job)); lp = lp->next)
+  for (lp = file_list;
+       lp != NULL && !exo_job_is_cancelled (EXO_JOB (job));
+       lp = lp->next, n_processed++)
     {
       g_assert (G_IS_FILE (lp->data));
 
@@ -455,7 +460,7 @@ _thunar_io_jobs_unlink (ThunarJob  *job,
         continue;
 
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), lp);
+      thunar_job_processing_file (THUNAR_JOB (job), lp, n_processed);
 
 again:
       /* try to delete the file */
@@ -708,6 +713,7 @@ _thunar_io_jobs_link (ThunarJob  *job,
   GList                *sp;
   GList                *target_file_list;
   GList                *tp;
+  guint                 n_processed = 0;
 
   _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
   _thunar_return_val_if_fail (param_values != NULL, FALSE);
@@ -728,13 +734,13 @@ _thunar_io_jobs_link (ThunarJob  *job,
   /* process all files */
   for (sp = source_file_list, tp = target_file_list;
        err == NULL && sp != NULL && tp != NULL;
-       sp = sp->next, tp = tp->next)
+       sp = sp->next, tp = tp->next, n_processed++)
     {
       _thunar_assert (G_IS_FILE (sp->data));
       _thunar_assert (G_IS_FILE (tp->data));
 
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), sp);
+      thunar_job_processing_file (THUNAR_JOB (job), sp, n_processed);
 
       /* try to create the symbolic link */
       real_target_file = _thunar_io_jobs_link_file (job, sp->data, tp->data, &err);
@@ -888,6 +894,7 @@ _thunar_io_jobs_chown (ThunarJob  *job,
   GList            *lp;
   gint              uid;
   gint              gid;
+  guint             n_processed = 0;
 
   _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE);
   _thunar_return_val_if_fail (param_values != NULL, FALSE);
@@ -917,10 +924,10 @@ _thunar_io_jobs_chown (ThunarJob  *job,
   thunar_job_set_total_files (THUNAR_JOB (job), file_list);
 
   /* change the ownership of all files */
-  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next)
+  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next, n_processed++)
     {
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), lp);
+      thunar_job_processing_file (THUNAR_JOB (job), lp, n_processed);
 
       /* try to query information about the file */
       info = g_file_query_info (lp->data,
@@ -1022,6 +1029,7 @@ _thunar_io_jobs_chmod (ThunarJob  *job,
   GError           *err = NULL;
   GList            *file_list;
   GList            *lp;
+  guint             n_processed = 0;
   ThunarFileMode    dir_mask;
   ThunarFileMode    dir_mode;
   ThunarFileMode    file_mask;
@@ -1059,10 +1067,10 @@ _thunar_io_jobs_chmod (ThunarJob  *job,
   thunar_job_set_total_files (THUNAR_JOB (job), file_list);
 
   /* change the ownership of all files */
-  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next)
+  for (lp = file_list; lp != NULL && err == NULL; lp = lp->next, n_processed++)
     {
       /* update progress information */
-      thunar_job_processing_file (THUNAR_JOB (job), lp);
+      thunar_job_processing_file (THUNAR_JOB (job), lp, n_processed);
 
       /* try to query information about the file */
       info = g_file_query_info (lp->data,
diff --git a/thunar/thunar-job.c b/thunar/thunar-job.c
index 22f4028..d5fd026 100644
--- a/thunar/thunar-job.c
+++ b/thunar/thunar-job.c
@@ -66,6 +66,7 @@ struct _ThunarJobPrivate
   ThunarJobResponse earlier_ask_overwrite_response;
   ThunarJobResponse earlier_ask_skip_response;
   GList            *total_files;
+  guint             n_total_files;
 };
 
 
@@ -206,6 +207,7 @@ thunar_job_init (ThunarJob *job)
   job->priv->earlier_ask_create_response = 0;
   job->priv->earlier_ask_overwrite_response = 0;
   job->priv->earlier_ask_skip_response = 0;
+  job->priv->n_total_files = 0;
 }
 
 
@@ -591,23 +593,28 @@ thunar_job_set_total_files (ThunarJob *job,
   _thunar_return_if_fail (total_files != NULL);
 
   job->priv->total_files = total_files;
+  job->priv->n_total_files = g_list_length (total_files);
 }
 
 
 
 void
 thunar_job_processing_file (ThunarJob *job,
-                            GList     *current_file)
+                            GList     *current_file,
+                            guint      n_processed)
 {
   GList *lp;
   gchar *base_name;
   gchar *display_name;
-  guint  n_processed;
   guint  n_total;
 
   _thunar_return_if_fail (THUNAR_IS_JOB (job));
   _thunar_return_if_fail (current_file != NULL);
 
+  /* emit only if n_processed is a multiple of 8 */
+  if ((n_processed % 8) != 0)
+    return;
+
   base_name = g_file_get_basename (current_file->data);
   display_name = g_filename_display_name (base_name);
   g_free (base_name);
@@ -616,20 +623,6 @@ thunar_job_processing_file (ThunarJob *job,
   g_free (display_name);
 
   /* verify that we have total files set */
-  if (G_LIKELY (job->priv->total_files != NULL))
-    {
-      /* determine the number of files processed so far */
-      for (lp = job->priv->total_files, n_processed = 0;
-           lp != current_file;
-           lp = lp->next, n_processed++);
-
-      /* emit only if n_processed is a multiple of 8 */
-      if ((n_processed % 8) == 0)
-        {
-          /* determine the total_number of files */
-          n_total = g_list_length (job->priv->total_files);
-
-          exo_job_percent (EXO_JOB (job), (n_processed * 100.0) / n_total);
-        }
-    }
+  if (G_LIKELY (job->priv->n_total_files > 0))
+    exo_job_percent (EXO_JOB (job), (n_processed * 100.0) / job->priv->n_total_files);
 }
diff --git a/thunar/thunar-job.h b/thunar/thunar-job.h
index f1f636b..c28e33d 100644
--- a/thunar/thunar-job.h
+++ b/thunar/thunar-job.h
@@ -69,7 +69,8 @@ GType             thunar_job_get_type               (void) G_GNUC_CONST;
 void              thunar_job_set_total_files        (ThunarJob       *job,
                                                      GList           *total_files);
 void              thunar_job_processing_file        (ThunarJob       *job,
-                                                     GList           *current_file);
+                                                     GList           *current_file,
+                                                     guint            n_processed);
 
 ThunarJobResponse thunar_job_ask_create             (ThunarJob       *job,
                                                      const gchar     *format,

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


More information about the Xfce4-commits mailing list