[gnome-software/1296-calculate-app-space-usage-for-download-context-tile] gs-app: Split download/installed size for the app and the dependencies
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1296-calculate-app-space-usage-for-download-context-tile] gs-app: Split download/installed size for the app and the dependencies
- Date: Wed, 28 Jul 2021 20:35:12 +0000 (UTC)
commit 92a8154014303b1e88a21ef1bb9b585c27869e3e
Author: Milan Crha <mcrha redhat com>
Date: Wed Jul 28 22:08:14 2021 +0200
gs-app: Split download/installed size for the app and the dependencies
This helps to show sizes separately for the application itself and
for its dependencies/addons.
lib/gs-app.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++-------------
lib/gs-app.h | 4 ++
2 files changed, 123 insertions(+), 32 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 1aebc59c7..72db3341f 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -158,7 +158,9 @@ typedef enum {
PROP_LICENSE,
PROP_SIZE_CACHE_DATA,
PROP_SIZE_DOWNLOAD,
+ PROP_SIZE_DOWNLOAD_DEPENDENCIES,
PROP_SIZE_INSTALLED,
+ PROP_SIZE_INSTALLED_DEPENDENCIES,
PROP_SIZE_USER_DATA,
PROP_PERMISSIONS,
PROP_RELATIONS,
@@ -678,8 +680,12 @@ gs_app_to_string_append (GsApp *app, GString *str)
}
if (priv->size_installed != 0)
gs_app_kv_size (str, "size-installed", priv->size_installed);
+ if (gs_app_get_size_installed_dependencies (app) != 0)
+ gs_app_kv_size (str, "size-installed-dependencies", gs_app_get_size_installed_dependencies
(app));
if (priv->size_download != 0)
gs_app_kv_size (str, "size-download", gs_app_get_size_download (app));
+ if (gs_app_get_size_download_dependencies (app) != 0)
+ gs_app_kv_size (str, "size-download-dependencies", gs_app_get_size_download_dependencies
(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)
@@ -3480,26 +3486,10 @@ guint64
gs_app_get_size_download (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- guint64 sz;
g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
- /* this app */
- sz = priv->size_download;
-
- /* add the runtime if this is not installed */
- if (priv->runtime != NULL) {
- if (gs_app_get_state (priv->runtime) == GS_APP_STATE_AVAILABLE)
- sz += gs_app_get_size_download (priv->runtime);
- }
-
- /* add related apps */
- for (guint i = 0; i < gs_app_list_length (priv->related); i++) {
- GsApp *app_related = gs_app_list_index (priv->related, i);
- sz += gs_app_get_size_download (app_related);
- }
-
- return sz;
+ return priv->size_download;
}
/**
@@ -3524,35 +3514,60 @@ gs_app_set_size_download (GsApp *app, guint64 size_download)
}
/**
- * gs_app_get_size_installed:
- * @app: a #GsApp
+ * gs_app_get_size_download_dependencies:
+ * @app: A #GsApp
*
- * Get the value of #GsApp:size-installed.
+ * Get the value of #GsApp:size-download-dependencies.
*
- * Returns: size in bytes, `0` for unknown, or %GS_APP_SIZE_UNKNOWABLE for invalid.
+ * Returns: number of bytes, `0` for unknown
*
- * Since: 3.22
+ * Since: 41
**/
guint64
-gs_app_get_size_installed (GsApp *app)
+gs_app_get_size_download_dependencies (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
- guint64 sz;
+ guint64 sz = 0;
g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
- /* this app */
- sz = priv->size_installed;
+ /* add the runtime if this is not installed */
+ if (priv->runtime != NULL) {
+ if (gs_app_get_state (priv->runtime) == GS_APP_STATE_AVAILABLE)
+ sz += gs_app_get_size_download (priv->runtime) +
+ gs_app_get_size_download_dependencies (priv->runtime);
+ }
/* add related apps */
for (guint i = 0; i < gs_app_list_length (priv->related); i++) {
GsApp *app_related = gs_app_list_index (priv->related, i);
- sz += gs_app_get_size_installed (app_related);
+ sz += gs_app_get_size_download (app_related) +
+ gs_app_get_size_download_dependencies (app_related);
}
return sz;
}
+/**
+ * gs_app_get_size_installed:
+ * @app: a #GsApp
+ *
+ * Get the value of #GsApp:size-installed.
+ *
+ * Returns: size in bytes, `0` for unknown, or %GS_APP_SIZE_UNKNOWABLE for invalid.
+ *
+ * Since: 3.22
+ **/
+guint64
+gs_app_get_size_installed (GsApp *app)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+
+ g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
+
+ return priv->size_installed;
+}
+
/**
* gs_app_set_size_installed:
* @app: a #GsApp
@@ -3573,6 +3588,34 @@ gs_app_set_size_installed (GsApp *app, guint64 size_installed)
gs_app_queue_notify (app, obj_props[PROP_SIZE_INSTALLED]);
}
+/**
+ * gs_app_get_size_installed_dependencies:
+ * @app: a #GsApp
+ *
+ * Get the value of #GsApp:size-installed-dependencies.
+ *
+ * Returns: size in bytes, `0` for unknown.
+ *
+ * Since: 41
+ **/
+guint64
+gs_app_get_size_installed_dependencies (GsApp *app)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ guint64 sz = 0;
+
+ g_return_val_if_fail (GS_IS_APP (app), G_MAXUINT64);
+
+ /* add related apps */
+ for (guint i = 0; i < gs_app_list_length (priv->related); i++) {
+ GsApp *app_related = gs_app_list_index (priv->related, i);
+ sz += gs_app_get_size_installed (app_related) +
+ gs_app_get_size_installed_dependencies (app_related);
+ }
+
+ return sz;
+}
+
/**
* gs_app_get_size_user_data:
* @app: A #GsApp
@@ -3882,8 +3925,8 @@ gs_app_add_related (GsApp *app, GsApp *app2)
gs_app_list_add (priv->related, app2);
/* The related apps add to the main app’s sizes. */
- gs_app_queue_notify (app, obj_props[PROP_SIZE_DOWNLOAD]);
- gs_app_queue_notify (app, obj_props[PROP_SIZE_INSTALLED]);
+ gs_app_queue_notify (app, obj_props[PROP_SIZE_DOWNLOAD_DEPENDENCIES]);
+ gs_app_queue_notify (app, obj_props[PROP_SIZE_INSTALLED_DEPENDENCIES]);
}
/**
@@ -4831,9 +4874,15 @@ gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *
case PROP_SIZE_DOWNLOAD:
g_value_set_uint64 (value, gs_app_get_size_download (app));
break;
+ case PROP_SIZE_DOWNLOAD_DEPENDENCIES:
+ g_value_set_uint64 (value, gs_app_get_size_download_dependencies (app));
+ break;
case PROP_SIZE_INSTALLED:
g_value_set_uint64 (value, gs_app_get_size_installed (app));
break;
+ case PROP_SIZE_INSTALLED_DEPENDENCIES:
+ g_value_set_uint64 (value, gs_app_get_size_installed_dependencies (app));
+ break;
case PROP_SIZE_USER_DATA:
g_value_set_uint64 (value, gs_app_get_size_user_data (app));
break;
@@ -4929,9 +4978,15 @@ gs_app_set_property (GObject *object, guint prop_id, const GValue *value, GParam
case PROP_SIZE_DOWNLOAD:
gs_app_set_size_download (app, g_value_get_uint64 (value));
break;
+ case PROP_SIZE_DOWNLOAD_DEPENDENCIES:
+ /* Read-only */
+ g_assert_not_reached ();
case PROP_SIZE_INSTALLED:
gs_app_set_size_installed (app, g_value_get_uint64 (value));
break;
+ case PROP_SIZE_INSTALLED_DEPENDENCIES:
+ /* Read-only */
+ g_assert_not_reached ();
case PROP_SIZE_USER_DATA:
gs_app_set_size_user_data (app, g_value_get_uint64 (value));
break;
@@ -5231,7 +5286,8 @@ gs_app_class_init (GsAppClass *klass)
* This is `0` if the download size is unknown, and
* %GS_APP_SIZE_UNKNOWABLE if it’s not possible to know.
*
- * If there is a runtime not yet installed then this is also added.
+ * To get the runtime or other dependencies download size,
+ * use GsApp:size-download-dependencies.
*
* Since: 41
*/
@@ -5240,6 +5296,22 @@ gs_app_class_init (GsAppClass *klass)
0, G_MAXUINT64, 0,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GsApp:size-download-dependencies
+ *
+ * The size of the total download needed to either install or update
+ * this application's dependencies, in bytes. If the dependencies are partially
+ * downloaded, this is the number of bytes remaining to download.
+ *
+ * This is `0` if the download size is unknown.
+ *
+ * Since: 41
+ */
+ obj_props[PROP_SIZE_DOWNLOAD_DEPENDENCIES] =
+ g_param_spec_uint64 ("size-download-dependencies", NULL, NULL,
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
/**
* GsApp:size-installed
*
@@ -5249,8 +5321,8 @@ gs_app_class_init (GsAppClass *klass)
* This is `0` if the download size is unknown, and
* %GS_APP_SIZE_UNKNOWABLE if it’s not possible to know.
*
- * If the application has a runtime or extensions, their size
- * requirements are also added.
+ * To get the application runtime or extensions installed sizes,
+ * use GsApp:size-installed-dependencies.
*
* Since: 41
*/
@@ -5259,6 +5331,21 @@ gs_app_class_init (GsAppClass *klass)
0, G_MAXUINT64, 0,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GsApp:size-installed-dependencies
+ *
+ * The size of the application's dependencies on disk, in bytes. If the dependencies are
+ * not yet installed, this is the size it would need, once installed.
+ *
+ * This is `0` if the download size is unknown.
+ *
+ * Since: 41
+ */
+ obj_props[PROP_SIZE_INSTALLED_DEPENDENCIES] =
+ g_param_spec_uint64 ("size-installed-dependencies", NULL, NULL,
+ 0, G_MAXUINT64, 0,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
/**
* GsApp:size-user-data
*
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 70a2d61dc..788cad46b 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -408,6 +408,8 @@ 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_installed_dependencies
+ (GsApp *app);
guint64 gs_app_get_size_user_data (GsApp *app);
void gs_app_set_size_user_data (GsApp *app,
guint64 size_user_data);
@@ -417,6 +419,8 @@ void gs_app_set_size_cache_data (GsApp *app,
guint64 gs_app_get_size_download (GsApp *app);
void gs_app_set_size_download (GsApp *app,
guint64 size_download);
+guint64 gs_app_get_size_download_dependencies
+ (GsApp *app);
void gs_app_add_related (GsApp *app,
GsApp *app2);
void gs_app_add_addon (GsApp *app,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]