[gnome-software/gnome-3-22] trivial: Add gs_app_list_remove()



commit d0c886d7bae797c6cc1f1388bbfae484b3f143dc
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 31 14:40:56 2016 +0000

    trivial: Add gs_app_list_remove()
    
    (cherry picked from commit 42cdbed61b754fa4f8931616ec07f4327b02a491)

 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 7447c5c..231430e 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_index:
  * @list: A #GsAppList
  * @idx: An index into the list
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index af7aa3a..5ca9017 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -262,6 +262,17 @@ gs_plugin_func (void)
        g_object_unref (app);
        g_assert_cmpint (gs_app_list_length (list), ==, 2);
        g_object_unref (list);
+
+       /* 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]