KContacts

vcardconverter.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2002 Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "vcardconverter.h"
9 #include "vcardtool_p.h"
10 
11 using namespace KContacts;
12 
14  : d(nullptr)
15 {
16 }
17 
19 {
20 }
21 
23 {
24  Addressee::List list;
25  list.append(addr);
26 
27  return exportVCards(list, version);
28 }
29 
31 {
32  VCardTool tool;
33  QByteArray returnValue;
34  switch (version) {
35  case v2_1:
36  returnValue = tool.exportVCards(list, VCard::v2_1);
37  break;
38  case v3_0:
39  returnValue = tool.exportVCards(list, VCard::v3_0);
40  break;
41  case v4_0:
42  returnValue = tool.exportVCards(list, VCard::v4_0);
43  break;
44  }
45 
46  return returnValue;
47 }
48 
50 {
51  Addressee::List list;
52  list.append(addr);
53 
54  return createVCards(list, version);
55 }
56 
58 {
59  VCardTool tool;
60  QByteArray returnValue;
61  switch (version) {
62  case v2_1:
63  returnValue = tool.createVCards(list, VCard::v2_1);
64  break;
65  case v3_0:
66  returnValue = tool.createVCards(list, VCard::v3_0);
67  break;
68  case v4_0:
69  returnValue = tool.createVCards(list, VCard::v4_0);
70  break;
71  }
72 
73  return returnValue;
74 }
75 
77 {
78  Addressee::List list = parseVCards(vcard);
79 
80  return list.isEmpty() ? Addressee() : list[0];
81 }
82 
84 {
85  VCardTool tool;
86 
87  return tool.parseVCards(vcard);
88 }
89 
90 /* Helper functions */
91 
92 QString KContacts::dateToVCardString(const QDateTime &dateTime)
93 {
94  return dateTime.toString(QStringLiteral("yyyyMMddThhmmssZ"));
95 }
96 
97 QString KContacts::dateToVCardString(QDate date)
98 {
99  return date.toString(QStringLiteral("yyyyMMdd"));
100 }
101 
102 QDateTime KContacts::VCardStringToDate(const QString &dateString)
103 {
104  QDate date;
105  QTime time;
106  QString d(dateString);
107 
108  d = d.remove(QLatin1Char('-')).remove(QLatin1Char(':'));
109 
110  if (d.length() >= 8) {
111 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
112  const QStringView strView(d);
113  date = QDate(strView.mid(0, 4).toUInt(), strView.mid(4, 2).toUInt(), strView.mid(6, 2).toUInt());
114 #else
115  date = QDate(d.midRef(0, 4).toUInt(), d.midRef(4, 2).toUInt(), d.midRef(6, 2).toUInt());
116 #endif
117  }
118 
119  if (d.length() > 9 && d[8].toUpper() == QLatin1Char('T')) {
120 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
121  const QStringView strView(d);
122  time = QTime(strView.mid(9, 2).toUInt(), strView.mid(11, 2).toUInt(), strView.mid(13, 2).toUInt());
123 #else
124  time = QTime(d.midRef(9, 2).toUInt(), d.midRef(11, 2).toUInt(), d.midRef(13, 2).toUInt());
125 #endif
126  }
127 
128  return QDateTime(date, time);
129 }
130 
131 void KContacts::adaptIMAttributes(QByteArray &data)
132 {
133  data.replace("X-messaging/aim-All", ("X-AIM"));
134  data.replace("X-messaging/icq-All", ("X-ICQ"));
135  data.replace("X-messaging/xmpp-All", ("X-JABBER"));
136  data.replace("X-messaging/msn-All", ("X-MSN"));
137  data.replace("X-messaging/yahoo-All", ("X-YAHOO"));
138  data.replace("X-messaging/gadu-All", ("X-GADUGADU"));
139  data.replace("X-messaging/skype-All", ("X-SKYPE"));
140  data.replace("X-messaging/groupwise-All", ("X-GROUPWISE"));
141  data.replace("X-messaging/sms-All", ("X-SMS"));
142  data.replace("X-messaging/meanwhile-All", ("X-MEANWHILE"));
143  data.replace("X-messaging/irc-All", ("X-IRC"));
144  data.replace("X-messaging/googletalk-All", ("X-GTALK"));
145 }
QString toString(Qt::DateFormat format) const const
QString toUpper() const const
QString toString(Qt::DateFormat format) const const
void append(const T &value)
QString & remove(int position, int n)
Addressee::List parseVCards(const QByteArray &vcard) const
Parses a string in vCard format and returns a list of contact objects.
QByteArray & replace(int pos, int len, const char *after)
QStringRef midRef(int position, int n) const const
uint toUInt(bool *ok, int base) const const
bool isEmpty() const const
QByteArray exportVCards(const Addressee::List &list, Version version) const
int length() const const
address book entry
Definition: addressee.h:69
QByteArray exportVCard(const Addressee &addr, Version version) const
QByteArray createVCards(const Addressee::List &list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
QStringView mid(qsizetype start) const const
Addressee parseVCard(const QByteArray &vcard) const
Parses a string in vCard format and returns the first contact.
QByteArray createVCard(const Addressee &addr, Version version=v3_0) const
Creates a string in vCard format which contains the given contact.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Sep 20 2021 22:56:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.