3 /// Blackberry database record parser class for contact records.
7 Copyright (C) 2005-2013, 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__
35 // forward declarations
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 struct BXEXPORT ContactGroupLink
48 ContactGroupLink() : Link(0), Unknown(0) {}
49 ContactGroupLink(uint32_t link
, uint16_t unknown
)
50 : Link(link
), Unknown(unknown
)
54 /// \addtogroup RecordParserClasses
58 // Contact record class
60 /// Represents a single record in the Address Book Blackberry database.
62 class BXEXPORT Contact
65 typedef Barry::CategoryList CategoryList
;
66 typedef ContactGroupLink GroupLink
;
67 typedef std::vector
<GroupLink
> GroupLinksType
;
68 typedef Barry::UnknownsType UnknownsType
;
69 typedef Barry::EmailType EmailType
;
70 typedef Barry::EmailList EmailList
;
76 // contact specific data
79 EmailList EmailAddresses
;
81 /// This field, Phone, is deprecated. It is possible
82 /// to write to this field to the Blackberry,
83 /// but modern devices won't let you add it
84 /// through their GUIs. This field only seems
85 /// to exist on the 7750. While other devices
86 /// accept the field and display it, it is
87 /// not accessible by default.
106 DefaultCommunicationsMethod
,
122 PostalAddress WorkAddress
;
123 PostalAddress HomeAddress
;
125 // Categories are not allowed to have commas in them.
126 // A category name containing a comma will be split into
127 // two categories, not only by this library, but by the
129 CategoryList Categories
;
131 GroupLinksType GroupLinks
;
132 UnknownsType Unknowns
;
135 bool m_FirstNameSeen
;
138 const unsigned char* ParseField(const unsigned char *begin
,
139 const unsigned char *end
, const IConverter
*ic
= 0);
145 uint32_t GetID() const { return RecordId
; }
146 std::string
GetFullName() const;
147 const std::string
& GetEmail(unsigned int index
= 0) const;
149 // Parser / Builder API (see parser.h / builder.h)
150 void Validate() const;
151 uint8_t GetRecType() const { return RecType
; }
152 uint32_t GetUniqueId() const { return RecordId
; }
153 void SetIds(uint8_t Type
, uint32_t Id
) { RecType
= Type
; RecordId
= Id
; }
154 void ParseHeader(const Data
&data
, size_t &offset
);
155 void ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
= 0);
156 void BuildHeader(Data
&data
, size_t &offset
) const;
157 void BuildFields(Data
&data
, size_t &offset
, const IConverter
*ic
= 0) const;
159 // operations (common among record classes)
160 void Clear(); // erase everything
161 void Dump(std::ostream
&os
) const;
162 std::string
GetDescription() const;
164 // Sorting - use enough data to make the sorting as
165 // consistent as possible
166 bool operator<(const Contact
&other
) const;
169 static const char * GetDBName() { return "Address Book"; }
170 static uint8_t GetDefaultRecType() { return 0; }
173 static void SplitName(const std::string
&full
, std::string
&first
, std::string
&last
);
174 static std::string
Email2CommaString(const EmailList
&list
);
175 static void CommaString2Email(const std::string
&list
, EmailList
&result
);
177 // Generic Field Handle support
178 static const FieldHandle
<Contact
>::ListT
& GetFieldHandles();
181 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const Contact
&contact
) {