File indexing completed on 2024-05-12 11:47:41
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 VCARDPARSER_VCARD_H 0009 #define VCARDPARSER_VCARD_H 0010 0011 #include "vcardline_p.h" 0012 #include <QMap> 0013 #include <QStringList> 0014 #include <QVector> 0015 0016 #include <vector> 0017 0018 namespace KContacts 0019 { 0020 class VCard 0021 { 0022 public: 0023 typedef QVector<VCard> List; 0024 0025 struct LineData { 0026 QString identifier; 0027 VCardLine::List list; 0028 }; 0029 using LineMap = std::vector<LineData>; 0030 0031 inline LineMap::iterator findByLineId(const QString &identifier) 0032 { 0033 return std::find_if(mLineMap.begin(), mLineMap.end(), [&identifier](const LineData &data) { 0034 return data.identifier == identifier; 0035 }); 0036 } 0037 0038 inline LineMap::const_iterator findByLineId(const QString &identifier) const 0039 { 0040 return std::find_if(mLineMap.cbegin(), mLineMap.cend(), [&identifier](const LineData &data) { 0041 return data.identifier == identifier; 0042 }); 0043 } 0044 0045 enum Version { 0046 v2_1, 0047 v3_0, 0048 v4_0, 0049 }; 0050 0051 VCard(); 0052 VCard(const VCard &card); 0053 0054 ~VCard(); 0055 0056 VCard &operator=(const VCard &card); 0057 0058 /** 0059 * Removes all lines from the vCard. 0060 */ 0061 void clear(); 0062 0063 /** 0064 * Returns a list of all identifiers that exists in the vCard. 0065 */ 0066 Q_REQUIRED_RESULT QStringList identifiers() const; 0067 0068 /** 0069 * Adds a VCardLine to the VCard 0070 */ 0071 void addLine(const VCardLine &line); 0072 0073 /** 0074 * Returns all lines of the vcard with a special identifier. 0075 */ 0076 Q_REQUIRED_RESULT VCardLine::List lines(const QString &identifier) const; 0077 0078 /** 0079 * Returns only the first line of the vcard with a special identifier. 0080 */ 0081 Q_REQUIRED_RESULT VCardLine line(const QString &identifier) const; 0082 0083 /** 0084 * Set the version of the vCard. 0085 */ 0086 void setVersion(Version version); 0087 0088 /** 0089 * Returns the version of this vCard. 0090 */ 0091 Q_REQUIRED_RESULT Version version() const; 0092 0093 private: 0094 /** 0095 * A container of LineData, sorted by identifier. 0096 */ 0097 LineMap mLineMap; 0098 }; 0099 0100 inline bool operator<(const VCard::LineData &a, const VCard::LineData &b) 0101 { 0102 return a.identifier < b.identifier; 0103 } 0104 } 0105 0106 #endif