r_task.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_task.h
00003 ///             Record parsing class for the task database.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008     Copyright (C) 2007, Brian Edginton
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019     See the GNU General Public License in the COPYING file at the
00020     root directory of this project for more details.
00021 */
00022 
00023 #ifndef __BARRY_RECORD_TASK_H__
00024 #define __BARRY_RECORD_TASK_H__
00025 
00026 #include "dll.h"
00027 #include "record.h"
00028 #include "r_recur_base.h"
00029 #include <vector>
00030 #include <string>
00031 #include <stdint.h>
00032 
00033 namespace Barry {
00034 
00035 // forward declarations
00036 class IConverter;
00037 
00038 //
00039 // Task record class
00040 //
00041 /// Task record class.  Note that there is a bug in many device firmwares.
00042 ///
00043 /// If you extract a Tasks record, and then write it back via
00044 /// SetRecordByIndex(), on many devices that I tested, it ends up
00045 /// corrupting the record on the device, and the GUI on the device
00046 /// appears messed up.  (It shows the first few fields twice)
00047 /// Such a corrupt record also loses the due date.
00048 ///
00049 /// The workaround, when working with the Tasks database, is to
00050 /// first DeleteByIndex() and then AddRecord() via the Desktop mode class,
00051 /// using the same record ID.  This works, but is unfortunately
00052 /// cumbersome.
00053 ///
00054 /// See the Desktop GUI and the opensync plugins for examples of this
00055 /// workaround.
00056 ///
00057 /// Ideally, we should test a Tasks sync on Windows, and see how
00058 /// the Windows software handles this.  There may be some protocol
00059 /// changes that will be needed in future Barry versions.
00060 ///
00061 class BXEXPORT Task : public RecurBase
00062 {
00063 public:
00064         typedef Barry::UnknownsType                     UnknownsType;
00065 
00066         uint8_t RecType;
00067         uint32_t RecordId;
00068 
00069         std::string Summary;
00070         std::string Notes;
00071         CategoryList Categories;
00072         std::string UID;
00073 
00074         Barry::TimeT StartTime;         // most devices set this the same as
00075                                         // DueTime... this is a read-only
00076                                         // variable.  By setting DueTime,
00077                                         // the library will write StartTime
00078                                         // for you automatically
00079         Barry::TimeT DueTime;
00080         Barry::TimeT AlarmTime;
00081         uint16_t TimeZoneCode;
00082         bool TimeZoneValid;             // true if the record contained a
00083                                         // time zone code
00084 
00085         enum AlarmFlagType
00086         {
00087                 Date = 1,
00088                 Relative
00089         };
00090         AlarmFlagType AlarmType;
00091 
00092         enum PriorityFlagType
00093         {
00094                 High = 0,
00095                 Normal,
00096                 Low
00097         };
00098         PriorityFlagType PriorityFlag;
00099 
00100         enum StatusFlagType
00101         {
00102                 NotStarted = 0,
00103                 InProgress,
00104                 Completed,
00105                 Waiting,
00106                 Deferred
00107         };
00108         StatusFlagType StatusFlag;
00109 
00110         // unknown
00111         UnknownsType Unknowns;
00112 
00113 protected:
00114         static AlarmFlagType AlarmProto2Rec(uint8_t a);
00115         static uint8_t AlarmRec2Proto(AlarmFlagType a);
00116 
00117         static PriorityFlagType PriorityProto2Rec(uint8_t p);
00118         static uint8_t PriorityRec2Proto(PriorityFlagType p);
00119 
00120         static StatusFlagType StatusProto2Rec(uint8_t s);
00121         static uint8_t StatusRec2Proto(StatusFlagType s);
00122 
00123 public:
00124         Task();
00125         ~Task();
00126 
00127         // Parser / Builder API (see parser.h / builder.h)
00128         void Validate() const;
00129         const unsigned char* ParseField(const unsigned char *begin,
00130                 const unsigned char *end, const IConverter *ic = 0);
00131         uint8_t GetRecType() const { return RecType; }
00132         uint32_t GetUniqueId() const { return RecordId; }
00133         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00134         void ParseHeader(const Data &data, size_t &offset);
00135         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00136         void BuildHeader(Data &data, size_t &offset) const;
00137         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00138 
00139         // operations (common among record classes)
00140         void Clear();
00141         void Dump(std::ostream &os) const;
00142         std::string GetDescription() const;
00143 
00144         bool operator<(const Task &other) const;
00145 
00146         // database name
00147         static const char * GetDBName() { return "Tasks"; }
00148         static uint8_t GetDefaultRecType() { return 2; }
00149 
00150         // Generic Field Handle support
00151         static const FieldHandle<Task>::ListT& GetFieldHandles();
00152 };
00153 
00154 BXEXPORT inline std::ostream& operator<<(std::ostream &os, const Task &msg) {
00155         msg.Dump(os);
00156         return os;
00157 }
00158 
00159 } // namespace Barry
00160 
00161 #endif
00162