Show rating as star characters
authorColin Clark <colin.clark@cclark.uk>
Sun, 3 Jun 2018 10:39:01 +0000 (11:39 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sun, 3 Jun 2018 10:39:01 +0000 (11:39 +0100)
Additional tag formatted.star_rating to show Xmp.xmp.Rating as a set of
star characters

doc/docbook/GuideReferenceTags.xml
src/bar.c
src/exif-common.c
src/main.h

index 42929b8..f40b473 100644 (file)
               </para>\r
             </entry>\r
           </row>\r
+          <row>\r
+            <entry>\r
+              <para>formatted.star_rating</para>\r
+            </entry>\r
+            <entry>\r
+              <para>Xmp.xmp.Rating</para>\r
+            </entry>\r
+            <entry>\r
+              <para>Rating shown as a set of ðŸŸŠ  characters</para>\r
+            </entry>\r
+          </row>\r
         </tbody>\r
       </tgroup>\r
     </table>\r
index 8f8673c..8f137ad 100644 (file)
--- a/src/bar.c
+++ b/src/bar.c
@@ -114,6 +114,7 @@ static const gchar default_config_exif[] =
 "                <entry key = 'formatted.SubjectDistance' if_set = 'true' editable = 'false' />"
 "                <entry key = 'formatted.Resolution' if_set = 'true' editable = 'false' />"
 "                <entry key = '" ORIENTATION_KEY "' if_set = 'true' editable = 'false' />"
+"                <entry key = 'formatted.star_rating' if_set = 'true' editable = 'false' />"
 "            </pane_exif>"
 "        </bar>"
 "    </layout>"
index a54f138..099cf07 100644 (file)
@@ -852,6 +852,32 @@ static gchar *exif_build_formatted_timezone(ExifData *exif)
        return time_zone;
 }
 
+static gchar *exif_build_formatted_star_rating(ExifData *exif)
+{
+       gint n;
+       gchar *ret = NULL;
+       GString *str = g_string_new(NULL);
+
+       exif_get_integer(exif, "Xmp.xmp.Rating", &n);
+
+       if (n == -1)
+               {
+               ret = g_strdup("⨷");
+               }
+       else if (n > 0 && n < 6)
+               {
+               while (n > 0)
+                       {
+                       str = g_string_append(str, "🟊");
+                       n = n - 1;
+                       }
+               ret = g_strdup(str->str);
+               g_string_free(str, TRUE);
+               }
+
+       return ret;
+}
+
 /* List of custom formatted pseudo-exif tags */
 #define EXIF_FORMATTED_TAG(name, label) { EXIF_FORMATTED()#name, label, exif_build_formatted##_##name }
 
@@ -873,6 +899,7 @@ ExifFormattedText ExifFormattedList[] = {
        EXIF_FORMATTED_TAG(GPSAltitude,         N_("GPS altitude")),
        EXIF_FORMATTED_TAG(localtime,           N_("Local time")),
        EXIF_FORMATTED_TAG(timezone,            N_("Time zone")),
+       EXIF_FORMATTED_TAG(star_rating,         N_("Star rating")),
        {"file.size",                           N_("File size"),        NULL},
        {"file.date",                           N_("File date"),        NULL},
        {"file.mode",                           N_("File mode"),        NULL},
index c892ad4..2c63afe 100644 (file)
                                "(%number%/%total%) [%zoom%] <b>%name%</b>\n" \
                                "%res%|%date%|%size%\n" \
                                "%formatted.Aperture%|%formatted.ShutterSpeed%|%formatted.ISOSpeedRating:ISO *%|%formatted.FocalLength%|%formatted.ExposureBias:* Ev%\n" \
-                               "%formatted.Camera:40%|%formatted.Flash%"
+                               "%formatted.Camera:40%|%formatted.Flash%\n"            \
+                               "%formatted.star_rating%"
 
 #define GQ_LINK_STR "↗"
 #include "typedefs.h"