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