Updated copyright dates for 2009
[barry/progweb.git] / src / r_calendar.h
blob995ad945393a4685b2c449656684e8614a8a7d54
1 ///
2 /// \file r_calendar.h
3 /// Blackberry database record parser class for calndar records.
4 ///
6 /*
7 Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_RECORD_CALENDAR_H__
23 #define __BARRY_RECORD_CALENDAR_H__
25 #include "dll.h"
26 #include "record.h"
27 #include <iosfwd>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <stdint.h>
33 namespace Barry {
35 // forward declarations
36 class IConverter;
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
45 /// \addtogroup RecordParserClasses
46 /// @{
48 class BXEXPORT Calendar
50 public:
51 typedef std::vector<UnknownField> UnknownsType;
53 uint8_t RecType;
54 uint32_t RecordId;
56 // general data
57 bool AllDayEvent;
58 std::string Subject;
59 std::string Notes;
60 std::string Location;
61 time_t NotificationTime; // 0 means notification is off
62 time_t StartTime;
63 time_t EndTime;
65 ///
66 /// Free Busy Flag
67 ///
68 /// This lists the available settings found in the device.
69 /// This list is based on information from MS Outlook 2007
70 /// (Free ==0 and Busy == 2)
71 /// This is FBTYPE in RFC2445 and is defined as
72 /// FREE, BUSY, BUSY-UNAVAILABLE and BUSY-TENTATIVE
73 ///
74 enum FreeBusyFlagType {
75 Free = 0,
76 Tentative,
77 Busy,
78 OutOfOffice
80 FreeBusyFlagType FreeBusyFlag;
82 ///
83 /// Class Flag
84 ///
85 /// This is also called classification in Evolution and it
86 /// is the equivilant of public or private in outlook
87 /// Private is set to 0x2 in Outlook
88 /// RFC2445 CLASS is PUBLIC, PRIVATE, CONFIDENTIAL
89 ///
90 enum ClassFlagType {
91 Public = 0,
92 Confidential,
93 Private
96 ClassFlagType ClassFlag;
98 ///
99 /// Recurring data
101 /// Note: interval can be used on all of these recurring types to
102 /// make it happen "every other time" or more, etc.
104 enum RecurringCodeType {
105 Day = 1, //< eg. every day
106 //< set: nothing
107 MonthByDate = 3, //< eg. every month on the 12th
108 //< set: DayOfMonth
109 MonthByDay = 4, //< eg. every month on 3rd Wed
110 //< set: DayOfWeek and WeekOfMonth
111 YearByDate = 5, //< eg. every year on March 5
112 //< set: DayOfMonth and MonthOfYear
113 YearByDay = 6, //< eg. every year on 3rd Wed of Jan
114 //< set: DayOfWeek, WeekOfMonth, and
115 //< MonthOfYear
116 Week = 12 //< eg. every week on Mon and Fri
117 //< set: WeekDays
122 bool Recurring;
123 RecurringCodeType RecurringType;
124 unsigned short Interval; // must be >= 1
125 time_t RecurringEndTime; // only pertains if Recurring is true
126 // sets the date and time when
127 // recurrence of this appointment
128 // should no longer occur
129 // If a perpetual appointment, this
130 // is 0xFFFFFFFF in the low level data
131 // Instead, set the following flag.
132 bool Perpetual; // if true, this will always recur
133 unsigned short TimeZoneCode; // the time zone originally used
134 // for the recurrence data...
135 // seems to have little use, but
136 // set to your current time zone
137 // as a good default
138 bool TimeZoneValid; // true if the record contained a
139 // time zone code
141 unsigned short // recurring details, depending on type
142 DayOfWeek, // 0-6
143 WeekOfMonth, // 1-5
144 DayOfMonth, // 1-31
145 MonthOfYear; // 1-12
146 unsigned char WeekDays; // bitmask, bit 0 = sunday
148 // FIXME - put these somewhere usable by both C and C++
149 #define CAL_WD_SUN 0x01
150 #define CAL_WD_MON 0x02
151 #define CAL_WD_TUE 0x04
152 #define CAL_WD_WED 0x08
153 #define CAL_WD_THU 0x10
154 #define CAL_WD_FRI 0x20
155 #define CAL_WD_SAT 0x40
157 // unknown
158 UnknownsType Unknowns;
160 public:
161 const unsigned char* ParseField(const unsigned char *begin,
162 const unsigned char *end, const IConverter *ic = 0);
163 void ParseRecurrenceData(const void *data);
164 void BuildRecurrenceData(void *data) const;
166 public:
167 Calendar();
168 ~Calendar();
170 // Parser / Builder API (see parser.h / builder.h)
171 uint8_t GetRecType() const { return RecType; }
172 uint32_t GetUniqueId() const { return RecordId; }
173 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
174 void ParseHeader(const Data &data, size_t &offset);
175 void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
176 void BuildHeader(Data &data, size_t &offset) const;
177 void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
179 void Clear();
181 void Dump(std::ostream &os) const;
183 // sorting
184 bool operator<(const Calendar &other) const { return StartTime < other.StartTime; }
186 // database name
187 static const char * GetDBName() { return "Calendar"; }
188 static uint8_t GetDefaultRecType() { return 5; } // or 0?
191 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Calendar &msg) {
192 msg.Dump(os);
193 return os;
196 /// @}
198 } // namespace Barry
200 #endif