[gnome-software: 7/11] gs-plugin-job: Add helper function for GET_DISTRO_UPDATES jobs




commit 05ad1dea21afa27ce81a8033935eeb57f731a9bc
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Mar 2 16:01:11 2022 +0000

    gs-plugin-job: Add helper function for GET_DISTRO_UPDATES jobs
    
    This creates a `GsPluginJob` for a `GET_DISTRO_UPDATES` action. In
    subsequent commits it will be turned into a full `GsPluginJob`
    subclass; this commit is factored out first so the call sites don’t
    have to change again later.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gnome-software.h                     |  1 +
 lib/gs-cmd.c                             | 12 ++++++-----
 lib/gs-plugin-job-list-distro-upgrades.c | 37 ++++++++++++++++++++++++++++++++
 lib/gs-plugin-job-list-distro-upgrades.h | 24 +++++++++++++++++++++
 lib/meson.build                          |  2 ++
 plugins/dummy/gs-self-test.c             | 12 +++++++----
 src/gs-update-monitor.c                  |  4 ++--
 src/gs-updates-page.c                    |  6 ++----
 8 files changed, 83 insertions(+), 15 deletions(-)
---
diff --git a/lib/gnome-software.h b/lib/gnome-software.h
index 1e27e23d0..a341f6a34 100644
--- a/lib/gnome-software.h
+++ b/lib/gnome-software.h
@@ -27,6 +27,7 @@
 #include <gs-plugin.h>
 #include <gs-plugin-helpers.h>
 #include <gs-plugin-job.h>
+#include <gs-plugin-job-list-distro-upgrades.h>
 #include <gs-plugin-job-list-installed-apps.h>
 #include <gs-plugin-job-refine.h>
 #include <gs-plugin-job-refresh-metadata.h>
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index e5e96ba2e..7fe9429db 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -548,13 +548,15 @@ main (int argc, char **argv)
        } else if (argc == 2 && g_strcmp0 (argv[1], "upgrades") == 0) {
                for (i = 0; i < repeat; i++) {
                        g_autoptr(GsPluginJob) plugin_job = NULL;
+                       GsPluginListDistroUpgradesFlags upgrades_flags = 
GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE;
+
                        if (list != NULL)
                                g_object_unref (list);
-                       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES,
-                                                        "refine-flags", self->refine_flags,
-                                                        "max-results", self->max_results,
-                                                        "interactive", self->interactive,
-                                                        NULL);
+
+                       if (self->interactive)
+                               upgrades_flags |= GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_INTERACTIVE;
+
+                       plugin_job = gs_plugin_job_list_distro_upgrades_new (upgrades_flags, 
self->refine_flags);
                        list = gs_plugin_loader_job_process (self->plugin_loader, plugin_job,
                                                             NULL, &error);
                        if (list == NULL) {
diff --git a/lib/gs-plugin-job-list-distro-upgrades.c b/lib/gs-plugin-job-list-distro-upgrades.c
new file mode 100644
index 000000000..0c623ccd7
--- /dev/null
+++ b/lib/gs-plugin-job-list-distro-upgrades.c
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2022 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <glib.h>
+
+#include "gs-plugin-job.h"
+#include "gs-plugin-job-list-distro-upgrades.h"
+#include "gs-plugin-types.h"
+
+/**
+ * gs_plugin_job_list_distro_upgrades_new:
+ * @flags: flags affecting how the operation runs
+ * @refine_flags: flags to affect how the results are refined, or
+ *   %GS_PLUGIN_REFINE_FLAGS_NONE to skip refining them
+ *
+ * Create a new #GsPluginJob for listing the available distro
+ * upgrades.
+ *
+ * Returns: (transfer full): a new #GsPluginJob
+ * Since: 42
+ */
+GsPluginJob *
+gs_plugin_job_list_distro_upgrades_new (GsPluginListDistroUpgradesFlags flags,
+                                        GsPluginRefineFlags             refine_flags)
+{
+       return gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES,
+                                  "refine-flags", refine_flags,
+                                  "interactive", (flags & GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_INTERACTIVE) 
? TRUE : FALSE,
+                                  NULL);
+}
diff --git a/lib/gs-plugin-job-list-distro-upgrades.h b/lib/gs-plugin-job-list-distro-upgrades.h
new file mode 100644
index 000000000..b53b3292f
--- /dev/null
+++ b/lib/gs-plugin-job-list-distro-upgrades.h
@@ -0,0 +1,24 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2022 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#pragma once
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "gs-plugin-job.h"
+
+G_BEGIN_DECLS
+
+GsPluginJob    *gs_plugin_job_list_distro_upgrades_new (GsPluginListDistroUpgradesFlags flags,
+                                                        GsPluginRefineFlags             refine_flags);
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index 7e1645770..c3b752746 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -22,6 +22,7 @@ libgnomesoftware_public_headers = [
   'gs-plugin-event.h',
   'gs-plugin-helpers.h',
   'gs-plugin-job.h',
+  'gs-plugin-job-list-distro-upgrades.h',
   'gs-plugin-job-list-installed-apps.h',
   'gs-plugin-job-refine.h',
   'gs-plugin-job-refresh-metadata.h',
@@ -101,6 +102,7 @@ libgnomesoftware = library(
     'gs-plugin-event.c',
     'gs-plugin-helpers.c',
     'gs-plugin-job.c',
+    'gs-plugin-job-list-distro-upgrades.c',
     'gs-plugin-job-list-installed-apps.c',
     'gs-plugin-job-refine.c',
     'gs-plugin-job-refresh-metadata.c',
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 4efc28076..3f64d5b28 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -307,7 +307,8 @@ gs_plugins_dummy_distro_upgrades_func (GsPluginLoader *plugin_loader)
        g_autoptr(GsPluginJob) plugin_job = NULL;
 
        /* get the updates list */
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
+       plugin_job = gs_plugin_job_list_distro_upgrades_new (GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE,
+                                                            GS_PLUGIN_REFINE_FLAGS_NONE);
        list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
        gs_test_flush_main_context ();
        g_assert_no_error (error);
@@ -542,7 +543,8 @@ gs_plugins_dummy_plugin_cache_func (GsPluginLoader *plugin_loader)
        g_autoptr(GsPluginJob) plugin_job = NULL;
 
        /* ensure we get the same results back from calling the methods twice */
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
+       plugin_job = gs_plugin_job_list_distro_upgrades_new (GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE,
+                                                            GS_PLUGIN_REFINE_FLAGS_NONE);
        list1 = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
        gs_test_flush_main_context ();
        g_assert_no_error (error);
@@ -551,7 +553,8 @@ gs_plugins_dummy_plugin_cache_func (GsPluginLoader *plugin_loader)
        app1 = gs_app_list_index (list1, 0);
 
        g_object_unref (plugin_job);
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
+       plugin_job = gs_plugin_job_list_distro_upgrades_new (GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE,
+                                                            GS_PLUGIN_REFINE_FLAGS_NONE);
        list2 = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
        gs_test_flush_main_context ();
        g_assert_no_error (error);
@@ -638,7 +641,8 @@ gs_plugins_dummy_limit_parallel_ops_func (GsPluginLoader *plugin_loader)
        gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* get the updates list */
-       plugin_job1 = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
+       plugin_job1 = gs_plugin_job_list_distro_upgrades_new (GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE,
+                                                             GS_PLUGIN_REFINE_FLAGS_NONE);
        list = gs_plugin_loader_job_process (plugin_loader, plugin_job1, NULL, &helper3->error);
        gs_test_flush_main_context ();
        g_assert_no_error (helper3->error);
diff --git a/src/gs-update-monitor.c b/src/gs-update-monitor.c
index 487776028..2780f9ac6 100644
--- a/src/gs-update-monitor.c
+++ b/src/gs-update-monitor.c
@@ -772,8 +772,8 @@ get_upgrades (GsUpdateMonitor *monitor)
         * AppStream data being up to date, either by the appstream-data
         * package being up-to-date, or the metadata being auto-downloaded */
        g_debug ("Getting upgrades");
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES,
-                                        NULL);
+       plugin_job = gs_plugin_job_list_distro_upgrades_new (GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_NONE,
+                                                            GS_PLUGIN_REFINE_FLAGS_NONE);
        gs_plugin_loader_job_process_async (monitor->plugin_loader,
                                            plugin_job,
                                            monitor->cancellable,
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index 2c9bd2871..1cfef81d6 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -666,10 +666,8 @@ gs_updates_page_load (GsUpdatesPage *self)
        if ((self->result_flags & GS_UPDATES_PAGE_FLAG_HAS_UPGRADES) == 0) {
                refine_flags |= GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPGRADE_REMOVED;
                g_object_unref (plugin_job);
-               plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES,
-                                                "interactive", TRUE,
-                                                "refine-flags", refine_flags,
-                                                NULL);
+               plugin_job = gs_plugin_job_list_distro_upgrades_new 
(GS_PLUGIN_LIST_DISTRO_UPGRADES_FLAGS_INTERACTIVE,
+                                                                    refine_flags);
                gs_plugin_loader_job_process_async (self->plugin_loader,
                                                    plugin_job,
                                                    self->cancellable,


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