recurrence.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef RECURRENCE_H
  18. #define RECURRENCE_H
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/RecurrenceState.h>
  21. #include <mapidefs.h>
  22. #include <mapix.h>
  23. #include <kopano/Util.h>
  24. #include <list>
  25. #include "TimeUtil.h"
  26. #include "freebusy.h"
  27. #include "freebusyutil.h"
  28. namespace KC {
  29. class _kc_export recurrence _kc_final {
  30. public:
  31. recurrence();
  32. HRESULT HrLoadRecurrenceState(const char *lpData, unsigned int ulLen, ULONG ulFlags);
  33. HRESULT HrGetRecurrenceState(char **lppData, unsigned int *lpulLen, void *base = NULL);
  34. HRESULT HrGetHumanReadableString(std::string *lpstrHRS);
  35. HRESULT HrGetItems(time_t start, time_t end, TIMEZONE_STRUCT ttZinfo, ULONG ulBusyStatus, OccrInfo **lppFbBlock, ULONG *lpcValues, bool last = false);
  36. enum freq_type { DAILY, WEEKLY, MONTHLY, YEARLY };
  37. enum term_type { DATE, NUMBER, NEVER };
  38. freq_type getFrequency();
  39. HRESULT setFrequency(freq_type ft);
  40. _kc_hidden time_t getStartDate(void);
  41. _kc_hidden HRESULT setStartDate(time_t);
  42. time_t getEndDate();
  43. HRESULT setEndDate(time_t tEnd);
  44. ULONG getStartTimeOffset();
  45. _kc_hidden HRESULT setStartTimeOffset(ULONG minutes_since_midnight);
  46. _kc_hidden ULONG getEndTimeOffset(void);
  47. HRESULT setEndTimeOffset(ULONG ulMinutesSinceMidnight);
  48. time_t getStartDateTime();
  49. HRESULT setStartDateTime(time_t tStart);
  50. _kc_hidden time_t getEndDateTime(void);
  51. _kc_hidden HRESULT setEndDateTime(time_t);
  52. ULONG getCount();
  53. HRESULT setCount(ULONG ulCount);
  54. term_type getEndType();
  55. HRESULT setEndType(term_type);
  56. ULONG getInterval();
  57. HRESULT setInterval(ULONG);
  58. _kc_hidden ULONG getSlidingFlag(void) { return m_sRecState.ulSlidingFlag; }
  59. _kc_hidden HRESULT setSlidingFlag(ULONG);
  60. _kc_hidden ULONG getFirstDOW(void);
  61. HRESULT setFirstDOW(ULONG);
  62. UCHAR getWeekDays();
  63. HRESULT setWeekDays(UCHAR);
  64. UCHAR getDayOfMonth();
  65. HRESULT setDayOfMonth(UCHAR);
  66. UCHAR getMonth();
  67. HRESULT setMonth(UCHAR);
  68. UCHAR getWeekNumber(); /* 1..4 and 5 (last) */
  69. HRESULT setWeekNumber(UCHAR);
  70. /* exception handling */
  71. HRESULT addDeletedException(time_t);
  72. std::list<time_t> getDeletedExceptions();
  73. ULONG getModifiedCount();
  74. ULONG getModifiedFlags(ULONG id); /* 0..getModifiedCount() */
  75. time_t getModifiedStartDateTime(ULONG id);
  76. time_t getModifiedEndDateTime(ULONG id);
  77. _kc_hidden time_t getModifiedOriginalDateTime(ULONG id); /* used as recurrence-id */
  78. std::wstring getModifiedSubject(ULONG id);
  79. _kc_hidden ULONG getModifiedMeetingType(ULONG id);
  80. LONG getModifiedReminderDelta(ULONG id);
  81. ULONG getModifiedReminder(ULONG id);
  82. std::wstring getModifiedLocation(ULONG id);
  83. ULONG getModifiedBusyStatus(ULONG id);
  84. _kc_hidden ULONG getModifiedAttachment(ULONG id);
  85. ULONG getModifiedSubType(ULONG id);
  86. HRESULT addModifiedException(time_t tStart, time_t tEnd, time_t tOriginalStart, ULONG *id);
  87. HRESULT setModifiedSubject(ULONG id, const std::wstring &strSubject);
  88. _kc_hidden HRESULT setModifiedMeetingType(ULONG id, ULONG type);
  89. HRESULT setModifiedReminderDelta(ULONG id, LONG delta);
  90. HRESULT setModifiedReminder(ULONG id, ULONG set);
  91. HRESULT setModifiedLocation(ULONG id, const std::wstring &strLocation);
  92. HRESULT setModifiedBusyStatus(ULONG id, ULONG status);
  93. _kc_hidden HRESULT setModifiedAttachment(ULONG id);
  94. HRESULT setModifiedSubType(ULONG id, ULONG subtype);
  95. _kc_hidden HRESULT setModifiedApptColor(ULONG id, ULONG color);
  96. HRESULT setModifiedBody(ULONG id);
  97. _kc_hidden HRESULT AddValidOccr(time_t occr_start, time_t occr_end, ULONG busy_status, OccrInfo **fbblocksall, ULONG *nvals);
  98. _kc_hidden bool isOccurrenceValid(time_t period_start, time_t period_end, time_t new_occ);
  99. _kc_hidden bool isDeletedOccurrence(time_t occ_date);
  100. _kc_hidden bool isException(time_t occ_date);
  101. _kc_hidden ULONG countDaysOfMonth(time_t date);
  102. _kc_hidden ULONG DaysTillMonth(time_t date, ULONG month);
  103. _kc_hidden std::list<time_t> getModifiedOccurrences(void);
  104. /* TODO: */
  105. /*
  106. _kc_hidden HRESULT setDeletedOccurrence(time_t);
  107. _kc_hidden HRESULT removeDeletedOccurrence(time_t);
  108. _kc_hidden std::list<time_t> getDeletedOccurrences(void);
  109. _kc_hidden HRESULT getChangedOccurrence(time_t, RecurrenceState::Exception *);
  110. _kc_hidden HRESULT setChangedOccurrence(RecurrenceState::Exception);
  111. _kc_hidden HRESULT removeChangedOccurrence(time_t);
  112. _kc_hidden std::list<RecurrenceState::Exception> getChangedOccurrences(void);
  113. _kc_hidden std::list<time_t> getExceptions(void);
  114. _kc_hidden bool isOccurrence(time_t);
  115. _kc_hidden bool isRuleOccurrence(time_t);
  116. _kc_hidden bool isAfter(time_t);
  117. */
  118. time_t calcStartDate();
  119. time_t calcEndDate();
  120. ULONG calcCount();
  121. _kc_hidden static time_t MonthInSeconds(ULONG year, ULONG month);
  122. _kc_hidden static time_t MonthsInSeconds(ULONG months);
  123. _kc_hidden static time_t Minutes2Time(ULONG);
  124. _kc_hidden static ULONG Time2Minutes(time_t);
  125. _kc_hidden static ULONG Minutes2Month(ULONG);
  126. static time_t StartOfDay(time_t);
  127. _kc_hidden static time_t StartOfWeek(time_t);
  128. _kc_hidden static time_t StartOfMonth(time_t);
  129. _kc_hidden static time_t StartOfYear(time_t);
  130. _kc_hidden static bool isLeapYear(ULONG year);
  131. _kc_hidden static ULONG DaysInMonth(ULONG);
  132. _kc_hidden static ULONG DaysInMonth(ULONG, ULONG);
  133. _kc_hidden static ULONG DaysInYear(ULONG);
  134. _kc_hidden static ULONG MonthFromTime(time_t);
  135. _kc_hidden static ULONG YearFromTime(time_t);
  136. _kc_hidden static ULONG AllMonthsFromTime(time_t);
  137. _kc_hidden static ULONG WeekDayFromTime(time_t);
  138. _kc_hidden static ULONG MonthDayFromTime(time_t);
  139. private:
  140. RecurrenceState m_sRecState;
  141. unsigned int m_ulMonth; // yearly, 1...12 (Not stored in the struct)
  142. std::vector<std::wstring> vExceptionsSubject;
  143. std::vector<std::wstring> vExceptionsLocation;
  144. /*
  145. std::list<time_t> exceptions;
  146. std::list<time_t> deleted_occurrences;
  147. std::list<RecurrenceState::Exception> changed_occurrences;
  148. */
  149. _kc_hidden ULONG calcBits(ULONG x);
  150. _kc_hidden bool CheckAddValidOccr(time_t now, time_t start, time_t end, TIMEZONE_STRUCT, ULONG busy_status, OccrInfo **occrinfoall, ULONG *nvals);
  151. };
  152. } /* namespace */
  153. #endif