aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine-eds.cpp16
-rw-r--r--src/main.cpp3
-rw-r--r--src/myself.cpp13
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);