[gnome-software/1391-style-storage-units-differently: 3/3] gs-storage-context-dialog: Format size value and size unit differently




commit bbe636eee43b511c9762d0d45c01c3e87013b424
Author: Milan Crha <mcrha redhat com>
Date:   Mon Apr 11 14:11:33 2022 +0200

    gs-storage-context-dialog: Format size value and size unit differently
    
    This follows the new design for the dialog. It depends on a new glib API,
    thus checks for it in configure time, instead of bumping the glib version.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1391

 meson.build                     |  5 +++++
 src/gs-storage-context-dialog.c | 12 +++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/meson.build b/meson.build
index 4a692def1..6b9843c7c 100644
--- a/meson.build
+++ b/meson.build
@@ -157,6 +157,11 @@ libadwaita = dependency('libadwaita-1',
   ]
 )
 
+# This should be available in GLib 2.74
+if meson.get_compiler('c').has_header_symbol('glib.h', 'G_FORMAT_SIZE_ONLY_VALUE', dependencies: glib)
+  conf.set('HAVE_G_FORMAT_SIZE_ONLY_VALUE', '1')
+endif
+
 libsysprof_capture_dep = dependency('sysprof-capture-4',
   required: get_option('sysprof'),
   default_options: [
diff --git a/src/gs-storage-context-dialog.c b/src/gs-storage-context-dialog.c
index 4699f5c65..c8df3db72 100644
--- a/src/gs-storage-context-dialog.c
+++ b/src/gs-storage-context-dialog.c
@@ -79,6 +79,7 @@ add_size_row (GtkListBox   *list_box,
 {
        GtkListBoxRow *row;
        g_autofree gchar *size_bytes_str = NULL;
+       gboolean is_markup = FALSE;
 
        if (size_bytes == GS_APP_SIZE_UNKNOWABLE)
                /* Translators: This is shown in a bubble if the storage
@@ -92,10 +93,11 @@ add_size_row (GtkListBox   *list_box,
                 * possible. */
                size_bytes_str = g_strdup (_("None"));
        else
-               size_bytes_str = g_format_size (size_bytes);
+               size_bytes_str = gs_utils_format_size (size_bytes, &is_markup);
 
        row = gs_context_dialog_row_new_text (size_bytes_str, GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL,
                                              title, description);
+       gs_context_dialog_row_set_content_is_markup (GS_CONTEXT_DIALOG_ROW (row), is_markup);
        gs_context_dialog_row_set_size_groups (GS_CONTEXT_DIALOG_ROW (row), lozenge_size_group, NULL, NULL);
        gtk_list_box_append (list_box, GTK_WIDGET (row));
 }
@@ -107,6 +109,7 @@ update_sizes_list (GsStorageContextDialog *self)
        g_autofree gchar *title_size_bytes_str = NULL;
        const gchar *title;
        gboolean cache_row_added = FALSE;
+       gboolean is_markup = FALSE;
 
        gs_widget_remove_all (GTK_WIDGET (self->sizes_list), (GsRemoveFunc) gtk_list_box_remove);
 
@@ -170,8 +173,11 @@ update_sizes_list (GsStorageContextDialog *self)
                /* FIXME: Addons, Potential Additional Downloads */
        }
 
-       title_size_bytes_str = g_format_size (title_size_bytes);
-       gtk_label_set_text (self->lozenge_content, title_size_bytes_str);
+       title_size_bytes_str = gs_utils_format_size (title_size_bytes, &is_markup);
+       if (is_markup)
+               gtk_label_set_markup (self->lozenge_content, title_size_bytes_str);
+       else
+               gtk_label_set_text (self->lozenge_content, title_size_bytes_str);
        gtk_label_set_text (self->title, title);
 
        /* Update the Manage Storage label. */


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