aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/datetime/engine-eds.h3
-rw-r--r--include/datetime/myself.h9
-rw-r--r--src/engine-eds.cpp16
-rw-r--r--src/main.cpp3
-rw-r--r--src/myself.cpp13
-rw-r--r--tests/test-eds-ics-all-day-events.cpp3
-rw-r--r--tests/test-eds-ics-missing-trigger.cpp5
-rw-r--r--tests/test-eds-ics-non-attending-alarms.cpp3
-rw-r--r--tests/test-eds-ics-nonrepeating-events.cpp3
-rw-r--r--tests/test-eds-ics-repeating-events.cpp3
-rw-r--r--tests/test-eds-ics-repeating-valarms.cpp3
-rw-r--r--tests/test-eds-ics-tzids-2.cpp3
-rw-r--r--tests/test-eds-ics-tzids-utc.cpp3
-rw-r--r--tests/test-eds-ics-tzids.cpp3
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> &myself);
+ EdsEngine(const std::shared_ptr<Myself> &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 <libaccounts-glib.h>
-
#include <core/property.h>
#include <string>
#include <vector>
#include <memory.h>
+#include <glib.h>
+
+typedef struct _AgManager AgManager;
namespace ayatana {
namespace indicator {
@@ -37,7 +38,7 @@ class Myself
public:
Myself();
- core::Property<std::vector<std::string>>& emails()
+ const core::Property<std::set<std::string>>& emails()
{
return m_emails;
}
@@ -46,7 +47,7 @@ public:
private:
std::shared_ptr<AgManager> m_accounts_manager;
- core::Property<std::vector<std::string> > m_emails;
+ core::Property<std::set<std::string> > 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> &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);
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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <algorithm>
-#include <datetime/engine-eds.h>
#include <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
+#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MissingTriggers)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, NonAttendingEvent)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -41,7 +42,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, UTCAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// 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 <datetime/alarm-queue-simple.h>
#include <datetime/clock-mock.h>
#include <datetime/engine-eds.h>
+#include <datetime/myself.h>
#include <datetime/planner-range.h>
#include <gtest/gtest.h>
@@ -43,7 +44,7 @@ using VAlarmFixture = GlibFixture;
TEST_F(VAlarmFixture, MultipleAppointments)
{
// start the EDS engine
- auto engine = std::make_shared<EdsEngine>();
+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
// we need a consistent timezone for the planner and our local DateTimes
constexpr char const * zone_str {"Europe/Berlin"};