[Pkg-privacy-commits] [nautilus-wipe] 03/37: Report operations' non-fatal warnings

Intrigeri intrigeri at moszumanska.debian.org
Wed Dec 7 18:46:01 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 4956a00ef14ec9c30bdda1ce4a49f687b53c2857
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Tue Jul 12 20:19:29 2016 +0200

    Report operations' non-fatal warnings
    
    New version of libgsecuredelete allows for warning messages in finished
    signal even with success.
---
 nautilus-wipe/nw-fill-operation.c    | 65 +++++++++++++++++++++++++++++++-----
 nautilus-wipe/nw-operation-manager.c | 37 +++++++++++++++-----
 2 files changed, 86 insertions(+), 16 deletions(-)

diff --git a/nautilus-wipe/nw-fill-operation.c b/nautilus-wipe/nw-fill-operation.c
index 9107dd9..b8c9ba8 100644
--- a/nautilus-wipe/nw-fill-operation.c
+++ b/nautilus-wipe/nw-fill-operation.c
@@ -67,13 +67,14 @@ static void     nw_fill_operation_progress_handler      (GsdFillOperation *opera
 
 
 struct _NwFillOperationPrivate {
-  GList  *directories;
+  GList    *directories;
   
-  guint   n_op;
-  guint   n_op_done;
+  guint     n_op;
+  guint     n_op_done;
+  GString  *message;
   
-  gulong  progress_hid;
-  gulong  finished_hid;
+  gulong    progress_hid;
+  gulong    finished_hid;
 };
 
 G_DEFINE_TYPE_WITH_CODE (NwFillOperation,
@@ -109,6 +110,7 @@ nw_fill_operation_init (NwFillOperation *self)
   self->priv->directories = NULL;
   self->priv->n_op = 0;
   self->priv->n_op_done = 0;
+  self->priv->message = NULL;
   
   self->priv->finished_hid = g_signal_connect (self, "finished",
                                                G_CALLBACK (nw_fill_operation_finished_handler),
@@ -127,6 +129,11 @@ nw_fill_operation_finalize (GObject *object)
   g_list_free (self->priv->directories);
   self->priv->directories = NULL;
   
+  if (self->priv->message) {
+    g_string_free (self->priv->message, TRUE);
+    self->priv->message = NULL;
+  }
+  
   G_OBJECT_CLASS (nw_fill_operation_parent_class)->finalize (object);
 }
 
@@ -161,6 +168,37 @@ nw_fill_operation_progress_handler (GsdFillOperation *operation,
   g_signal_handler_unblock (operation, self->priv->progress_hid);
 }
 
+static void
+append_error_message (NwFillOperation  *self,
+                      const gchar      *message)
+{
+  if (! self->priv->message) {
+    self->priv->message = g_string_new (message);
+  } else {
+    g_string_append (self->priv->message, "\n");
+    g_string_append (self->priv->message, message);
+  }
+}
+
+static void
+emit_final_finished (NwFillOperation *self,
+                     gboolean         success,
+                     const gchar     *message)
+{
+  const gchar *full_message;
+  
+  if (! self->priv->message) {
+    full_message = message;
+  } else {
+    append_error_message (self, message);
+    full_message = self->priv->message->str;
+  }
+  
+  g_signal_handler_block (self, self->priv->finished_hid);
+  g_signal_emit_by_name (self, "finished", success, full_message);
+  g_signal_handler_unblock (self, self->priv->finished_hid);
+}
+
 /* timeout function to launch next operation after finish of the previous
  * operation.
  * we need this kind of hack since operation are locked while running. */
@@ -178,9 +216,7 @@ launch_next_operation (NwFillOperation *self)
                                       self->priv->directories->data,
                                       &err);
     if (! success) {
-      g_signal_handler_block (self, self->priv->finished_hid);
-      g_signal_emit_by_name (self, "finished", success, err->message);
-      g_signal_handler_unblock (self, self->priv->finished_hid);
+      emit_final_finished (self, success, err->message);
       g_error_free (err);
     }
   }
@@ -210,6 +246,8 @@ nw_fill_operation_finished_handler (GsdFillOperation *operation,
                                     const gchar      *message,
                                     NwFillOperation  *self)
 {
+  gboolean last = TRUE;
+  
   if (success) {
     self->priv->n_op_done++;
     /* remove the directory just proceeded */
@@ -220,6 +258,11 @@ nw_fill_operation_finished_handler (GsdFillOperation *operation,
       /* block signal emission, it's not the last one */
       g_signal_stop_emission_by_name (operation, "finished");
       
+      /* remember any warning for the final signal */
+      if (message) {
+        append_error_message (self, message);
+      }
+      
       /* we can't launch the next operation right here since the previous must
        * release its lock before, which is done just after return of the current
        * function.
@@ -227,8 +270,14 @@ nw_fill_operation_finished_handler (GsdFillOperation *operation,
        * the next operation if the current one is not busy, which fixes the
        * problem. */
       g_timeout_add (10, (GSourceFunc) launch_next_operation, self);
+      last = FALSE;
     }
   }
+  /* if we didn't schedule a new job, check if we have to alter the signal */
+  if (last && self->priv->message) {
+    g_signal_stop_emission_by_name (operation, "finished");
+    emit_final_finished (self, success, message);
+  }
 }
 
 
diff --git a/nautilus-wipe/nw-operation-manager.c b/nautilus-wipe/nw-operation-manager.c
index 321133f..3d4e7fc 100644
--- a/nautilus-wipe/nw-operation-manager.c
+++ b/nautilus-wipe/nw-operation-manager.c
@@ -185,6 +185,7 @@ opdata_window_destroy_handler (GtkWidget               *obj,
 /* Displays an operation's error */
 static void
 display_operation_error (struct NwOperationData  *opdata,
+                         gboolean                 is_warning,
                          const gchar             *error)
 {
   GtkWidget      *dialog;
@@ -197,14 +198,34 @@ display_operation_error (struct NwOperationData  *opdata,
   
   dialog = gtk_message_dialog_new (opdata->window,
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
-                                   GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE,
-                                   "%s", opdata->failed_primary_text);
+                                   is_warning ? GTK_MESSAGE_WARNING
+                                              : GTK_MESSAGE_ERROR,
+                                   GTK_BUTTONS_NONE,
+                                   "%s",
+                                   is_warning ? opdata->success_primary_text
+                                              : opdata->failed_primary_text);
   gtk_window_set_title (GTK_WINDOW (dialog), opdata->title);
   gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
   /* we hope that the last line in the error message is meaningful */
   short_error = string_last_line (error);
-  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                            "%s", short_error);
+  if (is_warning) {
+    const gchar *conditional = _("However, the following warning was issued "
+                                 "during the operation:");
+    
+    if (opdata->success_secondary_text) {
+      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                "%s\n\n%s\n%s",
+                                                opdata->success_secondary_text,
+                                                conditional, short_error);
+    } else {
+      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                "%s\n%s",
+                                                conditional, short_error);
+    }
+  } else {
+    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                              "%s", short_error);
+  }
   g_free (short_error);
   /* add the details expander */
   content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
@@ -237,8 +258,8 @@ operation_finished_handler (GsdDeleteOperation *operation,
   struct NwOperationData *opdata = data;
   
   gtk_widget_destroy (GTK_WIDGET (opdata->progress_dialog));
-  if (! success) {
-    display_operation_error (opdata, error);
+  if (! success || error) {
+    display_operation_error (opdata, success, error);
   } else {
     display_dialog (opdata->window, GTK_MESSAGE_INFO, FALSE, opdata->title,
                     opdata->success_primary_text,
@@ -580,10 +601,10 @@ nw_operation_manager_run (GtkWindow    *parent,
                                      "Please make sure you have the secure-delete "
                                      "package properly installed on your system."),
                                    err->message);
-        display_operation_error (opdata, message);
+        display_operation_error (opdata, FALSE, message);
         g_free (message);
       } else {
-        display_operation_error (opdata, err->message);
+        display_operation_error (opdata, FALSE, err->message);
       }
       g_error_free (err);
       gtk_widget_destroy (GTK_WIDGET (opdata->progress_dialog));

-- 
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