[gnome-software] trivial: Allow setting the dedupe flags on the GsPluginJob



commit 060c40eae502fb3b10e7e4d2588943f2d34ecbf5
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 28 12:01:45 2018 +0100

    trivial: Allow setting the dedupe flags on the GsPluginJob
    
    This allows us to have different dedupe flags for the different panels used in
    GNOME Software, for instance not showing duplicate installed apps in the search
    results, but showing all the installed applications in the installed page.

 lib/gs-plugin-job-private.h |  1 +
 lib/gs-plugin-job.c         | 32 ++++++++++++++++++++++++++++++++
 lib/gs-plugin-job.h         |  4 +++-
 lib/gs-plugin-loader.c      |  8 ++++----
 4 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-plugin-job-private.h b/lib/gs-plugin-job-private.h
index 6daadd09..7d6f765b 100644
--- a/lib/gs-plugin-job-private.h
+++ b/lib/gs-plugin-job-private.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 
 GsPluginAction          gs_plugin_job_get_action               (GsPluginJob    *self);
 GsPluginRefineFlags     gs_plugin_job_get_filter_flags         (GsPluginJob    *self);
+GsAppListFilterFlags    gs_plugin_job_get_dedupe_flags         (GsPluginJob    *self);
 GsPluginRefineFlags     gs_plugin_job_get_refine_flags         (GsPluginJob    *self);
 gboolean                gs_plugin_job_has_refine_flags         (GsPluginJob    *self,
                                                                 GsPluginRefineFlags refine_flags);
diff --git a/lib/gs-plugin-job.c b/lib/gs-plugin-job.c
index 2d6decb9..930a2759 100644
--- a/lib/gs-plugin-job.c
+++ b/lib/gs-plugin-job.c
@@ -32,6 +32,7 @@ struct _GsPluginJob
        GObject                  parent_instance;
        GsPluginRefineFlags      refine_flags;
        GsPluginRefineFlags      filter_flags;
+       GsAppListFilterFlags     dedupe_flags;
        gboolean                 interactive;
        guint                    max_results;
        guint                    timeout;
@@ -58,6 +59,7 @@ enum {
        PROP_SEARCH,
        PROP_REFINE_FLAGS,
        PROP_FILTER_FLAGS,
+       PROP_DEDUPE_FLAGS,
        PROP_INTERACTIVE,
        PROP_AUTH,
        PROP_APP,
@@ -84,6 +86,8 @@ gs_plugin_job_to_string (GsPluginJob *self)
                g_autofree gchar *tmp = gs_plugin_refine_flags_to_string (self->filter_flags);
                g_string_append_printf (str, " with filter-flags=%s", tmp);
        }
+       if (self->dedupe_flags > 0)
+               g_string_append_printf (str, " with dedupe-flags=%x", self->dedupe_flags);
        if (self->refine_flags > 0) {
                g_autofree gchar *tmp = gs_plugin_refine_flags_to_string (self->refine_flags);
                g_string_append_printf (str, " with refine-flags=%s", tmp);
@@ -169,6 +173,13 @@ gs_plugin_job_set_filter_flags (GsPluginJob *self, GsPluginRefineFlags filter_fl
        self->filter_flags = filter_flags;
 }
 
+void
+gs_plugin_job_set_dedupe_flags (GsPluginJob *self, GsAppListFilterFlags dedupe_flags)
+{
+       g_return_if_fail (GS_IS_PLUGIN_JOB (self));
+       self->dedupe_flags = dedupe_flags;
+}
+
 GsPluginRefineFlags
 gs_plugin_job_get_refine_flags (GsPluginJob *self)
 {
@@ -183,6 +194,13 @@ gs_plugin_job_get_filter_flags (GsPluginJob *self)
        return self->filter_flags;
 }
 
+GsAppListFilterFlags
+gs_plugin_job_get_dedupe_flags (GsPluginJob *self)
+{
+       g_return_val_if_fail (GS_IS_PLUGIN_JOB (self), 0);
+       return self->dedupe_flags;
+}
+
 gboolean
 gs_plugin_job_has_refine_flags (GsPluginJob *self, GsPluginRefineFlags refine_flags)
 {
@@ -453,6 +471,9 @@ gs_plugin_job_get_property (GObject *obj, guint prop_id, GValue *value, GParamSp
        case PROP_FILTER_FLAGS:
                g_value_set_uint64 (value, self->filter_flags);
                break;
+       case PROP_DEDUPE_FLAGS:
+               g_value_set_uint64 (value, self->dedupe_flags);
+               break;
        case PROP_INTERACTIVE:
                g_value_set_uint64 (value, self->interactive);
                break;
@@ -510,6 +531,9 @@ gs_plugin_job_set_property (GObject *obj, guint prop_id, const GValue *value, GP
        case PROP_FILTER_FLAGS:
                gs_plugin_job_set_filter_flags (self, g_value_get_uint64 (value));
                break;
+       case PROP_DEDUPE_FLAGS:
+               gs_plugin_job_set_dedupe_flags (self, g_value_get_uint64 (value));
+               break;
        case PROP_INTERACTIVE:
                gs_plugin_job_set_interactive (self, g_value_get_uint64 (value));
                break;
@@ -596,6 +620,11 @@ gs_plugin_job_class_init (GsPluginJobClass *klass)
                                     G_PARAM_READWRITE);
        g_object_class_install_property (object_class, PROP_FILTER_FLAGS, pspec);
 
+       pspec = g_param_spec_uint64 ("dedupe-flags", NULL, NULL,
+                                    0, G_MAXUINT64, 0,
+                                    G_PARAM_READWRITE);
+       g_object_class_install_property (object_class, PROP_DEDUPE_FLAGS, pspec);
+
        pspec = g_param_spec_uint64 ("interactive", NULL, NULL,
                                     0, G_MAXUINT64, 0,
                                     G_PARAM_READWRITE);
@@ -657,6 +686,9 @@ gs_plugin_job_init (GsPluginJob *self)
 {
        self->refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT;
        self->filter_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT;
+       self->dedupe_flags = GS_APP_LIST_FILTER_FLAG_KEY_ID |
+                            GS_APP_LIST_FILTER_FLAG_KEY_SOURCE |
+                            GS_APP_LIST_FILTER_FLAG_KEY_VERSION;
        self->list = gs_app_list_new ();
        self->time_created = g_get_monotonic_time ();
 }
diff --git a/lib/gs-plugin-job.h b/lib/gs-plugin-job.h
index fdca6868..25110bde 100644
--- a/lib/gs-plugin-job.h
+++ b/lib/gs-plugin-job.h
@@ -24,7 +24,7 @@
 
 #include <glib-object.h>
 
-#include "gs-app-list.h"
+#include "gs-app-list-private.h"
 #include "gs-auth.h"
 #include "gs-category.h"
 #include "gs-plugin-types.h"
@@ -40,6 +40,8 @@ void           gs_plugin_job_set_refine_flags         (GsPluginJob    *self,
                                                         GsPluginRefineFlags refine_flags);
 void            gs_plugin_job_set_filter_flags         (GsPluginJob    *self,
                                                         GsPluginRefineFlags filter_flags);
+void            gs_plugin_job_set_dedupe_flags         (GsPluginJob    *self,
+                                                        GsAppListFilterFlags dedupe_flags);
 void            gs_plugin_job_set_interactive          (GsPluginJob    *self,
                                                         gboolean        interactive);
 void            gs_plugin_job_set_max_results          (GsPluginJob    *self,
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 30f51d94..8ba1d580 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3097,6 +3097,7 @@ gs_plugin_loader_process_thread_cb (GTask *task,
 {
        GError *error = NULL;
        GsPluginLoaderHelper *helper = (GsPluginLoaderHelper *) task_data;
+       GsAppListFilterFlags dedupe_flags;
        GsAppList *list = gs_plugin_job_get_list (helper->plugin_job);
        GsPluginAction action = gs_plugin_job_get_action (helper->plugin_job);
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
@@ -3400,10 +3401,9 @@ gs_plugin_loader_process_thread_cb (GTask *task,
        /* filter duplicates with priority, taking into account the source name
         * & version, so we combine available updates with the installed app */
        gs_app_list_filter (list, gs_plugin_loader_app_set_prio, plugin_loader);
-       gs_app_list_filter_duplicates (list,
-                                      GS_APP_LIST_FILTER_FLAG_KEY_ID |
-                                      GS_APP_LIST_FILTER_FLAG_KEY_SOURCE |
-                                      GS_APP_LIST_FILTER_FLAG_KEY_VERSION);
+       dedupe_flags = gs_plugin_job_get_dedupe_flags (helper->plugin_job);
+       if (dedupe_flags != GS_APP_LIST_FILTER_FLAG_NONE)
+               gs_app_list_filter_duplicates (list, dedupe_flags);
 
        /* sort these again as the refine may have added useful metadata */
        gs_plugin_loader_job_sorted_truncation_again (helper);


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