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

Generated on Tue Jun 30 16:08:14 2009 for Barry by  doxygen 1.5.8