[california/wip/725783-time] Honor 24-hour time throughout create/update event deck



commit 8fb70076eb078abc87a8626a9c826115823807c9
Author: Jim Nelson <jim yorba org>
Date:   Mon Aug 4 15:48:05 2014 -0700

    Honor 24-hour time throughout create/update event deck

 src/host/host-create-update-event.vala |   32 ++++++++++++++++++++------------
 src/host/host-date-time-widget.vala    |   18 +++++++++++++++++-
 src/host/host-event-time-settings.vala |    6 ++++++
 3 files changed, 43 insertions(+), 13 deletions(-)
---
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 1fffb56..bcd2c3e 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -113,6 +113,12 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
         rotating_button_box.halign = Gtk.Align.FILL;
         rotating_button_box.valign = Gtk.Align.END;
         rotating_button_box_container.add(rotating_button_box);
+        
+        Calendar.System.instance.is_24hr_changed.connect(on_update_time_summary);
+    }
+    
+    ~CreateUpdateEvent() {
+        Calendar.System.instance.is_24hr_changed.disconnect(on_update_time_summary);
     }
     
     private bool transform_summary_to_accept(Binding binding, Value source_value, ref Value target_value) {
@@ -127,10 +133,8 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
             return;
         
         if (message.type() == typeof(EventTimeSettings.Message)) {
-            debug("is message");
             dt = (EventTimeSettings.Message) message;
         } else {
-            debug("is event");
             event = (Component.Event) message;
             if (dt == null)
                 dt = new EventTimeSettings.Message.from_event(event);
@@ -145,16 +149,7 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
         else
             summary_entry.text = "";
         
-        // use the Message, not the Event, to load this up
-        time_summary_label.visible = true;
-        if (dt.date_span != null) {
-            time_summary_label.label = dt.date_span.to_pretty_string(Calendar.Date.PrettyFlag.NONE);
-        } else if (dt.exact_time_span != null) {
-            time_summary_label.label = dt.exact_time_span.to_pretty_string(Calendar.Date.PrettyFlag.NONE,
-                Calendar.ExactTimeSpan.PrettyFlag.NONE);
-        } else {
-            time_summary_label.visible = false;
-        }
+        on_update_time_summary();
         
         // set combo to event's calendar
         if (event.calendar_source != null) {
@@ -175,6 +170,19 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
         original_calendar_source = event.calendar_source;
     }
     
+    private void on_update_time_summary() {
+        // use the Message, not the Event, to load this up
+        time_summary_label.visible = true;
+        if (dt.date_span != null) {
+            time_summary_label.label = dt.date_span.to_pretty_string(Calendar.Date.PrettyFlag.NONE);
+        } else if (dt.exact_time_span != null) {
+            time_summary_label.label = dt.exact_time_span.to_pretty_string(Calendar.Date.PrettyFlag.NONE,
+                Calendar.ExactTimeSpan.PrettyFlag.NONE);
+        } else {
+            time_summary_label.visible = false;
+        }
+    }
+    
     [GtkCallback]
     private void on_recurring_button_clicked() {
         // update the component with what's in the controls now
diff --git a/src/host/host-date-time-widget.vala b/src/host/host-date-time-widget.vala
index c14475b..b12859f 100644
--- a/src/host/host-date-time-widget.vala
+++ b/src/host/host-date-time-widget.vala
@@ -81,6 +81,14 @@ public class DateTimeWidget : Gtk.Box {
             hour_entry, colon_label, minutes_entry, meridiem_label));
         
         bind_bool_to_time_controls(PROP_ENABLE_DATE, iterate<Gtk.Widget>(calendar));
+        
+        // honor 24-hour time
+        Calendar.System.instance.is_24hr_changed.connect(system_24hr_changed);
+        system_24hr_changed();
+    }
+    
+    ~DateTimeWidget() {
+        Calendar.System.instance.is_24hr_changed.disconnect(system_24hr_changed);
     }
     
     private void bind_bool_to_time_controls(string property, California.Iterable<Gtk.Widget> time_widgets) {
@@ -217,12 +225,20 @@ public class DateTimeWidget : Gtk.Box {
     private void on_wall_time_changed() {
         disconnect_widget_signals();
         
-        hour_entry.text = "%d".printf(wall_time.12hour);
+        hour_entry.text = "%d".printf(Calendar.System.is_24hr ? wall_time.hour : wall_time.12hour);
         minutes_entry.text = "%02d".printf(wall_time.minute);
         meridiem_label.label = wall_time.is_pm ? Calendar.FMT_PM : Calendar.FMT_AM;
         
         connect_widget_signals();
     }
+    
+    private void system_24hr_changed() {
+        meridiem_label.visible = meridiem_up.visible = meridiem_down.visible = !Calendar.System.is_24hr;
+        meridiem_label.no_show_all = meridiem_up.no_show_all = meridiem_down.no_show_all = 
Calendar.System.is_24hr;
+        
+        // redo time widgets
+        on_wall_time_changed();
+    }
 }
 
 }
diff --git a/src/host/host-event-time-settings.vala b/src/host/host-event-time-settings.vala
index 8c9a365..885a7d6 100644
--- a/src/host/host-event-time-settings.vala
+++ b/src/host/host-event-time-settings.vala
@@ -87,6 +87,12 @@ public class EventTimeSettings : Gtk.Box, Toolkit.Card {
             BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
         all_day_checkbutton.bind_property("active", to_widget, DateTimeWidget.PROP_ENABLE_TIME,
             BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
+        
+        Calendar.System.instance.is_24hr_changed.connect(on_update_summary);
+    }
+    
+    ~EventTimeSettings() {
+        Calendar.System.instance.is_24hr_changed.disconnect(on_update_summary);
     }
     
     public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message_value) {


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