From dc501b4b28452b097da0703cc77867377340ed13 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 16 Sep 2014 14:55:30 -0500 Subject: LiveClock only needs one Timezone, so give it that instead of a Timezones object --- src/clock-live.cpp | 31 ++++++++++++++++--------------- src/main.cpp | 5 +++-- 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/clock-live.cpp b/src/clock-live.cpp index 21a18a3..68a8a8b 100644 --- a/src/clock-live.cpp +++ b/src/clock-live.cpp @@ -18,7 +18,7 @@ */ #include -#include +#include namespace unity { namespace indicator { @@ -59,14 +59,15 @@ class LiveClock::Impl { public: - Impl(LiveClock& owner, const std::shared_ptr& tzd): + Impl(LiveClock& owner, const std::shared_ptr& timezone_): m_owner(owner), - m_timezones(tzd) + m_timezone(timezone_) { - if (m_timezones) + if (m_timezone) { - m_timezones->timezone.changed().connect([this](const std::string& z) {setTimezone(z);}); - setTimezone(m_timezones->timezone.get()); + auto setter = [this](const std::string& z){setTimezone(z);}; + m_timezone->timezone.changed().connect(setter); + setter(m_timezone->timezone.get()); } restart_minute_timer(); @@ -76,14 +77,14 @@ public: { clearTimer(m_timer); - g_clear_pointer(&m_timezone, g_time_zone_unref); + g_clear_pointer(&m_gtimezone, g_time_zone_unref); } DateTime localtime() const { - g_assert(m_timezone != nullptr); + g_assert(m_gtimezone != nullptr); - auto gdt = g_date_time_new_now(m_timezone); + auto gdt = g_date_time_new_now(m_gtimezone); DateTime ret(gdt); g_date_time_unref(gdt); return ret; @@ -93,8 +94,8 @@ private: void setTimezone(const std::string& str) { - g_clear_pointer(&m_timezone, g_time_zone_unref); - m_timezone = g_time_zone_new(str.c_str()); + g_clear_pointer(&m_gtimezone, g_time_zone_unref); + m_gtimezone = g_time_zone_new(str.c_str()); m_owner.minute_changed(); } @@ -134,15 +135,15 @@ private: protected: LiveClock& m_owner; - GTimeZone* m_timezone = nullptr; - std::shared_ptr m_timezones; + GTimeZone* m_gtimezone = nullptr; + std::shared_ptr m_timezone; DateTime m_prev_datetime; unsigned int m_timer = 0; }; -LiveClock::LiveClock(const std::shared_ptr& tzd): - p(new Impl(*this, tzd)) +LiveClock::LiveClock(const std::shared_ptr& timezone_): + p(new Impl(*this, timezone_)) { } diff --git a/src/main.cpp b/src/main.cpp index 54517c9..08d6dc1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,8 +67,8 @@ namespace { // create the live objects auto live_settings = std::make_shared(); - auto live_timezones = std::make_shared(live_settings, TIMEZONE_FILE); - auto live_clock = std::make_shared(live_timezones); + auto timezone_ = std::make_shared(TIMEZONE_FILE); + auto live_clock = std::make_shared(timezone_); // create a full-month planner currently pointing to the current month const auto now = live_clock->localtime(); @@ -80,6 +80,7 @@ namespace auto calendar_upcoming = std::make_shared(range_planner, now); // create the state + auto live_timezones = std::make_shared(live_settings, TIMEZONE_FILE); auto state = std::make_shared(); state->settings = live_settings; state->clock = live_clock; -- cgit v1.2.3 From 13fd249f0f4ff0aece96ae5925be76c8d7ca089e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 16 Sep 2014 15:13:16 -0500 Subject: in main.cpp, reuse the existing FileTimezone so that we don't have an unneccessary extra one --- src/main.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 08d6dc1..c16cb20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,20 +63,19 @@ namespace } std::shared_ptr create_state(const std::shared_ptr& engine, - const std::shared_ptr& tz) + const std::shared_ptr& timezone_) { // create the live objects auto live_settings = std::make_shared(); - auto timezone_ = std::make_shared(TIMEZONE_FILE); auto live_clock = std::make_shared(timezone_); // create a full-month planner currently pointing to the current month const auto now = live_clock->localtime(); - auto range_planner = std::make_shared(engine, tz); + auto range_planner = std::make_shared(engine, timezone_); auto calendar_month = std::make_shared(range_planner, now); // create an upcoming-events planner currently pointing to the current date - range_planner = std::make_shared(engine, tz); + range_planner = std::make_shared(engine, timezone_); auto calendar_upcoming = std::make_shared(range_planner, now); // create the state @@ -128,8 +127,8 @@ main(int /*argc*/, char** /*argv*/) textdomain(GETTEXT_PACKAGE); auto engine = create_engine(); - auto timezone = std::make_shared(TIMEZONE_FILE); - auto state = create_state(engine, timezone); + auto timezone_ = std::make_shared(TIMEZONE_FILE); + auto state = create_state(engine, timezone_); auto actions = std::make_shared(state); MenuFactory factory(actions, state); @@ -137,7 +136,7 @@ main(int /*argc*/, char** /*argv*/) auto snooze_planner = std::make_shared(state->settings, state->clock); auto notification_engine = std::make_shared("indicator-datetime-service"); std::unique_ptr snap (new Snap(notification_engine, state->settings)); - auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone); + auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone_); auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);}; auto on_ok = [](const Appointment&){}; auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);}; -- cgit v1.2.3 From 6863994ff1cb0aa2df940d94e88dbf324ece8132 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 16 Sep 2014 15:14:39 -0500 Subject: in SimpleRangePlanner, re-query the engine for appointments when the local timezone changes. --- src/planner-range.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/planner-range.cpp b/src/planner-range.cpp index 41b0f56..c223665 100644 --- a/src/planner-range.cpp +++ b/src/planner-range.cpp @@ -28,7 +28,7 @@ namespace datetime { ***/ SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr& engine, - const std::shared_ptr& timezone): + const std::shared_ptr& timezone): m_engine(engine), m_timezone(timezone), m_range(std::pair(DateTime::NowLocal(), DateTime::NowLocal())) @@ -38,6 +38,11 @@ SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr& engine, rebuild_soon(); }); + m_timezone->timezone.changed().connect([this](const std::string& s){ + g_debug("RangePlanner %p rebuilding soon because the timezone changed to '%s'", this, s.c_str()); + rebuild_soon(); + }); + range().changed().connect([this](const std::pair&){ g_debug("rebuilding because the date range changed"); rebuild_soon(); -- cgit v1.2.3 From 8da361db324d454ee9910ea3e169f428d32a925a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 16 Sep 2014 15:25:52 -0500 Subject: copyediting: move line to remove unnecessary diff from trunk --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index c16cb20..aa8f829 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,6 +67,7 @@ namespace { // create the live objects auto live_settings = std::make_shared(); + auto live_timezones = std::make_shared(live_settings, TIMEZONE_FILE); auto live_clock = std::make_shared(timezone_); // create a full-month planner currently pointing to the current month @@ -79,7 +80,6 @@ namespace auto calendar_upcoming = std::make_shared(range_planner, now); // create the state - auto live_timezones = std::make_shared(live_settings, TIMEZONE_FILE); auto state = std::make_shared(); state->settings = live_settings; state->clock = live_clock; -- cgit v1.2.3