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.

59 lines
1.5 KiB

  1. #include <ical/Event.h>
  2. #include <ical/Alarm.h>
  3. namespace ical {
  4. Event::Event(icalcomponent* event_component) {
  5. parse(event_component);
  6. }
  7. void Event::parse(icalcomponent* event_component) {
  8. uid = icalcomponent_get_uid(event_component);
  9. dtstart = icalcomponent_get_dtstart(event_component);
  10. dtend = icalcomponent_get_dtend(event_component);
  11. summary = std::string(icalcomponent_get_summary(event_component));
  12. parse_alarms(event_component);
  13. }
  14. void Event::parse_alarms(icalcomponent* event_component) {
  15. icalcomponent* c;
  16. for(c = icalcomponent_get_first_component(event_component, ICAL_VALARM_COMPONENT);
  17. c != 0;
  18. c = icalcomponent_get_next_component(event_component, ICAL_VALARM_COMPONENT))
  19. {
  20. alarms.push_back(Alarm(c));
  21. }
  22. }
  23. std::string get_uid() const {
  24. return uid;
  25. }
  26. std::string get_summary() const {
  27. return summary;
  28. }
  29. icaltimetype get_dtstart() const {
  30. return dtstart;
  31. }
  32. icaltimetype get_dtend() const {
  33. return dtend;
  34. }
  35. std::vector<Alarm> get_alarms() const {
  36. return alarms;
  37. }
  38. std::string Event::print() const {
  39. std::string s = "";
  40. s += "UID: " + uid + "\n";
  41. s += "DTSTART: " + std::string(icaltime_as_ical_string(dtstart)) + "\n";
  42. s += "DTEND: " + std::string(icaltime_as_ical_string(dtend)) + "\n";
  43. s += "SUMMARY: " + summary + "\n";
  44. s += "ALARMS:\n";
  45. for(auto const& a : alarms) {
  46. s += a.print();
  47. }
  48. return s;
  49. }
  50. }