diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2016-03-31 16:53:36 -0300 |
---|---|---|
committer | Robert Tari <robert@tari.in> | 2021-07-05 02:28:32 +0200 |
commit | 30b0ba7facf333209ea60db9f3b5820dc0f4d5f3 (patch) | |
tree | bf0e9bd431af493e44fa484229c654d0d71c0873 /src | |
parent | 6df38ca1d68d1eb2fed2aca024ea938fb00d306c (diff) | |
download | ayatana-indicator-datetime-30b0ba7facf333209ea60db9f3b5820dc0f4d5f3.tar.gz ayatana-indicator-datetime-30b0ba7facf333209ea60db9f3b5820dc0f4d5f3.tar.bz2 ayatana-indicator-datetime-30b0ba7facf333209ea60db9f3b5820dc0f4d5f3.zip |
Update code as requested by reviewer.
Diffstat (limited to 'src')
-rw-r--r-- | src/engine-eds.cpp | 16 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rw-r--r-- | src/myself.cpp | 13 |
3 files changed, 15 insertions, 17 deletions
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> &myself) + Impl(const std::shared_ptr<Myself> &myself) + : m_myself(myself) { auto cancellable_deleter = [](GCancellable * c) { g_cancellable_cancel(c); @@ -59,9 +60,7 @@ public: m_cancellable = std::shared_ptr<GCancellable>(g_cancellable_new(), cancellable_deleter); e_source_registry_new(m_cancellable.get(), on_source_registry_ready, this); - - m_myself = std::unique_ptr<Myself>(new Myself()); - m_myself->emails().changed().connect([this](std::vector<std::string>) { + m_myself->emails().changed().connect([this](const std::set<std::string> &) { set_dirty_soon(); }); } @@ -1254,19 +1253,14 @@ private: ESourceRegistry* m_source_registry {}; guint m_rebuild_tag {}; time_t m_rebuild_deadline {}; - std::unique_ptr<Myself> m_myself; + std::shared_ptr<Myself> m_myself; }; /*** **** ***/ -EdsEngine::EdsEngine(): - p(new Impl(std::unique_ptr<Myself>(new Myself))) -{ -} - -EdsEngine::EdsEngine(const std::unique_ptr<Myself> &myself): +EdsEngine::EdsEngine(const std::shared_ptr<Myself> &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 <datetime/exporter.h> #include <datetime/locations-settings.h> #include <datetime/menu.h> +#include <datetime/myself.h> #include <datetime/planner-aggregate.h> #include <datetime/planner-snooze.h> #include <datetime/planner-range.h> @@ -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<Myself>(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<std::string> emails; + std::set<std::string> 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); |