[totem/wip/hadess/precise-stepping: 7/7] gst: Add support for showing msecs in time label




commit 5ad1644b5a38843490993792b869cbfaced262ce
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Feb 17 21:48:19 2022 +0100

    gst: Add support for showing msecs in time label

 src/gst/totem-time-helpers.c | 81 +++++++++++++++++++++++++++++++++-----------
 src/gst/totem-time-helpers.h |  1 +
 src/test-totem.c             |  4 +++
 3 files changed, 66 insertions(+), 20 deletions(-)
---
diff --git a/src/gst/totem-time-helpers.c b/src/gst/totem-time-helpers.c
index 13d10e88e..da217fd3f 100644
--- a/src/gst/totem-time-helpers.c
+++ b/src/gst/totem-time-helpers.c
@@ -37,7 +37,7 @@ char *
 totem_time_to_string (gint64        msecs,
                      TotemTimeFlag flags)
 {
-       int sec, min, hour, _time;
+       int msec, sec, min, hour, _time;
        double time_f;
 
        if (msecs <= 0) {
@@ -55,6 +55,7 @@ totem_time_to_string (gint64        msecs,
                time_f = round (time_f);
        _time = (int) time_f;
 
+       msec = msecs - (_time * 1000);
        sec = _time % 60;
        _time = _time - sec;
        min = (_time % (60*60)) / 60;
@@ -63,32 +64,72 @@ totem_time_to_string (gint64        msecs,
 
        if (hour > 0 || flags & TOTEM_TIME_FLAG_FORCE_HOUR) {
                if (!(flags & TOTEM_TIME_FLAG_REMAINING)) {
-                       /* hour:minutes:seconds */
-                       /* Translators: This is a time format, like "9:05:02" for 9
-                        * hours, 5 minutes, and 2 seconds. You may change ":" to
-                        * the separator that your locale uses or use "%Id" instead
-                        * of "%d" if your locale uses localized digits.
+                       if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
+                               /* hour:minutes:seconds */
+                               /* Translators: This is a time format, like "9:05:02" for 9
+                                * hours, 5 minutes, and 2 seconds. You may change ":" to
+                                * the separator that your locale uses or use "%Id" instead
+                                * of "%d" if your locale uses localized digits.
+                                */
+                               return g_strdup_printf (C_("long time format", "%d:%02d:%02d"), hour, min, 
sec);
+                       } else {
+                               /* hour:minutes:seconds.msecs */
+                               /* Translators: This is a time format, like "9:05:02.050" for 9
+                                * hours, 5 minutes, 2 seconds and 50 milliseconds. You may change ":" to
+                                * the separator that your locale uses or use "%Id" instead
+                                * of "%d" if your locale uses localized digits.
+                                */
+                               return g_strdup_printf (C_("long time format", "%d:%02d:%02d.%03d"), hour, 
min, sec, msec);
+                       }
+               } else {
+                       if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
+                               /* -hour:minutes:seconds */
+                               /* Translators: This is a time format, like "-9:05:02" for 9
+                                * hours, 5 minutes, and 2 seconds playback remaining. You may
+                                * change ":" to the separator that your locale uses or use
+                                * "%Id" instead of "%d" if your locale uses localized digits.
+                                */
+                               return g_strdup_printf (C_("long time format", "-%d:%02d:%02d"), hour, min, 
sec);
+                       } else {
+                               /* -hour:minutes:seconds.msecs */
+                               /* Translators: This is a time format, like "-9:05:02.050" for 9
+                                * hours, 5 minutes, 2 seconds and 50 milliseconds playback remaining. You may
+                                * change ":" to the separator that your locale uses or use
+                                * "%Id" instead of "%d" if your locale uses localized digits.
+                                */
+                               return g_strdup_printf (C_("long time format", "-%d:%02d:%02d.%03d"), hour, 
min, sec, msec);
+                       }
+               }
+       }
+
+       if (flags & TOTEM_TIME_FLAG_REMAINING) {
+               if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
+                       /* -minutes:seconds */
+                       /* Translators: This is a time format, like "-5:02" for 5
+                        * minutes and 2 seconds playback remaining. You may change
+                        * ":" to the separator that your locale uses or use "%Id"
+                        * instead of "%d" if your locale uses localized digits.
                         */
-                       return g_strdup_printf (C_("long time format", "%d:%02d:%02d"), hour, min, sec);
+                       return g_strdup_printf (C_("short time format", "-%d:%02d"), min, sec);
                } else {
-                       /* -hour:minutes:seconds */
-                       /* Translators: This is a time format, like "-9:05:02" for 9
-                        * hours, 5 minutes, and 2 seconds playback remaining. You may
-                        * change ":" to the separator that your locale uses or use
-                        * "%Id" instead of "%d" if your locale uses localized digits.
+                       /* -minutes:seconds.msec */
+                       /* Translators: This is a time format, like "-5:02.050" for 5
+                        * minutes 2 seconds and 50 milliseconds playback remaining. You may change
+                        * ":" to the separator that your locale uses or use "%Id"
+                        * instead of "%d" if your locale uses localized digits.
                         */
-                       return g_strdup_printf (C_("long time format", "-%d:%02d:%02d"), hour, min, sec);
+                       return g_strdup_printf (C_("short time format", "-%d:%02d.%03d"), min, sec, msec);
                }
        }
 
-       if (flags & TOTEM_TIME_FLAG_REMAINING) {
-               /* -minutes:seconds */
-               /* Translators: This is a time format, like "-5:02" for 5
-                * minutes and 2 seconds playback remaining. You may change
-                * ":" to the separator that your locale uses or use "%Id"
-                * instead of "%d" if your locale uses localized digits.
+       if (flags & TOTEM_TIME_FLAG_MSECS) {
+               /* minutes:seconds.msec */
+               /* Translators: This is a time format, like "5:02" for 5
+                * minutes 2 seconds and 50 milliseconds. You may change ":" to the
+                * separator that your locale uses or use "%Id" instead of
+                * "%d" if your locale uses localized digits.
                 */
-               return g_strdup_printf (C_("short time format", "-%d:%02d"), min, sec);
+               return g_strdup_printf (C_("short time format", "%d:%02d.%03d"), min, sec, msec);
        }
 
        /* minutes:seconds */
diff --git a/src/gst/totem-time-helpers.h b/src/gst/totem-time-helpers.h
index 79099e0ac..31225d082 100644
--- a/src/gst/totem-time-helpers.h
+++ b/src/gst/totem-time-helpers.h
@@ -34,6 +34,7 @@ typedef enum {
        TOTEM_TIME_FLAG_NONE = 0,
        TOTEM_TIME_FLAG_REMAINING,
        TOTEM_TIME_FLAG_FORCE_HOUR,
+       TOTEM_TIME_FLAG_MSECS
 } TotemTimeFlag;
 
 char *totem_time_to_string (gint64        msecs,
diff --git a/src/test-totem.c b/src/test-totem.c
index e055b25ff..7c2ec1f02 100644
--- a/src/test-totem.c
+++ b/src/test-totem.c
@@ -165,6 +165,10 @@ test_time_label (void)
        str = totem_time_to_string (1250, TOTEM_TIME_FLAG_REMAINING);
        g_assert_cmpstr (str, ==, "-0:02");
        g_free (str);
+
+       str = totem_time_to_string (1250, TOTEM_TIME_FLAG_MSECS);
+       g_assert_cmpstr (str, ==, "0:01.250");
+       g_free (str);
 }
 
 int main (int argc, char **argv)


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