Commit 826b834d authored by Volker Krause's avatar Volker Krause

Use locale-aware address formatting

parent cfb1e5cb
......@@ -19,6 +19,7 @@ import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.0 as Kirigami
import org.kde.itinerary 1.0
import "." as App
Item {
......@@ -31,12 +32,7 @@ Item {
QQC2.Label {
id: label
visible: !place.address.isEmpty
// TODO KContact-based locale-dependent address formatting
text: qsTr("%1\n%2 %3\n%4 ")
.arg(place.address.streetAddress)
.arg(place.address.postalCode)
.arg(place.address.addressLocality)
.arg(place.address.addressCountry)
text: Localizer.formatAddress(place.address)
color: Kirigami.Theme.textColor
}
......
......@@ -18,6 +18,7 @@
#include "localizer.h"
#include <KItinerary/JsonLdDocument>
#include <KItinerary/Place>
#include <KContacts/Address>
......@@ -39,6 +40,23 @@ QString Localizer::countryName(const QString& isoCode) const
return KContacts::Address::ISOtoCountry(isoCode);
}
QString Localizer::formatAddress(const QVariant &obj) const
{
if (!JsonLd::isA<PostalAddress>(obj)) {
return {};
}
const auto a = obj.value<PostalAddress>();
KContacts::Address address;
address.setStreet(a.streetAddress());
address.setPostalCode(a.postalCode());
address.setLocality(a.addressLocality());
address.setRegion(a.addressRegion());
address.setCountry(KContacts::Address::ISOtoCountry(a.addressCountry()));
return address.formattedAddress();
}
static bool needsTimeZone(const QDateTime &dt)
{
if (dt.timeSpec() == Qt::TimeZone && dt.timeZone().abbreviation(dt) != QTimeZone::systemTimeZone().abbreviation(dt)) {
......
......@@ -34,6 +34,7 @@ public:
~Localizer();
Q_INVOKABLE QString countryName(const QString &isoCode) const;
Q_INVOKABLE QString formatAddress(const QVariant &obj) const;
Q_INVOKABLE QString formatTime(const QVariant &obj, const QString &propertyName) const;
Q_INVOKABLE QString formatDateTime(const QVariant &obj, const QString &propertyName) const;
};
......
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