[california] Honor GNOME 12/24-hour settings: Closes bgo#725766
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Honor GNOME 12/24-hour settings: Closes bgo#725766
- Date: Tue, 11 Mar 2014 18:57:10 +0000 (UTC)
commit ed10be7abb86e29276cd0c425e7b046624c3c17b
Author: Jim Nelson <jim yorba org>
Date: Tue Mar 11 11:56:06 2014 -0700
Honor GNOME 12/24-hour settings: Closes bgo#725766
src/calendar/calendar-system.vala | 23 +++++++++++++++++++++--
src/calendar/calendar-wall-time.vala | 22 ++++++++++++++++++----
src/calendar/calendar.vala | 8 ++++++++
src/host/host-show-event.vala | 9 +++++++++
src/view/month/month-cell.vala | 14 ++++++++++++++
5 files changed, 70 insertions(+), 6 deletions(-)
---
diff --git a/src/calendar/calendar-system.vala b/src/calendar/calendar-system.vala
index bcb452c..be1558b 100644
--- a/src/calendar/calendar-system.vala
+++ b/src/calendar/calendar-system.vala
@@ -16,6 +16,10 @@ namespace California.Calendar {
*/
public class System : BaseObject {
+ private const string CLOCK_FORMAT_SCHEMA = "org.gnome.desktop.interface";
+ private const string CLOCK_FORMAT_KEY = "clock-format";
+ private const string CLOCK_FORMAT_24H = "24h";
+
public static System instance { get; private set; }
/**
@@ -56,6 +60,13 @@ public class System : BaseObject {
private static DBus.Properties timedated_properties;
/**
+ * Fired when { link is_24hr} changes.
+ *
+ * This means the user has changed the their clock format configuration.
+ */
+ public signal void is_24hr_changed(bool new_is_24hr);
+
+ /**
* Fired when { link zone} changes.
*
* This generally indicates that the user has changed system time zone manually or that the
@@ -68,6 +79,8 @@ public class System : BaseObject {
*/
public signal void timezone_changed(Timezone new_timezone);
+ private Settings system_clock_format_schema = new Settings(CLOCK_FORMAT_SCHEMA);
+
private System() {
zone = new OlsonZone(timedated_service.timezone);
timezone = new Timezone(zone);
@@ -76,8 +89,14 @@ public class System : BaseObject {
// to be notified of changes as they occur
timedated_properties.properties_changed.connect(on_timedated_properties_changed);
- // TODO: Fetch and update from GNOME settings
- is_24hr = false;
+ is_24hr = system_clock_format_schema.get_string(CLOCK_FORMAT_KEY) == CLOCK_FORMAT_24H;
+ system_clock_format_schema.changed[CLOCK_FORMAT_KEY].connect(() => {
+ bool new_is_24hr = system_clock_format_schema.get_string(CLOCK_FORMAT_KEY) == CLOCK_FORMAT_24H;
+ if (new_is_24hr != is_24hr) {
+ is_24hr = new_is_24hr;
+ is_24hr_changed(is_24hr);
+ }
+ });
// TODO: Tie this into the event loop so it's properly updated
today = new Date.now(Timezone.local);
diff --git a/src/calendar/calendar-wall-time.vala b/src/calendar/calendar-wall-time.vala
index e9b23ab..ff93fae 100644
--- a/src/calendar/calendar-wall-time.vala
+++ b/src/calendar/calendar-wall-time.vala
@@ -256,18 +256,23 @@ public class WallTime : BaseObject, Gee.Comparable<WallTime>, Gee.Hashable<WallT
/**
* Returns a prettified, localized user-visible string.
+ *
+ * The string respects { link System.is_24hr}.
*/
public string to_pretty_string(PrettyFlag flags) {
bool include_sec = (flags & PrettyFlag.INCLUDE_SECONDS) != 0;
bool optional_min = (flags & PrettyFlag.OPTIONAL_MINUTES) != 0;
bool meridiem_post_only = (flags & PrettyFlag.MERIDIEM_POST_ONLY) != 0;
bool brief_meridiem = (flags & PrettyFlag.BRIEF_MERIDIEM) != 0;
+ bool is_24hr = System.is_24hr;
unowned string pm = brief_meridiem ? FMT_BRIEF_PM : FMT_PM;
unowned string am = brief_meridiem ? FMT_BRIEF_AM : FMT_AM;
unowned string meridiem;
- if (meridiem_post_only)
+ if (is_24hr)
+ meridiem = "";
+ else if (meridiem_post_only)
meridiem = is_pm ? pm : "";
else
meridiem = is_pm? pm : am;
@@ -276,10 +281,19 @@ public class WallTime : BaseObject, Gee.Comparable<WallTime>, Gee.Hashable<WallT
// isn't something that varies between locales, on the assumption that the user has
// specified 12-hour time to begin with
if (optional_min && minute == 0)
- return "%d%s".printf(12hour, meridiem);
+ return "%d%s".printf(is_24hr ? hour : 12hour, meridiem);
- if (!include_sec)
+ if (!include_sec) {
+ // hour and minutes only
+ if (is_24hr)
+ return FMT_24HOUR_MIN.printf(hour, minute);
+
return FMT_12HOUR_MIN_MERIDIEM.printf(12hour, minute, meridiem);
+ }
+
+ // the full package
+ if (is_24hr)
+ return FMT_24HOUR_MIN_SEC.printf(hour, minute, second);
return FMT_12HOUR_MIN_SEC_MERIDIEM.printf(12hour, minute, second, meridiem);
}
@@ -304,7 +318,7 @@ public class WallTime : BaseObject, Gee.Comparable<WallTime>, Gee.Hashable<WallT
}
public uint hash() {
- // since each unit is >= 60, give each 6 bits (2^6 = 64) of space
+ // since each unit is < 60, give each 6 bits (2^6 = 64) of space
return ((uint) hour << 12) | ((uint) minute << 6) | (uint) second;
}
diff --git a/src/calendar/calendar.vala b/src/calendar/calendar.vala
index 193c2d7..cafb6cb 100644
--- a/src/calendar/calendar.vala
+++ b/src/calendar/calendar.vala
@@ -36,6 +36,8 @@ private static unowned string FMT_PM;
private static unowned string FMT_BRIEF_PM;
private static unowned string FMT_12HOUR_MIN_MERIDIEM;
private static unowned string FMT_12HOUR_MIN_SEC_MERIDIEM;
+private static unowned string FMT_24HOUR_MIN;
+private static unowned string FMT_24HOUR_MIN_SEC;
public void init() throws Error {
if (!California.Unit.do_init(ref init_count))
@@ -124,6 +126,12 @@ public void init() throws Error {
/// format user settings to be honored)
FMT_12HOUR_MIN_SEC_MERIDIEM = _("%d:%02d:%02d%s");
+ /// The 24-hour time with minutes, i.e. "17:06"
+ FMT_24HOUR_MIN = _("%d:%02d");
+
+ /// The 24-hour time with minutes and seconds, i.e. "17:06:31"
+ FMT_24HOUR_MIN_SEC = _("%d:%02d:%02d");
+
// return LC_MESSAGES back to proper locale and return LANGUAGE environment variable
if (messages_locale != null)
Intl.setlocale(LocaleCategory.MESSAGES, messages_locale);
diff --git a/src/host/host-show-event.vala b/src/host/host-show-event.vala
index 83dedac..dd87d92 100644
--- a/src/host/host-show-event.vala
+++ b/src/host/host-show-event.vala
@@ -31,6 +31,15 @@ public class ShowEvent : Gtk.Grid, Interaction {
public ShowEvent(Component.Event event) {
this.event = event;
+ build_display();
+ Calendar.System.instance.is_24hr_changed.connect(build_display);
+ }
+
+ ~ShowEvent() {
+ Calendar.System.instance.is_24hr_changed.disconnect(build_display);
+ }
+
+ private void build_display() {
// Each string should end without whitespace; add_lf_lf will ensure each section is
// separated as long as there's preceding text
StringBuilder builder = new StringBuilder();
diff --git a/src/view/month/month-cell.vala b/src/view/month/month-cell.vala
index 587f42d..ff7e0d9 100644
--- a/src/view/month/month-cell.vala
+++ b/src/view/month/month-cell.vala
@@ -90,10 +90,15 @@ public class Cell : Gtk.EventBox {
notify["date"].connect(queue_draw);
notify["selected"].connect(queue_draw);
+ Calendar.System.instance.is_24hr_changed.connect(on_24hr_changed);
canvas.draw.connect(on_draw);
}
+ ~Cell() {
+ Calendar.System.instance.is_24hr_changed.disconnect(on_24hr_changed);
+ }
+
internal static void init() {
top_line_font = new Pango.FontDescription();
top_line_font.set_size(TOP_LINE_FONT_SIZE_PT * Pango.SCALE);
@@ -145,6 +150,15 @@ public class Cell : Gtk.EventBox {
queue_draw();
}
+ public bool has_events() {
+ return days_events.size > 0;
+ }
+
+ private void on_24hr_changed() {
+ if (has_events())
+ queue_draw();
+ }
+
private void on_span_updated(Object object, ParamSpec param) {
if (date == null)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]