[gnome-software/1005-add-option-for-packaging-format-preference: 6/7] gs-app: Introduce gs_app_get_packaging_format_raw()




commit 27bbae76f6fbd4091de7b9888462116b6e86addf
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 27 12:32:01 2021 +0200

    gs-app: Introduce gs_app_get_packaging_format_raw()
    
    It returns a raw value, suitable for machine processing, in contract
    to the gs_app_get_packaging_format(), which returns a value suitable
    for the UI.

 lib/gs-app.c | 26 ++++++++++++++++++++++++++
 lib/gs-app.h |  1 +
 2 files changed, 27 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index ce334de38..ce15509ef 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -5441,6 +5441,32 @@ gs_app_get_packaging_format (GsApp *app)
        return g_strdup (bundle_kind_ui);
 }
 
+/**
+ * gs_app_get_packaging_format_raw:
+ * @app: a #GsApp
+ *
+ * Similar to gs_app_get_packaging_format(), but it does not return a newly
+ * allocated string and the value is not suitable for the UI. Depending on
+ * the plugin, it can be "deb", "flatpak", "package", "RPM", "snap", ....
+ *
+ * Returns: The raw value of the packaging format
+ *
+ * Since: 41
+ **/
+const gchar *
+gs_app_get_packaging_format_raw (GsApp *app)
+{
+       const gchar *packaging_format;
+
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+
+       packaging_format = gs_app_get_metadata_item (app, "GnomeSoftware::PackagingFormat");
+       if (packaging_format != NULL)
+               return packaging_format;
+
+       return as_bundle_kind_to_string (gs_app_get_bundle_kind (app));
+}
+
 /**
  * gs_app_subsume_metadata:
  * @app: a #GsApp
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 935344ea2..87c07df98 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -467,6 +467,7 @@ gchar               *gs_app_get_origin_ui           (GsApp          *app);
 void            gs_app_set_origin_ui           (GsApp          *app,
                                                 const gchar    *origin_ui);
 gchar          *gs_app_get_packaging_format    (GsApp          *app);
+const gchar    *gs_app_get_packaging_format_raw(GsApp *app);
 void            gs_app_subsume_metadata        (GsApp          *app,
                                                 GsApp          *donor);
 GsAppPermissions gs_app_get_permissions                (GsApp          *app);


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