[gnome-software/1296-calculate-app-space-usage-for-download-context-tile: 37/43] gs-app: Add properties for user and cache data sizes




commit fcf793eb9a2d67728fd404e29f068868379f019e
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jul 28 18:47:42 2021 +0200

    gs-app: Add properties for user and cache data sizes
    
    Add members to store the information to.

 lib/gs-app.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gs-app.h |   6 +++
 2 files changed, 139 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 9a5a73ebc..c70676f4b 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -103,6 +103,8 @@ typedef struct
        GPtrArray               *provided; /* of AsProvided */
        guint64                  size_installed;
        guint64                  size_download;
+       guint64                  size_user_data;
+       guint64                  size_cache_data;
        AsComponentKind          kind;
        GsAppSpecialKind         special_kind;
        GsAppState               state;
@@ -154,8 +156,10 @@ typedef enum {
        PROP_URL_MISSING,
        PROP_CONTENT_RATING,
        PROP_LICENSE,
+       PROP_SIZE_CACHE_DATA,
        PROP_SIZE_DOWNLOAD,
        PROP_SIZE_INSTALLED,
+       PROP_SIZE_USER_DATA,
        PROP_PERMISSIONS,
        PROP_RELATIONS,
 } GsAppProperty;
@@ -676,6 +680,11 @@ gs_app_to_string_append (GsApp *app, GString *str)
                gs_app_kv_size (str, "size-installed", priv->size_installed);
        if (priv->size_download != 0)
                gs_app_kv_size (str, "size-download", gs_app_get_size_download (app));
+       if (priv->size_cache_data != GS_APP_SIZE_UNKNOWABLE)
+               gs_app_kv_size (str, "size-cache-data", gs_app_get_size_cache_data (app));
+       if (priv->size_user_data != GS_APP_SIZE_UNKNOWABLE)
+               gs_app_kv_size (str, "size-user-data", gs_app_get_size_user_data (app));
+
        for (i = 0; i < gs_app_list_length (priv->related); i++) {
                GsApp *app_tmp = gs_app_list_index (priv->related, i);
                const gchar *id = gs_app_get_unique_id (app_tmp);
@@ -3524,6 +3533,88 @@ gs_app_set_size_installed (GsApp *app, guint64 size_installed)
        gs_app_queue_notify (app, obj_props[PROP_SIZE_INSTALLED]);
 }
 
+/**
+ * gs_app_get_size_user_data:
+ * @app: A #GsApp
+ *
+ * Get the value of #GsApp:size-user-data.
+ *
+ * Returns: number of bytes, or %GS_APP_SIZE_UNKNOWABLE for unknown
+ *
+ * Since: 41
+ **/
+guint64
+gs_app_get_size_user_data (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+
+       g_return_val_if_fail (GS_IS_APP (app), GS_APP_SIZE_UNKNOWABLE);
+
+       return priv->size_user_data;
+}
+
+/**
+ * gs_app_set_size_user_data:
+ * @app: a #GsApp
+ * @size_user_data: size in bytes, or %GS_APP_SIZE_UNKNOWABLE for unknown
+ *
+ * Sets the user data size of the @app.
+ *
+ * Since: 41
+ **/
+void
+gs_app_set_size_user_data (GsApp *app,
+                          guint64 size_user_data)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_if_fail (GS_IS_APP (app));
+       if (size_user_data == priv->size_user_data)
+               return;
+       priv->size_user_data = size_user_data;
+       gs_app_queue_notify (app, obj_props[PROP_SIZE_USER_DATA]);
+}
+
+/**
+ * gs_app_get_size_cache_data:
+ * @app: A #GsApp
+ *
+ * Get the value of #GsApp:size-cache-data.
+ *
+ * Returns: number of bytes, or %GS_APP_SIZE_UNKNOWABLE for unknown
+ *
+ * Since: 41
+ **/
+guint64
+gs_app_get_size_cache_data (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+
+       g_return_val_if_fail (GS_IS_APP (app), GS_APP_SIZE_UNKNOWABLE);
+
+       return priv->size_cache_data;
+}
+
+/**
+ * gs_app_set_size_cache_data:
+ * @app: a #GsApp
+ * @size_cache_data: size in bytes, or %GS_APP_SIZE_UNKNOWABLE for unknown
+ *
+ * Sets the cache data size of the @app.
+ *
+ * Since: 41
+ **/
+void
+gs_app_set_size_cache_data (GsApp *app,
+                           guint64 size_cache_data)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_if_fail (GS_IS_APP (app));
+       if (size_cache_data == priv->size_cache_data)
+               return;
+       priv->size_cache_data = size_cache_data;
+       gs_app_queue_notify (app, obj_props[PROP_SIZE_CACHE_DATA]);
+}
+
 /**
  * gs_app_get_metadata_item:
  * @app: a #GsApp
@@ -4694,12 +4785,18 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
        case PROP_LICENSE:
                g_value_set_string (value, priv->license);
                break;
+       case PROP_SIZE_CACHE_DATA:
+               g_value_set_uint64 (value, gs_app_get_size_cache_data (app));
+               break;
        case PROP_SIZE_DOWNLOAD:
                g_value_set_uint64 (value, gs_app_get_size_download (app));
                break;
        case PROP_SIZE_INSTALLED:
                g_value_set_uint64 (value, gs_app_get_size_installed (app));
                break;
+       case PROP_SIZE_USER_DATA:
+               g_value_set_uint64 (value, gs_app_get_size_user_data (app));
+               break;
        case PROP_PERMISSIONS:
                g_value_set_flags (value, priv->permissions);
                break;
@@ -4786,12 +4883,18 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
        case PROP_LICENSE:
                /* Read-only */
                g_assert_not_reached ();
+       case PROP_SIZE_CACHE_DATA:
+               gs_app_set_size_cache_data (app, g_value_get_uint64 (value));
+               break;
        case PROP_SIZE_DOWNLOAD:
                gs_app_set_size_download (app, g_value_get_uint64 (value));
                break;
        case PROP_SIZE_INSTALLED:
                gs_app_set_size_installed (app, g_value_get_uint64 (value));
                break;
+       case PROP_SIZE_USER_DATA:
+               gs_app_set_size_user_data (app, g_value_get_uint64 (value));
+               break;
        case PROP_PERMISSIONS:
                gs_app_set_permissions (app, g_value_get_flags (value));
                break;
@@ -5064,6 +5167,20 @@ gs_app_class_init (GsAppClass *klass)
                                     NULL,
                                     G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+       /**
+        * GsApp:size-cache-data
+        *
+        * The size on the disk for the cache data of the application.
+        *
+        * This is %GS_APP_SIZE_UNKNOWABLE if not known.
+        *
+        * Since: 41
+        */
+       obj_props[PROP_SIZE_CACHE_DATA] =
+               g_param_spec_uint64 ("size-cache-data", NULL, NULL,
+                                    0, G_MAXUINT64, 0,
+                                    G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
        /**
         * GsApp:size-download
         *
@@ -5102,6 +5219,20 @@ gs_app_class_init (GsAppClass *klass)
                                     0, G_MAXUINT64, 0,
                                     G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+       /**
+        * GsApp:size-user-data
+        *
+        * The size on the disk for the user data of the application.
+        *
+        * This is %GS_APP_SIZE_UNKNOWABLE if not known.
+        *
+        * Since: 41
+        */
+       obj_props[PROP_SIZE_USER_DATA] =
+               g_param_spec_uint64 ("size-user-data", NULL, NULL,
+                                    0, G_MAXUINT64, 0,
+                                    G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
        /**
         * GsApp:permissions
         *
@@ -5166,6 +5297,8 @@ gs_app_init (GsApp *app)
                                                   NULL,
                                                   g_free);
        priv->allow_cancel = TRUE;
+       priv->size_cache_data = GS_APP_SIZE_UNKNOWABLE;
+       priv->size_user_data = GS_APP_SIZE_UNKNOWABLE;
        g_mutex_init (&priv->mutex);
 }
 
diff --git a/lib/gs-app.h b/lib/gs-app.h
index c78bfe2f4..46987f13a 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -407,6 +407,12 @@ void                gs_app_add_provided_item       (GsApp          *app,
 guint64                 gs_app_get_size_installed      (GsApp          *app);
 void            gs_app_set_size_installed      (GsApp          *app,
                                                 guint64         size_installed);
+guint64                 gs_app_get_size_user_data      (GsApp          *app);
+void            gs_app_set_size_user_data      (GsApp          *app,
+                                                guint64         size_user_data);
+guint64                 gs_app_get_size_cache_data     (GsApp          *app);
+void            gs_app_set_size_cache_data     (GsApp          *app,
+                                                guint64         size_cache_data);
 guint64                 gs_app_get_size_download       (GsApp          *app);
 void            gs_app_set_size_download       (GsApp          *app,
                                                 guint64         size_download);


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