Release tarball for barry-0.9
[barry.git] / src / r_contact.h
blob9373f9fb826ed439a7c0c1ae9283fa33469a1e06
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.
39 struct ContactGroupLink
41 uint32_t Link;
42 uint16_t Unknown;
44 ContactGroupLink() : Link(0), Unknown(0) {}
45 ContactGroupLink(uint32_t link, uint16_t unknown)
46 : Link(link), Unknown(unknown)
50 typedef std::vector<std::string> CategoryList;
52 /// \addtogroup RecordParserClasses
53 /// @{
55 class Contact
57 public:
58 typedef Barry::CategoryList CategoryList;
59 typedef ContactGroupLink GroupLink;
60 typedef std::vector<GroupLink> GroupLinksType;
61 typedef std::vector<UnknownField> UnknownsType;
63 // contact specific data
64 uint8_t RecType;
65 uint32_t RecordId;
66 std::string
67 Email,
68 Phone,
69 Fax,
70 WorkPhone,
71 HomePhone,
72 MobilePhone,
73 Pager,
74 PIN,
75 Radio,
76 WorkPhone2,
77 HomePhone2,
78 OtherPhone,
79 FirstName,
80 LastName,
81 Company,
82 DefaultCommunicationsMethod,
83 JobTitle,
84 PublicKey,
85 URL,
86 Prefix,
87 Notes,
88 UserDefined1,
89 UserDefined2,
90 UserDefined3,
91 UserDefined4,
92 Image;
94 PostalAddress WorkAddress;
95 PostalAddress HomeAddress;
97 // Categories are not allowed to have commas in them.
98 // A category name containing a comma will be split into
99 // two categories, not only by this library, but by the
100 // device itself.
101 CategoryList Categories;
103 GroupLinksType GroupLinks;
104 UnknownsType Unknowns;
106 private:
107 bool m_FirstNameSeen;
109 //protected:
110 public:
111 const unsigned char* ParseField(const unsigned char *begin,
112 const unsigned char *end);
114 public:
115 Contact();
116 ~Contact();
118 uint32_t GetID() const { return RecordId; }
119 std::string GetFullName() const;
121 // Parser / Builder API (see parser.h / builder.h)
122 uint8_t GetRecType() const { return RecType; }
123 uint32_t GetUniqueId() const { return RecordId; }
124 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
125 void ParseHeader(const Data &data, size_t &offset);
126 void ParseFields(const Data &data, size_t &offset);
127 void BuildHeader(Data &data, size_t &offset) const;
128 void BuildFields(Data &data, size_t &offset) const;
130 void Clear(); // erase everything
132 void Dump(std::ostream &os) const;
134 // sorting - put group links at the end
135 bool operator<(const Contact &other) const {
136 return GroupLinks.size() == 0 && other.GroupLinks.size() > 0;
137 // // testing - put group links at the top
138 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
141 // database name
142 static const char * GetDBName() { return "Address Book"; }
143 static uint8_t GetDefaultRecType() { return 0; }
145 // helpers
146 static void SplitName(const std::string &full, std::string &first, std::string &last);
147 static void CategoryStr2List(const std::string &str, Barry::CategoryList &list);
148 static void CategoryList2Str(const Barry::CategoryList &list, std::string &str);
151 inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
152 contact.Dump(os);
153 return os;
156 /// @}
158 } // namespace Barry
160 #endif