[totem] gst: Add more time display options



commit 52a8a194507b1bfe811cc4e17b90d19e08713cbc
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Mar 28 17:20:20 2013 +0100

    gst: Add more time display options
    
    Add options to force the hour to be shown, and whether to
    show the time as "remaining" time.

 src/gst/totem-time-helpers.c          |   39 +++++++++++++++++++++++++-------
 src/gst/totem-time-helpers.h          |    4 ++-
 src/plugins/grilo/totem-grilo.c       |    2 +-
 src/plugins/skipto/totem-time-entry.c |    4 +-
 src/totem-statusbar.c                 |    5 +--
 src/totem-time-label.c                |    8 +++---
 src/totem-video-thumbnailer.c         |    4 +-
 7 files changed, 44 insertions(+), 22 deletions(-)
---
diff --git a/src/gst/totem-time-helpers.c b/src/gst/totem-time-helpers.c
index 71e9e82..0e2cfb2 100644
--- a/src/gst/totem-time-helpers.c
+++ b/src/gst/totem-time-helpers.c
@@ -34,7 +34,9 @@
 /* FIXME: Remove
  * See https://bugzilla.gnome.org/show_bug.cgi?id=679850 */
 char *
-totem_time_to_string (gint64 msecs)
+totem_time_to_string (gint64   msecs,
+                     gboolean remaining,
+                     gboolean force_hour)
 {
        int sec, min, hour, _time;
 
@@ -45,15 +47,34 @@ totem_time_to_string (gint64 msecs)
        _time = _time - (min * 60);
        hour = _time / (60*60);
 
-       if (hour > 0)
-       {
-               /* 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 (hour > 0 || force_hour) {
+               if (!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.
+                        */
+                       return g_strdup_printf (C_("long time format", "%d:%02d:%02d"), hour, 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.
+                        */
+                       return g_strdup_printf (C_("long time format", "-%d:%02d:%02d"), hour, min, sec);
+               }
+       }
+
+       if (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.
                 */
-               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);
        }
 
        /* minutes:seconds */
diff --git a/src/gst/totem-time-helpers.h b/src/gst/totem-time-helpers.h
index fc3067e..a5269b7 100644
--- a/src/gst/totem-time-helpers.h
+++ b/src/gst/totem-time-helpers.h
@@ -30,6 +30,8 @@
 
 #include <glib.h>
 
-char *totem_time_to_string (gint64 msecs);
+char *totem_time_to_string (gint64   msecs,
+                           gboolean remaining,
+                           gboolean force_hour);
 
 #endif /* _TOTEM_TIME_HELPERS_H_ */
diff --git a/src/plugins/grilo/totem-grilo.c b/src/plugins/grilo/totem-grilo.c
index 4b454b9..837fd76 100644
--- a/src/plugins/grilo/totem-grilo.c
+++ b/src/plugins/grilo/totem-grilo.c
@@ -169,7 +169,7 @@ get_secondary_text (GrlMedia *media)
                return g_strdup (artist);
        duration = grl_media_get_duration (media);
        if (duration > 0)
-               return totem_time_to_string (duration * 1000);
+               return totem_time_to_string (duration * 1000, FALSE, FALSE);
        return NULL;
 }
 
diff --git a/src/plugins/skipto/totem-time-entry.c b/src/plugins/skipto/totem-time-entry.c
index 7b2e97b..dab27b0 100644
--- a/src/plugins/skipto/totem-time-entry.c
+++ b/src/plugins/skipto/totem-time-entry.c
@@ -122,7 +122,7 @@ output_cb (GtkSpinButton *self, gpointer user_data)
 {
        gchar *text;
 
-       text = totem_time_to_string ((gint64) gtk_spin_button_get_value (self) * 1000);
+       text = totem_time_to_string ((gint64) gtk_spin_button_get_value (self) * 1000, FALSE, FALSE);
        gtk_entry_set_text (GTK_ENTRY (self), text);
        g_free (text);
 
@@ -170,7 +170,7 @@ changed_cb (GtkAdjustment *adjustment, TotemTimeEntry *self)
        /* Set the width of the entry according to the length of the longest string it'll now accept */
        upper = (guint) gtk_adjustment_get_upper (adjustment); /* in seconds */
 
-       time_string = totem_time_to_string (((gint64) upper) * 1000);
+       time_string = totem_time_to_string (((gint64) upper) * 1000, FALSE, FALSE);
        width = strlen (time_string);
        g_free (time_string);
 
diff --git a/src/totem-statusbar.c b/src/totem-statusbar.c
index e822f7e..2726ea1 100644
--- a/src/totem-statusbar.c
+++ b/src/totem-statusbar.c
@@ -127,13 +127,12 @@ totem_statusbar_update_time (TotemStatusbar *statusbar)
   TotemStatusbarPrivate *priv = statusbar->priv;
   char *time_string, *length, *label;
 
-  time_string = totem_time_to_string (priv->time * 1000);
+  time_string = totem_time_to_string (priv->time * 1000, FALSE, FALSE);
 
   if (priv->length < 0) {
     label = g_strdup_printf (_("%s (Streaming)"), time_string);
   } else {
-    length = totem_time_to_string
-           (priv->length == -1 ? 0 : priv->length * 1000);
+    length = totem_time_to_string (priv->length == -1 ? 0 : priv->length * 1000, FALSE, FALSE);
 
     if (priv->seeking == FALSE)
       /* Elapsed / Total Length */
diff --git a/src/totem-time-label.c b/src/totem-time-label.c
index f1dc11f..c3a7c40 100644
--- a/src/totem-time-label.c
+++ b/src/totem-time-label.c
@@ -20,7 +20,7 @@ totem_time_label_init (TotemTimeLabel *label)
        char *time_string;
        label->priv = G_TYPE_INSTANCE_GET_PRIVATE (label, TOTEM_TYPE_TIME_LABEL, TotemTimeLabelPrivate);
 
-       time_string = totem_time_to_string (0);
+       time_string = totem_time_to_string (0, FALSE, FALSE);
        gtk_label_set_text (GTK_LABEL (label), time_string);
        g_free (time_string);
 
@@ -53,12 +53,12 @@ totem_time_label_set_time (TotemTimeLabel *label, gint64 _time, gint64 length)
                return;
 
        if (length <= 0) {
-               label_str = totem_time_to_string (_time);
+               label_str = totem_time_to_string (_time, FALSE, FALSE);
        } else {
                char *time_str, *length_str;
 
-               time_str = totem_time_to_string (_time);
-               length_str = totem_time_to_string (length);
+               time_str = totem_time_to_string (_time, FALSE, FALSE);
+               length_str = totem_time_to_string (length, FALSE, FALSE);
                if (label->priv->seeking == FALSE) {
                        /* Elapsed / Total Length */
                        label_str = g_strdup_printf (_("%s / %s"), time_str, length_str);
diff --git a/src/totem-video-thumbnailer.c b/src/totem-video-thumbnailer.c
index 48d5862..38d4df0 100644
--- a/src/totem-video-thumbnailer.c
+++ b/src/totem-video-thumbnailer.c
@@ -826,7 +826,7 @@ create_gallery (ThumbApp *app)
        g_object_unref (pixbuf);
 
        /* Build the header information */
-       duration_text = totem_time_to_string (stream_length);
+       duration_text = totem_time_to_string (stream_length, FALSE, FALSE);
        filename = NULL;
        if (strstr (app->input, "://")) {
                char *local;
@@ -881,7 +881,7 @@ create_gallery (ThumbApp *app)
                gchar *timestamp_text;
                gint layout_width, layout_height;
 
-               timestamp_text = totem_time_to_string (pos);
+               timestamp_text = totem_time_to_string (pos, FALSE, FALSE);
 
                pango_layout_set_text (layout, timestamp_text, -1);
                pango_layout_get_pixel_size (layout, &layout_width, &layout_height);


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