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



commit 1015a98f2e141a98296eb570d68b4d9875cc0d41
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-shell-details.c |   29 ++++++++++++++++++-----------
 src/gs-shell-updates.c |   10 +++++-----
 2 files changed, 23 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 9ff5eec..0730d81 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -56,6 +56,7 @@ struct _GsShellDetails
        GsPluginLoader          *plugin_loader;
        GtkBuilder              *builder;
        GCancellable            *cancellable;
+       GCancellable            *app_cancellable;
        GsApp                   *app;
        GsShell                 *shell;
        SoupSession             *session;
@@ -391,7 +392,7 @@ gs_shell_details_refresh_progress (GsShellDetails *self)
        case AS_APP_STATE_INSTALLING:
                gtk_widget_set_visible (self->button_cancel, TRUE);
                gtk_widget_set_sensitive (self->button_cancel,
-                                         !g_cancellable_is_cancelled (self->cancellable));
+                                         !g_cancellable_is_cancelled (self->app_cancellable));
                break;
        default:
                gtk_widget_set_visible (self->button_cancel, FALSE);
@@ -1439,6 +1440,8 @@ gs_shell_details_file_to_app_cb (GObject *source,
        gs_shell_details_refresh_all (self);
        gs_shell_details_set_state (self, GS_SHELL_DETAILS_STATE_READY);
 
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
+
        /* do 2nd stage refine */
        gs_shell_details_app_refine2 (self);
 }
@@ -1543,6 +1546,9 @@ gs_shell_details_set_app (GsShellDetails *self, GsApp *app)
        g_signal_connect_object (self->app, "notify::progress",
                                 G_CALLBACK (gs_shell_details_progress_changed_cb),
                                 self, 0);
+
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
+
        gs_shell_details_load (self);
 
        /* change widgets */
@@ -1562,15 +1568,14 @@ gs_shell_details_get_app (GsShellDetails *self)
 static void
 gs_shell_details_app_remove_button_cb (GtkWidget *widget, GsShellDetails *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_shell_details_app_cancel_button_cb (GtkWidget *widget, GsShellDetails *self)
 {
-       g_cancellable_cancel (self->cancellable);
+       g_cancellable_cancel (self->app_cancellable);
        gtk_widget_set_sensitive (widget, FALSE);
 }
 
@@ -1579,7 +1584,6 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *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));
@@ -1592,14 +1596,14 @@ gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *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, self->cancellable);
+       gs_page_install_app (GS_PAGE (self), self->app, self->app_cancellable);
 }
 
 static void
@@ -1619,9 +1623,11 @@ gs_shell_details_addon_selected_cb (GsAppAddonRow *row,
        case AS_APP_STATE_UPDATABLE:
        case AS_APP_STATE_UPDATABLE_LIVE:
                if (gs_app_addon_row_get_selected (row)) {
-                       gs_page_install_app (GS_PAGE (self), addon, self->cancellable);
+                       g_set_object (&self->app_cancellable, gs_app_get_cancellable (addon));
+                       gs_page_install_app (GS_PAGE (self), addon, 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_shell_details_refresh_addons (self);
@@ -1962,6 +1968,7 @@ gs_shell_details_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_shell_details_parent_class)->dispose (object);
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index d586914..47ba017 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -685,11 +685,9 @@ gs_shell_updates_button_clicked_cb (GsUpdateList *update_list,
                                    GsApp *app,
                                    GsShellUpdates *self)
 {
-       g_autoptr(GCancellable) cancellable = g_cancellable_new ();
        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
@@ -901,6 +899,7 @@ gs_shell_updates_reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer
        GsShellUpdates *self = GS_SHELL_UPDATES (user_data);
        g_autoptr(GError) error = NULL;
        g_autoptr(GsAppList) apps = NULL;
+       GsApp *app = NULL;
        g_autoptr(GVariant) retval = NULL;
 
        /* get result */
@@ -915,10 +914,11 @@ gs_shell_updates_reboot_failed_cb (GObject *source, GAsyncResult *res, gpointer
 
        /* cancel trigger */
        apps = gs_update_list_get_apps (GS_UPDATE_LIST (self->list_box_updates));
+       app = gs_app_list_index (apps, 0);
        gs_plugin_loader_app_action_async (self->plugin_loader,
-                                          gs_app_list_index (apps, 0),
+                                          app,
                                           GS_PLUGIN_ACTION_UPDATE_CANCEL,
-                                          self->cancellable,
+                                          gs_app_get_cancellable (app),
                                           cancel_trigger_failed_cb,
                                           self);
 }


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