[gnome-software] plugin-loader: Allow the whole generic updates operation to be cancelled
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] plugin-loader: Allow the whole generic updates operation to be cancelled
- Date: Thu, 2 Nov 2017 10:56:54 +0000 (UTC)
commit ec11d6598527690839b882c511306b3e79f480e3
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 49ff93e..0bc9e37 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2989,6 +2989,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,
@@ -2996,6 +3003,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 */
@@ -3013,11 +3021,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}",
@@ -3026,8 +3046,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]