aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2016-03-30 16:52:02 -0300
committerRobert Tari <robert@tari.in>2021-07-05 00:44:12 +0200
commit8c57742f1e42bf8076b38b4509a109a911b811c7 (patch)
treea258e1b123bf05821f61bb7d4977afdf47560822
parent6105ec78d545d11184aae91700fe5aec8b8bde4b (diff)
downloadayatana-indicator-datetime-8c57742f1e42bf8076b38b4509a109a911b811c7.tar.gz
ayatana-indicator-datetime-8c57742f1e42bf8076b38b4509a109a911b811c7.tar.bz2
ayatana-indicator-datetime-8c57742f1e42bf8076b38b4509a109a911b811c7.zip
Only play a sound alert if the event contains a SOUND reminder.
-rw-r--r--include/datetime/appointment.h6
-rw-r--r--src/engine-eds.cpp24
-rw-r--r--src/snap.cpp4
-rw-r--r--tests/manual-test-snap.cpp2
4 files changed, 26 insertions, 10 deletions
diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h
index 950f4bb..5b4c27e 100644
--- a/include/datetime/appointment.h
+++ b/include/datetime/appointment.h
@@ -34,9 +34,15 @@ namespace datetime {
*/
struct Alarm
{
+ enum Type {
+ EMAIL = 0x001,
+ SOUND = 0x010,
+ TEXT = 0x100
+ };
std::string text;
std::string audio_url;
DateTime time;
+ int type;
bool operator== (const Alarm& that) const;
bool has_sound() const;
diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp
index becd40f..f3b08cd 100644
--- a/src/engine-eds.cpp
+++ b/src/engine-eds.cpp
@@ -604,13 +604,14 @@ private:
}
};
- static std::string get_alarm_text(ECalComponentAlarm * alarm)
+ static std::string get_alarm_text(ECalComponentAlarm * alarm, bool * hasText)
{
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)
@@ -627,13 +628,14 @@ private:
return ret;
}
- static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, const std::string & default_sound)
+ static std::string get_alarm_sound_url(ECalComponentAlarm * alarm, bool * hasSound)
{
std::string ret;
auto action = e_cal_component_alarm_get_action(alarm);
if (action == E_CAL_COMPONENT_ALARM_AUDIO)
{
+ *hasSound = true;
ICalAttach *attach = nullptr;
auto attachments = e_cal_component_alarm_get_attachments(alarm);
@@ -649,8 +651,6 @@ private:
ret = url;
}
}
- if (ret.empty())
- ret = default_sound;
}
return ret;
@@ -1138,17 +1138,23 @@ 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);
+ alarm.text = get_alarm_text(a, &hasText);
if (alarm.audio_url.empty())
- alarm.audio_url = get_alarm_sound_url(a, (baseline.is_ubuntu_alarm() ?
- "file://" ALARM_DEFAULT_SOUND :
- "file://" CALENDAR_DEFAULT_SOUND));
+ alarm.audio_url = get_alarm_sound_url(a, &hasSound);
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);
}
@@ -1160,7 +1166,7 @@ private:
appointment.alarms.reserve(i.second.size());
for (auto& j : i.second)
{
- if (j.second.has_text() || j.second.has_sound())
+ if ((j.second.type & Alarm::TEXT) || (j.second.type & Alarm::SOUND))
appointment.alarms.push_back(j.second);
}
subtask->task->appointments.push_back(appointment);
diff --git a/src/snap.cpp b/src/snap.cpp
index 9c2b4b6..72d68a2 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -227,6 +227,10 @@ 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 a0f80f2..5aa49a7 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 Text", "", a.begin});
+ a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, Alarm::SOUND});
auto loop = g_main_loop_new(nullptr, false);
auto on_snooze = [loop](const Appointment& appt, const Alarm&){