[gnome-software: 2/14] gs-app-query: Add a helper to count the number of query properties set
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 2/14] gs-app-query: Add a helper to count the number of query properties set
- Date: Mon, 9 May 2022 13:34:15 +0000 (UTC)
commit 5ab5f614685d0b1881e64f6b282a3ce222d5aff5
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed May 4 16:46:10 2022 +0100
gs-app-query: Add a helper to count the number of query properties set
Until all the plugins are rewritten to support complex queries which
filter by more than one query property, those plugins need to reject
such complex queries.
Add a helper function to count the number of query properties set, which
will help with this as the number of query properties increases.
This could eventually be removed once all plugins support complex
queries, but that’s unlikely to happen in the near future, as there are
currently no bits of the UI which use such queries.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-app-query.c | 33 +++++++++++++++++++++++++++++++++
lib/gs-app-query.h | 2 ++
2 files changed, 35 insertions(+)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index f25b20d11..1fb7980cc 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -622,6 +622,39 @@ gs_app_query_get_filter_func (GsAppQuery *self,
return self->filter_func;
}
+/**
+ * gs_app_query_get_n_properties_set:
+ * @self: a #GsAppQuery
+ *
+ * Get the number of query properties which have been set.
+ *
+ * These are the properties which determine the query results, rather than ones
+ * which control refining the results (#GsAppQuery:refine-flags,
+ * #GsAppQuery:max-results, #GsAppQuery:dedupe-flags, #GsAppQuery:sort-func and
+ * its user data, #GsAppQuery:filter-func and its user data).
+ *
+ * Returns: number of properties set so they will affect query results
+ * Since: 43
+ */
+guint
+gs_app_query_get_n_properties_set (GsAppQuery *self)
+{
+ guint n = 0;
+
+ g_return_val_if_fail (GS_IS_APP_QUERY (self), 0);
+
+ if (self->provides_files != NULL)
+ n++;
+ if (self->released_since != NULL)
+ n++;
+ if (self->is_curated != GS_APP_QUERY_TRISTATE_UNSET)
+ n++;
+ if (self->category != NULL)
+ n++;
+
+ return n;
+}
+
/**
* gs_app_query_get_provides_files:
* @self: a #GsAppQuery
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index d6c099dec..84705f90b 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -56,6 +56,8 @@ GsAppListSortFunc gs_app_query_get_sort_func (GsAppQuery *self,
GsAppListFilterFunc gs_app_query_get_filter_func (GsAppQuery *self,
gpointer *user_data_out);
+guint gs_app_query_get_n_properties_set (GsAppQuery *self);
+
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]