Commit 8f398cce authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix compile with last kcontact api

parent 7c7e79f6
Pipeline #91003 passed with stage
in 4 minutes and 7 seconds
......@@ -430,3 +430,15 @@ QString Contact::emailSchemeToProtocolName(const QString &scheme)
return type;
}
KContacts::Email::Type Contact::emailSchemeToProtocolType(const QString &scheme)
{
QString type = scheme.mid(scheme.lastIndexOf(QLatin1Char('#')) + 1);
if (type == QLatin1String("work")) {
return KContacts::Email::Work;
} else if (type == QLatin1String("home")) {
return KContacts::Email::Home;
} else if (type == QLatin1String("other")) {
return KContacts::Email::Other;
}
return KContacts::Email::Unknown;
}
......@@ -225,6 +225,7 @@ class KGAPICONTACTS_EXPORT Contact : public KGAPI2::Object,
* @brief Contacts Google scheme URL to email type.
*/
static QString emailSchemeToProtocolName(const QString &scheme);
static KContacts::Email::Type emailSchemeToProtocolType(const QString &scheme);
private:
class Private;
......
......@@ -9,6 +9,7 @@
#include "contactsgroup.h"
#include "utils.h"
#include "../debug.h"
#include <kcontacts_version.h>
#include <QDomDocument>
#include <QDomElement>
......@@ -450,9 +451,16 @@ ObjectPtr Private::JSONToContact(const QVariantMap& data)
for (const QVariant & em : emails) {
const QVariantMap email = em.toMap();
const auto emailType = Contact::emailSchemeToProtocolName(email.value(QStringLiteral("rel")).toString());
#if KContacts_VERSION < QT_VERSION_CHECK(5, 88, 0)
const QMap<QString, QStringList> params({ { QStringLiteral("type"), { emailType } } });
contact->insertEmail(email.value(QStringLiteral("address")).toString(),
email.value(QStringLiteral("primary")).toBool(), params);
#else
KContacts::Email emailAddress(email.value(QStringLiteral("address")).toString());
emailAddress.setType(Contact::emailSchemeToProtocolType(emailType));
emailAddress.setPreferred(email.value(QStringLiteral("primary")).toBool());
contact->addEmail(emailAddress);
#endif
}
/* IMs */
......@@ -1059,9 +1067,20 @@ ContactPtr XMLToContact(const QByteArray& xmlData)
/* Emails */
if (e.tagName() == QLatin1String("gd:email")) {
const auto emailType = Contact::emailSchemeToProtocolName(e.attribute(QStringLiteral("rel"), {}));
#if KContacts_VERSION < QT_VERSION_CHECK(5, 88, 0)
const QMap<QString, QStringList> params({ { QStringLiteral("type"), { emailType } } });
contact->insertEmail(e.attribute(QStringLiteral("address")),
(e.attribute(QStringLiteral("primary")).toLower() == QLatin1String("true")), params);
#else
KContacts::Email emailAddress(e.attribute(QStringLiteral("address")));
emailAddress.setType(Contact::emailSchemeToProtocolType(emailType));
emailAddress.setPreferred(e.attribute(QStringLiteral("primary")).toLower() == QLatin1String("true"));
contact->addEmail(emailAddress);
#endif
continue;
}
......
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