[gnome-software/1081-gsapp-show-packaging-format-in-origin-ui-string: 37/38] GsApp: Show packaging format in the origin UI string




commit 615e8ca8be8cf29ef05478d63df6233b40a12c5c
Author: Milan Crha <mcrha redhat com>
Date:   Tue Feb 2 10:21:35 2021 +0100

    GsApp: Show packaging format in the origin UI string
    
    Show the packaging format in the origin UI string to be able
    to easily distinguish what format the respective origin is,
    even when it has a similar name/title.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1081

 lib/gs-app.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 5b613fd69..5e0a5c1d1 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -4774,16 +4774,11 @@ gs_app_get_origin_ui (GsApp *app)
 {
        GsAppPrivate *priv;
        g_autoptr(GMutexLocker) locker = NULL;
+       g_autofree gchar *packaging_format = NULL;
+       const gchar *origin_str;
 
        g_return_val_if_fail (GS_IS_APP (app), NULL);
 
-       priv = gs_app_get_instance_private (app);
-       locker = g_mutex_locker_new (&priv->mutex);
-       if (priv->origin_ui && *priv->origin_ui)
-               return g_strdup (priv->origin_ui);
-
-       g_clear_pointer (&locker, g_mutex_locker_free);
-
        /* use the distro name for official packages */
        if (gs_app_has_quirk (app, GS_APP_QUIRK_PROVENANCE)) {
                g_autoptr(GsOsRelease) os_release = gs_os_release_new (NULL);
@@ -4791,21 +4786,33 @@ gs_app_get_origin_ui (GsApp *app)
                        return g_strdup (gs_os_release_get_name (os_release));
        }
 
-       /* use "Local file" rather than the filename for local files */
-       if (gs_app_get_state (app) == GS_APP_STATE_AVAILABLE_LOCAL) {
-               /* TRANSLATORS: this is a locally downloaded package */
-               return g_strdup (_("Local file"));
+       priv = gs_app_get_instance_private (app);
+       locker = g_mutex_locker_new (&priv->mutex);
+
+       origin_str = priv->origin_ui;
+
+       if (origin_str == NULL || origin_str[0] == '\0') {
+               /* use "Local file" rather than the filename for local files */
+               if (gs_app_get_state (app) == GS_APP_STATE_AVAILABLE_LOCAL)
+                       origin_str = _("Local file");
+               else if (g_strcmp0 (gs_app_get_origin (app), "flathub") == 0)
+                       origin_str = "Flathub";
+               else if (g_strcmp0 (gs_app_get_origin (app), "flathub-beta") == 0)
+                       origin_str = "Flathub Beta";
+               else
+                       origin_str = gs_app_get_origin (app);
        }
 
-       /* capitalize "Flathub" and "Flathub Beta" */
-       if (g_strcmp0 (gs_app_get_origin (app), "flathub") == 0) {
-               return g_strdup ("Flathub");
-       } else if (g_strcmp0 (gs_app_get_origin (app), "flathub-beta") == 0) {
-               return g_strdup ("Flathub Beta");
+       packaging_format = gs_app_get_packaging_format (app);
+
+       if (packaging_format) {
+               /* TRANSLATORS: the first %s is replaced with an origin name;
+                  the second %s is replaced with the packaging format.
+                  Example string: "Local file (RPM)" */
+               return g_strdup_printf (_("%s (%s)"), origin_str, packaging_format);
        }
 
-       /* fall back to origin */
-       return g_strdup (gs_app_get_origin (app));
+       return g_strdup (origin_str);
 }
 
 void


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