[gnome-software] Add gs_app_list_add_list()



commit 486187a30f9c38e90152d444b71e9aeba6def0bc
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 d66bc14..f2d62f1 100644
--- a/src/gs-app-list.c
+++ b/src/gs-app-list.c
@@ -146,6 +146,32 @@ gs_app_list_add (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.24
+ **/
+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 07d717b..4ecadfb 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -276,6 +276,21 @@ gs_plugin_func (void)
        g_object_unref (app);
        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);
 }
 
 static void


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