3 /// Blackberry database record parser class for contact records.
7 Copyright (C) 2005-2009, 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 typedef std::vector
<std::string
> CategoryList
;
56 /// \addtogroup RecordParserClasses
60 // Contact record class
62 /// Represents a single record in the Address Book Blackberry database.
64 class BXEXPORT Contact
67 typedef Barry::CategoryList CategoryList
;
68 typedef ContactGroupLink GroupLink
;
69 typedef std::vector
<GroupLink
> GroupLinksType
;
70 typedef std::vector
<UnknownField
> UnknownsType
;
71 typedef std::string EmailType
;
72 typedef std::vector
<EmailType
> EmailList
;
78 // contact specific data
81 EmailList EmailAddresses
;
83 /// This field, Phone, is deprecated. It is possible
84 /// to write to this field to the Blackberry,
85 /// but modern devices won't let you add it
86 /// through their GUIs. This field only seems
87 /// to exist on the 7750. While other devices
88 /// accept the field and display it, it is
89 /// not accessible by default.
106 DefaultCommunicationsMethod
,
121 PostalAddress WorkAddress
;
122 PostalAddress HomeAddress
;
124 // Categories are not allowed to have commas in them.
125 // A category name containing a comma will be split into
126 // two categories, not only by this library, but by the
128 CategoryList Categories
;
130 GroupLinksType GroupLinks
;
131 UnknownsType Unknowns
;
134 bool m_FirstNameSeen
;
137 const unsigned char* ParseField(const unsigned char *begin
,
138 const unsigned char *end
, const IConverter
*ic
= 0);
144 uint32_t GetID() const { return RecordId
; }
145 std::string
GetFullName() const;
146 const std::string
& GetEmail(unsigned int index
= 0) const;
148 // Parser / Builder API (see parser.h / builder.h)
149 uint8_t GetRecType() const { return RecType
; }
150 uint32_t GetUniqueId() const { return RecordId
; }
151 void SetIds(uint8_t Type
, uint32_t Id
) { RecType
= Type
; RecordId
= Id
; }
152 void ParseHeader(const Data
&data
, size_t &offset
);
153 void ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
= 0);
154 void BuildHeader(Data
&data
, size_t &offset
) const;
155 void BuildFields(Data
&data
, size_t &offset
, const IConverter
*ic
= 0) const;
157 void Clear(); // erase everything
159 void Dump(std::ostream
&os
) const;
161 // sorting - put group links at the end
162 bool operator<(const Contact
&other
) const {
163 return GroupLinks
.size() == 0 && other
.GroupLinks
.size() > 0;
164 // // testing - put group links at the top
165 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
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 void CategoryStr2List(const std::string
&str
, Barry::CategoryList
&list
);
175 static void CategoryList2Str(const Barry::CategoryList
&list
, std::string
&str
);
178 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const Contact
&contact
) {