summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvladimirb <vladimir.bezkorovainyi@nokia.com>2012-05-07 18:18:41 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-16 04:06:15 +0200
commit9c68d7c658bc1901efa7b2e43a4a8be61a313c40 (patch)
treebe5b93df166ad469ddf4bb50b50aa644aef76eac /src
parent89e01acaae12f1e3dedcd51478f49d0fc4b340e8 (diff)
downloadqtlocation-9c68d7c658bc1901efa7b2e43a4a8be61a313c40.tar.gz
China shifting support for dual sim
Change-Id: I278bad0a8b167a3a40c8e737622a83683e966e64 Reviewed-by: Alex Wilson <alex.wilson@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/geoservices/nokia/nokia.pro10
-rw-r--r--src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp16
-rw-r--r--src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h5
-rw-r--r--src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp15
-rw-r--r--src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.h3
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp4
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp185
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h44
-rw-r--r--src/plugins/geoservices/nokia/qgeouriprovider.cpp146
-rw-r--r--src/plugins/geoservices/nokia/qgeouriprovider.h90
-rw-r--r--src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp55
-rw-r--r--src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h11
-rw-r--r--src/plugins/geoservices/nokia/uri_constants.cpp60
-rw-r--r--src/plugins/geoservices/nokia/uri_constants.h66
14 files changed, 465 insertions, 245 deletions
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro
index a5b7b6d1..892d3392 100644
--- a/src/plugins/geoservices/nokia/nokia.pro
+++ b/src/plugins/geoservices/nokia/nokia.pro
@@ -5,8 +5,8 @@ QT += location network
contains(QT_CONFIG, location-china-support) {
# China support
- QT += systeminfo
DEFINES += USE_CHINA_NETWORK_REGISTRATION
+ QT += systeminfo
}
load(qt_plugin)
@@ -28,7 +28,9 @@ HEADERS += \
qgeoserviceproviderplugin_nokia.h \
marclanguagecodes.h \
qgeonetworkaccessmanager.h \
- qgeointrinsicnetworkaccessmanager.h
+ qgeointrinsicnetworkaccessmanager.h \
+ qgeouriprovider.h \
+ uri_constants.h
SOURCES += \
@@ -43,7 +45,9 @@ SOURCES += \
qgeoroutexmlparser.cpp \
qgeoroutingmanagerengine_nokia.cpp \
qgeoserviceproviderplugin_nokia.cpp \
- qgeointrinsicnetworkaccessmanager.cpp
+ qgeointrinsicnetworkaccessmanager.cpp \
+ qgeouriprovider.cpp \
+ uri_constants.cpp
include(placesv1/placesv1.pri)
include(placesv2/placesv2.pri)
diff --git a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
index c37cadf9..be2b63f7 100644
--- a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.cpp
@@ -50,6 +50,8 @@
#include "qgeocodereply_nokia.h"
#include "marclanguagecodes.h"
#include "qgeonetworkaccessmanager.h"
+#include "qgeouriprovider.h"
+#include "uri_constants.h"
#include <qgeoaddress.h>
#include <qgeocoordinate.h>
@@ -66,17 +68,11 @@ QGeocodingManagerEngineNokia::QGeocodingManagerEngineNokia(
QString *errorString)
: QGeocodingManagerEngine(parameters)
, m_networkManager(networkManager)
- , m_host("loc.desktop.maps.svc.ovi.com")
+ , m_uriProvider(new QGeoUriProvider(this, parameters, "geocoding.host", GEOCODING_HOST, GEOCODING_HOST_CN))
{
Q_ASSERT(networkManager);
m_networkManager->setParent(this);
- if (parameters.contains("geocoding.host")) {
- QString host = parameters.value("geocoding.host").toString();
- if (!host.isEmpty())
- m_host = host;
- }
-
if (parameters.contains("token")) {
m_token = parameters.value("token").toString();
}
@@ -120,7 +116,7 @@ QGeocodeReply *QGeocodingManagerEngineNokia::geocode(const QGeoAddress &address,
const QGeoBoundingArea &bounds)
{
QString requestString = "http://";
- requestString += m_host;
+ requestString += m_uriProvider->getCurrentHost();
requestString += "/geocoder/gc/2.0";
requestString += getAuthenticationString();
@@ -189,7 +185,7 @@ QGeocodeReply *QGeocodingManagerEngineNokia::reverseGeocode(const QGeoCoordinate
const QGeoBoundingArea &bounds)
{
QString requestString = "http://";
- requestString += m_host;
+ requestString += m_uriProvider->getCurrentHost();
requestString += "/geocoder/rgc/2.0";
requestString += getAuthenticationString();
@@ -211,7 +207,7 @@ QGeocodeReply *QGeocodingManagerEngineNokia::geocode(const QString &address,
const QGeoBoundingArea &bounds)
{
QString requestString = "http://";
- requestString += m_host;
+ requestString += m_uriProvider->getCurrentHost();
requestString += "/geocoder/gc/2.0";
requestString += getAuthenticationString();
diff --git a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
index d021191d..1100e835 100644
--- a/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeocodingmanagerengine_nokia.h
@@ -54,13 +54,12 @@
#include <qgeoserviceprovider.h>
#include <qgeocodingmanagerengine.h>
-
#include <QLocale>
-
QT_BEGIN_NAMESPACE
class QGeoNetworkAccessManager;
+class QGeoUriProvider;
class QGeocodingManagerEngineNokia : public QGeocodingManagerEngine
{
@@ -93,9 +92,9 @@ private:
QString getAuthenticationString() const;
QGeoNetworkAccessManager *m_networkManager;
- QString m_host;
QString m_token;
QString m_applicationId;
+ QGeoUriProvider *m_uriProvider;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp
index f4295f57..f8a92932 100644
--- a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.cpp
@@ -49,6 +49,8 @@
#include "qgeoroutingmanagerengine_nokia.h"
#include "qgeoroutereply_nokia.h"
#include "qgeonetworkaccessmanager.h"
+#include "qgeouriprovider.h"
+#include "uri_constants.h"
#include <QStringList>
#include <QUrl>
@@ -64,19 +66,12 @@ QGeoRoutingManagerEngineNokia::QGeoRoutingManagerEngineNokia(
QString *errorString)
: QGeoRoutingManagerEngine(parameters)
, m_networkManager(networkManager)
- , m_host(QStringLiteral("route.nlp.nokia.com"))
+ , m_uriProvider(new QGeoUriProvider(this, parameters, "routing.host", ROUTING_HOST))
{
Q_ASSERT(networkManager);
m_networkManager->setParent(this);
- if (parameters.contains(QStringLiteral("routing.host"))) {
- QString host = parameters.value(QStringLiteral("routing.host")).toString();
- if (!host.isEmpty())
- m_host = host;
- }
-
-
m_appId = parameters.value(QStringLiteral("app_id")).toString();
m_token = parameters.value(QStringLiteral("token")).toString();
@@ -230,7 +225,7 @@ QString QGeoRoutingManagerEngineNokia::calculateRouteRequestString(const QGeoRou
return QString();
QString requestString = QStringLiteral("http://");
- requestString += m_host;
+ requestString += m_uriProvider->getCurrentHost();
requestString += QStringLiteral("/routing/6.2/calculateroute.xml");
requestString += QStringLiteral("?alternatives=");
@@ -268,7 +263,7 @@ QString QGeoRoutingManagerEngineNokia::updateRouteRequestString(const QGeoRoute
return "";
QString requestString = "http://";
- requestString += m_host;
+ requestString += m_uriProvider->getCurrentHost();
requestString += "/routing/6.2/getroute.xml";
requestString += "?routeid=";
diff --git a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.h
index f5bb9541..a775dd12 100644
--- a/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeoroutingmanagerengine_nokia.h
@@ -57,6 +57,7 @@
QT_BEGIN_NAMESPACE
class QGeoNetworkAccessManager;
+class QGeoUriProvider;
class QGeoRoutingManagerEngineNokia : public QGeoRoutingManagerEngine
{
@@ -86,7 +87,7 @@ private:
static QString trimDouble(double degree, int decimalDigits = 10);
QGeoNetworkAccessManager *m_networkManager;
- QString m_host;
+ QGeoUriProvider *m_uriProvider;
QString m_appId;
QString m_token;
};
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
index 15c67ded..1e46796f 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -98,9 +98,7 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(
types << QGeoMapType(QGeoMapType::GrayStreetMap,tr("Mobile Gray Street Map"),tr("Nokia Mobile Gray Street Map"), true, 11);
setSupportedMapTypes(types);
- QGeoTileFetcherNokia *fetcher = new QGeoTileFetcherNokia(networkManager, this);
- fetcher->setParams(parameters);
- fetcher->setTileSize(tileSize());
+ QGeoTileFetcherNokia *fetcher = new QGeoTileFetcherNokia(parameters, networkManager, this, tileSize());
setTileFetcher(fetcher);
// TODO: do this in a plugin-neutral way so that other tiled map plugins
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
index c33000c3..3a77f215 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
@@ -51,6 +51,8 @@
#include "qgeotiledmapdata_nokia.h"
#include "qgeotiledmappingmanagerengine_nokia.h"
#include "qgeonetworkaccessmanager.h"
+#include "qgeouriprovider.h"
+#include "uri_constants.h"
#include <qgeotilespec.h>
@@ -66,17 +68,59 @@
QT_BEGIN_NAMESPACE
-const char *MAPTILES_HOST = "1-4.maptile.lbs.ovi.com";
-const char *MAPTILES_HOST_CN = "a-k.maptile.maps.svc.nokia.com.cn";
+namespace
+{
+ QString sizeToStr(const QSize &size)
+ {
+ static const QString s256("256");
+ static const QString s128("128");
+ if (size.height() >= LARGE_TILE_DIMENSION ||
+ size.width() >= LARGE_TILE_DIMENSION)
+ return s256;
+ else
+ return s128;
+ }
-QGeoTileFetcherNokia::QGeoTileFetcherNokia(QGeoNetworkAccessManager *networkManager,
- QGeoTiledMappingManagerEngine *engine)
+ QString mapIdToStr(int mapId)
+ {
+ typedef std::map<int, QString> MapTypeRegistry;
+ static MapTypeRegistry registeredTypes;
+ if (registeredTypes.empty()) {
+ registeredTypes[0] = "normal.day";
+ registeredTypes[1] = "normal.day";
+ registeredTypes[2] = "satellite.day";
+ registeredTypes[3] = "terrain.day";
+ registeredTypes[4] = "hybrid.day";
+ registeredTypes[5] = "normal.day.transit";
+ registeredTypes[6] = "normal.day.grey";
+ registeredTypes[7] = "normal.day.mobile";
+ registeredTypes[8] = "terrain.day.mobile";
+ registeredTypes[9] = "hybrid.day.mobile";
+ registeredTypes[10] = "normal.day.transit.mobile";
+ registeredTypes[11] = "normal.day.grey.mobile";
+ }
+
+ MapTypeRegistry::const_iterator it = registeredTypes.find(mapId);
+ if (it != registeredTypes.end()) {
+ return it->second;
+ }
+
+ qWarning() << "Unknown mapId: " << mapId;
+ return "normal.day";
+ }
+}
+QGeoTileFetcherNokia::QGeoTileFetcherNokia(
+ const QMap<QString, QVariant> &parameters,
+ QGeoNetworkAccessManager *networkManager,
+ QGeoTiledMappingManagerEngine *engine,
+ const QSize &tileSize)
: QGeoTileFetcher(engine),
m_engineNokia(static_cast<QGeoTiledMappingManagerEngineNokia *>(engine)),
m_networkManager(networkManager),
- m_firstSubdomain(QChar::Null),
+ m_parameters(parameters),
+ m_tileSize(tileSize),
m_copyrightsReply(0),
- m_maxSubdomains(0)
+ m_uriProvider(new QGeoUriProvider(this, parameters, "mapping.host", MAP_TILES_HOST, MAP_TILES_HOST_CN))
{
Q_ASSERT(networkManager);
m_networkManager->setParent(this);
@@ -86,16 +130,8 @@ QGeoTileFetcherNokia::~QGeoTileFetcherNokia() {}
bool QGeoTileFetcherNokia::init()
{
- setHost(MAPTILES_HOST);
-
qsrand((uint)QTime::currentTime().msec());
- if (m_parameters.contains("mapping.host")) {
- QString host = m_parameters.value("mapping.host").toString();
- if (!host.isEmpty())
- setHost(host);
- }
-
if (m_parameters.contains("app_id")) {
m_applicationId = m_parameters.value("app_id").toString();
}
@@ -103,20 +139,6 @@ bool QGeoTileFetcherNokia::init()
if (m_parameters.contains("token")) {
m_token = m_parameters.value("token").toString();
}
-
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- connect(&m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int, const QString&)),
- SLOT(currentMobileCountryCodeChanged(int, const QString&)));
- currentMobileCountryCodeChanged(0, m_networkInfo.currentMobileCountryCode(0));
-#endif
-
- // Temporary testing aid for setting China maptile server
- QFile file("/.enable_china_maptile_server");
- if (file.exists()) {
- qDebug() << "CHINA MAPTILE SERVER SET FOR TESTING PURPOSES.";
- setHost(MAPTILES_HOST_CN);
- }
-
return true;
}
@@ -137,19 +159,13 @@ QGeoTiledMapReply *QGeoTileFetcherNokia::getTileImage(const QGeoTileSpec &spec)
QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec)
{
- const char subdomain = m_maxSubdomains ? m_firstSubdomain.toLatin1() +
- qrand() % m_maxSubdomains : 0;
static const QString http("http://");
static const QString path("/maptiler/v2/maptile/newest/");
- static const QChar dot('.');
static const QChar slash('/');
QString requestString = http;
- if (subdomain != 0) {
- requestString += subdomain;
- requestString += dot;
- }
- requestString += m_host;
+
+ requestString += m_uriProvider->getCurrentHost();
requestString += path;
requestString += mapIdToStr(spec.mapId());
@@ -180,102 +196,15 @@ QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec)
return requestString;
}
-QString QGeoTileFetcherNokia::sizeToStr(const QSize &size)
-{
- static const QString s256("256");
- static const QString s128("128");
- if (size.height() >= LARGE_TILE_DIMENSION ||
- size.width() >= LARGE_TILE_DIMENSION)
- return s256;
- else
- return s128;
-}
-
-QString QGeoTileFetcherNokia::mapIdToStr(int mapId)
-{
- typedef std::map<int, QString> MapTypeRegistry;
- static MapTypeRegistry registeredTypes;
- if (registeredTypes.empty()) {
- registeredTypes[0] = "normal.day";
- registeredTypes[1] = "normal.day";
- registeredTypes[2] = "satellite.day";
- registeredTypes[3] = "terrain.day";
- registeredTypes[4] = "hybrid.day";
- registeredTypes[5] = "normal.day.transit";
- registeredTypes[6] = "normal.day.grey";
- registeredTypes[7] = "normal.day.mobile";
- registeredTypes[8] = "terrain.day.mobile";
- registeredTypes[9] = "hybrid.day.mobile";
- registeredTypes[10] = "normal.day.transit.mobile";
- registeredTypes[11] = "normal.day.grey.mobile";
- }
-
- MapTypeRegistry::const_iterator it = registeredTypes.find(mapId);
- if (it != registeredTypes.end()) {
- return it->second;
- }
-
- qWarning() << "Unknown mapId: " << mapId;
- return "normal.day";
-}
-
-void QGeoTileFetcherNokia::setParams(const QMap<QString, QVariant> &parameters)
-{
- m_parameters = parameters;
-}
-
-void QGeoTileFetcherNokia::setTileSize(QSize tileSize)
-{
- m_tileSize = tileSize;
-}
-
-const QString & QGeoTileFetcherNokia::token() const
+QString QGeoTileFetcherNokia::token() const
{
return m_token;
}
-const QString & QGeoTileFetcherNokia::host() const
-{
- return m_host;
-}
-
-const QString & QGeoTileFetcherNokia::applicationId() const
+QString QGeoTileFetcherNokia::applicationId() const
{
return m_applicationId;
}
-QChar QGeoTileFetcherNokia::firstSubdomain() const
-{
- return m_firstSubdomain;
-}
-
-unsigned char QGeoTileFetcherNokia::maxSubdomains() const
-{
- return m_maxSubdomains;
-}
-
-void QGeoTileFetcherNokia::setHost(const QString &host)
-{
- if (host.length() > 4 && host.at(1) == QChar('-') && host.at(3) == QChar('.')) {
- QString realHost = host.right(host.length() - 4);
- m_firstSubdomain = host.at(0);
- m_maxSubdomains = host.at(2).toLatin1() - host.at(0).toLatin1() + 1;
- m_host = realHost;
- } else {
- m_host = host;
- m_firstSubdomain = QChar::Null;
- m_maxSubdomains = 0;
- }
-}
-
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-void QGeoTileFetcherNokia::currentMobileCountryCodeChanged(int interface, const QString & mcc)
-{
- Q_UNUSED(interface)
- if (mcc == "460" || mcc == "461" || mcc == "454" || mcc == "455") {
- setHost(MAPTILES_HOST_CN);
- }
-}
-#endif
void QGeoTileFetcherNokia::copyrightsFetched()
{
@@ -288,12 +217,8 @@ void QGeoTileFetcherNokia::copyrightsFetched()
void QGeoTileFetcherNokia::fetchCopyrightsData()
{
QString copyrightUrl = "http://";
- if (!firstSubdomain().isNull()) {
- copyrightUrl += firstSubdomain();
- copyrightUrl += ".";
- }
- copyrightUrl += host();
+ copyrightUrl += m_uriProvider->getCurrentHost();
copyrightUrl += "/maptiler/v2/copyright/newest?output=json";
if (!token().isEmpty()) {
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
index 6a51e8de..81c8b269 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
@@ -50,16 +50,8 @@
#define QGEOTILEFETCHER_NOKIA_H
#include "qgeoserviceproviderplugin_nokia.h"
-
-#include <QGeoServiceProvider>
#include "qgeotilefetcher.h"
-#include <QMap>
-
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-#include <qnetworkinfo.h>
-#endif
-
QT_BEGIN_NAMESPACE
class QGeoTiledMapReply;
@@ -68,62 +60,46 @@ class QGeoTiledMappingManagerEngine;
class QGeoTiledMappingManagerEngineNokia;
class QNetworkReply;
class QGeoNetworkAccessManager;
+class QGeoUriProvider;
class QGeoTileFetcherNokia : public QGeoTileFetcher
{
Q_OBJECT
public:
- QGeoTileFetcherNokia(QGeoNetworkAccessManager *networkManager, QGeoTiledMappingManagerEngine *engine);
+ QGeoTileFetcherNokia(
+ const QMap<QString, QVariant> &parameters,
+ QGeoNetworkAccessManager *networkManager,
+ QGeoTiledMappingManagerEngine *engine,
+ const QSize &tileSize);
+
~QGeoTileFetcherNokia();
bool init();
QGeoTiledMapReply *getTileImage(const QGeoTileSpec &spec);
- const QString &host() const;
- QChar firstSubdomain() const;
- unsigned char maxSubdomains() const;
- const QString &token() const;
- const QString &applicationId() const;
-
- void setParams(const QMap<QString, QVariant> &parameters);
- void setTileSize(QSize tileSize);
+ QString token() const;
+ QString applicationId() const;
public Q_SLOTS:
void copyrightsFetched();
void fetchCopyrightsData();
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-private Q_SLOTS:
- void currentMobileCountryCodeChanged(int interface, const QString &mcc);
-#endif
-
private:
Q_DISABLE_COPY(QGeoTileFetcherNokia)
QString getRequestString(const QGeoTileSpec &spec);
- static QString sizeToStr(const QSize &size);
- static QString mapIdToStr(int mapId);
-
- void setHost(const QString &host);
-
QGeoTiledMappingManagerEngineNokia *m_engineNokia;
QGeoNetworkAccessManager *m_networkManager;
QMap<QString, QVariant> m_parameters;
QSize m_tileSize;
- QString m_host;
QString m_token;
- QChar m_firstSubdomain;
QNetworkReply *m_copyrightsReply;
- unsigned char m_maxSubdomains;
QString m_applicationId;
-
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- QNetworkInfo m_networkInfo;
-#endif
+ QGeoUriProvider *m_uriProvider;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeouriprovider.cpp b/src/plugins/geoservices/nokia/qgeouriprovider.cpp
new file mode 100644
index 00000000..6aa43f36
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeouriprovider.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+#include "qgeouriprovider.h"
+
+#ifdef USE_CHINA_NETWORK_REGISTRATION
+#include <QNetworkInfo>
+#endif
+
+#include <QMap>
+#include <QVariant>
+#include <QSet>
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+
+namespace
+{
+ const QString CHINA_MCC = QStringLiteral("460"); // China mobile country code
+ const QString CHINA2_MCC = QStringLiteral("461"); // China mobile country code
+ const QString HONG_KONG_MCC = QStringLiteral("454"); // Hong Kong mobile country code
+ const QString MACAU_MCC = QStringLiteral("455"); // Macau mobile country code
+}
+
+QGeoUriProvider::QGeoUriProvider(
+ QObject *parent,
+ const QMap<QString, QVariant> & parameters,
+ const QString &hostParameterName,
+ const QString &internationalHost,
+ const QString &localizedHost)
+ : QObject(parent)
+#ifdef USE_CHINA_NETWORK_REGISTRATION
+ , m_networkInfo(new QNetworkInfo(this))
+#endif
+ , m_internationalHost(parameters.value(hostParameterName, internationalHost).toString())
+ , m_localizedHost(localizedHost)
+ , m_firstSubdomain(QChar::Null)
+ , m_maxSubdomains(0)
+{
+#ifdef USE_CHINA_NETWORK_REGISTRATION
+ QObject::connect(m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int, const QString&)), this, SLOT(mobileCountryCodeChanged(int, const QString &)));
+#endif
+ setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost);
+}
+
+QString QGeoUriProvider::getCurrentHost() const
+{
+ if (m_maxSubdomains) {
+ QString result(m_firstSubdomain.toAscii() + qrand() % m_maxSubdomains);
+ result += "." + m_currentHost;
+ return result;
+ }
+ return m_currentHost;
+}
+
+void QGeoUriProvider::setCurrentHost(const QString &host)
+{
+ if (host.length() > 4 && host.at(1) == QChar('-') && host.at(3) == QChar('.')) {
+ QString realHost = host.right(host.length() - 4);
+ m_firstSubdomain = host.at(0);
+ m_maxSubdomains = host.at(2).toAscii() - host.at(0).toAscii() + 1;
+ m_currentHost = realHost;
+ } else {
+ m_currentHost = host;
+ m_firstSubdomain = QChar::Null;
+ m_maxSubdomains = 0;
+ }
+}
+
+void QGeoUriProvider::mobileCountryCodeChanged(int interface, const QString& mcc)
+{
+ Q_UNUSED(interface)
+ Q_UNUSED(mcc)
+
+ setCurrentHost(isInternationalNetwork() || m_localizedHost.isEmpty() ? m_internationalHost : m_localizedHost);
+}
+
+bool QGeoUriProvider::isInternationalNetwork() const
+{
+#ifndef USE_CHINA_NETWORK_REGISTRATION
+ return true;
+#else
+ static QSet<QString> codes;
+ if (codes.empty()) {
+ codes.insert(CHINA_MCC);
+ codes.insert(CHINA2_MCC);
+ }
+
+ QNetworkInfo::NetworkMode mode = m_networkInfo->currentNetworkMode();
+
+ int interfaces = m_networkInfo->networkInterfaceCount(mode);
+ for (int i = 0; i < interfaces; ++i) {
+ QString mcc = m_networkInfo->currentMobileCountryCode(interfaces);
+ if (codes.contains(mcc))
+ return false;
+ }
+
+ return true;
+#endif // USE_CHINA_NETWORK_REGISTRATION
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeouriprovider.h b/src/plugins/geoservices/nokia/qgeouriprovider.h
new file mode 100644
index 00000000..b77927cd
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeouriprovider.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+#ifndef QGEO_MOBILE_COUNTRY_TRACKER_H
+#define QGEO_MOBILE_COUNTRY_TRACKER_H
+
+#include <QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkInfo;
+
+class QGeoUriProvider : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(QGeoUriProvider)
+
+public:
+ QGeoUriProvider(QObject *parent,
+ const QMap<QString, QVariant> & parameters,
+ const QString &hostParameterName,
+ const QString &internationalHost,
+ const QString &localizedHost = QString());
+
+ QString getCurrentHost() const;
+
+private Q_SLOTS:
+ void mobileCountryCodeChanged(int interface, const QString& mcc);
+
+private:
+ bool isInternationalNetwork() const;
+ void setCurrentHost(const QString &host);
+
+#ifdef USE_CHINA_NETWORK_REGISTRATION
+ QNetworkInfo *m_networkInfo;
+#endif
+ const QString m_internationalHost;
+ const QString m_localizedHost;
+ QString m_currentHost;
+ QChar m_firstSubdomain;
+ unsigned char m_maxSubdomains;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEO_MOBILE_COUNTRY_TRACKER_H
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
index 6a465441..f117ea1a 100644
--- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
+++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
@@ -56,6 +56,8 @@
#include "placesv2/qplacedetailsreplyimpl.h"
#include "placesv2/qplaceidreplyimpl.h"
#include "qgeonetworkaccessmanager.h"
+#include "qgeouriprovider.h"
+#include "uri_constants.h"
#include <QtCore/QFile>
#include <QtCore/QJsonDocument>
@@ -64,9 +66,7 @@
#include <QtCore/QUrlQuery>
#include <QtNetwork/QNetworkProxy>
#include <QtNetwork/QNetworkProxyFactory>
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-#include <QtSystemInfo/QNetworkInfo>
-#endif
+
#include <QtLocation/QPlaceContentRequest>
#include <QtLocation/QGeoBoundingCircle>
@@ -89,38 +89,23 @@ static const int FIXED_CATEGORIES_indices[] = {
115, -1
};
-static const char * const placesServerInternational = "http://api.places.lbs.maps.nokia.com/places";
-static const char * const placesServerChina = "http://api.places.lbs.maps.nokia.com.cn/places";
-
QPlaceManagerEngineNokiaV2::QPlaceManagerEngineNokiaV2(
QGeoNetworkAccessManager *networkManager,
const QMap<QString, QVariant> &parameters,
QGeoServiceProvider::Error *error,
QString *errorString)
-: QPlaceManagerEngine(parameters), m_manager(networkManager)
+ : QPlaceManagerEngine(parameters)
+ , m_manager(networkManager)
+ , m_uriProvider(new QGeoUriProvider(this, parameters, "places.host", PLACES_HOST, PLACES_HOST_CN))
{
Q_ASSERT(networkManager);
m_manager->setParent(this);
m_locales.append(QLocale());
- // Unless specified in the plugin parameters set the international places server to the builtin
- // one. This is the server used when not in China.
- m_host = parameters.value(QLatin1String("places.host"),
- QLatin1String(placesServerInternational)).toString();
-
m_appId = parameters.value(QLatin1String("app_id")).toString();
m_appCode = parameters.value(QLatin1String("token")).toString();
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- m_networkInfo = new QNetworkInfo(this);
- connect(m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int,QString)),
- this, SLOT(currentMobileCountryCodeChanged(int,QString)));
- currentMobileCountryCodeChanged(0, m_networkInfo->currentMobileCountryCode(0));
-#else
- m_placesServer = m_host;
-#endif
-
m_theme = parameters.value("places.theme", QString()).toString();
if (m_theme == QLatin1String("default"))
@@ -147,7 +132,7 @@ QPlaceManagerEngineNokiaV2::~QPlaceManagerEngineNokiaV2() {}
QPlaceDetailsReply *QPlaceManagerEngineNokiaV2::getPlaceDetails(const QString &placeId)
{
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/places/") + placeId);
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/places/") + placeId);
QUrlQuery queryItems;
@@ -170,7 +155,7 @@ QPlaceDetailsReply *QPlaceManagerEngineNokiaV2::getPlaceDetails(const QString &p
QPlaceContentReply *QPlaceManagerEngineNokiaV2::getPlaceContent(const QString &placeId,
const QPlaceContentRequest &request)
{
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/places/") + placeId + QLatin1String("/media/"));
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/places/") + placeId + QLatin1String("/media/"));
QNetworkReply *networkReply = 0;
@@ -298,7 +283,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
if (!query.searchTerm().isEmpty()) {
// search term query
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/discover/search"));
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/discover/search"));
QUrlQuery queryItems;
@@ -328,7 +313,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
// The request URL should be "/v1/discover/explore" but that returns both places and
// clusters of places. We don't support clusters so we use the undocumented
// "/v1/discover/explore/places" instead which only returns places.
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/discover/explore/places"));
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/discover/explore/places"));
QUrlQuery queryItems;
@@ -369,7 +354,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
QPlaceSearchReply *QPlaceManagerEngineNokiaV2::recommendations(const QString &placeId, const QPlaceSearchRequest &query)
{
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/places/") + placeId + QLatin1String("/related/recommended"));
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/places/") + placeId + QLatin1String("/related/recommended"));
QUrlQuery queryItems;
@@ -398,7 +383,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::recommendations(const QString &pl
QPlaceSearchSuggestionReply *QPlaceManagerEngineNokiaV2::searchSuggestions(const QPlaceSearchRequest &query)
{
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/suggest"));
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/suggest"));
QUrlQuery queryItems;
@@ -481,7 +466,7 @@ QPlaceReply *QPlaceManagerEngineNokiaV2::initializeCategories()
const QString id = QString::fromLatin1(FIXED_CATEGORIES_string +
FIXED_CATEGORIES_indices[i]);
- QUrl requestUrl(m_placesServer + QLatin1String("/v1/categories/places/") + id);
+ QUrl requestUrl(m_uriProvider->getCurrentHost() + QLatin1String("/v1/categories/places/") + id);
QNetworkReply *networkReply = sendRequest(requestUrl);
connect(networkReply, SIGNAL(finished()), this, SLOT(categoryReplyFinished()));
connect(networkReply, SIGNAL(error(QNetworkReply::NetworkError)),
@@ -624,20 +609,6 @@ void QPlaceManagerEngineNokiaV2::categoryReplyError()
}
}
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-void QPlaceManagerEngineNokiaV2::currentMobileCountryCodeChanged(int interface, const QString &mcc)
-{
- Q_UNUSED(interface)
-
- if (mcc == QLatin1String("460") || mcc == QLatin1String("461") ||
- mcc == QLatin1String("454") || mcc == QLatin1String("455")) {
- m_placesServer = QLatin1String(placesServerChina);
- } else {
- m_placesServer = m_host;
- }
-}
-#endif
-
QNetworkReply *QPlaceManagerEngineNokiaV2::sendRequest(const QUrl &url)
{
QUrlQuery queryItems(url);
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
index 60539aa5..0513251d 100644
--- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
+++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
@@ -60,8 +60,8 @@ class QPlaceContentReply;
class QNetworkReply;
class QNetworkAccessManager;
class QPlaceCategoriesReplyImpl;
-class QNetworkInfo;
class QGeoNetworkAccessManager;
+class QGeoUriProvider;
struct PlaceCategoryNode
{
@@ -118,15 +118,10 @@ private Q_SLOTS:
void replyError(QPlaceReply::Error error_, const QString &errorString);
void categoryReplyFinished();
void categoryReplyError();
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- void currentMobileCountryCodeChanged(int interface, const QString &mcc);
-#endif
private:
QGeoNetworkAccessManager *m_manager;
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- QNetworkInfo *m_networkInfo;
-#endif
+ QGeoUriProvider *m_uriProvider;
QList<QLocale> m_locales;
@@ -137,9 +132,7 @@ private:
QString m_appId;
QString m_appCode;
- QString m_host;
- QString m_placesServer;
QString m_localDataPath;
QString m_theme;
};
diff --git a/src/plugins/geoservices/nokia/uri_constants.cpp b/src/plugins/geoservices/nokia/uri_constants.cpp
new file mode 100644
index 00000000..6aac12fe
--- /dev/null
+++ b/src/plugins/geoservices/nokia/uri_constants.cpp
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+#include "uri_constants.h"
+
+QT_BEGIN_NAMESPACE
+
+const QString ROUTING_HOST = QStringLiteral("route.nlp.nokia.com");
+const QString GEOCODING_HOST = QStringLiteral("loc.desktop.maps.svc.ovi.com");
+const QString GEOCODING_HOST_CN = QStringLiteral("pr.geo.maps.svc.nokia.com.cn");
+const QString PLACES_HOST = QStringLiteral("api.places.lbs.maps.nokia.com/places");
+const QString PLACES_HOST_CN = QStringLiteral("api.places.lbs.maps.nokia.com.cn/places");
+const QString MAP_TILES_HOST = QStringLiteral("1-4.maptile.lbs.ovi.com");
+const QString MAP_TILES_HOST_CN = QStringLiteral("a-k.maptile.maps.svc.nokia.com.cn");
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/uri_constants.h b/src/plugins/geoservices/nokia/uri_constants.h
new file mode 100644
index 00000000..2e3f41af
--- /dev/null
+++ b/src/plugins/geoservices/nokia/uri_constants.h
@@ -0,0 +1,66 @@
+
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+#ifndef URI_CONSTANTS_H
+#define URI_CONSTANTS_H
+
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+
+extern const QString ROUTING_HOST;
+extern const QString GEOCODING_HOST;
+extern const QString GEOCODING_HOST_CN;
+extern const QString PLACES_HOST;
+extern const QString PLACES_HOST_CN;
+extern const QString MAP_TILES_HOST;
+extern const QString MAP_TILES_HOST_CN;
+
+QT_END_NAMESPACE
+
+#endif // URI_CONSTANTS_H