Commit 3ae2da04 authored by Laurent Montel's avatar Laurent Montel 😁

Allow to store/restore parameters

parent 3bc0d0a0
......@@ -93,9 +93,9 @@ void ImportExportVCardTest::shouldExportFullTestVcard4()
"NICKNAME:Shirley\r\n"
"PRODID:-//KADDRESSBOOK//NONSGML Version 1//EN\r\n"
"ROLE:Detective\r\n"
"TEL:ext=5555\r\n"
"TEL;TYPE=\"cell,voice\":tel:+44-555-555-6666\r\n"
"TEL;TYPE=\"voice,work\":tel:+44-555-555-7777\r\n"
"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"
"TZ:+00:00\r\n"
"UID:urn:uuid:b8767877-b4a1-4c70-9acc-505d3819e519\r\n"
......
......@@ -52,6 +52,7 @@ public:
QString mId;
QString mNumber;
Type mType;
QMap<QString, QStringList> mParameters;
};
PhoneNumber::PhoneNumber()
......@@ -88,6 +89,10 @@ bool PhoneNumber::operator==(const PhoneNumber &other) const
return false;
}
if (d->mParameters != other.d->mParameters) {
return false;
}
return true;
}
......@@ -251,21 +256,40 @@ QString PhoneNumber::toString() const
str += QLatin1String("PhoneNumber {\n");
str += QStringLiteral(" Id: %1\n").arg(d->mId);
str += QStringLiteral(" Type: %1\n").arg(typeLabel(d->mType));
if (!d->mParameters.isEmpty()) {
QMapIterator<QString, QStringList> i(d->mParameters);
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 += QStringLiteral(" Number: %1\n").arg(d->mNumber);
str += QLatin1String("}\n");
return str;
}
void PhoneNumber::setParameters(const QMap<QString, QStringList> &params)
{
d->mParameters = params;
}
QMap<QString, QStringList> PhoneNumber::parameters() const
{
return d->mParameters;
}
QDataStream &KContacts::operator<<(QDataStream &s, const PhoneNumber &phone)
{
return s << phone.d->mId << (uint)phone.d->mType << phone.d->mNumber;
return s << phone.d->mId << (uint)phone.d->mType << phone.d->mNumber << phone.d->mParameters;
}
QDataStream &KContacts::operator>>(QDataStream &s, PhoneNumber &phone)
{
uint type;
s >> phone.d->mId >> type >> phone.d->mNumber;
s >> phone.d->mId >> type >> phone.d->mNumber >> phone.d->mParameters;
phone.d->mType = PhoneNumber::Type(type);
return s;
......
......@@ -26,6 +26,8 @@
#include <QtCore/QSharedDataPointer>
#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QMap>
namespace KContacts
{
......@@ -205,6 +207,10 @@ public:
*/
QString toString() const;
void setParameters(const QMap<QString, QStringList> &params);
QMap<QString, QStringList> parameters() const;
private:
class Private;
QSharedDataPointer<Private> d;
......
......@@ -456,6 +456,13 @@ QByteArray VCardTool::createVCards(const Addressee::List &list,
PhoneNumber::List::ConstIterator phoneEnd(phoneNumbers.end());
for (phoneIt = phoneNumbers.begin(); phoneIt != phoneEnd; ++phoneIt) {
VCardLine line(QStringLiteral("TEL"), (*phoneIt).number());
QMapIterator<QString, QStringList> i((*phoneIt).parameters());
while (i.hasNext()) {
i.next();
if (i.key().toUpper() != QLatin1String("TYPE")) {
line.addParameter(i.key(), i.value().join(QLatin1Char(',')));
}
}
QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeIt;
QMap<QString, PhoneNumber::TypeFlag>::ConstIterator typeEnd(mPhoneTypeMap.constEnd());
......@@ -1044,6 +1051,7 @@ Addressee::List VCardTool::parseVCards(const QByteArray &vcard) const
foundType = true;
}
phone.setType(foundType ? type : PhoneNumber::Undefined);
phone.setParameters((*lineIt).parameterMap());
addr.insertPhoneNumber(phone);
}
......
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