[gnome-software/1744-software-remembers-past-install-intent] gs-app-list: Let the gs_app_list_remove() return whether it deleted anything



commit 0c86e28d3ff8965a1d34ffaff1b357fbe762b8fd
Author: Milan Crha <mcrha redhat com>
Date:   Tue May 17 14:30:02 2022 +0200

    gs-app-list: Let the gs_app_list_remove() return whether it deleted anything
    
    This can be used by the caller to decide what to do when the app
    was or was not removed from the list.

 lib/gs-app-list.c | 21 +++++++++++++--------
 lib/gs-app-list.h |  2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index c10b04552..6da2a25ec 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -477,21 +477,26 @@ gs_app_list_add (GsAppList *list, GsApp *app)
  *
  * Since: 3.22
  **/
-void
+gboolean
 gs_app_list_remove (GsAppList *list, GsApp *app)
 {
        g_autoptr(GMutexLocker) locker = NULL;
+       gboolean removed;
 
-       g_return_if_fail (GS_IS_APP_LIST (list));
-       g_return_if_fail (GS_IS_APP (app));
+       g_return_val_if_fail (GS_IS_APP_LIST (list), FALSE);
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
 
        locker = g_mutex_locker_new (&list->mutex);
-       g_ptr_array_remove (list->array, app);
-       gs_app_list_maybe_unwatch_app (list, app);
+       removed = g_ptr_array_remove (list->array, app);
+       if (removed) {
+               gs_app_list_maybe_unwatch_app (list, app);
 
-       /* recalculate global state */
-       gs_app_list_invalidate_state (list);
-       gs_app_list_invalidate_progress (list);
+               /* recalculate global state */
+               gs_app_list_invalidate_state (list);
+               gs_app_list_invalidate_progress (list);
+       }
+
+       return removed;
 }
 
 /**
diff --git a/lib/gs-app-list.h b/lib/gs-app-list.h
index 233e2689f..adf85f7c9 100644
--- a/lib/gs-app-list.h
+++ b/lib/gs-app-list.h
@@ -70,7 +70,7 @@ void           gs_app_list_add                (GsAppList      *list,
                                                 GsApp          *app);
 void            gs_app_list_add_list           (GsAppList      *list,
                                                 GsAppList      *donor);
-void            gs_app_list_remove             (GsAppList      *list,
+gboolean        gs_app_list_remove             (GsAppList      *list,
                                                 GsApp          *app);
 GsApp          *gs_app_list_index              (GsAppList      *list,
                                                 guint           idx);


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