Commit ebd79b22 authored by Laurent Montel's avatar Laurent Montel 😁

Import/export field group

parent 390166ad
......@@ -124,12 +124,14 @@ void FieldGroupTest::shouldParseFieldGroup()
"UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n"
"REV:2015-03-14T09:24:45+00:00\n"
"FN:FirstName LastName\n"
"fr.foo:bla\n"
"fr2.foo:bla\n"
"END:VCARD\n");
KContacts::VCardTool vcard;
const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata);
QCOMPARE(lst.count(), 1);
QCOMPARE(lst.at(0).fieldGroupList().count(), 1);
QCOMPARE(lst.at(0).fieldGroupList().count(), 2);
}
void FieldGroupTest::shouldParseWithoutFieldGroup()
......@@ -168,6 +170,7 @@ void FieldGroupTest::shouldCreateVCard()
"EMAIL:foo@kde.org\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"fr:bla\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
......@@ -196,6 +199,8 @@ void FieldGroupTest::shouldCreateVCardWithTwoLang()
"EMAIL:foo@kde.org\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"fr:bla\r\n"
"fr2:bla\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
......@@ -226,6 +231,7 @@ void FieldGroupTest::shouldCreateVCardWithParameters()
"EMAIL:foo@kde.org\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"fr;FOO1=bla1,blo1;FOO2=bla2,blo2:bla\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
}
......@@ -254,6 +260,7 @@ void FieldGroupTest::shouldNotGenerateFieldGroupForVCard3()
"EMAIL:foo@kde.org\r\n"
"N:;;;;\r\n"
"UID:testuid\r\n"
"fr;FOO1=bla1,blo1;FOO2=bla2,blo2:bla\r\n"
"END:VCARD\r\n\r\n");
QCOMPARE(ba, expected);
}
......
......@@ -27,6 +27,7 @@
#include "lang.h"
#include "gender.h"
#include "related.h"
#include "fieldgroup.h"
#include <QtCore/QString>
#include <QtCore/QBuffer>
#include <QDebug>
......@@ -541,6 +542,17 @@ QByteArray VCardTool::createVCards(const Addressee::List &list,
}
}
}
//FieldGroup
Q_FOREACH (const FieldGroup &group, (*addrIt).fieldGroupList()) {
VCardLine line(group.fieldGroupName(), group.value());
QMapIterator<QString, QStringList> i(group.parameters());
while (i.hasNext()) {
i.next();
line.addParameter(i.key(), i.value().join(QStringLiteral(",")));
}
card.addLine(line);
}
// IMPP (supported in vcard 3 too)
Q_FOREACH (const Impp &impp, (*addrIt).imppList()) {
VCardLine line(QStringLiteral("IMPP"), impp.address());
......@@ -654,6 +666,10 @@ Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const
identifier = (*lineIt).identifier().toLower();
group = (*lineIt).group();
if (!group.isEmpty()) {
KContacts::FieldGroup groupField(group);
groupField.setParameters((*lineIt).parameterMap());
groupField.setValue((*lineIt).value().toString());
addr.insertFieldGroup(groupField);
qDebug() << "group not empty "<< (*lineIt).value().toString();
}
// ADR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment