summaryrefslogtreecommitdiff
path: root/src/plugins
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
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')
-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
-rw-r--r--src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp60
-rw-r--r--src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h1
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp9
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h1
9 files changed, 38 insertions, 315 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();
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
index 0ecf0cb0..561574d1 100644
--- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
+++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp
@@ -52,7 +52,6 @@
#include "placesv2/qplacecontentreplyimpl.h"
#include "placesv2/qplacesearchsuggestionreplyimpl.h"
#include "placesv2/qplacesearchreplyimpl.h"
-#include "placesv2/qplacerecommendationreplyimpl.h"
#include "placesv2/qplacedetailsreplyimpl.h"
#include "placesv2/qplaceidreplyimpl.h"
#include "qgeonetworkaccessmanager.h"
@@ -382,8 +381,12 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
// Both a search term and search categories are not supported.
unsupported |= !query.searchTerm().isEmpty() && !query.categories().isEmpty();
+ unsupported |= !query.searchTerm().isEmpty() && !query.recommendationId().isEmpty();
+
+ unsupported |= !query.categories().isEmpty() && !query.recommendationId().isEmpty();
+
if (unsupported) {
- QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(0, this);
+ QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, 0, this);
QMetaObject::invokeMethod(reply, "setError", Qt::QueuedConnection,
Q_ARG(QPlaceReply::Error, QPlaceReply::BadArgumentError),
Q_ARG(QString, "Unsupported search request options specified."));
@@ -413,7 +416,25 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
QNetworkReply *networkReply = sendRequest(requestUrl);
- QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(networkReply, this);
+ QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this);
+ connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
+ connect(reply, SIGNAL(error(QPlaceReply::Error,QString)),
+ this, SLOT(replyError(QPlaceReply::Error,QString)));
+
+ return reply;
+ } else if (!query.recommendationId().isEmpty()) {
+ QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() +
+ QLatin1String("/places/v1/places/") + query.recommendationId() +
+ QLatin1String("/related/recommended"));
+
+ QUrlQuery queryItems;
+ queryItems.addQueryItem(QLatin1String("tf"), QLatin1String("html"));
+
+ requestUrl.setQuery(queryItems);
+
+ QNetworkReply *networkReply = sendRequest(requestUrl);
+
+ QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this);
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
connect(reply, SIGNAL(error(QPlaceReply::Error,QString)),
this, SLOT(replyError(QPlaceReply::Error,QString)));
@@ -455,7 +476,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
QNetworkReply *networkReply = sendRequest(requestUrl);
- QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(networkReply, this);
+ QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, networkReply, this);
connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
connect(reply, SIGNAL(error(QPlaceReply::Error,QString)),
this, SLOT(replyError(QPlaceReply::Error,QString)));
@@ -464,37 +485,6 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest
}
}
-QPlaceSearchReply *QPlaceManagerEngineNokiaV2::recommendations(const QString &placeId, const QPlaceSearchRequest &query)
-{
- QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() +
- QLatin1String("/places/v1/places/") + placeId +
- QLatin1String("/related/recommended"));
-
- QUrlQuery queryItems;
-
- queryItems.addQueryItem(QLatin1String("tf"), QLatin1String("html"));
-
- if (query.limit() > 0) {
- queryItems.addQueryItem(QLatin1String("size"),
- QString::number(query.limit()));
- }
- if (query.offset() > -1) {
- queryItems.addQueryItem(QLatin1String("offset"),
- QString::number(query.offset()));
- }
-
- requestUrl.setQuery(queryItems);
-
- QNetworkReply *networkReply = sendRequest(requestUrl);
-
- QPlaceRecommendationReplyImpl *reply = new QPlaceRecommendationReplyImpl(networkReply, this);
- connect(reply, SIGNAL(finished()), this, SLOT(replyFinished()));
- connect(reply, SIGNAL(error(QPlaceReply::Error,QString)),
- this, SLOT(replyError(QPlaceReply::Error,QString)));
-
- return reply;
-}
-
QPlaceSearchSuggestionReply *QPlaceManagerEngineNokiaV2::searchSuggestions(const QPlaceSearchRequest &query)
{
QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() +
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
index ca375ebe..70654db6 100644
--- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
+++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.h
@@ -89,7 +89,6 @@ public:
QPlaceSearchReply *search(const QPlaceSearchRequest &query);
- QPlaceSearchReply *recommendations(const QString &placeId, const QPlaceSearchRequest &query);
QPlaceSearchSuggestionReply *searchSuggestions(const QPlaceSearchRequest &query);
QPlaceIdReply *savePlace(const QPlace &place);
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
index eb28eca4..113c4d3c 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
@@ -143,15 +143,6 @@ QPlaceSearchReply *QPlaceManagerEngineJsonDb::search(const QPlaceSearchRequest &
return searchReply;
}
-QPlaceSearchReply *QPlaceManagerEngineJsonDb::recommendations(const QString &placeId, const QPlaceSearchRequest &request)
-{
- Q_UNUSED(placeId);
- SearchReply *searchReply = new SearchReply(this);
- searchReply->setRequest(request);
- searchReply->triggerDone(QPlaceReply::UnsupportedError, QString::fromLatin1("Recommendations are unsupported"));
- return searchReply;
-}
-
QPlaceSearchSuggestionReply *QPlaceManagerEngineJsonDb::searchSuggestions(const QPlaceSearchRequest &request)
{
Q_UNUSED(request)
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
index bf8ed9be..4fe905b0 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
@@ -82,7 +82,6 @@ public:
QPlaceSearchReply *search(const QPlaceSearchRequest &request);
- QPlaceSearchReply *recommendations(const QString &placeId, const QPlaceSearchRequest &request);
QPlaceSearchSuggestionReply *searchSuggestions(const QPlaceSearchRequest &request);
QPlaceIdReply *savePlace(const QPlace &place);