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




commit bbfabd492261a8bb787a3c7c874f564f839dbdee
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 | 24 +++++++++++++++---------
 lib/gs-app-list.h |  2 +-
 2 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/lib/gs-app-list.c b/lib/gs-app-list.c
index 1934699e5..12ad55f3d 100644
--- a/lib/gs-app-list.c
+++ b/lib/gs-app-list.c
@@ -475,23 +475,29 @@ gs_app_list_add (GsAppList *list, GsApp *app)
  * Removes an application from the list. If the application does not exist the
  * request is ignored.
  *
- * Since: 3.22
+ * Returns: %TRUE if the app was removed, %FALSE if it did not exist in the @list
+ * Since: 43
  **/
-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]