[gnome-software/wip/kalev/gnome-3-22: 6/96] Add gs_app_list_add_list()



commit 253533201667c0d60dbe876a2ab0eef1a45932d3
Author: Richard Hughes <richard hughsie com>
Date:   Fri Oct 21 14:12:37 2016 +0100

    Add gs_app_list_add_list()
    
    This allows us to add one GsAppList to another GsAppList.

 src/gs-app-list.c  |   26 ++++++++++++++++++++++++++
 src/gs-app-list.h  |    2 ++
 src/gs-self-test.c |   15 +++++++++++++++
 3 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-list.c b/src/gs-app-list.c
index f37b450..2a6d965 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -178,6 +178,32 @@ gs_app_list_remove (GsAppList *list, GsApp *app)
 }
 
 /**
+ * gs_app_list_add_list:
+ * @list: A #GsAppList
+ * @donor: Another #GsAppList
+ *
+ * Adds all the applications in @donor to @list.
+ *
+ * Since: 3.22
+ **/
+void
+gs_app_list_add_list (GsAppList *list, GsAppList *donor)
+{
+       guint i;
+       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_LIST (donor));
+       g_return_if_fail (list != donor);
+
+       /* add each app */
+       for (i = 0; i < donor->array->len; i++) {
+               GsApp *app = gs_app_list_index (donor, i);
+               gs_app_list_add_safe (list, app);
+       }
+}
+
+/**
  * gs_app_list_index:
  * @list: A #GsAppList
  * @idx: An index into the list
diff --git a/src/gs-app-list.h b/src/gs-app-list.h
index 0ae5451..a87b372 100644
--- a/src/gs-app-list.h
+++ b/src/gs-app-list.h
@@ -35,6 +35,8 @@ G_DECLARE_FINAL_TYPE (GsAppList, gs_app_list, GS, APP_LIST, GObject)
 GsAppList      *gs_app_list_new                (void);
 void            gs_app_list_add                (GsAppList      *list,
                                                 GsApp          *app);
+void            gs_app_list_add_list           (GsAppList      *list,
+                                                GsAppList      *donor);
 GsApp          *gs_app_list_index              (GsAppList      *list,
                                                 guint           idx);
 GsApp          *gs_app_list_lookup             (GsAppList      *list,
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 902a2ed..1898052 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -272,6 +272,21 @@ gs_plugin_func (void)
        g_assert_cmpint (gs_app_list_length (list), ==, 2);
        g_object_unref (list);
 
+       /* add a list to a list */
+       list = gs_app_list_new ();
+       list_dup = gs_app_list_new ();
+       app = gs_app_new ("a");
+       gs_app_list_add (list, app);
+       g_object_unref (app);
+       app = gs_app_new ("b");
+       gs_app_list_add (list_dup, app);
+       g_object_unref (app);
+       gs_app_list_add_list (list, list_dup);
+       g_assert_cmpint (gs_app_list_length (list), ==, 2);
+       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");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]