From 3b8833efe6ab21387b6f73b4a4ef757445801623 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 17 Dec 2013 22:10:18 -0600 Subject: add geoclue, glib test fixtures --- src/timezones-live.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/timezones-live.cpp (limited to 'src/timezones-live.cpp') diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp new file mode 100644 index 0000000..cb5e2bc --- /dev/null +++ b/src/timezones-live.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +LiveTimezones::LiveTimezones (const std::string& filename): + file_ (filename) +{ + file_.timezone.changed().connect([this](const std::string&){updateTimezones();}); + + geolocationEnabled.changed().connect([this](bool){updateGeolocation();}); + updateGeolocation(); + + updateTimezones(); +} + +void +LiveTimezones::updateGeolocation() +{ + geo_.reset(); + + if (geolocationEnabled.get()) + { + GeoclueTimezone * geo = new GeoclueTimezone(); + geo->timezone.changed().connect([this](const std::string&){updateTimezones();}); + geo_.reset(geo); + } +} + +void +LiveTimezones::updateTimezones() +{ + const std::string a = file_.timezone.get(); + const std::string b = geo_ ? geo_->timezone.get() : ""; + + timezone.set (a.empty() ? b : a); + + std::set zones; + if (!a.empty()) + zones.insert(a); + if (!b.empty()) + zones.insert(b); + timezones.set(zones); +} + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 From ee64bb2698adfe27e55615a8856b0e2c78ad8469 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Jan 2014 23:07:10 -0600 Subject: Function: add fully-tested ActionGroups, per-profile Menus, state object. Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again --- src/timezones-live.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/timezones-live.cpp') diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp index cb5e2bc..dc14021 100644 --- a/src/timezones-live.cpp +++ b/src/timezones-live.cpp @@ -24,37 +24,35 @@ namespace unity { namespace indicator { namespace datetime { -LiveTimezones::LiveTimezones (const std::string& filename): - file_ (filename) +LiveTimezones::LiveTimezones(const std::string& filename): + m_file(filename) { - file_.timezone.changed().connect([this](const std::string&){updateTimezones();}); + m_file.timezone.changed().connect([this](const std::string&){update_timezones();}); - geolocationEnabled.changed().connect([this](bool){updateGeolocation();}); - updateGeolocation(); + geolocation_enabled.changed().connect([this](bool){update_geolocation();}); + update_geolocation(); - updateTimezones(); + update_timezones(); } -void -LiveTimezones::updateGeolocation() +void LiveTimezones::update_geolocation() { - geo_.reset(); + m_geo.reset(); - if (geolocationEnabled.get()) + if(geolocation_enabled.get()) { - GeoclueTimezone * geo = new GeoclueTimezone(); - geo->timezone.changed().connect([this](const std::string&){updateTimezones();}); - geo_.reset(geo); + auto geo = new GeoclueTimezone(); + geo->timezone.changed().connect([this](const std::string&){update_timezones();}); + m_geo.reset(geo); } } -void -LiveTimezones::updateTimezones() +void LiveTimezones::update_timezones() { - const std::string a = file_.timezone.get(); - const std::string b = geo_ ? geo_->timezone.get() : ""; + const auto a = m_file.timezone.get(); + const auto b = m_geo ? m_geo->timezone.get() : ""; - timezone.set (a.empty() ? b : a); + timezone.set(a.empty() ? b : a); std::set zones; if (!a.empty()) -- cgit v1.2.3 From 40689ea36c360cb6fb42048f5d93303237745b86 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 17:42:43 -0600 Subject: update timezones-live to use Settings to tell when the user has enabled/disabled GeoClue lookups --- src/timezones-live.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/timezones-live.cpp') diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp index dc14021..baac05d 100644 --- a/src/timezones-live.cpp +++ b/src/timezones-live.cpp @@ -18,18 +18,20 @@ */ #include + #include namespace unity { namespace indicator { namespace datetime { -LiveTimezones::LiveTimezones(const std::string& filename): - m_file(filename) +LiveTimezones::LiveTimezones(std::shared_ptr& settings, const std::string& filename): + m_file(filename), + m_settings(settings) { m_file.timezone.changed().connect([this](const std::string&){update_timezones();}); - geolocation_enabled.changed().connect([this](bool){update_geolocation();}); + m_settings->show_detected_location.changed().connect([this](bool){update_geolocation();}); update_geolocation(); update_timezones(); @@ -37,9 +39,11 @@ LiveTimezones::LiveTimezones(const std::string& filename): void LiveTimezones::update_geolocation() { + // clear the previous pointer, if any m_geo.reset(); - if(geolocation_enabled.get()) + // if location detection is enabled, turn on GeoClue + if(m_settings->show_detected_location.get()) { auto geo = new GeoclueTimezone(); geo->timezone.changed().connect([this](const std::string&){update_timezones();}); -- cgit v1.2.3 From 197309468247c893bdaa37ef47a98db695b2ea78 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:44:12 -0600 Subject: following on the review comment covered in the last commit, use shared_ptr instead of shared_ptr where possible. --- src/timezones-live.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/timezones-live.cpp') diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp index baac05d..4902b76 100644 --- a/src/timezones-live.cpp +++ b/src/timezones-live.cpp @@ -25,7 +25,8 @@ namespace unity { namespace indicator { namespace datetime { -LiveTimezones::LiveTimezones(std::shared_ptr& settings, const std::string& filename): +LiveTimezones::LiveTimezones(const std::shared_ptr& settings, + const std::string& filename): m_file(filename), m_settings(settings) { -- cgit v1.2.3