[gnome-autoar] AutoarExtract: remove AutoarPref member



commit 5a5cfc81524525b81c9a6acfdece92ab01d73ffe
Author: Razvan Chitu <razvan ch95 gmail com>
Date:   Sat Aug 13 18:01:33 2016 +0300

    AutoarExtract: remove AutoarPref member
    
    After removing pattern checking from AutoarExtract, the AutoarPref member was
    only used for deleting the original archive if the operation succeeds. This
    should be replaced with a boolean property in the AutoarExtract class.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768645

 gnome-autoar/autoar-extract.c |   65 ++++++++++++++++++++++++++++++++++------
 gnome-autoar/autoar-extract.h |   56 +++++++++++++++++-----------------
 tests/test-extract.c          |   11 +------
 3 files changed, 85 insertions(+), 47 deletions(-)
---
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index 5013b20..b476c8b 100644
--- a/gnome-autoar/autoar-extract.c
+++ b/gnome-autoar/autoar-extract.c
@@ -28,7 +28,6 @@
 
 #include "autoar-misc.h"
 #include "autoar-private.h"
-#include "autoar-pref.h"
 
 #include <archive.h>
 #include <archive_entry.h>
@@ -114,8 +113,7 @@ struct _AutoarExtractPrivate
   char *source_basename;
 
   int output_is_dest : 1;
-
-  AutoarPref *arpref;
+  gboolean delete_after_extraction;
 
   GCancellable *cancellable;
 
@@ -180,6 +178,7 @@ enum
   PROP_FILES,
   PROP_COMPLETED_FILES,
   PROP_OUTPUT_IS_DEST,
+  PROP_DELETE_AFTER_EXTRACTION,
   PROP_NOTIFY_INTERVAL
 };
 
@@ -219,6 +218,9 @@ autoar_extract_get_property (GObject    *object,
     case PROP_OUTPUT_IS_DEST:
       g_value_set_boolean (value, priv->output_is_dest);
       break;
+    case PROP_DELETE_AFTER_EXTRACTION:
+      g_value_set_boolean (value, priv->delete_after_extraction);
+      break;
     case PROP_NOTIFY_INTERVAL:
       g_value_set_int64 (value, priv->notify_interval);
       break;
@@ -252,6 +254,10 @@ autoar_extract_set_property (GObject      *object,
     case PROP_OUTPUT_IS_DEST:
       autoar_extract_set_output_is_dest (arextract, g_value_get_boolean (value));
       break;
+    case PROP_DELETE_AFTER_EXTRACTION:
+      autoar_extract_set_delete_after_extraction (arextract,
+                                                  g_value_get_boolean (value));
+      break;
     case PROP_NOTIFY_INTERVAL:
       autoar_extract_set_notify_interval (arextract, g_value_get_int64 (value));
       break;
@@ -371,6 +377,22 @@ autoar_extract_get_output_is_dest (AutoarExtract *arextract)
 }
 
 /**
+ * autoar_extract_get_delete_after_extraction:
+ * @arextract: an #AutoarExtract
+ *
+ * Whether the source archive will be deleted after a successful extraction.
+ *
+ * Returns: %TRUE if the source archive will be deleted after a succesful
+ * extraction
+ **/
+gboolean
+autoar_extract_get_delete_after_extraction (AutoarExtract *arextract)
+{
+  g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), FALSE);
+  return arextract->priv->delete_after_extraction;
+}
+
+/**
  * autoar_extract_get_notify_interval:
  * @arextract: an #AutoarExtract
  *
@@ -415,6 +437,23 @@ autoar_extract_set_output_is_dest  (AutoarExtract *arextract,
 }
 
 /**
+ * autoar_extract_set_delete_after_extraction:
+ * @arextract: an #AutoarExtract
+ * @delete_after_extraction: %TRUE if the source archive should be deleted after
+ * a successful extraction
+ *
+ * By default #AutoarExtract:delete-after-extraction is set to %FALSE so the
+ * source archive will not be automatically deleted if extraction succeeds.
+ **/
+void
+autoar_extract_set_delete_after_extraction (AutoarExtract *arextract,
+                                            gboolean       delete_after_extraction)
+{
+  g_return_if_fail (AUTOAR_IS_EXTRACT (arextract));
+  arextract->priv->delete_after_extraction = delete_after_extraction;
+}
+
+/**
  * autoar_extract_set_notify_interval:
  * @arextract: an #AutoarExtract
  * @notify_interval: the minimal interval in microseconds
@@ -454,7 +493,6 @@ autoar_extract_dispose (GObject *object)
 
   g_clear_object (&(priv->source_file));
   g_clear_object (&(priv->output_file));
-  g_clear_object (&(priv->arpref));
   g_clear_object (&(priv->destination_dir));
   g_clear_object (&(priv->cancellable));
   g_clear_object (&(priv->prefix));
@@ -1301,6 +1339,16 @@ autoar_extract_class_init (AutoarExtractClass *klass)
                                                          G_PARAM_CONSTRUCT |
                                                          G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_DELETE_AFTER_EXTRACTION,
+                                   g_param_spec_boolean ("delete-after-extraction",
+                                                         "Delete after extraction",
+                                                         "Whether the source archive is deleted after "
+                                                         "a successful extraction",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_CONSTRUCT |
+                                                         G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_property (object_class, PROP_NOTIFY_INTERVAL,
                                    g_param_spec_int64 ("notify-interval",
                                                        "Notify interval",
@@ -1492,7 +1540,6 @@ autoar_extract_init (AutoarExtract *arextract)
  * @output_file: output directory of extracted file or directory, or the
  * file name of the extracted file or directory itself if you set
  * #AutoarExtract:output-is-dest on the returned object
- * @arpref: an #AutoarPref object
  *
  * Create a new #AutoarExtract object.
  *
@@ -1500,8 +1547,7 @@ autoar_extract_init (AutoarExtract *arextract)
  **/
 AutoarExtract*
 autoar_extract_new (GFile *source_file,
-                    GFile *output_file,
-                    AutoarPref *arpref)
+                    GFile *output_file)
 {
   AutoarExtract *arextract;
 
@@ -1513,8 +1559,6 @@ autoar_extract_new (GFile *source_file,
                             "output-file", output_file,
                             NULL);
 
-  arextract->priv->arpref = g_object_ref (arpref);
-
   arextract->priv->source_basename = g_file_get_basename (arextract->priv->source_file);
   arextract->priv->suggested_destname = autoar_common_get_basename_remove_extension 
(arextract->priv->source_basename);
 
@@ -1888,7 +1932,8 @@ autoar_extract_step_cleanup (AutoarExtract *arextract) {
   priv->notify_last = 0;
   autoar_extract_signal_progress (arextract);
   g_debug ("autoar_extract_step_cleanup: Update progress");
-  if (autoar_pref_get_delete_if_succeed (priv->arpref) && priv->source_file != NULL) {
+
+  if (priv->delete_after_extraction) {
     g_debug ("autoar_extract_step_cleanup: Delete");
     g_file_delete (priv->source_file, priv->cancellable, NULL);
   }
diff --git a/gnome-autoar/autoar-extract.h b/gnome-autoar/autoar-extract.h
index 772705a..13e5460 100644
--- a/gnome-autoar/autoar-extract.h
+++ b/gnome-autoar/autoar-extract.h
@@ -29,8 +29,6 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "autoar-pref.h"
-
 G_BEGIN_DECLS
 
 #define AUTOAR_TYPE_EXTRACT             autoar_extract_get_type ()
@@ -65,32 +63,34 @@ struct _AutoarExtractClass
  **/
 #define AUTOAR_EXTRACT_ERROR autoar_extract_quark()
 
-GQuark          autoar_extract_quark               (void);
-
-GType           autoar_extract_get_type            (void) G_GNUC_CONST;
-
-AutoarExtract  *autoar_extract_new                 (GFile *source_file,
-                                                    GFile *output_file,
-                                                    AutoarPref *arpref);
-
-void            autoar_extract_start               (AutoarExtract *arextract,
-                                                    GCancellable *cancellable);
-void            autoar_extract_start_async         (AutoarExtract *arextract,
-                                                    GCancellable *cancellable);
-
-GFile          *autoar_extract_get_source_file     (AutoarExtract *arextract);
-GFile          *autoar_extract_get_output_file     (AutoarExtract *arextract);
-guint64         autoar_extract_get_size            (AutoarExtract *arextract);
-guint64         autoar_extract_get_completed_size  (AutoarExtract *arextract);
-guint           autoar_extract_get_files           (AutoarExtract *arextract);
-guint           autoar_extract_get_completed_files (AutoarExtract *arextract);
-gboolean        autoar_extract_get_output_is_dest  (AutoarExtract *arextract);
-gint64          autoar_extract_get_notify_interval (AutoarExtract *arextract);
-
-void            autoar_extract_set_output_is_dest  (AutoarExtract *arextract,
-                                                    gboolean output_is_dest);
-void            autoar_extract_set_notify_interval (AutoarExtract *arextract,
-                                                    gint64 notify_interval);
+GQuark          autoar_extract_quark                       (void);
+
+GType           autoar_extract_get_type                    (void) G_GNUC_CONST;
+
+AutoarExtract  *autoar_extract_new                         (GFile *source_file,
+                                                            GFile *output_file);
+
+void            autoar_extract_start                       (AutoarExtract *arextract,
+                                                            GCancellable *cancellable);
+void            autoar_extract_start_async                 (AutoarExtract *arextract,
+                                                            GCancellable *cancellable);
+
+GFile          *autoar_extract_get_source_file             (AutoarExtract *arextract);
+GFile          *autoar_extract_get_output_file             (AutoarExtract *arextract);
+guint64         autoar_extract_get_size                    (AutoarExtract *arextract);
+guint64         autoar_extract_get_completed_size          (AutoarExtract *arextract);
+guint           autoar_extract_get_files                   (AutoarExtract *arextract);
+guint           autoar_extract_get_completed_files         (AutoarExtract *arextract);
+gboolean        autoar_extract_get_output_is_dest          (AutoarExtract *arextract);
+gboolean        autoar_extract_get_delete_after_extraction (AutoarExtract *arextract);
+gint64          autoar_extract_get_notify_interval         (AutoarExtract *arextract);
+
+void            autoar_extract_set_output_is_dest          (AutoarExtract *arextract,
+                                                            gboolean output_is_dest);
+void            autoar_extract_set_delete_after_extraction (AutoarExtract *arextract,
+                                                            gboolean delete_after_extraction);
+void            autoar_extract_set_notify_interval         (AutoarExtract *arextract,
+                                                            gint64 notify_interval);
 
 typedef enum {
     AUTOAR_CONFLICT_SKIP = 0,
diff --git a/tests/test-extract.c b/tests/test-extract.c
index 3c92bcc..01c2d38 100644
--- a/tests/test-extract.c
+++ b/tests/test-extract.c
@@ -88,8 +88,6 @@ main (int argc,
       char *argv[])
 {
   AutoarExtract *arextract;
-  AutoarPref *arpref;
-  GSettings *settings;
   char *content;
   g_autoptr (GFile) source = NULL;
   g_autoptr (GFile) output = NULL;
@@ -103,15 +101,12 @@ main (int argc,
   setlocale (LC_ALL, "");
 
   content = NULL;
-  settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
-
-  arpref = autoar_pref_new_with_gsettings (settings);
-  autoar_pref_set_delete_if_succeed (arpref, FALSE);
 
   source = g_file_new_for_commandline_arg (argv[1]);
   output = g_file_new_for_commandline_arg (argv[2]);
+  arextract = autoar_extract_new (source, output);
 
-  arextract = autoar_extract_new (source, output, arpref);
+  autoar_extract_set_delete_after_extraction (arextract, TRUE);
 
   g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL);
   g_signal_connect (arextract, "decide-destination", G_CALLBACK (my_handler_decide_destination), NULL);
@@ -123,8 +118,6 @@ main (int argc,
   autoar_extract_start (arextract, NULL);
 
   g_object_unref (arextract);
-  g_object_unref (arpref);
-  g_object_unref (settings);
   g_free (content);
 
   return 0;


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