[gnome-software/1021-please-add-a-way-to-show-only-open-source-apps: 6/6] gs-plugin-job-list-apps: Filter only for freely licensed apps when set to




commit 81559874eab5f65ea47d38c761c6a29ec1232088
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 10 15:17:12 2022 +0200

    gs-plugin-job-list-apps: Filter only for freely licensed apps when set to
    
    When the user asks to see only freely licensed apps, filter out the proprietary
    apps from the resulting list, unless they are already installed.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1021

 lib/gs-plugin-job-list-apps.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/lib/gs-plugin-job-list-apps.c b/lib/gs-plugin-job-list-apps.c
index a556387e5..f73e93afc 100644
--- a/lib/gs-plugin-job-list-apps.c
+++ b/lib/gs-plugin-job-list-apps.c
@@ -149,6 +149,20 @@ filter_valid_apps (GsApp    *app,
        return gs_plugin_loader_app_is_valid (app, refine_flags);
 }
 
+static gboolean
+filter_freely_licensed_apps (GsApp    *app,
+                            gpointer  user_data)
+{
+       return (gs_app_get_kind (app) != AS_COMPONENT_KIND_GENERIC &&
+               gs_app_get_kind (app) != AS_COMPONENT_KIND_DESKTOP_APP &&
+               gs_app_get_kind (app) != AS_COMPONENT_KIND_CONSOLE_APP &&
+               gs_app_get_kind (app) != AS_COMPONENT_KIND_WEB_APP) ||
+              gs_app_get_state (app) == GS_APP_STATE_INSTALLED ||
+              gs_app_get_state (app) == GS_APP_STATE_UPDATABLE ||
+              gs_app_get_state (app) == GS_APP_STATE_UPDATABLE_LIVE ||
+              gs_app_get_license_is_free (app);
+}
+
 static gboolean
 app_filter_qt_for_gtk_and_compatible (GsApp    *app,
                                       gpointer  user_data)
@@ -303,6 +317,12 @@ finish_op (GTask  *task,
        if (self->query != NULL)
                refine_flags = gs_app_query_get_refine_flags (self->query);
 
+       if ((refine_flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE) == 0 &&
+           (self->flags & GS_PLUGIN_LIST_APPS_FILTER_FREELY_LICENSED) != 0) {
+               /* Needs the license information when filtering with it */
+               refine_flags |= GS_PLUGIN_REFINE_FLAGS_REQUIRE_LICENSE;
+       }
+
        if (merged_list != NULL &&
            gs_app_list_length (merged_list) > 0 &&
            refine_flags != GS_PLUGIN_REFINE_FLAGS_NONE) {
@@ -361,6 +381,9 @@ finish_task (GTask     *task,
        gs_app_list_filter (merged_list, filter_valid_apps, self);
        gs_app_list_filter (merged_list, app_filter_qt_for_gtk_and_compatible, plugin_loader);
 
+       if ((self->flags & GS_PLUGIN_LIST_APPS_FILTER_FREELY_LICENSED) != 0)
+               gs_app_list_filter (merged_list, filter_freely_licensed_apps, self);
+
        /* Caller-specified filtering. */
        if (self->query != NULL)
                filter_func = gs_app_query_get_filter_func (self->query, &filter_func_data);


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