Commit 23ce1aa6 authored by Volker Krause's avatar Volker Krause
Browse files

Use KContact's address formatter also for producing geo: URIs

parent d6ad8878
Pipeline #152180 passed with stages
in 3 minutes and 45 seconds
......@@ -10,7 +10,6 @@
#include <KCalendarCore/ICalFormat>
#include <KCalendarCore/MemoryCalendar>
#include <kcontacts_version.h>
#include <QDebug>
#include <QFile>
......@@ -103,10 +102,8 @@ private Q_SLOTS:
QCOMPARE(newEvent->dtStart(), refEvent->dtStart());
QCOMPARE(newEvent->dtEnd(), refEvent->dtEnd());
QCOMPARE(newEvent->customProperty("KITINERARY", "RESERVATION"), refEvent->customProperty("KITINERARY", "RESERVATION"));
#if KContacts_VERSION >= QT_VERSION_CHECK(5, 92, 0)
QCOMPARE(newEvent->description(), refEvent->description());
QVERIFY(*newEvent == *refEvent);
#endif
}
void testFindEvent_data()
......
......@@ -148,7 +148,7 @@ private Q_SLOTS:
QCOMPARE(LocationUtil::geoUri(p), QUrl(QStringLiteral("geo:45.5137,9.21139")));
p.setGeo({});
QCOMPARE(LocationUtil::geoUri(p), QUrl(QStringLiteral("geo:0,0?q=Piazza della Scienza, Milan, IT")));
QCOMPARE(LocationUtil::geoUri(p), QUrl(QStringLiteral("geo:0,0?q=Piazza della Scienza,MILAN,IT")));
}
};
......
......@@ -7,6 +7,7 @@
#include "config-kitinerary.h"
#include "calendarhandler.h"
#include "jsonlddocument.h"
#include "locationutil_p.h"
#include "logging.h"
#include "mergeutil.h"
#include "sortutil.h"
......@@ -29,7 +30,6 @@
#include <KCalendarCore/Event>
#endif
#include <kcontacts_version.h>
#include <KContacts/Address>
#include <KLocalizedString>
......@@ -40,33 +40,14 @@
using namespace KItinerary;
static KContacts::Address convertAddress(const PostalAddress &addr)
{
KContacts::Address a;
a.setStreet(addr.streetAddress());
a.setPostalCode(addr.postalCode());
a.setLocality(addr.addressLocality());
a.setRegion(addr.addressRegion());
a.setCountry(addr.addressCountry());
return a;
}
static QString formatAddress(const PostalAddress &addr)
{
#if KContacts_VERSION >= QT_VERSION_CHECK(5, 92, 0)
return convertAddress(addr).formatted(KContacts::AddressFormatStyle::MultiLineInternational);
#else
return convertAddress(addr).formattedAddress();
#endif
return LocationUtil::toAddress(addr).formatted(KContacts::AddressFormatStyle::MultiLineInternational);
}
static QString formatAddressSingleLine(const PostalAddress &addr)
{
#if KContacts_VERSION >= QT_VERSION_CHECK(5, 92, 0)
return convertAddress(addr).formatted(KContacts::AddressFormatStyle::SingleLineInternational);
#else
return formatAddress(addr).replace(QLatin1String("\n\n"), QLatin1String("\n")).replace(QLatin1Char('\n'), QLatin1String(", "));
#endif
return LocationUtil::toAddress(addr).formatted(KContacts::AddressFormatStyle::SingleLineInternational);
}
#ifdef HAVE_KCAL
......
......@@ -5,6 +5,7 @@
*/
#include "locationutil.h"
#include "locationutil_p.h"
#include <KItinerary/BoatTrip>
#include <KItinerary/BusTrip>
......@@ -15,6 +16,8 @@
#include <KItinerary/TrainTrip>
#include <KItinerary/Visit>
#include <KContacts/Address>
#include <QDebug>
#include <QUrl>
#include <QUrlQuery>
......@@ -23,6 +26,17 @@
using namespace KItinerary;
KContacts::Address LocationUtil::toAddress(const PostalAddress &addr)
{
KContacts::Address a;
a.setStreet(addr.streetAddress());
a.setPostalCode(addr.postalCode());
a.setLocality(addr.addressLocality());
a.setRegion(addr.addressRegion());
a.setCountry(addr.addressCountry());
return a;
}
bool LocationUtil::isLocationChange(const QVariant &res)
{
if (JsonLd::isA<RentalCarReservation>(res)) {
......@@ -309,22 +323,8 @@ QUrl LocationUtil::geoUri(const QVariant &location)
const auto addr = LocationUtil::address(location);
if (!addr.isEmpty()) {
url.setPath(QStringLiteral("0,0"));
QStringList q;
if (!addr.streetAddress().isEmpty()) {
q.push_back(addr.streetAddress());
}
if (!addr.addressLocality().isEmpty()) {
q.push_back(addr.postalCode().isEmpty() ? addr.addressLocality() : (addr.postalCode() + QLatin1Char(' ') + addr.addressLocality()));
}
if (!addr.addressRegion().isEmpty()) {
q.push_back(addr.addressRegion());
}
if (!addr.addressCountry().isEmpty()) {
q.push_back(addr.addressCountry());
}
QUrlQuery query;
query.addQueryItem(QStringLiteral("q"), q.join(QLatin1String(", ")));
query.addQueryItem(QStringLiteral("q"), toAddress(addr).formatted(KContacts::AddressFormatStyle::GeoUriQuery));
url.setQuery(query);
return url;
}
......
/*
SPDX-FileCopyrightText: 2017-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_LOCATIONUTIL_P_H
#define KITINERARY_LOCATIONUTIL_P_H
namespace KContacts {
class Address;
}
namespace KItinerary {
class PostalAddress;
namespace LocationUtil {
/** Convert a schema.org address object into a KContacts one. */
KContacts::Address toAddress(const PostalAddress &addr);
}
}
#endif
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