summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices
diff options
context:
space:
mode:
authorAnders Gunnarsson <anders.gunnarsson@appello.com>2014-02-12 09:01:03 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-03 16:08:00 +0100
commit61d235c2f5af88a0a22105722142f2c72817ee00 (patch)
treed310f0c75bc939589bdc9f20e28b824f63ac58f2 /src/plugins/geoservices
parent985a8b9c608503d90b7fe73f5a995ad2091f0070 (diff)
downloadqtlocation-61d235c2f5af88a0a22105722142f2c72817ee00.tar.gz
Tile cache versioning for Nokia maps
Added to avoid mixing of different map versions in map view. Generic cache versioning by adding an incremental version number to tile specs and filenames. Default version -1 falls back to not using version in file names for backward compatibility. Nokia specific version management by implementing the version request, comparing all version information and increment the version if anything has changed. Task-number: QTBUG-25559 Change-Id: I6820f2efbe7458701475cc833d3077022797b2df Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/plugins/geoservices')
-rw-r--r--src/plugins/geoservices/nokia/nokia.pro6
-rw-r--r--src/plugins/geoservices/nokia/qgeomapversion.cpp91
-rw-r--r--src/plugins/geoservices/nokia/qgeomapversion.h75
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp6
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h2
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp76
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h7
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp56
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h3
9 files changed, 315 insertions, 7 deletions
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro
index 597f8bae..647a0a4e 100644
--- a/src/plugins/geoservices/nokia/nokia.pro
+++ b/src/plugins/geoservices/nokia/nokia.pro
@@ -27,7 +27,8 @@ HEADERS += \
qgeointrinsicnetworkaccessmanager.h \
qgeouriprovider.h \
uri_constants.h \
- qgeoerror_messages.h
+ qgeoerror_messages.h \
+ qgeomapversion.h
SOURCES += \
@@ -45,7 +46,8 @@ SOURCES += \
qgeointrinsicnetworkaccessmanager.cpp \
qgeouriprovider.cpp \
uri_constants.cpp \
- qgeoerror_messages.cpp
+ qgeoerror_messages.cpp \
+ qgeomapversion.cpp
include(placesv2/placesv2.pri)
diff --git a/src/plugins/geoservices/nokia/qgeomapversion.cpp b/src/plugins/geoservices/nokia/qgeomapversion.cpp
new file mode 100644
index 00000000..c86b98a3
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeomapversion.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Appello Systems AB.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Nokia services plugin for the Maps and
+** Navigation API. The use of these services, whether by use of the
+** plugin or by other means, is governed by the terms and conditions
+** described by the file NOKIA_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Nokia services
+** plugin source code.
+**
+****************************************************************************/
+
+#include "qgeomapversion.h"
+
+#include <QJsonDocument>
+
+QT_BEGIN_NAMESPACE
+
+QGeoMapVersion::QGeoMapVersion()
+ : m_version(-1) {}
+
+bool QGeoMapVersion::isNewVersion(const QJsonObject &newVersionData)
+{
+ return m_versionData != newVersionData;
+}
+
+int QGeoMapVersion::version() const
+{
+ return m_version;
+}
+
+void QGeoMapVersion::setVersion(int version)
+{
+ m_version = version;
+}
+
+void QGeoMapVersion::setVersionData(const QJsonObject &versionData)
+{
+ m_versionData = versionData;
+}
+
+
+QByteArray QGeoMapVersion::toJson() const
+{
+
+ QJsonObject object;
+ object[QLatin1String("version")] = m_version;
+ object[QLatin1String("data")] = m_versionData;
+
+ QJsonDocument document(object);
+
+ return document.toJson();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeomapversion.h b/src/plugins/geoservices/nokia/qgeomapversion.h
new file mode 100644
index 00000000..18a9f3a7
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeomapversion.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Appello Systems AB.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Nokia services plugin for the Maps and
+** Navigation API. The use of these services, whether by use of the
+** plugin or by other means, is governed by the terms and conditions
+** described by the file NOKIA_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Nokia services
+** plugin source code.
+**
+****************************************************************************/
+
+#ifndef QGEOMAPVERSION_H
+#define QGEOMAPVERSION_H
+
+#include <QByteArray>
+#include <QJsonObject>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoMapVersion
+{
+
+public:
+ QGeoMapVersion();
+ bool isNewVersion(const QJsonObject &newVersionData);
+ int version() const;
+ void setVersion(const int);
+ void setVersionData(const QJsonObject &versionData);
+ QByteArray toJson() const;
+
+private:
+ int m_version;
+ QJsonObject m_versionData;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOMAPVERSION_H
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
index 506b3f70..563d8270 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
@@ -155,4 +155,10 @@ void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visible
}
}
+int QGeoTiledMapDataNokia::mapVersion()
+{
+ QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine());
+ return engineNokia->mapVersion();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
index 24e6b9c7..af87540d 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
@@ -66,6 +66,8 @@ public:
QString getViewCopyright();
void evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles);
+ int mapVersion();
+
private:
Q_DISABLE_COPY(QGeoTiledMapDataNokia)
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
index 0968b0b3..8c3cbe3b 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -138,7 +138,9 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(
}
populateMapSchemes();
+ loadMapVersion();
QMetaObject::invokeMethod(fetcher, "fetchCopyrightsData", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(fetcher, "fetchVersionData", Qt::QueuedConnection);
}
QGeoTiledMappingManagerEngineNokia::~QGeoTiledMappingManagerEngineNokia()
@@ -181,6 +183,11 @@ QString QGeoTiledMappingManagerEngineNokia::getBaseScheme(int mapId)
return fullScheme.section(QLatin1Char('.'), 0, 0);
}
+int QGeoTiledMappingManagerEngineNokia::mapVersion()
+{
+ return m_mapVersion.version();
+}
+
void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const QByteArray &jsonData)
{
QJsonDocument doc = QJsonDocument::fromJson(QByteArray(jsonData));
@@ -225,6 +232,75 @@ void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const
}
}
+void QGeoTiledMappingManagerEngineNokia::parseNewVersionInfo(const QByteArray &versionData)
+{
+ const QString versionString = QString::fromUtf8(versionData);
+
+ const QStringList versionLines = versionString.split(QLatin1Char('\n'));
+ QJsonObject newVersionData;
+ foreach (const QString &line, versionLines) {
+ const QStringList versionInfo = line.split(':');
+ if (versionInfo.size() > 1) {
+ const QString versionKey = versionInfo[0].trimmed();
+ const QString versionValue = versionInfo[1].trimmed();
+ if (!versionKey.isEmpty() && !versionValue.isEmpty()) {
+ newVersionData[versionKey] = versionValue;
+ }
+ }
+ }
+
+ updateVersion(newVersionData);
+}
+
+void QGeoTiledMappingManagerEngineNokia::updateVersion(const QJsonObject &newVersionData) {
+
+ if (m_mapVersion.isNewVersion(newVersionData)) {
+
+ m_mapVersion.setVersionData(newVersionData);
+ m_mapVersion.setVersion(m_mapVersion.version() + 1);
+
+ saveMapVersion();
+
+ emit mapVersionChanged();
+ }
+}
+
+void QGeoTiledMappingManagerEngineNokia::saveMapVersion()
+{
+ QDir saveDir(tileCache()->directory());
+ QFile saveFile(saveDir.filePath(QLatin1String("nokia_version")));
+
+ if (!saveFile.open(QIODevice::WriteOnly)) {
+ qWarning("Failed to write nokia map version.");
+ return;
+ }
+
+ saveFile.write(m_mapVersion.toJson());
+ saveFile.close();
+}
+
+void QGeoTiledMappingManagerEngineNokia::loadMapVersion()
+{
+
+ QDir saveDir(tileCache()->directory());
+ QFile loadFile(saveDir.filePath(QLatin1String("nokia_version")));
+
+ if (!loadFile.open(QIODevice::ReadOnly)) {
+ qWarning("Failed to read nokia map version.");
+ return;
+ }
+
+ QByteArray saveData = loadFile.readAll();
+ loadFile.close();
+
+ QJsonDocument doc(QJsonDocument::fromJson(saveData));
+
+ QJsonObject object = doc.object();
+
+ m_mapVersion.setVersion(object[QLatin1String("version")].toInt());
+ m_mapVersion.setVersionData(object[QLatin1String("data")].toObject());
+}
+
QString QGeoTiledMappingManagerEngineNokia::evaluateCopyrightsText(const QGeoMapType mapType,
const qreal zoomLevel,
const QSet<QGeoTileSpec> &tiles)
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
index a30dcf69..0f2f5cb1 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
@@ -52,6 +52,7 @@
#include "qgeotiledmappingmanagerengine_p.h"
#include <QtPositioning/QGeoRectangle>
#include "qgeomaptype_p.h"
+#include "qgeomapversion.h"
#include <QGeoServiceProvider>
@@ -82,9 +83,11 @@ public:
const QSet<QGeoTileSpec> &tiles);
QString getScheme(int mapId);
QString getBaseScheme(int mapId);
+ int mapVersion();
public Q_SLOTS:
void loadCopyrightsDescriptorsFromJson(const QByteArray &jsonData);
+ void parseNewVersionInfo(const QByteArray &versionData);
private:
class CopyrightDesc
@@ -103,9 +106,13 @@ private:
void initialize();
void populateMapSchemes();
+ void updateVersion(const QJsonObject &newVersionData);
+ void saveMapVersion();
+ void loadMapVersion();
QHash<QString, QList<CopyrightDesc> > m_copyrights;
QHash<int, QString> m_mapSchemes;
+ QGeoMapVersion m_mapVersion;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
index c7f16eeb..a6ce9c0a 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
@@ -246,28 +246,42 @@ QString QGeoTileFetcherNokia::applicationId() const
void QGeoTileFetcherNokia::copyrightsFetched()
{
- if (m_engineNokia) {
+ if (m_engineNokia && m_copyrightsReply->error() == QNetworkReply::NoError) {
QMetaObject::invokeMethod(m_engineNokia.data(),
"loadCopyrightsDescriptorsFromJson",
Qt::QueuedConnection,
Q_ARG(QByteArray, m_copyrightsReply->readAll()));
}
+
+ m_copyrightsReply->deleteLater();
+}
+
+void QGeoTileFetcherNokia::versionFetched()
+{
+ if (m_engineNokia && m_versionReply->error() == QNetworkReply::NoError) {
+ QMetaObject::invokeMethod(m_engineNokia.data(),
+ "parseNewVersionInfo",
+ Qt::QueuedConnection,
+ Q_ARG(QByteArray, m_versionReply->readAll()));
+ }
+
+ m_versionReply->deleteLater();
}
void QGeoTileFetcherNokia::fetchCopyrightsData()
{
- QString copyrightUrl = "http://";
+ QString copyrightUrl = QStringLiteral("http://");
copyrightUrl += m_baseUriProvider->getCurrentHost();
- copyrightUrl += "/maptile/2.1/copyright/newest?output=json";
+ copyrightUrl += QStringLiteral("/maptile/2.1/copyright/newest?output=json");
if (!token().isEmpty()) {
- copyrightUrl += "&token=";
+ copyrightUrl += QStringLiteral("&token=");
copyrightUrl += token();
}
if (!applicationId().isEmpty()) {
- copyrightUrl += "&app_id=";
+ copyrightUrl += QStringLiteral("&app_id=");
copyrightUrl += applicationId();
}
@@ -286,4 +300,36 @@ void QGeoTileFetcherNokia::fetchCopyrightsData()
}
}
+void QGeoTileFetcherNokia::fetchVersionData()
+{
+ QString versionUrl = QStringLiteral("http://");
+
+ versionUrl += m_baseUriProvider->getCurrentHost();
+ versionUrl += QStringLiteral("/maptile/2.1/version");
+
+ if (!token().isEmpty()) {
+ versionUrl += QStringLiteral("?token=");
+ versionUrl += token();
+ }
+
+ if (!applicationId().isEmpty()) {
+ versionUrl += QStringLiteral("&app_id=");
+ versionUrl += applicationId();
+ }
+
+ QNetworkRequest netRequest((QUrl(versionUrl)));
+ m_versionReply = m_networkManager->get(netRequest);
+
+ if (m_versionReply->error() != QNetworkReply::NoError) {
+ qWarning() << __FUNCTION__ << m_versionReply->errorString();
+ m_versionReply->deleteLater();
+ return;
+ }
+
+ if (m_versionReply->isFinished())
+ versionFetched();
+ else
+ connect(m_versionReply, SIGNAL(finished()), this, SLOT(versionFetched()));
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
index a5e1801a..8d5fea45 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
@@ -80,6 +80,8 @@ public:
public Q_SLOTS:
void copyrightsFetched();
void fetchCopyrightsData();
+ void versionFetched();
+ void fetchVersionData();
private:
Q_DISABLE_COPY(QGeoTileFetcherNokia)
@@ -93,6 +95,7 @@ private:
QSize m_tileSize;
QString m_token;
QNetworkReply *m_copyrightsReply;
+ QNetworkReply *m_versionReply;
QString m_applicationId;
QGeoUriProvider *m_baseUriProvider;