summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-09-14 10:11:32 +0100
committerRichard Hughes <richard@hughsie.com>2017-09-14 10:11:32 +0100
commit10c41ba6b3b3a1dc0ac91be491c707e4776dc3fd (patch)
tree89b567447b502813aca257ca787cdb7594db9b0e
parenta21bc97045e3b7e880181aa7f4a213c0156f90f5 (diff)
downloadappstream-glib-10c41ba6b3b3a1dc0ac91be491c707e4776dc3fd.tar.gz
Add as_app_get_release_by_version()
-rw-r--r--libappstream-glib/as-app.c23
-rw-r--r--libappstream-glib/as-app.h2
-rw-r--r--libappstream-glib/as-self-test.c5
3 files changed, 30 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 5ad365a..488fd09 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -1120,6 +1120,29 @@ as_app_get_release_default (AsApp *app)
}
/**
+ * as_app_get_release_by_version:
+ * @app: a #AsApp instance.
+ * @version: a release version number, e.g. "1.2.3"
+ *
+ * Gets a specific release from the application.
+ *
+ * Returns: (transfer none): a release, or %NULL
+ *
+ * Since: 0.7.3
+ **/
+AsRelease *
+as_app_get_release_by_version (AsApp *app, const gchar *version)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ for (guint i = 0; i < priv->releases->len; i++) {
+ AsRelease *release_tmp = g_ptr_array_index (priv->releases, i);
+ if (g_strcmp0 (version, as_release_get_version (release_tmp)) == 0)
+ return release_tmp;
+ }
+ return NULL;
+}
+
+/**
* as_app_get_provides:
* @app: a #AsApp instance.
*
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index d2ed773..3a40dd9 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -713,6 +713,8 @@ AsBundle *as_app_get_bundle_default (AsApp *app);
AsRelease *as_app_get_release (AsApp *app,
const gchar *version);
AsRelease *as_app_get_release_default (AsApp *app);
+AsRelease *as_app_get_release_by_version (AsApp *app,
+ const gchar *version);
AsRequire *as_app_get_require_by_value (AsApp *app,
AsRequireKind kind,
const gchar *value);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index fe1987d..b73a528 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1828,6 +1828,11 @@ as_test_app_func (void)
g_assert (rel != NULL);
g_assert_cmpstr (as_release_get_version (rel), ==, "3.11.91");
+ /* check specific release */
+ rel = as_app_get_release_by_version (app, "3.11.91");
+ g_assert (rel != NULL);
+ g_assert_cmpstr (as_release_get_version (rel), ==, "3.11.91");
+
/* check icons */
icons = as_app_get_icons (app);
g_assert (icons != NULL);