summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Krause <[email protected]>2017-11-26 17:23:23 +0100
committerVolker Krause <[email protected]>2017-11-26 19:51:19 +0100
commite23b39e3a2e800d3276dc82a0e2855120efc08c3 (patch)
tree855e60ad3fd421470b98fe69c0215d8428e82a36
parent9a16c031bc380a18f66b5852facc65be2d1517f3 (diff)
Add action to show hotel locations on OpenStreetMap
-rw-r--r--plugins/messageviewer/bodypartformatter/semantic/semanticurlhandler.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/plugins/messageviewer/bodypartformatter/semantic/semanticurlhandler.cpp b/plugins/messageviewer/bodypartformatter/semantic/semanticurlhandler.cpp
index 999f1b4..a98e9f9 100644
--- a/plugins/messageviewer/bodypartformatter/semantic/semanticurlhandler.cpp
+++ b/plugins/messageviewer/bodypartformatter/semantic/semanticurlhandler.cpp
@@ -35,9 +35,11 @@
#include <QDate>
#include <QDBusInterface>
+#include <QDesktopServices>
#include <QIcon>
#include <QMenu>
#include <QMetaProperty>
+#include <QUrlQuery>
#include <memory>
@@ -72,11 +74,34 @@ bool SemanticUrlHandler::handleContextMenuRequest(MimeTreeParser::Interface::Bod
showCalendar(date);
});
}
+
action = menu.addAction(QIcon::fromTheme(QStringLiteral("appointment-new")), i18n("Add To Calendar"));
QObject::connect(action, &QAction::triggered, this, [this, m](){
addToCalendar(m);
});
+ for (const auto &r : m->data()) {
+ if (r.userType() == qMetaTypeId<LodgingReservation>()) {
+ const auto hotel = JsonLdDocument::readProperty(r, "reservationFor");
+ const auto addr = JsonLdDocument::readProperty(hotel, "address");
+ action = menu.addAction(QIcon::fromTheme(QStringLiteral("map-globe")), i18n("Show %1 On Map", JsonLdDocument::readProperty(hotel, "name").toString()));
+ QObject::connect(action, &QAction::triggered, this, [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);
+ });
+ }
+ }
+
menu.exec(p);
return true;
}