~ubuntu-branches/ubuntu/trusty/jreen/trusty

« back to all changes in this revision

Viewing changes to src/vcard.cpp

  • Committer: Package Import Robot
  • Author(s): Prasad Murthy
  • Date: 2013-03-08 00:00:33 UTC
  • Revision ID: package-import@ubuntu.com-20130308000033-x8thp6syo1kkh63s
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Jreen
 
4
**
 
5
** Copyright Ā© 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
 
6
**
 
7
*****************************************************************************
 
8
**
 
9
** $JREEN_BEGIN_LICENSE$
 
10
** This program is free software: you can redistribute it and/or modify
 
11
** it under the terms of the GNU General Public License as published by
 
12
** the Free Software Foundation, either version 2 of the License, or
 
13
** (at your option) any later version.
 
14
**
 
15
** This program is distributed in the hope that it will be useful,
 
16
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
** See the GNU General Public License for more details.
 
19
**
 
20
** You should have received a copy of the GNU General Public License
 
21
** along with this program.  If not, see http://www.gnu.org/licenses/.
 
22
** $JREEN_END_LICENSE$
 
23
**
 
24
****************************************************************************/
 
25
 
 
26
#include "vcard_p.h"
 
27
 
 
28
namespace Jreen {
 
29
 
 
30
VCard::Name::Name() : d_ptr(new VCard::NamePrivate)
 
31
{
 
32
}
 
33
 
 
34
VCard::Name::Name(const VCard::Name &o) : d_ptr(o.d_ptr)
 
35
{
 
36
}
 
37
 
 
38
VCard::Name::Name(VCard::NamePrivate &p) : d_ptr(&p)
 
39
{
 
40
}
 
41
 
 
42
VCard::Name::~Name()
 
43
{
 
44
}
 
45
 
 
46
VCard::Name &VCard::Name::operator =(const VCard::Name &o)
 
47
{
 
48
        d_ptr = o.d_ptr;
 
49
        return *this;
 
50
}
 
51
 
 
52
QString VCard::Name::family() const
 
53
{
 
54
        return d_ptr->family;
 
55
}
 
56
 
 
57
void VCard::Name::setFamily(const QString &name)
 
58
{
 
59
        d_ptr->family = name;
 
60
}
 
61
 
 
62
QString VCard::Name::given() const
 
63
{
 
64
        return d_ptr->given;
 
65
}
 
66
 
 
67
void VCard::Name::setGiven(const QString &name)
 
68
{
 
69
        d_ptr->given = name;
 
70
}
 
71
 
 
72
QString VCard::Name::middle() const
 
73
{
 
74
        return d_ptr->middle;
 
75
}
 
76
 
 
77
void VCard::Name::setMiddle(const QString &name)
 
78
{
 
79
        d_ptr->middle = name;
 
80
}
 
81
 
 
82
QString VCard::Name::prefix() const
 
83
{
 
84
        return d_ptr->prefix;
 
85
}
 
86
 
 
87
void VCard::Name::setPrefix(const QString &name)
 
88
{
 
89
        d_ptr->prefix = name;
 
90
}
 
91
 
 
92
QString VCard::Name::suffix() const
 
93
{
 
94
        return d_ptr->suffix;
 
95
}
 
96
 
 
97
void VCard::Name::setSuffix(const QString &name)
 
98
{
 
99
        d_ptr->suffix = name;
 
100
}
 
101
 
 
102
VCard::Photo::Photo() : d_ptr(new PhotoPrivate)
 
103
{
 
104
}
 
105
 
 
106
VCard::Photo::Photo(const Photo &o) : d_ptr(o.d_ptr)
 
107
{
 
108
}
 
109
 
 
110
VCard::Photo::Photo(VCard::PhotoPrivate &p) : d_ptr(&p)
 
111
{
 
112
}
 
113
 
 
114
VCard::Photo::~Photo()
 
115
{
 
116
}
 
117
 
 
118
VCard::Photo &VCard::Photo::operator =(const Photo &o)
 
119
{
 
120
        d_ptr = o.d_ptr;
 
121
        return *this;
 
122
}
 
123
 
 
124
QString VCard::Photo::external() const
 
125
{
 
126
        return d_ptr->extval;
 
127
}
 
128
 
 
129
void VCard::Photo::setExternal(const QString &extval)
 
130
{
 
131
        d_ptr->extval = extval;
 
132
        d_ptr->binval = QByteArray();
 
133
        d_ptr->type = QString();
 
134
}
 
135
 
 
136
void VCard::Photo::setData(const QByteArray &data, const QString &mimeType)
 
137
{
 
138
        d_ptr->extval = QString();
 
139
        d_ptr->binval = data;
 
140
        d_ptr->type = mimeType;
 
141
}
 
142
 
 
143
QByteArray VCard::Photo::data() const
 
144
{
 
145
        return d_ptr->binval;
 
146
}
 
147
 
 
148
QString VCard::Photo::mimeType() const
 
149
{
 
150
        return d_ptr->type;
 
151
}
 
152
 
 
153
VCard::Telephone::Telephone() : d_ptr(new VCard::TelephonePrivate)
 
154
{
 
155
}
 
156
 
 
157
VCard::Telephone::Telephone(const Telephone &o) : d_ptr(o.d_ptr)
 
158
{
 
159
}
 
160
 
 
161
VCard::Telephone::Telephone(VCard::TelephonePrivate &p) : d_ptr(&p)
 
162
{
 
163
}
 
164
 
 
165
VCard::Telephone::~Telephone()
 
166
{
 
167
}
 
168
 
 
169
VCard::Telephone &VCard::Telephone::operator =(const VCard::Telephone &o)
 
170
{
 
171
        d_ptr = o.d_ptr;
 
172
        return *this;
 
173
}
 
174
 
 
175
bool VCard::Telephone::testType(Type t) const
 
176
{
 
177
        return d_ptr->types & t;
 
178
}
 
179
 
 
180
bool VCard::EMail::testType(Type t) const
 
181
{
 
182
        return d_ptr->types & t;
 
183
}
 
184
 
 
185
const QString &VCard::EMail::userId() const
 
186
{
 
187
        return d_ptr->userId;
 
188
}
 
189
 
 
190
void VCard::EMail::setType(Type t, bool value)
 
191
{
 
192
        d_ptr->types ^= ((d_ptr->types & t) == t) == value ? 0 : t;
 
193
}
 
194
 
 
195
void VCard::EMail::setUserId(const QString &userId)
 
196
{
 
197
        d_ptr->userId = userId;
 
198
}
 
199
 
 
200
void VCard::Telephone::setType(Type t, bool value)
 
201
{
 
202
        d_ptr->types ^= ((d_ptr->types & t) == t) == value ? 0 : t;
 
203
}
 
204
 
 
205
QString VCard::Telephone::number() const
 
206
{
 
207
        return d_ptr->number;
 
208
}
 
209
 
 
210
void VCard::Telephone::setNumber(const QString &number)
 
211
{
 
212
        d_ptr->number = number;
 
213
}
 
214
 
 
215
VCard::EMail::EMail() : d_ptr(new VCard::EMailPrivate)
 
216
{
 
217
}
 
218
 
 
219
VCard::EMail::EMail(const EMail &o) : d_ptr(o.d_ptr)
 
220
{
 
221
}
 
222
 
 
223
VCard::EMail::EMail(VCard::EMailPrivate &p) : d_ptr(&p)
 
224
{
 
225
}
 
226
 
 
227
VCard::EMail::~EMail()
 
228
{
 
229
}
 
230
 
 
231
VCard::EMail &VCard::EMail::operator =(const EMail &o)
 
232
{
 
233
        d_ptr = o.d_ptr;
 
234
        return *this;
 
235
}
 
236
 
 
237
VCard::Address::Address() : d_ptr(new VCard::AddressPrivate)
 
238
{
 
239
}
 
240
 
 
241
VCard::Address::Address(const Address &o) : d_ptr(o.d_ptr)
 
242
{
 
243
}
 
244
 
 
245
VCard::Address::Address(VCard::AddressPrivate &p) : d_ptr(&p)
 
246
{
 
247
}
 
248
 
 
249
VCard::Address::~Address()
 
250
{
 
251
}
 
252
 
 
253
VCard::Address &VCard::Address::operator =(const VCard::Address &o)
 
254
{
 
255
        d_ptr = o.d_ptr;
 
256
        return *this;
 
257
}
 
258
 
 
259
bool VCard::Address::testType(VCard::Address::Type t) const
 
260
{
 
261
        return d_ptr->types & t;
 
262
}
 
263
 
 
264
QString VCard::Address::postBox() const
 
265
{
 
266
        return d_ptr->pobox;
 
267
}
 
268
 
 
269
QString VCard::Address::extendedAddress() const
 
270
{
 
271
        return d_ptr->extendedAddress;
 
272
}
 
273
 
 
274
QString VCard::Address::street() const
 
275
{
 
276
        return d_ptr->street;
 
277
}
 
278
 
 
279
QString VCard::Address::locality() const
 
280
{
 
281
        return d_ptr->locality;
 
282
}
 
283
 
 
284
QString VCard::Address::region() const
 
285
{
 
286
        return d_ptr->region;
 
287
}
 
288
 
 
289
QString VCard::Address::postCode() const
 
290
{
 
291
        return d_ptr->pcode;
 
292
}
 
293
 
 
294
QString VCard::Address::country() const
 
295
{
 
296
        return d_ptr->country;
 
297
}
 
298
 
 
299
void VCard::Address::setType(VCard::Address::Type t, bool value)
 
300
{
 
301
        d_ptr->types ^= ((d_ptr->types & t) == t) == value ? 0 : t;
 
302
}
 
303
 
 
304
void VCard::Address::setPostBox(const QString &postBox)
 
305
{
 
306
        d_ptr->pobox = postBox;
 
307
}
 
308
 
 
309
void VCard::Address::setExtendedAddress(const QString &extendedAddress)
 
310
{
 
311
        d_ptr->extendedAddress = extendedAddress;
 
312
}
 
313
 
 
314
void VCard::Address::setStreet(const QString &street)
 
315
{
 
316
        d_ptr->street = street;
 
317
}
 
318
 
 
319
void VCard::Address::setLocality(const QString &locality)
 
320
{
 
321
        d_ptr->locality = locality;
 
322
}
 
323
 
 
324
void VCard::Address::setRegion(const QString &region)
 
325
{
 
326
        d_ptr->region = region;
 
327
}
 
328
 
 
329
void VCard::Address::setPostCode(const QString &postCode)
 
330
{
 
331
        d_ptr->pcode = postCode;
 
332
}
 
333
 
 
334
void VCard::Address::setCountry(const QString &country)
 
335
{
 
336
        d_ptr->country = country;
 
337
}
 
338
 
 
339
VCard::Organization::Organization() : d_ptr(new VCard::OrganizationPrivate)
 
340
{
 
341
}
 
342
 
 
343
VCard::Organization::Organization(const Organization &o) : d_ptr(o.d_ptr)
 
344
{
 
345
}
 
346
 
 
347
VCard::Organization::Organization(OrganizationPrivate &p) : d_ptr(&p)
 
348
{
 
349
}
 
350
 
 
351
VCard::Organization::~Organization()
 
352
{
 
353
}
 
354
 
 
355
VCard::Organization &VCard::Organization::operator =(const VCard::Organization &o)
 
356
{
 
357
        d_ptr = o.d_ptr;
 
358
        return *this;
 
359
}
 
360
 
 
361
QString VCard::Organization::name() const
 
362
{
 
363
        return d_ptr->orgName;
 
364
}
 
365
 
 
366
QStringList VCard::Organization::units() const
 
367
{
 
368
        return d_ptr->orgUnits;
 
369
}
 
370
 
 
371
void VCard::Organization::setName(const QString &name)
 
372
{
 
373
        d_ptr->orgName = name;
 
374
}
 
375
 
 
376
void VCard::Organization::setUnits(const QStringList &units)
 
377
{
 
378
        d_ptr->orgUnits = units;
 
379
}
 
380
 
 
381
void VCard::Organization::addUnit(const QString &unit)
 
382
{
 
383
        d_ptr->orgUnits << unit;
 
384
}
 
385
 
 
386
VCard::VCard(const QString &formattedName, Classification classification)
 
387
        : d_ptr(new VCardPrivate)
 
388
{
 
389
        Q_D(VCard);
 
390
        d->formattedName = formattedName;
 
391
        d->classification = classification;
 
392
}
 
393
 
 
394
VCard::VCard(VCardPrivate &p) : d_ptr(&p)
 
395
{
 
396
}
 
397
 
 
398
VCard::~VCard()
 
399
{
 
400
}
 
401
 
 
402
void VCard::setFormattedName(const QString &fn)
 
403
{
 
404
        d_func()->formattedName = fn;
 
405
}
 
406
 
 
407
const QString &VCard::formattedName() const
 
408
{
 
409
        return d_func()->formattedName;
 
410
}
 
411
 
 
412
void VCard::setName(const Name &name)
 
413
{
 
414
        d_func()->name = name;
 
415
}
 
416
 
 
417
const VCard::Name& VCard::name() const
 
418
{
 
419
        return d_func()->name;
 
420
}
 
421
 
 
422
void VCard::setNickname(const QString& nickname)
 
423
{
 
424
        d_func()->nickname = nickname;
 
425
}
 
426
 
 
427
QString VCard::nickname() const
 
428
{
 
429
        return d_func()->nickname;
 
430
}
 
431
 
 
432
void VCard::setName(const QString &family,
 
433
                                        const QString &given,
 
434
                                        const QString &middle,
 
435
                                        const QString &prefix,
 
436
                                        const QString &suffix)
 
437
{
 
438
        Q_D(VCard);
 
439
        d->name.setFamily(family);
 
440
        d->name.setGiven(given);
 
441
        d->name.setMiddle(middle);
 
442
        d->name.setPrefix(prefix);
 
443
        d->name.setSuffix(suffix);
 
444
}
 
445
 
 
446
void VCard::setPhoto(const QString &extval)
 
447
{
 
448
        Q_D(VCard);
 
449
        d->photo.setExternal(extval);
 
450
}
 
451
 
 
452
void VCard::setPhoto(const Photo &photo)
 
453
{
 
454
        d_func()->photo = photo;
 
455
}
 
456
 
 
457
VCard::Photo VCard::photo() const
 
458
{
 
459
        return d_func()->photo;
 
460
}
 
461
 
 
462
void VCard::setBday(const QDateTime& bday)
 
463
{
 
464
        d_func()->bday = bday;
 
465
}
 
466
 
 
467
void VCard::setBirthday(const QDateTime &bday)
 
468
{
 
469
        d_func()->bday = bday;
 
470
}
 
471
 
 
472
void VCard::setBirthday(const QDate &bday)
 
473
{
 
474
        d_func()->bday = QDateTime(bday, QTime(), Qt::UTC);
 
475
}
 
476
 
 
477
QDateTime VCard::bday() const
 
478
{
 
479
        return d_func()->bday;
 
480
}
 
481
 
 
482
QDateTime VCard::birthday() const
 
483
{
 
484
        return d_func()->bday;
 
485
}
 
486
 
 
487
void VCard::setUrl(const QUrl& url)
 
488
{
 
489
        d_func()->url = url;
 
490
}
 
491
 
 
492
const QUrl &VCard::url() const
 
493
{
 
494
        return d_func()->url;
 
495
}
 
496
 
 
497
QList<VCard::Telephone> VCard::telephones() const
 
498
{
 
499
        return d_func()->telephones;
 
500
}
 
501
 
 
502
void VCard::addTelephone(const Telephone &t)
 
503
{
 
504
        d_func()->telephones.append(t);
 
505
}
 
506
 
 
507
void VCard::addEmail(const EMail &email)
 
508
{
 
509
        d_func()->emails.append(email);
 
510
}
 
511
 
 
512
QList<VCard::EMail> VCard::emails() const
 
513
{
 
514
        return d_func()->emails;
 
515
}
 
516
 
 
517
QList<VCard::Address> VCard::addresses() const
 
518
{
 
519
        return d_func()->addresses;
 
520
}
 
521
 
 
522
void VCard::addAdress(const Address &adr)
 
523
{
 
524
        return d_func()->addresses.append(adr);
 
525
}
 
526
 
 
527
void VCard::setDesc(const QString& desc)
 
528
{
 
529
        d_func()->description = desc;
 
530
}
 
531
 
 
532
const QString& VCard::desc() const
 
533
{
 
534
        return d_func()->description;
 
535
}
 
536
 
 
537
void VCard::setTitle(const QString& title)
 
538
{
 
539
        d_func()->title = title;
 
540
}
 
541
 
 
542
QString VCard::title() const
 
543
{
 
544
        return d_func()->title;
 
545
}
 
546
 
 
547
void VCard::setRole(const QString& role)
 
548
{
 
549
        d_func()->role = role;
 
550
}
 
551
 
 
552
QString VCard::role() const
 
553
{
 
554
        return d_func()->role;
 
555
}
 
556
 
 
557
void VCard::setOrganization(const VCard::Organization &org)
 
558
{
 
559
        d_func()->org = org;
 
560
}
 
561
 
 
562
void VCard::setOrganization(const QString &orgName, const QStringList &orgUnits)
 
563
{
 
564
        Q_D(VCard);
 
565
        d->org.setName(orgName);
 
566
        d->org.setUnits(orgUnits);
 
567
}
 
568
 
 
569
VCard::Organization VCard::organization()
 
570
{
 
571
        return d_func()->org;
 
572
}
 
573
 
 
574
} // namespace Jreen