[Pkg-privacy-commits] [nautilus-wipe] 06/37: Add progress text

Intrigeri intrigeri at moszumanska.debian.org
Wed Dec 7 18:46:02 UTC 2016


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

intrigeri pushed a commit to branch master
in repository nautilus-wipe.

commit 93380c8e8b670c5a0cb8da6b62daa0a1136636cf
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Wed Jul 13 18:32:15 2016 +0200

    Add progress text
    
    This helps a little when the operation takes a long time so the user
    can at least know the progress isn't expected to be more precise.
---
 nautilus-wipe/nw-delete-operation.c  | 33 ++++++++++++++++++++++---
 nautilus-wipe/nw-fill-operation.c    | 47 +++++++++++++++++++++++++++---------
 nautilus-wipe/nw-operation-manager.c | 20 ++++++++++++---
 nautilus-wipe/nw-operation.c         | 19 ++++++++++++---
 nautilus-wipe/nw-operation.h         | 20 ++++++++-------
 5 files changed, 108 insertions(+), 31 deletions(-)

diff --git a/nautilus-wipe/nw-delete-operation.c b/nautilus-wipe/nw-delete-operation.c
index c002070..3bd0bb7 100644
--- a/nautilus-wipe/nw-delete-operation.c
+++ b/nautilus-wipe/nw-delete-operation.c
@@ -19,18 +19,24 @@
  *
  */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nw-delete-operation.h"
 
 #include <glib.h>
+#include <glib/gi18n-lib.h>
 #include <glib-object.h>
 #include <gsecuredelete/gsecuredelete.h>
 
 #include "nw-operation.h"
 
 
-static void   nw_delete_operation_opeartion_iface_init  (NwOperationInterface *iface);
-static void   nw_delete_operation_real_add_file         (NwOperation *self,
-                                                         const gchar *file);
+static void   nw_delete_operation_opeartion_iface_init    (NwOperationInterface *iface);
+static void   nw_delete_operation_real_add_file           (NwOperation *self,
+                                                           const gchar *file);
+static gchar *nw_delete_operation_real_get_progress_step  (NwOperation *self);
 
 
 G_DEFINE_TYPE_WITH_CODE (NwDeleteOperation,
@@ -43,7 +49,8 @@ G_DEFINE_TYPE_WITH_CODE (NwDeleteOperation,
 static void
 nw_delete_operation_opeartion_iface_init (NwOperationInterface *iface)
 {
-  iface->add_file = nw_delete_operation_real_add_file;
+  iface->add_file           = nw_delete_operation_real_add_file;
+  iface->get_progress_step  = nw_delete_operation_real_get_progress_step;
 }
 
 static void
@@ -63,6 +70,24 @@ nw_delete_operation_real_add_file (NwOperation *self,
   gsd_delete_operation_add_path (GSD_DELETE_OPERATION (self), file);
 }
 
+static gchar *
+nw_delete_operation_real_get_progress_step (NwOperation *operation)
+{
+  /* it's a bit ugly here: we rely on the knowledge that
+   * GsdSecureDeleteOperation's get_max_progress() returns the individual
+   * pass count, and GsdDeleteOperation overrides it multiplying it by the
+   * file count.  But well, that gives us everything but the file name. */
+  GsdAsyncOperation      *op        = GSD_ASYNC_OPERATION (operation);
+  GsdAsyncOperationClass *delopcls  = g_type_class_peek (GSD_TYPE_SECURE_DELETE_OPERATION);
+  guint                   passes    = delopcls->get_max_progress (op);
+  guint                   n_files   = op->n_passes / passes;
+  guint                   file      = op->passes / passes;
+  guint                   pass      = op->passes % passes;
+  
+  return g_strdup_printf (_("File %u out of %u, pass %u out of %u"),
+                          file + 1, n_files, pass + 1, passes);
+}
+
 NwOperation *
 nw_delete_operation_new (void)
 {
diff --git a/nautilus-wipe/nw-fill-operation.c b/nautilus-wipe/nw-fill-operation.c
index b8c9ba8..8bfefd5 100644
--- a/nautilus-wipe/nw-fill-operation.c
+++ b/nautilus-wipe/nw-fill-operation.c
@@ -53,17 +53,18 @@ nw_fill_operation_error_quark (void)
 }
 
 
-static void     nw_fill_operation_operation_iface_init  (NwOperationInterface *iface);
-static void     nw_fill_operation_real_add_file         (NwOperation *op,
-                                                         const gchar *path);
-static void     nw_fill_operation_finalize              (GObject *object);
-static void     nw_fill_operation_finished_handler      (GsdFillOperation *operation,
-                                                         gboolean          success,
-                                                         const gchar      *message,
-                                                         NwFillOperation  *self);
-static void     nw_fill_operation_progress_handler      (GsdFillOperation *operation,
-                                                         gdouble           fraction,
-                                                         NwFillOperation  *self);
+static void     nw_fill_operation_operation_iface_init    (NwOperationInterface *iface);
+static void     nw_fill_operation_real_add_file           (NwOperation *op,
+                                                           const gchar *path);
+static gchar   *nw_fill_operation_real_get_progress_step  (NwOperation *op);
+static void     nw_fill_operation_finalize                (GObject *object);
+static void     nw_fill_operation_finished_handler        (GsdFillOperation *operation,
+                                                           gboolean          success,
+                                                           const gchar      *message,
+                                                           NwFillOperation  *self);
+static void     nw_fill_operation_progress_handler        (GsdFillOperation *operation,
+                                                           gdouble           fraction,
+                                                           NwFillOperation  *self);
 
 
 struct _NwFillOperationPrivate {
@@ -87,7 +88,8 @@ G_DEFINE_TYPE_WITH_CODE (NwFillOperation,
 static void
 nw_fill_operation_operation_iface_init (NwOperationInterface *iface)
 {
-  iface->add_file = nw_fill_operation_real_add_file;
+  iface->add_file           = nw_fill_operation_real_add_file;
+  iface->get_progress_step  = nw_fill_operation_real_get_progress_step;
 }
 
 static void
@@ -152,6 +154,24 @@ nw_fill_operation_real_add_file (NwOperation *op,
                                     self->priv->directories->data);
 }
 
+static gchar *
+nw_fill_operation_real_get_progress_step (NwOperation *operation)
+{
+  NwFillOperation    *self  = NW_FILL_OPERATION (operation);
+  GsdAsyncOperation  *op    = GSD_SECURE_DELETE_OPERATION (operation);
+  
+  if (self->priv->n_op > 1) {
+    return g_strdup_printf (_("Device \"%s\" (%u out of %u), pass %u out of %u"),
+                            (const gchar *) self->priv->directories->data,
+                            self->priv->n_op_done + 1, self->priv->n_op,
+                            op->passes + 1, op->n_passes);
+  } else {
+    return g_strdup_printf (_("Device \"%s\", pass %u out of %u"),
+                            (const gchar *) self->priv->directories->data,
+                            op->passes + 1, op->n_passes);
+  }
+}
+
 /* wrapper for the progress handler returning the current progression over all
  * operations  */
 static void
@@ -218,6 +238,9 @@ launch_next_operation (NwFillOperation *self)
     if (! success) {
       emit_final_finished (self, success, err->message);
       g_error_free (err);
+    } else {
+      /* as the step changed, report the progress changed */
+      g_signal_emit_by_name (self, "progress", 0.0);
     }
   }
   
diff --git a/nautilus-wipe/nw-operation-manager.c b/nautilus-wipe/nw-operation-manager.c
index 4dcb0ef..32cf070 100644
--- a/nautilus-wipe/nw-operation-manager.c
+++ b/nautilus-wipe/nw-operation-manager.c
@@ -271,13 +271,24 @@ operation_finished_handler (GsdAsyncOperation  *operation,
 }
 
 static void
+update_operation_progress (struct NwOperationData  *opdata,
+                           gdouble                  fraction)
+{
+  gchar *step = nw_operation_get_progress_step (opdata->operation);
+  
+  nw_progress_dialog_set_fraction (opdata->progress_dialog, fraction);
+  nw_progress_dialog_set_progress_text (opdata->progress_dialog,
+                                        step ? "%s" : NULL, step);
+  
+  g_free (step);
+}
+
+static void
 operation_progress_handler (GsdAsyncOperation  *operation,
                             gdouble             fraction,
                             gpointer            data)
 {
-  struct NwOperationData *opdata = data;
-  
-  nw_progress_dialog_set_fraction (opdata->progress_dialog, fraction);
+  update_operation_progress (data, fraction);
 }
 
 /* sets @pref according to state of @toggle */
@@ -610,6 +621,9 @@ nw_operation_manager_run (GtkWindow    *parent,
       gtk_widget_destroy (GTK_WIDGET (opdata->progress_dialog));
       free_opdata (opdata);
     } else {
+      /* update the initial progress so the step is correct, too */
+      update_operation_progress (opdata, 0.0);
+      
       gtk_widget_show (GTK_WIDGET (opdata->progress_dialog));
     }
   }
diff --git a/nautilus-wipe/nw-operation.c b/nautilus-wipe/nw-operation.c
index d13875f..2cfcfef 100644
--- a/nautilus-wipe/nw-operation.c
+++ b/nautilus-wipe/nw-operation.c
@@ -27,8 +27,9 @@
 #include <gsecuredelete/gsecuredelete.h>
 
 
-static void   nw_operation_real_add_files   (NwOperation *self,
-                                             GList       *files);
+static void   nw_operation_real_add_files           (NwOperation *self,
+                                                     GList       *files);
+static gchar *nw_operation_real_get_progress_step   (NwOperation *self);
 
 
 G_DEFINE_INTERFACE (NwOperation,
@@ -39,7 +40,8 @@ G_DEFINE_INTERFACE (NwOperation,
 static void
 nw_operation_default_init (NwOperationInterface *iface)
 {
-  iface->add_files = nw_operation_real_add_files;
+  iface->add_files          = nw_operation_real_add_files;
+  iface->get_progress_step  = nw_operation_real_get_progress_step;
 }
 
 static void
@@ -53,6 +55,12 @@ nw_operation_real_add_files (NwOperation *self,
   }
 }
 
+static gchar *
+nw_operation_real_get_progress_step (NwOperation *self)
+{
+  return NULL;
+}
+
 void
 nw_operation_add_file (NwOperation *self,
                        const gchar *file)
@@ -67,3 +75,8 @@ nw_operation_add_files (NwOperation *self,
   NW_OPERATION_GET_INTERFACE (self)->add_files (self, files);
 }
 
+gchar *
+nw_operation_get_progress_step (NwOperation *self)
+{
+  return NW_OPERATION_GET_INTERFACE (self)->get_progress_step (self);
+}
diff --git a/nautilus-wipe/nw-operation.h b/nautilus-wipe/nw-operation.h
index 776087b..28bfbfc 100644
--- a/nautilus-wipe/nw-operation.h
+++ b/nautilus-wipe/nw-operation.h
@@ -39,19 +39,21 @@ typedef struct _NwOperationInterface  NwOperationInterface;
 struct _NwOperationInterface {
   GTypeInterface parent;
   
-  void   (*add_file)        (NwOperation *self,
-                             const gchar *path);
-  void   (*add_files)       (NwOperation *self,
-                             GList       *files);
+  void   (*add_file)            (NwOperation *self,
+                                 const gchar *path);
+  void   (*add_files)           (NwOperation *self,
+                                 GList       *files);
+  gchar *(*get_progress_step)   (NwOperation *self);
 };
 
 
-GType   nw_operation_get_type   (void) G_GNUC_CONST;
+GType   nw_operation_get_type           (void) G_GNUC_CONST;
 
-void    nw_operation_add_file   (NwOperation *self,
-                                 const gchar *path);
-void    nw_operation_add_files  (NwOperation *self,
-                                 GList       *files);
+void    nw_operation_add_file           (NwOperation *self,
+                                         const gchar *path);
+void    nw_operation_add_files          (NwOperation *self,
+                                         GList       *files);
+gchar  *nw_operation_get_progress_step  (NwOperation *self);
 
 
 G_END_DECLS

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/nautilus-wipe.git



More information about the Pkg-privacy-commits mailing list