[gnome-software/uajain/flatpak-autoupdates-fix: 1/2] GsFlatpakTransaction: Add a property corresponding to --no-deploy



commit daa100d06f34d30705af6bec0325119ecb8779fd
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Oct 4 06:17:59 2019 -0400

    GsFlatpakTransaction: Add a property corresponding to --no-deploy
    
    Add a property corresponding to flatpak's --no-deploy to
    GsFlatpakTransaction and use the helper method instead,
    in the flatpak-plugin.
    
    This is also done as a ground-work to let the FlatpakTransaction
    know if an update was a autoupdate(non-interactive) or a manual
    update(interaction) in subsequent commit.
    
    https://gitlab.gnome.org/GNOME/gnome-software/issues/819

 plugins/flatpak/gs-flatpak-transaction.c | 45 ++++++++++++++++++++++++++++++++
 plugins/flatpak/gs-flatpak-transaction.h |  3 +++
 plugins/flatpak/gs-plugin-flatpak.c      |  2 +-
 3 files changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index c6b49909..527473c6 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -15,8 +15,13 @@ struct _GsFlatpakTransaction {
        FlatpakTransaction       parent_instance;
        GHashTable              *refhash;       /* ref:GsApp */
        GError                  *first_operation_error;
+       gboolean                 no_deploy;
 };
 
+typedef enum {
+  PROP_NO_DEPLOY = 1,
+} GsFlatpakTransactionProperty;
+
 enum {
        SIGNAL_REF_TO_APP,
        LAST_SIGNAL
@@ -41,6 +46,22 @@ gs_flatpak_transaction_finalize (GObject *object)
        G_OBJECT_CLASS (gs_flatpak_transaction_parent_class)->finalize (object);
 }
 
+void
+gs_flatpak_transaction_set_no_deploy (FlatpakTransaction *transaction, gboolean no_deploy)
+{
+       GsFlatpakTransaction *self;
+
+       g_return_if_fail (GS_IS_FLATPAK_TRANSACTION (transaction));
+
+       self = GS_FLATPAK_TRANSACTION (transaction);
+       if (self->no_deploy == no_deploy)
+               return;
+       self->no_deploy = no_deploy;
+       flatpak_transaction_set_no_deploy (transaction, no_deploy);
+
+       g_object_notify (G_OBJECT (self), "no-deploy");
+}
+
 GsApp *
 gs_flatpak_transaction_get_app_by_ref (FlatpakTransaction *transaction, const gchar *ref)
 {
@@ -348,11 +369,28 @@ _transaction_add_new_remote (FlatpakTransaction *transaction,
        return FALSE;
 }
 
+static void
+gs_flatpak_transaction_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+       FlatpakTransaction *transaction = FLATPAK_TRANSACTION (object);
+
+       switch ((GsFlatpakTransactionProperty) prop_id) {
+       case PROP_NO_DEPLOY:
+               gs_flatpak_transaction_set_no_deploy (transaction, g_value_get_boolean (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
 static void
 gs_flatpak_transaction_class_init (GsFlatpakTransactionClass *klass)
 {
+       GParamSpec *pspec;
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        FlatpakTransactionClass *transaction_class = FLATPAK_TRANSACTION_CLASS (klass);
+       object_class->set_property = gs_flatpak_transaction_set_property;
        object_class->finalize = gs_flatpak_transaction_finalize;
        transaction_class->ready = _transaction_ready;
        transaction_class->add_new_remote = _transaction_add_new_remote;
@@ -362,6 +400,13 @@ gs_flatpak_transaction_class_init (GsFlatpakTransactionClass *klass)
        transaction_class->choose_remote_for_ref = _transaction_choose_remote_for_ref;
        transaction_class->end_of_lifed = _transaction_end_of_lifed;
 
+       /* FIXME: getter functions for "no-deploy" are now added to libflatpak (1.5.1) but we are creating a 
property
+        * here to avoid the libflatpak version bump. In future, port to use the libflatpak's getters. */
+       pspec = g_param_spec_boolean ("no-deploy",NULL,
+                                     "Whether the current transaction will deploy the downloaded objects",
+                                     FALSE, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT);
+       g_object_class_install_property (object_class, PROP_NO_DEPLOY, pspec);
+
        signals[SIGNAL_REF_TO_APP] =
                g_signal_new ("ref-to-app",
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/plugins/flatpak/gs-flatpak-transaction.h b/plugins/flatpak/gs-flatpak-transaction.h
index 2caa289d..245f708a 100644
--- a/plugins/flatpak/gs-flatpak-transaction.h
+++ b/plugins/flatpak/gs-flatpak-transaction.h
@@ -26,5 +26,8 @@ void                   gs_flatpak_transaction_add_app         (FlatpakTransaction     
*transaction,
 gboolean                gs_flatpak_transaction_run             (FlatpakTransaction     *transaction,
                                                                 GCancellable           *cancellable,
                                                                 GError                 **error);
+void                    gs_flatpak_transaction_set_no_deploy   (FlatpakTransaction     *transaction,
+                                                                gboolean                no_deploy);
+
 
 G_END_DECLS
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 228dedbc..5e3e3fe1 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -507,7 +507,7 @@ gs_plugin_download (GsPlugin *plugin, GsAppList *list,
                        gs_flatpak_error_convert (error);
                        return FALSE;
                }
-               flatpak_transaction_set_no_deploy (transaction, TRUE);
+               gs_flatpak_transaction_set_no_deploy (transaction, TRUE);
                for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
                        GsApp *app = gs_app_list_index (list_tmp, i);
                        g_autofree gchar *ref = NULL;


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