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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
// SPDX-FileCopyrightText: 2010 Manjeet Dahiya <manjeetdahiya@gmail.com>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "QXmppVCardIq.h"
#include "QXmppConstants_p.h"
#include "QXmppUtils.h"
#include <QBuffer>
#include <QXmlStreamWriter>
static QString getImageType(const QByteArray &contents)
{
if (contents.startsWith("\x89PNG\x0d\x0a\x1a\x0a")) {
return QStringLiteral("image/png");
} else if (contents.startsWith("\x8aMNG")) {
return QStringLiteral("video/x-mng");
} else if (contents.startsWith("GIF8")) {
return QStringLiteral("image/gif");
} else if (contents.startsWith("BM")) {
return QStringLiteral("image/bmp");
} else if (contents.contains("/* XPM */")) {
return QStringLiteral("image/x-xpm");
} else if (contents.contains("<?xml") && contents.contains("<svg")) {
return QStringLiteral("image/svg+xml");
} else if (contents.startsWith("\xFF\xD8\xFF\xE0")) {
return QStringLiteral("image/jpeg");
}
return QStringLiteral("image/unknown");
}
class QXmppVCardAddressPrivate : public QSharedData
{
public:
QXmppVCardAddressPrivate() : type(QXmppVCardAddress::None) {};
QString country;
QString locality;
QString postcode;
QString region;
QString street;
QXmppVCardAddress::Type type;
};
/// Constructs an empty address.
QXmppVCardAddress::QXmppVCardAddress()
: d(new QXmppVCardAddressPrivate)
{
}
/// Copy-constructor
QXmppVCardAddress::QXmppVCardAddress(const QXmppVCardAddress &other) = default;
/// Move-constructor
QXmppVCardAddress::QXmppVCardAddress(QXmppVCardAddress &&) = default;
QXmppVCardAddress::~QXmppVCardAddress() = default;
/// Assignment operator.
QXmppVCardAddress &QXmppVCardAddress::operator=(const QXmppVCardAddress &other) = default;
/// Move-assignment operator.
QXmppVCardAddress &QXmppVCardAddress::operator=(QXmppVCardAddress &&) = default;
/// \brief Checks if two address objects represent the same address.
bool operator==(const QXmppVCardAddress &left, const QXmppVCardAddress &right)
{
return left.type() == right.type() &&
left.country() == right.country() &&
left.locality() == right.locality() &&
left.postcode() == right.postcode() &&
left.region() == right.region() &&
left.street() == right.street();
}
/// \brief Checks if two address objects represent different addresses.
bool operator!=(const QXmppVCardAddress &left, const QXmppVCardAddress &right)
{
return !(left == right);
}
/// Returns the country.
QString QXmppVCardAddress::country() const
{
return d->country;
}
/// Sets the country.
void QXmppVCardAddress::setCountry(const QString &country)
{
d->country = country;
}
/// Returns the locality.
QString QXmppVCardAddress::locality() const
{
return d->locality;
}
/// Sets the locality.
void QXmppVCardAddress::setLocality(const QString &locality)
{
d->locality = locality;
}
/// Returns the postcode.
QString QXmppVCardAddress::postcode() const
{
return d->postcode;
}
/// Sets the postcode.
void QXmppVCardAddress::setPostcode(const QString &postcode)
{
d->postcode = postcode;
}
/// Returns the region.
QString QXmppVCardAddress::region() const
{
return d->region;
}
/// Sets the region.
void QXmppVCardAddress::setRegion(const QString ®ion)
{
d->region = region;
}
/// Returns the street address.
QString QXmppVCardAddress::street() const
{
return d->street;
}
/// Sets the street address.
void QXmppVCardAddress::setStreet(const QString &street)
{
d->street = street;
}
/// Returns the address type, which is a combination of TypeFlag.
QXmppVCardAddress::Type QXmppVCardAddress::type() const
{
return d->type;
}
/// Sets the address \a type, which is a combination of TypeFlag.
void QXmppVCardAddress::setType(QXmppVCardAddress::Type type)
{
d->type = type;
}
/// \cond
void QXmppVCardAddress::parse(const QDomElement &element)
{
if (!element.firstChildElement(QStringLiteral("HOME")).isNull()) {
d->type |= Home;
}
if (!element.firstChildElement(QStringLiteral("WORK")).isNull()) {
d->type |= Work;
}
if (!element.firstChildElement(QStringLiteral("POSTAL")).isNull()) {
d->type |= Postal;
}
if (!element.firstChildElement(QStringLiteral("PREF")).isNull()) {
d->type |= Preferred;
}
d->country = element.firstChildElement(QStringLiteral("CTRY")).text();
d->locality = element.firstChildElement(QStringLiteral("LOCALITY")).text();
d->postcode = element.firstChildElement(QStringLiteral("PCODE")).text();
d->region = element.firstChildElement(QStringLiteral("REGION")).text();
d->street = element.firstChildElement(QStringLiteral("STREET")).text();
}
void QXmppVCardAddress::toXml(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("ADR"));
if (d->type & Home) {
writer->writeEmptyElement(QStringLiteral("HOME"));
}
if (d->type & Work) {
writer->writeEmptyElement(QStringLiteral("WORK"));
}
if (d->type & Postal) {
writer->writeEmptyElement(QStringLiteral("POSTAL"));
}
if (d->type & Preferred) {
writer->writeEmptyElement(QStringLiteral("PREF"));
}
if (!d->country.isEmpty()) {
writer->writeTextElement(QStringLiteral("CTRY"), d->country);
}
if (!d->locality.isEmpty()) {
writer->writeTextElement(QStringLiteral("LOCALITY"), d->locality);
}
if (!d->postcode.isEmpty()) {
writer->writeTextElement(QStringLiteral("PCODE"), d->postcode);
}
if (!d->region.isEmpty()) {
writer->writeTextElement(QStringLiteral("REGION"), d->region);
}
if (!d->street.isEmpty()) {
writer->writeTextElement(QStringLiteral("STREET"), d->street);
}
writer->writeEndElement();
}
/// \endcond
class QXmppVCardEmailPrivate : public QSharedData
{
public:
QXmppVCardEmailPrivate() : type(QXmppVCardEmail::None) {};
QString address;
QXmppVCardEmail::Type type;
};
/// Constructs an empty e-mail address.
QXmppVCardEmail::QXmppVCardEmail()
: d(new QXmppVCardEmailPrivate)
{
}
/// Constructs a copy of \a other.
QXmppVCardEmail::QXmppVCardEmail(const QXmppVCardEmail &other)
: d(other.d)
{
}
QXmppVCardEmail::~QXmppVCardEmail()
{
}
/// Assigns \a other to this e-mail address.
QXmppVCardEmail &QXmppVCardEmail::operator=(const QXmppVCardEmail &other)
{
d = other.d;
return *this;
}
/// \brief Checks if two email objects represent the same email address.
bool operator==(const QXmppVCardEmail &left, const QXmppVCardEmail &right)
{
return left.type() == right.type() &&
left.address() == right.address();
}
/// \brief Checks if two email objects represent different email addresses.
bool operator!=(const QXmppVCardEmail &left, const QXmppVCardEmail &right)
{
return !(left == right);
}
/// Returns the e-mail address.
QString QXmppVCardEmail::address() const
{
return d->address;
}
/// Sets the e-mail \a address.
void QXmppVCardEmail::setAddress(const QString &address)
{
d->address = address;
}
/// Returns the e-mail type, which is a combination of TypeFlag.
QXmppVCardEmail::Type QXmppVCardEmail::type() const
{
return d->type;
}
/// Sets the e-mail \a type, which is a combination of TypeFlag.
void QXmppVCardEmail::setType(QXmppVCardEmail::Type type)
{
d->type = type;
}
/// \cond
void QXmppVCardEmail::parse(const QDomElement &element)
{
if (!element.firstChildElement(QStringLiteral("HOME")).isNull()) {
d->type |= Home;
}
if (!element.firstChildElement(QStringLiteral("WORK")).isNull()) {
d->type |= Work;
}
if (!element.firstChildElement(QStringLiteral("INTERNET")).isNull()) {
d->type |= Internet;
}
if (!element.firstChildElement(QStringLiteral("PREF")).isNull()) {
d->type |= Preferred;
}
if (!element.firstChildElement(QStringLiteral("X400")).isNull()) {
d->type |= X400;
}
d->address = element.firstChildElement(QStringLiteral("USERID")).text();
}
void QXmppVCardEmail::toXml(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("EMAIL"));
if (d->type & Home) {
writer->writeEmptyElement(QStringLiteral("HOME"));
}
if (d->type & Work) {
writer->writeEmptyElement(QStringLiteral("WORK"));
}
if (d->type & Internet) {
writer->writeEmptyElement(QStringLiteral("INTERNET"));
}
if (d->type & Preferred) {
writer->writeEmptyElement(QStringLiteral("PREF"));
}
if (d->type & X400) {
writer->writeEmptyElement(QStringLiteral("X400"));
}
writer->writeTextElement(QStringLiteral("USERID"), d->address);
writer->writeEndElement();
}
/// \endcond
class QXmppVCardPhonePrivate : public QSharedData
{
public:
QXmppVCardPhonePrivate() : type(QXmppVCardPhone::None) {};
QString number;
QXmppVCardPhone::Type type;
};
/// Constructs an empty phone number.
QXmppVCardPhone::QXmppVCardPhone()
: d(new QXmppVCardPhonePrivate)
{
}
/// Constructs a copy of \a other.
QXmppVCardPhone::QXmppVCardPhone(const QXmppVCardPhone &other)
: d(other.d)
{
}
QXmppVCardPhone::~QXmppVCardPhone()
{
}
/// Assigns \a other to this phone number.
QXmppVCardPhone &QXmppVCardPhone::operator=(const QXmppVCardPhone &other)
{
d = other.d;
return *this;
}
/// Returns the phone number.
QString QXmppVCardPhone::number() const
{
return d->number;
}
/// \brief Checks if two phone objects represent the same phone number.
bool operator==(const QXmppVCardPhone &left, const QXmppVCardPhone &right)
{
return left.type() == right.type() &&
left.number() == right.number();
}
/// \brief Checks if two phone objects represent different phone numbers.
bool operator!=(const QXmppVCardPhone &left, const QXmppVCardPhone &right)
{
return !(left == right);
}
/// Sets the phone \a number.
void QXmppVCardPhone::setNumber(const QString &number)
{
d->number = number;
}
/// Returns the phone number type, which is a combination of TypeFlag.
QXmppVCardPhone::Type QXmppVCardPhone::type() const
{
return d->type;
}
/// Sets the phone number \a type, which is a combination of TypeFlag.
void QXmppVCardPhone::setType(QXmppVCardPhone::Type type)
{
d->type = type;
}
/// \cond
void QXmppVCardPhone::parse(const QDomElement &element)
{
if (!element.firstChildElement(QStringLiteral("HOME")).isNull()) {
d->type |= Home;
}
if (!element.firstChildElement(QStringLiteral("WORK")).isNull()) {
d->type |= Work;
}
if (!element.firstChildElement(QStringLiteral("VOICE")).isNull()) {
d->type |= Voice;
}
if (!element.firstChildElement(QStringLiteral("FAX")).isNull()) {
d->type |= Fax;
}
if (!element.firstChildElement(QStringLiteral("PAGER")).isNull()) {
d->type |= Pager;
}
if (!element.firstChildElement(QStringLiteral("MSG")).isNull()) {
d->type |= Messaging;
}
if (!element.firstChildElement(QStringLiteral("CELL")).isNull()) {
d->type |= Cell;
}
if (!element.firstChildElement(QStringLiteral("VIDEO")).isNull()) {
d->type |= Video;
}
if (!element.firstChildElement(QStringLiteral("BBS")).isNull()) {
d->type |= BBS;
}
if (!element.firstChildElement(QStringLiteral("MODEM")).isNull()) {
d->type |= Modem;
}
if (!element.firstChildElement(QStringLiteral("ISDN")).isNull()) {
d->type |= ISDN;
}
if (!element.firstChildElement(QStringLiteral("PCS")).isNull()) {
d->type |= PCS;
}
if (!element.firstChildElement(QStringLiteral("PREF")).isNull()) {
d->type |= Preferred;
}
d->number = element.firstChildElement(QStringLiteral("NUMBER")).text();
}
void QXmppVCardPhone::toXml(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("TEL"));
if (d->type & Home) {
writer->writeEmptyElement(QStringLiteral("HOME"));
}
if (d->type & Work) {
writer->writeEmptyElement(QStringLiteral("WORK"));
}
if (d->type & Voice) {
writer->writeEmptyElement(QStringLiteral("VOICE"));
}
if (d->type & Fax) {
writer->writeEmptyElement(QStringLiteral("FAX"));
}
if (d->type & Pager) {
writer->writeEmptyElement(QStringLiteral("PAGER"));
}
if (d->type & Messaging) {
writer->writeEmptyElement(QStringLiteral("MSG"));
}
if (d->type & Cell) {
writer->writeEmptyElement(QStringLiteral("CELL"));
}
if (d->type & Video) {
writer->writeEmptyElement(QStringLiteral("VIDEO"));
}
if (d->type & BBS) {
writer->writeEmptyElement(QStringLiteral("BBS"));
}
if (d->type & Modem) {
writer->writeEmptyElement(QStringLiteral("MODEM"));
}
if (d->type & ISDN) {
writer->writeEmptyElement(QStringLiteral("ISDN"));
}
if (d->type & PCS) {
writer->writeEmptyElement(QStringLiteral("PCS"));
}
if (d->type & Preferred) {
writer->writeEmptyElement(QStringLiteral("PREF"));
}
writer->writeTextElement(QStringLiteral("NUMBER"), d->number);
writer->writeEndElement();
}
/// \endcond
class QXmppVCardOrganizationPrivate : public QSharedData
{
public:
QString organization;
QString unit;
QString role;
QString title;
};
/// Constructs an empty organization information.
QXmppVCardOrganization::QXmppVCardOrganization()
: d(new QXmppVCardOrganizationPrivate)
{
}
/// Constructs a copy of \a other.
QXmppVCardOrganization::QXmppVCardOrganization(const QXmppVCardOrganization &other)
: d(other.d)
{
}
QXmppVCardOrganization::~QXmppVCardOrganization()
{
}
/// Assigns \a other to this organization info.
QXmppVCardOrganization &QXmppVCardOrganization::operator=(const QXmppVCardOrganization &other)
{
d = other.d;
return *this;
}
/// \brief Checks if two organization objects represent the same organization.
bool operator==(const QXmppVCardOrganization &left, const QXmppVCardOrganization &right)
{
return left.organization() == right.organization() &&
left.unit() == right.unit() &&
left.title() == right.title() &&
left.role() == right.role();
}
/// \brief Checks if two organization objects represent different organizations.
bool operator!=(const QXmppVCardOrganization &left, const QXmppVCardOrganization &right)
{
return !(left == right);
}
/// Returns the name of the organization.
QString QXmppVCardOrganization::organization() const
{
return d->organization;
}
/// Sets the organization \a name.
void QXmppVCardOrganization::setOrganization(const QString &name)
{
d->organization = name;
}
/// Returns the organization unit (also known as department).
QString QXmppVCardOrganization::unit() const
{
return d->unit;
}
/// Sets the \a unit within the organization.
void QXmppVCardOrganization::setUnit(const QString &unit)
{
d->unit = unit;
}
/// Returns the job role within the organization.
QString QXmppVCardOrganization::role() const
{
return d->role;
}
/// Sets the job \a role within the organization.
void QXmppVCardOrganization::setRole(const QString &role)
{
d->role = role;
}
/// Returns the job title within the organization.
QString QXmppVCardOrganization::title() const
{
return d->title;
}
/// Sets the job \a title within the organization.
void QXmppVCardOrganization::setTitle(const QString &title)
{
d->title = title;
}
/// \cond
void QXmppVCardOrganization::parse(const QDomElement &cardElem)
{
d->title = cardElem.firstChildElement(QStringLiteral("TITLE")).text();
d->role = cardElem.firstChildElement(QStringLiteral("ROLE")).text();
const QDomElement &orgElem = cardElem.firstChildElement(QStringLiteral("ORG"));
d->organization = orgElem.firstChildElement(QStringLiteral("ORGNAME")).text();
d->unit = orgElem.firstChildElement(QStringLiteral("ORGUNIT")).text();
}
void QXmppVCardOrganization::toXml(QXmlStreamWriter *stream) const
{
if (!d->unit.isEmpty() || !d->organization.isEmpty()) {
stream->writeStartElement(QStringLiteral("ORG"));
stream->writeTextElement(QStringLiteral("ORGNAME"), d->organization);
stream->writeTextElement(QStringLiteral("ORGUNIT"), d->unit);
stream->writeEndElement();
}
helperToXmlAddTextElement(stream, QStringLiteral("TITLE"), d->title);
helperToXmlAddTextElement(stream, QStringLiteral("ROLE"), d->role);
}
/// \endcond
class QXmppVCardIqPrivate : public QSharedData
{
public:
QDate birthday;
QString description;
QString firstName;
QString fullName;
QString lastName;
QString middleName;
QString nickName;
QString url;
// not as 64 base
QByteArray photo;
QString photoType;
QList<QXmppVCardAddress> addresses;
QList<QXmppVCardEmail> emails;
QList<QXmppVCardPhone> phones;
QXmppVCardOrganization organization;
};
/// Constructs a QXmppVCardIq for the specified recipient.
///
/// \param jid
QXmppVCardIq::QXmppVCardIq(const QString &jid)
: QXmppIq(), d(new QXmppVCardIqPrivate)
{
// for self jid should be empty
setTo(jid);
}
/// Constructs a copy of \a other.
QXmppVCardIq::QXmppVCardIq(const QXmppVCardIq &other)
: QXmppIq(other), d(other.d)
{
}
QXmppVCardIq::~QXmppVCardIq()
{
}
/// Assigns \a other to this vCard IQ.
QXmppVCardIq &QXmppVCardIq::operator=(const QXmppVCardIq &other)
{
QXmppIq::operator=(other);
d = other.d;
return *this;
}
/// \brief Checks if two VCard objects represent the same VCard.
bool operator==(const QXmppVCardIq &left, const QXmppVCardIq &right)
{
return left.birthday() == right.birthday() &&
left.description() == right.description() &&
left.email() == right.email() &&
left.firstName() == right.firstName() &&
left.fullName() == right.fullName() &&
left.lastName() == right.lastName() &&
left.middleName() == right.middleName() &&
left.nickName() == right.nickName() &&
left.photo() == right.photo() &&
left.photoType() == right.photoType() &&
left.url() == right.url() &&
left.addresses() == right.addresses() &&
left.emails() == right.emails() &&
left.phones() == right.phones() &&
left.organization() == right.organization();
}
/// \brief Checks if two VCard objects represent different VCards.
bool operator!=(const QXmppVCardIq &left, const QXmppVCardIq &right)
{
return !(left == right);
}
/// Returns the date of birth of the individual associated with the vCard.
///
QDate QXmppVCardIq::birthday() const
{
return d->birthday;
}
/// Sets the date of birth of the individual associated with the vCard.
///
/// \param birthday
void QXmppVCardIq::setBirthday(const QDate &birthday)
{
d->birthday = birthday;
}
/// Returns the free-form descriptive text.
QString QXmppVCardIq::description() const
{
return d->description;
}
/// Sets the free-form descriptive text.
void QXmppVCardIq::setDescription(const QString &description)
{
d->description = description;
}
/// Returns the email address.
///
QString QXmppVCardIq::email() const
{
if (d->emails.isEmpty()) {
return QString();
} else {
return d->emails.first().address();
}
}
/// Sets the email address.
///
/// \param email
void QXmppVCardIq::setEmail(const QString &email)
{
QXmppVCardEmail first;
first.setAddress(email);
first.setType(QXmppVCardEmail::Internet);
d->emails = QList<QXmppVCardEmail>() << first;
}
/// Returns the first name.
///
QString QXmppVCardIq::firstName() const
{
return d->firstName;
}
/// Sets the first name.
///
/// \param firstName
void QXmppVCardIq::setFirstName(const QString &firstName)
{
d->firstName = firstName;
}
/// Returns the full name.
///
QString QXmppVCardIq::fullName() const
{
return d->fullName;
}
/// Sets the full name.
///
/// \param fullName
void QXmppVCardIq::setFullName(const QString &fullName)
{
d->fullName = fullName;
}
/// Returns the last name.
///
QString QXmppVCardIq::lastName() const
{
return d->lastName;
}
/// Sets the last name.
///
/// \param lastName
void QXmppVCardIq::setLastName(const QString &lastName)
{
d->lastName = lastName;
}
/// Returns the middle name.
///
QString QXmppVCardIq::middleName() const
{
return d->middleName;
}
/// Sets the middle name.
///
/// \param middleName
void QXmppVCardIq::setMiddleName(const QString &middleName)
{
d->middleName = middleName;
}
/// Returns the nickname.
///
QString QXmppVCardIq::nickName() const
{
return d->nickName;
}
/// Sets the nickname.
///
/// \param nickName
void QXmppVCardIq::setNickName(const QString &nickName)
{
d->nickName = nickName;
}
/// Returns the URL associated with the vCard. It can represent the user's
/// homepage or a location at which you can find real-time information about
/// the vCard.
QString QXmppVCardIq::url() const
{
return d->url;
}
/// Sets the URL associated with the vCard. It can represent the user's
/// homepage or a location at which you can find real-time information about
/// the vCard.
///
/// \param url
void QXmppVCardIq::setUrl(const QString &url)
{
d->url = url;
}
/// Returns the photo's binary contents.
///
/// If you want to use the photo as a QImage you can use:
///
/// \code
/// QBuffer buffer;
/// buffer.setData(myCard.photo());
/// buffer.open(QIODevice::ReadOnly);
/// QImageReader imageReader(&buffer);
/// QImage myImage = imageReader.read();
/// \endcode
QByteArray QXmppVCardIq::photo() const
{
return d->photo;
}
/// Sets the photo's binary contents.
void QXmppVCardIq::setPhoto(const QByteArray &photo)
{
d->photo = photo;
}
/// Returns the photo's MIME type.
QString QXmppVCardIq::photoType() const
{
return d->photoType;
}
/// Sets the photo's MIME type.
void QXmppVCardIq::setPhotoType(const QString &photoType)
{
d->photoType = photoType;
}
/// Returns the addresses.
QList<QXmppVCardAddress> QXmppVCardIq::addresses() const
{
return d->addresses;
}
/// Sets the addresses.
void QXmppVCardIq::setAddresses(const QList<QXmppVCardAddress> &addresses)
{
d->addresses = addresses;
}
/// Returns the e-mail addresses.
QList<QXmppVCardEmail> QXmppVCardIq::emails() const
{
return d->emails;
}
/// Sets the e-mail addresses.
void QXmppVCardIq::setEmails(const QList<QXmppVCardEmail> &emails)
{
d->emails = emails;
}
/// Returns the phone numbers.
QList<QXmppVCardPhone> QXmppVCardIq::phones() const
{
return d->phones;
}
/// Sets the phone numbers.
void QXmppVCardIq::setPhones(const QList<QXmppVCardPhone> &phones)
{
d->phones = phones;
}
/// Returns the organization info.
QXmppVCardOrganization QXmppVCardIq::organization() const
{
return d->organization;
}
/// Sets the organization info.
void QXmppVCardIq::setOrganization(const QXmppVCardOrganization &org)
{
d->organization = org;
}
/// \cond
bool QXmppVCardIq::isVCard(const QDomElement &nodeRecv)
{
return nodeRecv.firstChildElement(QStringLiteral("vCard")).namespaceURI() == ns_vcard;
}
bool QXmppVCardIq::checkIqType(const QString &tagName, const QString &xmlNamespace)
{
return tagName == "vCard" && xmlNamespace == ns_vcard;
}
void QXmppVCardIq::parseElementFromChild(const QDomElement &nodeRecv)
{
// vCard
QDomElement cardElement = nodeRecv.firstChildElement(QStringLiteral("vCard"));
d->birthday = QDate::fromString(cardElement.firstChildElement(QStringLiteral("BDAY")).text(), QStringLiteral("yyyy-MM-dd"));
d->description = cardElement.firstChildElement(QStringLiteral("DESC")).text();
d->fullName = cardElement.firstChildElement(QStringLiteral("FN")).text();
d->nickName = cardElement.firstChildElement(QStringLiteral("NICKNAME")).text();
QDomElement nameElement = cardElement.firstChildElement(QStringLiteral("N"));
d->firstName = nameElement.firstChildElement(QStringLiteral("GIVEN")).text();
d->lastName = nameElement.firstChildElement(QStringLiteral("FAMILY")).text();
d->middleName = nameElement.firstChildElement(QStringLiteral("MIDDLE")).text();
d->url = cardElement.firstChildElement(QStringLiteral("URL")).text();
QDomElement photoElement = cardElement.firstChildElement(QStringLiteral("PHOTO"));
QByteArray base64data = photoElement.firstChildElement(QStringLiteral("BINVAL")).text().toLatin1();
d->photo = QByteArray::fromBase64(base64data);
d->photoType = photoElement.firstChildElement(QStringLiteral("TYPE")).text();
QDomElement child = cardElement.firstChildElement();
while (!child.isNull()) {
if (child.tagName() == QStringLiteral("ADR")) {
QXmppVCardAddress address;
address.parse(child);
d->addresses << address;
} else if (child.tagName() == QStringLiteral("EMAIL")) {
QXmppVCardEmail email;
email.parse(child);
d->emails << email;
} else if (child.tagName() == QStringLiteral("TEL")) {
QXmppVCardPhone phone;
phone.parse(child);
d->phones << phone;
}
child = child.nextSiblingElement();
}
d->organization.parse(cardElement);
}
void QXmppVCardIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
writer->writeStartElement(QStringLiteral("vCard"));
writer->writeDefaultNamespace(ns_vcard);
for (const QXmppVCardAddress &address : d->addresses) {
address.toXml(writer);
}
if (d->birthday.isValid()) {
helperToXmlAddTextElement(writer, QStringLiteral("BDAY"), d->birthday.toString(QStringLiteral("yyyy-MM-dd")));
}
if (!d->description.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("DESC"), d->description);
}
for (const QXmppVCardEmail &email : d->emails) {
email.toXml(writer);
}
if (!d->fullName.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("FN"), d->fullName);
}
if (!d->nickName.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("NICKNAME"), d->nickName);
}
if (!d->firstName.isEmpty() ||
!d->lastName.isEmpty() ||
!d->middleName.isEmpty()) {
writer->writeStartElement("N");
if (!d->firstName.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("GIVEN"), d->firstName);
}
if (!d->lastName.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("FAMILY"), d->lastName);
}
if (!d->middleName.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("MIDDLE"), d->middleName);
}
writer->writeEndElement();
}
for (const QXmppVCardPhone &phone : d->phones) {
phone.toXml(writer);
}
if (!photo().isEmpty()) {
writer->writeStartElement(QStringLiteral("PHOTO"));
QString photoType = d->photoType;
if (photoType.isEmpty()) {
photoType = getImageType(d->photo);
}
helperToXmlAddTextElement(writer, QStringLiteral("TYPE"), photoType);
helperToXmlAddTextElement(writer, QStringLiteral("BINVAL"), d->photo.toBase64());
writer->writeEndElement();
}
if (!d->url.isEmpty()) {
helperToXmlAddTextElement(writer, QStringLiteral("URL"), d->url);
}
d->organization.toXml(writer);
writer->writeEndElement();
}
/// \endcond
|