KContacts

vcardconverter.cpp
1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "vcardconverter.h"
9#include "vcardtool_p.h"
10
11using namespace KContacts;
12
14 : d(nullptr)
15{
16}
17
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
92QString KContacts::dateToVCardString(const QDateTime &dateTime)
93{
94 return dateTime.toString(QStringLiteral("yyyyMMddThhmmssZ"));
95}
96
97QString KContacts::dateToVCardString(QDate date)
98{
99 return date.toString(QStringLiteral("yyyyMMdd"));
100}
101
102QDateTime 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 const QStringView strView(d);
112 date = QDate(strView.mid(0, 4).toUInt(), strView.mid(4, 2).toUInt(), strView.mid(6, 2).toUInt());
113 }
114
115 if (d.length() > 9 && d[8].toUpper() == QLatin1Char('T')) {
116 const QStringView strView(d);
117 time = QTime(strView.mid(9, 2).toUInt(), strView.mid(11, 2).toUInt(), strView.mid(13, 2).toUInt());
118 }
119
120 return QDateTime(date, time);
121}
122
123void KContacts::adaptIMAttributes(QByteArray &data)
124{
125 data.replace("X-messaging/aim-All", ("X-AIM"));
126 data.replace("X-messaging/icq-All", ("X-ICQ"));
127 data.replace("X-messaging/xmpp-All", ("X-JABBER"));
128 data.replace("X-messaging/msn-All", ("X-MSN"));
129 data.replace("X-messaging/yahoo-All", ("X-YAHOO"));
130 data.replace("X-messaging/gadu-All", ("X-GADUGADU"));
131 data.replace("X-messaging/skype-All", ("X-SKYPE"));
132 data.replace("X-messaging/groupwise-All", ("X-GROUPWISE"));
133 data.replace("X-messaging/sms-All", ("X-SMS"));
134 data.replace("X-messaging/meanwhile-All", ("X-MEANWHILE"));
135 data.replace("X-messaging/irc-All", ("X-IRC"));
136 data.replace("X-messaging/googletalk-All", ("X-GTALK"));
137}
address book entry
Definition addressee.h:70
QByteArray createVCards(const Addressee::List &list, Version version=v3_0) const
Creates a string in vCard format which contains the given list of contact.
QByteArray exportVCard(const Addressee &addr, Version version) 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.
Addressee::List parseVCards(const QByteArray &vcard) const
Parses a string in vCard format and returns a list of contact objects.
QByteArray exportVCards(const Addressee::List &list, Version version) const
QByteArray & replace(QByteArrayView before, QByteArrayView after)
QString toString(QStringView format, QCalendar cal) const const
QString toString(QStringView format, QCalendar cal) const const
void append(QList< T > &&value)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 12:00:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.