[gnome-software: 6/14] gs-plugin-job: Add helper function for GET_INSTALLED jobs




commit 8de5f8a3fd288e639f53b0655a4ce88718cfc3b1
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Dec 9 16:43:32 2021 +0000

    gs-plugin-job: Add helper function for GET_INSTALLED jobs
    
    This creates a `GsPluginJob` for a `GET_INSTALLED` 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                            |  5 +----
 lib/gs-plugin-job-list-installed-apps.c | 34 +++++++++++++++++++++++++++++++++
 lib/gs-plugin-job-list-installed-apps.h | 25 ++++++++++++++++++++++++
 lib/meson.build                         |  2 ++
 plugins/dummy/gs-self-test.c            | 19 +++++++++---------
 src/gs-installed-page.c                 |  5 +----
 7 files changed, 74 insertions(+), 17 deletions(-)
---
diff --git a/lib/gnome-software.h b/lib/gnome-software.h
index b16d25072..724cc7e9f 100644
--- a/lib/gnome-software.h
+++ b/lib/gnome-software.h
@@ -26,6 +26,7 @@
 #include <gs-plugin.h>
 #include <gs-plugin-helpers.h>
 #include <gs-plugin-job.h>
+#include <gs-plugin-job-list-installed-apps.h>
 #include <gs-plugin-job-refine.h>
 #include <gs-plugin-vfuncs.h>
 #include <gs-remote-icon.h>
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index 1c4eaeb2d..ea2c5efeb 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -394,10 +394,7 @@ main (int argc, char **argv)
                        g_autoptr(GsPluginJob) plugin_job = NULL;
                        if (list != NULL)
                                g_object_unref (list);
-                       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_INSTALLED,
-                                                        "refine-flags", self->refine_flags,
-                                                        "max-results", self->max_results,
-                                                        NULL);
+                       plugin_job = gs_plugin_job_list_installed_apps_new (self->refine_flags, 
self->max_results, GS_APP_LIST_FILTER_FLAGS_DEFAULT);
                        list = gs_plugin_loader_job_process (self->plugin_loader, plugin_job,
                                                             NULL, &error);
                        if (list == NULL) {
diff --git a/lib/gs-plugin-job-list-installed-apps.c b/lib/gs-plugin-job-list-installed-apps.c
new file mode 100644
index 000000000..1e24b905a
--- /dev/null
+++ b/lib/gs-plugin-job-list-installed-apps.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 Endless OS Foundation LLC
+ *
+ * Author: Philip Withnall <pwithnall endlessos org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/**
+ * gs_plugin_job_list_installed_apps_new:
+ * @refine_flags: flags to affect how the results are refined, or
+ *   %GS_PLUGIN_REFINE_FLAGS_NONE to skip refining them
+ * @max_results: maximum number of results to return, or `0` to not limit the
+ *   results
+ * @dedupe_flags: flags to control deduplicating the results
+ *
+ * Create a new #GsPluginJob for listing the installed apps.
+ *
+ * Returns: (transfer full): a new #GsPluginJob
+ * Since: 42
+ */
+GsPluginJob *
+gs_plugin_job_list_installed_apps_new (GsPluginRefineFlags  refine_flags,
+                                       guint                max_results,
+                                       GsAppListFilterFlags dedupe_flags)
+{
+       return gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_INSTALLED,
+                                  "refine-flags", refine_flags,
+                                  "max-results", max_results,
+                                  "dedupe-flags", dedupe_flags,
+                                  NULL);
+}
diff --git a/lib/gs-plugin-job-list-installed-apps.h b/lib/gs-plugin-job-list-installed-apps.h
new file mode 100644
index 000000000..3a7c6be2f
--- /dev/null
+++ b/lib/gs-plugin-job-list-installed-apps.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ * vi:set noexpandtab tabstop=8 shiftwidth=8:
+ *
+ * Copyright (C) 2021 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_installed_apps_new  (GsPluginRefineFlags  refine_flags,
+                                                        guint                max_results,
+                                                        GsAppListFilterFlags dedupe_flags);
+
+G_END_DECLS
diff --git a/lib/meson.build b/lib/meson.build
index cbee2e82c..4b42c1076 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -21,6 +21,7 @@ libgnomesoftware_public_headers = [
   'gs-plugin-event.h',
   'gs-plugin-helpers.h',
   'gs-plugin-job.h',
+  'gs-plugin-job-list-installed-apps.h',
   'gs-plugin-job-refine.h',
   'gs-plugin-loader.h',
   'gs-plugin-loader-sync.h',
@@ -96,6 +97,7 @@ libgnomesoftware = library(
     'gs-plugin-event.c',
     'gs-plugin-helpers.c',
     'gs-plugin-job.c',
+    'gs-plugin-job-list-installed-apps.c',
     'gs-plugin-job-refine.c',
     'gs-plugin-loader.c',
     'gs-plugin-loader-sync.c',
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index ca6cd123b..b2009a097 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -346,17 +346,18 @@ gs_plugins_dummy_installed_func (GsPluginLoader *plugin_loader)
        g_autoptr(GsAppList) list = NULL;
        g_autoptr(GsPluginJob) plugin_job = NULL;
        g_autoptr(GIcon) icon = NULL;
+       GsPluginRefineFlags refine_flags;
 
        /* get installed packages */
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_INSTALLED,
-                                        "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_KUDOS |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_CATEGORIES |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE,
-                                        NULL);
+       refine_flags = (GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_ADDONS |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_KUDOS |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_CATEGORIES |
+                       GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE);
+
+       plugin_job = gs_plugin_job_list_installed_apps_new (refine_flags, 0, 
GS_APP_LIST_FILTER_FLAGS_DEFAULT);
        list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
        gs_test_flush_main_context ();
        g_assert_no_error (error);
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index b4751ee2e..3817ab01f 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -453,10 +453,7 @@ gs_installed_page_load (GsInstalledPage *self)
                flags |= GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE;
 
        /* get installed apps */
-       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_INSTALLED,
-                                        "refine-flags", flags,
-                                        "dedupe-flags", GS_APP_LIST_FILTER_FLAG_NONE,
-                                        NULL);
+       plugin_job = gs_plugin_job_list_installed_apps_new (flags, 0, GS_APP_LIST_FILTER_FLAG_NONE);
        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]