aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/datetime/appointment.h11
-rw-r--r--src/appointment.cpp17
-rw-r--r--src/engine-eds.cpp22
-rw-r--r--src/snap.cpp5
-rw-r--r--tests/manual-test-snap.cpp2
-rw-r--r--tests/notification-fixture.h4
-rw-r--r--tests/test-alarm-queue.cpp4
-rw-r--r--tests/test-eds-ics-missing-trigger.cpp1
-rw-r--r--tests/test-eds-ics-nonrepeating-events.cpp2
-rw-r--r--tests/test-eds-ics-repeating-events.cpp16
-rw-r--r--tests/test-eds-ics-repeating-valarms.cpp16
-rw-r--r--tests/test-eds-ics-tzids-2.cpp2
12 files changed, 40 insertions, 62 deletions
diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h
index ae9e8ff..faf8a18 100644
--- a/include/datetime/appointment.h
+++ b/include/datetime/appointment.h
@@ -34,20 +34,13 @@ namespace datetime {
*/
struct Alarm
{
- enum Type {
- None = 0,
- EMAIL = 0x001,
- SOUND = 0x010,
- TEXT = 0x100
- };
- int type;
std::string text;
std::string audio_url;
DateTime time;
bool operator== (const Alarm& that) const;
- Alarm();
- Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_);
+ bool has_sound() const;
+ bool has_text() const;
};
/**
diff --git a/src/appointment.cpp b/src/appointment.cpp
index e014a85..ebd5a47 100644
--- a/src/appointment.cpp
+++ b/src/appointment.cpp
@@ -27,22 +27,21 @@ namespace datetime {
*****
****/
-Alarm::Alarm()
- : type(Alarm::None)
+bool Alarm::operator==(const Alarm& that) const
{
+ return (text==that.text)
+ && (audio_url==that.audio_url)
+ && (this->time==that.time);
}
-Alarm::Alarm(int type_, const std::string &text_, const std::string& audio_url_, const DateTime &time_)
- : type(type_), text(text_), audio_url(audio_url_), time(time_)
+bool Alarm::has_sound() const
{
+ return !audio_url.empty();
}
-bool Alarm::operator==(const Alarm& that) const
+bool Alarm::has_text() const
{
- return (type==that.type)
- && (text==that.text)
- && (audio_url==that.audio_url)
- && (this->time==that.time);
+ return !text.empty();
}
bool Appointment::operator==(const Appointment& that) const
diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp
index bd94251..68e2bdd 100644
--- a/src/engine-eds.cpp
+++ b/src/engine-eds.cpp
@@ -604,14 +604,13 @@ private:
}
};
- static std::string get_alarm_text(ECalComponentAlarm * alarm, bool * hasText)
+ static std::string get_alarm_text(ECalComponentAlarm * alarm)
{
std::string ret;
auto action = e_cal_component_alarm_get_action(alarm);
if (action == E_CAL_COMPONENT_ALARM_DISPLAY)
{
- *hasText = true;
auto text = e_cal_component_alarm_get_description(alarm);
if (text != nullptr)
@@ -628,14 +627,14 @@ private:
return ret;
}
- static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, bool * hasSound)
+ static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, const std::string & default_sound)
{
std::string ret;
auto action = e_cal_component_alarm_get_action(alarm);
if (action == E_CAL_COMPONENT_ALARM_AUDIO)
{
- *hasSound = true;
+ ret = default_sound;
ICalAttach *attach = nullptr;
auto attachments = e_cal_component_alarm_get_attachments(alarm);
@@ -1138,23 +1137,16 @@ private:
DateTime{gtz, e_cal_component_alarm_instance_get_occur_end(ai)});
auto trigger_time = DateTime{gtz, e_cal_component_alarm_instance_get_time(ai)};
auto& alarm = alarms[instance_time][trigger_time];
- bool hasText = false;
- bool hasSound = false;
-
if (alarm.text.empty())
- alarm.text = get_alarm_text(a, &hasText);
+ alarm.text = get_alarm_text(a);
if (alarm.audio_url.empty())
- alarm.audio_url = get_alarm_sound_url(a, &hasSound);
+ alarm.audio_url = get_alarm_sound_url(a, baseline.is_ubuntu_alarm() ?
+ ALARM_DEFAULT_SOUND : CALENDAR_DEFAULT_SOUND);
if (!alarm.time.is_set())
alarm.time = trigger_time;
- if (hasText)
- alarm.type = alarm.type | Alarm::TEXT;
- if (hasSound)
- alarm.type = alarm.type | Alarm::SOUND;
-
e_cal_component_alarm_free(a);
}
@@ -1166,7 +1158,7 @@ private:
appointment.alarms.reserve(i.second.size());
for (auto& j : i.second)
{
- if ((j.second.type & Alarm::TEXT) || (j.second.type & Alarm::SOUND))
+ if (j.second.has_text() || (j.second.has_sound()))
appointment.alarms.push_back(j.second);
}
subtask->task->appointments.push_back(appointment);
diff --git a/src/snap.cpp b/src/snap.cpp
index 72d68a2..97fcbab 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -226,11 +226,6 @@ private:
};
std::string uri;
-
- // does not play any sound if alarm is not set as sound
- if (!is_alarm && !(alarm.type & Alarm::SOUND))
- return uri;
-
for(const auto& candidate : candidates)
{
if (gst_uri_is_valid (candidate.c_str()))
diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp
index 1479ef9..a0f80f2 100644
--- a/tests/manual-test-snap.cpp
+++ b/tests/manual-test-snap.cpp
@@ -71,7 +71,7 @@ int main(int argc, const char* argv[])
a.type = Appointment::UBUNTU_ALARM;
a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0);
a.end = a.begin.end_of_day();
- a.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a.begin});
+ a.alarms.push_back(Alarm{"Alarm Text", "", a.begin});
auto loop = g_main_loop_new(nullptr, false);
auto on_snooze = [loop](const Appointment& appt, const Alarm&){
diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h
index 40f7cee..29066c0 100644
--- a/tests/notification-fixture.h
+++ b/tests/notification-fixture.h
@@ -111,7 +111,7 @@ protected:
const auto christmas = ayatana::indicator::datetime::DateTime::Local(2015,12,25,0,0,0);
appt.begin = christmas.start_of_day();
appt.end = christmas.end_of_day();
- appt.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "Ho Ho Ho!", "", appt.begin });
+ appt.alarms.push_back(ayatana::indicator::datetime::Alarm{"Ho Ho Ho!", "", appt.begin });
// init a Lomiri Alarm
ualarm.color = "red";
@@ -121,7 +121,7 @@ protected:
const auto tomorrow = ayatana::indicator::datetime::DateTime::NowLocal().add_days(1);
ualarm.begin = tomorrow;
ualarm.end = tomorrow;
- ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{ayatana::indicator::datetime::Alarm::SOUND, "It's Tomorrow!", "", appt.begin});
+ ualarm.alarms.push_back(ayatana::indicator::datetime::Alarm{"It's Tomorrow!", "", appt.begin});
///
/// Add the AccountsService mock
diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp
index 49bd933..42edf74 100644
--- a/tests/test-alarm-queue.cpp
+++ b/tests/test-alarm-queue.cpp
@@ -79,7 +79,7 @@ protected:
a1.type = Appointment::UBUNTU_ALARM;
a1.begin = tomorrow_begin;
a1.end = tomorrow_end;
- a1.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a1.begin});
+ a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin});
const auto ubermorgen_begin = now.add_days(2).start_of_day();
const auto ubermorgen_end = ubermorgen_begin.end_of_day();
@@ -92,7 +92,7 @@ protected:
a2.type = Appointment::EVENT;
a2.begin = ubermorgen_begin;
a2.end = ubermorgen_end;
- a2.alarms.push_back(Alarm{Alarm::SOUND, "Alarm Text", "", a2.begin});
+ a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin});
return std::vector<Appointment>({a1, a2});
}
diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp
index 3894569..0aa00c6 100644
--- a/tests/test-eds-ics-missing-trigger.cpp
+++ b/tests/test-eds-ics-missing-trigger.cpp
@@ -91,7 +91,6 @@ TEST_F(VAlarmFixture, MissingTriggers)
a.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND;
a.alarms[0].time = a.begin;
a.alarms[0].text = a.summary;
- a.alarms[0].type = Alarm::SOUND | Alarm::TEXT;
expected.push_back(a);
// build expected: recurring alarm
diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp
index fe0d851..ff0ef3f 100644
--- a/tests/test-eds-ics-nonrepeating-events.cpp
+++ b/tests/test-eds-ics-nonrepeating-events.cpp
@@ -84,7 +84,7 @@ TEST_F(VAlarmFixture, MultipleAppointments)
expected_appt.color = "#becedd";
expected_appt.summary = "Alarm";
std::array<Alarm,1> expected_alarms = {
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)})
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)})
};
// compare it to what we actually loaded...
diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp
index cdc0bbc..5d2a2ee 100644
--- a/tests/test-eds-ics-repeating-events.cpp
+++ b/tests/test-eds-ics-repeating-events.cpp
@@ -84,14 +84,14 @@ TEST_F(VAlarmFixture, MultipleAppointments)
expected_appt.color = "#becedd";
expected_appt.summary = "Alarm";
std::array<Alarm,8> expected_alarms = {
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}),
- Alarm({Alarm::SOUND | Alarm::TEXT, "Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)})
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,15,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,22,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,29,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6, 5,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,12,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,19,16,40,0)}),
+ Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,6,26,16,40,0)})
};
// compare it to what we actually loaded...
diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp
index 49ec41b..4f53e68 100644
--- a/tests/test-eds-ics-repeating-valarms.cpp
+++ b/tests/test-eds-ics-repeating-valarms.cpp
@@ -83,14 +83,14 @@ TEST_F(VAlarmFixture, MultipleAppointments)
ASSERT_EQ(1, appts.size());
const auto& appt = appts.front();
ASSERT_EQ(8, appt.alarms.size());
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]);
- EXPECT_EQ(Alarm({Alarm::SOUND | Alarm::TEXT, "Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]);
+ EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]);
+ EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]);
+ EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]);
+ EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]);
+ EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]);
+ EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]);
+ EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]);
+ EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]);
// now let's try this out with AlarmQueue...
// hook the planner up to a SimpleAlarmQueue and confirm that it triggers for each of the reminders
diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp
index b1a344a..c8b0370 100644
--- a/tests/test-eds-ics-tzids-2.cpp
+++ b/tests/test-eds-ics-tzids-2.cpp
@@ -86,7 +86,7 @@ TEST_F(VAlarmFixture, MultipleAppointments)
appt->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar";
appt->begin = DateTime{gtz,2014,1,21,11,0,0};
appt->end = DateTime{gtz,2014,1,21,13,0,0};
- appt->alarms = std::vector<Alarm>{ Alarm({Alarm::TEXT, "Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) };
+ appt->alarms = std::vector<Alarm>{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) };
// compare it to what we actually loaded...
const auto appts = planner->appointments().get();