[gnome-software/gnome-3-26] plugin-loader: Allow the whole generic updates operation to be cancelled
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-26] plugin-loader: Allow the whole generic updates operation to be cancelled
- Date: Thu, 2 Nov 2017 20:16:44 +0000 (UTC)
commit 820b2012ae514af86d623a53fe852f69fe9101d1
Author: Joaquim Rocha <jrocha endlessm com>
Date: Tue Oct 10 13:44:29 2017 +0200
plugin-loader: Allow the whole generic updates operation to be cancelled
This patch makes use of the generic cancellable object passed to the
function that performs the generic updates and cancels the whole
operation.
This functionality is not reflected in the UI yet but we should have a
button for aborting the "update all" operation. And when that happens we
simply need it to cancel the cancellable object mentioned above.
lib/gs-plugin-loader.c | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 47f7c14..8feb9cb 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2967,6 +2967,13 @@ _gs_app_get_icon_by_kind (GsApp *app, AsIconKind kind)
return NULL;
}
+static void
+generic_update_cancelled_cb (GCancellable *cancellable, gpointer data)
+{
+ GCancellable *app_cancellable = G_CANCELLABLE (data);
+ g_cancellable_cancel (app_cancellable);
+}
+
static gboolean
gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
GsPluginLoaderHelper *helper,
@@ -2974,6 +2981,7 @@ gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
GError **error)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+ guint cancel_handler_id = 0;
GsAppList *list;
/* run each plugin, per-app version */
@@ -2991,11 +2999,23 @@ gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
/* for each app */
for (guint j = 0; j < gs_app_list_length (list); j++) {
+ GCancellable *app_cancellable;
GsApp *app = gs_app_list_index (list, j);
gboolean ret;
g_autoptr(AsProfileTask) ptask = NULL;
g_autoptr(GError) error_local = NULL;
+ /* if the whole operation should be cancelled */
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return FALSE;
+
+ /* make sure that the app update is cancelled when the whole op is cancelled */
+ app_cancellable = gs_app_get_cancellable (app);
+ cancel_handler_id = g_cancellable_connect (cancellable,
+ G_CALLBACK (generic_update_cancelled_cb),
+ g_object_ref (app_cancellable),
+ g_object_unref);
+
gs_plugin_job_set_app (helper->plugin_job, app);
ptask = as_profile_start (priv->profile,
"GsPlugin::%s(%s){%s}",
@@ -3004,8 +3024,10 @@ gs_plugin_loader_generic_update (GsPluginLoader *plugin_loader,
gs_app_get_id (app));
g_assert (ptask != NULL);
gs_plugin_loader_action_start (plugin_loader, plugin, FALSE);
- ret = plugin_app_func (plugin, app, gs_app_get_cancellable (app), &error_local);
+ ret = plugin_app_func (plugin, app, app_cancellable, &error_local);
gs_plugin_loader_action_stop (plugin_loader, plugin);
+ g_cancellable_disconnect (cancellable, cancel_handler_id);
+
if (!ret) {
if (!gs_plugin_error_handle_failure (helper,
plugin,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]