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
=== modified file 'include/datetime/clock.h'
--- include/datetime/clock.h 2014-09-13 18:12:04 +0000
+++ include/datetime/clock.h 2014-09-16 21:33:33 +0000
@@ -68,7 +68,7 @@
68****68****
69***/69***/
7070
71class Timezones;71class Timezone;
7272
73/**73/**
74 * \brief A live #Clock that provides the actual system time.74 * \brief A live #Clock that provides the actual system time.
@@ -76,7 +76,7 @@
76class LiveClock: public Clock76class LiveClock: public Clock
77{77{
78public:78public:
79 LiveClock (const std::shared_ptr<const Timezones>& zones);79 LiveClock (const std::shared_ptr<const Timezone>& zones);
80 virtual ~LiveClock();80 virtual ~LiveClock();
81 virtual DateTime localtime() const;81 virtual DateTime localtime() const;
8282
8383
=== modified file 'src/clock-live.cpp'
--- src/clock-live.cpp 2014-01-31 00:33:14 +0000
+++ src/clock-live.cpp 2014-09-16 21:33:33 +0000
@@ -18,7 +18,7 @@
18 */18 */
1919
20#include <datetime/clock.h>20#include <datetime/clock.h>
21#include <datetime/timezones.h>21#include <datetime/timezone.h>
2222
23namespace unity {23namespace unity {
24namespace indicator {24namespace indicator {
@@ -59,14 +59,15 @@
59{59{
60public:60public:
6161
62 Impl(LiveClock& owner, const std::shared_ptr<const Timezones>& tzd):62 Impl(LiveClock& owner, const std::shared_ptr<const Timezone>& timezone_):
63 m_owner(owner),63 m_owner(owner),
64 m_timezones(tzd)64 m_timezone(timezone_)
65 {65 {
66 if (m_timezones)66 if (m_timezone)
67 {67 {
68 m_timezones->timezone.changed().connect([this](const std::string& z) {setTimezone(z);});68 auto setter = [this](const std::string& z){setTimezone(z);};
69 setTimezone(m_timezones->timezone.get());69 m_timezone->timezone.changed().connect(setter);
70 setter(m_timezone->timezone.get());
70 }71 }
7172
72 restart_minute_timer();73 restart_minute_timer();
@@ -76,14 +77,14 @@
76 {77 {
77 clearTimer(m_timer);78 clearTimer(m_timer);
7879
79 g_clear_pointer(&m_timezone, g_time_zone_unref);80 g_clear_pointer(&m_gtimezone, g_time_zone_unref);
80 }81 }
8182
82 DateTime localtime() const83 DateTime localtime() const
83 {84 {
84 g_assert(m_timezone != nullptr);85 g_assert(m_gtimezone != nullptr);
8586
86 auto gdt = g_date_time_new_now(m_timezone);87 auto gdt = g_date_time_new_now(m_gtimezone);
87 DateTime ret(gdt);88 DateTime ret(gdt);
88 g_date_time_unref(gdt);89 g_date_time_unref(gdt);
89 return ret;90 return ret;
@@ -93,8 +94,8 @@
9394
94 void setTimezone(const std::string& str)95 void setTimezone(const std::string& str)
95 {96 {
96 g_clear_pointer(&m_timezone, g_time_zone_unref);97 g_clear_pointer(&m_gtimezone, g_time_zone_unref);
97 m_timezone = g_time_zone_new(str.c_str());98 m_gtimezone = g_time_zone_new(str.c_str());
98 m_owner.minute_changed();99 m_owner.minute_changed();
99 }100 }
100101
@@ -134,15 +135,15 @@
134protected:135protected:
135136
136 LiveClock& m_owner;137 LiveClock& m_owner;
137 GTimeZone* m_timezone = nullptr;138 GTimeZone* m_gtimezone = nullptr;
138 std::shared_ptr<const Timezones> m_timezones;139 std::shared_ptr<const Timezone> m_timezone;
139140
140 DateTime m_prev_datetime;141 DateTime m_prev_datetime;
141 unsigned int m_timer = 0;142 unsigned int m_timer = 0;
142};143};
143144
144LiveClock::LiveClock(const std::shared_ptr<const Timezones>& tzd):145LiveClock::LiveClock(const std::shared_ptr<const Timezone>& timezone_):
145 p(new Impl(*this, tzd))146 p(new Impl(*this, timezone_))
146{147{
147}148}
148149
149150
=== modified file 'src/main.cpp'
--- src/main.cpp 2014-09-02 16:16:01 +0000
+++ src/main.cpp 2014-09-16 21:33:33 +0000
@@ -63,20 +63,20 @@
63 }63 }
6464
65 std::shared_ptr<State> create_state(const std::shared_ptr<Engine>& engine,65 std::shared_ptr<State> create_state(const std::shared_ptr<Engine>& engine,
66 const std::shared_ptr<Timezone>& tz)66 const std::shared_ptr<Timezone>& timezone_)
67 {67 {
68 // create the live objects68 // create the live objects
69 auto live_settings = std::make_shared<LiveSettings>();69 auto live_settings = std::make_shared<LiveSettings>();
70 auto live_timezones = std::make_shared<LiveTimezones>(live_settings, TIMEZONE_FILE);70 auto live_timezones = std::make_shared<LiveTimezones>(live_settings, TIMEZONE_FILE);
71 auto live_clock = std::make_shared<LiveClock>(live_timezones);71 auto live_clock = std::make_shared<LiveClock>(timezone_);
7272
73 // create a full-month planner currently pointing to the current month73 // create a full-month planner currently pointing to the current month
74 const auto now = live_clock->localtime();74 const auto now = live_clock->localtime();
75 auto range_planner = std::make_shared<SimpleRangePlanner>(engine, tz);75 auto range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_);
76 auto calendar_month = std::make_shared<MonthPlanner>(range_planner, now);76 auto calendar_month = std::make_shared<MonthPlanner>(range_planner, now);
7777
78 // create an upcoming-events planner currently pointing to the current date78 // create an upcoming-events planner currently pointing to the current date
79 range_planner = std::make_shared<SimpleRangePlanner>(engine, tz);79 range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_);
80 auto calendar_upcoming = std::make_shared<UpcomingPlanner>(range_planner, now);80 auto calendar_upcoming = std::make_shared<UpcomingPlanner>(range_planner, now);
8181
82 // create the state82 // create the state
@@ -127,8 +127,8 @@
127 textdomain(GETTEXT_PACKAGE);127 textdomain(GETTEXT_PACKAGE);
128128
129 auto engine = create_engine();129 auto engine = create_engine();
130 auto timezone = std::make_shared<FileTimezone>(TIMEZONE_FILE);130 auto timezone_ = std::make_shared<FileTimezone>(TIMEZONE_FILE);
131 auto state = create_state(engine, timezone);131 auto state = create_state(engine, timezone_);
132 auto actions = std::make_shared<LiveActions>(state);132 auto actions = std::make_shared<LiveActions>(state);
133 MenuFactory factory(actions, state);133 MenuFactory factory(actions, state);
134134
@@ -136,7 +136,7 @@
136 auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock);136 auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock);
137 auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");137 auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
138 std::unique_ptr<Snap> snap (new Snap(notification_engine, state->settings));138 std::unique_ptr<Snap> snap (new Snap(notification_engine, state->settings));
139 auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone);139 auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_);
140 auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);};140 auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);};
141 auto on_ok = [](const Appointment&){};141 auto on_ok = [](const Appointment&){};
142 auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);};142 auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);};
143143
=== modified file 'src/planner-range.cpp'
--- src/planner-range.cpp 2014-04-25 03:34:42 +0000
+++ src/planner-range.cpp 2014-09-16 21:33:33 +0000
@@ -28,7 +28,7 @@
28***/28***/
2929
30SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr<Engine>& engine,30SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr<Engine>& engine,
31 const std::shared_ptr<Timezone>& timezone):31 const std::shared_ptr<Timezone>& timezone):
32 m_engine(engine),32 m_engine(engine),
33 m_timezone(timezone),33 m_timezone(timezone),
34 m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal()))34 m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal()))
@@ -38,6 +38,11 @@
38 rebuild_soon();38 rebuild_soon();
39 });39 });
4040
41 m_timezone->timezone.changed().connect([this](const std::string& s){
42 g_debug("RangePlanner %p rebuilding soon because the timezone changed to '%s'", this, s.c_str());
43 rebuild_soon();
44 });
45
41 range().changed().connect([this](const std::pair<DateTime,DateTime>&){46 range().changed().connect([this](const std::pair<DateTime,DateTime>&){
42 g_debug("rebuilding because the date range changed");47 g_debug("rebuilding because the date range changed");
43 rebuild_soon();48 rebuild_soon();
4449
=== modified file 'tests/manual'
--- tests/manual 2014-09-15 17:02:50 +0000
+++ tests/manual 2014-09-16 21:33:33 +0000
@@ -40,6 +40,15 @@
40 <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd>40 <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd>
41</dl>41</dl>
4242
43Test-case indicator-datetime/alarm-timezone
44<dl>
45 <dt>In ubuntu-system-settings, change your timezone to a zone you're not in</dt>
46 <dt>In ubuntu-clock-app, create and save an upcoming alarm</dt>
47 <dd>The indicator's menu should show the alarm to click at the specified time</dd>
48 <dt>In ubuntu-system-settings, change back to your correct timezone</dt>
49 <dd>The indicator's menu should still show the alarm to click at the specified time</dd>
50</dl>
51
43Test-case indicator-datetime/snooze52Test-case indicator-datetime/snooze
44<dl>53<dl>
45 <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt>54 <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt>
4655
=== modified file 'tests/test-clock.cpp'
--- tests/test-clock.cpp 2014-09-15 19:49:20 +0000
+++ tests/test-clock.cpp 2014-09-16 21:33:33 +0000
@@ -19,11 +19,12 @@
1919
20#include <datetime/clock.h>20#include <datetime/clock.h>
21#include <datetime/clock-mock.h>21#include <datetime/clock-mock.h>
22#include <datetime/timezones.h>22#include <datetime/timezone.h>
2323
24#include <notifications/dbus-shared.h>24#include <notifications/dbus-shared.h>
2525
26#include "test-dbus-fixture.h"26#include "test-dbus-fixture.h"
27#include "timezone-mock.h"
2728
28/***29/***
29****30****
@@ -40,9 +41,9 @@
40TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute)41TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute)
41{42{
42 // start up a live clock43 // start up a live clock
43 std::shared_ptr<Timezones> zones(new Timezones);44 auto timezone_ = std::make_shared<MockTimezone>();
44 zones->timezone.set("America/New_York");45 timezone_->timezone.set("America/New_York");
45 LiveClock clock(zones);46 LiveClock clock(timezone_);
46 wait_msec(500); // wait for the bus to set up47 wait_msec(500); // wait for the bus to set up
4748
48 // count how many times clock.minute_changed() is emitted over the next minute49 // count how many times clock.minute_changed() is emitted over the next minute
@@ -65,17 +66,17 @@
6566
66TEST_F(ClockFixture, HelloFixture)67TEST_F(ClockFixture, HelloFixture)
67{68{
68 std::shared_ptr<Timezones> zones(new Timezones);69 auto timezone_ = std::make_shared<MockTimezone>();
69 zones->timezone.set("America/New_York");70 timezone_->timezone.set("America/New_York");
70 LiveClock clock(zones);71 LiveClock clock(timezone_);
71}72}
7273
7374
74TEST_F(ClockFixture, TimezoneChangeTriggersSkew)75TEST_F(ClockFixture, TimezoneChangeTriggersSkew)
75{76{
76 std::shared_ptr<Timezones> zones(new Timezones);77 auto timezone_ = std::make_shared<MockTimezone>();
77 zones->timezone.set("America/New_York");78 timezone_->timezone.set("America/New_York");
78 LiveClock clock(zones);79 LiveClock clock(timezone_);
7980
80 auto tz_nyc = g_time_zone_new("America/New_York");81 auto tz_nyc = g_time_zone_new("America/New_York");
81 auto now_nyc = g_date_time_new_now(tz_nyc);82 auto now_nyc = g_date_time_new_now(tz_nyc);
@@ -90,9 +91,9 @@
90 g_main_loop_quit(loop);91 g_main_loop_quit(loop);
91 });92 });
92 g_idle_add([](gpointer gs){93 g_idle_add([](gpointer gs){
93 static_cast<Timezones*>(gs)->timezone.set("America/Los_Angeles");94 static_cast<Timezone*>(gs)->timezone.set("America/Los_Angeles");
94 return G_SOURCE_REMOVE;95 return G_SOURCE_REMOVE;
95 }, zones.get());96 }, timezone_.get());
96 g_main_loop_run(loop);97 g_main_loop_run(loop);
9798
98 auto tz_la = g_time_zone_new("America/Los_Angeles");99 auto tz_la = g_time_zone_new("America/Los_Angeles");
@@ -130,9 +131,9 @@
130 */131 */
131TEST_F(ClockFixture, SleepTriggersSkew)132TEST_F(ClockFixture, SleepTriggersSkew)
132{133{
133 std::shared_ptr<Timezones> zones(new Timezones);134 auto timezone_ = std::make_shared<MockTimezone>();
134 zones->timezone.set("America/New_York");135 timezone_->timezone.set("America/New_York");
135 LiveClock clock(zones);136 LiveClock clock(timezone_);
136 wait_msec(250); // wait for the bus to set up137 wait_msec(250); // wait for the bus to set up
137138
138 bool skewed = false;139 bool skewed = false;

Subscribers

People subscribed via source and target branches