Merge lp:~charlesk/indicator-datetime/lp-1332095-refresh-floating-alarms-when-timezone-changes into lp:indicator-datetime/13.10

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 381
Merged at revision: 378
Proposed branch: lp:~charlesk/indicator-datetime/lp-1332095-refresh-floating-alarms-when-timezone-changes
Merge into: lp:indicator-datetime/13.10
Diff against target: 278 lines (+56/-40)
6 files modified
include/datetime/clock.h (+2/-2)
src/clock-live.cpp (+16/-15)
src/main.cpp (+7/-7)
src/planner-range.cpp (+6/-1)
tests/manual (+9/-0)
tests/test-clock.cpp (+16/-15)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-1332095-refresh-floating-alarms-when-timezone-changes
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+234890@code.launchpad.net

Commit message

Adjust our floating alarms when the local timezone changes.

Description of the change

== Description of the Change

When our timezone changes, re-query EDS for alarms. This will keep the 'floating' (i.e., kick at 6:30 am, regardless of what timezone you're in) alarms in sync with the current timezone.

== Checklist

> Are there any related MPs required for this MP to build/function as expected? Please list.

No

> Is your branch in sync with latest trunk? (e.g. bzr pull lp:trunk -> no changes)

Yes

> Did the code build without warnings?

Yes

> Did the tests run successfully?

Yes

> Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

> If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

> What device (or emulator) has your component test plan been executed successfully on?

mako + RTM r41

> What manual tests are relevant for this MP?

indicator-datetime/alarm-timezone (added in this MP)

> Did you include a link to the MR Review Checklist Template to make your reviewer's life easier?

https://wiki.ubuntu.com/Process/Merges/Checklists/indicator-datetime

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Makes sense to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/datetime/clock.h'
2--- include/datetime/clock.h 2014-09-13 18:12:04 +0000
3+++ include/datetime/clock.h 2014-09-16 21:33:33 +0000
4@@ -68,7 +68,7 @@
5 ****
6 ***/
7
8-class Timezones;
9+class Timezone;
10
11 /**
12 * \brief A live #Clock that provides the actual system time.
13@@ -76,7 +76,7 @@
14 class LiveClock: public Clock
15 {
16 public:
17- LiveClock (const std::shared_ptr<const Timezones>& zones);
18+ LiveClock (const std::shared_ptr<const Timezone>& zones);
19 virtual ~LiveClock();
20 virtual DateTime localtime() const;
21
22
23=== modified file 'src/clock-live.cpp'
24--- src/clock-live.cpp 2014-01-31 00:33:14 +0000
25+++ src/clock-live.cpp 2014-09-16 21:33:33 +0000
26@@ -18,7 +18,7 @@
27 */
28
29 #include <datetime/clock.h>
30-#include <datetime/timezones.h>
31+#include <datetime/timezone.h>
32
33 namespace unity {
34 namespace indicator {
35@@ -59,14 +59,15 @@
36 {
37 public:
38
39- Impl(LiveClock& owner, const std::shared_ptr<const Timezones>& tzd):
40+ Impl(LiveClock& owner, const std::shared_ptr<const Timezone>& timezone_):
41 m_owner(owner),
42- m_timezones(tzd)
43+ m_timezone(timezone_)
44 {
45- if (m_timezones)
46+ if (m_timezone)
47 {
48- m_timezones->timezone.changed().connect([this](const std::string& z) {setTimezone(z);});
49- setTimezone(m_timezones->timezone.get());
50+ auto setter = [this](const std::string& z){setTimezone(z);};
51+ m_timezone->timezone.changed().connect(setter);
52+ setter(m_timezone->timezone.get());
53 }
54
55 restart_minute_timer();
56@@ -76,14 +77,14 @@
57 {
58 clearTimer(m_timer);
59
60- g_clear_pointer(&m_timezone, g_time_zone_unref);
61+ g_clear_pointer(&m_gtimezone, g_time_zone_unref);
62 }
63
64 DateTime localtime() const
65 {
66- g_assert(m_timezone != nullptr);
67+ g_assert(m_gtimezone != nullptr);
68
69- auto gdt = g_date_time_new_now(m_timezone);
70+ auto gdt = g_date_time_new_now(m_gtimezone);
71 DateTime ret(gdt);
72 g_date_time_unref(gdt);
73 return ret;
74@@ -93,8 +94,8 @@
75
76 void setTimezone(const std::string& str)
77 {
78- g_clear_pointer(&m_timezone, g_time_zone_unref);
79- m_timezone = g_time_zone_new(str.c_str());
80+ g_clear_pointer(&m_gtimezone, g_time_zone_unref);
81+ m_gtimezone = g_time_zone_new(str.c_str());
82 m_owner.minute_changed();
83 }
84
85@@ -134,15 +135,15 @@
86 protected:
87
88 LiveClock& m_owner;
89- GTimeZone* m_timezone = nullptr;
90- std::shared_ptr<const Timezones> m_timezones;
91+ GTimeZone* m_gtimezone = nullptr;
92+ std::shared_ptr<const Timezone> m_timezone;
93
94 DateTime m_prev_datetime;
95 unsigned int m_timer = 0;
96 };
97
98-LiveClock::LiveClock(const std::shared_ptr<const Timezones>& tzd):
99- p(new Impl(*this, tzd))
100+LiveClock::LiveClock(const std::shared_ptr<const Timezone>& timezone_):
101+ p(new Impl(*this, timezone_))
102 {
103 }
104
105
106=== modified file 'src/main.cpp'
107--- src/main.cpp 2014-09-02 16:16:01 +0000
108+++ src/main.cpp 2014-09-16 21:33:33 +0000
109@@ -63,20 +63,20 @@
110 }
111
112 std::shared_ptr<State> create_state(const std::shared_ptr<Engine>& engine,
113- const std::shared_ptr<Timezone>& tz)
114+ const std::shared_ptr<Timezone>& timezone_)
115 {
116 // create the live objects
117 auto live_settings = std::make_shared<LiveSettings>();
118 auto live_timezones = std::make_shared<LiveTimezones>(live_settings, TIMEZONE_FILE);
119- auto live_clock = std::make_shared<LiveClock>(live_timezones);
120+ auto live_clock = std::make_shared<LiveClock>(timezone_);
121
122 // create a full-month planner currently pointing to the current month
123 const auto now = live_clock->localtime();
124- auto range_planner = std::make_shared<SimpleRangePlanner>(engine, tz);
125+ auto range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_);
126 auto calendar_month = std::make_shared<MonthPlanner>(range_planner, now);
127
128 // create an upcoming-events planner currently pointing to the current date
129- range_planner = std::make_shared<SimpleRangePlanner>(engine, tz);
130+ range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_);
131 auto calendar_upcoming = std::make_shared<UpcomingPlanner>(range_planner, now);
132
133 // create the state
134@@ -127,8 +127,8 @@
135 textdomain(GETTEXT_PACKAGE);
136
137 auto engine = create_engine();
138- auto timezone = std::make_shared<FileTimezone>(TIMEZONE_FILE);
139- auto state = create_state(engine, timezone);
140+ auto timezone_ = std::make_shared<FileTimezone>(TIMEZONE_FILE);
141+ auto state = create_state(engine, timezone_);
142 auto actions = std::make_shared<LiveActions>(state);
143 MenuFactory factory(actions, state);
144
145@@ -136,7 +136,7 @@
146 auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock);
147 auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
148 std::unique_ptr<Snap> snap (new Snap(notification_engine, state->settings));
149- auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone);
150+ auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_);
151 auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);};
152 auto on_ok = [](const Appointment&){};
153 auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);};
154
155=== modified file 'src/planner-range.cpp'
156--- src/planner-range.cpp 2014-04-25 03:34:42 +0000
157+++ src/planner-range.cpp 2014-09-16 21:33:33 +0000
158@@ -28,7 +28,7 @@
159 ***/
160
161 SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr<Engine>& engine,
162- const std::shared_ptr<Timezone>& timezone):
163+ const std::shared_ptr<Timezone>& timezone):
164 m_engine(engine),
165 m_timezone(timezone),
166 m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal()))
167@@ -38,6 +38,11 @@
168 rebuild_soon();
169 });
170
171+ m_timezone->timezone.changed().connect([this](const std::string& s){
172+ g_debug("RangePlanner %p rebuilding soon because the timezone changed to '%s'", this, s.c_str());
173+ rebuild_soon();
174+ });
175+
176 range().changed().connect([this](const std::pair<DateTime,DateTime>&){
177 g_debug("rebuilding because the date range changed");
178 rebuild_soon();
179
180=== modified file 'tests/manual'
181--- tests/manual 2014-09-15 17:02:50 +0000
182+++ tests/manual 2014-09-16 21:33:33 +0000
183@@ -40,6 +40,15 @@
184 <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd>
185 </dl>
186
187+Test-case indicator-datetime/alarm-timezone
188+<dl>
189+ <dt>In ubuntu-system-settings, change your timezone to a zone you're not in</dt>
190+ <dt>In ubuntu-clock-app, create and save an upcoming alarm</dt>
191+ <dd>The indicator's menu should show the alarm to click at the specified time</dd>
192+ <dt>In ubuntu-system-settings, change back to your correct timezone</dt>
193+ <dd>The indicator's menu should still show the alarm to click at the specified time</dd>
194+</dl>
195+
196 Test-case indicator-datetime/snooze
197 <dl>
198 <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt>
199
200=== modified file 'tests/test-clock.cpp'
201--- tests/test-clock.cpp 2014-09-15 19:49:20 +0000
202+++ tests/test-clock.cpp 2014-09-16 21:33:33 +0000
203@@ -19,11 +19,12 @@
204
205 #include <datetime/clock.h>
206 #include <datetime/clock-mock.h>
207-#include <datetime/timezones.h>
208+#include <datetime/timezone.h>
209
210 #include <notifications/dbus-shared.h>
211
212 #include "test-dbus-fixture.h"
213+#include "timezone-mock.h"
214
215 /***
216 ****
217@@ -40,9 +41,9 @@
218 TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute)
219 {
220 // start up a live clock
221- std::shared_ptr<Timezones> zones(new Timezones);
222- zones->timezone.set("America/New_York");
223- LiveClock clock(zones);
224+ auto timezone_ = std::make_shared<MockTimezone>();
225+ timezone_->timezone.set("America/New_York");
226+ LiveClock clock(timezone_);
227 wait_msec(500); // wait for the bus to set up
228
229 // count how many times clock.minute_changed() is emitted over the next minute
230@@ -65,17 +66,17 @@
231
232 TEST_F(ClockFixture, HelloFixture)
233 {
234- std::shared_ptr<Timezones> zones(new Timezones);
235- zones->timezone.set("America/New_York");
236- LiveClock clock(zones);
237+ auto timezone_ = std::make_shared<MockTimezone>();
238+ timezone_->timezone.set("America/New_York");
239+ LiveClock clock(timezone_);
240 }
241
242
243 TEST_F(ClockFixture, TimezoneChangeTriggersSkew)
244 {
245- std::shared_ptr<Timezones> zones(new Timezones);
246- zones->timezone.set("America/New_York");
247- LiveClock clock(zones);
248+ auto timezone_ = std::make_shared<MockTimezone>();
249+ timezone_->timezone.set("America/New_York");
250+ LiveClock clock(timezone_);
251
252 auto tz_nyc = g_time_zone_new("America/New_York");
253 auto now_nyc = g_date_time_new_now(tz_nyc);
254@@ -90,9 +91,9 @@
255 g_main_loop_quit(loop);
256 });
257 g_idle_add([](gpointer gs){
258- static_cast<Timezones*>(gs)->timezone.set("America/Los_Angeles");
259+ static_cast<Timezone*>(gs)->timezone.set("America/Los_Angeles");
260 return G_SOURCE_REMOVE;
261- }, zones.get());
262+ }, timezone_.get());
263 g_main_loop_run(loop);
264
265 auto tz_la = g_time_zone_new("America/Los_Angeles");
266@@ -130,9 +131,9 @@
267 */
268 TEST_F(ClockFixture, SleepTriggersSkew)
269 {
270- std::shared_ptr<Timezones> zones(new Timezones);
271- zones->timezone.set("America/New_York");
272- LiveClock clock(zones);
273+ auto timezone_ = std::make_shared<MockTimezone>();
274+ timezone_->timezone.set("America/New_York");
275+ LiveClock clock(timezone_);
276 wait_msec(250); // wait for the bus to set up
277
278 bool skewed = false;

Subscribers

People subscribed via source and target branches