i18n work in progress... desperately needs some housecleaning.
[barry.git] / src / r_calendar.h
blob9fc6d18bebfaca3f2de44a50e6c2a1f417ce0802
1 ///
2 /// \file r_calendar.h
3 /// Blackberry database record parser class for calndar records.
4 ///
6 /*
7 Copyright (C) 2005-2008, 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 {
36 // NOTE: All classes here must be container-safe! Perhaps add sorting
37 // operators in the future.
42 /// \addtogroup RecordParserClasses
43 /// @{
45 class BXEXPORT Calendar
47 public:
48 typedef std::vector<UnknownField> UnknownsType;
50 uint8_t RecType;
51 uint32_t RecordId;
53 // general data
54 bool AllDayEvent;
55 std::string Subject;
56 std::string Notes;
57 std::string Location;
58 time_t NotificationTime; // 0 means notification is off
59 time_t StartTime;
60 time_t EndTime;
62 ///
63 /// Free Busy Flag
64 ///
65 /// This lists the available settings found in the device.
66 /// This list is based on information from MS Outlook 2007
67 /// (Free ==0 and Busy == 2)
68 /// This is FBTYPE in RFC2445 and is defined as
69 /// FREE, BUSY, BUSY-UNAVAILABLE and BUSY-TENTATIVE
70 ///
71 enum FreeBusyFlagType {
72 Free = 0,
73 Tentative,
74 Busy,
75 OutOfOffice
77 FreeBusyFlagType FreeBusyFlag;
79 ///
80 /// Class Flag
81 ///
82 /// This is also called classification in Evolution and it
83 /// is the equivilant of public or private in outlook
84 /// Private is set to 0x2 in Outlook
85 /// RFC2445 CLASS is PUBLIC, PRIVATE, CONFIDENTIAL
86 ///
87 enum ClassFlagType {
88 Public = 0,
89 Confidential,
90 Private
93 ClassFlagType ClassFlag;
95 ///
96 /// Recurring data
97 ///
98 /// Note: interval can be used on all of these recurring types to
99 /// make it happen "every other time" or more, etc.
101 enum RecurringCodeType {
102 Day = 1, //< eg. every day
103 //< set: nothing
104 MonthByDate = 3, //< eg. every month on the 12th
105 //< set: DayOfMonth
106 MonthByDay = 4, //< eg. every month on 3rd Wed
107 //< set: DayOfWeek and WeekOfMonth
108 YearByDate = 5, //< eg. every year on March 5
109 //< set: DayOfMonth and MonthOfYear
110 YearByDay = 6, //< eg. every year on 3rd Wed of Jan
111 //< set: DayOfWeek, WeekOfMonth, and
112 //< MonthOfYear
113 Week = 12 //< eg. every week on Mon and Fri
114 //< set: WeekDays
119 bool Recurring;
120 RecurringCodeType RecurringType;
121 unsigned short Interval; // must be >= 1
122 time_t RecurringEndTime; // only pertains if Recurring is true
123 // sets the date and time when
124 // recurrence of this appointment
125 // should no longer occur
126 // If a perpetual appointment, this
127 // is 0xFFFFFFFF in the low level data
128 // Instead, set the following flag.
129 bool Perpetual; // if true, this will always recur
130 unsigned short TimeZoneCode; // the time zone originally used
131 // for the recurrence data...
132 // seems to have little use, but
133 // set to your current time zone
134 // as a good default
135 bool TimeZoneValid; // true if the record contained a
136 // time zone code
138 unsigned short // recurring details, depending on type
139 DayOfWeek, // 0-6
140 WeekOfMonth, // 1-5
141 DayOfMonth, // 1-31
142 MonthOfYear; // 1-12
143 unsigned char WeekDays; // bitmask, bit 0 = sunday
145 // FIXME - put these somewhere usable by both C and C++
146 #define CAL_WD_SUN 0x01
147 #define CAL_WD_MON 0x02
148 #define CAL_WD_TUE 0x04
149 #define CAL_WD_WED 0x08
150 #define CAL_WD_THU 0x10
151 #define CAL_WD_FRI 0x20
152 #define CAL_WD_SAT 0x40
154 // unknown
155 UnknownsType Unknowns;
157 public:
158 const unsigned char* ParseField(const unsigned char *begin,
159 const unsigned char *end);
160 void ParseRecurrenceData(const void *data);
161 void BuildRecurrenceData(void *data) const;
163 public:
164 Calendar();
165 ~Calendar();
167 // Parser / Builder API (see parser.h / builder.h)
168 uint8_t GetRecType() const { return RecType; }
169 uint32_t GetUniqueId() const { return RecordId; }
170 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
171 void ParseHeader(const Data &data, size_t &offset);
172 void ParseFields(const Data &data, size_t &offset);
173 void BuildHeader(Data &data, size_t &offset) const;
174 void BuildFields(Data &data, size_t &offset) const;
176 void Clear();
178 void Dump(std::ostream &os) const;
180 // sorting
181 bool operator<(const Calendar &other) const { return StartTime < other.StartTime; }
183 // database name
184 static const char * GetDBName() { return "Calendar"; }
185 static uint8_t GetDefaultRecType() { return 5; } // or 0?
188 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Calendar &msg) {
189 msg.Dump(os);
190 return os;
193 /// @}
195 } // namespace Barry
197 #endif