diff options
author | Aaron McCarthy <mccarthy.aaron@gmail.com> | 2013-07-17 23:43:43 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-26 08:19:47 +0200 |
commit | cfec9ee4fd3fb2633eda7fc65eae2adf3ee4643c (patch) | |
tree | cf5c33435b33823d3f1a45250f09520b92a1e12c /src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp | |
parent | 8df09353686b3b9121e84788e84afc52a1a12de0 (diff) | |
download | qtlocation-cfec9ee4fd3fb2633eda7fc65eae2adf3ee4643c.tar.gz |
Support explore functionality.
Add support for Nokia's explore functionality in places. This adds the
ProposedSearchResult search result type. The proposed search result has
a QPlaceSearchRequest, which can be submitted to
QPlaceManager::search() to perform the proposed search.
This has the added advantage that any arbitrary search request can be
returned as a search result. To facilitate this further a search
context field has been added to the place search request. This field
can be used by backends to store additional search context. Other
relevant fields should also be filled in. This allows additional search
context to be kept.
The Nokia v2 places implementation has be updated to use the explore
feature and to return ProposedSearchResults as well as place results.
Task-number: QTBUG-24874
Change-Id: Ib20c5a8c8a60e6bf16f38dcd75961a752b8b1b32
Reviewed-by: Alex <alexander.blasche@digia.com>
Diffstat (limited to 'src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp')
-rw-r--r-- | src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp index 27c4d06d..a31d88c4 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokiav2.cpp @@ -402,9 +402,9 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest QUrlQuery queryItems; - //check the search area is valid for all searches except recommendation searches - //which do not need search centers. - if (query.recommendationId().isEmpty()) { + // Check that the search area is valid for all searches except recommendation and proposed + // searches, which do not need search centers. + if (query.recommendationId().isEmpty() && !query.searchContext().isValid()) { if (!addAtForBoundingArea(query.searchArea(), &queryItems)) { QPlaceSearchReplyImpl *reply = new QPlaceSearchReplyImpl(query, 0, this); connect(reply, SIGNAL(finished()), this, SLOT(replyFinished())); @@ -417,7 +417,28 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest } } - if (!query.searchTerm().isEmpty()) { + QNetworkReply *networkReply = 0; + + if (query.searchContext().userType() == qMetaTypeId<QUrl>()) { + // provided search context + QUrl u = query.searchContext().value<QUrl>(); + + typedef QPair<QString, QString> QueryItem; + QList<QueryItem> queryItemList = queryItems.queryItems(QUrl::FullyEncoded); + queryItems = QUrlQuery(u); + foreach (const QueryItem &item, queryItemList) + queryItems.addQueryItem(item.first, item.second); + + if (query.limit() > 0) + queryItems.addQueryItem(QStringLiteral("size"), QString::number(query.limit())); + + if (query.offset() > -1) + queryItems.addQueryItem(QStringLiteral("offset"), QString::number(query.offset())); + + u.setQuery(queryItems); + + networkReply = sendRequest(u); + } else if (!query.searchTerm().isEmpty()) { // search term query QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() + QLatin1String("/places/v1/discover/search")); @@ -449,30 +470,22 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest 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))); - - return reply; + networkReply = sendRequest(requestUrl); } else { // category search - // The request URL should be "/places/v1/discover/explore" but that returns both places and - // clusters of places. We don't support clusters so we use the undocumented - // "/places/v1/discover/explore/places" instead which only returns places. - QUrl requestUrl(QString::fromLatin1("http://") + m_uriProvider->getCurrentHost() + - QLatin1String("/places/v1/discover/explore/places")); + QUrl requestUrl(QStringLiteral("http://") + m_uriProvider->getCurrentHost() + + QStringLiteral("/places/v1/discover/explore")); QStringList ids; foreach (const QPlaceCategory &category, query.categories()) ids.append(category.categoryId()); - if (ids.count() > 0) { - queryItems.addQueryItem(QLatin1String("cat"), - ids.join(QLatin1String(","))); - } + QUrlQuery queryItems; + + if (!ids.isEmpty()) + queryItems.addQueryItem(QStringLiteral("cat"), ids.join(QStringLiteral(","))); + + addAtForBoundingArea(query.searchArea(), &queryItems); queryItems.addQueryItem(QLatin1String("tf"), QLatin1String("html")); @@ -487,15 +500,15 @@ QPlaceSearchReply *QPlaceManagerEngineNokiaV2::search(const QPlaceSearchRequest requestUrl.setQuery(queryItems); - QNetworkReply *networkReply = sendRequest(requestUrl); + 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))); + 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; - } + return reply; } QPlaceSearchSuggestionReply *QPlaceManagerEngineNokiaV2::searchSuggestions(const QPlaceSearchRequest &query) |