[gthumb] show the rating as a sequence of stars



commit e80cbf601f9c05acc57ff127305ea33c5b7b67be
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jan 8 17:29:21 2019 +0100

    show the rating as a sequence of stars

 gthumb/gth-file-data.c | 13 ++++++++++++-
 gthumb/gth-grid-view.c |  7 ++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/gthumb/gth-file-data.c b/gthumb/gth-file-data.c
index 2c421643..caf840d6 100644
--- a/gthumb/gth-file-data.c
+++ b/gthumb/gth-file-data.c
@@ -534,7 +534,18 @@ gth_file_data_get_attribute_as_string (GthFileData *file_data,
                if (GTH_IS_METADATA (obj)) {
                        switch (gth_metadata_get_data_type (GTH_METADATA (obj))) {
                        case GTH_METADATA_TYPE_STRING:
-                               value = g_strdup (gth_metadata_get_formatted (GTH_METADATA (obj)));
+                               if (strcmp (id, "general::rating") == 0) {
+                                       int n = atoi (gth_metadata_get_formatted (GTH_METADATA (obj)));
+                                       if ((n >= 0) && (n <= 5)) {
+                                               GString *str = g_string_new ("");
+                                               int      i;
+                                               for (i = 1; i <= n; i++)
+                                                       g_string_append (str, "⭐");
+                                               value = g_string_free (str, FALSE);
+                                       }
+                               }
+                               if (value == NULL)
+                                       value = g_strdup (gth_metadata_get_formatted (GTH_METADATA (obj)));
                                break;
                        case GTH_METADATA_TYPE_STRING_LIST:
                                value = gth_string_list_join (GTH_STRING_LIST (gth_metadata_get_string_list 
(GTH_METADATA (obj))), " ");
diff --git a/gthumb/gth-grid-view.c b/gthumb/gth-grid-view.c
index 8b7ee6ac..68f67bf4 100644
--- a/gthumb/gth-grid-view.c
+++ b/gthumb/gth-grid-view.c
@@ -298,6 +298,7 @@ gth_grid_view_item_update_caption (GthGridViewItem  *item,
                value = gth_file_data_get_attribute_as_string (item->file_data, attributes_v[i]);
                if ((value != NULL) && ! g_str_equal (value, "")) {
                        char *escaped;
+                       char *style;
 
                        if (metadata->len > 0)
                                g_string_append (metadata, "\n");
@@ -313,7 +314,11 @@ gth_grid_view_item_update_caption (GthGridViewItem  *item,
                        }
 
                        escaped = g_markup_escape_text (value, -1);
-                       g_string_append_printf (metadata, "<span%s>%s</span>", (odd ? ODD_ROW_ATTR_STYLE : 
EVEN_ROW_ATTR_STYLE), escaped);
+                       if (strcmp (attributes_v[i], "general::rating") == 0)
+                               style = "";
+                       else
+                               style = (odd ? ODD_ROW_ATTR_STYLE : EVEN_ROW_ATTR_STYLE);
+                       g_string_append_printf (metadata, "<span%s>%s</span>", style, escaped);
 
                        g_free (escaped);
                }


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