[gnome-software/wip/automatic-update-fixes: 88/92] gs-app: Add gs_app_is_downloaded()




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

    gs-app: Add gs_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.

 lib/gs-app.c | 32 ++++++++++++++++++++++++++++++++
 lib/gs-app.h |  1 +
 2 files changed, 33 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 29898765b..d7f8be279 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -6656,3 +6656,35 @@ gs_app_set_has_translations (GsApp    *app,
        priv->has_translations = has_translations;
        gs_app_queue_notify (app, obj_props[PROP_HAS_TRANSLATIONS]);
 }
+
+/**
+ * gs_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_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/lib/gs-app.h b/lib/gs-app.h
index d78503c3e..a053299f2 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -516,5 +516,6 @@ void                 gs_app_set_relations           (GsApp          *app,
 gboolean        gs_app_get_has_translations    (GsApp          *app);
 void            gs_app_set_has_translations    (GsApp          *app,
                                                 gboolean        has_translations);
+gboolean        gs_app_is_downloaded           (GsApp          *app);
 
 G_END_DECLS


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