[gnome-software] Add a cancellable to GsApp objects



commit da83bd73a66f4f1efb45a2d2a7b348599832ad0c
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         |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 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 d943714..50a52c0 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -124,6 +124,7 @@ typedef struct
        AsContentRating         *content_rating;
        GdkPixbuf               *pixbuf;
        GsPrice                 *price;
+       GCancellable            *cancellable;
 } GsAppPrivate;
 
 enum {
@@ -3810,6 +3811,34 @@ gs_app_get_priority (GsApp *app)
        return priv->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;
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+
+       if (priv->cancellable == NULL || g_cancellable_is_cancelled (priv->cancellable)) {
+               cancellable = g_cancellable_new ();
+               g_set_object (&priv->cancellable, cancellable);
+       }
+       return priv->cancellable;
+}
+
 static void
 gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
@@ -3968,6 +3997,7 @@ gs_app_finalize (GObject *object)
        g_hash_table_unref (priv->related_hash);
        g_ptr_array_unref (priv->categories);
        g_ptr_array_unref (priv->key_colors);
+       g_clear_object (&priv->cancellable);
        if (priv->keywords != NULL)
                g_ptr_array_unref (priv->keywords);
        if (priv->local_file != NULL)


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