[gnome-software] trivial: Add gs_app_list_remove()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add gs_app_list_remove()
- Date: Mon, 31 Oct 2016 16:50:52 +0000 (UTC)
commit 42cdbed61b754fa4f8931616ec07f4327b02a491
Author: Richard Hughes <richard hughsie com>
Date: Mon Oct 31 14:40:56 2016 +0000
trivial: Add gs_app_list_remove()
src/gs-app-list-private.h | 2 ++
src/gs-app-list.c | 29 +++++++++++++++++++++++++++++
src/gs-self-test.c | 11 +++++++++++
3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-list-private.h b/src/gs-app-list-private.h
index 96e0769..de4592e 100644
--- a/src/gs-app-list-private.h
+++ b/src/gs-app-list-private.h
@@ -56,6 +56,8 @@ void gs_app_list_sort (GsAppList *list,
void gs_app_list_filter_duplicates (GsAppList *list,
GsAppListFilterFlags flags);
void gs_app_list_randomize (GsAppList *list);
+void gs_app_list_remove (GsAppList *list,
+ GsApp *app);
void gs_app_list_remove_all (GsAppList *list);
G_END_DECLS
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index 43fd0f6..cf9b401 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -145,6 +145,35 @@ gs_app_list_add (GsAppList *list, GsApp *app)
}
/**
+ * gs_app_list_remove:
+ * @list: A #GsAppList
+ * @app: A #GsApp
+ *
+ * Removes an application from the list. If the application does not exist the
+ * request is ignored.
+ *
+ * Since: 3.24
+ **/
+void
+gs_app_list_remove (GsAppList *list, GsApp *app)
+{
+ AsApp *app_tmp;
+ const gchar *unique_id;
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&list->mutex);
+
+ g_return_if_fail (GS_IS_APP_LIST (list));
+ g_return_if_fail (GS_IS_APP (app));
+
+ /* remove, or ignore if not found */
+ unique_id = gs_app_get_unique_id (app);
+ app_tmp = g_hash_table_lookup (list->hash_by_id, unique_id);
+ if (app_tmp == NULL)
+ return;
+ g_ptr_array_remove (list->array, app_tmp);
+ g_hash_table_remove (list->hash_by_id, unique_id);
+}
+
+/**
* gs_app_list_add_list:
* @list: A #GsAppList
* @donor: Another #GsAppList
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 4ecadfb..2bec290 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -291,6 +291,17 @@ gs_plugin_func (void)
g_assert_cmpint (gs_app_list_length (list_dup), ==, 1);
g_object_unref (list);
g_object_unref (list_dup);
+
+ /* remove apps from the list */
+ list = gs_app_list_new ();
+ app = gs_app_new ("a");
+ gs_app_list_add (list, app);
+ g_object_unref (app);
+ app = gs_app_new ("a");
+ gs_app_list_remove (list, app);
+ g_object_unref (app);
+ g_assert_cmpint (gs_app_list_length (list), ==, 0);
+ g_object_unref (list);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]