vcomponent_cxx.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /**
  2. * @file vcomponent_cxx.h
  3. * @author fnguyen (12/10/01)
  4. * @brief C++ classes for the icalcomponent wrapper (VToDo VEvent, etc..).
  5. *
  6. * (C) COPYRIGHT 2001, Critical Path
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of either:
  9. The LGPL as published by the Free Software Foundation, version
  10. 2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html
  11. Or:
  12. The Mozilla Public License Version 1.0. You may obtain a copy of
  13. the License at http://www.mozilla.org/MPL/
  14. */
  15. #ifndef ICAL_VCOMPONENT_CXX_H
  16. #define ICAL_VCOMPONENT_CXX_H
  17. #include "libical_ical_export.h"
  18. #include "icptrholder_cxx.h"
  19. extern "C"
  20. {
  21. #include "icalerror.h"
  22. #include "icalcomponent.h"
  23. };
  24. #include <string>
  25. namespace LibICal
  26. {
  27. class ICalProperty;
  28. /**
  29. * @class VComponent
  30. * @brief A class wrapping the libical icalcomponent functions
  31. *
  32. * @exception icalerrorenum Any errors generated in libical are
  33. * propagated via this exception type.
  34. */
  35. class LIBICAL_ICAL_EXPORT VComponent
  36. {
  37. public:
  38. VComponent() throw(icalerrorenum);
  39. VComponent(const VComponent &) throw(icalerrorenum);
  40. VComponent & operator=(const VComponent &) throw(icalerrorenum);
  41. virtual ~ VComponent();
  42. explicit VComponent(icalcomponent *v) throw(icalerrorenum);
  43. explicit VComponent(const std::string & str) throw(icalerrorenum);
  44. explicit VComponent(const icalcomponent_kind & kind) throw(icalerrorenum);
  45. operator icalcomponent *()
  46. {
  47. return imp;
  48. }
  49. void new_from_string(const std::string & str);
  50. // detach imp to this object. use with caution. it would cause
  51. // memory leak if you are not careful.
  52. void detach();
  53. public:
  54. std::string as_ical_string() throw(icalerrorenum);
  55. bool is_valid();
  56. icalcomponent_kind isa();
  57. int isa_component(void *component);
  58. /// Working with properties
  59. void add_property(ICalProperty * property);
  60. void remove_property(ICalProperty * property);
  61. int count_properties(const icalproperty_kind & kind);
  62. // Iterate through the properties
  63. ICalProperty *get_current_property();
  64. ICalProperty *get_first_property(const icalproperty_kind & kind);
  65. ICalProperty *get_next_property(const icalproperty_kind & kind);
  66. // Working with components
  67. /**
  68. * Return the first VEVENT, VTODO or VJOURNAL sub-component if
  69. * it is one of those types
  70. */
  71. VComponent *get_inner();
  72. void add_component(VComponent * child);
  73. void remove_component(VComponent * child);
  74. int count_components(const icalcomponent_kind & kind);
  75. /**
  76. * Iteration Routines. There are two forms of iterators,
  77. * internal and external. The internal ones came first, and
  78. * are almost completely sufficient, but they fail badly when
  79. * you want to construct a loop that removes components from
  80. * the container.
  81. */
  82. /// Iterate through components
  83. VComponent *get_current_component();
  84. VComponent *get_first_component(const icalcomponent_kind & kind);
  85. VComponent *get_next_component(const icalcomponent_kind & kind);
  86. /// Using external iterators
  87. icalcompiter begin_component(const icalcomponent_kind & kind);
  88. icalcompiter end_component(const icalcomponent_kind & kind);
  89. VComponent *next(icalcompiter * i);
  90. VComponent *prev(icalcompiter * i);
  91. VComponent *current(icalcompiter * i);
  92. /// Working with embedded error properties
  93. int count_errors();
  94. /// Remove all X-LIC-ERROR properties
  95. void strip_errors();
  96. /// Convert some X-LIC-ERROR properties into RETURN-STATUS properties
  97. void convert_errors();
  98. /// Kind conversion routines
  99. static icalcomponent_kind string_to_kind(const std::string & str);
  100. static std::string kind_to_string(const icalcomponent_kind & kind);
  101. public:
  102. struct icaltimetype get_dtstart() const;
  103. void set_dtstart(const struct icaltimetype &v);
  104. /** For the icalcomponent routines only, dtend and duration
  105. * are tied together. If you call the set routine for one and
  106. * the other exists, the routine will calculate the change to
  107. * the other. That is, if there is a DTEND and you call
  108. * set_duration, the routine will modify DTEND to be the sum
  109. * of DTSTART and the duration. If you call a get routine for
  110. * one and the other exists, the routine will calculate the
  111. * return value. If you call a set routine and neither
  112. * exists, the routine will create the appropriate property
  113. */
  114. struct icaltimetype get_dtend() const;
  115. void set_dtend(const struct icaltimetype &v);
  116. struct icaltimetype get_due() const;
  117. void set_due(const struct icaltimetype &v);
  118. struct icaldurationtype get_duration() const;
  119. void set_duration(const struct icaldurationtype &v);
  120. icalproperty_method get_method() const;
  121. void set_method(const icalproperty_method & method);
  122. struct icaltimetype get_dtstamp() const;
  123. void set_dtstamp(const struct icaltimetype &v);
  124. std::string get_summary() const;
  125. void set_summary(const std::string & v);
  126. std::string get_location() const;
  127. void set_location(const std::string & v);
  128. std::string get_description() const;
  129. void set_description(const std::string & v);
  130. std::string get_comment() const;
  131. void set_comment(const std::string & v);
  132. std::string get_uid() const;
  133. void set_uid(const std::string & v);
  134. std::string get_relcalid() const;
  135. void set_relcalid(const std::string & v);
  136. struct icaltimetype get_recurrenceid() const;
  137. void set_recurrenceid(const struct icaltimetype &v);
  138. int get_sequence() const;
  139. void set_sequence(const int &v);
  140. int get_status() const;
  141. void set_status(const enum icalproperty_status &v);
  142. public:
  143. /**
  144. * For VCOMPONENT: Return a reference to the first VEVENT,
  145. * VTODO, or VJOURNAL
  146. */
  147. VComponent * get_first_real_component();
  148. /**
  149. * For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the
  150. * start and end times of an event in UTC
  151. */
  152. virtual struct icaltime_span get_span();
  153. int recurrence_is_excluded(struct icaltimetype *dtstart, struct icaltimetype *recurtime);
  154. public:
  155. /**
  156. helper functions for adding/removing/updating property and
  157. sub-components */
  158. /// Note: the VComponent kind have to be the same
  159. bool remove(VComponent &, bool ignoreValue);
  160. bool update(VComponent &, bool removeMissing);
  161. bool add(VComponent &);
  162. private:
  163. /* Internal operations. They are private, and you should not be using them. */
  164. VComponent * get_parent();
  165. void set_parent(VComponent * parent);
  166. char *quote_ical_string(char *str);
  167. private:
  168. icalcomponent *imp;
  169. };
  170. class LIBICAL_ICAL_EXPORT VCalendar:public VComponent
  171. {
  172. public:
  173. VCalendar();
  174. VCalendar(const VCalendar &);
  175. VCalendar & operator=(const VCalendar &);
  176. ~VCalendar();
  177. explicit VCalendar(icalcomponent *v);
  178. explicit VCalendar(const std::string & str);
  179. };
  180. class LIBICAL_ICAL_EXPORT VEvent:public VComponent
  181. {
  182. public:
  183. VEvent();
  184. VEvent(const VEvent &);
  185. VEvent & operator=(const VEvent &);
  186. ~VEvent();
  187. explicit VEvent(icalcomponent *v);
  188. explicit VEvent(const std::string & str);
  189. };
  190. class LIBICAL_ICAL_EXPORT VToDo:public VComponent
  191. {
  192. public:
  193. VToDo();
  194. VToDo(const VToDo &);
  195. VToDo & operator=(const VToDo &);
  196. ~VToDo();
  197. explicit VToDo(icalcomponent *v);
  198. explicit VToDo(const std::string & str);
  199. };
  200. class LIBICAL_ICAL_EXPORT VAgenda:public VComponent
  201. {
  202. public:
  203. VAgenda();
  204. VAgenda(const VAgenda &);
  205. VAgenda & operator=(const VAgenda &);
  206. ~VAgenda();
  207. explicit VAgenda(icalcomponent *v);
  208. explicit VAgenda(const std::string & str);
  209. };
  210. class LIBICAL_ICAL_EXPORT VQuery:public VComponent
  211. {
  212. public:
  213. VQuery();
  214. VQuery(const VQuery &);
  215. VQuery & operator=(const VQuery &);
  216. ~VQuery();
  217. explicit VQuery(icalcomponent *v);
  218. explicit VQuery(const std::string & str);
  219. };
  220. class LIBICAL_ICAL_EXPORT VJournal:public VComponent
  221. {
  222. public:
  223. VJournal();
  224. VJournal(const VJournal &);
  225. VJournal & operator=(const VJournal &);
  226. ~VJournal();
  227. explicit VJournal(icalcomponent *v);
  228. explicit VJournal(const std::string & str);
  229. };
  230. class LIBICAL_ICAL_EXPORT VAlarm:public VComponent
  231. {
  232. public:
  233. VAlarm();
  234. VAlarm(const VAlarm &);
  235. VAlarm & operator=(const VAlarm &);
  236. ~VAlarm();
  237. explicit VAlarm(icalcomponent *v);
  238. explicit VAlarm(const std::string & str);
  239. /**
  240. * compute the absolute trigger time for this alarm. trigger
  241. * may be related to the containing component c. the result
  242. * is populated in tr->time
  243. */
  244. icalrequeststatus getTriggerTime(VComponent & c, struct icaltriggertype *tr);
  245. };
  246. class LIBICAL_ICAL_EXPORT VFreeBusy:public VComponent
  247. {
  248. public:
  249. VFreeBusy();
  250. VFreeBusy(const VFreeBusy &);
  251. VFreeBusy & operator=(const VFreeBusy &);
  252. ~VFreeBusy();
  253. explicit VFreeBusy(icalcomponent *v);
  254. explicit VFreeBusy(const std::string & str);
  255. };
  256. class LIBICAL_ICAL_EXPORT VTimezone:public VComponent
  257. {
  258. public:
  259. VTimezone();
  260. VTimezone(const VTimezone &);
  261. VTimezone & operator=(const VTimezone &);
  262. ~VTimezone();
  263. explicit VTimezone(icalcomponent *v);
  264. explicit VTimezone(const std::string & str);
  265. };
  266. class LIBICAL_ICAL_EXPORT XStandard:public VComponent
  267. {
  268. public:
  269. XStandard();
  270. XStandard(const XStandard &);
  271. XStandard & operator=(const XStandard &);
  272. ~XStandard();
  273. explicit XStandard(icalcomponent *v);
  274. explicit XStandard(const std::string & str);
  275. };
  276. class LIBICAL_ICAL_EXPORT XDaylight:public VComponent
  277. {
  278. public:
  279. XDaylight();
  280. XDaylight(const XDaylight &);
  281. XDaylight & operator=(const XDaylight &);
  282. ~XDaylight();
  283. explicit XDaylight(icalcomponent *v);
  284. explicit XDaylight(const std::string & str);
  285. };
  286. } // namespace LibICal;
  287. typedef ICPointerHolder < LibICal::VComponent > VComponentTmpPtr;
  288. #endif /* ICAL_VCOMPONENT_H */