Commit 1097d5cd authored by Volker Krause's avatar Volker Krause

Allow to show arrival/departure airports on a map too

parent 27bbd9f3
...@@ -49,6 +49,47 @@ bool SemanticUrlHandler::handleClick(MessageViewer::Viewer *viewerInstance, Mime ...@@ -49,6 +49,47 @@ bool SemanticUrlHandler::handleClick(MessageViewer::Viewer *viewerInstance, Mime
return path == QLatin1String("semanticAction"); return path == QLatin1String("semanticAction");
} }
static void addGoToMapAction(QMenu *menu, const QVariant &place)
{
if (place.isNull())
return;
const auto addr = JsonLdDocument::readProperty(place, "address");
if (!addr.isNull()) {
auto action = menu->addAction(QIcon::fromTheme(QStringLiteral("map-globe")), i18n("Show \'%1\' On Map", JsonLdDocument::readProperty(place, "name").toString()));
QObject::connect(action, &QAction::triggered, menu, [addr]() {
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/search"));
const QString queryString = JsonLdDocument::readProperty(addr, "streetAddress").toString() + QLatin1String(", ")
+ JsonLdDocument::readProperty(addr, "postalCode").toString() + QLatin1Char(' ')
+ JsonLdDocument::readProperty(addr, "addressLocality").toString() + QLatin1String(", ")
+ JsonLdDocument::readProperty(addr, "addressCountry").toString();
QUrlQuery query;
query.addQueryItem(QStringLiteral("query"), queryString);
url.setQuery(query);
QDesktopServices::openUrl(url);
});
return;
}
const auto geo = JsonLdDocument::readProperty(place, "geo");
if (!geo.isNull()) {
auto action = menu->addAction(QIcon::fromTheme(QStringLiteral("map-globe")), i18n("Show \'%1\' On Map", JsonLdDocument::readProperty(place, "name").toString()));
QObject::connect(action, &QAction::triggered, menu, [geo]() {
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/"));
const QString fragment = QLatin1String("map=12/") + JsonLdDocument::readProperty(geo, "longitude").toString()
+ QLatin1String("/") + JsonLdDocument::readProperty(geo, "latitude").toString();
url.setFragment(fragment);
QDesktopServices::openUrl(url);
});
}
}
bool SemanticUrlHandler::handleContextMenuRequest(MimeTreeParser::Interface::BodyPart *part, const QString &path, const QPoint &p) const bool SemanticUrlHandler::handleContextMenuRequest(MimeTreeParser::Interface::BodyPart *part, const QString &path, const QPoint &p) const
{ {
Q_UNUSED(part); Q_UNUSED(part);
...@@ -76,25 +117,26 @@ bool SemanticUrlHandler::handleContextMenuRequest(MimeTreeParser::Interface::Bod ...@@ -76,25 +117,26 @@ bool SemanticUrlHandler::handleContextMenuRequest(MimeTreeParser::Interface::Bod
addToCalendar(m); addToCalendar(m);
}); });
QSet<QString> places;
for (const auto &r : m->data()) { for (const auto &r : m->data()) {
if (r.userType() == qMetaTypeId<LodgingReservation>()) { if (r.userType() == qMetaTypeId<LodgingReservation>()) {
const auto hotel = JsonLdDocument::readProperty(r, "reservationFor"); addGoToMapAction(&menu, JsonLdDocument::readProperty(r, "reservationFor"));
const auto addr = JsonLdDocument::readProperty(hotel, "address"); } else if (r.userType() == qMetaTypeId<FlightReservation>()) {
action = menu.addAction(QIcon::fromTheme(QStringLiteral("map-globe")), i18n("Show \'%1\' On Map", JsonLdDocument::readProperty(hotel, "name").toString())); const auto flight = JsonLdDocument::readProperty(r, "reservationFor");
QObject::connect(action, &QAction::triggered, this, [addr]() {
QUrl url; auto airport = JsonLdDocument::readProperty(flight, "departureAirport");
url.setScheme(QStringLiteral("https")); auto iataCode = JsonLdDocument::readProperty(airport, "iataCode").toString();
url.setHost(QStringLiteral("www.openstreetmap.org")); if (!places.contains(iataCode)) {
url.setPath(QStringLiteral("/search")); addGoToMapAction(&menu, airport);
const QString queryString = JsonLdDocument::readProperty(addr, "streetAddress").toString() + QLatin1String(", ") places.insert(iataCode);
+ JsonLdDocument::readProperty(addr, "postalCode").toString() + QLatin1Char(' ') }
+ JsonLdDocument::readProperty(addr, "addressLocality").toString() + QLatin1String(", ")
+ JsonLdDocument::readProperty(addr, "addressCountry").toString(); airport = JsonLdDocument::readProperty(flight, "arrivalAirport");
QUrlQuery query; iataCode = JsonLdDocument::readProperty(airport, "iataCode").toString();
query.addQueryItem(QStringLiteral("query"), queryString); if (!places.contains(iataCode)) {
url.setQuery(query); addGoToMapAction(&menu, airport);
QDesktopServices::openUrl(url); places.insert(iataCode);
}); }
} }
} }
......
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