Merge lp:~benwaffle/granite/am-pm-modebutton into lp:~elementary-pantheon/granite/granite

Proposed by Ben
Status: Merged
Approved by: Danielle Foré
Approved revision: 927
Merged at revision: 929
Proposed branch: lp:~benwaffle/granite/am-pm-modebutton
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 140 lines (+28/-40)
1 file modified
lib/Widgets/TimePicker.vala (+28/-40)
To merge this branch: bzr merge lp:~benwaffle/granite/am-pm-modebutton
Reviewer Review Type Date Requested Status
Corentin Noël code Approve
Review via email: mp+283250@code.launchpad.net

Commit message

TimePicker: use a ModeButton for AM/PM

Description of the change

TimePicker: use a ModeButton for AM/PM

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

Please use no_show_all instead of creating a temporary variable and hiding the widget afterwards.

review: Needs Fixing
Revision history for this message
Corentin Noël (tintou) wrote :

I can't tell if it's behaving properly as AM/PM doesn't exist here in my country but all I can say is that the code looks fine!

review: Approve (code)
Revision history for this message
Danielle Foré (danrabbit) wrote :

Looks like this checks against org.gnome.desktop.interface clock-format. Are we sure this is the best check? It doesn't look like it's being set. Is this a bug in the way locale is set or is this key maybe deprecated?

Revision history for this message
RabbitBot (rabbitbot-a) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/TimePicker.vala'
2--- lib/Widgets/TimePicker.vala 2014-09-04 12:39:00 +0000
3+++ lib/Widgets/TimePicker.vala 2016-02-09 02:10:11 +0000
4@@ -50,16 +50,7 @@
5 public GLib.DateTime time {
6 get {
7 if (_time == null) {
8- _time = new GLib.DateTime.now_local ();
9- changing_time = true;
10- if (_time.get_hour () > 12) {
11- am_pm_switch.active = true;
12- } else {
13- am_pm_switch.active = false;
14- }
15-
16- update_text (true);
17- changing_time = false;
18+ time = new GLib.DateTime.now_local ();
19 }
20
21 return _time;
22@@ -69,10 +60,10 @@
23 _time = value;
24 changing_time = true;
25
26- if (_time.get_hour () > 12) {
27- am_pm_switch.active = true;
28+ if (_time.get_hour () >= 12) {
29+ am_pm_modebutton.selected = 1;
30 } else {
31- am_pm_switch.active = false;
32+ am_pm_modebutton.selected = 0;
33 }
34
35 update_text (true);
36@@ -84,8 +75,7 @@
37
38 private Gtk.SpinButton hours_spinbutton;
39 private Gtk.SpinButton minutes_spinbutton;
40- private Gtk.Switch am_pm_switch;
41- private Gtk.Grid am_pm_grid;
42+ private ModeButton am_pm_modebutton;
43 private bool changing_time = false;
44
45 private Gtk.Popover popover;
46@@ -106,31 +96,29 @@
47 pop_grid.column_spacing = 6;
48 pop_grid.row_spacing = 6;
49
50- am_pm_grid = new Gtk.Grid ();
51- am_pm_grid.column_spacing = 6;
52- am_pm_grid.no_show_all = true;
53-
54- am_pm_switch = new Gtk.Switch ();
55- am_pm_switch.notify["active"].connect (() => {
56- if (changing_time == true) {
57+ am_pm_modebutton = new ModeButton ();
58+ am_pm_modebutton.orientation = Gtk.Orientation.VERTICAL;
59+ am_pm_modebutton.no_show_all = true;
60+ /// TRANSLATORS: this will only show up when 12-hours clock is in use
61+ am_pm_modebutton.append_text (_("AM"));
62+ /// TRANSLATORS: this will only show up when 12-hours clock is in use
63+ am_pm_modebutton.append_text (_("PM"));
64+ am_pm_modebutton.mode_changed.connect (mode => {
65+ if (changing_time) {
66 return;
67 }
68
69- if (am_pm_switch.active == true) {
70+ if (am_pm_modebutton.selected == 0) {
71+ time = _time.add_hours (-12);
72+ } else if (am_pm_modebutton.selected == 1) {
73 time = _time.add_hours (12);
74 } else {
75- time = _time.add_hours (-12);
76+ assert_not_reached ();
77 }
78
79 update_text (true);
80 });
81-
82- /// TRANSLATORS: this will only show up when 12-hours clock is in use
83- var am_pm_label = new Gtk.Label (_("PM"));
84- am_pm_label.hexpand = true;
85- am_pm_label.justify = Gtk.Justification.RIGHT;
86- am_pm_grid.attach (am_pm_switch, 0, 0, 1, 1);
87- am_pm_grid.attach (am_pm_label, 1, 0, 1, 1);
88+ am_pm_modebutton.hexpand = true;
89
90 if (Granite.DateTime.is_clock_format_12h ()) {
91 hours_spinbutton = new Gtk.SpinButton.with_range (1, 12, 1);
92@@ -151,7 +139,7 @@
93 pop_grid.attach (hours_spinbutton, 0, 0, 1, 1);
94 pop_grid.attach (separation_label, 1, 0, 1, 1);
95 pop_grid.attach (minutes_spinbutton, 2, 0, 1, 1);
96- pop_grid.attach (am_pm_grid, 0, 1, 3, 1);
97+ pop_grid.attach (am_pm_modebutton, 3, 0, 1, 1);
98 pop_grid.margin = MARGIN;
99
100 popover = new Gtk.Popover (this);
101@@ -205,13 +193,13 @@
102 var new_hour = hours_spinbutton.get_value_as_int () - time.get_hour ();
103
104 if (Granite.DateTime.is_clock_format_12h ()) {
105- if (hours_spinbutton.get_value_as_int () == 12 && am_pm_switch.active == false) {
106+ if (hours_spinbutton.get_value_as_int () == 12 && am_pm_modebutton.selected == 0) {
107 _time = _time.add_hours (-_time.get_hour ());
108- } else if (hours_spinbutton.get_value_as_int () < 12 && am_pm_switch.active == false) {
109+ } else if (hours_spinbutton.get_value_as_int () < 12 && am_pm_modebutton.selected == 0) {
110 _time = _time.add_hours (new_hour);
111- } else if (hours_spinbutton.get_value_as_int () == 12 && am_pm_switch.active == true) {
112+ } else if (hours_spinbutton.get_value_as_int () == 12 && am_pm_modebutton.selected == 1) {
113 _time = _time.add_hours (-_time.get_hour () + 12);
114- } else if (hours_spinbutton.get_value_as_int () < 12 && am_pm_switch.active == true) {
115+ } else if (hours_spinbutton.get_value_as_int () < 12 && am_pm_modebutton.selected == 1) {
116 _time = _time.add_hours (new_hour + 12);
117
118 if (time.get_hour () <= 12)
119@@ -236,18 +224,18 @@
120 hours_spinbutton.set_value (time.get_hour ());
121
122 if (Granite.DateTime.is_clock_format_12h ()) {
123- am_pm_grid.no_show_all = false;
124- am_pm_grid.show_all ();
125+ am_pm_modebutton.no_show_all = false;
126+ am_pm_modebutton.show_all ();
127
128 if (time.get_hour () > 12) {
129 hours_spinbutton.set_value (time.get_hour () - 12);
130 } else if (time.get_hour () == 0) {
131- hours_spinbutton.set_value (12);
132+ hours_spinbutton.set_value (12);
133 } else {
134 hours_spinbutton.set_value (time.get_hour ());
135 }
136 } else {
137- am_pm_grid.hide ();
138+ am_pm_modebutton.hide ();
139 hours_spinbutton.set_value (time.get_hour ());
140 }
141

Subscribers

People subscribed via source and target branches