aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-26 21:36:21 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-26 21:36:21 (GMT)
commitbad818176d79b1379bd4d68364b81ccdb36a6ca0 (patch)
tree8b1a01ddd8f86ad7ce9fdcf979ecfa874a3161bf
parentd6347ae7c27d3b895727a4124bed61dc241204d7 (diff)
Add support for clientpidmap
-rw-r--r--autotests/CMakeLists.txt1
-rw-r--r--autotests/clientpidmaptest.cpp249
-rw-r--r--autotests/clientpidmaptest.h48
-rw-r--r--autotests/importexportvcardtest.cpp33
-rw-r--r--autotests/importexportvcardtest.h1
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/addressee.cpp28
-rw-r--r--src/addressee.h6
-rw-r--r--src/clientpidmap.cpp139
-rw-r--r--src/clientpidmap.h71
-rw-r--r--src/vcardtool.cpp20
11 files changed, 597 insertions, 1 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 56287dc..92c5617 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -39,5 +39,6 @@ ecm_add_tests(birthdaytest.cpp
roletest.cpp
orgtest.cpp
datetimetest.cpp
+ clientpidmaptest.cpp
NAME_PREFIX "kcontacts-" LINK_LIBRARIES KF5Contacts Qt5::Test KF5::ConfigCore Qt5::Gui)
diff --git a/autotests/clientpidmaptest.cpp b/autotests/clientpidmaptest.cpp
new file mode 100644
index 0000000..763d47d
--- /dev/null
+++ b/autotests/clientpidmaptest.cpp
@@ -0,0 +1,249 @@
+/*
+ This file is part of the KContacts framework.
+ Copyright (c) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "clientpidmaptest.h"
+#include "clientpidmap.h"
+#include "vcardtool.h"
+#include <qtest.h>
+
+ClientPidMapTest::ClientPidMapTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+ClientPidMapTest::~ClientPidMapTest()
+{
+
+}
+
+void ClientPidMapTest::shouldHaveDefaultValue()
+{
+ KContacts::ClientPidMap role;
+ QVERIFY(!role.isValid());
+ QVERIFY(role.clientPidMap().isEmpty());
+ QVERIFY(role.parameters().isEmpty());
+}
+
+void ClientPidMapTest::shouldAssignValue()
+{
+ const QString lang(QStringLiteral("fr"));
+ QMap<QString, QStringList> params;
+ params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1"));
+ params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
+ KContacts::ClientPidMap role(lang);
+ role.setParameters(params);
+ QVERIFY(role.isValid());
+ QVERIFY(!role.clientPidMap().isEmpty());
+ QCOMPARE(role.clientPidMap(), lang);
+ QVERIFY(!role.parameters().isEmpty());
+ QCOMPARE(role.parameters(), params);
+
+}
+
+void ClientPidMapTest::shouldAssignExternal()
+{
+ KContacts::ClientPidMap role;
+ const QString lang(QStringLiteral("fr"));
+ role.setClientPidMap(lang);
+ QVERIFY(role.isValid());
+ QCOMPARE(role.clientPidMap(), lang);
+}
+
+void ClientPidMapTest::shouldSerialized()
+{
+ KContacts::ClientPidMap role;
+ KContacts::ClientPidMap result;
+ const QString lang(QStringLiteral("fr"));
+ role.setClientPidMap(lang);
+ QMap<QString, QStringList> params;
+ params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1"));
+ params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
+ role.setParameters(params);
+
+ QByteArray data;
+ QDataStream s(&data, QIODevice::WriteOnly);
+ s << role;
+
+ QDataStream t(&data, QIODevice::ReadOnly);
+ t >> result;
+
+ QVERIFY(role == result);
+
+}
+
+void ClientPidMapTest::shouldEqualClientPidMap()
+{
+ KContacts::ClientPidMap role;
+ KContacts::ClientPidMap result;
+ const QString lang(QStringLiteral("fr"));
+ role.setClientPidMap(lang);
+ QMap<QString, QStringList> params;
+ params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1"));
+ params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
+ role.setParameters(params);
+
+ result = role;
+ QVERIFY(role == result);
+}
+
+#if 0
+void ClientPidMapTest::shouldParseClientPidMap()
+{
+
+ QByteArray vcarddata("BEGIN:VCARD\n"
+ "VERSION:3.0\n"
+ "N:LastName;FirstName;;;\n"
+ "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n"
+ "ClientPidMap:boo\n"
+ "REV:2015-03-14T09:24:45+00:00\n"
+ "FN:FirstName LastName\n"
+ "END:VCARD\n");
+
+ KContacts::VCardTool vcard;
+ const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata);
+ QCOMPARE(lst.count(), 1);
+ QCOMPARE(lst.at(0).extraClientPidMapList().count(), 1);
+ QCOMPARE(lst.at(0).clie(), QStringLiteral("boo"));
+ QCOMPARE(lst.at(0).extraClientPidMapList().at(0).role(), QStringLiteral("boo"));
+}
+
+void ClientPidMapTest::shouldParseWithoutClientPidMap()
+{
+ QByteArray vcarddata("BEGIN:VCARD\n"
+ "VERSION:3.0\n"
+ "N:LastName;FirstName;;;\n"
+ "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n"
+ "REV:2015-03-14T09:24:45+00:00\n"
+ "FN:FirstName LastName\n"
+ "END:VCARD\n");
+
+ KContacts::VCardTool vcard;
+ const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata);
+ QCOMPARE(lst.count(), 1);
+ QCOMPARE(lst.at(0).extraClientPidMapList().count(), 0);
+ QCOMPARE(lst.at(0).role(), QString());
+}
+
+void ClientPidMapTest::shouldCreateVCard()
+{
+ KContacts::AddresseeList lst;
+ KContacts::Addressee addr;
+ addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
+ addr.setUid(QStringLiteral("testuid"));
+ KContacts::ClientPidMap::List lstClientPidMap;
+ KContacts::ClientPidMap role(QStringLiteral("fr"));
+ lstClientPidMap << role;
+ addr.setExtraClientPidMapList(lstClientPidMap);
+ lst << addr;
+ KContacts::VCardTool vcard;
+ const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
+ QByteArray expected("BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "EMAIL:foo@kde.org\r\n"
+ "N:;;;;\r\n"
+ "ROLE:fr\r\n"
+ "UID:testuid\r\n"
+ "END:VCARD\r\n\r\n");
+
+ QCOMPARE(ba, expected);
+}
+
+void ClientPidMapTest::shouldCreateVCardWithTwoClientPidMap()
+{
+ KContacts::AddresseeList lst;
+ KContacts::Addressee addr;
+ addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
+ addr.setUid(QStringLiteral("testuid"));
+ KContacts::ClientPidMap::List lstClientPidMap;
+ KContacts::ClientPidMap role(QStringLiteral("fr"));
+ KContacts::ClientPidMap role2(QStringLiteral("fr2"));
+ lstClientPidMap << role << role2;
+ addr.setExtraClientPidMapList(lstClientPidMap);
+ lst << addr;
+ KContacts::VCardTool vcard;
+ const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
+ QByteArray expected("BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "EMAIL:foo@kde.org\r\n"
+ "N:;;;;\r\n"
+ "ROLE:fr\r\n"
+ "ROLE:fr2\r\n"
+ "UID:testuid\r\n"
+ "END:VCARD\r\n\r\n");
+
+ QCOMPARE(ba, expected);
+
+}
+void ClientPidMapTest::shouldCreateVCardWithParameters()
+{
+ KContacts::AddresseeList lst;
+ KContacts::Addressee addr;
+ addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
+ addr.setUid(QStringLiteral("testuid"));
+ KContacts::ClientPidMap::List lstClientPidMap;
+ KContacts::ClientPidMap role(QStringLiteral("fr"));
+ QMap<QString, QStringList> params;
+ params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1"));
+ params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
+ role.setParameters(params);
+ lstClientPidMap << role;
+ addr.setExtraClientPidMapList(lstClientPidMap);
+ lst << addr;
+ KContacts::VCardTool vcard;
+ const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
+ QByteArray expected("BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "EMAIL:foo@kde.org\r\n"
+ "N:;;;;\r\n"
+ "ROLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n"
+ "UID:testuid\r\n"
+ "END:VCARD\r\n\r\n");
+ QCOMPARE(ba, expected);
+}
+
+void ClientPidMapTest::shouldGenerateClientPidMapForVCard3()
+{
+ KContacts::AddresseeList lst;
+ KContacts::Addressee addr;
+ addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
+ addr.setUid(QStringLiteral("testuid"));
+ KContacts::ClientPidMap::List lstClientPidMap;
+ KContacts::ClientPidMap role(QStringLiteral("fr"));
+ QMap<QString, QStringList> params;
+ params.insert(QStringLiteral("Foo1"), QStringList() << QStringLiteral("bla1") << QStringLiteral("blo1"));
+ params.insert(QStringLiteral("Foo2"), QStringList() << QStringLiteral("bla2") << QStringLiteral("blo2"));
+ role.setParameters(params);
+ lstClientPidMap << role;
+ addr.setExtraClientPidMapList(lstClientPidMap);
+ lst << addr;
+ KContacts::VCardTool vcard;
+ const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0);
+ QByteArray expected("BEGIN:VCARD\r\n"
+ "VERSION:3.0\r\n"
+ "EMAIL:foo@kde.org\r\n"
+ "N:;;;;\r\n"
+ "ROLE;FOO1=bla1,blo1;FOO2=bla2,blo2:fr\r\n"
+ "UID:testuid\r\n"
+ "END:VCARD\r\n\r\n");
+ QCOMPARE(ba, expected);
+}
+#endif
+QTEST_MAIN(ClientPidMapTest)
diff --git a/autotests/clientpidmaptest.h b/autotests/clientpidmaptest.h
new file mode 100644
index 0000000..93583dd
--- /dev/null
+++ b/autotests/clientpidmaptest.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of the KContacts framework.
+ Copyright (c) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef ROLETEST_H
+#define ROLETEST_H
+
+#include <QObject>
+
+class ClientPidMapTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ClientPidMapTest(QObject *parent = Q_NULLPTR);
+ ~ClientPidMapTest();
+private Q_SLOTS:
+ void shouldHaveDefaultValue();
+ void shouldAssignValue();
+ void shouldAssignExternal();
+ void shouldSerialized();
+ void shouldEqualClientPidMap();
+#if 0
+ void shouldParseClientPidMap();
+ void shouldParseWithoutClientPidMap();
+ void shouldCreateVCard();
+ void shouldCreateVCardWithTwoClientPidMap();
+ void shouldCreateVCardWithParameters();
+ void shouldGenerateClientPidMapForVCard3();
+#endif
+};
+
+#endif // ROLETEST_H
diff --git a/autotests/importexportvcardtest.cpp b/autotests/importexportvcardtest.cpp
index ce310ab..9c9e6fc 100644
--- a/autotests/importexportvcardtest.cpp
+++ b/autotests/importexportvcardtest.cpp
@@ -108,6 +108,39 @@ void ImportExportVCardTest::shouldExportFullTestVcard4()
const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0);
qDebug() << " result " << result;
+ QCOMPARE(result, vcardexpected);
+}
+
+void ImportExportVCardTest::shouldExportMiscElementVcard4()
+{
+ QByteArray vcarddata("BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "UID:urn:uuid:4fbe8971-0bc3-424c-9c26-36c3e1eff6b1\r\n"
+ "FN;PID=1.1:J. Doe\r\n"
+ "N:Doe;J.;;;\r\n"
+ "EMAIL;PID=1.1:jdoe@example.com\r\n"
+ "EMAIL;PID=2.1:boss@example.com\r\n"
+ "TEL;PID=1.1;VALUE=uri:tel:+1-555-555-5555\r\n"
+ "TEL;PID=2.1;VALUE=uri:tel:+1-666-666-6666\r\n"
+ "CLIENTPIDMAP:1;urn:uuid:53e374d9-337e-4727-8803-a1e9c14e0556\r\n"
+ "END:VCARD\r\n\r\n");
+ QByteArray vcardexpected("BEGIN:VCARD\r\n"
+ "VERSION:4.0\r\n"
+ "CLIENTPIDMAP:1;urn:uuid:53e374d9-337e-4727-8803-a1e9c14e0556\r\n"
+ "EMAIL;PID=1.1:jdoe@example.com\r\n"
+ "EMAIL;PID=2.1:boss@example.com\r\n"
+ "FN:J. Doe\r\n"
+ "N:Doe;J.;;;\r\n"
+ "TEL;PID=1.1;VALUE=uri:tel:+1-555-555-5555\r\n"
+ "TEL;PID=2.1;VALUE=uri:tel:+1-666-666-6666\r\n"
+ "UID:urn:uuid:4fbe8971-0bc3-424c-9c26-36c3e1eff6b1\r\n"
+ "END:VCARD\r\n\r\n");
+
+ KContacts::VCardTool vcard;
+ const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata);
+
+ const QByteArray result = vcard.exportVCards(lst, KContacts::VCard::v4_0);
+ qDebug() << " result " << result;
QCOMPARE(result, vcardexpected);
}
diff --git a/autotests/importexportvcardtest.h b/autotests/importexportvcardtest.h
index bf30b32..50c19a0 100644
--- a/autotests/importexportvcardtest.h
+++ b/autotests/importexportvcardtest.h
@@ -31,6 +31,7 @@ public:
~ImportExportVCardTest();
private Q_SLOTS:
void shouldExportFullTestVcard4();
+ void shouldExportMiscElementVcard4();
};
#endif // IMPORTEXPORTVCARDTEST_H
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 02357c1..9bf1380 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -37,6 +37,7 @@ set(kcontacts_SRCS
role.cpp
note.cpp
org.cpp
+ clientpidmap.cpp
${vcardparser_SRCS}
)
@@ -106,6 +107,7 @@ ecm_generate_headers(KContacts_CamelCase_HEADERS
NickName
VCardDrag
FieldGroup
+ ClientPidMap
PREFIX KContacts
REQUIRED_HEADERS KContacts_HEADERS
)
diff --git a/src/addressee.cpp b/src/addressee.cpp
index d66cbe5..c76a3dc 100644
--- a/src/addressee.cpp
+++ b/src/addressee.cpp
@@ -153,6 +153,7 @@ public:
Role::List mRoleExtraList;
Org::List mOrgExtraList;
NickName::List mNickNameExtraList;
+ ClientPidMap::List mClientPidMapList;
bool mEmpty : 1;
bool mChanged : 1;
bool mBirthdayWithTime;
@@ -400,6 +401,11 @@ bool Addressee::operator==(const Addressee &addressee) const
qCDebug(KCONTACTS_LOG) << "Extra NickName List differs";
return false;
}
+
+ if (!listEquals(d->mClientPidMapList, addressee.d->mClientPidMapList)) {
+ qCDebug(KCONTACTS_LOG) << "ClientPidMap List differs";
+ return false;
+ }
return true;
}
@@ -575,6 +581,26 @@ void Addressee::insertFieldGroup(const FieldGroup &fieldGroup)
}
}
+ClientPidMap::List Addressee::clientPidMapList() const
+{
+ return d->mClientPidMapList;
+}
+
+void Addressee::setClientPidMapList(const ClientPidMap::List &clientpidmaplist)
+{
+ d->mEmpty = false;
+ d->mClientPidMapList = clientpidmaplist;
+}
+
+void Addressee::insertClientPidMap(const ClientPidMap &clientpidmap)
+{
+ if (clientpidmap.isValid()) {
+ d->mEmpty = false;
+ //TODO don't duplicate ?
+ d->mClientPidMapList.append(clientpidmap);
+ }
+}
+
void Addressee::insertImpp(const Impp &impp)
{
if (impp.isValid()) {
@@ -2448,6 +2474,7 @@ QDataStream &KContacts::operator<<(QDataStream &s, const Addressee &a)
s << a.d->mRoleExtraList;
s << a.d->mOrgExtraList;
s << a.d->mNickNameExtraList;
+ s << a.d->mClientPidMapList;
return s;
}
@@ -2502,6 +2529,7 @@ QDataStream &KContacts::operator>>(QDataStream &s, Addressee &a)
s >> a.d->mRoleExtraList;
s >> a.d->mOrgExtraList;
s >> a.d->mNickNameExtraList;
+ s >> a.d->mClientPidMapList;
a.d->mEmpty = false;
return s;
diff --git a/src/addressee.h b/src/addressee.h
index 744dfa7..aa5f69f 100644
--- a/src/addressee.h
+++ b/src/addressee.h
@@ -49,6 +49,7 @@
#include "nickname.h"
#include "role.h"
#include "org.h"
+#include "clientpidmap.h"
namespace KContacts
{
@@ -1079,6 +1080,11 @@ public:
void setFieldGroupList(const FieldGroup::List &fieldGroupList);
void insertFieldGroup(const FieldGroup &fieldGroup);
+ //ClientPidMap
+ ClientPidMap::List clientPidMapList() const;
+ void setClientPidMapList(const ClientPidMap::List &clientpidmaplist);
+ void insertClientPidMap(const ClientPidMap &clientpidmap);
+
private:
class Private;
QSharedDataPointer<Private> d;
diff --git a/src/clientpidmap.cpp b/src/clientpidmap.cpp
new file mode 100644
index 0000000..7c7dfd7
--- /dev/null
+++ b/src/clientpidmap.cpp
@@ -0,0 +1,139 @@
+/*
+ This file is part of the KContacts framework.
+ Copyright (c) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "clientpidmap.h"
+#include <QMap>
+#include <qstringlist.h>
+#include <QDataStream>
+
+using namespace KContacts;
+
+class Q_DECL_HIDDEN ClientPidMap::Private : public QSharedData
+{
+public:
+ Private()
+ {
+ }
+
+ Private(const Private &other)
+ : QSharedData(other)
+ {
+ parameters = other.parameters;
+ clientpidmap = other.clientpidmap;
+ }
+ QMap<QString, QStringList> parameters;
+ QString clientpidmap;
+};
+
+ClientPidMap::ClientPidMap()
+ : d(new Private)
+{
+
+}
+
+ClientPidMap::ClientPidMap(const ClientPidMap &other)
+ : d(other.d)
+{
+
+}
+
+ClientPidMap::ClientPidMap(const QString &clientpidmap)
+ : d(new Private)
+{
+ d->clientpidmap = clientpidmap;
+}
+
+ClientPidMap::~ClientPidMap()
+{
+
+}
+
+void ClientPidMap::setClientPidMap(const QString &clientpidmap)
+{
+ d->clientpidmap = clientpidmap;
+}
+
+QString ClientPidMap::clientPidMap() const
+{
+ return d->clientpidmap;
+}
+
+bool ClientPidMap::isValid() const
+{
+ return !d->clientpidmap.isEmpty();
+}
+
+void ClientPidMap::setParameters(const QMap<QString, QStringList> &params)
+{
+ d->parameters = params;
+}
+
+QMap<QString, QStringList> ClientPidMap::parameters() const
+{
+ return d->parameters;
+}
+
+bool ClientPidMap::operator==(const ClientPidMap &other) const
+{
+ return (d->parameters == other.parameters()) && (d->clientpidmap == other.clientPidMap());
+}
+
+bool ClientPidMap::operator!=(const ClientPidMap &other) const
+{
+ return !(other == *this);
+}
+
+ClientPidMap &ClientPidMap::operator=(const ClientPidMap &other)
+{
+ if (this != &other) {
+ d = other.d;
+ }
+
+ return *this;
+}
+
+QString ClientPidMap::toString() const
+{
+ QString str;
+ str += QLatin1String("ClientPidMap {\n");
+ str += QStringLiteral(" clientpidmap: %1\n").arg(d->clientpidmap);
+ if (!d->parameters.isEmpty()) {
+ QMapIterator<QString, QStringList> i(d->parameters);
+ QString param;
+ while (i.hasNext()) {
+ i.next();
+ param += QStringLiteral("%1 %2").arg(i.key(), i.value().join(QLatin1Char(',')));
+ }
+ str += QStringLiteral(" parameters: %1\n").arg(param);
+ }
+ str += QLatin1String("}\n");
+ return str;
+}
+
+QDataStream &KContacts::operator<<(QDataStream &s, const ClientPidMap &clientpidmap)
+{
+ return s << clientpidmap.d->parameters << clientpidmap.d->clientpidmap;
+}
+
+QDataStream &KContacts::operator>>(QDataStream &s, ClientPidMap &clientpidmap)
+{
+ s >> clientpidmap.d->parameters >> clientpidmap.d->clientpidmap;
+ return s;
+}
diff --git a/src/clientpidmap.h b/src/clientpidmap.h
new file mode 100644
index 0000000..fd30ea1
--- /dev/null
+++ b/src/clientpidmap.h
@@ -0,0 +1,71 @@
+/*
+ This file is part of the KContacts framework.
+ Copyright (c) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CLIENTPIDMAP_H
+#define CLIENTPIDMAP_H
+
+#include "kcontacts_export.h"
+#include <QtCore/QSharedDataPointer>
+#include <QtCore/QString>
+#include <QtCore/QMap>
+
+/** @short Class that holds a ClientPidMap for a contact.
+ * @since 5.3
+ */
+namespace KContacts
+{
+class KCONTACTS_EXPORT ClientPidMap
+{
+ friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const ClientPidMap &);
+ friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, ClientPidMap &);
+public:
+ ClientPidMap();
+ ClientPidMap(const ClientPidMap &other);
+ ClientPidMap(const QString &clientpidmap);
+
+ ~ClientPidMap();
+
+ typedef QVector<ClientPidMap> List;
+
+ void setClientPidMap(const QString &clientpidmap);
+ QString clientPidMap() const;
+
+ bool isValid() const;
+
+ void setParameters(const QMap<QString, QStringList> &params);
+ QMap<QString, QStringList> parameters() const;
+
+ bool operator==(const ClientPidMap &other) const;
+ bool operator!=(const ClientPidMap &other) const;
+
+ ClientPidMap &operator=(const ClientPidMap &other);
+
+ QString toString() const;
+private:
+ class Private;
+ QSharedDataPointer<Private> d;
+};
+KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ClientPidMap &object);
+
+KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ClientPidMap &object);
+
+}
+Q_DECLARE_TYPEINFO(KContacts::ClientPidMap, Q_MOVABLE_TYPE);
+#endif // CLIENTPIDMAP_H
diff --git a/src/vcardtool.cpp b/src/vcardtool.cpp
index c97c00d..138a048 100644
--- a/src/vcardtool.cpp
+++ b/src/vcardtool.cpp
@@ -279,6 +279,17 @@ QByteArray VCardTool::createVCards(const Addressee::List &list,
card.addLine(line);
}
}
+ // CLIENTPIDMAP
+ if (version == VCard::v4_0) {
+ const ClientPidMap::List clientpidmapList = (*addrIt).clientPidMapList();
+ ClientPidMap::List::ConstIterator clientPidMapIt;
+ ClientPidMap::List::ConstIterator clientPidMapEnd(clientpidmapList.end());
+ for (clientPidMapIt = clientpidmapList.begin(); clientPidMapIt != clientPidMapEnd; ++clientPidMapIt) {
+ VCardLine line(QStringLiteral("CLIENTPIDMAP"), (*clientPidMapIt).clientPidMap());
+ addParameters(line, (*clientPidMapIt).parameters());
+ card.addLine(line);
+ }
+ }
// EMAIL
const Email::List emailList = (*addrIt).emailList();
Email::List::ConstIterator emailIt;
@@ -1122,6 +1133,13 @@ Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const
related.setParameters((*lineIt).parameterMap());
addr.insertRelationShip(related);
}
+ // CLIENTPIDMAP (vcard 4.0)
+ else if (identifier == QLatin1String("clientpidmap")) {
+ ClientPidMap clientpidmap;
+ clientpidmap.setClientPidMap((*lineIt).value().toString());
+ clientpidmap.setParameters((*lineIt).parameterMap());
+ addr.insertClientPidMap(clientpidmap);
+ }
// X-
//TODO import X-GENDER
else if (identifier.startsWith(QLatin1String("x-"))) {
@@ -1203,7 +1221,7 @@ QDateTime VCardTool::parseDateTime(const QString &str, bool *timeValid)
int offsetSecs = 0;
if (strings.length() > 1) {
QString timeString = strings.at(1);
- timeString = timeString.replace(QLatin1String(":"), QLatin1String(""));
+ timeString = timeString.replace(QLatin1String(":"), QString());
QStringList timeStrings = timeString.split(QRegularExpression(QStringLiteral("[Z+-]")));
const QString hhmmssString = timeStrings.at(0);
switch(hhmmssString.size())