ReleaseChecklist: added notes on how to access sourceforge shell
[barry.git] / src / r_contact.h
blob1f0f58329d5b932b9042f5d4336c8fdb108938a4
1 ///
2 /// \file r_contact.h
3 /// Blackberry database record parser class for contact records.
4 ///
6 /*
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__
25 #include "dll.h"
26 #include "record.h"
27 #include <iosfwd>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <stdint.h>
33 namespace Barry {
35 // forward declarations
36 class IConverter;
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 struct BXEXPORT ContactGroupLink
45 uint32_t Link;
46 uint16_t Unknown;
48 ContactGroupLink() : Link(0), Unknown(0) {}
49 ContactGroupLink(uint32_t link, uint16_t unknown)
50 : Link(link), Unknown(unknown)
54 /// \addtogroup RecordParserClasses
55 /// @{
58 // Contact record class
60 /// Represents a single record in the Address Book Blackberry database.
61 ///
62 class BXEXPORT Contact
64 public:
65 typedef Barry::CategoryList CategoryList;
66 typedef ContactGroupLink GroupLink;
67 typedef std::vector<GroupLink> GroupLinksType;
68 typedef std::vector<UnknownField> UnknownsType;
69 typedef std::string EmailType;
70 typedef std::vector<EmailType> EmailList;
73 // Record fields
76 // contact specific data
77 uint8_t RecType;
78 uint32_t RecordId;
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.
88 std::string Phone;
90 std::string
91 Fax,
92 WorkPhone,
93 HomePhone,
94 MobilePhone,
95 Pager,
96 PIN,
97 Radio,
98 WorkPhone2,
99 HomePhone2,
100 OtherPhone,
101 FirstName,
102 LastName,
103 Company,
104 DefaultCommunicationsMethod,
105 JobTitle,
106 PublicKey,
107 URL,
108 Prefix,
109 Notes,
110 UserDefined1,
111 UserDefined2,
112 UserDefined3,
113 UserDefined4,
114 Image;
116 Date Birthday;
117 Date Anniversary;
119 PostalAddress WorkAddress;
120 PostalAddress HomeAddress;
122 // Categories are not allowed to have commas in them.
123 // A category name containing a comma will be split into
124 // two categories, not only by this library, but by the
125 // device itself.
126 CategoryList Categories;
128 GroupLinksType GroupLinks;
129 UnknownsType Unknowns;
131 private:
132 bool m_FirstNameSeen;
134 public:
135 const unsigned char* ParseField(const unsigned char *begin,
136 const unsigned char *end, const IConverter *ic = 0);
138 public:
139 Contact();
140 ~Contact();
142 uint32_t GetID() const { return RecordId; }
143 std::string GetFullName() const;
144 const std::string& GetEmail(unsigned int index = 0) const;
146 // Parser / Builder API (see parser.h / builder.h)
147 uint8_t GetRecType() const { return RecType; }
148 uint32_t GetUniqueId() const { return RecordId; }
149 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
150 void ParseHeader(const Data &data, size_t &offset);
151 void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
152 void BuildHeader(Data &data, size_t &offset) const;
153 void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
155 void Clear(); // erase everything
157 void Dump(std::ostream &os) const;
159 // sorting - put group links at the end
160 bool operator<(const Contact &other) const {
161 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
162 // // testing - put group links at the top
163 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
166 // database name
167 static const char * GetDBName() { return "Address Book"; }
168 static uint8_t GetDefaultRecType() { return 0; }
170 // helpers
171 static void SplitName(const std::string &full, std::string &first, std::string &last);
174 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
175 contact.Dump(os);
176 return os;
179 /// @}
181 } // namespace Barry
183 #endif