[gnome-software/gnome-3-22] Add a cancellable to GsApp objects
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-22] Add a cancellable to GsApp objects
- Date: Thu, 2 Nov 2017 22:20:49 +0000 (UTC)
commit 29e842a9db55f7e3e8846b70727f76e5b36822d1
Author: Joaquim Rocha <jrocha endlessm com>
Date: Tue Oct 10 12:21:55 2017 +0200
Add a cancellable to GsApp objects
This cancellable should be used in operations related to the app, e.g.
installing, updating, etc. This is convenient because sometimes an
operation will be shown in different views, so we cannot use a local
cancellable, as it will be impossible to start the operation in one view
and cancel it in another.
src/gs-app-private.h | 1 +
src/gs-app.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app-private.h b/src/gs-app-private.h
index 608c420..a8b4650 100644
--- a/src/gs-app-private.h
+++ b/src/gs-app-private.h
@@ -36,6 +36,7 @@ void gs_app_set_unique_id (GsApp *app,
const gchar *unique_id);
void gs_app_remove_addon (GsApp *app,
GsApp *addon);
+GCancellable *gs_app_get_cancellable (GsApp *app);
G_END_DECLS
diff --git a/src/gs-app.c b/src/gs-app.c
index 03845ba..ad8857b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -122,6 +122,7 @@ struct _GsApp
GsApp *runtime;
GFile *local_file;
GdkPixbuf *pixbuf;
+ GCancellable *cancellable;
};
enum {
@@ -3448,6 +3449,33 @@ gs_app_set_last_error (GsApp *app, GError *error)
app->last_error = g_error_copy (error);
}
+/**
+ * gs_app_get_cancellable:
+ * @app: a #GsApp
+ *
+ * Get a cancellable to be used with operations related to the #GsApp. This is a
+ * way for views to be able to cancel an on-going operation. If the #GCancellable
+ * is canceled, it will be unreferenced and renewed before returning it, i.e. the
+ * cancellable object will always be ready to use for new operations. So be sure
+ * to keep a reference to it if you do more than just passing the cancellable to
+ * a process.
+ *
+ * Returns: a #GCancellable
+ *
+ * Since: 3.28
+ **/
+GCancellable *
+gs_app_get_cancellable (GsApp *app)
+{
+ g_autoptr(GCancellable) cancellable = NULL;
+
+ if (app->cancellable == NULL || g_cancellable_is_cancelled (app->cancellable)) {
+ cancellable = g_cancellable_new ();
+ g_set_object (&app->cancellable, cancellable);
+ }
+ return app->cancellable;
+}
+
static void
gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
@@ -3596,6 +3624,7 @@ gs_app_finalize (GObject *object)
g_hash_table_unref (app->related_hash);
g_ptr_array_unref (app->categories);
g_ptr_array_unref (app->key_colors);
+ g_clear_object (&app->cancellable);
if (app->keywords != NULL)
g_ptr_array_unref (app->keywords);
if (app->last_error != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]