- changed some TODO's to FIXME's to keep it grep-consistent
[barry.git] / src / r_contact.h
blob907938d927f5245f3f5c157ef2f4786bffe0d578
1 ///
2 /// \file r_contact.h
3 /// Blackberry database record parser class for contact records.
4 ///
6 /*
7 Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_RECORD_CONTACT_H__
23 #define __BARRY_RECORD_CONTACT_H__
25 #include "record.h"
26 #include <iosfwd>
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <stdint.h>
32 namespace Barry {
35 // NOTE: All classes here must be container-safe! Perhaps add sorting
36 // operators in the future.
40 /// \addtogroup RecordParserClasses
41 /// @{
43 class Contact
45 public:
46 struct GroupLink
48 uint32_t Link;
49 uint16_t Unknown;
51 GroupLink() : Link(0), Unknown(0) {}
52 GroupLink(uint32_t link, uint16_t unknown)
53 : Link(link), Unknown(unknown)
57 typedef std::vector<GroupLink> GroupLinksType;
58 typedef std::vector<UnknownField> UnknownsType;
60 // contact specific data
61 uint8_t RecType;
62 uint32_t RecordId;
63 std::string
64 Email,
65 Phone,
66 Fax,
67 WorkPhone,
68 HomePhone,
69 MobilePhone,
70 Pager,
71 PIN,
72 Radio,
73 WorkPhone2,
74 HomePhone2,
75 OtherPhone,
76 FirstName,
77 LastName,
78 Company,
79 DefaultCommunicationsMethod,
80 Address1,
81 Address2,
82 Address3,
83 City,
84 Province,
85 PostalCode,
86 Country,
87 Title,
88 PublicKey,
89 URL,
90 Prefix,
91 Category,
92 HomeAddress1,
93 HomeAddress2,
94 HomeAddress3,
95 Notes,
96 UserDefined1,
97 UserDefined2,
98 UserDefined3,
99 UserDefined4,
100 HomeCity,
101 HomeProvince,
102 HomePostalCode,
103 HomeCountry,
104 Image;
106 GroupLinksType GroupLinks;
107 UnknownsType Unknowns;
109 private:
110 bool m_FirstNameSeen;
112 //protected:
113 public:
114 const unsigned char* ParseField(const unsigned char *begin,
115 const unsigned char *end);
117 public:
118 Contact();
119 ~Contact();
121 uint32_t GetID() const { return RecordId; }
122 std::string GetPostalAddress() const;
124 // Parser / Builder API (see parser.h / builder.h)
125 uint8_t GetRecType() const { return RecType; }
126 uint32_t GetUniqueId() const { return RecordId; }
127 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
128 void ParseHeader(const Data &data, size_t &offset);
129 void ParseFields(const Data &data, size_t &offset);
130 void BuildHeader(Data &data, size_t &offset) const;
131 void BuildFields(Data &data, size_t &offset) const;
133 void Clear(); // erase everything
135 void Dump(std::ostream &os) const;
137 // sorting - put group links at the end
138 bool operator<(const Contact &other) const {
139 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
140 // // testing - put group links at the top
141 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
144 // database name
145 static const char * GetDBName() { return "Address Book"; }
146 static uint8_t GetDefaultRecType() { return 0; }
148 // helpers
149 static void SplitName(const std::string &full, std::string &first, std::string &last);
152 inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
153 contact.Dump(os);
154 return os;
157 /// @}
159 } // namespace Barry
161 #endif