[gnome-software/wip/automatic-update-fixes: 21/25] gs-common: Add gs_utils_get_app_is_downloaded()




commit 0c39cddf1d0f7cc8b4522bc710293809f663fa49
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 15 18:05:38 2022 +0200

    gs-common: Add gs_utils_get_app_is_downloaded()
    
    This avoid code duplication on two places. It also makes sure the places
    agree on the way the app is/is-not downloaded is determined.

 src/gs-common.c | 32 ++++++++++++++++++++++++++++++++
 src/gs-common.h |  1 +
 2 files changed, 33 insertions(+)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index 948fdadbf..aade6fcc4 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -986,3 +986,35 @@ gs_utils_format_size (guint64 size_bytes,
        return g_format_size (size_bytes);
 #endif /* HAVE_G_FORMAT_SIZE_ONLY_VALUE */
 }
+
+/**
+ * gs_utils_get_app_is_downloaded:
+ * @app: a #GsApp
+ *
+ * Returns whether the @app is downloaded for updates or not,
+ * considering also its dependencies.
+ *
+ * Returns: %TRUE, when the @app is downloaded, %FALSE otherwise
+ *
+ * Since: 43
+ **/
+gboolean
+gs_utils_get_app_is_downloaded (GsApp *app)
+{
+       GsSizeType size_type;
+       guint64 size_bytes = 0;
+
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+
+       if (!gs_app_has_quirk (app, GS_APP_QUIRK_IS_PROXY)) {
+               size_type = gs_app_get_size_download (app, &size_bytes);
+               if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0)
+                       return FALSE;
+       }
+
+       size_type = gs_app_get_size_download_dependencies (app, &size_bytes);
+       if (size_type != GS_SIZE_TYPE_VALID || size_bytes != 0)
+               return FALSE;
+
+       return TRUE;
+}
diff --git a/src/gs-common.h b/src/gs-common.h
index 8d60d46d3..541987aff 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -64,5 +64,6 @@ gboolean      gs_utils_split_time_difference  (gint64 unix_time_seconds,
                                                 gint *out_years_ago);
 gchar          *gs_utils_format_size           (guint64 size_bytes,
                                                 gboolean *out_is_markup);
+gboolean        gs_utils_get_app_is_downloaded (GsApp *app);
 
 G_END_DECLS


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