Commit 562a0482 authored by Volker Krause's avatar Volker Krause
Browse files

Use the new KContacts address formatting API

This also restores compatibility with KF 5.91 (which is the minimum
required version by 22.04) after dce31b90.
parent 3eb750df
Pipeline #151818 skipped
......@@ -11,6 +11,7 @@
#include <KContacts/Addressee>
#include <KContacts/ContactGroup>
#include <kcontacts_version.h>
#include <KIconLoader>
#include <KLocalizedString>
......@@ -99,14 +100,22 @@ QVariant ContactsTreeModel::entityData(const Item &item, int column, int role) c
case HomeAddress: {
const KContacts::Address address = contact.address(KContacts::Address::Home);
if (!address.isEmpty()) {
return address.formatted(KContacts::AddressFormatStyle::Postal);
#if KContacts_VERSION < QT_VERSION_CHECK(5, 92, 0)
return address.formattedAddress();
#else
return address.formatted(KContacts::AddressFormatStyle::MultiLineInternational);
#endif
}
break;
}
case BusinessAddress: {
const KContacts::Address address = contact.address(KContacts::Address::Work);
if (!address.isEmpty()) {
return address.formatted(KContacts::AddressFormatStyle::Postal);
#if KContacts_VERSION < QT_VERSION_CHECK(5, 92, 0)
return address.formattedAddress();
#else
return address.formatted(KContacts::AddressFormatStyle::MultiLineInternational);
#endif
}
break;
}
......
......@@ -12,6 +12,7 @@
#include <KColorScheme>
#include <KConfigGroup>
#include <KContacts/Addressee>
#include <kcontacts_version.h>
#include <KLocalizedString>
#include <KStringHandler>
......@@ -146,12 +147,20 @@ QString StandardContactFormatter::toHtml(HtmlForm form) const
QString formattedAddress;
if (address.label().isEmpty()) {
formattedAddress = address.formatted(KContacts::AddressFormatStyle::Postal).trimmed().toHtmlEscaped();
#if KContacts_VERSION < QT_VERSION_CHECK(5, 92, 0)
formattedAddress = address.formattedAddress().trimmed().toHtmlEscaped();
#else
formattedAddress = address.formatted(KContacts::AddressFormatStyle::MultiLineInternational).toHtmlEscaped();
#endif
} else {
formattedAddress = address.label().toHtmlEscaped();
}
#if KContacts_VERSION < QT_VERSION_CHECK(5, 92, 0)
formattedAddress.replace(QRegularExpression(QStringLiteral("\n+")), QStringLiteral("<br>"));
#else
formattedAddress.replace(QLatin1Char('\n'), QStringLiteral("<br>"));
#endif
const QString url = QStringLiteral("<a href=\"address:?index=%1\" title=\"%2\"><img src=\"map_icon\" alt=\"%2\"/></a>")
.arg(counter)
......
......@@ -8,6 +8,8 @@
#include "addressmodel.h"
#include <kcontacts_version.h>
using namespace ContactEditor;
AddressModel::AddressModel(QObject *parent)
......@@ -80,7 +82,11 @@ QVariant AddressModel::data(const QModelIndex &index, int role) const
if (!addr.label().isEmpty()) {
str += addr.label().toHtmlEscaped().replace(QLatin1Char('\n'), QLatin1String("<br/>"));
} else {
str += addr.formatted(KContacts::AddressFormatStyle::Postal).trimmed().toHtmlEscaped().replace(QLatin1Char('\n'), QLatin1String("<br/>"));
#if KContacts_VERSION < QT_VERSION_CHECK(5, 92, 0)
str += addr.formattedAddress().trimmed().toHtmlEscaped().replace(QLatin1Char('\n'), QLatin1String("<br/>"));
#else
str += addr.formatted(KContacts::AddressFormatStyle::MultiLineInternational).toHtmlEscaped().replace(QLatin1Char('\n'), QLatin1String("<br/>"));
#endif
}
return str;
}
......
Supports Markdown
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