You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include <ical/Alarm.h>
#include <libical/icalproperty_cxx.h>
#include <db/db.h>
namespace ical { Alarm::Alarm(icalcomponent* alarm_component, const uint32_t& event_dtstart) : m_event_dtstart(event_dtstart) { parse(alarm_component); }
void Alarm::parse(icalcomponent* alarm_component) { parse_action(alarm_component); parse_description(alarm_component); parse_trigger(alarm_component); }
void Alarm::parse_action(icalcomponent* alarm_component) { std::string action = icalproperty_get_value_as_string(icalcomponent_get_first_property(alarm_component, ICAL_ACTION_PROPERTY)); if(action == "DISPLAY") m_action = ical::action::DISPLAY; else if(action == "AUDIO") m_action = ical::action::AUDIO; else if(action == "EMAIL") m_action = ical::action::EMAIL; else if(action == "PROC" ) m_action = ical::action::PROC; else m_action = ical::action::DISPLAY; }
void Alarm::parse_description(icalcomponent* alarm_component) { icalproperty* description_property = icalcomponent_get_first_property(alarm_component, ICAL_DESCRIPTION_PROPERTY); if(description_property != 0) { m_description = icalproperty_get_value_as_string(description_property); } }
void Alarm::parse_trigger(icalcomponent* alarm_component) { icalproperty* trigger_property = icalcomponent_get_first_property(alarm_component, ICAL_TRIGGER_PROPERTY); struct icaltriggertype tr; if(trigger_property != 0) { tr = icalproperty_get_trigger(trigger_property); if (!icaltime_is_null_time(tr.time)) { m_trigger = ical::trigger_type::ABSOLUTE; } else { m_trigger = ical::trigger_type::RELATIVE; m_absolute_trigger = m_event_dtstart + icaldurationtype_as_int(tr.duration); } } }
std::string Alarm::get_action() const { switch(m_action) { case ical::action::DISPLAY: return "display"; case ical::action::AUDIO: return "audio"; case ical::action::EMAIL: return "email"; case ical::action::PROC: return "proc"; default: return ""; } return ""; }
std::string Alarm::get_trigger_type() const { switch(m_trigger) { case ical::trigger_type::ABSOLUTE: return "absolute"; case ical::trigger_type::RELATIVE: return "relative"; default: return ""; } }
//std::string Alarm::get_absolute_trigger() const {
// return m_absolute_trigger;
//}
std::vector<std::string> Alarm::get_db_row() const { return {db_safe(get_action()), db_safe(m_description), db_safe(std::to_string(m_absolute_trigger))}; }
std::string Alarm::print() const { std::string s = ""; //s += "DESCRIPTION: " + m_description + "\n";
////s += m_trigger == ical::trigger_type::ABSOLUTE ? "ABSOLUTE: " : "RELATIVE: ";
//s += "ABSOLUTE_TRIGGER: " + std::to_string(m_absolute_trigger) + "\n";
return s; } }
|