[gnome-software/gnome-3-24] Add a cancellable to GsApp objects



commit d79201b7de97fb1ed19c74ac70a3d079fc416184
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.

 lib/gs-app-private.h |    1 +
 lib/gs-app.c         |   29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/lib/gs-app-private.h b/lib/gs-app-private.h
index 982ac5c..7c98d56 100644
--- a/lib/gs-app-private.h
+++ b/lib/gs-app-private.h
@@ -33,6 +33,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/lib/gs-app.c b/lib/gs-app.c
index a7a0d78..02e3f73 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -123,6 +123,7 @@ struct _GsApp
        GFile                   *local_file;
        AsContentRating         *content_rating;
        GdkPixbuf               *pixbuf;
+       GCancellable            *cancellable;
 };
 
 enum {
@@ -3522,6 +3523,33 @@ gs_app_get_priority (GsApp *app)
        return app->priority;
 }
 
+/**
+ * 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)
 {
@@ -3671,6 +3699,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->local_file != NULL)


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