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.

46 lines
1.5 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. icalproperty* description_property = icalcomponent_get_first_property(alarm_component, ICAL_DESCRIPTION_PROPERTY);
  18. if(description_property != 0) {
  19. description = icalproperty_get_value_as_string(description_property);
  20. }
  21. }
  22. void Alarm::parse_trigger(icalcomponent* alarm_component) {
  23. icalproperty* trigger_property = icalcomponent_get_first_property(alarm_component, ICAL_TRIGGER_PROPERTY);
  24. struct icaltriggertype tr;
  25. if(trigger_property != 0) {
  26. tr = icalproperty_get_trigger(trigger_property);
  27. if (!icaltime_is_null_time(tr.time)) {
  28. trigger = ical::trigger_type::ABSOLUTE;
  29. } else {
  30. trigger = ical::trigger_type::RELATIVE;
  31. }
  32. }
  33. }
  34. std::string Alarm::print() const {
  35. std::string s = "";
  36. s += "DESCRIPTION: " + description + "\n";
  37. s += trigger == ical::trigger_type::ABSOLUTE ? "ABSOLUTE: " : "RELATIVE: ";
  38. return s;
  39. }
  40. }