[gthumb] trash/delete files: show progress for long operations



commit 4c8a92a191ba3b5fdf90b36813248941d20488d2
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Dec 9 17:37:52 2019 +0100

    trash/delete files: show progress for long operations

 extensions/webalbums/gth-web-exporter.c |  1 +
 gthumb/gio-utils.c                      | 82 ++++++++++++++++++++++++---------
 gthumb/gio-utils.h                      |  2 +
 gthumb/gth-delete-task.c                | 15 ++++++
 gthumb/gth-trash-task.c                 | 15 ++++++
 5 files changed, 93 insertions(+), 22 deletions(-)
---
diff --git a/extensions/webalbums/gth-web-exporter.c b/extensions/webalbums/gth-web-exporter.c
index cce2c5c6..a6cd5f20 100644
--- a/extensions/webalbums/gth-web-exporter.c
+++ b/extensions/webalbums/gth-web-exporter.c
@@ -1856,6 +1856,7 @@ cleanup_and_terminate (GthWebExporter *self,
                                           TRUE,
                                           TRUE,
                                           NULL,
+                                          NULL,
                                           delete_temp_dir_ready_cb,
                                           self);
 
diff --git a/gthumb/gio-utils.c b/gthumb/gio-utils.c
index d094451a..b97eb5bb 100644
--- a/gthumb/gio-utils.c
+++ b/gthumb/gio-utils.c
@@ -1575,12 +1575,15 @@ _g_file_list_delete (GList     *file_list,
 
 
 typedef struct {
-       GList        *file_list;
-       GList        *current;
-       gboolean      include_metadata;
-       GCancellable *cancellable;
-       ReadyFunc     callback;
-       gpointer      user_data;
+       GList             *file_list;
+       GList             *current;
+       gboolean           include_metadata;
+       GCancellable      *cancellable;
+       ProgressCallback   progress_callback;
+       ReadyFunc          callback;
+       gpointer           user_data;
+       glong              n_files;
+       glong              n_deleted;
 } DeleteData;
 
 
@@ -1611,6 +1614,7 @@ delete_files__delete_current_cb (GObject      *source_object,
                return;
        }
 
+       delete_data->n_deleted++;
        delete_data->current = delete_data->current->next;
        delete_files__delete_current (delete_data);
 }
@@ -1627,6 +1631,14 @@ delete_files__delete_current (DeleteData *delete_data)
                return;
        }
 
+       if (delete_data->progress_callback != NULL)
+               delete_data->progress_callback (NULL,
+                               _("Deleting files"),
+                               NULL,
+                               FALSE,
+                               (double) (delete_data->n_deleted + 1) / (delete_data->n_files + 1),
+                               delete_data->user_data);
+
        file_data = delete_data->current->data;
        g_file_delete_async (file_data->file,
                             G_PRIORITY_DEFAULT,
@@ -1652,17 +1664,20 @@ delete_files__info_ready_cb (GList    *files,
        delete_data->file_list = _g_object_list_ref (files);
        delete_data->file_list = g_list_reverse (delete_data->file_list);
        delete_data->current = delete_data->file_list;
+       delete_data->n_files = g_list_length (delete_data->file_list);
+       delete_data->n_deleted = 0;
        delete_files__delete_current (delete_data);
 }
 
 
 void
-_g_file_list_delete_async (GList        *file_list,
-                          gboolean      recursive,
-                          gboolean      include_metadata,
-                          GCancellable *cancellable,
-                          ReadyFunc     callback,
-                          gpointer      user_data)
+_g_file_list_delete_async (GList                *file_list,
+                          gboolean               recursive,
+                          gboolean               include_metadata,
+                          GCancellable          *cancellable,
+                          ProgressCallback       progress_callback,
+                          ReadyFunc              callback,
+                          gpointer               user_data)
 {
        DeleteData   *delete_data;
        GthListFlags  flags;
@@ -1671,6 +1686,7 @@ _g_file_list_delete_async (GList        *file_list,
        delete_data->file_list = NULL;
        delete_data->include_metadata = include_metadata;
        delete_data->cancellable = _g_object_ref (cancellable);
+       delete_data->progress_callback = progress_callback;
        delete_data->callback = callback;
        delete_data->user_data = user_data;
 
@@ -1678,6 +1694,14 @@ _g_file_list_delete_async (GList        *file_list,
        if (recursive)
                flags |= GTH_LIST_RECURSIVE;
 
+       if (delete_data->progress_callback != NULL)
+               delete_data->progress_callback (NULL,
+                               _("Getting file information"),
+                               NULL,
+                               TRUE,
+                               0.0,
+                               delete_data->user_data);
+
        _g_file_list_query_info_async (file_list,
                                       flags,
                                       GFILE_NAME_TYPE_ATTRIBUTES,
@@ -1691,11 +1715,14 @@ _g_file_list_delete_async (GList        *file_list,
 
 
 typedef struct {
-       GList        *file_list;
-       GList        *current;
-       GCancellable *cancellable;
-       ReadyFunc     callback;
-       gpointer      user_data;
+       GList            *file_list;
+       GList            *current;
+       GCancellable     *cancellable;
+       ProgressCallback  progress_callback;
+       ReadyFunc         callback;
+       gpointer          user_data;
+       glong             n_files;
+       glong             n_deleted;
 } TrashData;
 
 
@@ -1740,6 +1767,14 @@ trash_files__delete_current (TrashData *tdata)
                return;
        }
 
+       if (tdata->progress_callback != NULL)
+               tdata->progress_callback (NULL,
+                               _("Deleting files"),
+                               NULL,
+                               FALSE,
+                               (double) (tdata->n_deleted + 1) / (tdata->n_files + 1),
+                               tdata->user_data);
+
        g_file_trash_async ((GFile *) tdata->current->data,
                            G_PRIORITY_DEFAULT,
                            tdata->cancellable,
@@ -1749,19 +1784,22 @@ trash_files__delete_current (TrashData *tdata)
 
 
 void
-_g_file_list_trash_async (GList        *file_list, /* GFile list */
-                         GCancellable *cancellable,
-                         ReadyFunc     callback,
-                         gpointer      user_data)
+_g_file_list_trash_async (GList                         *file_list, /* GFile list */
+                         GCancellable           *cancellable,
+                         ProgressCallback        progress_callback,
+                         ReadyFunc               callback,
+                         gpointer                user_data)
 {
        TrashData *tdata;
 
        tdata = g_new0 (TrashData, 1);
        tdata->file_list = _g_object_list_ref (file_list);
        tdata->cancellable = _g_object_ref (cancellable);
+       tdata->progress_callback = progress_callback;
        tdata->callback = callback;
        tdata->user_data = user_data;
-
+       tdata->n_files = g_list_length (tdata->file_list);
+       tdata->n_deleted = 0;
        tdata->current = tdata->file_list;
        trash_files__delete_current (tdata);
 }
diff --git a/gthumb/gio-utils.h b/gthumb/gio-utils.h
index b38701b9..0f4b7fb5 100644
--- a/gthumb/gio-utils.h
+++ b/gthumb/gio-utils.h
@@ -161,10 +161,12 @@ void              _g_file_list_delete_async       (GList                   *file_list, 
/* GFile list */
                                                 gboolean                 recursive,
                                                 gboolean                 include_metadata,
                                                 GCancellable            *cancellable,
+                                                ProgressCallback         progress_callback,
                                                 ReadyFunc                callback,
                                                 gpointer                 user_data);
 void           _g_file_list_trash_async        (GList                   *file_list, /* GFile list */
                                                 GCancellable            *cancellable,
+                                                ProgressCallback         progress_callback,
                                                 ReadyFunc                callback,
                                                 gpointer                 user_data);
 
diff --git a/gthumb/gth-delete-task.c b/gthumb/gth-delete-task.c
index 25998800..a7213902 100644
--- a/gthumb/gth-delete-task.c
+++ b/gthumb/gth-delete-task.c
@@ -57,6 +57,20 @@ delete_ready_cb (GError   *error,
 }
 
 
+static void
+delete_progress_cb (GObject    *object,
+                   const char *description,
+                   const char *details,
+                   gboolean    pulse,
+                   double      fraction,
+                   gpointer    user_data)
+{
+       GthDeleteTask *self = user_data;
+
+       gth_task_progress (GTH_TASK (self), description, details, pulse, fraction);
+}
+
+
 static void
 gth_delete_task_exec (GthTask *task)
 {
@@ -70,6 +84,7 @@ gth_delete_task_exec (GthTask *task)
                                   TRUE,
                                   TRUE,
                                   gth_task_get_cancellable (task),
+                                  delete_progress_cb,
                                   delete_ready_cb,
                                   self);
 }
diff --git a/gthumb/gth-trash-task.c b/gthumb/gth-trash-task.c
index b68347a4..9529cbad 100644
--- a/gthumb/gth-trash-task.c
+++ b/gthumb/gth-trash-task.c
@@ -57,6 +57,20 @@ trash_ready_cb (GError   *error,
 }
 
 
+static void
+trash_progress_cb (GObject    *object,
+                  const char *description,
+                  const char *details,
+                  gboolean    pulse,
+                  double      fraction,
+                  gpointer    user_data)
+{
+       GthTrashTask *self = user_data;
+
+       gth_task_progress (GTH_TASK (self), description, details, pulse, fraction);
+}
+
+
 static void
 gth_trash_task_exec (GthTask *task)
 {
@@ -68,6 +82,7 @@ gth_trash_task_exec (GthTask *task)
 
        _g_file_list_trash_async (self->priv->file_list,
                                  gth_task_get_cancellable (task),
+                                 trash_progress_cb,
                                  trash_ready_cb,
                                  self);
 }


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