r_contact.h

Go to the documentation of this file.
00001 ///
00002 /// \file       r_contact.h
00003 ///             Blackberry database record parser class for contact records.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2009, 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_CONTACT_H__
00023 #define __BARRY_RECORD_CONTACT_H__
00024 
00025 #include "dll.h"
00026 #include "record.h"
00027 #include <iosfwd>
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <stdint.h>
00032 
00033 namespace Barry {
00034 
00035 // forward declarations
00036 class IConverter;
00037 
00038 //
00039 // NOTE:  All classes here must be container-safe!  Perhaps add sorting
00040 //        operators in the future.
00041 //
00042 
00043 struct BXEXPORT ContactGroupLink
00044 {
00045         uint32_t Link;
00046         uint16_t Unknown;
00047 
00048         ContactGroupLink() : Link(0), Unknown(0) {}
00049         ContactGroupLink(uint32_t link, uint16_t unknown)
00050                 : Link(link), Unknown(unknown)
00051         {}
00052 };
00053 
00054 typedef std::vector<std::string> CategoryList;
00055 
00056 /// \addtogroup RecordParserClasses
00057 /// @{
00058 
00059 //
00060 // Contact record class
00061 //
00062 /// Represents a single record in the Address Book Blackberry database.
00063 ///
00064 class BXEXPORT Contact
00065 {
00066 public:
00067         typedef Barry::CategoryList                     CategoryList;
00068         typedef ContactGroupLink                        GroupLink;
00069         typedef std::vector<GroupLink>                  GroupLinksType;
00070         typedef std::vector<UnknownField>               UnknownsType;
00071         typedef std::string                             EmailType;
00072         typedef std::vector<EmailType>                  EmailList;
00073 
00074         //
00075         // Record fields
00076         //
00077 
00078         // contact specific data
00079         uint8_t RecType;
00080         uint32_t RecordId;
00081         EmailList EmailAddresses;
00082 
00083         /// This field, Phone, is deprecated.  It is possible
00084         /// to write to this field to the Blackberry,
00085         /// but modern devices won't let you add it
00086         /// through their GUIs.  This field only seems
00087         /// to exist on the 7750.  While other devices
00088         /// accept the field and display it, it is
00089         /// not accessible by default.
00090         std::string Phone;
00091 
00092         std::string
00093                 Fax,
00094                 WorkPhone,
00095                 HomePhone,
00096                 MobilePhone,
00097                 Pager,
00098                 PIN,
00099                 Radio,
00100                 WorkPhone2,
00101                 HomePhone2,
00102                 OtherPhone,
00103                 FirstName,
00104                 LastName,
00105                 Company,
00106                 DefaultCommunicationsMethod,
00107                 JobTitle,
00108                 PublicKey,
00109                 URL,
00110                 Prefix,
00111                 Notes,
00112                 UserDefined1,
00113                 UserDefined2,
00114                 UserDefined3,
00115                 UserDefined4,
00116                 Image;
00117 
00118         Date Birthday;
00119         Date Anniversary;
00120 
00121         PostalAddress WorkAddress;
00122         PostalAddress HomeAddress;
00123 
00124         // Categories are not allowed to have commas in them.
00125         // A category name containing a comma will be split into
00126         // two categories, not only by this library, but by the
00127         // device itself.
00128         CategoryList Categories;
00129 
00130         GroupLinksType GroupLinks;
00131         UnknownsType Unknowns;
00132 
00133 private:
00134         bool m_FirstNameSeen;
00135 
00136 public:
00137         const unsigned char* ParseField(const unsigned char *begin,
00138                 const unsigned char *end, const IConverter *ic = 0);
00139 
00140 public:
00141         Contact();
00142         ~Contact();
00143 
00144         uint32_t GetID() const { return RecordId; }
00145         std::string GetFullName() const;
00146         const std::string& GetEmail(unsigned int index = 0) const;
00147 
00148         // Parser / Builder API (see parser.h / builder.h)
00149         uint8_t GetRecType() const { return RecType; }
00150         uint32_t GetUniqueId() const { return RecordId; }
00151         void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
00152         void ParseHeader(const Data &data, size_t &offset);
00153         void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
00154         void BuildHeader(Data &data, size_t &offset) const;
00155         void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
00156 
00157         void Clear();                   // erase everything
00158 
00159         void Dump(std::ostream &os) const;
00160 
00161         // sorting - put group links at the end
00162         bool operator<(const Contact &other) const {
00163                 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
00164 //              // testing - put group links at the top
00165 //              return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
00166         }
00167 
00168         // database name
00169         static const char * GetDBName() { return "Address Book"; }
00170         static uint8_t GetDefaultRecType() { return 0; }
00171 
00172         // helpers
00173         static void SplitName(const std::string &full, std::string &first, std::string &last);
00174         static void CategoryStr2List(const std::string &str, Barry::CategoryList &list);
00175         static void CategoryList2Str(const Barry::CategoryList &list, std::string &str);
00176 };
00177 
00178 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
00179         contact.Dump(os);
00180         return os;
00181 }
00182 
00183 /// @}
00184 
00185 } // namespace Barry
00186 
00187 #endif
00188 

Generated on Mon Jan 12 10:51:13 2009 for Barry by  doxygen 1.5.7.1