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 --- include/datetime/clock.h | 4 ++-- src/clock-live.cpp | 31 ++++++++++++++++--------------- src/main.cpp | 5 +++-- tests/test-clock.cpp | 31 ++++++++++++++++--------------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 1d488d1..c5c3105 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -71,7 +71,7 @@ private: **** ***/ -class Timezones; +class Timezone; /** * \brief A live #Clock that provides the actual system time. @@ -79,7 +79,7 @@ class Timezones; class LiveClock: public Clock { public: - LiveClock (const std::shared_ptr& zones); + LiveClock (const std::shared_ptr& zones); virtual ~LiveClock(); virtual DateTime localtime() const; 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; diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp index a4924b3..cbe13f3 100644 --- a/tests/test-clock.cpp +++ b/tests/test-clock.cpp @@ -18,9 +18,10 @@ */ #include -#include +#include #include "test-dbus-fixture.h" +#include "timezone-mock.h" /*** **** @@ -49,9 +50,9 @@ class ClockFixture: public TestDBusFixture TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) { // start up a live clock - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); wait_msec(500); // wait for the bus to set up // count how many times clock.minute_changed() is emitted over the next minute @@ -74,17 +75,17 @@ TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) TEST_F(ClockFixture, HelloFixture) { - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); } TEST_F(ClockFixture, TimezoneChangeTriggersSkew) { - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); auto tz_nyc = g_time_zone_new("America/New_York"); auto now_nyc = g_date_time_new_now(tz_nyc); @@ -99,9 +100,9 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) g_main_loop_quit(loop); }); g_idle_add([](gpointer gs){ - static_cast(gs)->timezone.set("America/Los_Angeles"); + static_cast(gs)->timezone.set("America/Los_Angeles"); return G_SOURCE_REMOVE; - }, zones.get()); + }, timezone_.get()); g_main_loop_run(loop); auto tz_la = g_time_zone_new("America/Los_Angeles"); @@ -118,9 +119,9 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) */ TEST_F(ClockFixture, SleepTriggersSkew) { - std::shared_ptr zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); wait_msec(500); // wait for the bus to set up bool skewed = false; -- cgit v1.2.3