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.
 
 
 
 

78 lines
2.7 KiB

#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) {
DEBUG << "Parsing ALARM";
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) {
DEBUG << "TODO alarm action parsing" << std::endl;
//DEBUG << icalproperty_get_value_as_string(icalcomponent_get_first_property(alarm_component, ICAL_ACTION_PROPERTY)) << std::endl;
}
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;
DEBUG << icaltime_as_ical_string(tr.time);
} else {
m_trigger = ical::trigger_type::RELATIVE;
DEBUG << icaldurationtype_as_int(tr.duration);
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::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;
}
}