From 30b0ba7facf333209ea60db9f3b5820dc0f4d5f3 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 31 Mar 2016 16:53:36 -0300 Subject: Update code as requested by reviewer. --- include/datetime/engine-eds.h | 3 +-- include/datetime/myself.h | 9 +++++---- src/engine-eds.cpp | 16 +++++----------- src/main.cpp | 3 ++- src/myself.cpp | 13 ++++++++----- tests/test-eds-ics-all-day-events.cpp | 3 ++- tests/test-eds-ics-missing-trigger.cpp | 5 +++-- tests/test-eds-ics-non-attending-alarms.cpp | 3 ++- tests/test-eds-ics-nonrepeating-events.cpp | 3 ++- tests/test-eds-ics-repeating-events.cpp | 3 ++- tests/test-eds-ics-repeating-valarms.cpp | 3 ++- tests/test-eds-ics-tzids-2.cpp | 3 ++- tests/test-eds-ics-tzids-utc.cpp | 3 ++- tests/test-eds-ics-tzids.cpp | 3 ++- 14 files changed, 40 insertions(+), 33 deletions(-) diff --git a/include/datetime/engine-eds.h b/include/datetime/engine-eds.h index 0b854e5..96b0f76 100644 --- a/include/datetime/engine-eds.h +++ b/include/datetime/engine-eds.h @@ -47,8 +47,7 @@ class Myself; class EdsEngine: public Engine { public: - EdsEngine(); - explicit EdsEngine(const std::unique_ptr &myself); + EdsEngine(const std::shared_ptr &myself); ~EdsEngine(); void get_appointments(const DateTime& begin, diff --git a/include/datetime/myself.h b/include/datetime/myself.h index c381780..452fa53 100644 --- a/include/datetime/myself.h +++ b/include/datetime/myself.h @@ -20,13 +20,14 @@ #ifndef INDICATOR_DATETIME_MYSELF_H #define INDICATOR_DATETIME_MYSELF_H -#include - #include #include #include #include +#include + +typedef struct _AgManager AgManager; namespace ayatana { namespace indicator { @@ -37,7 +38,7 @@ class Myself public: Myself(); - core::Property>& emails() + const core::Property>& emails() { return m_emails; } @@ -46,7 +47,7 @@ public: private: std::shared_ptr m_accounts_manager; - core::Property > m_emails; + core::Property > m_emails; static void on_accounts_changed(AgManager*, guint, Myself*); void reloadEmails(); diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index 7450beb..585841b 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -50,7 +50,8 @@ class EdsEngine::Impl { public: - Impl(const std::unique_ptr &myself) + Impl(const std::shared_ptr &myself) + : m_myself(myself) { auto cancellable_deleter = [](GCancellable * c) { g_cancellable_cancel(c); @@ -59,9 +60,7 @@ public: m_cancellable = std::shared_ptr(g_cancellable_new(), cancellable_deleter); e_source_registry_new(m_cancellable.get(), on_source_registry_ready, this); - - m_myself = std::unique_ptr(new Myself()); - m_myself->emails().changed().connect([this](std::vector) { + m_myself->emails().changed().connect([this](const std::set &) { set_dirty_soon(); }); } @@ -1254,19 +1253,14 @@ private: ESourceRegistry* m_source_registry {}; guint m_rebuild_tag {}; time_t m_rebuild_deadline {}; - std::unique_ptr m_myself; + std::shared_ptr m_myself; }; /*** **** ***/ -EdsEngine::EdsEngine(): - p(new Impl(std::unique_ptr(new Myself))) -{ -} - -EdsEngine::EdsEngine(const std::unique_ptr &myself): +EdsEngine::EdsEngine(const std::shared_ptr &myself): p(new Impl(myself)) { } diff --git a/src/main.cpp b/src/main.cpp index fdd84b5..0da55a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ namespace if (!g_strcmp0("lightdm", g_get_user_name())) engine.reset(new MockEngine); else - engine.reset(new EdsEngine); + engine.reset(new EdsEngine(std::shared_ptr(new Myself))); return engine; } diff --git a/src/myself.cpp b/src/myself.cpp index 04c2126..0debfe4 100644 --- a/src/myself.cpp +++ b/src/myself.cpp @@ -41,8 +41,7 @@ Myself::Myself() bool Myself::isMyEmail(const std::string &email) { - auto emails = m_emails.get(); - return (std::find(emails.begin(), emails.end(), email) != emails.end()); + return m_emails.get().count(email) > 0; } void Myself::on_accounts_changed(AgManager *, guint, Myself *self) @@ -52,15 +51,19 @@ void Myself::on_accounts_changed(AgManager *, guint, Myself *self) void Myself::reloadEmails() { - std::vector emails; + std::set emails; auto manager = m_accounts_manager.get(); auto ids = ag_manager_list(manager); for (auto l=ids; l!=nullptr; l=l->next) { auto acc = ag_manager_get_account(manager, GPOINTER_TO_UINT(l->data)); - auto account_name = ag_account_get_display_name(acc); - emails.push_back(account_name); + if (acc) { + auto account_name = ag_account_get_display_name(acc); + if (account_name != nullptr) + emails.insert(account_name); + g_object_unref(acc); + } } ag_manager_list_free(ids); diff --git a/tests/test-eds-ics-all-day-events.cpp b/tests/test-eds-ics-all-day-events.cpp index 68a3c95..5d7cdc6 100644 --- a/tests/test-eds-ics-all-day-events.cpp +++ b/tests/test-eds-ics-all-day-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp index 0aa00c6..3da53ae 100644 --- a/tests/test-eds-ics-missing-trigger.cpp +++ b/tests/test-eds-ics-missing-trigger.cpp @@ -21,9 +21,10 @@ #include -#include #include #include +#include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MissingTriggers) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-non-attending-alarms.cpp b/tests/test-eds-ics-non-attending-alarms.cpp index 796dd2d..b636e6f 100644 --- a/tests/test-eds-ics-non-attending-alarms.cpp +++ b/tests/test-eds-ics-non-attending-alarms.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, NonAttendingEvent) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Recife"}; diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index ff0ef3f..8aa2b82 100644 --- a/tests/test-eds-ics-nonrepeating-events.cpp +++ b/tests/test-eds-ics-nonrepeating-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index 5d2a2ee..4125623 100644 --- a/tests/test-eds-ics-repeating-events.cpp +++ b/tests/test-eds-ics-repeating-events.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp index 53a6d41..5e418f8 100644 --- a/tests/test-eds-ics-repeating-valarms.cpp +++ b/tests/test-eds-ics-repeating-valarms.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Chicago"}; diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index c8b0370..a1d2f5a 100644 --- a/tests/test-eds-ics-tzids-2.cpp +++ b/tests/test-eds-ics-tzids-2.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Los_Angeles"}; diff --git a/tests/test-eds-ics-tzids-utc.cpp b/tests/test-eds-ics-tzids-utc.cpp index 3ea40d0..f79bf3e 100644 --- a/tests/test-eds-ics-tzids-utc.cpp +++ b/tests/test-eds-ics-tzids-utc.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, UTCAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"America/Recife"}; diff --git a/tests/test-eds-ics-tzids.cpp b/tests/test-eds-ics-tzids.cpp index c80feb2..11d44b7 100644 --- a/tests/test-eds-ics-tzids.cpp +++ b/tests/test-eds-ics-tzids.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture; TEST_F(VAlarmFixture, MultipleAppointments) { // start the EDS engine - auto engine = std::make_shared(); + auto engine = std::make_shared(std::make_shared()); // we need a consistent timezone for the planner and our local DateTimes constexpr char const * zone_str {"Europe/Berlin"}; -- cgit v1.2.3