[totem/wip/hadess/precise-stepping: 9/10] backend: Add msecs support to time label widget
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/precise-stepping: 9/10] backend: Add msecs support to time label widget
- Date: Thu, 17 Feb 2022 21:42:28 +0000 (UTC)
commit 053ab88a0f4a70535a901026567870bd605ec3bb
Author: Bastien Nocera <hadess hadess net>
Date: Thu Feb 17 22:28:32 2022 +0100
backend: Add msecs support to time label widget
src/backend/bacon-time-label.c | 33 +++++++++++++++++++++++++++++----
src/backend/bacon-time-label.h | 5 +++--
src/test-totem.c | 27 +++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 6 deletions(-)
---
diff --git a/src/backend/bacon-time-label.c b/src/backend/bacon-time-label.c
index 310a86181..62ea8ad1e 100644
--- a/src/backend/bacon-time-label.c
+++ b/src/backend/bacon-time-label.c
@@ -31,13 +31,15 @@ struct _BaconTimeLabel {
gint64 time;
gint64 length;
gboolean remaining;
+ gboolean show_msecs;
};
G_DEFINE_TYPE(BaconTimeLabel, bacon_time_label, GTK_TYPE_LABEL)
enum {
PROP_0,
- PROP_REMAINING
+ PROP_REMAINING,
+ PROP_SHOW_MSECS
};
static void
@@ -76,6 +78,9 @@ bacon_time_label_set_property (GObject *object,
case PROP_REMAINING:
bacon_time_label_set_remaining (BACON_TIME_LABEL (object), g_value_get_boolean (value));
break;
+ case PROP_SHOW_MSECS:
+ bacon_time_label_set_show_msecs (BACON_TIME_LABEL (object), g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -94,6 +99,10 @@ bacon_time_label_class_init (BaconTimeLabelClass *klass)
g_param_spec_boolean ("remaining", "Remaining",
"Whether to show a remaining time.", FALSE,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_SHOW_MSECS,
+ g_param_spec_boolean ("show-msecs", "Show milliseconds",
+ "Whether to show milliseconds.", FALSE,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
}
static void
@@ -109,6 +118,7 @@ update_label_text (BaconTimeLabel *label)
flags = label->remaining ? TOTEM_TIME_FLAG_REMAINING : TOTEM_TIME_FLAG_NONE;
if (length > 60 * 60 * 1000)
flags |= TOTEM_TIME_FLAG_FORCE_HOUR;
+ flags |= label->show_msecs ? TOTEM_TIME_FLAG_MSECS : TOTEM_TIME_FLAG_NONE;
if (length <= 0 || _time > length)
label_str = totem_time_to_string (label->remaining ? -1 : _time, flags);
@@ -129,9 +139,11 @@ bacon_time_label_set_time (BaconTimeLabel *label,
length == -1)
return;
- if (_time / 1000 == label->time / 1000 &&
- length / 1000 == label->length / 1000)
- return;
+ if (!label->show_msecs) {
+ if (_time / 1000 == label->time / 1000 &&
+ length / 1000 == label->length / 1000)
+ return;
+ }
label->time = _time;
label->length = length;
@@ -144,6 +156,7 @@ bacon_time_label_reset (BaconTimeLabel *label)
{
g_return_if_fail (BACON_IS_TIME_LABEL (label));
+ bacon_time_label_set_show_msecs (label, FALSE);
bacon_time_label_set_time (label, 0, 0);
}
@@ -156,3 +169,15 @@ bacon_time_label_set_remaining (BaconTimeLabel *label,
label->remaining = remaining;
update_label_text (label);
}
+
+void
+bacon_time_label_set_show_msecs (BaconTimeLabel *label,
+ gboolean show_msecs)
+{
+ g_return_if_fail (BACON_IS_TIME_LABEL (label));
+
+ if (show_msecs != label->show_msecs) {
+ label->show_msecs = show_msecs;
+ update_label_text (label);
+ }
+}
diff --git a/src/backend/bacon-time-label.h b/src/backend/bacon-time-label.h
index eb4e624c1..fd0819fef 100644
--- a/src/backend/bacon-time-label.h
+++ b/src/backend/bacon-time-label.h
@@ -33,6 +33,7 @@ void bacon_time_label_set_time (BaconTimeLabel *label,
gint64 length_msecs);
void bacon_time_label_reset (BaconTimeLabel *label);
-void
-bacon_time_label_set_remaining (BaconTimeLabel *label,
+void bacon_time_label_set_remaining (BaconTimeLabel *label,
gboolean remaining);
+void bacon_time_label_set_show_msecs (BaconTimeLabel *label,
+ gboolean show_msecs);
diff --git a/src/test-totem.c b/src/test-totem.c
index 7c2ec1f02..0eef26015 100644
--- a/src/test-totem.c
+++ b/src/test-totem.c
@@ -146,6 +146,33 @@ test_time_label (void)
50 * 60 * 1000, 45 * 60 * 1000,
"50:00", "--:--");
+ bacon_time_label_set_show_msecs (BACON_TIME_LABEL (label), TRUE);
+ bacon_time_label_set_show_msecs (BACON_TIME_LABEL (label_remaining), TRUE);
+
+ set_labels (label, label_remaining,
+ 0, 1000,
+ "0:00.000", "-0:01.000");
+
+ set_labels (label, label_remaining,
+ 500, 1000,
+ "0:00.500", "-0:00.500");
+
+ set_labels (label, label_remaining,
+ 700, 1400,
+ "0:00.700", "-0:00.700");
+
+ set_labels (label, label_remaining,
+ 1000, 1400,
+ "0:01.000", "-0:00.400");
+
+ set_labels (label, label_remaining,
+ 0, 45 * 60 * 1000,
+ "0:00.000", "-45:00.000");
+
+ set_labels (label, label_remaining,
+ 50 * 60 * 1000, 45 * 60 * 1000,
+ "50:00.000", "--:--");
+
str = totem_time_to_string (0, TOTEM_TIME_FLAG_NONE);
g_assert_cmpstr (str, ==, "0:00");
g_free (str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]