[Pkg-privacy-commits] [nautilus-wipe] 168/224: Rewrite operations as GObjects

Ulrike Uhlig u-guest at moszumanska.debian.org
Thu Jul 7 19:45:46 UTC 2016


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

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

commit 4d82c5d048df4cb4333070f03efc791dbed085bd
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Tue May 22 16:07:07 2012 +0200

    Rewrite operations as GObjects
---
 nautilus-wipe/Makefile.am            |   2 +
 nautilus-wipe/nw-delete-operation.c  | 118 ++++-------
 nautilus-wipe/nw-delete-operation.h  |  50 +++--
 nautilus-wipe/nw-extension.c         |   4 +-
 nautilus-wipe/nw-fill-operation.c    | 388 +++++++++++++++++------------------
 nautilus-wipe/nw-fill-operation.h    |  45 ++--
 nautilus-wipe/nw-operation-manager.c |  61 +++---
 nautilus-wipe/nw-operation-manager.h |  52 ++---
 nautilus-wipe/nw-operation.c         |  69 +++++++
 nautilus-wipe/nw-operation.h         |  59 ++++++
 10 files changed, 460 insertions(+), 388 deletions(-)

diff --git a/nautilus-wipe/Makefile.am b/nautilus-wipe/Makefile.am
index 20aaf18..8d5869d 100644
--- a/nautilus-wipe/Makefile.am
+++ b/nautilus-wipe/Makefile.am
@@ -12,6 +12,8 @@ libnautilus_wipe_la_SOURCES  = extension.c \
                                nw-extension.h \
                                nw-fill-operation.c \
                                nw-fill-operation.h \
+                               nw-operation.c \
+                               nw-operation.h \
                                nw-operation-manager.c \
                                nw-operation-manager.h \
                                nw-path-list.c \
diff --git a/nautilus-wipe/nw-delete-operation.c b/nautilus-wipe/nw-delete-operation.c
index 2c22f35..c002070 100644
--- a/nautilus-wipe/nw-delete-operation.c
+++ b/nautilus-wipe/nw-delete-operation.c
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -19,96 +19,52 @@
  *
  */
 
-#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 <gio/gio.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);
+
+
+G_DEFINE_TYPE_WITH_CODE (NwDeleteOperation,
+                         nw_delete_operation,
+                         GSD_TYPE_DELETE_OPERATION,
+                         G_IMPLEMENT_INTERFACE (NW_TYPE_OPERATION,
+                                                nw_delete_operation_opeartion_iface_init))
 
-GQuark
-nw_delete_operation_error_quark (void)
+
+static void
+nw_delete_operation_opeartion_iface_init (NwOperationInterface *iface)
 {
-  static volatile gsize quark = 0;
-  
-  if (g_once_init_enter (&quark)) {
-    GQuark q = g_quark_from_static_string ("NwDeleteOperationError");
-    
-    g_once_init_leave (&quark, q);
-  }
-  
-  return (GQuark) quark;
+  iface->add_file = nw_delete_operation_real_add_file;
 }
 
-/*
- * nw_delete_operation:
- * @files: A list of paths to delete.
- * @fast: The Gsd.SecureDeleteOperation:fast setting
- * @mode: The Gsd.SecureDeleteOperation:mode setting
- * @zeroise: The Gsd.ZeroableOperation:zeroise setting
- * @finished_handler: A handler for GsdAsyncOperation::finished
- * @progress_handler: A handler for GsdAsyncOperation::progress
- * @data: User data to pass to @finished_handler and @progress_handler
- * @error: Return location for errors or %NULL to ignore them. The errors are
- *         those from gsd_secure_delete_operation_run().
- * 
- * Deletes the given files with libgsecuredelete.
- * 
- * Returns: The operation object that was launched, or %NULL on failure.
- *          The operation object should be unref'd with g_object_unref() when
- *          no longer needed.
- */
-GsdAsyncOperation *
-nw_delete_operation (GList                       *files,
-                     gboolean                     fast,
-                     GsdSecureDeleteOperationMode mode,
-                     gboolean                     zeroise,
-                     GCallback                    finished_handler,
-                     GCallback                    progress_handler,
-                     gpointer                     data,
-                     GError                     **error)
+static void
+nw_delete_operation_class_init (NwDeleteOperationClass *klass)
 {
-  gboolean            success = TRUE;
-  GsdDeleteOperation *operation;
-  guint               n_files = 0;
-  
-  operation = gsd_delete_operation_new ();
-  for (; files; files = g_list_next (files)) {
-    gsd_delete_operation_add_path (operation, files->data);
-    n_files ++;
-  }
-  if (n_files < 1) {
-    g_set_error (error,
-                 NW_DELETE_OPERATION_ERROR,
-                 NW_DELETE_OPERATION_ERROR_FAILED,
-                 _("Nothing to do!"));
-    success = FALSE;
-  } else {
-    /* if file addition succeeded, try to launch operation */
-    gsd_secure_delete_operation_set_fast (GSD_SECURE_DELETE_OPERATION (operation), fast);
-    gsd_secure_delete_operation_set_mode (GSD_SECURE_DELETE_OPERATION (operation), mode);
-    gsd_zeroable_operation_set_zeroise (GSD_ZEROABLE_OPERATION (operation), zeroise);
-    g_signal_connect (operation, "progress", progress_handler, data);
-    g_signal_connect (operation, "finished", finished_handler, data);
-    /* unrefs the operation when done (notice that it is called after the default
-     * handler) */
-    g_signal_connect_after (operation, "finished",
-                            G_CALLBACK (g_object_unref), NULL);
-    success = gsd_secure_delete_operation_run (GSD_SECURE_DELETE_OPERATION (operation),
-                                               error);
-  }
-  /* if something failed, abort */
-  if (! success) {
-    /* on failure here the callback will not be called, then unref right here */
-    g_object_unref (operation);
-  }
-  
-  return success ? g_object_ref (operation) : NULL;
 }
 
+static void
+nw_delete_operation_init (NwDeleteOperation *self)
+{
+}
+
+static void
+nw_delete_operation_real_add_file (NwOperation *self,
+                                   const gchar *file)
+{
+  gsd_delete_operation_add_path (GSD_DELETE_OPERATION (self), file);
+}
+
+NwOperation *
+nw_delete_operation_new (void)
+{
+  return g_object_new (NW_TYPE_DELETE_OPERATION, NULL);
+}
diff --git a/nautilus-wipe/nw-delete-operation.h b/nautilus-wipe/nw-delete-operation.h
index 97e0e7b..797da0d 100644
--- a/nautilus-wipe/nw-delete-operation.h
+++ b/nautilus-wipe/nw-delete-operation.h
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -26,36 +26,32 @@
 #include <glib-object.h>
 #include <gsecuredelete/gsecuredelete.h>
 
+#include "nw-operation.h"
+
 G_BEGIN_DECLS
 
 
-/**
- * NwDeleteOperationError:
- * @NW_DELETE_OPERATION_ERROR_FAILED: An error occurred
- * 
- * Possible errors from the %NW_DELETE_OPERATION_ERROR domain.
- */
-typedef enum
-{
-  NW_DELETE_OPERATION_ERROR_FAILED
-} NwDeleteOperationError;
+#define NW_TYPE_DELETE_OPERATION         (nw_delete_operation_get_type ())
+#define NW_DELETE_OPERATION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), NW_TYPE_DELETE_OPERATION, NwDeleteOperation))
+#define NW_DELETE_OPERATION_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), NW_TYPE_DELETE_OPERATION, NwDeleteOperationClass))
+#define NW_IS_DELETE_OPERATION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), NW_TYPE_DELETE_OPERATION))
+#define NW_IS_DELETE_OPERATION_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), NW_TYPE_DELETE_OPERATION))
+#define NW_DELETE_OPERATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NW_TYPE_DELETE_OPERATION, NwDeleteOperationClass))
 
-/**
- * NW_DELETE_OPERATION_ERROR:
- * 
- * Domain for error coming from a NautilusWipe's delete operation.
- */
-#define NW_DELETE_OPERATION_ERROR (nw_delete_operation_error_quark ())
-
-GQuark              nw_delete_operation_error_quark (void) G_GNUC_CONST;
-GsdAsyncOperation  *nw_delete_operation  (GList                       *files,
-                                          gboolean                     fast,
-                                          GsdSecureDeleteOperationMode mode,
-                                          gboolean                     zeroise,
-                                          GCallback                    finished_handler,
-                                          GCallback                    progress_handler,
-                                          gpointer                     data,
-                                          GError                     **error);
+typedef struct _NwDeleteOperation         NwDeleteOperation;
+typedef struct _NwDeleteOperationClass    NwDeleteOperationClass;
+
+struct _NwDeleteOperation {
+  GsdDeleteOperation parent;
+};
+
+struct _NwDeleteOperationClass {
+  GsdDeleteOperationClass parent;
+};
+
+
+GType         nw_delete_operation_get_type    (void) G_GNUC_CONST;
+NwOperation  *nw_delete_operation_new         (void);
 
 
 G_END_DECLS
diff --git a/nautilus-wipe/nw-extension.c b/nautilus-wipe/nw-extension.c
index 2b61e64..e577790 100644
--- a/nautilus-wipe/nw-extension.c
+++ b/nautilus-wipe/nw-extension.c
@@ -130,7 +130,7 @@ nw_extension_run_delete_operation (GtkWindow *parent,
     /* progress dialog */
     _("Wiping files..."),
     /* operation launcher */
-    nw_delete_operation,
+    nw_delete_operation_new (),
     /* failed dialog */
     _("Wipe failed."),
     /* success dialog */
@@ -206,7 +206,7 @@ nw_extension_run_fill_operation (GtkWindow *parent,
     /* progress dialog */
     _("Wiping available diskspace..."),
     /* operation launcher */
-    nw_fill_operation,
+    nw_fill_operation_new (),
     /* failed dialog */
     _("Wipe failed"),
     /* success dialog */
diff --git a/nautilus-wipe/nw-fill-operation.c b/nautilus-wipe/nw-fill-operation.c
index 9ab26e3..34ab892 100644
--- a/nautilus-wipe/nw-fill-operation.c
+++ b/nautilus-wipe/nw-fill-operation.c
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -33,6 +33,8 @@
 # include <gio/gunixmounts.h>
 #endif
 #include <gsecuredelete/gsecuredelete.h>
+
+#include "nw-operation.h"
 #include "nw-path-list.h"
 
 
@@ -50,6 +52,186 @@ nw_fill_operation_error_quark (void)
   return (GQuark) quark;
 }
 
+
+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);
+
+
+struct _NwFillOperationPrivate {
+  GList  *directories;
+  
+  guint   n_op;
+  guint   n_op_done;
+  
+  gulong  progress_hid;
+  gulong  finished_hid;
+};
+
+G_DEFINE_TYPE_WITH_CODE (NwFillOperation,
+                         nw_fill_operation,
+                         GSD_TYPE_FILL_OPERATION,
+                         G_IMPLEMENT_INTERFACE (NW_TYPE_OPERATION,
+                                                nw_fill_operation_operation_iface_init))
+
+
+static void
+nw_fill_operation_operation_iface_init (NwOperationInterface *iface)
+{
+  iface->add_file = nw_fill_operation_real_add_file;
+}
+
+static void
+nw_fill_operation_class_init (NwFillOperationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  
+  object_class->finalize = nw_fill_operation_finalize;
+  
+  g_type_class_add_private (klass, sizeof (NwFillOperationPrivate));
+}
+
+static void
+nw_fill_operation_init (NwFillOperation *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            NW_TYPE_FILL_OPERATION,
+                                            NwFillOperationPrivate);
+  
+  self->priv->directories = NULL;
+  self->priv->n_op = 0;
+  self->priv->n_op_done = 0;
+  
+  self->priv->finished_hid = g_signal_connect (self, "finished",
+                                               G_CALLBACK (nw_fill_operation_finished_handler),
+                                               self);
+  self->priv->progress_hid = g_signal_connect (self, "progress",
+                                               G_CALLBACK (nw_fill_operation_progress_handler),
+                                               self);
+}
+
+static void
+nw_fill_operation_finalize (GObject *object)
+{
+  NwFillOperation *self = NW_FILL_OPERATION (object);
+  
+  g_list_foreach (self->priv->directories, (GFunc) g_free, NULL);
+  g_list_free (self->priv->directories);
+  self->priv->directories = NULL;
+  
+  G_OBJECT_CLASS (nw_fill_operation_parent_class)->finalize (object);
+}
+
+static void
+nw_fill_operation_real_add_file (NwOperation *op,
+                                 const gchar *path)
+{
+  NwFillOperation *self = NW_FILL_OPERATION (op);
+  
+  /* FIXME: filter file? */
+  self->priv->directories = g_list_prepend (self->priv->directories,
+                                            g_strdup (path));
+  self->priv->n_op ++;
+  
+  gsd_fill_operation_set_directory (GSD_FILL_OPERATION (self),
+                                    self->priv->directories->data);
+}
+
+/* wrapper for the progress handler returning the current progression over all
+ * operations  */
+static void
+nw_fill_operation_progress_handler (GsdFillOperation *operation,
+                                    gdouble           fraction,
+                                    NwFillOperation  *self)
+{
+  /* abort emission and replace by our overridden one.  Not to do that
+   * recursively, we block our handler during the re-emission */
+  g_signal_stop_emission_by_name (operation, "progress");
+  g_signal_handler_block (operation, self->priv->progress_hid);
+  g_signal_emit_by_name (operation, "progress", 0,
+                         (self->priv->n_op_done + fraction) / self->priv->n_op);
+  g_signal_handler_unblock (operation, self->priv->progress_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. */
+static gboolean
+launch_next_operation (NwFillOperation *self)
+{
+  gboolean busy;
+  
+  busy = gsd_async_operation_get_busy (GSD_ASYNC_OPERATION (self));
+  if (! busy) {
+    GError   *err = NULL;
+    gboolean  success;
+    
+    success = gsd_fill_operation_run (GSD_FILL_OPERATION (self),
+                                      self->priv->directories->data,
+                                      &err);
+    if (! success) {
+      g_signal_handler_block (self, self->priv->finished_hid);
+      g_signal_emit_by_name (self, "finished", 0, success, err->message);
+      g_signal_handler_unblock (self, self->priv->finished_hid);
+      g_error_free (err);
+    }
+  }
+  
+  return busy; /* keeps our timeout function until lock is released */
+}
+
+/* Removes the current directory to proceed */
+static void
+nw_fill_operation_pop_dir (NwFillOperation *self)
+{
+  GList *tmp;
+  
+  tmp = self->priv->directories;
+  if (tmp) {
+    self->priv->directories = tmp->next;
+    g_free (tmp->data);
+    g_list_free_1 (tmp);
+  }
+}
+
+/* Wrapper for the finished handler.  It launches the next operation if there
+ * is one left. */
+static void
+nw_fill_operation_finished_handler (GsdFillOperation *operation,
+                                    gboolean          success,
+                                    const gchar      *message,
+                                    NwFillOperation  *self)
+{
+  if (success) {
+    self->priv->n_op_done++;
+    /* remove the directory just proceeded */
+    nw_fill_operation_pop_dir (self);
+    
+    /* if we have work left to be done... */
+    if (self->priv->directories) {
+      /* block signal emission, it's not the last one */
+      g_signal_stop_emission_by_name (operation, "finished");
+      
+      /* 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.
+       * To work around this, we add a timeout function that will try to launch
+       * the next operation if the current one is not busy, which fixes the
+       * problem. */
+      g_timeout_add (10, (GSourceFunc) launch_next_operation, self);
+    }
+  }
+}
+
+
 #if HAVE_GIO_UNIX
 /*
  * find_mountpoint_unix:
@@ -145,145 +327,6 @@ find_mountpoint (const gchar *path,
   return mountpoint_path;
 }
 
-
-
-
-typedef void  (*FillFinishedFunc) (GsdFillOperation  *self,
-                                   gboolean           success,
-                                   const gchar       *message,
-                                   gpointer           data);
-typedef void  (*FillProgressFunc) (GsdFillOperation  *self,
-                                   gdouble            fraction,
-                                   gpointer           data);
-/* The data structure that holds the operation state and data */
-struct FillOperationData
-{
-  GsdFillOperation *operation;
-  /* the current directory to work on (dir->data) */
-  GList *dir;
-  /* GObject's signals handlers IDs */
-  gulong finished_hid;
-  gulong progress_hid;
-  /* operation status */
-  guint n_op;
-  guint n_op_done;
-  
-  /* caller's handlers for wrapping */
-  FillFinishedFunc  finished_handler;
-  FillProgressFunc  progress_handler;
-  gpointer          cbdata;
-};
-
-static void   nw_fill_finished_handler  (GsdFillOperation         *operation,
-                                         gboolean                  success,
-                                         const gchar              *message,
-                                         struct FillOperationData *opdata);
-static void   nw_fill_progress_handler  (GsdFillOperation         *operation,
-                                         gdouble                   fraction,
-                                         struct FillOperationData *opdata);
-
-
-/* Actually calls libgsecuredelete */
-static gboolean
-do_fill_operation (struct FillOperationData *opdata,
-                   GError                  **error)
-{
-  g_message ("Starting work on %s", (const gchar *)opdata->dir->data);
-  /* FIXME: don't launch sfill in a useful directory since it can leave a bunch
-   * of files if it get interrupted (e.g. from a crash, a user kill or so) */
-  return gsd_fill_operation_run (opdata->operation, opdata->dir->data, error);
-}
-
-/* Removes the current directory to proceed */
-static void
-nw_fill_pop_dir (struct FillOperationData *opdata)
-{
-  GList *tmp;
-  
-  tmp = opdata->dir;
-  opdata->dir = g_list_next (opdata->dir);
-  g_free (tmp->data);
-  g_list_free_1 (tmp);
-}
-
-/* Cleans up the opdata structure and frees it */
-static void
-nw_fill_cleanup (struct FillOperationData *opdata)
-{
-  g_signal_handler_disconnect (opdata->operation, opdata->progress_hid);
-  g_signal_handler_disconnect (opdata->operation, opdata->finished_hid);
-  if (opdata->operation) {
-    g_object_unref (opdata->operation);
-  }
-  while (opdata->dir) {
-    nw_fill_pop_dir (opdata);
-  }
-  g_slice_free1 (sizeof *opdata, opdata);
-}
-
-/* wrapper for the progress handler returning the current progression over all
- * operations  */
-static void
-nw_fill_progress_handler (GsdFillOperation         *operation,
-                          gdouble                   fraction,
-                          struct FillOperationData *opdata)
-{
-  opdata->progress_handler (operation,
-                            (opdata->n_op_done + fraction) / opdata->n_op,
-                            opdata->cbdata);
-}
-
-/* timeout function to launch next operation after finish of the previous
- * operation.
- * we need this kind of hack since operation are locked while running. */
-static gboolean
-launch_next_fill_operation (struct FillOperationData *opdata)
-{
-  gboolean busy;
-  
-  busy = gsd_async_operation_get_busy (GSD_ASYNC_OPERATION (opdata->operation));
-  if (! busy) {
-    GError   *err = NULL;
-    gboolean  success;
-    
-    success = do_fill_operation (opdata, &err);
-    if (! success) {
-      nw_fill_finished_handler (opdata->operation,
-                                           success, err->message, opdata);
-      g_error_free (err);
-    }
-  }
-  
-  return busy; /* keeps our timeout function until lock is released */
-}
-
-/* Wrapper for the finished handler.
- * It launches the next operation if there is one left, or call the user's
- * handler if done or on error. */
-static void
-nw_fill_finished_handler (GsdFillOperation         *operation,
-                          gboolean                  success,
-                          const gchar              *message,
-                          struct FillOperationData *opdata)
-{
-  opdata->n_op_done++;
-  /* remove the directory just proceeded */
-  nw_fill_pop_dir (opdata);
-  /* if the last operation succeeded and we have work left */
-  if (success && opdata->dir) {
-    /* 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.
-     * To work around this, we add a timeout function that will try to launch
-     * the next operation if the current one is not busy, which fixes the
-     * problem. */
-    g_timeout_add (10, (GSourceFunc)launch_next_fill_operation, opdata);
-  } else {
-    opdata->finished_handler (operation, success, message, opdata->cbdata);
-    nw_fill_cleanup (opdata);
-  }
-}
-
 /*
  * nw_fill_operation_filter_files:
  * @paths: A list of paths to filter
@@ -291,7 +334,7 @@ nw_fill_finished_handler (GsdFillOperation         *operation,
  * @work_mounts_: return location for filtered paths' mounts
  * @error: return location for errors, or %NULL to ignore them
  * 
- * Ties to get usable paths (local directories) and keep only one per
+ * Tries to get usable paths (local directories) and keep only one per
  * mountpoint.
  * 
  * The returned lists (@work_paths_ and @work_mounts_) have the same length, and
@@ -356,65 +399,8 @@ nw_fill_operation_filter_files (GList    *paths,
   return ! err;
 }
 
-/*
- * nw_fill_operation:
- * @directories: A list of paths to work on (should have been filtered with
- *               nw_fill_operation_filter_files() or so)
- * @fast: The Gsd.SecureDeleteOperation:fast setting
- * @mode: The Gsd.SecureDeleteOperation:mode setting
- * @zeroise: The Gsd.ZeroableOperation:zeroise setting
- * @finished_handler: A handler for GsdAsyncOperation::finished
- * @progress_handler: A handler for GsdAsyncOperation::progress
- * @data: User data to pass to @finished_handler and @progress_handler
- * @error: Return location for errors or %NULL to ignore them. The errors are
- *         those from gsd_fill_operation_run().
- * 
- * fills the given directories to overwrite available diskspace.
- * 
- * Returns: The operation object that was launched, or %NULL on failure.
- *          The operation object should be unref'd with g_object_unref() when
- *          no longer needed.
- */
-GsdAsyncOperation *
-nw_fill_operation (GList                       *directories,
-                   gboolean                     fast,
-                   GsdSecureDeleteOperationMode mode,
-                   gboolean                     zeroise,
-                   GCallback                    finished_handler,
-                   GCallback                    progress_handler,
-                   gpointer                     data,
-                   GError                     **error)
+NwOperation *
+nw_fill_operation_new (void)
 {
-  gboolean                  success = FALSE;
-  struct FillOperationData *opdata;
-  GList                    *dirs;
-  
-  g_return_val_if_fail (directories != NULL, NULL);
-  
-  dirs = nw_path_list_copy (directories);
-  if (dirs) {
-    opdata = g_slice_alloc (sizeof *opdata);
-    opdata->dir               = dirs;
-    opdata->finished_handler  = (FillFinishedFunc)finished_handler;
-    opdata->progress_handler  = (FillProgressFunc)progress_handler;
-    opdata->cbdata            = data;
-    opdata->n_op              = g_list_length (opdata->dir);
-    opdata->n_op_done         = 0;
-    opdata->operation         = gsd_fill_operation_new ();
-    gsd_secure_delete_operation_set_fast (GSD_SECURE_DELETE_OPERATION (opdata->operation), fast);
-    gsd_secure_delete_operation_set_mode (GSD_SECURE_DELETE_OPERATION (opdata->operation), mode);
-    gsd_zeroable_operation_set_zeroise (GSD_ZEROABLE_OPERATION (opdata->operation), zeroise);
-    opdata->progress_hid = g_signal_connect (opdata->operation, "progress",
-                                             G_CALLBACK (nw_fill_progress_handler), opdata);
-    opdata->finished_hid = g_signal_connect (opdata->operation, "finished",
-                                             G_CALLBACK (nw_fill_finished_handler), opdata);
-    /* launches the operation */
-    success = do_fill_operation (opdata, error);
-    if (! success) {
-      nw_fill_cleanup (opdata);
-    }
-  }
-  
-  return success ? g_object_ref (opdata->operation) : NULL;
+  return g_object_new (NW_TYPE_FILL_OPERATION, NULL);
 }
-
diff --git a/nautilus-wipe/nw-fill-operation.h b/nautilus-wipe/nw-fill-operation.h
index 6ac56cc..b89c93a 100644
--- a/nautilus-wipe/nw-fill-operation.h
+++ b/nautilus-wipe/nw-fill-operation.h
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -26,9 +26,31 @@
 #include <glib-object.h>
 #include <gsecuredelete/gsecuredelete.h>
 
+#include "nw-operation.h"
+
 G_BEGIN_DECLS
 
 
+#define NW_TYPE_FILL_OPERATION          (nw_fill_operation_get_type ())
+#define NW_FILL_OPERATION(o)            (G_TYPE_CHECK_INSTANCE_CAST ((o), NW_TYPE_FILL_OPERATION, NwFillOperation))
+#define NW_FILL_OPERATION_CLASS(k)      (G_TYPE_CHECK_CLASS_CAST ((k), NW_TYPE_FILL_OPERATION, NwFillOperationClass))
+#define NW_IS_FILL_OPERATION(o)         (G_TYPE_CHECK_INSTANCE_TYPE ((o), NW_TYPE_FILL_OPERATION))
+#define NW_IS_FILL_OPERATION_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), NW_TYPE_FILL_OPERATION))
+#define NW_FILL_OPERATION_GET_CLASS(o)  (G_TYPE_INSTANCE_GET_CLASS ((o), NW_TYPE_FILL_OPERATION, NwFillOperationClass))
+
+typedef struct _NwFillOperation         NwFillOperation;
+typedef struct _NwFillOperationClass    NwFillOperationClass;
+typedef struct _NwFillOperationPrivate  NwFillOperationPrivate;
+
+struct _NwFillOperation {
+  GsdFillOperation parent;
+  NwFillOperationPrivate *priv;
+};
+
+struct _NwFillOperationClass {
+  GsdFillOperationClass parent;
+};
+
 /**
  * NwFillOperationError:
  * @NW_FILL_OPERATION_ERROR_MISSING_MOUNT: A file have no mount
@@ -51,19 +73,14 @@ typedef enum
  */
 #define NW_FILL_OPERATION_ERROR (nw_fill_operation_error_quark ())
 
-GQuark   nw_fill_operation_error_quark  (void) G_GNUC_CONST;
-gboolean nw_fill_operation_filter_files (GList    *paths,
-                                         GList   **work_paths_,
-                                         GList   **work_mounts_,
-                                         GError  **error);
-GsdAsyncOperation  *nw_fill_operation   (GList                       *files,
-                                         gboolean                     fast,
-                                         GsdSecureDeleteOperationMode mode,
-                                         gboolean                     zeroise,
-                                         GCallback                    finished_handler,
-                                         GCallback                    progress_handler,
-                                         gpointer                     data,
-                                         GError                     **error);
+GQuark        nw_fill_operation_error_quark   (void) G_GNUC_CONST;
+GType         nw_fill_operation_get_type      (void) G_GNUC_CONST;
+
+gboolean      nw_fill_operation_filter_files  (GList    *paths,
+                                               GList   **work_paths_,
+                                               GList   **work_mounts_,
+                                               GError  **error);
+NwOperation  *nw_fill_operation_new           (void);
 
 
 G_END_DECLS
diff --git a/nautilus-wipe/nw-operation-manager.c b/nautilus-wipe/nw-operation-manager.c
index 73ff48a..3da5deb 100644
--- a/nautilus-wipe/nw-operation-manager.c
+++ b/nautilus-wipe/nw-operation-manager.c
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -140,7 +140,7 @@ string_last_line (const gchar *str)
 
 struct NwOperationData
 {
-  GsdAsyncOperation  *operation;
+  NwOperation        *operation;
   GtkWindow          *window;
   gulong              window_destroy_hid;
   NwProgressDialog   *progress_dialog;
@@ -474,7 +474,7 @@ progress_dialog_response_handler (GtkDialog *dialog,
                           _("Resume operation"), GTK_RESPONSE_REJECT,
                           _("Cancel operation"), GTK_RESPONSE_ACCEPT,
                           NULL) == GTK_RESPONSE_ACCEPT) {
-        gsd_async_operation_cancel (opdata->operation);
+        gsd_async_operation_cancel (GSD_ASYNC_OPERATION (opdata->operation));
       }
       break;
     
@@ -495,7 +495,7 @@ progress_dialog_response_handler (GtkDialog *dialog,
  *                       or %NULL for none or the default (e.g. if
  *                       @confirm_button_text is a stock item that have an icon)
  * @progress_dialog_text: Text for the progress dialog
- * @operation_launcher_func: the function that will be launched to do the operation
+ * @operation: (transfer:full): the operation object
  * @failed_primary_text: Primary text of the dialog displayed if operation failed.
  *                       (secondary is the error message)
  * @success_primary_text: Primary text for the the success dialog
@@ -504,28 +504,30 @@ progress_dialog_response_handler (GtkDialog *dialog,
  * 
  */
 void
-nw_operation_manager_run (GtkWindow      *parent,
-                          GList          *files,
-                          const gchar    *confirm_primary_text,
-                          const gchar    *confirm_secondary_text,
-                          const gchar    *confirm_button_text,
-                          GtkWidget      *confirm_button_icon,
-                          const gchar    *progress_dialog_text,
-                          NwOperationFunc operation_launcher_func,
-                          const gchar    *failed_primary_text,
-                          const gchar    *success_primary_text,
-                          const gchar    *success_secondary_text)
+nw_operation_manager_run (GtkWindow    *parent,
+                          GList        *files,
+                          const gchar  *confirm_primary_text,
+                          const gchar  *confirm_secondary_text,
+                          const gchar  *confirm_button_text,
+                          GtkWidget    *confirm_button_icon,
+                          const gchar  *progress_dialog_text,
+                          NwOperation  *operation,
+                          const gchar  *failed_primary_text,
+                          const gchar  *success_primary_text,
+                          const gchar  *success_secondary_text)
 {
   /* if the user confirms, try to launch the operation */
   gboolean                      fast        = FALSE;
   GsdSecureDeleteOperationMode  delete_mode = GSD_SECURE_DELETE_OPERATION_MODE_INSECURE;
   gboolean                      zeroise     = FALSE;
   
-  if (operation_confirm_dialog (parent,
-                                confirm_primary_text, confirm_secondary_text,
-                                confirm_button_text, confirm_button_icon,
-                                &fast, &delete_mode, &zeroise)) {
-    GError                           *err = NULL;
+  if (! operation_confirm_dialog (parent,
+                                  confirm_primary_text, confirm_secondary_text,
+                                  confirm_button_text, confirm_button_icon,
+                                  &fast, &delete_mode, &zeroise)) {
+    g_object_unref (operation);
+  } else {
+    GError                 *err = NULL;
     struct NwOperationData *opdata;
     
     opdata = g_slice_alloc (sizeof *opdata);
@@ -540,11 +542,20 @@ nw_operation_manager_run (GtkWindow      *parent,
     opdata->failed_primary_text = g_strdup (failed_primary_text);
     opdata->success_primary_text = g_strdup (success_primary_text);
     opdata->success_secondary_text = g_strdup (success_secondary_text);
-    opdata->operation = operation_launcher_func (files, fast, delete_mode, zeroise,
-                                                 G_CALLBACK (operation_finished_handler),
-                                                 G_CALLBACK (operation_progress_handler),
-                                                 opdata, &err);
-    if (! opdata->operation) {
+    opdata->operation = operation;
+    g_object_set (operation,
+                  "fast", fast,
+                  "mode", delete_mode,
+                  "zeroise", zeroise,
+                  NULL);
+    g_signal_connect (opdata->operation, "finished",
+                      G_CALLBACK (operation_finished_handler), opdata);
+    g_signal_connect (opdata->operation, "progress",
+                      G_CALLBACK (operation_progress_handler), opdata);
+    
+    nw_operation_add_files (opdata->operation, files);
+    if (! gsd_secure_delete_operation_run (GSD_SECURE_DELETE_OPERATION (opdata->operation),
+                                           &err)) {
       if (err->code == G_SPAWN_ERROR_NOENT) {
         gchar *message;
         
diff --git a/nautilus-wipe/nw-operation-manager.h b/nautilus-wipe/nw-operation-manager.h
index 54fe53b..8a22a2b 100644
--- a/nautilus-wipe/nw-operation-manager.h
+++ b/nautilus-wipe/nw-operation-manager.h
@@ -1,7 +1,7 @@
 /*
  *  nautilus-wipe - a nautilus extension to wipe file(s)
  * 
- *  Copyright (C) 2009-2011 Colomban Wendling <ban at herbesfolles.org>
+ *  Copyright (C) 2009-2012 Colomban Wendling <ban at herbesfolles.org>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU General Public
@@ -25,47 +25,23 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
-#include <gsecuredelete/gsecuredelete.h>
 
-G_BEGIN_DECLS
+#include "nw-operation.h"
 
+G_BEGIN_DECLS
 
-/**
- * NwOperationFunc:
- * @files: Paths to work on
- * @fast: The Gsd.SecureDeleteOperation:fast setting
- * @mode: The Gsd.SecureDeleteOperation:mode setting
- * @zeroise: The Gsd.ZeroableOperation:zeroise setting
- * @finished_handler: Handler for GsdAsyncOperation::finished
- * @progress_handler: Handler for GsdAsyncOperation::progress
- * @data: User data for @finished_hanlder and @progress_handler
- * @error: Return location for errors, or %NULL to ignore them
- * 
- * 
- * Returns: The operation object that was launched, or %NULL on failure.
- *          The operation object should be unref'd with g_object_unref() when
- *          no longer needed.
- */
-typedef GsdAsyncOperation  *(*NwOperationFunc)  (GList                       *files,
-                                                 gboolean                     fast,
-                                                 GsdSecureDeleteOperationMode mode,
-                                                 gboolean                     zeroise,
-                                                 GCallback                    finished_handler,
-                                                 GCallback                    progress_handler,
-                                                 gpointer                     data,
-                                                 GError                     **error);
 
-void    nw_operation_manager_run  (GtkWindow       *parent,
-                                   GList           *files,
-                                   const gchar     *confirm_primary_text,
-                                   const gchar     *confirm_secondary_text,
-                                   const gchar     *confirm_button_text,
-                                   GtkWidget       *confirm_button_icon,
-                                   const gchar     *progress_dialog_text,
-                                   NwOperationFunc  operation_launcher_func,
-                                   const gchar     *failed_primary_text,
-                                   const gchar     *success_primary_text,
-                                   const gchar     *success_secondary_text);
+void    nw_operation_manager_run  (GtkWindow   *parent,
+                                   GList       *files,
+                                   const gchar *confirm_primary_text,
+                                   const gchar *confirm_secondary_text,
+                                   const gchar *confirm_button_text,
+                                   GtkWidget   *confirm_button_icon,
+                                   const gchar *progress_dialog_text,
+                                   NwOperation *operation,
+                                   const gchar *failed_primary_text,
+                                   const gchar *success_primary_text,
+                                   const gchar *success_secondary_text);
 
 
 G_END_DECLS
diff --git a/nautilus-wipe/nw-operation.c b/nautilus-wipe/nw-operation.c
new file mode 100644
index 0000000..d13875f
--- /dev/null
+++ b/nautilus-wipe/nw-operation.c
@@ -0,0 +1,69 @@
+/*
+ *  nautilus-wipe - a nautilus extension to wipe file(s)
+ * 
+ *  Copyright (C) 2012 Colomban Wendling <ban at herbesfolles.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "nw-operation.h"
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gsecuredelete/gsecuredelete.h>
+
+
+static void   nw_operation_real_add_files   (NwOperation *self,
+                                             GList       *files);
+
+
+G_DEFINE_INTERFACE (NwOperation,
+                    nw_operation,
+                    GSD_TYPE_ZEROABLE_OPERATION)
+
+
+static void
+nw_operation_default_init (NwOperationInterface *iface)
+{
+  iface->add_files = nw_operation_real_add_files;
+}
+
+static void
+nw_operation_real_add_files (NwOperation *self,
+                             GList       *files)
+{
+  NwOperationInterface *iface = NW_OPERATION_GET_INTERFACE (self);
+  
+  for (; files; files = files->next) {
+    iface->add_file (self, files->data);
+  }
+}
+
+void
+nw_operation_add_file (NwOperation *self,
+                       const gchar *file)
+{
+  NW_OPERATION_GET_INTERFACE (self)->add_file (self, file);
+}
+
+void
+nw_operation_add_files (NwOperation *self,
+                        GList       *files)
+{
+  NW_OPERATION_GET_INTERFACE (self)->add_files (self, files);
+}
+
diff --git a/nautilus-wipe/nw-operation.h b/nautilus-wipe/nw-operation.h
new file mode 100644
index 0000000..776087b
--- /dev/null
+++ b/nautilus-wipe/nw-operation.h
@@ -0,0 +1,59 @@
+/*
+ *  nautilus-wipe - a nautilus extension to wipe file(s)
+ * 
+ *  Copyright (C) 2012 Colomban Wendling <ban at herbesfolles.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 3 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef NW_OPERATION_H
+#define NW_OPERATION_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+#define NW_TYPE_OPERATION             (nw_operation_get_type ())
+#define NW_OPERATION(o)               (G_TYPE_CHECK_INSTANCE_CAST ((o), NW_TYPE_OPERATION, NwOperation))
+#define NW_IS_OPERATION(o)            (G_TYPE_CHECK_INSTANCE_TYPE ((o), NW_TYPE_OPERATION))
+#define NW_OPERATION_GET_INTERFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), NW_TYPE_OPERATION, NwOperationInterface))
+
+typedef struct _NwOperation           NwOperation;
+typedef struct _NwOperationInterface  NwOperationInterface;
+
+struct _NwOperationInterface {
+  GTypeInterface parent;
+  
+  void   (*add_file)        (NwOperation *self,
+                             const gchar *path);
+  void   (*add_files)       (NwOperation *self,
+                             GList       *files);
+};
+
+
+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);
+
+
+G_END_DECLS
+
+#endif /* guard */

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