[gnome-autoar/wip/razvan/general-improvements: 7/20] AutoarExtract: remove AutoarPref member



commit f6f8908aa9246063ca092b0376a61dd8abac01b3
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 |   64 ++++++++++++++++++++++++++++++++++------
 gnome-autoar/autoar-extract.h |   60 +++++++++++++++++++-------------------
 tests/test-extract.c          |   11 +------
 3 files changed, 85 insertions(+), 50 deletions(-)
---
diff --git a/gnome-autoar/autoar-extract.c b/gnome-autoar/autoar-extract.c
index 0d1d20e..1aff71e 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_if_succeed;
 
   GCancellable *cancellable;
 
@@ -180,6 +178,7 @@ enum
   PROP_FILES,
   PROP_COMPLETED_FILES,
   PROP_OUTPUT_IS_DEST,
+  PROP_DELETE_IF_SUCCEED,
   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_IF_SUCCEED:
+      g_value_set_boolean (value, priv->delete_if_succeed);
+      break;
     case PROP_NOTIFY_INTERVAL:
       g_value_set_int64 (value, priv->notify_interval);
       break;
@@ -252,6 +254,9 @@ 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_IF_SUCCEED:
+      autoar_extract_set_delete_if_succeed (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 +376,22 @@ autoar_extract_get_output_is_dest (AutoarExtract *arextract)
 }
 
 /**
+ * autoar_extract_get_delete_if_succeed:
+ * @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_if_succeed (AutoarExtract *arextract)
+{
+  g_return_val_if_fail (AUTOAR_IS_EXTRACT (arextract), FALSE);
+  return arextract->priv->delete_if_succeed;
+}
+
+/**
  * autoar_extract_get_notify_interval:
  * @arextract: an #AutoarExtract
  *
@@ -415,6 +436,23 @@ autoar_extract_set_output_is_dest  (AutoarExtract *arextract,
 }
 
 /**
+ * autoar_extract_set_delete_if_succeed:
+ * @arextract: an #AutoarExtract
+ * @delete_if_succeed: %TRUE if the source archive should be deleted after a
+ * successful extraction
+ *
+ * By default #AutoarExtract:delete-if-succeed is set to %FALSE so the source
+ * archive will not be automatically deleted if extraction succeeds.
+ **/
+void
+autoar_extract_set_delete_if_succeed (AutoarExtract *arextract,
+                                      gboolean       delete_if_succeed)
+{
+  g_return_if_fail (AUTOAR_IS_EXTRACT (arextract));
+  arextract->priv->delete_if_succeed = delete_if_succeed;
+}
+
+/**
  * autoar_extract_set_notify_interval:
  * @arextract: an #AutoarExtract
  * @notify_interval: the minimal interval in microseconds
@@ -454,7 +492,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 +1338,16 @@ autoar_extract_class_init (AutoarExtractClass *klass)
                                                          G_PARAM_CONSTRUCT |
                                                          G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_DELETE_IF_SUCCEED,
+                                   g_param_spec_boolean ("delete-if-succeed",
+                                                         "Delete if succeeded",
+                                                         "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 +1539,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 +1546,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 +1558,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 =
@@ -1883,7 +1926,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_if_succeed) {
     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 7d677f1..d916cf2 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,34 +63,36 @@ 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);
-
-char           *autoar_extract_get_source          (AutoarExtract *arextract);
-GFile          *autoar_extract_get_source_file     (AutoarExtract *arextract);
-char           *autoar_extract_get_output          (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);
+
+char           *autoar_extract_get_source            (AutoarExtract *arextract);
+GFile          *autoar_extract_get_source_file       (AutoarExtract *arextract);
+char           *autoar_extract_get_output            (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_if_succeed (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_if_succeed (AutoarExtract *arextract,
+                                                      gboolean delete_if_succeed);
+void            autoar_extract_set_notify_interval   (AutoarExtract *arextract,
+                                                      gint64 notify_interval);
 
 typedef enum {
     AUTOAR_CONFLICT_OVERWRITE = 0,
diff --git a/tests/test-extract.c b/tests/test-extract.c
index 0ba9004..00650ce 100644
--- a/tests/test-extract.c
+++ b/tests/test-extract.c
@@ -89,8 +89,6 @@ main (int argc,
       char *argv[])
 {
   AutoarExtract *arextract;
-  AutoarPref *arpref;
-  GSettings *settings;
   char *content;
   g_autoptr (GFile) source = NULL;
   g_autoptr (GFile) output = NULL;
@@ -104,15 +102,10 @@ 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, arpref);
+  arextract = autoar_extract_new (source, output);
 
   g_signal_connect (arextract, "scanned", G_CALLBACK (my_handler_scanned), NULL);
   g_signal_connect (arextract, "decide-destination", G_CALLBACK (my_handler_decide_destination), NULL);
@@ -124,8 +117,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]