diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2015-04-06 14:26:24 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2015-04-06 14:26:24 -0500 |
commit | 392788b1db2d60cd73cac12e58fbc4e6ce304d9e (patch) | |
tree | 94c0139f9dde03cda1097db1b7312ec49947c844 | |
parent | 81f4d9916f4915365e7e271354771b71e0ef2c38 (diff) | |
download | ayatana-indicator-datetime-392788b1db2d60cd73cac12e58fbc4e6ce304d9e.tar.gz ayatana-indicator-datetime-392788b1db2d60cd73cac12e58fbc4e6ce304d9e.tar.bz2 ayatana-indicator-datetime-392788b1db2d60cd73cac12e58fbc4e6ce304d9e.zip |
in SimpleAlarmQueue, add a new method 'bool already_triggered() const' to reduce code overlapl between find_next_alarm() and appointment_get_current_alarm()
-rw-r--r-- | src/alarm-queue-simple.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/alarm-queue-simple.cpp b/src/alarm-queue-simple.cpp index 19e5208..921e8d2 100644 --- a/src/alarm-queue-simple.cpp +++ b/src/alarm-queue-simple.cpp @@ -103,6 +103,12 @@ private: } } + bool already_triggered (const Appointment& appt, const Alarm& alarm) const + { + const std::pair<const std::string&,const DateTime&> key{appt.uid, alarm.time}; + return m_triggered.count(key) != 0; + } + // return the next Alarm (if any) that will kick now or in the future const Alarm* find_next_alarm(const std::vector<Appointment>& appointments) const { @@ -116,8 +122,7 @@ private: { for(const auto& alarm : appointment.alarms) { - const std::pair<const std::string&,const DateTime&> trig{appointment.uid, alarm.time}; - if (m_triggered.count(trig)) + if (already_triggered(appointment, alarm)) continue; if (alarm.time < beginning_of_minute) // has this one already passed? @@ -139,14 +144,8 @@ private: const auto now = m_clock->localtime(); for (const auto& alarm : appointment.alarms) - { - const std::pair<const std::string&,const DateTime&> trig{appointment.uid, alarm.time}; - if (m_triggered.count(trig)) // did we already use this one? - continue; - - if (DateTime::is_same_minute(now, alarm.time)) + if (!already_triggered(appointment, alarm) && DateTime::is_same_minute(now, alarm.time)) return &alarm; - } return nullptr; } |