Branch data Line data Source code
1 : : /* SPDX-License-Identifier: GPL-2.0-or-later
2 : : * SPDX-FileCopyrightText: 2002-2012 Bastien Nocera <hadess@hadess.net>
3 : : * SPDX-FileContributor: 2005 Christian Schaller
4 : : *
5 : : * Copyright © 2002-2012 Bastien Nocera <hadess@hadess.net>
6 : : *
7 : : * This program is free software; you can redistribute it and/or modify
8 : : * it under the terms of the GNU General Public License as published by
9 : : * the Free Software Foundation; either version 2 of the License, or
10 : : * (at your option) any later version.
11 : : *
12 : : * This program is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : * GNU General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU General Public License
18 : : * along with this program; if not, write to the Free Software
19 : : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 : : *
21 : : * The Totem project hereby grant permission for non-gpl compatible GStreamer
22 : : * plugins to be used and distributed together with GStreamer and Totem. This
23 : : * permission is above and beyond the permissions granted by the GPL license
24 : : * Totem is covered by.
25 : : *
26 : : * Monday 7th February 2005: Christian Schaller: Add exception clause.
27 : : * See license_change file for details.
28 : : *
29 : : */
30 : :
31 : : #include "config.h"
32 : :
33 : : #include <math.h>
34 : : #include <glib/gi18n-lib.h>
35 : : #include <libintl.h>
36 : :
37 : : #include "valent-ui-utils-private.h"
38 : :
39 : :
40 : : /* FIXME: Remove
41 : : * See https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/26 */
42 : : char *
43 : 2 : valent_media_time_to_string (int64_t msecs,
44 : : TotemTimeFlag flags)
45 : : {
46 : 2 : int64_t _time;
47 : 2 : int msec, sec, min, hour;
48 : :
49 [ + - ]: 2 : if (msecs < 0) {
50 : : /* translators: Unknown time */
51 [ - + ]: 4 : return g_strdup (_("--:--"));
52 : : }
53 : :
54 : : /* When calculating the remaining time,
55 : : * we want to make sure that:
56 : : * current time + time remaining = total run time */
57 : 0 : msec = msecs % 1000;
58 [ # # ]: 0 : if (flags & TOTEM_TIME_FLAG_MSECS) {
59 : 0 : _time = msecs - msec;
60 : 0 : _time = _time / 1000;
61 : : } else {
62 : 0 : double time_f;
63 : :
64 : 0 : time_f = (double) msecs / 1000;
65 [ # # ]: 0 : if (flags & TOTEM_TIME_FLAG_REMAINING)
66 : 0 : time_f = ceil (time_f);
67 : : else
68 : 0 : time_f = round (time_f);
69 : 0 : _time = (int64_t) time_f;
70 : : }
71 : :
72 : 0 : sec = _time % 60;
73 : 0 : _time = _time - sec;
74 : 0 : min = (_time % (60*60)) / 60;
75 : 0 : _time = _time - (min * 60);
76 : 0 : hour = _time / (60*60);
77 : :
78 [ # # # # ]: 0 : if (hour > 0 || flags & TOTEM_TIME_FLAG_FORCE_HOUR) {
79 [ # # ]: 0 : if (!(flags & TOTEM_TIME_FLAG_REMAINING)) {
80 [ # # ]: 0 : if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
81 : : /* hour:minutes:seconds */
82 : : /* Translators: This is a time format, like "9:05:02" for 9
83 : : * hours, 5 minutes, and 2 seconds. You may change ":" to
84 : : * the separator that your locale uses or use "%Id" instead
85 : : * of "%d" if your locale uses localized digits.
86 : : */
87 : 0 : return g_strdup_printf (C_("long time format", "%d:%02d:%02d"), hour, min, sec);
88 : : } else {
89 : : /* hour:minutes:seconds.msecs */
90 : : /* Translators: This is a time format, like "9:05:02.050" for 9
91 : : * hours, 5 minutes, 2 seconds and 50 milliseconds. You may change ":" to
92 : : * the separator that your locale uses or use "%Id" instead
93 : : * of "%d" if your locale uses localized digits.
94 : : */
95 : 0 : return g_strdup_printf (C_("long time format", "%d:%02d:%02d.%03d"), hour, min, sec, msec);
96 : : }
97 : : } else {
98 [ # # ]: 0 : if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
99 : : /* -hour:minutes:seconds */
100 : : /* Translators: This is a time format, like "-9:05:02" for 9
101 : : * hours, 5 minutes, and 2 seconds playback remaining. You may
102 : : * change ":" to the separator that your locale uses or use
103 : : * "%Id" instead of "%d" if your locale uses localized digits.
104 : : */
105 : 0 : return g_strdup_printf (C_("long time format", "-%d:%02d:%02d"), hour, min, sec);
106 : : } else {
107 : : /* -hour:minutes:seconds.msecs */
108 : : /* Translators: This is a time format, like "-9:05:02.050" for 9
109 : : * hours, 5 minutes, 2 seconds and 50 milliseconds playback remaining. You may
110 : : * change ":" to the separator that your locale uses or use
111 : : * "%Id" instead of "%d" if your locale uses localized digits.
112 : : */
113 : 0 : return g_strdup_printf (C_("long time format", "-%d:%02d:%02d.%03d"), hour, min, sec, msec);
114 : : }
115 : : }
116 : : }
117 : :
118 [ # # ]: 0 : if (flags & TOTEM_TIME_FLAG_REMAINING) {
119 [ # # ]: 0 : if (!(flags & TOTEM_TIME_FLAG_MSECS)) {
120 : : /* -minutes:seconds */
121 : : /* Translators: This is a time format, like "-5:02" for 5
122 : : * minutes and 2 seconds playback remaining. You may change
123 : : * ":" to the separator that your locale uses or use "%Id"
124 : : * instead of "%d" if your locale uses localized digits.
125 : : */
126 : 0 : return g_strdup_printf (C_("short time format", "-%d:%02d"), min, sec);
127 : : } else {
128 : : /* -minutes:seconds.msec */
129 : : /* Translators: This is a time format, like "-5:02.050" for 5
130 : : * minutes 2 seconds and 50 milliseconds playback remaining. You may change
131 : : * ":" to the separator that your locale uses or use "%Id"
132 : : * instead of "%d" if your locale uses localized digits.
133 : : */
134 : 0 : return g_strdup_printf (C_("short time format", "-%d:%02d.%03d"), min, sec, msec);
135 : : }
136 : : }
137 : :
138 [ # # ]: 0 : if (flags & TOTEM_TIME_FLAG_MSECS) {
139 : : /* minutes:seconds.msec */
140 : : /* Translators: This is a time format, like "5:02" for 5
141 : : * minutes 2 seconds and 50 milliseconds. You may change ":" to the
142 : : * separator that your locale uses or use "%Id" instead of
143 : : * "%d" if your locale uses localized digits.
144 : : */
145 : 0 : return g_strdup_printf (C_("short time format", "%d:%02d.%03d"), min, sec, msec);
146 : : }
147 : :
148 : : /* minutes:seconds */
149 : : /* Translators: This is a time format, like "5:02" for 5
150 : : * minutes and 2 seconds. You may change ":" to the
151 : : * separator that your locale uses or use "%Id" instead of
152 : : * "%d" if your locale uses localized digits.
153 : : */
154 : 0 : return g_strdup_printf (C_("short time format", "%d:%02d"), min, sec);
155 : : }
156 : :
|