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

Use Title directly so we can save/restore parameters (vcard4)

parent 3ae2da04
......@@ -57,7 +57,8 @@ void ImportExportVCardTest::shouldExportFullTestVcard4()
"LANG;TYPE=work;PREF=2:fr\r\n"
"TZ:London/Europe\r\n"
"GEO:geo:51.5237,0.1585\r\n"
"TITLE:Detective\r\n"
"TITLE;ALTID=1;LANGUAGE=fr:Patron\r\n"
"TITLE;ALTID=2;LANGUAGE=en:Boss\r\n"
"ROLE:Detective\r\n"
"UID:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\r\n"
"CATEGORIES:FICTION,LITERATURE\r\n"
......@@ -85,8 +86,7 @@ void ImportExportVCardTest::shouldExportFullTestVcard4()
"GEO:geo:51.523701,0.158500\r\n"
"IMPP;X-SERVICE-TYPE=xmpp;PREF=1:detective@sherlockholmes.com\r\n"
"KEY;MEDIATYPE=application/pgp-keys:https://sherlockholmes.com/sherlock-holm\r\n"
" es.pub.asc\r\n"
"KIND:individual\r\n"
" es.pub.asc\r\nKIND:individual\r\n"
"LANG;PREF=1;TYPE=work:en\r\n"
"LANG;PREF=2;TYPE=work:fr\r\n"
"N:Holmes;Sherlock;;Mr;\r\n"
......@@ -96,11 +96,13 @@ void ImportExportVCardTest::shouldExportFullTestVcard4()
"TEL;PREF=1;VALUE=uri:ext=5555\r\n"
"TEL;TYPE=\"cell,voice\";VALUE=uri:tel:+44-555-555-6666\r\n"
"TEL;TYPE=\"voice,work\";VALUE=uri:tel:+44-555-555-7777\r\n"
"TITLE:Detective\r\n"
"TITLE;ALTID=1;LANGUAGE=fr:Patron\r\n"
"TITLE;ALTID=2;LANGUAGE=en:Boss\r\n"
"TZ:+00:00\r\n"
"UID:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\r\n"
"URL:https://sherlockholmes.com\r\n"
"END:VCARD\r\n\r\n");
KContacts::VCardTool vcard;
const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata);
......
......@@ -69,7 +69,6 @@ public:
mMailer = other.mMailer;
mTimeZone = other.mTimeZone;
mGeo = other.mGeo;
mTitle = other.mTitle;
mRole = other.mRole;
mOrganization = other.mOrganization;
mDepartment = other.mDepartment;
......@@ -101,6 +100,7 @@ public:
mEmpty = other.mEmpty;
mImpps = other.mImpps;
mChanged = other.mChanged;
mTitleExtraList = other.mTitleExtraList;
}
~Private()
......@@ -120,7 +120,6 @@ public:
QString mMailer;
TimeZone mTimeZone;
Geo mGeo;
QString mTitle;
QString mRole;
QString mOrganization;
QString mDepartment;
......@@ -152,6 +151,7 @@ public:
QStringList mMembers;
Related::List mRelationShips;
FieldGroup::List mFieldGroupList;
Title::List mTitleExtraList;
bool mEmpty : 1;
bool mChanged : 1;
......@@ -259,12 +259,6 @@ bool Addressee::operator==(const Addressee &addressee) const
return false;
}
if (d->mTitle != addressee.d->mTitle &&
!(d->mTitle.isEmpty() && addressee.d->mTitle.isEmpty())) {
qCDebug(KCONTACTS_LOG) << "title differs";
return false;
}
if (d->mRole != addressee.d->mRole &&
!(d->mRole.isEmpty() && addressee.d->mRole.isEmpty())) {
qCDebug(KCONTACTS_LOG) << "role differs";
......@@ -403,6 +397,10 @@ bool Addressee::operator==(const Addressee &addressee) const
return false;
}
if (!listEquals(d->mTitleExtraList, addressee.d->mTitleExtraList)) {
qCDebug(KCONTACTS_LOG) << "Extra TitleList differs";
return false;
}
return true;
}
......@@ -949,17 +947,47 @@ QString Addressee::geoLabel()
void Addressee::setTitle(const QString &title)
{
if (title == d->mTitle) {
return;
Title t(title);
if (!d->mTitleExtraList.isEmpty()) {
d->mTitleExtraList.takeFirst();
d->mTitleExtraList.prepend(t);
d->mEmpty = false;
} else {
insertExtraTitle(title);
}
}
d->mEmpty = false;
d->mTitle = title;
void Addressee::setTitle(const Title &title)
{
insertExtraTitle(title);
}
void Addressee::insertExtraTitle(const Title &title)
{
if (title.isValid()) {
d->mEmpty = false;
d->mTitleExtraList.append(title);
}
}
QString Addressee::title() const
{
return d->mTitle;
if (d->mTitleExtraList.isEmpty()) {
return {};
} else {
return d->mTitleExtraList.at(0).title();
}
}
Title::List Addressee::extraTitleList() const
{
return d->mTitleExtraList;
}
void Addressee::setExtraTitleList(const Title::List &urltitle)
{
d->mEmpty = false;
d->mTitleExtraList = urltitle;
}
QString Addressee::titleLabel()
......@@ -2272,7 +2300,6 @@ QDataStream &KContacts::operator<<(QDataStream &s, const Addressee &a)
s << a.d->mMailer;
s << a.d->mTimeZone;
s << a.d->mGeo;
s << a.d->mTitle;
s << a.d->mRole;
s << a.d->mOrganization;
s << a.d->mDepartment;
......@@ -2303,6 +2330,7 @@ QDataStream &KContacts::operator<<(QDataStream &s, const Addressee &a)
s << a.d->mSources;
s << a.d->mImpps;
s << a.d->mFieldGroupList;
s << a.d->mTitleExtraList;
return s;
}
......@@ -2323,7 +2351,6 @@ QDataStream &KContacts::operator>>(QDataStream &s, Addressee &a)
s >> a.d->mMailer;
s >> a.d->mTimeZone;
s >> a.d->mGeo;
s >> a.d->mTitle;
s >> a.d->mRole;
s >> a.d->mOrganization;
s >> a.d->mDepartment;
......@@ -2356,6 +2383,7 @@ QDataStream &KContacts::operator>>(QDataStream &s, Addressee &a)
s >> a.d->mSources;
s >> a.d->mImpps;
s >> a.d->mFieldGroupList;
s >> a.d->mTitleExtraList;
a.d->mEmpty = false;
return s;
......
......@@ -45,6 +45,7 @@
#include "addresseelist.h"
#include "resourcelocatorurl.h"
#include "fieldgroup.h"
#include "title.h"
namespace KContacts
{
......@@ -452,7 +453,13 @@ public:
/**
Set title.
*/
//Remove in kf6
void setTitle(const QString &title);
void setTitle(const Title &title);
void insertExtraTitle(const Title &title);
void setExtraTitleList(const Title::List &urltitle);
Title::List extraTitleList() const;
/**
Return title.
......
......@@ -54,10 +54,10 @@ Title::Title(const Title &other)
}
Title::Title(const QString &language)
Title::Title(const QString &title)
: d(new Private)
{
d->title = language;
d->title = title;
}
Title::~Title()
......
......@@ -38,7 +38,7 @@ class KCONTACTS_EXPORT Title
public:
Title();
Title(const Title &other);
Title(const QString &titleuage);
Title(const QString &title);
~Title();
......
......@@ -483,12 +483,20 @@ QByteArray VCardTool::createVCards(const Addressee::List &list,
}
// TITLE
VCardLine titleLine(QStringLiteral("TITLE"), (*addrIt).title());
if (version == VCard::v2_1 && needsEncoding((*addrIt).title())) {
titleLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8"));
titleLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE"));
Q_FOREACH (const Title &title, (*addrIt).extraTitleList()) {
VCardLine titleLine(QStringLiteral("TITLE"), title.title());
if (version == VCard::v2_1 && needsEncoding(title.title())) {
titleLine.addParameter(QStringLiteral("charset"), QStringLiteral("UTF-8"));
titleLine.addParameter(QStringLiteral("encoding"), QStringLiteral("QUOTED-PRINTABLE"));
}
QMapIterator<QString, QStringList> i(title.parameters());
while (i.hasNext()) {
i.next();
titleLine.addParameter(i.key(), i.value().join(QLatin1Char(',')));
}
card.addLine(titleLine);
}
card.addLine(titleLine);
// TZ
// TODO Add vcard4.0 support
......@@ -1034,16 +1042,11 @@ Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const
// TEL
else if (identifier == QLatin1String("tel")) {
//TODO implement load vcard4
PhoneNumber phone;
phone.setNumber((*lineIt).value().toString());
PhoneNumber::Type type;
bool foundType = false;
#if 0
qDebug() << " (*lineIt).parameters" << (*lineIt).parameterMap();
qDebug() << " (*lineIt).value()" << (*lineIt).value().toString();
#endif
const QStringList types = (*lineIt).parameters(QStringLiteral("type"));
QStringList::ConstIterator typeEnd(types.constEnd());
for (QStringList::ConstIterator it = types.constBegin(); it != typeEnd; ++it) {
......@@ -1058,7 +1061,9 @@ Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const
// TITLE
else if (identifier == QLatin1String("title")) {
addr.setTitle((*lineIt).value().toString());
Title title((*lineIt).value().toString());
title.setParameters((*lineIt).parameterMap());
addr.insertExtraTitle(title);
}
// TZ
......
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