summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices/nokia/placesv2
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-06-18 17:45:59 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-21 07:42:36 +0200
commit9e6adfbec01e164793cbd08684524547f31972e1 (patch)
tree966dc3903b4b548e3f7c1245e3aea36056a136aa /src/plugins/geoservices/nokia/placesv2
parent7343a401cd740a65d430fba4fa01abd7c601f4ef (diff)
downloadqtlocation-9e6adfbec01e164793cbd08684524547f31972e1.tar.gz
Refactor recommendations
Recommendations can be incorporated into ordinary searches. this is more convenient for the developer. Change-Id: Ifd3e040b6b7a964227981175b074ca4f52d7579c Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/plugins/geoservices/nokia/placesv2')
-rw-r--r--src/plugins/geoservices/nokia/placesv2/placesv2.pri2
-rw-r--r--src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.cpp180
-rw-r--r--src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.h82
-rw-r--r--src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp15
-rw-r--r--src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h3
5 files changed, 13 insertions, 269 deletions
diff --git a/src/plugins/geoservices/nokia/placesv2/placesv2.pri b/src/plugins/geoservices/nokia/placesv2/placesv2.pri
index 43835f65..73f3fcbd 100644
--- a/src/plugins/geoservices/nokia/placesv2/placesv2.pri
+++ b/src/plugins/geoservices/nokia/placesv2/placesv2.pri
@@ -6,7 +6,6 @@ HEADERS += \
placesv2/qplacecontentreplyimpl.h \
placesv2/qplacedetailsreplyimpl.h \
placesv2/qplaceidreplyimpl.h \
- placesv2/qplacerecommendationreplyimpl.h \
placesv2/qplacesearchreplyimpl.h \
placesv2/qplacesearchsuggestionreplyimpl.h \
placesv2/jsonparserhelpers.h
@@ -17,7 +16,6 @@ SOURCES += \
placesv2/qplacecontentreplyimpl.cpp \
placesv2/qplacedetailsreplyimpl.cpp \
placesv2/qplaceidreplyimpl.cpp \
- placesv2/qplacerecommendationreplyimpl.cpp \
placesv2/qplacesearchreplyimpl.cpp \
placesv2/qplacesearchsuggestionreplyimpl.cpp \
placesv2/jsonparserhelpers.cpp
diff --git a/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.cpp b/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.cpp
deleted file mode 100644
index 76ddba43..00000000
--- a/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** 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 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 "qplacerecommendationreplyimpl.h"
-#include "jsonparserhelpers.h"
-#include "../qplacemanagerengine_nokiav2.h"
-#include "../qgeoerror_messages.h"
-
-#include <QCoreApplication>
-#include <QtCore/QJsonDocument>
-#include <QtCore/QJsonObject>
-#include <QtCore/QJsonArray>
-#include <QtLocation/QPlaceIcon>
-#include <QtLocation/QPlaceResult>
-
-QT_BEGIN_NAMESPACE
-
-QPlaceRecommendationReplyImpl::QPlaceRecommendationReplyImpl(QNetworkReply *reply,
- QPlaceManagerEngineNokiaV2 *parent)
- : QPlaceSearchReply(parent), m_reply(reply), m_engine(parent)
-{
- Q_ASSERT(parent);
-
- if (!m_reply)
- return;
-
- m_reply->setParent(this);
- connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
- connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
- this, SLOT(replyError(QNetworkReply::NetworkError)));
-}
-
-QPlaceRecommendationReplyImpl::~QPlaceRecommendationReplyImpl()
-{
-}
-
-void QPlaceRecommendationReplyImpl::abort()
-{
- if (m_reply)
- m_reply->abort();
-}
-
-void QPlaceRecommendationReplyImpl::setError(QPlaceReply::Error error_, const QString &errorString)
-{
- QPlaceReply::setError(error_, errorString);
- emit error(error_, errorString);
- setFinished(true);
- emit finished();
-}
-
-void QPlaceRecommendationReplyImpl::replyFinished()
-{
- QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll());
- if (!document.isObject()) {
- setError(ParseError, QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, PARSE_ERROR));
- emit error(error(), errorString());
- return;
- }
-
- QJsonObject object = document.object();
-
- //const QUrl next = object.value(QLatin1String("next")).toString();
-
- QJsonArray items = object.value(QLatin1String("items")).toArray();
-
- QList<QPlaceSearchResult> results;
- for (int i = 0; i < items.count(); ++i) {
- QJsonObject item = items.at(i).toObject();
-
- QPlaceResult result;
-
- result.setDistance(item.value(QLatin1String("distance")).toDouble());
-
- QPlace place;
-
- QGeoLocation location;
-
- location.setCoordinate(parseCoordinate(item.value(QLatin1String("position")).toArray()));
-
- const QString vicinity = item.value(QLatin1String("vicinity")).toString();
- QGeoAddress address;
- address.setText(vicinity);
- location.setAddress(address);
-
- place.setLocation(location);
-
- QPlaceRatings ratings;
- ratings.setAverage(item.value(QLatin1String("averageRating")).toDouble());
- ratings.setMaximum(5.0);
- place.setRatings(ratings);
-
- const QString title = item.value(QLatin1String("title")).toString();
- place.setName(title);
- result.setTitle(title);
-
-
- place.setCategories(parseCategories(item.value(QLatin1String("categories")).toArray(),
- m_engine));
-
- QPlaceIcon icon = m_engine->icon(item.value(QLatin1String("icon")).toString(),
- place.categories());
- place.setIcon(icon);
- result.setIcon(icon);
-
- //QJsonArray having = item.value(QLatin1String("having")).toArray();
-
- QUrl href = item.value(QLatin1String("href")).toString();
- place.setPlaceId(href.path().mid(18, 41));
-
- result.setPlace(place);
-
- results.append(result);
- }
-
- setResults(results);
-
- m_reply->deleteLater();
- m_reply = 0;
-
- setFinished(true);
- emit finished();
-}
-
-void QPlaceRecommendationReplyImpl::replyError(QNetworkReply::NetworkError error)
-{
- switch (error) {
- case QNetworkReply::OperationCanceledError:
- setError(CancelError, "Request canceled.");
- break;
- default:
- setError(CommunicationError, "Network error.");
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.h b/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.h
deleted file mode 100644
index a7a407ef..00000000
--- a/src/plugins/geoservices/nokia/placesv2/qplacerecommendationreplyimpl.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** 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 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 QPLACERECOMMENDATIONREPLYIMPL_H
-#define QPLACERECOMMENDATIONREPLYIMPL_H
-
-#include <QtNetwork/QNetworkReply>
-#include <QtLocation/QPlaceSearchReply>
-
-QT_BEGIN_NAMESPACE
-
-class QPlaceManager;
-class QPlaceManagerEngineNokiaV2;
-
-class QPlaceRecommendationReplyImpl : public QPlaceSearchReply
-{
- Q_OBJECT
-
-public:
- QPlaceRecommendationReplyImpl(QNetworkReply *reply, QPlaceManagerEngineNokiaV2 *parent);
- ~QPlaceRecommendationReplyImpl();
-
- void abort();
-
-private slots:
- void setError(QPlaceReply::Error error_, const QString &errorString);
- void replyFinished();
- void replyError(QNetworkReply::NetworkError error);
-
-private:
- QNetworkReply *m_reply;
- QPlaceManagerEngineNokiaV2 *m_engine;
-};
-
-QT_END_NAMESPACE
-
-#endif // QPLACERECOMMENDATIONREPLYIMPL_H
diff --git a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp
index db97dffb..db42257a 100644
--- a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp
+++ b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.cpp
@@ -62,12 +62,15 @@
QT_BEGIN_NAMESPACE
-QPlaceSearchReplyImpl::QPlaceSearchReplyImpl(QNetworkReply *reply,
+QPlaceSearchReplyImpl::QPlaceSearchReplyImpl(const QPlaceSearchRequest &request,
+ QNetworkReply *reply,
QPlaceManagerEngineNokiaV2 *parent)
: QPlaceSearchReply(parent), m_reply(reply), m_engine(parent)
{
Q_ASSERT(parent);
+ setRequest(request);
+
if (!m_reply)
return;
@@ -106,9 +109,13 @@ void QPlaceSearchReplyImpl::replyFinished()
QJsonObject object = document.object();
//QJsonObject searchObject = object.value(QLatin1String("search")).toObject();
-
- QJsonObject resultsObject = object.value(QLatin1String("results")).toObject();
- QJsonArray items = resultsObject.value(QLatin1String("items")).toArray();
+ QJsonArray items;
+ if (request().recommendationId().isEmpty()) {
+ QJsonObject resultsObject = object.value(QLatin1String("results")).toObject();
+ items = resultsObject.value(QLatin1String("items")).toArray();
+ } else {
+ items = object.value(QLatin1String("items")).toArray();
+ }
QList<QPlaceSearchResult> results;
for (int i = 0; i < items.count(); ++i) {
diff --git a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h
index 2bdc1347..9fd076ec 100644
--- a/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h
+++ b/src/plugins/geoservices/nokia/placesv2/qplacesearchreplyimpl.h
@@ -61,7 +61,8 @@ class QPlaceSearchReplyImpl : public QPlaceSearchReply
Q_OBJECT
public:
- explicit QPlaceSearchReplyImpl(QNetworkReply *reply,
+ explicit QPlaceSearchReplyImpl(const QPlaceSearchRequest &request,
+ QNetworkReply *reply,
QPlaceManagerEngineNokiaV2 *parent);
~QPlaceSearchReplyImpl();