[gnome-software/1409-add-available-for-fedora-section-to-the-explore-page: 110/115] gs-app-query: Add 'deployment-featured' property




commit 861aebea99aef54325a495f2f3911b7b0c1e4e18
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 6 11:38:33 2022 +0200

    gs-app-query: Add 'deployment-featured' property

 lib/gs-app-query.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gs-app-query.h |  2 ++
 2 files changed, 66 insertions(+)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index f4dad5035..206c11f58 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -76,6 +76,9 @@ struct _GsAppQuery
        GsAppQueryTristate is_curated;
        GsCategory *category;  /* (nullable) (owned) */
        GsAppQueryTristate is_installed;
+
+       /* This is guaranteed to either be %NULL, or a non-empty array */
+       gchar **deployment_featured;  /* (owned) (nullable) (array zero-terminated=1) */
 };
 
 G_DEFINE_TYPE (GsAppQuery, gs_app_query, G_TYPE_OBJECT)
@@ -90,6 +93,7 @@ typedef enum {
        PROP_FILTER_FUNC,
        PROP_FILTER_USER_DATA,
        PROP_FILTER_USER_DATA_NOTIFY,
+       PROP_DEPLOYMENT_FEATURED,
        PROP_PROVIDES_FILES,
        PROP_RELEASED_SINCE,
        PROP_IS_CURATED,
@@ -135,6 +139,9 @@ gs_app_query_get_property (GObject    *object,
        case PROP_FILTER_USER_DATA_NOTIFY:
                g_value_set_pointer (value, self->filter_user_data_notify);
                break;
+       case PROP_DEPLOYMENT_FEATURED:
+               g_value_set_boxed (value, self->deployment_featured);
+               break;
        case PROP_PROVIDES_FILES:
                g_value_set_boxed (value, self->provides_files);
                break;
@@ -209,6 +216,16 @@ gs_app_query_set_property (GObject      *object,
                /* Construct only. */
                g_assert (self->filter_user_data_notify == NULL);
                self->filter_user_data_notify = g_value_get_pointer (value);
+               break;
+       case PROP_DEPLOYMENT_FEATURED:
+               /* Construct only. */
+               g_assert (self->deployment_featured == NULL);
+               self->deployment_featured = g_value_dup_boxed (value);
+
+               /* Squash empty arrays to %NULL. */
+               if (self->deployment_featured != NULL && self->deployment_featured[0] == NULL)
+                       g_clear_pointer (&self->deployment_featured, g_strfreev);
+
                break;
        case PROP_PROVIDES_FILES:
                /* Construct only. */
@@ -271,6 +288,7 @@ gs_app_query_finalize (GObject *object)
 {
        GsAppQuery *self = GS_APP_QUERY (object);
 
+       g_clear_pointer (&self->deployment_featured, g_strfreev);
        g_clear_pointer (&self->provides_files, g_strfreev);
        g_clear_pointer (&self->released_since, g_date_time_unref);
 
@@ -423,6 +441,29 @@ gs_app_query_class_init (GsAppQueryClass *klass)
                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                      G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+       /**
+        * GsAppQuery:deployment-featured: (nullable)
+        *
+        * A list of `GnomeSoftware::DeploymentFeatured` app keys.
+        *
+        * Search for applications that should be featured in a deployment-specific
+        * section on the overview page.
+        * This is expected to be a curated list of applications that are high quality
+        * and feature-complete. Only apps matching at least one of the keys in this
+        * list are returned.
+        *
+        * This may be %NULL to not filter on it. An empty array is
+        * considered equivalent to %NULL.
+        *
+        * Since: 43
+        */
+       props[PROP_DEPLOYMENT_FEATURED] =
+               g_param_spec_boxed ("deployment-featured", "Deployment Featured",
+                                   "A list of `GnomeSoftware::DeploymentFeatured` app keys.",
+                                   G_TYPE_STRV,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                                   G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
        /**
         * GsAppQuery:provides-files: (nullable)
         *
@@ -683,6 +724,8 @@ gs_app_query_get_n_properties_set (GsAppQuery *self)
                n++;
        if (self->is_installed != GS_APP_QUERY_TRISTATE_UNSET)
                n++;
+       if (self->deployment_featured != NULL)
+               n++;
 
        return n;
 }
@@ -781,3 +824,24 @@ gs_app_query_get_is_installed (GsAppQuery *self)
 
        return self->is_installed;
 }
+
+/**
+ * gs_app_query_get_deployment_featured:
+ * @self: a #GsAppQuery
+ *
+ * Get the value of #GsAppQuery:deployment-featured.
+ *
+ * Returns: (nullable): a list of `GnomeSoftware::DeploymentFeatured` app keys,
+ *   which the apps have set in a custom key, or %NULL to not filter on this
+ * Since: 43
+ */
+const gchar * const *
+gs_app_query_get_deployment_featured (GsAppQuery *self)
+{
+       g_return_val_if_fail (GS_IS_APP_QUERY (self), NULL);
+
+       /* Always return %NULL or a non-empty array */
+       g_assert (self->deployment_featured == NULL || self->deployment_featured[0] != NULL);
+
+       return (const gchar * const *) self->deployment_featured;
+}
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index 203cdeaef..7d586beaf 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -63,5 +63,7 @@ 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);
+const gchar * const    *gs_app_query_get_deployment_featured
+                                                        (GsAppQuery *self);
 
 G_END_DECLS


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