[gnome-software/gnome-3-30] updates section: Update apps in display order



commit c1d32d9bbcf137c1c66d7df31f36f41425dfa400
Author: Kalev Lember <klember redhat com>
Date:   Fri Oct 5 13:07:27 2018 +0200

    updates section: Update apps in display order
    
    When passing the list of apps to update to the plugin loader, pass them
    in the same order as they are displayed. This makes it look much nicer
    when clicking on "Update All": instead of updating a random app down
    below, they now get updated in order (or at least mostly, dependant
    runtimes are still out of order).

 src/gs-updates-section.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index f5f701dd..ef8314d9 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -324,6 +324,21 @@ _button_cancel_clicked_cb (GtkButton *button, GsUpdatesSection *self)
        _update_buttons (self);
 }
 
+static GsAppList *
+_get_listbox_apps (GsUpdatesSection *self)
+{
+       g_autoptr(GsAppList) apps = gs_app_list_new ();
+       g_autoptr(GList) listbox_children = NULL;
+
+       listbox_children = gtk_container_get_children (GTK_CONTAINER (self));
+       for (GList *l = listbox_children; l; l = l->next) {
+               GsAppRow *app_row = GS_APP_ROW (l->data);
+               gs_app_list_add (apps, gs_app_row_get_app (app_row));
+       }
+
+       return g_steal_pointer (&apps);
+}
+
 static void
 _button_update_all_clicked_cb (GtkButton *button, GsUpdatesSection *self)
 {
@@ -331,12 +346,17 @@ _button_update_all_clicked_cb (GtkButton *button, GsUpdatesSection *self)
        g_autoptr(GCancellable) cancellable = g_cancellable_new ();
        g_autoptr(GsPluginJob) plugin_job = NULL;
        GsUpdatesSectionUpdateHelper *helper = g_new0 (GsUpdatesSectionUpdateHelper, 1);
+       g_autoptr(GsAppList) sorted_list = NULL;
+
+       /* instead of using self->list, get the already-sorted apps back from
+        * the listbox to be able to update them in display order */
+       sorted_list = _get_listbox_apps (self);
 
        helper->self = g_object_ref (self);
 
        /* look at each app in turn */
-       for (guint i = 0; i < gs_app_list_length (self->list); i++) {
-               GsApp *app = gs_app_list_index (self->list, i);
+       for (guint i = 0; i < gs_app_list_length (sorted_list); i++) {
+               GsApp *app = gs_app_list_index (sorted_list, i);
                if (gs_app_get_state (app) == AS_APP_STATE_UPDATABLE)
                        helper->do_reboot = TRUE;
                if (gs_app_has_quirk (app, AS_APP_QUIRK_NEEDS_REBOOT))
@@ -345,7 +365,7 @@ _button_update_all_clicked_cb (GtkButton *button, GsUpdatesSection *self)
 
        g_set_object (&self->cancellable, cancellable);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_UPDATE,
-                                        "list", self->list,
+                                        "list", sorted_list,
                                         "interactive", TRUE,
                                         NULL);
        gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,


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