KContacts

vcard.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2003 Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "vcard.h"
9 
10 using namespace KContacts;
11 
12 VCard::VCard()
13 {
14 }
15 
16 VCard::VCard(const VCard &vcard)
17 {
18  mLineMap = vcard.mLineMap;
19 }
20 
21 VCard::~VCard()
22 {
23 }
24 
25 VCard &VCard::operator=(const VCard &vcard)
26 {
27  if (&vcard == this) {
28  return *this;
29  }
30 
31  mLineMap = vcard.mLineMap;
32 
33  return *this;
34 }
35 
36 void VCard::clear()
37 {
38  mLineMap.clear();
39 }
40 
41 QStringList VCard::identifiers() const
42 {
43  return mLineMap.keys();
44 }
45 
46 void VCard::addLine(const VCardLine &line)
47 {
48  mLineMap[ line.identifier() ].append(line);
49 }
50 
51 VCardLine::List VCard::lines(const QString &identifier) const
52 {
53  LineMap::ConstIterator it = mLineMap.find(identifier);
54  if (it == mLineMap.end()) {
55  return VCardLine::List();
56  }
57 
58  return *it;
59 }
60 
61 VCardLine VCard::line(const QString &identifier) const
62 {
63  LineMap::ConstIterator it = mLineMap.find(identifier);
64  if (it == mLineMap.end()) {
65  return VCardLine();
66  }
67 
68  if ((*it).isEmpty()) {
69  return VCardLine();
70  } else {
71  return (*it).first();
72  }
73 }
74 
75 void VCard::setVersion(Version version)
76 {
77  mLineMap.remove(QStringLiteral("VERSION"));
78 
79  VCardLine line;
80  line.setIdentifier(QStringLiteral("VERSION"));
81  if (version == v2_1) {
82  line.setIdentifier(QStringLiteral("2.1"));
83  } else if (version == v3_0) {
84  line.setIdentifier(QStringLiteral("3.0"));
85  } else if (version == v4_0) {
86  line.setIdentifier(QStringLiteral("4.0"));
87  }
88 
89  mLineMap[ QStringLiteral("VERSION") ].append(line);
90 }
91 
92 VCard::Version VCard::version() const
93 {
94  LineMap::ConstIterator versionEntry = mLineMap.find(QStringLiteral("VERSION"));
95  if (versionEntry == mLineMap.end()) {
96  return v3_0;
97  }
98 
99  VCardLine line = (*versionEntry)[ 0 ];
100  if (line.value() == QLatin1String("2.1")) {
101  return v2_1;
102  } else if (line.value() == QLatin1String("3.0")) {
103  return v3_0;
104  } else {
105  return v4_0;
106  }
107 }
void append(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 5 2020 22:52:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.