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  date = QDate(d.midRef(0, 4).toUInt(), d.midRef(4, 2).toUInt(), d.midRef(6, 2).toUInt());
112  }
113 
114  if (d.length() > 9 && d[ 8 ].toUpper() == QLatin1Char('T')) {
115  time = QTime(d.midRef(9, 2).toUInt(), d.midRef(11, 2).toUInt(), d.midRef(13, 2).toUInt());
116  }
117 
118  return QDateTime(date, time);
119 }
120 
121 void KContacts::adaptIMAttributes(QByteArray &data)
122 {
123  data.replace("X-messaging/aim-All", ("X-AIM"));
124  data.replace("X-messaging/icq-All", ("X-ICQ"));
125  data.replace("X-messaging/xmpp-All", ("X-JABBER"));
126  data.replace("X-messaging/msn-All", ("X-MSN"));
127  data.replace("X-messaging/yahoo-All", ("X-YAHOO"));
128  data.replace("X-messaging/gadu-All", ("X-GADUGADU"));
129  data.replace("X-messaging/skype-All", ("X-SKYPE"));
130  data.replace("X-messaging/groupwise-All", ("X-GROUPWISE"));
131  data.replace("X-messaging/sms-All", ("X-SMS"));
132  data.replace("X-messaging/meanwhile-All", ("X-MEANWHILE"));
133  data.replace("X-messaging/irc-All", ("X-IRC"));
134  data.replace("X-messaging/googletalk-All", ("X-GTALK"));
135 }
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:68
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.
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:54:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.