From 7bcba4d2f90c3b02882277739d46af6bd7146a11 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 16 Apr 2018 16:04:53 +0100 Subject: Add as_store_get_app_by_launchable() --- libappstream-glib/as-store.c | 37 +++++++++++++++++++++++++++++++++++++ libappstream-glib/as-store.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 8ce7e5e..7d44fcd 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -666,6 +666,43 @@ as_store_get_app_by_provide (AsStore *store, AsProvideKind kind, const gchar *va } +/** + * as_store_get_app_by_launchable: + * @store: a #AsStore instance. + * @kind: the #AsLaunchableKind + * @value: the provide value, e.g. "gimp.desktop" + * + * Finds an application in the store that provides a specific launchable. + * + * Returns: (transfer none): a #AsApp or %NULL + * + * Since: 0.7.8 + **/ +AsApp * +as_store_get_app_by_launchable (AsStore *store, AsLaunchableKind kind, const gchar *value) +{ + AsStorePrivate *priv = GET_PRIVATE (store); + + g_return_val_if_fail (AS_IS_STORE (store), NULL); + g_return_val_if_fail (kind != AS_LAUNCHABLE_KIND_UNKNOWN, NULL); + g_return_val_if_fail (value != NULL, NULL); + + for (guint i = 0; i < priv->array->len; i++) { + AsApp *app = g_ptr_array_index (priv->array, i); + GPtrArray *launchables = as_app_get_launchables (app); + for (guint j = 0; j < launchables->len; j++) { + AsLaunchable *tmp = g_ptr_array_index (launchables, j); + if (kind != as_launchable_get_kind (tmp)) + continue; + if (g_strcmp0 (as_launchable_get_value (tmp), value) != 0) + continue; + return app; + } + } + return NULL; + +} + /** * as_store_get_apps_by_provide: * @store: a #AsStore instance. diff --git a/libappstream-glib/as-store.h b/libappstream-glib/as-store.h index dbe41a5..553b38d 100644 --- a/libappstream-glib/as-store.h +++ b/libappstream-glib/as-store.h @@ -214,6 +214,9 @@ AsApp *as_store_get_app_by_pkgnames (AsStore *store, AsApp *as_store_get_app_by_provide (AsStore *store, AsProvideKind kind, const gchar *value); +AsApp *as_store_get_app_by_launchable (AsStore *store, + AsLaunchableKind kind, + const gchar *value); GPtrArray *as_store_get_apps_by_provide (AsStore *store, AsProvideKind kind, const gchar *value); -- cgit v1.2.1