summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2018-04-16 16:04:53 +0100
committerRichard Hughes <richard@hughsie.com>2018-04-18 18:25:46 +0100
commit7bcba4d2f90c3b02882277739d46af6bd7146a11 (patch)
treeb2e4c7a5c06ed70b6da50154cba00c36c73f2b7f
parent5a7d76de734b049192b5b992a1e54117b98de733 (diff)
downloadappstream-glib-7bcba4d2f90c3b02882277739d46af6bd7146a11.tar.gz
Add as_store_get_app_by_launchable()
-rw-r--r--libappstream-glib/as-store.c37
-rw-r--r--libappstream-glib/as-store.h3
2 files changed, 40 insertions, 0 deletions
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
@@ -667,6 +667,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.
* @kind: the #AsProvideKind
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);