[gnome-software: 2/20] gs-app-query: Add a keywords property
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/20] gs-app-query: Add a keywords property
- Date: Mon, 11 Jul 2022 08:41:48 +0000 (UTC)
commit 9fec0ee3bd447a7de34fc798f8d9b8820a4fd001
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Jul 1 15:01:29 2022 +0100
gs-app-query: Add a keywords property
This will be used to replace `GS_PLUGIN_ACTION_SEARCH` in the next few
commits.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-app-query.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
lib/gs-app-query.h | 1 +
2 files changed, 64 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index 403996cb9..079b2a11e 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -82,6 +82,8 @@ struct _GsAppQuery
gchar **deployment_featured; /* (owned) (nullable) (array zero-terminated=1) */
/* This is guaranteed to either be %NULL, or a non-empty array */
gchar **developers; /* (owned) (nullable) (array zero-terminated=1) */
+
+ gchar **keywords; /* (owned) (nullable) (array zero-terminated=1) */
};
G_DEFINE_TYPE (GsAppQuery, gs_app_query, G_TYPE_OBJECT)
@@ -104,9 +106,10 @@ typedef enum {
PROP_IS_FEATURED,
PROP_CATEGORY,
PROP_IS_INSTALLED,
+ PROP_KEYWORDS,
} GsAppQueryProperty;
-static GParamSpec *props[PROP_IS_INSTALLED + 1] = { NULL, };
+static GParamSpec *props[PROP_KEYWORDS + 1] = { NULL, };
static void
gs_app_query_get_property (GObject *object,
@@ -168,6 +171,9 @@ gs_app_query_get_property (GObject *object,
case PROP_IS_INSTALLED:
g_value_set_enum (value, self->is_installed);
break;
+ case PROP_KEYWORDS:
+ g_value_set_boxed (value, self->keywords);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -282,6 +288,16 @@ gs_app_query_set_property (GObject *object,
/* Construct only. */
g_assert (self->is_installed == GS_APP_QUERY_TRISTATE_UNSET);
self->is_installed = g_value_get_enum (value);
+ break;
+ case PROP_KEYWORDS:
+ /* Construct only. */
+ g_assert (self->keywords == NULL);
+ self->keywords = g_value_dup_boxed (value);
+
+ /* Squash empty arrays to %NULL. */
+ if (self->keywords != NULL && self->keywords[0] == NULL)
+ g_clear_pointer (&self->keywords, g_strfreev);
+
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -318,6 +334,7 @@ gs_app_query_finalize (GObject *object)
g_clear_pointer (&self->developers, g_strfreev);
g_clear_pointer (&self->provides_files, g_strfreev);
g_clear_pointer (&self->released_since, g_date_time_unref);
+ g_clear_pointer (&self->keywords, g_strfreev);
G_OBJECT_CLASS (gs_app_query_parent_class)->finalize (object);
}
@@ -629,6 +646,28 @@ gs_app_query_class_init (GsAppQueryClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GsAppQuery:keywords:
+ *
+ * A set of search keywords which apps must match.
+ *
+ * Search matches may be done against multiple properties of the app,
+ * such as its name, description, supported content types, defined
+ * keywords, etc. The keywords in this property may be stemmed in an
+ * undefined way after being retrieved from #GsAppQuery.
+ *
+ * If this is %NULL, apps are not filtered by matches to this set of
+ * keywords. An empty array is considered equivalent to %NULL.
+ *
+ * Since: 43
+ */
+ props[PROP_KEYWORDS] =
+ g_param_spec_boxed ("keywords", "Keywords",
+ "A set of search keywords which apps must match.",
+ G_TYPE_STRV,
+ 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);
}
@@ -800,6 +839,8 @@ gs_app_query_get_n_properties_set (GsAppQuery *self)
n++;
if (self->developers != NULL)
n++;
+ if (self->keywords != NULL)
+ n++;
return n;
}
@@ -959,3 +1000,24 @@ gs_app_query_get_developers (GsAppQuery *self)
return (const gchar * const *) self->developers;
}
+
+/**
+ * gs_app_query_get_keywords:
+ * @self: a #GsAppQuery
+ *
+ * Get the value of #GsAppQuery:keywords.
+ *
+ * Returns: a set of search keywords which apps must match, or %NULL to not
+ * filter by it
+ * Since: 43
+ */
+const gchar * const *
+gs_app_query_get_keywords (GsAppQuery *self)
+{
+ g_return_val_if_fail (GS_IS_APP_QUERY (self), NULL);
+
+ /* Always return %NULL or a non-empty array */
+ g_assert (self->keywords == NULL || self->keywords[0] != NULL);
+
+ return (const gchar * const *) self->keywords;
+}
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index 666c3d240..10afa493a 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -67,5 +67,6 @@ GsAppQueryTristate gs_app_query_get_is_installed (GsAppQuery *self);
const gchar * const *gs_app_query_get_deployment_featured
(GsAppQuery *self);
const gchar * const *gs_app_query_get_developers (GsAppQuery *self);
+const gchar * const *gs_app_query_get_keywords (GsAppQuery *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]