diff options
46 files changed, 531 insertions, 405 deletions
diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 0bf48a8..0214d65 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,21 +36,21 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr<State>& state_in); - ~LiveActions() =default; + explicit LiveActions(const std::shared_ptr<State>& state_in); + virtual ~LiveActions() =default; - bool desktop_has_calendar_app() const; - void desktop_open_alarm_app(); - void desktop_open_appointment(const Appointment&); - void desktop_open_calendar_app(const DateTime&); - void desktop_open_settings_app(); + bool desktop_has_calendar_app() const override; + void desktop_open_alarm_app() override; + void desktop_open_appointment(const Appointment&) override; + void desktop_open_calendar_app(const DateTime&) override; + void desktop_open_settings_app() override; - void phone_open_alarm_app(); - void phone_open_appointment(const Appointment&); - void phone_open_calendar_app(const DateTime&); - void phone_open_settings_app(); + void phone_open_alarm_app() override; + void phone_open_appointment(const Appointment&) override; + void phone_open_calendar_app(const DateTime&) override; + void phone_open_settings_app() override; - void set_location(const std::string& zone, const std::string& name); + void set_location(const std::string& zone, const std::string& name) override; protected: virtual void execute_command(const std::string& command); diff --git a/include/datetime/actions.h b/include/datetime/actions.h index f59ef67..87cb676 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -61,7 +61,7 @@ public: const std::shared_ptr<State> state() const; protected: - Actions(const std::shared_ptr<State>& state); + explicit Actions(const std::shared_ptr<State>& state); virtual ~Actions(); private: diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 0e24377..84fd860 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -36,7 +36,7 @@ namespace datetime { class MockClock: public Clock { public: - MockClock(const DateTime& dt): m_localtime(dt) {} + explicit MockClock(const DateTime& dt): m_localtime(dt) {} ~MockClock() =default; DateTime localtime() const { return m_localtime; } diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 0b2a543..8745d24 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -25,8 +25,6 @@ #include <core/property.h> #include <core/signal.h> -#include <gio/gio.h> // GDBusConnection - #include <memory> // std::shared_ptr, std::unique_ptr namespace unity { @@ -68,7 +66,7 @@ private: **** ***/ -class Timezones; +class Timezone; /** * \brief A live #Clock that provides the actual system time. @@ -76,7 +74,7 @@ class Timezones; class LiveClock: public Clock { public: - LiveClock (const std::shared_ptr<const Timezones>& zones); + LiveClock (const std::shared_ptr<const Timezone>& zones); virtual ~LiveClock(); virtual DateTime localtime() const; diff --git a/include/datetime/dbus-shared.h b/include/datetime/dbus-shared.h index c09caa2..0c6b4be 100644 --- a/include/datetime/dbus-shared.h +++ b/include/datetime/dbus-shared.h @@ -18,8 +18,8 @@ * Charles Kerr <charles.kerr@canonical.com> */ -#ifndef _INDICATOR_DATETIME_DBUS_SHARED_H_ -#define _INDICATOR_DATETIME_DBUS_SHARED_H_ +#ifndef INDICATOR_DATETIME_DBUS_SHARED_H +#define INDICATOR_DATETIME_DBUS_SHARED_H #define BUS_DATETIME_NAME "com.canonical.indicator.datetime" #define BUS_DATETIME_PATH "/com/canonical/indicator/datetime" @@ -29,4 +29,4 @@ #define BUS_POWERD_INTERFACE "com.canonical.powerd" -#endif /* _INDICATOR_DATETIME_DBUS_SHARED_H_ */ +#endif /* INDICATOR_DATETIME_DBUS_SHARED_H */ diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h index 4b260a8..ebee838 100644 --- a/include/datetime/engine-eds.h +++ b/include/datetime/engine-eds.h @@ -17,8 +17,8 @@ * Charles Kerr <charles.kerr@canonical.com> */ -#ifndef INDICATOR_DATETIME_ENGINE_EDS__H -#define INDICATOR_DATETIME_ENGINE_EDS__H +#ifndef INDICATOR_DATETIME_ENGINE_EDS_H +#define INDICATOR_DATETIME_ENGINE_EDS_H #include <datetime/engine.h> @@ -72,4 +72,4 @@ private: } // namespace indicator } // namespace unity -#endif // INDICATOR_DATETIME_ENGINE_EDS__H +#endif // INDICATOR_DATETIME_ENGINE_EDS_H diff --git a/include/datetime/engine-mock.h b/include/datetime/engine-mock.h index ecbf102..4b25120 100644 --- a/include/datetime/engine-mock.h +++ b/include/datetime/engine-mock.h @@ -17,8 +17,8 @@ * Charles Kerr <charles.kerr@canonical.com> */ -#ifndef INDICATOR_DATETIME_ENGINE_MOCK__H -#define INDICATOR_DATETIME_ENGINE_MOCK__H +#ifndef INDICATOR_DATETIME_ENGINE_MOCK_H +#define INDICATOR_DATETIME_ENGINE_MOCK_H #include <datetime/engine.h> @@ -65,4 +65,4 @@ private: } // namespace indicator } // namespace unity -#endif // INDICATOR_DATETIME_ENGINE_NOOP__H +#endif // INDICATOR_DATETIME_ENGINE_MOCK_H diff --git a/include/datetime/engine.h b/include/datetime/engine.h index 2e8237e..56e9343 100644 --- a/include/datetime/engine.h +++ b/include/datetime/engine.h @@ -17,8 +17,8 @@ * Charles Kerr <charles.kerr@canonical.com> */ -#ifndef INDICATOR_DATETIME_ENGINE__H -#define INDICATOR_DATETIME_ENGINE__H +#ifndef INDICATOR_DATETIME_ENGINE_H +#define INDICATOR_DATETIME_ENGINE_H #include <datetime/appointment.h> #include <datetime/date-time.h> @@ -65,4 +65,4 @@ protected: } // namespace indicator } // namespace unity -#endif // INDICATOR_DATETIME_ENGINE__H +#endif // INDICATOR_DATETIME_ENGINE_H diff --git a/include/datetime/exporter.h b/include/datetime/exporter.h index dd57263..211e7bb 100644 --- a/include/datetime/exporter.h +++ b/include/datetime/exporter.h @@ -39,7 +39,7 @@ namespace datetime { class Exporter { public: - Exporter(const std::shared_ptr<Settings>&); + explicit Exporter(const std::shared_ptr<Settings>&); ~Exporter(); core::Signal<>& name_lost(); diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index 0d695e2..9b3699d 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -86,7 +86,7 @@ public: std::string relative_format(GDateTime* then, GDateTime* then_end=nullptr) const; protected: - Formatter(const std::shared_ptr<const Clock>&); + explicit Formatter(const std::shared_ptr<const Clock>&); virtual ~Formatter(); static const char* default_header_time_format(bool twelvehour, bool show_seconds); @@ -126,7 +126,7 @@ private: class PhoneFormatter: public Formatter { public: - PhoneFormatter(const std::shared_ptr<const Clock>& clock): Formatter(clock) { + explicit PhoneFormatter(const std::shared_ptr<const Clock>& clock): Formatter(clock) { header_format.set(default_header_time_format(is_locale_12h(), false)); } }; diff --git a/include/datetime/planner-range.h b/include/datetime/planner-range.h index 2ee2fa0..d638182 100644 --- a/include/datetime/planner-range.h +++ b/include/datetime/planner-range.h @@ -72,7 +72,7 @@ private: core::Property<std::vector<Appointment>> m_appointments; // we've got a GSignal tag here, so disable copying - SimpleRangePlanner(const RangePlanner&) =delete; + explicit SimpleRangePlanner(const RangePlanner&) =delete; SimpleRangePlanner& operator=(const RangePlanner&) =delete; }; diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index a67c01a..eca9c29 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -24,9 +24,6 @@ #include <string> // std::string -#include <glib.h> -#include <gio/gio.h> - namespace unity { namespace indicator { namespace datetime { @@ -37,21 +34,15 @@ namespace datetime { class FileTimezone: public Timezone { public: - FileTimezone(); FileTimezone(const std::string& filename); ~FileTimezone(); private: - void set_filename(const std::string& filename); - static void on_file_changed(gpointer gself); - void clear(); - void reload(); - - std::string m_filename; - GFileMonitor * m_monitor = nullptr; - unsigned long m_monitor_handler_id = 0; + class Impl; + friend Impl; + std::unique_ptr<Impl> impl; - // we have raw pointers and glib tags in here, so disable copying + // we have pointers in here, so disable copying FileTimezone(const FileTimezone&) =delete; FileTimezone& operator=(const FileTimezone&) =delete; }; diff --git a/include/datetime/timezone-geoclue.h b/include/datetime/timezone-geoclue.h index 4a5b726..ab6b815 100644 --- a/include/datetime/timezone-geoclue.h +++ b/include/datetime/timezone-geoclue.h @@ -22,11 +22,6 @@ #include <datetime/timezone.h> // base class -#include <string> - -#include <glib.h> -#include <gio/gio.h> - namespace unity { namespace indicator { namespace datetime { @@ -41,21 +36,10 @@ public: ~GeoclueTimezone(); private: - static void on_bus_got (GObject*, GAsyncResult*, gpointer); - static void on_client_created (GObject*, GAsyncResult*, gpointer); - static void on_address_changed (GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); - static void on_requirements_set (GObject*, GAsyncResult*, gpointer); - static void on_address_started (GObject*, GAsyncResult*, gpointer); - static void on_address_got (GObject*, GAsyncResult*, gpointer); - void setTimezoneFromAddressVariant (GVariant*); - static GVariant * call_finish (GObject*, GAsyncResult*); - - GCancellable * m_cancellable = nullptr; - GDBusConnection * m_connection = nullptr; - std::string m_client_object_path; - guint m_signal_subscription = 0; + struct Impl; + std::unique_ptr<Impl> impl; - // we've got pointers and gsignal tags in here, so don't allow copying + // we've got pointers in here, so don't allow copying GeoclueTimezone(const GeoclueTimezone&) =delete; GeoclueTimezone& operator=(const GeoclueTimezone&) =delete; }; diff --git a/include/datetime/wakeup-timer-mainloop.h b/include/datetime/wakeup-timer-mainloop.h index 480d728..86da8cf 100644 --- a/include/datetime/wakeup-timer-mainloop.h +++ b/include/datetime/wakeup-timer-mainloop.h @@ -39,7 +39,7 @@ namespace datetime { class MainloopWakeupTimer: public WakeupTimer { public: - MainloopWakeupTimer(const std::shared_ptr<Clock>&); + explicit MainloopWakeupTimer(const std::shared_ptr<Clock>&); ~MainloopWakeupTimer(); void set_wakeup_time (const DateTime&); core::Signal<>& timeout(); diff --git a/include/datetime/wakeup-timer-powerd.h b/include/datetime/wakeup-timer-powerd.h index 6adbbb8..f11febe 100644 --- a/include/datetime/wakeup-timer-powerd.h +++ b/include/datetime/wakeup-timer-powerd.h @@ -39,7 +39,7 @@ namespace datetime { class PowerdWakeupTimer: public WakeupTimer { public: - PowerdWakeupTimer(const std::shared_ptr<Clock>&); + explicit PowerdWakeupTimer(const std::shared_ptr<Clock>&); ~PowerdWakeupTimer(); void set_wakeup_time(const DateTime&); core::Signal<>& timeout(); diff --git a/include/notifications/awake.h b/include/notifications/awake.h index fd812c1..bc38817 100644 --- a/include/notifications/awake.h +++ b/include/notifications/awake.h @@ -36,7 +36,7 @@ namespace notifications { class Awake { public: - Awake(const std::string& app_name); + explicit Awake(const std::string& app_name); ~Awake(); private: diff --git a/include/notifications/haptic.h b/include/notifications/haptic.h index bfb5679..f4f1b4d 100644 --- a/include/notifications/haptic.h +++ b/include/notifications/haptic.h @@ -41,7 +41,7 @@ public: MODE_PULSE }; - Haptic(const Mode& mode = MODE_PULSE); + explicit Haptic(const Mode& mode = MODE_PULSE); ~Haptic(); private: diff --git a/include/notifications/notifications.h b/include/notifications/notifications.h index c95e829..fd41edf 100644 --- a/include/notifications/notifications.h +++ b/include/notifications/notifications.h @@ -86,7 +86,7 @@ private: class Engine { public: - Engine(const std::string& app_name); + explicit Engine(const std::string& app_name); ~Engine(); /** @see Builder::set_action() */ 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 <datetime/clock.h> -#include <datetime/timezones.h> +#include <datetime/timezone.h> namespace unity { namespace indicator { @@ -59,14 +59,15 @@ class LiveClock::Impl { public: - Impl(LiveClock& owner, const std::shared_ptr<const Timezones>& tzd): + Impl(LiveClock& owner, const std::shared_ptr<const Timezone>& 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<const Timezones> m_timezones; + GTimeZone* m_gtimezone = nullptr; + std::shared_ptr<const Timezone> m_timezone; DateTime m_prev_datetime; unsigned int m_timer = 0; }; -LiveClock::LiveClock(const std::shared_ptr<const Timezones>& tzd): - p(new Impl(*this, tzd)) +LiveClock::LiveClock(const std::shared_ptr<const Timezone>& timezone_): + p(new Impl(*this, timezone_)) { } diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 58be0c4..c282a5c 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -285,7 +285,7 @@ private: if (e_cal_client_get_view_finish (E_CAL_CLIENT(client), res, &view, &error)) { // add the view to our collection - e_cal_client_view_set_flags(view, E_CAL_CLIENT_VIEW_FLAGS_NONE, NULL); + e_cal_client_view_set_flags(view, E_CAL_CLIENT_VIEW_FLAGS_NONE, nullptr); e_cal_client_view_start(view, &error); g_debug("got a view for %s", e_cal_client_get_local_attachment_store(E_CAL_CLIENT(client))); auto self = static_cast<Impl*>(gself); diff --git a/src/main.cpp b/src/main.cpp index 54517c9..aa8f829 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,20 +63,20 @@ namespace } std::shared_ptr<State> create_state(const std::shared_ptr<Engine>& engine, - const std::shared_ptr<Timezone>& tz) + const std::shared_ptr<Timezone>& timezone_) { // create the live objects auto live_settings = std::make_shared<LiveSettings>(); auto live_timezones = std::make_shared<LiveTimezones>(live_settings, TIMEZONE_FILE); - auto live_clock = std::make_shared<LiveClock>(live_timezones); + auto live_clock = std::make_shared<LiveClock>(timezone_); // create a full-month planner currently pointing to the current month const auto now = live_clock->localtime(); - auto range_planner = std::make_shared<SimpleRangePlanner>(engine, tz); + auto range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_); auto calendar_month = std::make_shared<MonthPlanner>(range_planner, now); // create an upcoming-events planner currently pointing to the current date - range_planner = std::make_shared<SimpleRangePlanner>(engine, tz); + range_planner = std::make_shared<SimpleRangePlanner>(engine, timezone_); auto calendar_upcoming = std::make_shared<UpcomingPlanner>(range_planner, now); // create the state @@ -127,8 +127,8 @@ main(int /*argc*/, char** /*argv*/) textdomain(GETTEXT_PACKAGE); auto engine = create_engine(); - auto timezone = std::make_shared<FileTimezone>(TIMEZONE_FILE); - auto state = create_state(engine, timezone); + auto timezone_ = std::make_shared<FileTimezone>(TIMEZONE_FILE); + auto state = create_state(engine, timezone_); auto actions = std::make_shared<LiveActions>(state); MenuFactory factory(actions, state); @@ -136,7 +136,7 @@ main(int /*argc*/, char** /*argv*/) auto snooze_planner = std::make_shared<SnoozePlanner>(state->settings, state->clock); auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service"); std::unique_ptr<Snap> 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);}; 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>& engine, - const std::shared_ptr<Timezone>& timezone): + const std::shared_ptr<Timezone>& timezone): m_engine(engine), m_timezone(timezone), m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal())) @@ -38,6 +38,11 @@ SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr<Engine>& 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<DateTime,DateTime>&){ g_debug("rebuilding because the date range changed"); rebuild_soon(); diff --git a/src/planner-snooze.cpp b/src/planner-snooze.cpp index 51ad0d2..29d5f06 100644 --- a/src/planner-snooze.cpp +++ b/src/planner-snooze.cpp @@ -46,7 +46,7 @@ public: { } - virtual core::Property<std::vector<Appointment>>& appointments() + core::Property<std::vector<Appointment>>& appointments() { return m_appointments; } diff --git a/src/sound.cpp b/src/sound.cpp index c6a7b0a..3a4b26f 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -113,17 +113,17 @@ private: else if ((GST_MESSAGE_TYPE(msg) == GST_MESSAGE_STREAM_START) && (self->m_loop)) { /* Set the media role if audio sink is pulsesink */ - GstElement *audio_sink = NULL; - g_object_get(self->m_play, "audio-sink", &audio_sink, NULL); + GstElement *audio_sink = nullptr; + g_object_get(self->m_play, "audio-sink", &audio_sink, nullptr); if (audio_sink) { - GstPluginFeature *feature = NULL; + GstPluginFeature *feature = nullptr; feature = GST_PLUGIN_FEATURE_CAST(GST_ELEMENT_GET_CLASS(audio_sink)->elementfactory); if (feature && g_strcmp0(gst_plugin_feature_get_name(feature), "pulsesink") == 0) { std::string role_str("props,media.role=alarm"); - GstStructure *props = gst_structure_from_string(role_str.c_str(), NULL); - g_object_set(audio_sink, "stream-properties", props, NULL); + GstStructure *props = gst_structure_from_string(role_str.c_str(), nullptr); + g_object_set(audio_sink, "stream-properties", props, nullptr); gst_structure_free(props); } gst_object_unref(audio_sink); diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp index bbe48f7..3c73913 100644 --- a/src/timezone-file.cpp +++ b/src/timezone-file.cpp @@ -19,11 +19,97 @@ #include <datetime/timezone-file.h> +#include <gio/gio.h> + #include <cerrno> #include <cstdlib> -namespace +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class FileTimezone::Impl { +public: + + Impl(FileTimezone& owner, const std::string& filename): + m_owner(owner) + { + set_filename(filename); + } + + ~Impl() + { + clear(); + } + +private: + + void clear() + { + if (m_monitor_handler_id) + g_signal_handler_disconnect(m_monitor, m_monitor_handler_id); + + g_clear_object (&m_monitor); + + m_filename.clear(); + } + + void set_filename(const std::string& filename) + { + clear(); + + auto tmp = realpath(filename.c_str(), nullptr); + if(tmp != nullptr) + { + m_filename = tmp; + free(tmp); + } + else + { + g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); + m_filename = filename; // better than nothing? + } + + auto file = g_file_new_for_path(m_filename.c_str()); + GError * err = nullptr; + m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); + g_object_unref(file); + if (err) + { + g_warning("%s Unable to monitor timezone file '%s': %s", G_STRLOC, TIMEZONE_FILE, err->message); + g_error_free(err); + } + else + { + m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); + g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); + } + + reload(); + } + + static void on_file_changed(gpointer gself) + { + static_cast<Impl*>(gself)->reload(); + } + + void reload() + { + const auto new_timezone = get_timezone_from_file(m_filename); + + if (!new_timezone.empty()) + m_owner.timezone.set(new_timezone); + } + + /*** + **** + ***/ + std::string get_timezone_from_file(const std::string& filename) { GError * error; @@ -73,86 +159,33 @@ namespace return ret; } -} -namespace unity { -namespace indicator { -namespace datetime { + /*** + **** + ***/ -FileTimezone::FileTimezone() -{ -} + FileTimezone & m_owner; + std::string m_filename; + GFileMonitor * m_monitor = nullptr; + unsigned long m_monitor_handler_id = 0; +}; -FileTimezone::FileTimezone(const std::string& filename) -{ - set_filename(filename); -} - -FileTimezone::~FileTimezone() -{ - clear(); -} +/*** +**** +***/ -void -FileTimezone::clear() +FileTimezone::FileTimezone(const std::string& filename): + impl(new Impl{*this, filename}) { - if (m_monitor_handler_id) - g_signal_handler_disconnect(m_monitor, m_monitor_handler_id); - - g_clear_object (&m_monitor); - - m_filename.clear(); } -void -FileTimezone::set_filename(const std::string& filename) -{ - clear(); - - auto tmp = realpath(filename.c_str(), nullptr); - if(tmp != nullptr) - { - m_filename = tmp; - free(tmp); - } - else - { - g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); - m_filename = filename; // better than nothing? - } - - auto file = g_file_new_for_path(m_filename.c_str()); - GError * err = nullptr; - m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); - g_object_unref(file); - if (err) - { - g_warning("%s Unable to monitor timezone file '%s': %s", G_STRLOC, TIMEZONE_FILE, err->message); - g_error_free(err); - } - else - { - m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); - g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); - } - - reload(); -} - -void -FileTimezone::on_file_changed(gpointer gself) +FileTimezone::~FileTimezone() { - static_cast<FileTimezone*>(gself)->reload(); } -void -FileTimezone::reload() -{ - const auto new_timezone = get_timezone_from_file(m_filename); - - if (!new_timezone.empty()) - timezone.set(new_timezone); -} +/*** +**** +***/ } // namespace datetime } // namespace indicator diff --git a/src/timezone-geoclue.cpp b/src/timezone-geoclue.cpp index b8847a4..ca9132f 100644 --- a/src/timezone-geoclue.cpp +++ b/src/timezone-geoclue.cpp @@ -19,225 +19,266 @@ #include <datetime/timezone-geoclue.h> +#include <gio/gio.h> + +#include <memory> +#include <string> +#include <vector> + #define GEOCLUE_BUS_NAME "org.freedesktop.Geoclue.Master" namespace unity { namespace indicator { namespace datetime { - -GeoclueTimezone::GeoclueTimezone(): - m_cancellable(g_cancellable_new()) -{ - g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_got, this); -} - -GeoclueTimezone::~GeoclueTimezone() +class GeoclueTimezone::Impl { - g_cancellable_cancel(m_cancellable); - g_object_unref(m_cancellable); - if (m_signal_subscription) - g_dbus_connection_signal_unsubscribe(m_connection, m_signal_subscription); +public: - g_object_unref(m_connection); -} - -/*** -**** -***/ - -void -GeoclueTimezone::on_bus_got(GObject* /*source*/, - GAsyncResult* res, - gpointer gself) -{ - GError * error; - GDBusConnection * connection; - - error = nullptr; - connection = g_bus_get_finish(res, &error); - if (error) + Impl(GeoclueTimezone& owner): + m_owner(owner), + m_cancellable(g_cancellable_new()) { - if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("Couldn't get bus: %s", error->message); - - g_error_free(error); + g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_got, this); } - else + + ~Impl() { - auto self = static_cast<GeoclueTimezone*>(gself); - - self->m_connection = connection; - - g_dbus_connection_call(self->m_connection, - GEOCLUE_BUS_NAME, - "/org/freedesktop/Geoclue/Master", - "org.freedesktop.Geoclue.Master", - "Create", - nullptr, // parameters - G_VARIANT_TYPE("(o)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_client_created, - self); + g_cancellable_cancel(m_cancellable); + g_object_unref(m_cancellable); + g_object_unref(m_bus); } -} -void -GeoclueTimezone::on_client_created(GObject * source, GAsyncResult * res, gpointer gself) -{ - GVariant * result; +private: - if ((result = call_finish(source, res))) + void remember_subscription(GDBusConnection * bus, + guint tag) { - auto self = static_cast<GeoclueTimezone*>(gself); - - GVariant * child = g_variant_get_child_value(result, 0); - self->m_client_object_path = g_variant_get_string(child, nullptr); - g_variant_unref(child); - g_variant_unref(result); - - self->m_signal_subscription = g_dbus_connection_signal_subscribe( - self->m_connection, - GEOCLUE_BUS_NAME, - "org.freedesktop.Geoclue.Address", // inteface - "AddressChanged", // signal name - self->m_client_object_path.c_str(), // object path - nullptr, // arg0 - G_DBUS_SIGNAL_FLAGS_NONE, - on_address_changed, - self, - nullptr); - - g_dbus_connection_call(self->m_connection, - GEOCLUE_BUS_NAME, - self->m_client_object_path.c_str(), - "org.freedesktop.Geoclue.MasterClient", - "SetRequirements", - g_variant_new("(iibi)", 2, 0, FALSE, 1023), - nullptr, - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_requirements_set, - self); - } -} + g_object_ref(bus); -void -GeoclueTimezone::on_address_changed(GDBusConnection* /*connection*/, - const gchar* /*sender_name*/, - const gchar* /*object_path*/, - const gchar* /*interface_name*/, - const gchar* /*signal_name*/, - GVariant* parameters, - gpointer gself) -{ - static_cast<GeoclueTimezone*>(gself)->setTimezoneFromAddressVariant(parameters); -} + auto deleter = [tag](GDBusConnection* bus){ + g_dbus_connection_signal_unsubscribe(bus, tag); + g_object_unref(G_OBJECT(bus)); + }; -void -GeoclueTimezone::on_requirements_set(GObject* source, GAsyncResult* res, gpointer gself) -{ - GVariant * result; + m_subscriptions.push_back(std::shared_ptr<GDBusConnection>(bus, deleter)); + } - if ((result = call_finish(source, res))) + static void on_bus_got(GObject * /*source*/, + GAsyncResult * res, + gpointer gself) { - auto self = static_cast<GeoclueTimezone*>(gself); - - g_dbus_connection_call(self->m_connection, - GEOCLUE_BUS_NAME, - self->m_client_object_path.c_str(), - "org.freedesktop.Geoclue.MasterClient", - "AddressStart", - nullptr, - nullptr, - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_address_started, - self); - - g_variant_unref(result); - } -} + GError * error; + GDBusConnection * connection; -void -GeoclueTimezone::on_address_started(GObject * source, GAsyncResult * res, gpointer gself) -{ - GVariant * result; + error = nullptr; + connection = g_bus_get_finish(res, &error); + if (error) + { + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning("Couldn't get bus: %s", error->message); - if ((result = call_finish(source, res))) + g_error_free(error); + } + else + { + auto self = static_cast<Impl*>(gself); + + self->m_bus = connection; + + g_dbus_connection_call(self->m_bus, + GEOCLUE_BUS_NAME, + "/org/freedesktop/Geoclue/Master", + "org.freedesktop.Geoclue.Master", + "Create", + nullptr, // parameters + G_VARIANT_TYPE("(o)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + self->m_cancellable, + on_client_created, + self); + } + } + + static void on_client_created(GObject* source, GAsyncResult* res, gpointer gself) { - auto self = static_cast<GeoclueTimezone*>(gself); - - g_dbus_connection_call(self->m_connection, - GEOCLUE_BUS_NAME, - self->m_client_object_path.c_str(), - "org.freedesktop.Geoclue.Address", - "GetAddress", - nullptr, - G_VARIANT_TYPE("(ia{ss}(idd))"), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->m_cancellable, - on_address_got, - self); - - g_variant_unref(result); + GVariant * result; + + if ((result = call_finish(G_STRFUNC, source, res))) + { + auto self = static_cast<Impl*>(gself); + + GVariant * child = g_variant_get_child_value(result, 0); + self->m_client_object_path = g_variant_get_string(child, nullptr); + g_variant_unref(child); + g_variant_unref(result); + + auto tag = g_dbus_connection_signal_subscribe(self->m_bus, + GEOCLUE_BUS_NAME, + "org.freedesktop.Geoclue.Address", // interface + "AddressChanged", // signal name + self->m_client_object_path.c_str(), // object path + nullptr, // arg0 + G_DBUS_SIGNAL_FLAGS_NONE, + on_address_changed, + self, + nullptr); + self->remember_subscription(self->m_bus, tag); + + g_dbus_connection_call(self->m_bus, + GEOCLUE_BUS_NAME, + self->m_client_object_path.c_str(), + "org.freedesktop.Geoclue.MasterClient", + "SetRequirements", + g_variant_new("(iibi)", 2, 0, FALSE, 1023), + nullptr, + G_DBUS_CALL_FLAGS_NONE, + -1, + self->m_cancellable, + on_requirements_set, + self); + } } -} -void -GeoclueTimezone::on_address_got(GObject * source, GAsyncResult * res, gpointer gself) -{ - GVariant * result; + static void on_address_changed(GDBusConnection* /*connection*/, + const gchar* /*sender_name*/, + const gchar* /*object_path*/, + const gchar* /*interface_name*/, + const gchar* /*signal_name*/, + GVariant* parameters, + gpointer gself) + { + static_cast<Impl*>(gself)->set_timezone_from_address_variant(parameters); + } - if ((result = call_finish(source, res))) + static void on_requirements_set(GObject* source, GAsyncResult* res, gpointer gself) { - static_cast<GeoclueTimezone*>(gself)->setTimezoneFromAddressVariant(result); - g_variant_unref(result); + GVariant * result; + + if ((result = call_finish(G_STRFUNC, source, res))) + { + auto self = static_cast<Impl*>(gself); + + g_dbus_connection_call(self->m_bus, + GEOCLUE_BUS_NAME, + self->m_client_object_path.c_str(), + "org.freedesktop.Geoclue.MasterClient", + "AddressStart", + nullptr, + nullptr, + G_DBUS_CALL_FLAGS_NONE, + -1, + self->m_cancellable, + on_address_started, + self); + + g_variant_unref(result); + } } -} -void -GeoclueTimezone::setTimezoneFromAddressVariant(GVariant * variant) -{ - g_return_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("(ia{ss}(idd))"))); + static void on_address_started(GObject* source, GAsyncResult* res, gpointer gself) + { + GVariant * result; + + if ((result = call_finish(G_STRFUNC, source, res))) + { + auto self = static_cast<Impl*>(gself); + + g_dbus_connection_call(self->m_bus, + GEOCLUE_BUS_NAME, + self->m_client_object_path.c_str(), + "org.freedesktop.Geoclue.Address", + "GetAddress", + nullptr, + G_VARIANT_TYPE("(ia{ss}(idd))"), + G_DBUS_CALL_FLAGS_NONE, + -1, + self->m_cancellable, + on_address_got, + self); + + g_variant_unref(result); + } + } - const gchar * timezone_string = nullptr; - GVariant * dict = g_variant_get_child_value(variant, 1); - if (dict) + static void on_address_got(GObject* source, GAsyncResult* res, gpointer gself) { - if (g_variant_lookup(dict, "timezone", "&s", &timezone_string)) - timezone.set(timezone_string); + GVariant * result; - g_variant_unref(dict); + if ((result = call_finish(G_STRFUNC, source, res))) + { + static_cast<Impl*>(gself)->set_timezone_from_address_variant(result); + g_variant_unref(result); + } } -} -GVariant* -GeoclueTimezone::call_finish(GObject * source, GAsyncResult * res) -{ - GError * error; - GVariant * result; + /*** + **** + ***/ - error = nullptr; - result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); + void set_timezone_from_address_variant(GVariant * variant) + { + g_return_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("(ia{ss}(idd))"))); + + const gchar * timezone_string = nullptr; + GVariant * dict = g_variant_get_child_value(variant, 1); + if (dict) + { + if (g_variant_lookup(dict, "timezone", "&s", &timezone_string)) + { + g_debug("from geoclue, setting timezone to '%s'", timezone_string); + m_owner.timezone.set(timezone_string); + } + + g_variant_unref(dict); + } + } - if (error) + static GVariant* call_finish(const char * funcname, GObject * source, GAsyncResult * res) { + GError * error; + GVariant * result; + + error = nullptr; + result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); + + if (error) + { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("AddressStart() failed: %s", error->message); + g_warning("%s failed: %s", funcname, error->message); g_error_free(error); g_clear_pointer(&result, g_variant_unref); + } + + return result; } - return result; + /*** + **** + ***/ + + GeoclueTimezone & m_owner; + GDBusConnection * m_bus = nullptr; + GCancellable * m_cancellable = nullptr; + std::string m_client_object_path; + std::vector<std::shared_ptr<GDBusConnection>> m_subscriptions; +}; + +/**** +***** +****/ + +GeoclueTimezone::GeoclueTimezone(): + impl(new Impl{*this}) +{ +} + +GeoclueTimezone::~GeoclueTimezone() +{ } /**** diff --git a/src/wakeup-timer-powerd.cpp b/src/wakeup-timer-powerd.cpp index 42d93e7..ab6859f 100644 --- a/src/wakeup-timer-powerd.cpp +++ b/src/wakeup-timer-powerd.cpp @@ -22,6 +22,8 @@ #include <notifications/dbus-shared.h> // BUS_POWERD_NAME +#include <gio/gio.h> + #include <memory> // std::shared_ptr namespace unity { @@ -195,7 +197,7 @@ private: } else { - const char* s = NULL; + const char* s = nullptr; g_variant_get(ret, "(&s)", &s); g_debug("%s %s::requestWakeup() sent cookie %s", G_STRLOC, BUS_POWERD_NAME, s); diff --git a/tests/actions-mock.h b/tests/actions-mock.h index 77315c0..9421708 100644 --- a/tests/actions-mock.h +++ b/tests/actions-mock.h @@ -31,7 +31,7 @@ namespace datetime { class MockActions: public Actions { public: - MockActions(std::shared_ptr<State>& state_in): Actions(state_in) {} + explicit MockActions(const std::shared_ptr<State>& state_in): Actions(state_in) {} ~MockActions() =default; enum Action { DesktopOpenAlarmApp, diff --git a/tests/geoclue-fixture.h b/tests/geoclue-fixture.h index 0c597d3..d028ec9 100644 --- a/tests/geoclue-fixture.h +++ b/tests/geoclue-fixture.h @@ -17,6 +17,9 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef INDICATOR_DATETIME_TESTS_GEOCLUE_FIXTURE_H +#define INDICATOR_DATETIME_TESTS_GEOCLUE_FIXTURE_H + #include "glib-fixture.h" #include <libdbustest/dbus-test.h> @@ -39,7 +42,7 @@ class GeoclueFixture : public GlibFixture DbusTestDbusMockObject * obj_geo_addr = nullptr; const std::string timezone_1 = "America/Denver"; - void SetUp () + void SetUp () override { super::SetUp(); @@ -80,7 +83,7 @@ class GeoclueFixture : public GlibFixture g_string_free (gstr, TRUE); } - virtual void TearDown () + void TearDown () override { g_clear_object (&mock); g_clear_object (&service); @@ -148,3 +151,4 @@ public: }; +#endif /* INDICATOR_DATETIME_TESTS_GEOCLUE_FIXTURE_H */ diff --git a/tests/glib-fixture.h b/tests/glib-fixture.h index 1914b8c..f888c59 100644 --- a/tests/glib-fixture.h +++ b/tests/glib-fixture.h @@ -17,6 +17,9 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef INDICATOR_DATETIME_TESTS_GLIB_FIXTURE_H +#define INDICATOR_DATETIME_TESTS_GLIB_FIXTURE_H + #include <map> #include <glib.h> @@ -29,6 +32,10 @@ class GlibFixture : public ::testing::Test { + public: + + virtual ~GlibFixture() =default; + private: //GLogFunc realLogHandler; @@ -59,7 +66,7 @@ class GlibFixture : public ::testing::Test protected: - virtual void SetUp() + virtual void SetUp() override { setlocale(LC_ALL, "C.UTF-8"); @@ -76,7 +83,7 @@ class GlibFixture : public ::testing::Test } - virtual void TearDown() + virtual void TearDown() override { #if 0 // confirm there aren't any unexpected log messages @@ -136,3 +143,5 @@ class GlibFixture : public ::testing::Test GMainLoop * loop; }; + +#endif /* INDICATOR_DATETIME_TESTS_GLIB_FIXTURE_H */ diff --git a/tests/manual b/tests/manual index 2b16841..87ad674 100644 --- a/tests/manual +++ b/tests/manual @@ -40,6 +40,15 @@ Test-case indicator-datetime/new-alarm-wakeup <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd> </dl> +Test-case indicator-datetime/alarm-timezone +<dl> + <dt>In ubuntu-system-settings, change your timezone to a zone you're not in</dt> + <dt>In ubuntu-clock-app, create and save an upcoming alarm</dt> + <dd>The indicator's menu should show the alarm to click at the specified time</dd> + <dt>In ubuntu-system-settings, change back to your correct timezone</dt> + <dd>The indicator's menu should still show the alarm to click at the specified time</dd> +</dl> + Test-case indicator-datetime/snooze <dl> <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt> diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 369e6cd..d4d9ec9 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -47,7 +47,7 @@ namespace GOptionEntry entries[] = { { "volume", 'v', 0, G_OPTION_ARG_INT, &volume, "Volume level [1..100]", "volume" }, - { NULL } + { nullptr } }; } diff --git a/tests/state-fixture.h b/tests/state-fixture.h index 7d8358e..e466a79 100644 --- a/tests/state-fixture.h +++ b/tests/state-fixture.h @@ -17,18 +17,30 @@ * Charles Kerr <charles.kerr@canonical.com> */ +#ifndef INDICATOR_DATETIME_TESTS_STATE_FIXTURE_H +#define INDICATOR_DATETIME_TESTS_STATE_FIXTURE_H + #include "glib-fixture.h" #include "actions-mock.h" #include "state-mock.h" -using namespace unity::indicator::datetime; +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ class StateFixture: public GlibFixture { private: typedef GlibFixture super; +public: + virtual ~StateFixture() =default; + protected: std::shared_ptr<MockState> m_mock_state; std::shared_ptr<State> m_state; @@ -56,5 +68,15 @@ protected: super::TearDown(); } + }; +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif /* INDICATOR_DATETIME_TESTS_STATE_FIXTURE_H */ diff --git a/tests/state-mock.h b/tests/state-mock.h index 792c60d..caa6393 100644 --- a/tests/state-mock.h +++ b/tests/state-mock.h @@ -17,12 +17,21 @@ * Charles Kerr <charles.kerr@canonical.com> */ +#ifndef INDICATOR_DATETIME_STATE_MOCK_H +#define INDICATOR_DATETIME_STATE_MOCK_H + #include "planner-mock.h" #include <datetime/clock-mock.h> #include <datetime/state.h> -using namespace unity::indicator::datetime; +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ class MockState: public State { @@ -47,3 +56,12 @@ public: } }; +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif /* INDICATOR_DATETIME_STATE_MOCK_H */ diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 9f7856c..aefeac0 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -55,12 +55,12 @@ class ActionsFixture: public StateFixture protected: - virtual void SetUp() + void SetUp() override { super::SetUp(); } - virtual void TearDown() + void TearDown() override { super::TearDown(); } diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp index 62281fb..5601d35 100644 --- a/tests/test-clock.cpp +++ b/tests/test-clock.cpp @@ -19,11 +19,12 @@ #include <datetime/clock.h> #include <datetime/clock-mock.h> -#include <datetime/timezones.h> +#include <datetime/timezone.h> #include <notifications/dbus-shared.h> #include "test-dbus-fixture.h" +#include "timezone-mock.h" /*** **** @@ -40,9 +41,9 @@ class ClockFixture: public TestDBusFixture TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) { // start up a live clock - std::shared_ptr<Timezones> zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared<MockTimezone>(); + 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 @@ -65,17 +66,17 @@ TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) TEST_F(ClockFixture, HelloFixture) { - std::shared_ptr<Timezones> zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared<MockTimezone>(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); } TEST_F(ClockFixture, TimezoneChangeTriggersSkew) { - std::shared_ptr<Timezones> zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared<MockTimezone>(); + 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); @@ -90,9 +91,9 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) g_main_loop_quit(loop); }); g_idle_add([](gpointer gs){ - static_cast<Timezones*>(gs)->timezone.set("America/Los_Angeles"); + static_cast<Timezone*>(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"); @@ -130,9 +131,9 @@ namespace */ TEST_F(ClockFixture, SleepTriggersSkew) { - std::shared_ptr<Timezones> zones(new Timezones); - zones->timezone.set("America/New_York"); - LiveClock clock(zones); + auto timezone_ = std::make_shared<MockTimezone>(); + timezone_->timezone.set("America/New_York"); + LiveClock clock(timezone_); wait_msec(250); // wait for the bus to set up bool skewed = false; diff --git a/tests/test-dbus-fixture.h b/tests/test-dbus-fixture.h index db06be2..a894f11 100644 --- a/tests/test-dbus-fixture.h +++ b/tests/test-dbus-fixture.h @@ -17,6 +17,9 @@ * Charles Kerr <charles.kerr@canonical.com> */ +#ifndef INDICATOR_DATETIME_TESTS_DBUS_FIXTURE_H +#define INDICATOR_DATETIME_TESTS_DBUS_FIXTURE_H + #include "glib-fixture.h" /*** @@ -27,9 +30,10 @@ class TestDBusFixture: public GlibFixture { public: - TestDBusFixture() {} + TestDBusFixture() =default; + virtual ~TestDBusFixture() =default; - TestDBusFixture(const std::vector<std::string>& service_dirs_in): service_dirs(service_dirs_in) {} + explicit TestDBusFixture(const std::vector<std::string>& service_dirs_in): service_dirs(service_dirs_in) {} private: @@ -65,7 +69,7 @@ class TestDBusFixture: public GlibFixture GDBusConnection * system_bus; const std::vector<std::string> service_dirs; - virtual void SetUp () + virtual void SetUp() override { super::SetUp (); @@ -84,7 +88,7 @@ class TestDBusFixture: public GlibFixture g_main_loop_run (loop); } - virtual void TearDown () + virtual void TearDown() override { wait_msec(); @@ -100,3 +104,5 @@ class TestDBusFixture: public GlibFixture super::TearDown(); } }; + +#endif /* INDICATOR_DATETIME_TESTS_DBUS_FIXTURE_H */ diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index ec19ef4..be8fcc3 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -42,7 +42,7 @@ protected: GTestDBus* bus = nullptr; - void SetUp() + void SetUp() override { super::SetUp(); @@ -54,7 +54,7 @@ protected: g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); } - void TearDown() + void TearDown() override { GError * error = nullptr; GDBusConnection* connection = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error); @@ -76,9 +76,9 @@ TEST_F(ExporterFixture, HelloWorld) TEST_F(ExporterFixture, Publish) { - std::shared_ptr<State> state(new MockState); - std::shared_ptr<Actions> actions(new MockActions(state)); - std::shared_ptr<Settings> settings(new Settings); + auto state = std::make_shared<MockState>(); + auto actions = std::make_shared<MockActions>(state); + auto settings = std::make_shared<Settings>(); std::vector<std::shared_ptr<Menu>> menus; MenuFactory menu_factory (actions, state); diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index 01df4f2..d011fea 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -46,7 +46,7 @@ class FormatterFixture: public GlibFixture std::shared_ptr<Settings> m_settings; - virtual void SetUp() + void SetUp() override { super::SetUp(); @@ -54,7 +54,7 @@ class FormatterFixture: public GlibFixture m_original_locale = g_strdup(setlocale(LC_TIME, nullptr)); } - virtual void TearDown() + void TearDown() override { m_settings.reset(); @@ -90,7 +90,7 @@ class FormatterFixture: public GlibFixture TEST_F(FormatterFixture, TestPhoneHeader) { auto now = g_date_time_new_local(2020, 10, 31, 18, 30, 59); - std::shared_ptr<Clock> clock(new MockClock(DateTime(now))); + auto clock = std::make_shared<MockClock>(DateTime(now)); g_date_time_unref(now); // test the default value in a 24h locale @@ -143,7 +143,7 @@ TEST_F(FormatterFixture, TestDesktopHeader) }; auto now = g_date_time_new_local(2020, 10, 31, 18, 30, 59); - std::shared_ptr<Clock> clock(new MockClock(DateTime(now))); + auto clock = std::make_shared<MockClock>(DateTime(now)); g_date_time_unref(now); for(const auto& test_case : test_cases) @@ -193,7 +193,7 @@ TEST_F(FormatterFixture, TestUpcomingTimes) { if (test_case.is_12h ? Set12hLocale() : Set24hLocale()) { - std::shared_ptr<Clock> clock (new MockClock(DateTime(test_case.now))); + auto clock = std::make_shared<MockClock>(DateTime(test_case.now)); DesktopFormatter f(clock, m_settings); const auto fmt = f.relative_format(test_case.then); @@ -236,7 +236,7 @@ TEST_F(FormatterFixture, TestEventTimes) { if (test_case.is_12h ? Set12hLocale() : Set24hLocale()) { - std::shared_ptr<Clock> clock(new MockClock(DateTime(test_case.now))); + auto clock = std::make_shared<MockClock>(DateTime(test_case.now)); DesktopFormatter f(clock, m_settings); const auto fmt = f.relative_format(test_case.then, test_case.then_end); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index c67b380..2cd6eef 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -26,17 +26,19 @@ **** ***/ +using namespace unity::indicator::datetime; + class MockLiveActions: public LiveActions { public: std::string last_cmd; std::string last_url; - MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} - virtual ~MockLiveActions() {} + explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} + ~MockLiveActions() {} protected: - void dispatch_url(const std::string& url) { last_url = url; } - void execute_command(const std::string& cmd) { last_cmd = cmd; } + void dispatch_url(const std::string& url) override { last_url = url; } + void execute_command(const std::string& cmd) override { last_cmd = cmd; } }; /*** diff --git a/tests/test-locations.cpp b/tests/test-locations.cpp index 48e845a..61a6ffd 100644 --- a/tests/test-locations.cpp +++ b/tests/test-locations.cpp @@ -47,7 +47,7 @@ class LocationsFixture: public GlibFixture const std::string nyc = "America/New_York"; const std::string chicago = "America/Chicago"; - virtual void SetUp() + void SetUp() override { super::SetUp(); @@ -65,7 +65,7 @@ class LocationsFixture: public GlibFixture m_timezones->timezones.set(std::set<std::string>({ nyc, chicago })); } - virtual void TearDown() + void TearDown() override { m_timezones.reset(); m_settings.reset(); diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index f5f8df2..363a132 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -39,7 +39,7 @@ protected: std::shared_ptr<MenuFactory> m_menu_factory; std::vector<std::shared_ptr<Menu>> m_menus; - virtual void SetUp() + void SetUp() override { super::SetUp(); @@ -49,7 +49,7 @@ protected: m_menus.push_back(m_menu_factory->buildMenu(Menu::Profile(i))); } - virtual void TearDown() + void TearDown() override { m_menus.clear(); m_menu_factory.reset(); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 5dfb5ae..44037f7 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -39,7 +39,7 @@ protected: std::shared_ptr<Settings> m_settings; GSettings * m_gsettings; - virtual void SetUp() + void SetUp() override { super::SetUp(); @@ -48,7 +48,7 @@ protected: m_settings = std::dynamic_pointer_cast<Settings>(m_live); } - virtual void TearDown() + void TearDown() override { g_clear_object(&m_gsettings); m_settings.reset(); diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 5afaab1..21202f4 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -96,7 +96,7 @@ protected: DbusTestDbusMockObject * screen_obj = nullptr; DbusTestDbusMockObject * haptic_obj = nullptr; - void SetUp() + void SetUp() override { GError * error = nullptr; char * str = nullptr; @@ -269,18 +269,18 @@ protected: dbus_test_service_start_tasks(service); g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); - session_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); + session_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); ASSERT_NE(nullptr, session_bus); g_dbus_connection_set_exit_on_close(session_bus, false); g_object_add_weak_pointer(G_OBJECT(session_bus), (gpointer *)&session_bus); - system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + system_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr); ASSERT_NE(nullptr, system_bus); g_dbus_connection_set_exit_on_close(system_bus, FALSE); g_object_add_weak_pointer(G_OBJECT(system_bus), (gpointer *)&system_bus); } - virtual void TearDown() + void TearDown() override { g_clear_object(&haptic_mock); g_clear_object(&screen_mock); diff --git a/tests/test-timezone-file.cpp b/tests/test-timezone-file.cpp index aec597c..8968429 100644 --- a/tests/test-timezone-file.cpp +++ b/tests/test-timezone-file.cpp @@ -52,12 +52,12 @@ class TimezoneFixture: public GlibFixture protected: - virtual void SetUp() + void SetUp() override { super::SetUp(); } - virtual void TearDown() + void TearDown() override { super::TearDown(); } diff --git a/tests/test-timezones.cpp b/tests/test-timezones.cpp index 3f02761..9e5c9cf 100644 --- a/tests/test-timezones.cpp +++ b/tests/test-timezones.cpp @@ -52,7 +52,7 @@ TEST_F(TimezonesFixture, ManagerTest) std::string timezone_geo = "America/Denver"; set_file(timezone_file); - std::shared_ptr<Settings> settings(new Settings); + auto settings = std::make_shared<Settings>(); LiveTimezones z(settings, TIMEZONE_FILE); wait_msec(500); // wait for the bus to get set up EXPECT_EQ(timezone_file, z.timezone.get()); |