[gnome-software/gnome-3-26] Allow to cancel app ops in the details view that were started elsewhere



commit bc42c7209b95bffd9bbec3b8bc65c23979605431
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Tue Oct 10 12:26:20 2017 +0200

    Allow to cancel app ops in the details view that were started elsewhere
    
    The cancellation of app related operations has been tied to each view
    individually. E.g. if an app update is started from the updates page and
    the user goes to that app's details page, even though there is a cancel
    button showing, it won't do anything because it's cancellable object is
    not the one with which the update operation was started.
    
    Now that each app has a cancellable object, this patch makes use of that
    to ensure that any operations related to the app are cancellable even if
    they were started from a different page.

 src/gs-details-page.c |   29 ++++++++++++++++++-----------
 src/gs-updates-page.c |   10 +++++-----
 2 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 25a26e5..eae2d01 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -57,6 +57,7 @@ struct _GsDetailsPage
        GsPluginLoader          *plugin_loader;
        GtkBuilder              *builder;
        GCancellable            *cancellable;
+       GCancellable            *app_cancellable;
        GsApp                   *app;
        GsShell                 *shell;
        SoupSession             *session;
@@ -418,7 +419,7 @@ gs_details_page_refresh_progress (GsDetailsPage *self)
                 *    package manager has already gone 'too far'
                 */
                gtk_widget_set_sensitive (self->button_cancel,
-                                         !g_cancellable_is_cancelled (self->cancellable) &&
+                                         !g_cancellable_is_cancelled (self->app_cancellable) &&
                                           gs_app_get_allow_cancel (self->app));
                break;
        default:
@@ -1558,6 +1559,8 @@ set_app (GsDetailsPage *self, GsApp *app)
        gs_details_page_refresh_content_rating (self);
        gs_details_page_set_state (self, GS_DETAILS_PAGE_STATE_READY);
 
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (app));
+
        /* do 2nd stage refine */
        gs_details_page_app_refine2 (self);
 }
@@ -1753,6 +1756,9 @@ gs_details_page_set_app (GsDetailsPage *self, GsApp *app)
        g_signal_connect_object (self->app, "notify::allow-cancel",
                                 G_CALLBACK (gs_details_page_allow_cancel_changed_cb),
                                 self, 0);
+
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
+
        gs_details_page_load (self);
 
        /* change widgets */
@@ -1772,15 +1778,14 @@ gs_details_page_get_app (GsDetailsPage *self)
 static void
 gs_details_page_app_remove_button_cb (GtkWidget *widget, GsDetailsPage *self)
 {
-       g_autoptr(GCancellable) cancellable = g_cancellable_new ();
-       g_set_object (&self->cancellable, cancellable);
-       gs_page_remove_app (GS_PAGE (self), self->app, self->cancellable);
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
+       gs_page_remove_app (GS_PAGE (self), self->app, self->app_cancellable);
 }
 
 static void
 gs_details_page_app_cancel_button_cb (GtkWidget *widget, GsDetailsPage *self)
 {
-       g_cancellable_cancel (self->cancellable);
+       g_cancellable_cancel (self->app_cancellable);
        gtk_widget_set_sensitive (widget, FALSE);
 }
 
@@ -1789,7 +1794,6 @@ gs_details_page_app_install_button_cb (GtkWidget *widget, GsDetailsPage *self)
 {
        GList *l;
        g_autoptr(GList) addons = NULL;
-       g_autoptr(GCancellable) cancellable = g_cancellable_new ();
 
        /* Mark ticked addons to be installed together with the app */
        addons = gtk_container_get_children (GTK_CONTAINER (self->list_box_addons));
@@ -1802,15 +1806,15 @@ gs_details_page_app_install_button_cb (GtkWidget *widget, GsDetailsPage *self)
                }
        }
 
-       g_set_object (&self->cancellable, cancellable);
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
 
        if (gs_app_get_state (self->app) == AS_APP_STATE_UPDATABLE_LIVE) {
-               gs_page_update_app (GS_PAGE (self), self->app, self->cancellable);
+               gs_page_update_app (GS_PAGE (self), self->app, self->app_cancellable);
                return;
        }
 
        gs_page_install_app (GS_PAGE (self), self->app, GS_SHELL_INTERACTION_FULL,
-                            self->cancellable);
+                            self->app_cancellable);
 }
 
 static void
@@ -1830,10 +1834,12 @@ gs_details_page_addon_selected_cb (GsAppAddonRow *row,
        case AS_APP_STATE_UPDATABLE:
        case AS_APP_STATE_UPDATABLE_LIVE:
                if (gs_app_addon_row_get_selected (row)) {
+                       g_set_object (&self->app_cancellable, gs_app_get_cancellable (addon));
                        gs_page_install_app (GS_PAGE (self), addon, GS_SHELL_INTERACTION_FULL,
-                                            self->cancellable);
+                                            self->app_cancellable);
                } else {
-                       gs_page_remove_app (GS_PAGE (self), addon, self->cancellable);
+                       g_set_object (&self->app_cancellable, gs_app_get_cancellable (addon));
+                       gs_page_remove_app (GS_PAGE (self), addon, self->app_cancellable);
                        /* make sure the addon checkboxes are synced if the
                         * user clicks cancel in the remove confirmation dialog */
                        gs_details_page_refresh_addons (self);
@@ -2267,6 +2273,7 @@ gs_details_page_dispose (GObject *object)
        g_clear_object (&self->builder);
        g_clear_object (&self->plugin_loader);
        g_clear_object (&self->cancellable);
+       g_clear_object (&self->app_cancellable);
        g_clear_object (&self->session);
 
        G_OBJECT_CLASS (gs_details_page_parent_class)->dispose (object);
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index d82a653..e1c2bb8 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -608,6 +608,7 @@ _reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
        GsUpdatesPage *self = GS_UPDATES_PAGE (user_data);
        g_autoptr(GError) error = NULL;
        g_autoptr(GsAppList) apps = NULL;
+       GsApp *app = NULL;
        g_autoptr(GsPluginJob) plugin_job = NULL;
        g_autoptr(GVariant) retval = NULL;
 
@@ -623,12 +624,13 @@ _reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer user_data)
 
        /* cancel trigger */
        apps = _get_all_apps (self);
+       app = gs_app_list_index (apps, 0);
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_UPDATE_CANCEL,
-                                        "app", gs_app_list_index (apps, 0),
+                                        "app", app,
                                         "failure-flags", GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
                                         NULL);
        gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
-                                           self->cancellable,
+                                           gs_app_get_cancellable (app),
                                            _cancel_trigger_failed_cb,
                                            self);
 }
@@ -902,12 +904,10 @@ _create_listbox_section (GsUpdatesPage *self, GsUpdatePageSection sect)
 static void
 _app_row_button_clicked_cb (GsAppRow *app_row, GsUpdatesPage *self)
 {
-       g_autoptr(GCancellable) cancellable = g_cancellable_new ();
        GsApp *app = gs_app_row_get_app (app_row);
        if (gs_app_get_state (app) != AS_APP_STATE_UPDATABLE_LIVE)
                return;
-       g_set_object (&self->cancellable, cancellable);
-       gs_page_update_app (GS_PAGE (self), app, self->cancellable);
+       gs_page_update_app (GS_PAGE (self), app, gs_app_get_cancellable (app));
 }
 
 static void


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