vevent.h

Go to the documentation of this file.
00001 ///
00002 /// \file       vevent.h
00003 ///             Conversion routines for vevents (VCALENDAR, etc)
00004 ///
00005 
00006 /*
00007     Copyright (C) 2006-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_SYNC_VEVENT_H__
00023 #define __BARRY_SYNC_VEVENT_H__
00024 
00025 #include "dll.h"
00026 #include "vbase.h"
00027 #include "vformat.h"
00028 #include "r_calendar.h"
00029 #include <stdint.h>
00030 #include <string>
00031 #include <map>
00032 
00033 namespace Barry { namespace Sync {
00034 
00035 //
00036 // vCalendar
00037 //
00038 /// Class for converting between RFC 2445 iCalendar data format,
00039 /// and the Barry::Calendar class.
00040 ///
00041 class BXEXPORT vCalendar : public vBase
00042 {
00043         typedef std::map<std::string, std::string>      ArgMapType;
00044 
00045         // external reference
00046         vTimeConverter &m_vtc;
00047 
00048         // data to pass to external requests
00049         char *m_gCalData;       // dynamic memory returned by vformat()... can
00050                                 // be used directly by the plugin, without
00051                                 // overmuch allocation and freeing (see Extract())
00052         std::string m_vCalData; // copy of m_gCalData, for C++ use
00053         Barry::Calendar m_BarryCal;
00054 
00055         static const char *WeekDays[7];
00056 
00057         void CheckUnsupportedArg(const ArgMapType &args,
00058                 const std::string &name);
00059         std::vector<std::string> SplitBYDAY(const std::string &ByDay);
00060         uint16_t GetMonthWeekNumFromBYDAY(const std::string& ByDay);
00061         uint16_t GetWeekDayIndexFromBYDAY(const std::string& ByDay);
00062         uint16_t GetDayOfMonthFromBYMONTHDAY(const ArgMapType &args,
00063                                         int month_override = -1);
00064 
00065 protected:
00066         void RecurToVCal();
00067         void RecurToBarryCal(vAttr& rrule, time_t starttime);
00068 
00069         static uint16_t GetWeekDayIndex(const char *dayname);
00070         bool HasMultipleVEvents() const;
00071 
00072 public:
00073         explicit vCalendar(vTimeConverter &vtc);
00074         ~vCalendar();
00075 
00076         const std::string&      ToVCal(const Barry::Calendar &cal);
00077         const Barry::Calendar&  ToBarry(const char *vcal, uint32_t RecordId);
00078 
00079         const std::string&      GetVCal() const { return m_vCalData; }
00080         const Barry::Calendar&  GetBarryCal() const { return m_BarryCal; }
00081 
00082         char* ExtractVCal();
00083 
00084         void Clear();
00085 
00086         // This is the v-name of the innermost BEGIN/END block
00087         static const char* GetVName() { return "VEVENT"; }
00088 };
00089 
00090 }} // namespace Barry::Sync
00091 
00092 #endif
00093