r_calendar.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_calendar.h
00003 ///             Blackberry database record parser class for calendar records.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_RECORD_CALENDAR_H__
00023 #define __BARRY_RECORD_CALENDAR_H__
00024 
00025 #include "dll.h"
00026 #include "record.h"
00027 #include "r_recur_base.h"
00028 #include <iosfwd>
00029 #include <string>
00030 #include <vector>
00031 #include <map>
00032 #include <stdint.h>
00033 
00034 namespace Barry {
00035 
00036 // forward declarations
00037 class IConverter;
00038 
00039 //
00040 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00041 //        operators in the future.
00042 //
00043 
00044 
00045 
00046 /// \addtogroup RecordParserClasses
00047 /// @{
00048 
00049 class BXEXPORT Calendar : public RecurBase
00050 {
00051 public:
00052         typedef Barry::UnknownsType             UnknownsType;
00053 
00054         uint8_t RecType;
00055         uint32_t RecordId;
00056 
00057         // general data
00058         bool AllDayEvent;
00059         std::string Subject;
00060         std::string Notes;
00061         std::string Location;
00062         Barry::TimeT NotificationTime;  // 0 means notification is off
00063         Barry::TimeT StartTime;
00064         Barry::TimeT EndTime;
00065         EmailAddressList Organizer;
00066         EmailAddressList AcceptedBy;
00067         EmailAddressList Invited;               // list of invited people (email a
00068 
00069         ///
00070         /// Free Busy Flag
00071         ///
00072         /// This lists the available settings found in the device.
00073         /// This list is based on information from MS Outlook 2007
00074         /// (Free ==0 and Busy == 2)
00075         /// This is FBTYPE in RFC2445 and is defined as
00076         /// FREE, BUSY, BUSY-UNAVAILABLE and BUSY-TENTATIVE
00077         ///
00078         enum FreeBusyFlagType {
00079                 Free = 0,
00080                 Tentative,
00081                 Busy,
00082                 OutOfOffice
00083         };
00084         FreeBusyFlagType FreeBusyFlag;
00085 
00086         ///
00087         /// Class Flag
00088         ///
00089         /// This is also called classification in Evolution and it
00090         ///  is the equivilant of public or private in outlook
00091         ///  Private is set to 0x2 in Outlook
00092         ///  RFC2445 CLASS is PUBLIC, PRIVATE, CONFIDENTIAL
00093         ///
00094         enum ClassFlagType {
00095                 Public = 0,
00096                 Confidential,
00097                 Private
00098         };
00099 
00100         ClassFlagType ClassFlag;
00101 
00102         uint64_t CalendarID;    // Calendar ID (usefull if devices have several calendars)
00103 
00104         uint16_t TimeZoneCode;          // the time zone originally used
00105                                         // for the recurrence data...
00106                                         // seems to have little use, but
00107                                         // set to your current time zone
00108                                         // as a good default
00109         bool TimeZoneValid;             // true if the record contained a
00110                                         // time zone code, or in other words,
00111                                         // true if TimeZoneCode contains
00112                                         // valid data.  Be sure to set this to
00113                                         // to true if you desire to write a
00114                                         // calendar item with a time zone
00115                                         // to the device, otherwise, the builder
00116                                         // code will skip the time zone.
00117 
00118         // unknown
00119         UnknownsType Unknowns;
00120 
00121 protected:
00122         static FreeBusyFlagType FreeBusyFlagProto2Rec(uint8_t f);
00123         static uint8_t FreeBusyFlagRec2Proto(FreeBusyFlagType f);
00124 
00125         static ClassFlagType ClassFlagProto2Rec(uint8_t f);
00126         static uint8_t ClassFlagRec2Proto(ClassFlagType f);
00127 
00128         virtual void DumpSpecialFields(std::ostream &os) const;
00129 
00130 public:
00131         const unsigned char* ParseField(const unsigned char *begin,
00132                 const unsigned char *end, const IConverter *ic = 0);
00133 
00134 public:
00135         Calendar();
00136         ~Calendar();
00137 
00138         // Parser / Builder API (see parser.h / builder.h)
00139         void Validate() const;
00140         uint8_t GetRecType() const { return RecType; }
00141         uint32_t GetUniqueId() const { return RecordId; }
00142         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00143         void ParseHeader(const Data &data, size_t &offset);
00144         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00145         void BuildHeader(Data &data, size_t &offset) const;
00146         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00147 
00148         // operations (common among record classes)
00149         void Clear();
00150         void Dump(std::ostream &os) const;
00151         std::string GetDescription() const;
00152 
00153         // sorting
00154         bool operator<(const Calendar &other) const;
00155 
00156         // database name
00157         static const char * GetDBName() { return "Calendar"; }
00158         static uint8_t GetDefaultRecType() { return 5; }        // or 0?
00159 
00160         // Generic Field Handle support
00161         static const FieldHandle<Calendar>::ListT& GetFieldHandles();
00162 };
00163 
00164 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Calendar &msg) {
00165         msg.Dump(os);
00166         return os;
00167 }
00168 
00169 
00170 class BXEXPORT CalendarAll : public Calendar
00171 {
00172 public:
00173         std::string MailAccount;
00174 
00175 protected:
00176         virtual void DumpSpecialFields(std::ostream &os) const;
00177 
00178 public:
00179         // Parser / Builder API (see parser.h / builder.h)
00180         void ParseHeader(const Data &data, size_t &offset);
00181 
00182         void Clear();
00183 
00184 public:
00185         // database name
00186         static const char * GetDBName() { return "Calendar - All"; }
00187 
00188         // Generic Field Handle support
00189         static const FieldHandle<CalendarAll>::ListT& GetFieldHandles();
00190 };
00191 
00192 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const CalendarAll &msg) {
00193         msg.Dump(os);
00194         return os;
00195 }
00196 
00197 
00198 /// @}
00199 
00200 } // namespace Barry
00201 
00202 #endif
00203