[gnome-software: 1/7] gs-app-query: Add provides-tag and provides-type properties
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/7] gs-app-query: Add provides-tag and provides-type properties
- Date: Wed, 13 Jul 2022 16:42:24 +0000 (UTC)
commit 2c5dea46790f82c66200e8441098c9bab215c5d0
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Jul 6 16:54:41 2022 +0100
gs-app-query: Add provides-tag and provides-type properties
These will be used to replace `GS_PLUGIN_ACTION_SEARCH_PROVIDES` in the
next few commits.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1472
lib/gs-app-query.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
lib/gs-app-query.h | 35 +++++++++++++++++++
2 files changed, 134 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index 885dc0144..cd2fc9331 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -85,6 +85,8 @@ struct _GsAppQuery
gchar **keywords; /* (owned) (nullable) (array zero-terminated=1) */
GsApp *alternate_of; /* (nullable) (owned) */
+ gchar *provides_tag; /* (owned) (nullable) */
+ GsAppQueryProvidesType provides_type;
};
G_DEFINE_TYPE (GsAppQuery, gs_app_query, G_TYPE_OBJECT)
@@ -109,9 +111,21 @@ typedef enum {
PROP_IS_INSTALLED,
PROP_KEYWORDS,
PROP_ALTERNATE_OF,
+ PROP_PROVIDES_TAG,
+ PROP_PROVIDES_TYPE,
} GsAppQueryProperty;
-static GParamSpec *props[PROP_ALTERNATE_OF + 1] = { NULL, };
+static GParamSpec *props[PROP_PROVIDES_TYPE + 1] = { NULL, };
+
+static void
+gs_app_query_constructed (GObject *object)
+{
+ GsAppQuery *self = GS_APP_QUERY (object);
+
+ G_OBJECT_CLASS (gs_app_query_parent_class)->constructed (object);
+
+ g_assert ((self->provides_tag != NULL) == (self->provides_type != GS_APP_QUERY_PROVIDES_UNKNOWN));
+}
static void
gs_app_query_get_property (GObject *object,
@@ -179,6 +193,12 @@ gs_app_query_get_property (GObject *object,
case PROP_ALTERNATE_OF:
g_value_set_object (value, self->alternate_of);
break;
+ case PROP_PROVIDES_TAG:
+ g_value_set_string (value, self->provides_tag);
+ break;
+ case PROP_PROVIDES_TYPE:
+ g_value_set_enum (value, self->provides_type);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -309,6 +329,16 @@ gs_app_query_set_property (GObject *object,
g_assert (self->alternate_of == NULL);
self->alternate_of = g_value_dup_object (value);
break;
+ case PROP_PROVIDES_TAG:
+ /* Construct only. */
+ g_assert (self->provides_tag == NULL);
+ self->provides_tag = g_value_dup_string (value);
+ break;
+ case PROP_PROVIDES_TYPE:
+ /* Construct only. */
+ g_assert (self->provides_type == GS_APP_QUERY_PROVIDES_UNKNOWN);
+ self->provides_type = g_value_get_enum (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -346,6 +376,7 @@ gs_app_query_finalize (GObject *object)
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_clear_pointer (&self->provides_tag, g_free);
G_OBJECT_CLASS (gs_app_query_parent_class)->finalize (object);
}
@@ -355,6 +386,7 @@ gs_app_query_class_init (GsAppQueryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->constructed = gs_app_query_constructed;
object_class->get_property = gs_app_query_get_property;
object_class->set_property = gs_app_query_set_property;
object_class->dispose = gs_app_query_dispose;
@@ -700,6 +732,45 @@ gs_app_query_class_init (GsAppQueryClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GsAppQuery:provides-tag: (nullable)
+ *
+ * A tag which apps must provide.
+ *
+ * The interpretation of the tag depends on #GsAppQuery:provides-type,
+ * which must not be %GS_APP_QUERY_PROVIDES_UNKNOWN if this is
+ * non-%NULL. Typically a tag will be a content type which the app
+ * implements, or the name of a printer which the app provides the
+ * driver for, etc.
+ *
+ * If this is %NULL, apps are not filtered by what they provide.
+ *
+ * Since: 43
+ */
+ props[PROP_PROVIDES_TAG] =
+ g_param_spec_string ("provides-tag", "Provides Tag",
+ "A tag which apps must provide.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ /**
+ * GsAppQuery:provides-type:
+ *
+ * The type of #GsAppQuery:provides-tag.
+ *
+ * If this is %GS_APP_QUERY_PROVIDES_UNKNOWN, apps are not filtered by
+ * what they provide.
+ *
+ * Since: 43
+ */
+ props[PROP_PROVIDES_TYPE] =
+ g_param_spec_enum ("provides-type", "Provides Type",
+ "The type of #GsAppQuery:provides-tag.",
+ GS_TYPE_APP_QUERY_PROVIDES_TYPE, GS_APP_QUERY_PROVIDES_UNKNOWN,
+ 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);
}
@@ -709,6 +780,7 @@ gs_app_query_init (GsAppQuery *self)
self->is_curated = GS_APP_QUERY_TRISTATE_UNSET;
self->is_featured = GS_APP_QUERY_TRISTATE_UNSET;
self->is_installed = GS_APP_QUERY_TRISTATE_UNSET;
+ self->provides_type = GS_APP_QUERY_PROVIDES_UNKNOWN;
}
/**
@@ -875,6 +947,8 @@ gs_app_query_get_n_properties_set (GsAppQuery *self)
n++;
if (self->alternate_of != NULL)
n++;
+ if (self->provides_tag != NULL)
+ n++;
return n;
}
@@ -1073,3 +1147,27 @@ gs_app_query_get_alternate_of (GsAppQuery *self)
return self->alternate_of;
}
+
+/**
+ * gs_app_query_get_provides:
+ * @self: a #GsAppQuery
+ * @out_provides_tag: (transfer none) (optional) (nullable) (out): return
+ * location for the value of #GsAppQuery:provides-tag, or %NULL to ignore
+ *
+ * Get the value of #GsAppQuery:provides-type and #GsAppQuery:provides-tag.
+ *
+ * Returns: the type of tag to filter on, or %GS_APP_QUERY_PROVIDES_UNKNOWN to
+ * not filter on provides
+ * Since: 43
+ */
+GsAppQueryProvidesType
+gs_app_query_get_provides (GsAppQuery *self,
+ const gchar **out_provides_tag)
+{
+ g_return_val_if_fail (GS_IS_APP_QUERY (self), GS_APP_QUERY_PROVIDES_UNKNOWN);
+
+ if (out_provides_tag != NULL)
+ *out_provides_tag = self->provides_tag;
+
+ return self->provides_type;
+}
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index 218e664ac..b66c56e5f 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -41,6 +41,39 @@ typedef enum
GS_APP_QUERY_TRISTATE_TRUE = 1,
} GsAppQueryTristate;
+/**
+ * GsAppQueryProvidesType:
+ * @GS_APP_QUERY_PROVIDES_UNKNOWN: Format is unknown and value is unset.
+ * @GS_APP_QUERY_PROVIDES_PACKAGE_NAME: A package name in whatever ID format is
+ * used natively by the current distro.
+ * @GS_APP_QUERY_PROVIDES_GSTREAMER: A GStreamer plugin name which the app must
+ * provide.
+ * @GS_APP_QUERY_PROVIDES_FONT: A font name which the app must provide.
+ * @GS_APP_QUERY_PROVIDES_MIME_HANDLER: A MIME type/content type which the app
+ * must support.
+ * @GS_APP_QUERY_PROVIDES_PS_DRIVER: A printer/PostScript driver which the app
+ * must provide.
+ * @GS_APP_QUERY_PROVIDES_PLASMA: A Plasma ID which the app must provide.
+ * (FIXME: It’s not really clear what this means, but it’s historically been
+ * supported.)
+ *
+ * A type for identifying the format or meaning of #GsAppQuery:provides-tag.
+ *
+ * This allows querying for apps which provide various types of functionality,
+ * such as printer drivers or fonts.
+ *
+ * Since: 43
+ */
+typedef enum {
+ GS_APP_QUERY_PROVIDES_UNKNOWN = 0,
+ GS_APP_QUERY_PROVIDES_PACKAGE_NAME,
+ GS_APP_QUERY_PROVIDES_GSTREAMER,
+ GS_APP_QUERY_PROVIDES_FONT,
+ GS_APP_QUERY_PROVIDES_MIME_HANDLER,
+ GS_APP_QUERY_PROVIDES_PS_DRIVER,
+ GS_APP_QUERY_PROVIDES_PLASMA,
+} GsAppQueryProvidesType;
+
#define GS_TYPE_APP_QUERY (gs_app_query_get_type ())
G_DECLARE_FINAL_TYPE (GsAppQuery, gs_app_query, GS, APP_QUERY, GObject)
@@ -69,5 +102,7 @@ const gchar * const *gs_app_query_get_deployment_featured
const gchar * const *gs_app_query_get_developers (GsAppQuery *self);
const gchar * const *gs_app_query_get_keywords (GsAppQuery *self);
GsApp *gs_app_query_get_alternate_of (GsAppQuery *self);
+GsAppQueryProvidesType gs_app_query_get_provides (GsAppQuery *self,
+ const gchar **out_provides_tag);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]