summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices/nokia
diff options
context:
space:
mode:
authorvladimirb <vladimir.bezkorovainyi@nokia.com>2012-05-02 16:10:01 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-04 02:48:14 +0200
commit231a5cde040907fd690d3d94d2e43fafc130f8cc (patch)
treee935aeb7f6fddf22b192781dcc30795dd3f28d5f /src/plugins/geoservices/nokia
parent523ebec5dca356e7ddf24792d9f6d2994a57599a (diff)
downloadqtlocation-231a5cde040907fd690d3d94d2e43fafc130f8cc.tar.gz
Refactore network access manager for mock purposes
Change-Id: I230171ac85ac53f79aef8b58ee2cb24253789f34 Reviewed-by: Cristian Adam <cristian.adam@nokia.com> Reviewed-by: Alex Wilson <alex.wilson@nokia.com>
Diffstat (limited to 'src/plugins/geoservices/nokia')
-rw-r--r--src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.cpp16
-rw-r--r--src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.h9
-rw-r--r--src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp100
-rw-r--r--src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h2
4 files changed, 50 insertions, 77 deletions
diff --git a/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.cpp b/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.cpp
index 4f5d4810..118a2d24 100644
--- a/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.cpp
+++ b/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.cpp
@@ -46,12 +46,21 @@
#include <QNetworkProxy>
#include <QNetworkAccessManager>
+QT_BEGIN_NAMESPACE
+
QGeoIntrinsicNetworkAccessManager::QGeoIntrinsicNetworkAccessManager(QObject *parent)
: QGeoNetworkAccessManager(parent)
, m_networkManager(new QNetworkAccessManager(this))
{
}
+QGeoIntrinsicNetworkAccessManager::QGeoIntrinsicNetworkAccessManager(const QMap<QString, QVariant> &parameters, const QString &token, QObject *parent)
+: QGeoNetworkAccessManager(parent)
+, m_customProxyToken(token)
+, m_networkManager(new QNetworkAccessManager(this))
+{
+ configure(parameters);
+}
void QGeoIntrinsicNetworkAccessManager::configure(const QMap<QString, QVariant> &parameters)
{
@@ -80,12 +89,6 @@ void QGeoIntrinsicNetworkAccessManager::configure(const QMap<QString, QVariant>
}
}
-
-void QGeoIntrinsicNetworkAccessManager::setCustomProxyToken(const QString& token)
-{
- m_customProxyToken = token;
-}
-
QNetworkReply* QGeoIntrinsicNetworkAccessManager::get(const QNetworkRequest& request)
{
return m_networkManager->get(request);
@@ -95,3 +98,4 @@ QNetworkReply *QGeoIntrinsicNetworkAccessManager::post(const QNetworkRequest &re
{
return m_networkManager->post(request, data);
}
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.h b/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.h
index 7e99182e..c1b85c9d 100644
--- a/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.h
+++ b/src/plugins/geoservices/nokia/qgeointrinsicnetworkaccessmanager.h
@@ -54,12 +54,15 @@ class QGeoIntrinsicNetworkAccessManager : public QGeoNetworkAccessManager
{
public:
explicit QGeoIntrinsicNetworkAccessManager(QObject *parent = 0);
- void configure(const QMap<QString, QVariant> &parameters);
- void setCustomProxyToken(const QString& token);
+ QGeoIntrinsicNetworkAccessManager(const QMap<QString, QVariant> &parameters, const QString &token = QString(), QObject *parent = 0);
+
virtual QNetworkReply* get(const QNetworkRequest& request);
virtual QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data);
+
private:
- QString m_customProxyToken;
+ void configure(const QMap<QString, QVariant> &parameters);
+
+ const QString m_customProxyToken;
QNetworkAccessManager* m_networkManager;
};
diff --git a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
index d061e118..1f567906 100644
--- a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
@@ -60,6 +60,28 @@
QT_BEGIN_NAMESPACE
+static bool isValidParameter(const QString &param)
+{
+ if (param.isEmpty())
+ return false;
+
+ if (param.length() > 512)
+ return false;
+
+ foreach (QChar c, param) {
+ if (!c.isLetterOrNumber() && c.toAscii() != '%' && c.toAscii() != '-' &&
+ c.toAscii() != '+' && c.toAscii() != '_') {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static QGeoNetworkAccessManager *tryGetNetworkAccessManager(const QVariantMap &parameters)
+{
+ return static_cast<QGeoNetworkAccessManager*>(qvariant_cast<void*>(parameters.value(QStringLiteral("nam"))));
+}
QGeoServiceProviderFactoryNokia::QGeoServiceProviderFactoryNokia()
: m_informedAboutUsageTerms(false)
@@ -74,15 +96,9 @@ QGeocodingManagerEngine* QGeoServiceProviderFactoryNokia::createGeocodingManager
{
informOnceAboutUsageTermsIfNecessary(parameters);
- QGeoNetworkAccessManager* networkManager = 0;
-
- if (!tryGetNetworkAccessManager(networkManager, parameters))
- {
- QGeoIntrinsicNetworkAccessManager* intrinsicNetworkManager = new QGeoIntrinsicNetworkAccessManager();
- intrinsicNetworkManager->configure(parameters);
-
- networkManager = intrinsicNetworkManager;
- }
+ QGeoNetworkAccessManager* networkManager = tryGetNetworkAccessManager(parameters);
+ if (!networkManager)
+ networkManager = new QGeoIntrinsicNetworkAccessManager(parameters);
return new QGeocodingManagerEngineNokia(networkManager, parameters, error, errorString);
}
@@ -94,16 +110,9 @@ QGeoMappingManagerEngine* QGeoServiceProviderFactoryNokia::createMappingManagerE
{
informOnceAboutUsageTermsIfNecessary(parameters);
- QGeoNetworkAccessManager* networkManager = 0;
-
- if (!tryGetNetworkAccessManager(networkManager, parameters))
- {
- QGeoIntrinsicNetworkAccessManager* intrinsicNetworkManager = new QGeoIntrinsicNetworkAccessManager();
- intrinsicNetworkManager->setCustomProxyToken(QStringLiteral("mapping.proxy"));
- intrinsicNetworkManager->configure(parameters);
-
- networkManager = intrinsicNetworkManager;
- }
+ QGeoNetworkAccessManager* networkManager = tryGetNetworkAccessManager(parameters);
+ if (!networkManager)
+ networkManager = new QGeoIntrinsicNetworkAccessManager(parameters, QStringLiteral("mapping.proxy"));
return new QGeoTiledMappingManagerEngineNokia(networkManager, parameters, error, errorString);
}
@@ -115,16 +124,9 @@ QGeoRoutingManagerEngine* QGeoServiceProviderFactoryNokia::createRoutingManagerE
{
informOnceAboutUsageTermsIfNecessary(parameters);
- QGeoNetworkAccessManager* networkManager = 0;
-
- if (!tryGetNetworkAccessManager(networkManager, parameters))
- {
- QGeoIntrinsicNetworkAccessManager* intrinsicNetworkManager = new QGeoIntrinsicNetworkAccessManager();
- intrinsicNetworkManager->setCustomProxyToken(QStringLiteral("routing.proxy"));
- intrinsicNetworkManager->configure(parameters);
-
- networkManager = intrinsicNetworkManager;
- }
+ QGeoNetworkAccessManager* networkManager = tryGetNetworkAccessManager(parameters);
+ if (!networkManager)
+ networkManager = new QGeoIntrinsicNetworkAccessManager(parameters, QStringLiteral("routing.proxy"));
return new QGeoRoutingManagerEngineNokia(networkManager, parameters, error, errorString);
}
@@ -136,16 +138,9 @@ QPlaceManagerEngine *QGeoServiceProviderFactoryNokia::createPlaceManagerEngine(
{
informOnceAboutUsageTermsIfNecessary(parameters);
- QGeoNetworkAccessManager* networkManager = 0;
-
- if (!tryGetNetworkAccessManager(networkManager, parameters))
- {
- QGeoIntrinsicNetworkAccessManager* intrinsicNetworkManager = new QGeoIntrinsicNetworkAccessManager();
- intrinsicNetworkManager->setCustomProxyToken(QStringLiteral("places.proxy"));
- intrinsicNetworkManager->configure(parameters);
-
- networkManager = intrinsicNetworkManager;
- }
+ QGeoNetworkAccessManager* networkManager = tryGetNetworkAccessManager(parameters);
+ if (!networkManager)
+ networkManager = new QGeoIntrinsicNetworkAccessManager(parameters, QStringLiteral("places.proxy"));
switch (parameters.value(QLatin1String("places.api_version"), 2).toUInt()) {
case 1:
@@ -175,33 +170,6 @@ void QGeoServiceProviderFactoryNokia::informOnceAboutUsageTermsIfNecessary(
}
}
-bool QGeoServiceProviderFactoryNokia::isValidParameter(const QString &param)
-{
- if (param.isEmpty())
- return false;
-
- if (param.length() > 512)
- return false;
-
- foreach (QChar c, param) {
- if (!c.isLetterOrNumber() && c.toAscii() != '%' && c.toAscii() != '-' &&
- c.toAscii() != '+' && c.toAscii() != '_') {
- return false;
- }
- }
-
- return true;
-}
-
-bool QGeoServiceProviderFactoryNokia::tryGetNetworkAccessManager(
- QGeoNetworkAccessManager*& networkManager,
- const QVariantMap &parameters)
-{
- networkManager = static_cast<QGeoNetworkAccessManager*>(qvariant_cast<void*>(parameters.value(QStringLiteral("nam"))));
-
- return networkManager != 0;
-}
-
const QString QGeoServiceProviderFactoryNokia::defaultToken("152022572f0e44e07489c35cd46fa246");
const QString QGeoServiceProviderFactoryNokia::defaultReferer("qtlocationapi");
diff --git a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h
index 29f77781..ed9ad35c 100644
--- a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h
@@ -85,8 +85,6 @@ public:
private:
void informOnceAboutUsageTermsIfNecessary(const QVariantMap &parameters) const;
- static bool isValidParameter(const QString &param);
- static bool tryGetNetworkAccessManager(QGeoNetworkAccessManager*&, const QVariantMap &parameters);
private:
mutable bool m_informedAboutUsageTerms;