[gnome-software: 1/16] gs-app-query: Add an is-installed property




commit 720bb7828c4c0fe04806e87be8b7d7afdacd9317
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon May 9 10:19:49 2022 +0100

    gs-app-query: Add an is-installed property
    
    This allows for querying for apps which are already installed.
    
    This query property will eventually replace the
    `GsPluginJobListInstalledApps` job, by setting this property and using
    `GsPluginJobListApps`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-app-query.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/gs-app-query.h |  1 +
 2 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index 1fb7980cc..fe21b797d 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -75,6 +75,7 @@ struct _GsAppQuery
        GDateTime *released_since;  /* (owned) (nullable) */
        GsAppQueryTristate is_curated;
        GsCategory *category;  /* (nullable) (owned) */
+       GsAppQueryTristate is_installed;
 };
 
 G_DEFINE_TYPE (GsAppQuery, gs_app_query, G_TYPE_OBJECT)
@@ -93,9 +94,10 @@ typedef enum {
        PROP_RELEASED_SINCE,
        PROP_IS_CURATED,
        PROP_CATEGORY,
+       PROP_IS_INSTALLED,
 } GsAppQueryProperty;
 
-static GParamSpec *props[PROP_CATEGORY + 1] = { NULL, };
+static GParamSpec *props[PROP_IS_INSTALLED + 1] = { NULL, };
 
 static void
 gs_app_query_get_property (GObject    *object,
@@ -145,6 +147,9 @@ gs_app_query_get_property (GObject    *object,
        case PROP_CATEGORY:
                g_value_set_object (value, self->category);
                break;
+       case PROP_IS_INSTALLED:
+               g_value_set_enum (value, self->is_installed);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -230,6 +235,11 @@ gs_app_query_set_property (GObject      *object,
                g_assert (self->category == NULL);
                self->category = g_value_dup_object (value);
                break;
+       case PROP_IS_INSTALLED:
+               /* Construct only. */
+               g_assert (self->is_installed == GS_APP_QUERY_TRISTATE_UNSET);
+               self->is_installed = g_value_get_enum (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -490,6 +500,25 @@ gs_app_query_class_init (GsAppQueryClass *klass)
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                     G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+       /**
+        * GsAppQuery:is-installed:
+        *
+        * Whether apps must be installed (%GS_APP_QUERY_TRISTATE_TRUE), or not
+        * installed (%GS_APP_QUERY_TRISTATE_FALSE).
+        *
+        * If this is %GS_APP_QUERY_TRISTATE_UNSET, apps are not filtered by
+        * their installed state.
+        *
+        * Since: 43
+        */
+       props[PROP_IS_INSTALLED] =
+               g_param_spec_enum ("is-installed", "Is Installed",
+                                  "Whether apps must be installed, or not installed.",
+                                  GS_TYPE_APP_QUERY_TRISTATE,
+                                  GS_APP_QUERY_TRISTATE_UNSET,
+                                  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);
 }
 
@@ -497,6 +526,7 @@ static void
 gs_app_query_init (GsAppQuery *self)
 {
        self->is_curated = GS_APP_QUERY_TRISTATE_UNSET;
+       self->is_installed = GS_APP_QUERY_TRISTATE_UNSET;
 }
 
 /**
@@ -651,6 +681,8 @@ gs_app_query_get_n_properties_set (GsAppQuery *self)
                n++;
        if (self->category != NULL)
                n++;
+       if (self->is_installed != GS_APP_QUERY_TRISTATE_UNSET)
+               n++;
 
        return n;
 }
@@ -730,3 +762,22 @@ gs_app_query_get_category (GsAppQuery *self)
 
        return self->category;
 }
+
+/**
+ * gs_app_query_get_is_installed:
+ * @self: a #GsAppQuery
+ *
+ * Get the value of #GsAppQuery:is-installed.
+ *
+ * Returns: %GS_APP_QUERY_TRISTATE_TRUE if apps must be installed,
+ *   %GS_APP_QUERY_TRISTATE_FALSE if they must be not installed, or
+ *   %GS_APP_QUERY_TRISTATE_UNSET if it doesn’t matter
+ * Since: 43
+ */
+GsAppQueryTristate
+gs_app_query_get_is_installed (GsAppQuery *self)
+{
+       g_return_val_if_fail (GS_IS_APP_QUERY (self), GS_APP_QUERY_TRISTATE_UNSET);
+
+       return self->is_installed;
+}
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index 84705f90b..203cdeaef 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -62,5 +62,6 @@ const gchar * const   *gs_app_query_get_provides_files (GsAppQuery *self);
 GDateTime              *gs_app_query_get_released_since (GsAppQuery *self);
 GsAppQueryTristate      gs_app_query_get_is_curated     (GsAppQuery *self);
 GsCategory             *gs_app_query_get_category       (GsAppQuery *self);
+GsAppQueryTristate      gs_app_query_get_is_installed   (GsAppQuery *self);
 
 G_END_DECLS


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