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 VCARDPARSER_VCARD_H |
9 | #define VCARDPARSER_VCARD_H |
10 | |
11 | #include "vcardline_p.h" |
12 | #include <QList> |
13 | #include <QMap> |
14 | #include <QStringList> |
15 | |
16 | #include <vector> |
17 | |
18 | namespace KContacts |
19 | { |
20 | class VCard |
21 | { |
22 | public: |
23 | typedef QList<VCard> List; |
24 | |
25 | struct LineData { |
26 | QString identifier; |
27 | VCardLine::List list; |
28 | }; |
29 | using LineMap = std::vector<LineData>; |
30 | |
31 | inline LineMap::iterator findByLineId(const QString &identifier) |
32 | { |
33 | return std::find_if(first: mLineMap.begin(), last: mLineMap.end(), pred: [&identifier](const LineData &data) { |
34 | return data.identifier == identifier; |
35 | }); |
36 | } |
37 | |
38 | inline LineMap::const_iterator findByLineId(const QString &identifier) const |
39 | { |
40 | return std::find_if(first: mLineMap.cbegin(), last: mLineMap.cend(), pred: [&identifier](const LineData &data) { |
41 | return data.identifier == identifier; |
42 | }); |
43 | } |
44 | |
45 | enum Version { |
46 | v2_1, |
47 | v3_0, |
48 | v4_0, |
49 | }; |
50 | |
51 | VCard(); |
52 | VCard(const VCard &card); |
53 | |
54 | ~VCard(); |
55 | |
56 | VCard &operator=(const VCard &card); |
57 | |
58 | /** |
59 | * Removes all lines from the vCard. |
60 | */ |
61 | void clear(); |
62 | |
63 | /** |
64 | * Returns a list of all identifiers that exists in the vCard. |
65 | */ |
66 | Q_REQUIRED_RESULT QStringList identifiers() const; |
67 | |
68 | /** |
69 | * Adds a VCardLine to the VCard |
70 | */ |
71 | void addLine(const VCardLine &line); |
72 | |
73 | /** |
74 | * Returns all lines of the vcard with a special identifier. |
75 | */ |
76 | Q_REQUIRED_RESULT VCardLine::List lines(const QString &identifier) const; |
77 | |
78 | /** |
79 | * Returns only the first line of the vcard with a special identifier. |
80 | */ |
81 | Q_REQUIRED_RESULT VCardLine line(const QString &identifier) const; |
82 | |
83 | /** |
84 | * Set the version of the vCard. |
85 | */ |
86 | void setVersion(Version version); |
87 | |
88 | /** |
89 | * Returns the version of this vCard. |
90 | */ |
91 | Q_REQUIRED_RESULT Version version() const; |
92 | |
93 | private: |
94 | /** |
95 | * A container of LineData, sorted by identifier. |
96 | */ |
97 | LineMap mLineMap; |
98 | }; |
99 | |
100 | inline bool operator<(const VCard::LineData &a, const VCard::LineData &b) |
101 | { |
102 | return a.identifier < b.identifier; |
103 | } |
104 | } |
105 | |
106 | #endif |
107 | |