[gnome-software/wip/hughsie/unique-id-hash] Add gs_app_list_lookup()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/unique-id-hash] Add gs_app_list_lookup()
- Date: Thu, 25 Aug 2016 17:51:10 +0000 (UTC)
commit 6e3ccb268c800321e568677ea06e4e68526338ba
Author: Richard Hughes <richard hughsie com>
Date: Thu Aug 25 17:42:11 2016 +0100
Add gs_app_list_lookup()
This allows us to access apps in the store using a wildcarded unique-id.
src/gs-app-list.c | 18 ++++++++++++++++++
src/gs-app-list.h | 2 ++
src/gs-self-test.c | 12 ++++++++++++
3 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index 0758e1f..114e14b 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -46,6 +46,24 @@ struct _GsAppList
G_DEFINE_TYPE (GsAppList, gs_app_list, G_TYPE_OBJECT)
/**
+ * gs_app_list_lookup:
+ * @list: A #GsAppList
+ * @unique_id: A unique_id
+ *
+ * Finds the first matching application in the list using the usual wildcard
+ * rules allowed in unique_ids.
+ *
+ * Returns: (transfer none): a #GsApp, or %NULL if not found
+ *
+ * Since: 3.22
+ **/
+GsApp *
+gs_app_list_lookup (GsAppList *list, const gchar *unique_id)
+{
+ return g_hash_table_lookup (list->hash_by_id, unique_id);
+}
+
+/**
* gs_app_list_add:
* @list: A #GsAppList
* @app: A #GsApp
diff --git a/src/gs-app-list.h b/src/gs-app-list.h
index 2897430..0ae5451 100644
--- a/src/gs-app-list.h
+++ b/src/gs-app-list.h
@@ -37,6 +37,8 @@ void gs_app_list_add (GsAppList *list,
GsApp *app);
GsApp *gs_app_list_index (GsAppList *list,
guint idx);
+GsApp *gs_app_list_lookup (GsAppList *list,
+ const gchar *unique_id);
guint gs_app_list_length (GsAppList *list);
G_END_DECLS
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 70c27bc..cec0caa 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -188,6 +188,18 @@ gs_plugin_func (void)
g_assert_cmpint (gs_app_list_length (list), ==, 1);
g_assert_cmpstr (gs_app_get_id (gs_app_list_index (list, 0)), ==, "b");
g_object_unref (list);
+
+ /* lookup with a wildcard */
+ list = gs_app_list_new ();
+ app = gs_app_new ("b");
+ gs_app_set_unique_id (app, "a/b/c/d/e/f");
+ gs_app_list_add (list, app);
+ g_object_unref (app);
+ g_assert (gs_app_list_lookup (list, "a/b/c/d/e/f") != NULL);
+ g_assert (gs_app_list_lookup (list, "a/b/c/d/e/*") != NULL);
+ g_assert (gs_app_list_lookup (list, "*/b/c/d/e/f") != NULL);
+ g_assert (gs_app_list_lookup (list, "x/x/x/x/x/x") == NULL);
+ g_object_unref (list);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]