Commit 2af01e5c authored by Volker Krause's avatar Volker Krause
Browse files

Port KContacts::Address::countryToISO to new KI18n API

This function in KContacts is about to be deprecated.
parent 7c822b1a
Pipeline #91389 passed with stage
in 10 minutes and 43 seconds
......@@ -175,6 +175,9 @@ target_link_libraries(KF5AkonadiContact
KF5::Prison
Grantlee5::Templates
)
if(TARGET KF5::I18nLocaleData)
target_link_libraries(KF5AkonadiContact PRIVATE KF5::I18nLocaleData)
endif()
if(TARGET KF5::Libkleo)
target_link_libraries(KF5AkonadiContact
......
......@@ -13,6 +13,10 @@
#include <KContacts/Address>
#include <KDialogJobUiDelegate>
#include <KIO/CommandLauncherJob>
#include <ki18n_version.h>
#if KI18N_VERSION >= QT_VERSION_CHECK(5, 88, 0)
#include <KCountry>
#endif
#include <QDesktopServices>
......@@ -20,12 +24,22 @@ using namespace Akonadi;
static void replaceArguments(QString &templateStr, const KContacts::Address &address)
{
#if KI18N_VERSION >= QT_VERSION_CHECK(5, 88, 0)
const auto country = KCountry::fromName(address.country()); // will also handle ISO 3166-1 alpha 2 or 3 codes
templateStr.replace(QLatin1String("%s"), address.street())
.replace(QLatin1String("%r"), address.region())
.replace(QLatin1String("%l"), address.locality())
.replace(QLatin1String("%z"), address.postalCode())
.replace(QLatin1String("%n"), country.name())
.replace(QLatin1String("%c"), country.alpha2());
#else
templateStr.replace(QLatin1String("%s"), address.street())
.replace(QLatin1String("%r"), address.region())
.replace(QLatin1String("%l"), address.locality())
.replace(QLatin1String("%z"), address.postalCode())
.replace(QLatin1String("%n"), address.country())
.replace(QLatin1String("%c"), address.countryToISO(address.country()));
#endif
}
void ShowAddressAction::showAddress(const KContacts::Address &address)
......
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