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.

44 lines
1.4 KiB

  1. #include <ical/Alarm.h>
  2. #include <libical/icalproperty_cxx.h>
  3. namespace ical {
  4. Alarm::Alarm(icalcomponent* alarm_component) {
  5. parse(alarm_component);
  6. }
  7. void Alarm::parse(icalcomponent* alarm_component) {
  8. parse_action(alarm_component);
  9. parse_description(alarm_component);
  10. parse_trigger(alarm_component);
  11. DEBUG << "\n" << print();
  12. }
  13. void Alarm::parse_action(icalcomponent* alarm_component) {
  14. DEBUG << icalproperty_get_value_as_string(icalcomponent_get_first_property(alarm_component, ICAL_ACTION_PROPERTY));
  15. }
  16. void Alarm::parse_description(icalcomponent* alarm_component) {
  17. // TODO Error Handling
  18. description = icalproperty_get_value_as_string(icalcomponent_get_first_property(alarm_component, ICAL_DESCRIPTION_PROPERTY));
  19. }
  20. void Alarm::parse_trigger(icalcomponent* alarm_component) {
  21. icalproperty* trigger_property = icalcomponent_get_first_property(alarm_component, ICAL_TRIGGER_PROPERTY);
  22. struct icaltriggertype tr;
  23. if(trigger_property != 0) {
  24. tr = icalproperty_get_trigger(trigger_property);
  25. if (!icaltime_is_null_time(tr.time)) {
  26. trigger = ical::trigger_type::ABSOLUTE;
  27. } else {
  28. trigger = ical::trigger_type::RELATIVE;
  29. }
  30. }
  31. }
  32. std::string Alarm::print() {
  33. std::string s = "";
  34. s += "DESCRIPTION: " + description + "\n";
  35. s += trigger == ical::trigger_type::ABSOLUTE ? "ABSOLUTE: " : "RELATIVE: ";
  36. return s;
  37. }
  38. }