[gnome-software/gnome-42: 2/3] gs-app-row: Use markup or text for description label according to the content




commit 99061a2fed883835b4316155bf1790b24949e872
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jul 14 07:54:25 2022 +0200

    gs-app-row: Use markup or text for description label according to the content
    
    Depending whether the app description is markup or plain text,
    set the value to the label as markup or as text, to not show
    markup-escaped sequences in user visible text.

 src/gs-app-row.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index d0c742db6..abe221c12 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -77,22 +77,27 @@ typedef enum {
 
 static GParamSpec *obj_props[PROP_IS_NARROW + 1] = { NULL, };
 
-/**
+/*
  * gs_app_row_get_description:
  *
- * Return value: PangoMarkup
- **/
+ * Return value: PangoMarkup or text
+ */
 static GString *
-gs_app_row_get_description (GsAppRow *app_row)
+gs_app_row_get_description (GsAppRow *app_row,
+                           gboolean *out_is_markup)
 {
        GsAppRowPrivate *priv = gs_app_row_get_instance_private (app_row);
        const gchar *tmp = NULL;
 
+       *out_is_markup = FALSE;
+
        /* convert the markdown update description into PangoMarkup */
        if (priv->show_update) {
                tmp = gs_app_get_update_details_markup (priv->app);
-               if (tmp != NULL && tmp[0] != '\0')
+               if (tmp != NULL && tmp[0] != '\0') {
+                       *out_is_markup = TRUE;
                        return g_string_new (tmp);
+               }
        }
 
        /* if missing summary is set, return it without escaping in order to
@@ -277,6 +282,7 @@ gs_app_row_actually_refresh (GsAppRow *app_row)
        const gchar *tmp;
        gboolean missing_search_result;
        guint64 size = 0;
+       gboolean is_markup = FALSE;
        g_autoptr(GIcon) icon = NULL;
 
        if (priv->app == NULL)
@@ -299,10 +305,13 @@ gs_app_row_actually_refresh (GsAppRow *app_row)
        }
 
        /* join the description lines */
-       str = gs_app_row_get_description (app_row);
+       str = gs_app_row_get_description (app_row, &is_markup);
        if (str != NULL) {
                as_gstring_replace (str, "\n", " ");
-               gtk_label_set_label (GTK_LABEL (priv->description_label), str->str);
+               if (is_markup)
+                       gtk_label_set_markup (GTK_LABEL (priv->description_label), str->str);
+               else
+                       gtk_label_set_label (GTK_LABEL (priv->description_label), str->str);
                g_string_free (str, TRUE);
        } else {
                gtk_label_set_text (GTK_LABEL (priv->description_label), NULL);


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