diff --git a/autotests/impptest.cpp b/autotests/impptest.cpp --- a/autotests/impptest.cpp +++ b/autotests/impptest.cpp @@ -140,18 +140,24 @@ "VERSION:4.0\n" "N:LastName;FirstName;;;\n" "UID:c80cf296-0825-4eb0-ab16-1fac1d522a33@xxxxxx.xx\n" - "IMPP:skype:xxxxxxxx\n" + "IMPP;PREF=1:skype:xxxxxxxx\n" + "IMPP:skype:1234567890\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).imppList().count(), 1); + QCOMPARE(lst.at(0).imppList().count(), 2); KContacts::Impp impp = lst.at(0).imppList().at(0); QCOMPARE(impp.address(), QStringLiteral("xxxxxxxx")); QCOMPARE(impp.type(), KContacts::Impp::Skype); + QVERIFY(impp.isPreferred()); + impp = lst.at(0).imppList().at(1); + QCOMPARE(impp.address(), QStringLiteral("1234567890")); + QCOMPARE(impp.type(), KContacts::Impp::Skype); + QVERIFY(!impp.isPreferred()); } QByteArray createCard(KContacts::Impp::ImppType type) @@ -283,6 +289,7 @@ impp.setAddress(QStringLiteral("address")); impp.setType(KContacts::Impp::Skype); impp.setParameters(params); + impp.setPreferred(false); addr.insertImpp(impp); lst << addr; @@ -296,7 +303,7 @@ QByteArray expected("BEGIN:VCARD\r\n" "VERSION:4.0\r\n" "EMAIL:foo@kde.org\r\n" - "IMPP;FOO1=bla1,blo1;FOO2=bla2,blo2;X-SERVICE-TYPE=skype:address\r\n" + "IMPP;FOO1=bla1,blo1;FOO2=bla2,blo2;X-SERVICE-TYPE=skype;PREF=1:address\r\n" "N:;;;;\r\n" "UID:testuid\r\n" "END:VCARD\r\n\r\n"); @@ -312,6 +319,7 @@ impp.setAddress(QStringLiteral("address")); impp.setType(KContacts::Impp::Skype); impp.setParameters(params); + impp.setPreferred(true); addr.insertImpp(impp); lst << addr; diff --git a/src/impp.h b/src/impp.h --- a/src/impp.h +++ b/src/impp.h @@ -22,9 +22,11 @@ #define IMPP_H #include "kcontacts_export.h" + +#include +#include #include #include -#include namespace KContacts { /** @short Class that holds a IMPP for a contact. @@ -36,6 +38,9 @@ */ class KCONTACTS_EXPORT Impp { + Q_GADGET + Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred) + friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Impp &); friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Impp &); public: @@ -72,6 +77,17 @@ void setAddress(const QString &address); Q_REQUIRED_RESULT QString address() const; + /** + * Returns whether this is the preferred messaging address. + * @since 5.12 + */ + bool isPreferred() const; + /** + * Sets that this is the preferred messaging address. + * @since 5.12 + */ + void setPreferred(bool preferred); + void setParameters(const QMap ¶ms); Q_REQUIRED_RESULT QMap parameters() const; @@ -94,5 +110,6 @@ KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Impp &object); } +Q_DECLARE_METATYPE(KContacts::Impp) Q_DECLARE_TYPEINFO(KContacts::Impp, Q_MOVABLE_TYPE); #endif // IMPP_H diff --git a/src/impp.cpp b/src/impp.cpp --- a/src/impp.cpp +++ b/src/impp.cpp @@ -92,6 +92,24 @@ return d->address; } +bool Impp::isPreferred() const +{ + const auto it = d->parameters.constFind(QLatin1String("pref")); + if (it != d->parameters.constEnd() && !it.value().isEmpty()) { + return it.value().at(0) == QLatin1String("1"); + } + return false; +} + +void Impp::setPreferred(bool preferred) +{ + if (preferred) { + d->parameters.insert(QStringLiteral("pref"), {QStringLiteral("1")}); + } else { + d->parameters.remove(QLatin1String("pref")); + } +} + void Impp::setParameters(const QMap ¶ms) { d->parameters = params;