File indexing completed on 2025-01-19 03:39:54
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2003 Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KCONTACTS_VCARDTOOL_H 0009 #define KCONTACTS_VCARDTOOL_H 0010 0011 #include "addressee.h" 0012 #include "kcontacts_export.h" 0013 #include "vcardparser/vcardparser_p.h" 0014 0015 class QDateTime; 0016 0017 namespace KContacts 0018 { 0019 class Key; 0020 class Picture; 0021 class Secrecy; 0022 class Sound; 0023 0024 class KCONTACTS_EXPORT VCardTool 0025 { 0026 public: 0027 VCardTool(); 0028 ~VCardTool(); 0029 0030 /** 0031 Creates a string that contains the addressees from the list in 0032 the vCard format. 0033 */ 0034 Q_REQUIRED_RESULT QByteArray createVCards(const Addressee::List &list, VCard::Version version = VCard::v3_0) const; 0035 0036 /** 0037 * @since 4.9.1 0038 */ 0039 Q_REQUIRED_RESULT QByteArray exportVCards(const Addressee::List &list, VCard::Version version = VCard::v3_0) const; 0040 /** 0041 Parses the string and returns a list of addressee objects. 0042 */ 0043 Q_REQUIRED_RESULT Addressee::List parseVCards(const QByteArray &vcard) const; 0044 0045 static QDateTime parseDateTime(const QString &str, bool *timeValid = nullptr); 0046 static QString createDateTime(const QDateTime &dateTime, VCard::Version version, bool withTime = true); 0047 static QString createDate(const QDate &date, VCard::Version version); 0048 static QString createTime(const QTime &time, VCard::Version version); 0049 0050 private: 0051 KCONTACTS_NO_EXPORT 0052 QByteArray createVCards(const Addressee::List &list, VCard::Version version, bool exportVcard) const; 0053 0054 /** 0055 Split a string and replaces escaped separators on the fly with 0056 unescaped ones. 0057 */ 0058 KCONTACTS_NO_EXPORT 0059 QStringList splitString(QChar sep, const QString &value) const; 0060 0061 KCONTACTS_NO_EXPORT 0062 Picture parsePicture(const VCardLine &line) const; 0063 KCONTACTS_NO_EXPORT 0064 VCardLine createPicture(const QString &identifier, const Picture &pic, VCard::Version version) const; 0065 0066 KCONTACTS_NO_EXPORT 0067 Sound parseSound(const VCardLine &line) const; 0068 KCONTACTS_NO_EXPORT 0069 VCardLine createSound(const Sound &snd, VCard::Version version) const; 0070 0071 KCONTACTS_NO_EXPORT 0072 Key parseKey(const VCardLine &line) const; 0073 KCONTACTS_NO_EXPORT 0074 VCardLine createKey(const Key &key, VCard::Version version) const; 0075 0076 KCONTACTS_NO_EXPORT 0077 Secrecy parseSecrecy(const VCardLine &line) const; 0078 KCONTACTS_NO_EXPORT 0079 VCardLine createSecrecy(const Secrecy &secrecy) const; 0080 0081 KCONTACTS_NO_EXPORT 0082 void addParameter(VCardLine *line, VCard::Version version, const QString &key, const QStringList &valueStringList) const; 0083 0084 /** Translate alternative or legacy IMPP service types. */ 0085 KCONTACTS_NO_EXPORT 0086 QString normalizeImppServiceType(const QString &serviceType) const; 0087 0088 KCONTACTS_NO_EXPORT 0089 void processAddresses(const Address::List &addresses, VCard::Version version, VCard *card) const; 0090 KCONTACTS_NO_EXPORT 0091 void processEmailList(const Email::List &emailList, VCard::Version version, VCard *card) const; 0092 KCONTACTS_NO_EXPORT 0093 void processOrganizations(const Addressee &addressee, VCard::Version version, VCard *card) const; 0094 KCONTACTS_NO_EXPORT 0095 void processPhoneNumbers(const PhoneNumber::List &phoneNumbers, VCard::Version version, VCard *card) const; 0096 KCONTACTS_NO_EXPORT 0097 void processCustoms(const QStringList &customs, VCard::Version version, VCard *card, bool exportVcard) const; 0098 0099 Q_DISABLE_COPY(VCardTool) 0100 }; 0101 } 0102 0103 #endif