[gnome-software] Make offline update triggering work when online updates are available



commit 835e23b3258c0e7a660c300fa4278078b9f67376
Author: Kalev Lember <klember redhat com>
Date:   Thu Mar 23 17:39:57 2017 +0100

    Make offline update triggering work when online updates are available
    
    Depending on what kind of updates are available, the "Restart & Update"
    and "Update All" buttons can be either up in the header bar or down in a
    section header. The code paths that the button click handlers were
    taking were completely different: one triggered
    gs_plugin_loader_app_action_async (app, GS_PLUGIN_ACTION_UPDATE) with
    each updatable app, and the other one triggered
    gs_plugin_loader_update_async (apps) with all the apps.
    
    This commit rewires this so that we take the same backend path with
    either one, and also makes the offline updates triggering work again
    when the "Restart & Update" button is down in the section header.

 src/gs-update-list.c  |   38 +++++++++++++++++++++++++++-----------
 src/gs-update-list.h  |    2 ++
 src/gs-updates-page.c |   28 ++++++++++++++++++++++------
 3 files changed, 51 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-update-list.c b/src/gs-update-list.c
index 1a442a0..1e66d06 100644
--- a/src/gs-update-list.c
+++ b/src/gs-update-list.c
@@ -48,6 +48,7 @@ typedef struct
 
 enum {
        SIGNAL_BUTTON_CLICKED,
+       SIGNAL_UPDATE_ALL,
        SIGNAL_LAST
 };
 
@@ -166,44 +167,52 @@ gs_update_list_get_apps (GsUpdateList *update_list)
        return apps;
 }
 
-static void
-gs_update_list_emit_clicked_for_section (GsUpdateList *update_list,
-                                        GsUpdateListSection section)
+static GsAppList *
+gs_update_list_get_apps_for_section (GsUpdateList *update_list,
+                                     GsUpdateListSection section)
 {
+       GsAppList *apps;
+       GList *l;
        g_autoptr(GList) children = NULL;
+
+       apps = gs_app_list_new ();
        children = gtk_container_get_children (GTK_CONTAINER (update_list));
-       for (GList *l = children; l != NULL; l = l->next) {
+       for (l = children; l != NULL; l = l->next) {
                GsAppRow *app_row = GS_APP_ROW (l->data);
                GsApp *app = gs_app_row_get_app (app_row);
                if (gs_update_list_get_app_section (app) != section)
                        continue;
-               g_signal_emit (update_list, signals[SIGNAL_BUTTON_CLICKED], 0, app);
+               gs_app_list_add (apps, gs_app_row_get_app (app_row));
        }
+       return apps;
 }
 
 static void
 gs_update_list_update_offline_firmware_cb (GtkButton *button,
                                           GsUpdateList *update_list)
 {
+       g_autoptr(GsAppList) apps = gs_update_list_get_apps_for_section (update_list,
+                                                                        
GS_UPDATE_LIST_SECTION_OFFLINE_FIRMWARE);
        gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
-       gs_update_list_emit_clicked_for_section (update_list,
-                                                GS_UPDATE_LIST_SECTION_OFFLINE_FIRMWARE);
+       g_signal_emit (update_list, signals[SIGNAL_UPDATE_ALL], 0, apps);
 }
 
 static void
 gs_update_list_update_offline_cb (GtkButton *button, GsUpdateList *update_list)
 {
+       g_autoptr(GsAppList) apps = gs_update_list_get_apps_for_section (update_list,
+                                                                        GS_UPDATE_LIST_SECTION_OFFLINE);
        gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
-       gs_update_list_emit_clicked_for_section (update_list,
-                                                GS_UPDATE_LIST_SECTION_OFFLINE);
+       g_signal_emit (update_list, signals[SIGNAL_UPDATE_ALL], 0, apps);
 }
 
 static void
 gs_update_list_update_online_cb (GtkButton *button, GsUpdateList *update_list)
 {
+       g_autoptr(GsAppList) apps = gs_update_list_get_apps_for_section (update_list,
+                                                                        GS_UPDATE_LIST_SECTION_ONLINE);
        gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
-       gs_update_list_emit_clicked_for_section (update_list,
-                                                GS_UPDATE_LIST_SECTION_ONLINE);
+       g_signal_emit (update_list, signals[SIGNAL_UPDATE_ALL], 0, apps);
 }
 
 static GtkWidget *
@@ -424,6 +433,13 @@ gs_update_list_class_init (GsUpdateListClass *klass)
                              NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
                              G_TYPE_NONE, 1, GS_TYPE_APP);
 
+       signals [SIGNAL_UPDATE_ALL] =
+               g_signal_new ("update-all",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsUpdateListClass, update_all),
+                             NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
+                             G_TYPE_NONE, 1, GS_TYPE_APP_LIST);
+
        object_class->dispose = gs_update_list_dispose;
 }
 
diff --git a/src/gs-update-list.h b/src/gs-update-list.h
index f89af51..9da6a52 100644
--- a/src/gs-update-list.h
+++ b/src/gs-update-list.h
@@ -37,6 +37,8 @@ struct _GsUpdateListClass
        GtkListBoxClass          parent_class;
        void                    (*button_clicked)       (GsUpdateList   *update_list,
                                                         GsApp          *app);
+       void                    (*update_all)           (GsUpdateList   *update_list,
+                                                        GsAppList      *apps);
 };
 
 GtkWidget      *gs_update_list_new                     (void);
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index e9219bb..668c206 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -957,25 +957,39 @@ gs_updates_page_perform_update_cb (GsPluginLoader *plugin_loader,
 }
 
 static void
-gs_updates_page_button_update_all_cb (GtkButton     *button,
-                                      GsUpdatesPage *self)
+update_all (GsUpdatesPage *self, GsAppList *apps)
 {
        g_autoptr(GError) error = NULL;
-       g_autoptr(GsAppList) apps = NULL;
        g_autoptr(GCancellable) cancellable = g_cancellable_new ();
 
-       /* do the offline update */
        g_set_object (&self->cancellable, cancellable);
-       apps = gs_update_list_get_apps (GS_UPDATE_LIST (self->list_box_updates));
        gs_plugin_loader_update_async (self->plugin_loader,
                                       apps,
                                       GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
                                       self->cancellable,
                                       (GAsyncReadyCallback) gs_updates_page_perform_update_cb,
                                       self);
+}
+
+static void
+gs_updates_page_header_update_all_cb (GtkButton     *button,
+                                      GsUpdatesPage *self)
+{
+       g_autoptr(GsAppList) apps = NULL;
+
+       apps = gs_update_list_get_apps (GS_UPDATE_LIST (self->list_box_updates));
+       update_all (self, apps);
        gtk_widget_set_sensitive (GTK_WIDGET (self->button_update_all), FALSE);
 }
 
+static void
+gs_updates_page_update_all_cb (GsUpdateList *update_list,
+                               GsAppList *apps,
+                               GsUpdatesPage *self)
+{
+       update_all (self, apps);
+}
+
 typedef struct {
        GsApp           *app;
        GsUpdatesPage   *self;
@@ -1338,6 +1352,8 @@ gs_updates_page_setup (GsPage *page,
                          G_CALLBACK (gs_updates_page_activated_cb), self);
        g_signal_connect (self->list_box_updates, "button-clicked",
                          G_CALLBACK (gs_updates_page_button_clicked_cb), self);
+       g_signal_connect (self->list_box_updates, "update-all",
+                         G_CALLBACK (gs_updates_page_update_all_cb), self);
 
        /* setup system upgrades */
        g_signal_connect (self->upgrade_banner, "download-clicked",
@@ -1358,7 +1374,7 @@ gs_updates_page_setup (GsPage *page,
        gtk_widget_set_visible (self->button_update_all, TRUE);
        gtk_style_context_add_class (gtk_widget_get_style_context (self->button_update_all), 
"suggested-action");
        gtk_container_add (GTK_CONTAINER (self->header_end_box), self->button_update_all);
-       g_signal_connect (self->button_update_all, "clicked", G_CALLBACK 
(gs_updates_page_button_update_all_cb), self);
+       g_signal_connect (self->button_update_all, "clicked", G_CALLBACK 
(gs_updates_page_header_update_all_cb), self);
 
        self->header_start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
        gtk_widget_set_visible (self->header_start_box, TRUE);


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