summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-store.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-08-10 18:05:45 +0100
committerRichard Hughes <richard@hughsie.com>2015-08-10 18:06:11 +0100
commiteee40b238adf84b77ac4d2f4e1f585a291c4299d (patch)
treed726cddaca2fbbd343acf5d1ff1f5f1f53e85ec3 /libappstream-glib/as-store.c
parent93f1a4b5ab2e6d80d66027cd80edef4dabe45b24 (diff)
downloadappstream-glib-eee40b238adf84b77ac4d2f4e1f585a291c4299d.tar.gz
Find the application in a store by the provide value
Diffstat (limited to 'libappstream-glib/as-store.c')
-rw-r--r--libappstream-glib/as-store.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index d9949bc..b2d7f91 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -429,6 +429,49 @@ as_store_get_app_by_id (AsStore *store, const gchar *id)
}
/**
+ * as_store_get_app_by_provide:
+ * @store: a #AsStore instance.
+ * @kind: the #AsProvideKind
+ * @value: the provide value, e.g. "com.hughski.ColorHug2.firmware"
+ *
+ * Finds an application in the store by something that it provides.
+ *
+ * Returns: (transfer none): a #AsApp or %NULL
+ *
+ * Since: 0.5.0
+ **/
+AsApp *
+as_store_get_app_by_provide (AsStore *store, AsProvideKind kind, const gchar *value)
+{
+ AsApp *app;
+ AsProvide *tmp;
+ AsStorePrivate *priv = GET_PRIVATE (store);
+ guint i;
+ guint j;
+ GPtrArray *provides;
+
+ g_return_val_if_fail (AS_IS_STORE (store), NULL);
+ g_return_val_if_fail (kind != AS_PROVIDE_KIND_UNKNOWN, NULL);
+ g_return_val_if_fail (value != NULL, NULL);
+
+ /* find an application that provides something */
+ for (i = 0; i < priv->array->len; i++) {
+ app = g_ptr_array_index (priv->array, i);
+ provides = as_app_get_provides (app);
+ for (j = 0; j < provides->len; j++) {
+ tmp = g_ptr_array_index (provides, j);
+ if (kind != as_provide_get_kind (tmp))
+ continue;
+ if (g_strcmp0 (as_provide_get_value (tmp), value) != 0)
+ continue;
+ return app;
+ }
+ }
+ return NULL;
+
+}
+
+/**
* as_store_get_app_by_id_with_fallbacks:
* @store: a #AsStore instance.
* @id: the application full ID.