summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-10-26 09:08:37 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-10-26 09:08:37 (GMT)
commit7bce2565109f6cb8bea8bfd897ec72d2f9b50cc5 (patch)
treef2f421198551525c6b0faca74361ef90a8b8573b
parent2e5a6e3443437057a54978b8c0047bcc9b199fc8 (diff)
Create proper link from OSM wikipedia tag
-rw-r--r--src/lib/marble/declarative/Placemark.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/lib/marble/declarative/Placemark.cpp b/src/lib/marble/declarative/Placemark.cpp
index 5a76bc2..150e5fe 100644
--- a/src/lib/marble/declarative/Placemark.cpp
+++ b/src/lib/marble/declarative/Placemark.cpp
@@ -155,7 +155,27 @@ QString Placemark::wikipedia() const
return m_wikipedia;
}
- m_wikipedia = m_placemark.osmData().tagValue("wikipedia");
+ // TODO: also support "wikipedia:lang=page title" tags
+ const QString wikipedia = m_placemark.osmData().tagValue("wikipedia");
+ if (!wikipedia.isEmpty()) {
+ // full URL?
+ if (wikipedia.startsWith(QLatin1String("http://")) ||
+ wikipedia.startsWith(QLatin1String("https://"))) {
+ m_wikipedia = wikipedia;
+ } else {
+ // match "(lang:)human readable title"
+ QRegularExpression re("^(?:([a-z]{2,}):)?(.*)$");
+ QRegularExpressionMatch match = re.match(wikipedia);
+ QString lang = match.captured(1);
+ if (lang.isEmpty()) {
+ lang = QStringLiteral("en");
+ }
+ const QString title = QString::fromLatin1(QUrl::toPercentEncoding(match.captured(2)));
+
+ m_wikipedia = QLatin1String("https://") + lang + QLatin1String(".wikipedia.org/wiki/") + title;
+ }
+ }
+
return m_wikipedia;
}