[gnome-software: 4/6] gs-plugin-job-list-installed-apps: Add flags property




commit 09388a7b31fbe9c6f92f2b630aeb8f47755094de
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Mar 3 21:41:41 2022 +0000

    gs-plugin-job-list-installed-apps: Add flags property
    
    I should have added this when originally writing the class: it provides
    a way to say whether the job is interactive.
    
    While `GsPluginJob:interactive` exists as a property, that can’t extend
    to the `GsPlugin.list_installed_apps_async()` vfuncs which this job
    eventually calls, so the enum needs to be added for them. If it’s being
    added there, it might as well be used to set the interactive state on
    the plugin job.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 doc/api/gnome-software-docs.xml         |  9 ++++----
 lib/gs-cmd.c                            |  8 ++++++-
 lib/gs-plugin-job-list-installed-apps.c | 41 +++++++++++++++++++++++++++++----
 lib/gs-plugin-job-list-installed-apps.h |  7 +++---
 lib/gs-plugin-types.h                   | 14 +++++++++++
 lib/gs-plugin.h                         |  1 +
 plugins/core/gs-plugin-appstream.c      |  9 ++++----
 plugins/dummy/gs-plugin-dummy.c         |  9 ++++----
 plugins/dummy/gs-self-test.c            |  3 ++-
 plugins/flatpak/gs-plugin-flatpak.c     | 11 +++++----
 plugins/snap/gs-plugin-snap.c           | 11 +++++----
 src/gs-installed-page.c                 |  3 ++-
 12 files changed, 94 insertions(+), 32 deletions(-)
---
diff --git a/doc/api/gnome-software-docs.xml b/doc/api/gnome-software-docs.xml
index 3ae8eece6..236f8b82b 100644
--- a/doc/api/gnome-software-docs.xml
+++ b/doc/api/gnome-software-docs.xml
@@ -212,10 +212,11 @@ gs_plugin_sample_init (GsPluginSample *self)
 }
 
 static void
-gs_plugin_custom_list_installed_apps_async (GsPlugin            *plugin,
-                                            GCancellable        *cancellable,
-                                            GAsyncReadyCallback  callback,
-                                            gpointer             user_data)
+gs_plugin_custom_list_installed_apps_async (GsPlugin                       *plugin,
+                                            GsPluginListInstalledAppsFlags  flags,
+                                            GCancellable                   *cancellable,
+                                            GAsyncReadyCallback             callback,
+                                            gpointer                        user_data)
 {
   g_autofree gchar *fn = NULL;
   g_autoptr(GsApp) app = NULL;
diff --git a/lib/gs-cmd.c b/lib/gs-cmd.c
index e5e96ba2e..1a91f88a7 100644
--- a/lib/gs-cmd.c
+++ b/lib/gs-cmd.c
@@ -402,9 +402,15 @@ main (int argc, char **argv)
        if (argc == 2 && g_strcmp0 (argv[1], "installed") == 0) {
                for (i = 0; i < repeat; i++) {
                        g_autoptr(GsPluginJob) plugin_job = NULL;
+                       GsPluginListInstalledAppsFlags installed_flags = 
GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_NONE;
+
                        if (list != NULL)
                                g_object_unref (list);
-                       plugin_job = gs_plugin_job_list_installed_apps_new (self->refine_flags, 
self->max_results, GS_PLUGIN_JOB_DEDUPE_FLAGS_DEFAULT);
+
+                       if (self->interactive)
+                               installed_flags |= GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_INTERACTIVE;
+
+                       plugin_job = gs_plugin_job_list_installed_apps_new (self->refine_flags, 
self->max_results, GS_PLUGIN_JOB_DEDUPE_FLAGS_DEFAULT, installed_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-installed-apps.c b/lib/gs-plugin-job-list-installed-apps.c
index fa113c1aa..b48fed9ec 100644
--- a/lib/gs-plugin-job-list-installed-apps.c
+++ b/lib/gs-plugin-job-list-installed-apps.c
@@ -57,6 +57,7 @@ struct _GsPluginJobListInstalledApps
        GsPluginRefineFlags refine_flags;
        guint max_results;
        GsAppListFilterFlags dedupe_flags;
+       GsPluginListInstalledAppsFlags flags;
 
        /* In-progress data. */
        GsAppList *merged_list;  /* (owned) (nullable) */
@@ -73,9 +74,10 @@ typedef enum {
        PROP_REFINE_FLAGS = 1,
        PROP_MAX_RESULTS,
        PROP_DEDUPE_FLAGS,
+       PROP_FLAGS,
 } GsPluginJobListInstalledAppsProperty;
 
-static GParamSpec *props[PROP_DEDUPE_FLAGS + 1] = { NULL, };
+static GParamSpec *props[PROP_FLAGS + 1] = { NULL, };
 
 static void
 gs_plugin_job_list_installed_apps_dispose (GObject *object)
@@ -109,6 +111,9 @@ gs_plugin_job_list_installed_apps_get_property (GObject    *object,
        case PROP_DEDUPE_FLAGS:
                g_value_set_flags (value, self->dedupe_flags);
                break;
+       case PROP_FLAGS:
+               g_value_set_flags (value, self->flags);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -142,6 +147,12 @@ gs_plugin_job_list_installed_apps_set_property (GObject      *object,
                self->dedupe_flags = g_value_get_flags (value);
                g_object_notify_by_pspec (object, props[prop_id]);
                break;
+       case PROP_FLAGS:
+               /* Construct only. */
+               g_assert (self->flags == 0);
+               self->flags = g_value_get_flags (value);
+               g_object_notify_by_pspec (object, props[prop_id]);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -287,7 +298,10 @@ gs_plugin_job_list_installed_apps_run_async (GsPluginJob         *job,
 
                /* run the plugin */
                self->n_pending_ops++;
-               plugin_class->list_installed_apps_async (plugin, cancellable, plugin_list_installed_apps_cb, 
g_object_ref (task));
+               plugin_class->list_installed_apps_async (plugin, self->flags,
+                                                        cancellable,
+                                                        plugin_list_installed_apps_cb,
+                                                        g_object_ref (task));
        }
 
        /* some functions are really required for proper operation */
@@ -491,6 +505,20 @@ gs_plugin_job_list_installed_apps_class_init (GsPluginJobListInstalledAppsClass
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                     G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+       /**
+        * GsPluginJobListInstalledApps:flags:
+        *
+        * Flags to specify how the list job should behave.
+        *
+        * Since: 42
+        */
+       props[PROP_FLAGS] =
+               g_param_spec_flags ("flags", "Flags",
+                                   "Flags to specify how the list job should behave.",
+                                   GS_TYPE_PLUGIN_LIST_INSTALLED_APPS_FLAGS, 
GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_NONE,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                                   G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
        g_object_class_install_properties (object_class, G_N_ELEMENTS (props), props);
 }
 
@@ -506,6 +534,7 @@ gs_plugin_job_list_installed_apps_init (GsPluginJobListInstalledApps *self)
  * @max_results: maximum number of results to return, or `0` to not limit the
  *   results
  * @dedupe_flags: flags to control deduplicating the results
+ * @flags: flags to affect the list operation
  *
  * Create a new #GsPluginJobListInstalledApps for listing the installed apps.
  *
@@ -513,14 +542,16 @@ gs_plugin_job_list_installed_apps_init (GsPluginJobListInstalledApps *self)
  * Since: 42
  */
 GsPluginJob *
-gs_plugin_job_list_installed_apps_new (GsPluginRefineFlags  refine_flags,
-                                       guint                max_results,
-                                       GsAppListFilterFlags dedupe_flags)
+gs_plugin_job_list_installed_apps_new (GsPluginRefineFlags            refine_flags,
+                                       guint                          max_results,
+                                       GsAppListFilterFlags           dedupe_flags,
+                                       GsPluginListInstalledAppsFlags flags)
 {
        return g_object_new (GS_TYPE_PLUGIN_JOB_LIST_INSTALLED_APPS,
                             "refine-flags", refine_flags,
                             "max-results", max_results,
                             "dedupe-flags", dedupe_flags,
+                            "flags", flags,
                             NULL);
 }
 
diff --git a/lib/gs-plugin-job-list-installed-apps.h b/lib/gs-plugin-job-list-installed-apps.h
index 6704db3d0..c62cb76e2 100644
--- a/lib/gs-plugin-job-list-installed-apps.h
+++ b/lib/gs-plugin-job-list-installed-apps.h
@@ -22,9 +22,10 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GsPluginJobListInstalledApps, gs_plugin_job_list_installed_apps, GS, 
PLUGIN_JOB_LIST_INSTALLED_APPS, GsPluginJob)
 
-GsPluginJob    *gs_plugin_job_list_installed_apps_new  (GsPluginRefineFlags  refine_flags,
-                                                        guint                max_results,
-                                                        GsAppListFilterFlags dedupe_flags);
+GsPluginJob    *gs_plugin_job_list_installed_apps_new  (GsPluginRefineFlags            refine_flags,
+                                                        guint                          max_results,
+                                                        GsAppListFilterFlags           dedupe_flags,
+                                                        GsPluginListInstalledAppsFlags flags);
 
 GsAppList      *gs_plugin_job_list_installed_apps_get_result_list      (GsPluginJobListInstalledApps *self);
 
diff --git a/lib/gs-plugin-types.h b/lib/gs-plugin-types.h
index 50373f682..dc0bc95eb 100644
--- a/lib/gs-plugin-types.h
+++ b/lib/gs-plugin-types.h
@@ -170,6 +170,20 @@ typedef enum {
        GS_PLUGIN_REFINE_FLAGS_MASK                     = ~0,
 } GsPluginRefineFlags;
 
+/**
+ * GsPluginListInstalledAppsFlags:
+ * @GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_NONE: No flags set.
+ * @GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_INTERACTIVE: User initiated the job.
+ *
+ * Flags for an operation to list installed apps.
+ *
+ * Since: 42
+ */
+typedef enum {
+       GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_NONE = 0,
+       GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_INTERACTIVE = 1 << 0,
+} GsPluginListInstalledAppsFlags;
+
 /**
  * GsPluginRefreshMetadataFlags:
  * @GS_PLUGIN_REFRESH_METADATA_FLAGS_NONE: No flags set.
diff --git a/lib/gs-plugin.h b/lib/gs-plugin.h
index 6ff0ad424..b6af301c2 100644
--- a/lib/gs-plugin.h
+++ b/lib/gs-plugin.h
@@ -117,6 +117,7 @@ struct _GsPluginClass
                                                         GError                 **error);
 
        void                    (*list_installed_apps_async)    (GsPlugin               *plugin,
+                                                                GsPluginListInstalledAppsFlags flags,
                                                                 GCancellable           *cancellable,
                                                                 GAsyncReadyCallback     callback,
                                                                 gpointer                user_data);
diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c
index 06e3cb78c..b04a4e427 100644
--- a/plugins/core/gs-plugin-appstream.c
+++ b/plugins/core/gs-plugin-appstream.c
@@ -1315,10 +1315,11 @@ static void list_installed_apps_thread_cb (GTask        *task,
                                            GCancellable *cancellable);
 
 static void
-gs_plugin_appstream_list_installed_apps_async (GsPlugin            *plugin,
-                                               GCancellable        *cancellable,
-                                               GAsyncReadyCallback  callback,
-                                               gpointer             user_data)
+gs_plugin_appstream_list_installed_apps_async (GsPlugin                       *plugin,
+                                               GsPluginListInstalledAppsFlags  flags,
+                                               GCancellable                   *cancellable,
+                                               GAsyncReadyCallback             callback,
+                                               gpointer                        user_data)
 {
        GsPluginAppstream *self = GS_PLUGIN_APPSTREAM (plugin);
        g_autoptr(GTask) task = NULL;
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index a044c7735..958bcc020 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -542,10 +542,11 @@ gs_plugin_add_updates (GsPlugin *plugin,
 }
 
 static void
-gs_plugin_dummy_list_installed_apps_async (GsPlugin            *plugin,
-                                           GCancellable        *cancellable,
-                                           GAsyncReadyCallback  callback,
-                                           gpointer             user_data)
+gs_plugin_dummy_list_installed_apps_async (GsPlugin                       *plugin,
+                                           GsPluginListInstalledAppsFlags  flags,
+                                           GCancellable                   *cancellable,
+                                           GAsyncReadyCallback             callback,
+                                           gpointer                        user_data)
 {
        const gchar *packages[] = { "zeus", "zeus-common", NULL };
        const gchar *app_ids[] = { "Uninstall Zeus.desktop", NULL };
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 4efc28076..4586e780f 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -368,7 +368,8 @@ gs_plugins_dummy_installed_func (GsPluginLoader *plugin_loader)
                        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_PLUGIN_JOB_DEDUPE_FLAGS_DEFAULT);
+       plugin_job = gs_plugin_job_list_installed_apps_new (refine_flags, 0, 
GS_PLUGIN_JOB_DEDUPE_FLAGS_DEFAULT,
+                                                           GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_NONE);
        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/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 996892d91..b846af4b0 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -357,16 +357,18 @@ static void list_installed_apps_thread_cb (GTask        *task,
                                            GCancellable *cancellable);
 
 static void
-gs_plugin_flatpak_list_installed_apps_async (GsPlugin            *plugin,
-                                             GCancellable        *cancellable,
-                                             GAsyncReadyCallback  callback,
-                                             gpointer             user_data)
+gs_plugin_flatpak_list_installed_apps_async (GsPlugin                       *plugin,
+                                             GsPluginListInstalledAppsFlags  flags,
+                                             GCancellable                   *cancellable,
+                                             GAsyncReadyCallback             callback,
+                                             gpointer                        user_data)
 {
        GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (plugin);
        g_autoptr(GTask) task = NULL;
 
        task = g_task_new (plugin, cancellable, callback, user_data);
        g_task_set_source_tag (task, gs_plugin_flatpak_list_installed_apps_async);
+       g_task_set_task_data (task, GINT_TO_POINTER (flags), NULL);
 
        /* Queue a job to get the installed apps. */
        gs_worker_thread_queue (self->worker, G_PRIORITY_DEFAULT,
@@ -382,6 +384,7 @@ list_installed_apps_thread_cb (GTask        *task,
 {
        GsPluginFlatpak *self = GS_PLUGIN_FLATPAK (source_object);
        g_autoptr(GsAppList) list = gs_app_list_new ();
+       GsPluginListInstalledAppsFlags flags = GPOINTER_TO_INT (task_data);
        g_autoptr(GError) local_error = NULL;
 
        assert_in_worker (self);
diff --git a/plugins/snap/gs-plugin-snap.c b/plugins/snap/gs-plugin-snap.c
index 34e8be8b8..149fba578 100644
--- a/plugins/snap/gs-plugin-snap.c
+++ b/plugins/snap/gs-plugin-snap.c
@@ -612,15 +612,16 @@ static void list_installed_apps_cb (GObject      *source_object,
                                     gpointer      user_data);
 
 static void
-gs_plugin_snap_list_installed_apps_async (GsPlugin            *plugin,
-                                          GCancellable        *cancellable,
-                                          GAsyncReadyCallback  callback,
-                                          gpointer             user_data)
+gs_plugin_snap_list_installed_apps_async (GsPlugin                       *plugin,
+                                          GsPluginListInstalledAppsFlags  flags,
+                                          GCancellable                   *cancellable,
+                                          GAsyncReadyCallback             callback,
+                                          gpointer                        user_data)
 {
        GsPluginSnap *self = GS_PLUGIN_SNAP (plugin);
        g_autoptr(GTask) task = NULL;
        g_autoptr(SnapdClient) client = NULL;
-       gboolean interactive = gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE);
+       gboolean interactive = (flags & GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_INTERACTIVE);
        g_autoptr(GError) local_error = NULL;
 
        task = g_task_new (plugin, cancellable, callback, user_data);
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 081fa65cc..accd7c36b 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -454,7 +454,8 @@ gs_installed_page_load (GsInstalledPage *self)
                flags |= GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE;
 
        /* get installed apps */
-       plugin_job = gs_plugin_job_list_installed_apps_new (flags, 0, GS_APP_LIST_FILTER_FLAG_NONE);
+       plugin_job = gs_plugin_job_list_installed_apps_new (flags, 0, GS_APP_LIST_FILTER_FLAG_NONE,
+                                                           GS_PLUGIN_LIST_INSTALLED_APPS_FLAGS_INTERACTIVE);
        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]