[gnome-software/wip/plugin-loader-inherit-list-properties] gs-plugin-loader: Inherit list properties when replacing it



commit 35e7b314a58591a6dc95dd8a90a8f3c1e1aedd20
Author: Milan Crha <mcrha redhat com>
Date:   Fri Mar 11 11:51:22 2022 +0100

    gs-plugin-loader: Inherit list properties when replacing it
    
    When running refine on a subset of the apps returned by a plugin action,
    the original list is discarded and replaced with the new refined list.
    The problem is that the discarded list has set important properties,
    like whether it had been randomized, truncated or how many max items
    the list had so far.
    
    These properties are usable for example when search for the apps, thus
    inherit them before discarding the original list.

 lib/gs-app-list-private.h |  2 ++
 lib/gs-app-list.c         | 17 +++++++++++++++++
 lib/gs-plugin-loader.c    | 16 ++++++++++++++++
 3 files changed, 35 insertions(+)
---
diff --git a/lib/gs-app-list-private.h b/lib/gs-app-list-private.h
index 9f540a620..e05febb1b 100644
--- a/lib/gs-app-list-private.h
+++ b/lib/gs-app-list-private.h
@@ -34,6 +34,8 @@ typedef enum {
 } GsAppListFlags;
 
 guint           gs_app_list_get_size_peak      (GsAppList      *list);
+void            gs_app_list_set_size_peak      (GsAppList      *list,
+                                                guint           size_peak);
 void            gs_app_list_filter_duplicates  (GsAppList      *list,
                                                 GsAppListFilterFlags flags);
 void            gs_app_list_randomize          (GsAppList      *list);
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index 465699ca1..3122aa41d 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -281,6 +281,23 @@ gs_app_list_get_size_peak (GsAppList *list)
        return list->size_peak;
 }
 
+/**
+ * gs_app_list_set_size_peak:
+ * @list: A #GsAppList
+ * @size_peak: A value to set
+ *
+ * Sets the largest size the list has ever been.
+ *
+ * Since: 43
+ **/
+void
+gs_app_list_set_size_peak (GsAppList *list,
+                          guint size_peak)
+{
+       g_return_if_fail (GS_IS_APP_LIST (list));
+       list->size_peak = size_peak;
+}
+
 static GsApp *
 gs_app_list_lookup_safe (GsAppList *list, const gchar *unique_id)
 {
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 6c72bb022..a5a0025b6 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3096,6 +3096,18 @@ gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
        return TRUE;
 }
 
+static void
+gs_plugin_loader_inherit_list_props (GsAppList *des_list,
+                                    GsAppList *src_list)
+{
+       if (gs_app_list_has_flag (src_list, GS_APP_LIST_FLAG_IS_TRUNCATED))
+               gs_app_list_add_flag (des_list, GS_APP_LIST_FLAG_IS_TRUNCATED);
+       if (gs_app_list_has_flag (src_list, GS_APP_LIST_FLAG_IS_RANDOMIZED))
+               gs_app_list_add_flag (des_list, GS_APP_LIST_FLAG_IS_RANDOMIZED);
+
+       gs_app_list_set_size_peak (des_list, gs_app_list_get_size_peak (src_list));
+}
+
 static void
 gs_plugin_loader_process_thread_cb (GTask *task,
                                    gpointer object,
@@ -3298,6 +3310,8 @@ gs_plugin_loader_process_thread_cb (GTask *task,
                        return;
                }
 
+               gs_plugin_loader_inherit_list_props (new_list, list);
+
                /* Update the app list in case the refine resolved any wildcards. */
                g_set_object (&list, new_list);
        } else {
@@ -3344,6 +3358,8 @@ gs_plugin_loader_process_thread_cb (GTask *task,
                        return;
                }
 
+               gs_plugin_loader_inherit_list_props (new_list, list);
+
                /* Update the app list in case the refine resolved any wildcards. */
                g_set_object (&list, new_list);
 


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