1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2003 Tobias Koenig <tokoe@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KCONTACTS_VCARDTOOL_H
9#define KCONTACTS_VCARDTOOL_H
10
11#include "addressee.h"
12#include "kcontacts_export.h"
13#include "vcardparser/vcardparser_p.h"
14
15class QDateTime;
16
17namespace KContacts
18{
19class Key;
20class Picture;
21class Secrecy;
22class Sound;
23
24class KCONTACTS_EXPORT VCardTool
25{
26public:
27 VCardTool();
28 ~VCardTool();
29
30 /**
31 Creates a string that contains the addressees from the list in
32 the vCard format.
33 */
34 Q_REQUIRED_RESULT QByteArray createVCards(const Addressee::List &list, VCard::Version version = VCard::v3_0) const;
35
36 /**
37 * @since 4.9.1
38 */
39 Q_REQUIRED_RESULT QByteArray exportVCards(const Addressee::List &list, VCard::Version version = VCard::v3_0) const;
40 /**
41 Parses the string and returns a list of addressee objects.
42 */
43 Q_REQUIRED_RESULT Addressee::List parseVCards(const QByteArray &vcard) const;
44
45 static QDateTime parseDateTime(const QString &str, bool *timeValid = nullptr);
46 static QString createDateTime(const QDateTime &dateTime, VCard::Version version, bool withTime = true);
47 static QString createDate(const QDate &date, VCard::Version version);
48 static QString createTime(const QTime &time, VCard::Version version);
49
50private:
51 KCONTACTS_NO_EXPORT
52 QByteArray createVCards(const Addressee::List &list, VCard::Version version, bool exportVcard) const;
53
54 /**
55 Split a string and replaces escaped separators on the fly with
56 unescaped ones.
57 */
58 KCONTACTS_NO_EXPORT
59 QStringList splitString(QChar sep, const QString &value) const;
60
61 KCONTACTS_NO_EXPORT
62 Picture parsePicture(const VCardLine &line) const;
63 KCONTACTS_NO_EXPORT
64 VCardLine createPicture(const QString &identifier, const Picture &pic, VCard::Version version) const;
65
66 KCONTACTS_NO_EXPORT
67 Sound parseSound(const VCardLine &line) const;
68 KCONTACTS_NO_EXPORT
69 VCardLine createSound(const Sound &snd, VCard::Version version) const;
70
71 KCONTACTS_NO_EXPORT
72 Key parseKey(const VCardLine &line) const;
73 KCONTACTS_NO_EXPORT
74 VCardLine createKey(const Key &key, VCard::Version version) const;
75
76 KCONTACTS_NO_EXPORT
77 Secrecy parseSecrecy(const VCardLine &line) const;
78 KCONTACTS_NO_EXPORT
79 VCardLine createSecrecy(const Secrecy &secrecy) const;
80
81 KCONTACTS_NO_EXPORT
82 void addParameter(VCardLine *line, VCard::Version version, const QString &key, const QStringList &valueStringList) const;
83
84 /** Translate alternative or legacy IMPP service types. */
85 KCONTACTS_NO_EXPORT
86 QString normalizeImppServiceType(const QString &serviceType) const;
87
88 KCONTACTS_NO_EXPORT
89 void processAddresses(const Address::List &addresses, VCard::Version version, VCard *card) const;
90 KCONTACTS_NO_EXPORT
91 void processEmailList(const Email::List &emailList, VCard::Version version, VCard *card) const;
92 KCONTACTS_NO_EXPORT
93 void processOrganizations(const Addressee &addressee, VCard::Version version, VCard *card) const;
94 KCONTACTS_NO_EXPORT
95 void processPhoneNumbers(const PhoneNumber::List &phoneNumbers, VCard::Version version, VCard *card) const;
96 KCONTACTS_NO_EXPORT
97 void processCustoms(const QStringList &customs, VCard::Version version, VCard *card, bool exportVcard) const;
98
99 Q_DISABLE_COPY(VCardTool)
100};
101}
102
103#endif
104

source code of kcontacts/src/vcardtool_p.h