summaryrefslogtreecommitdiff
path: root/src/containers/kolabcontact.h
blob: 58ded59eb4e1d41316cd90a5f381a02b4fb6b7b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
/*
 * Copyright (C) 2011  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KOLABCONTACT_H
#define KOLABCONTACT_H

#include <string>
#include <vector>
#include <boost/scoped_ptr.hpp>
#include "kolabcontainers.h"

namespace Kolab {
    
struct NameComponents {
    bool operator==(const NameComponents &other) const { return mSurnames == other.mSurnames &&
                                                        mGiven == other.mGiven &&
                                                        mAdditional == other.mAdditional &&
                                                        mPrefixes == other.mPrefixes &&
                                                        mSuffixes == other.mSuffixes;
                                                        };
    void setSurnames(const std::vector<std::string> &s) { mSurnames = s; };
    std::vector<std::string> surnames() const { return mSurnames; };
    void setGiven(const std::vector<std::string> &s) { mGiven = s; };
    std::vector<std::string> given() const { return mGiven; };
    void setAdditional(const std::vector<std::string> &s) { mAdditional = s; };
    std::vector<std::string> additional() const { return mAdditional; };
    void setPrefixes(const std::vector<std::string> &s) { mPrefixes = s; };
    std::vector<std::string> prefixes() const { return mPrefixes; };
    void setSuffixes(const std::vector<std::string> &s) { mSuffixes = s; };
    std::vector<std::string> suffixes() const { return mSuffixes; };
    bool isValid() const { return !(mSurnames.empty() && mGiven.empty() && mAdditional.empty() && mPrefixes.empty() && mSuffixes.empty()); };
private:
    std::vector<std::string> mSurnames;
    std::vector<std::string> mGiven;
    std::vector<std::string> mAdditional;
    std::vector<std::string> mPrefixes;
    std::vector<std::string> mSuffixes;
};

struct Related {
    
    enum DescriptionType {
        Invalid,
        Text,
        Uid
    };
    Related(): mType(Invalid), mRelationType(NoRelation) {};
    Related(DescriptionType t, const std::string &textOrUri, int relationType = NoRelation)
    :   mType(t), mRelationType(relationType)
    {
        if (t == Text) {
            mText = textOrUri;
        } else {
            mUri = textOrUri;
        }
    };
    bool operator==(const Related &other) const { return mType == other.mType &&
    mUri == other.mUri &&
    mText == other.mText &&
    mRelationType == other.mRelationType;
    };
    DescriptionType type() const { return mType; };
    std::string uri() const { return mUri; };
    std::string text() const { return mText; };
    enum RelationType {
        NoRelation = 0,
        Child = 0x01,
        Spouse = 0x02,
        Manager = 0x04,
        Assistant = 0x08,
    };
    void setRelationTypes(int t) { mRelationType = t; };
    int relationTypes() const { return mRelationType; };
private:
    DescriptionType mType;
    std::string mUri;
    std::string mText;
    int mRelationType;
};

struct Address {
    
    Address(): mTypes(0) {};
    enum Type {
        Work = 0x01,
        Home = 0x02
    };
    bool operator==(const Address &other) const { return mTypes == other.mTypes &&
    mLabel == other.mLabel &&
    mStreet == other.mStreet &&
    mLocality == other.mLocality &&
    mRegion == other.mRegion &&
    mCode == other.mCode &&
    mCountry == other.mCountry;
    };
    void setTypes(int t) { mTypes = t; };
    int types() const { return mTypes; };
    
    void setLabel(const std::string &s) { mLabel = s; };
    std::string label() const { return mLabel; }
    
    void setStreet(const std::string &s) { mStreet = s; };
    std::string street() const { return mStreet; };
    
    void setLocality(const std::string &s) { mLocality = s; };
    std::string locality() const { return mLocality; };
    
    void setRegion(const std::string &s) { mRegion = s; };
    std::string region() const { return mRegion; };
    
    void setCode(const std::string &s) { mCode = s; };
    std::string code() const { return mCode; };
    
    void setCountry(const std::string &s) { mCountry = s; };
    std::string country() const { return mCountry; };
private:
    int mTypes;
    std::string mLabel;
    std::string mStreet;
    std::string mLocality;
    std::string mRegion;
    std::string mCode;
    std::string mCountry;
};

struct Affiliation {
    bool operator==(const Affiliation &other) const { return mOrg == other.mOrg &&
                                                    mOrgUnits == other.mOrgUnits &&
                                                    mLogo == other.mLogo &&
                                                    mLogoMimetype == other.mLogoMimetype &&
                                                    mRoles == other.mRoles &&
                                                    mRelateds == other.mRelateds &&
                                                    mOffices == other.mOffices;
                                                    };
    void setOrganisation(const std::string &org) { mOrg = org; };
    std::string organisation() const { return mOrg; };
    void setOrganisationalUnits(const std::vector<std::string> &units) { mOrgUnits = units; };
    std::vector<std::string> organisationalUnits() const { return mOrgUnits; };
    void setLogo(const std::string &l, const std::string mimetype) { mLogo = l; mLogoMimetype = mimetype; };
    std::string logo() const { return mLogo; };
    std::string logoMimetype() const { return mLogoMimetype; };

    void setRoles(const std::vector<std::string> &roles) { mRoles = roles; };
    std::vector<std::string> roles() const { return mRoles; };
    void setRelateds(const std::vector<Related> &relateds) { mRelateds = relateds; };
    std::vector<Related> relateds() const { return mRelateds; };
    void setAddresses(const std::vector<Address> &offices) { mOffices = offices; };
    std::vector<Address> addresses() const { return mOffices; };
private:
    std::string mOrg;
    std::vector<std::string> mOrgUnits;
    std::string mLogo;
    std::string mLogoMimetype;
    std::vector<std::string> mRoles;
    std::vector<Related> mRelateds;
    std::vector<Address> mOffices;
};

struct Telephone {
    enum Type {
        Work = 0x01,
        Home = 0x02,
        Text = 0x04,
        Voice = 0x08,
        Fax = 0x10,
        Cell = 0x20,
        Video = 0x40,
        Pager = 0x80,
        Textphone = 0x100,
        Car = 0x200
    };
    Telephone(): mType(0){};
    bool operator==(const Telephone &other) const { return mNumber == other.mNumber &&
                                                    mType == other.mType;
                                                    };
    void setTypes(int t) { mType = t; };
    int types() const { return mType; };
    void setNumber(const std::string &n) { mNumber = n; };
    std::string number() const { return mNumber; };
private:
    std::string mNumber;
    int mType;
};

struct Email {
    enum Type {
        NoType = 0,
        Work = 0x01,
        Home = 0x02
    };
    Email(): mType(NoType){};
    Email(const std::string &a, int t = NoType): mAddress(a), mType(t) {};
    bool operator==(const Email &other) const { return mAddress == other.mAddress &&
                                                    mType == other.mType; };
    void setTypes(int t) { mType = t; };
    int types() const { return mType; };
    void setAddress(const std::string &n) { mAddress = n; };
    std::string address() const { return mAddress; };
private:
    std::string mAddress;
    int mType;
};

struct Crypto {
    enum CryptoTypes {
        PGPinline = 0x01,
        PGPmime = 0x02,
        SMIME = 0x04,
        SMIMEopaque = 0x08
    };
    
    enum CryptoPref {
        Ask,
        Never,
        Always,
        IfPossible
    };
    Crypto(): mCryptoTypes(0), mSignPref(Ask), mEncryptPref(Ask){};
    bool operator==(const Crypto &other) const { return mCryptoTypes == other.mCryptoTypes &&
                                                    mSignPref == other.mSignPref &&
                                                    mEncryptPref == other.mEncryptPref; };
    bool isValid() const { return mCryptoTypes; };

    void setAllowed(int cryptoTypes) { mCryptoTypes = cryptoTypes; };
    int allowed() const { return mCryptoTypes; };
    void setSignPref(CryptoPref p) { mSignPref = p; };
    CryptoPref signPref() const { return mSignPref; };
    void setEncryptPref(CryptoPref p) { mEncryptPref = p; };
    CryptoPref encryptPref() const { return mEncryptPref; };
private:
    int mCryptoTypes;
    CryptoPref mSignPref;
    CryptoPref mEncryptPref;
};

struct Geo {
    Geo(): latitude(0.0), longitude(0.0) {};
    Geo(double lat, double lon)
    : latitude(lat), longitude(lon) {};
    
    bool operator==(const Geo &other) const{ return (longitude == other.longitude && latitude == other.latitude);};
    double latitude;
    double longitude;
};

struct Url {
    enum UrlTypes {
        NoType = 0,
        Blog
    };
    Url(): mType(NoType) {};
    Url(const std::string &u, int t = NoType): mUrl(u), mType(t) {};
    
    bool operator==(const Url &other) const{ return (mType == other.mType && mUrl == other.mUrl);};
    
    int type() const { return mType; };
    std::string url() const { return mUrl; };
private:
    std::string mUrl;
    int mType;
};

struct Key {
    enum KeyType {
        Invalid,
        PGP,
        PKCS7_MIME
    };
    Key(): keytype(Invalid) {};
    Key(const std::string &k, KeyType type)
    : mKey(k), keytype(type) {};
    
    bool operator==(const Key &other) const{ return (mKey == other.mKey && keytype == other.keytype);};
    
    KeyType type() const { return keytype; };
    std::string key() const { return mKey; };
    
private:
    std::string mKey;
    KeyType keytype;
};


class DistList {
public:
    DistList();
    ~DistList();
    DistList(const DistList &);
    void operator=(const DistList &);

    bool isValid() const;

    void setUid(const std::string &);
    std::string uid() const;

    void setLastModified(const cDateTime &);
    cDateTime lastModified() const;

    void setName(const std::string &);
    std::string name() const;

    void setMembers(const std::vector<ContactReference> &);
    std::vector<ContactReference> members() const;

    void setCustomProperties(const std::vector<CustomProperty> &);
    std::vector<CustomProperty> customProperties() const;

private:
    struct Private;
    boost::scoped_ptr<Private> d;
};

class Contact {
public:
    Contact();
    ~Contact();
    Contact(const Contact &);
    void operator=(const Contact &);

    bool isValid() const;

    void setUid(const std::string &);
    std::string uid() const;
    
    void setLastModified(const cDateTime &);
    cDateTime lastModified() const;
    
    void setCategories(const std::vector<std::string> &);
    void addCategory(const std::string &);
    std::vector<std::string> categories() const;
    
    void setName(const std::string &);
    std::string name() const;
    
    void setNameComponents(const NameComponents &);
    NameComponents nameComponents() const;
    
    void setNote(const std::string &);
    std::string note() const;
    
    void setFreeBusyUrl(const std::string &);
    std::string freeBusyUrl() const;
    
    void setTitles(const std::vector<std::string> &titles);
    std::vector<std::string> titles() const;
    
    void setAffiliations(const std::vector<Affiliation> &);
    std::vector<Affiliation> affiliations() const;
    
    void setUrls(const std::vector<Url> &);
    std::vector<Url> urls() const;
    
    void setAddresses(const std::vector<Address> &, int preferred = -1);
    std::vector<Address> addresses() const;
    int addressPreferredIndex() const;
    
    void setNickNames(const std::vector< std::string > &);
    std::vector< std::string > nickNames() const;
    
    void setRelateds(const std::vector<Related> &);
    std::vector<Related> relateds() const;
     
    void setBDay(const cDateTime &);
    cDateTime bDay() const;
    
    void setAnniversary(const cDateTime &);
    cDateTime anniversary() const;
    
    void setPhoto(const std::string &data, const std::string &mimetype);
    std::string photo() const;
    std::string photoMimetype() const;
    
    enum Gender {
        NotSet,
        NotSpecified,
        Male,
        Female
    };
    
    void setGender(Gender);
    Gender gender() const;
    
    void setLanguages(const std::vector<std::string> &);
    std::vector<std::string> languages() const;
    
    void setTelephones(const std::vector<Telephone> &, int preferredIndex = -1);
    std::vector<Telephone> telephones() const;
    int telephonesPreferredIndex() const;
    
    void setIMaddresses(const std::vector<std::string> &, int preferredIndex = -1);
    std::vector<std::string> imAddresses() const;
    int imAddressPreferredIndex() const;
    
    void setEmailAddresses(const std::vector<Email> &, int preferredIndex = -1);
    std::vector<Email> emailAddresses() const;
    int emailAddressPreferredIndex() const;
    
    void setGPSpos(const std::vector<Geo> &);
    std::vector<Geo> gpsPos() const;
    
    void setKeys(const std::vector<Key> &);
    std::vector<Key> keys() const;
    
    void setCrypto(const Crypto &);
    Crypto crypto() const;
    
    void setCustomProperties(const std::vector<CustomProperty> &);
    std::vector<CustomProperty> customProperties() const;

private:
    struct Private;
    boost::scoped_ptr<Private> d;
};

} //Namespace

#endif // KOLABCONTACT_H