diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2011-07-22 14:03:53 +1000 |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2011-07-29 07:51:06 +0200 |
commit | 1d7195981caf1bf1d0bf0b0d1a047bc13b140d6f (patch) | |
tree | 5b06e91da400b7f0310db40454511951fca77679 /src/plugins/geoservices | |
parent | f7131b42e6b997680ed4ebcc3d19becc1ef6da0e (diff) | |
download | qtlocation-1d7195981caf1bf1d0bf0b0d1a047bc13b140d6f.tar.gz |
Incorporate places/nokia plugin into geoservices/nokia plugin.
This brings the usage of the Places API inline with the rest of the
functional groups in QtLocation.
Removes the PlaceManager element.
Change-Id: I6d7259fe7ea1e55dcf97b95025e0c78748e82b9f
Reviewed-on: http://codereview.qt.nokia.com/2245
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/plugins/geoservices')
46 files changed, 6030 insertions, 0 deletions
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro index 062f2760..4ed75df4 100644 --- a/src/plugins/geoservices/nokia/nokia.pro +++ b/src/plugins/geoservices/nokia/nokia.pro @@ -33,6 +33,8 @@ SOURCES += \ qgeoserviceproviderplugin_nokia.cpp \ qgeotiledmapdata_nokia.cpp +include(places/places.pri) + RESOURCES += resource.qrc INCLUDEPATH += $$QT.location.includes diff --git a/src/plugins/geoservices/nokia/places/places.pri b/src/plugins/geoservices/nokia/places/places.pri new file mode 100644 index 00000000..b24b5f90 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/places.pri @@ -0,0 +1,59 @@ +QT *= location network script + +HEADERS += \ +#data classes +#parsers + places/qplacejsonparser_p.h \ + places/qplacejsoncategoriesparser.h \ + places/qplacejsondetailsparser.h \ + places/qplacejsonmediaparser.h \ + places/qplacejsonrecommendationparser.h \ + places/qplacejsonreviewparser.h \ + places/qplacejsonsearchparser.h \ + places/qplacejsontextpredictionparser.h \ +#query classes +#reply classes + places/qplacecategoriesreplyimpl.h \ + places/qplacemediareplyimpl.h \ + places/qplacedetailsreplyimpl.h \ + places/qplaceratingreplyimpl.h \ + places/qplacerecommendationreplyimpl.h \ + places/qplacereviewreplyimpl.h \ + places/qplacesearchreplyimpl.h \ + places/qplacetextpredictionreplyimpl.h \ +#manager and engine + qplacemanagerengine_nokia.h \ + places/qplacecategoriesrepository.h \ + places/qplacerestreply.h \ + places/qplacerestmanager.h \ + places/qplacesuppliersrepository.h + +SOURCES += \ +#data classes +#parsers + places/qplacejsonparser.cpp \ + places/qplacejsoncategoriesparser.cpp \ + places/qplacejsondetailsparser.cpp \ + places/qplacejsonmediaparser.cpp \ + places/qplacejsonrecommendationparser.cpp \ + places/qplacejsonreviewparser.cpp \ + places/qplacejsonsearchparser.cpp \ + places/qplacejsontextpredictionparser.cpp \ +#query classes +#reply classes + places/qplacecategoriesreplyimpl.cpp \ + places/qplacedetailsreplyimpl.cpp \ + places/qplacemediareplyimpl.cpp \ + places/qplaceratingreplyimpl.cpp \ + places/qplacerecommendationreplyimpl.cpp \ + places/qplacereviewreplyimpl.cpp \ + places/qplacesearchreplyimpl.cpp \ + places/qplacetextpredictionreplyimpl.cpp \ +#manager and engine + qplacemanagerengine_nokia.cpp \ + places/qplacecategoriesrepository.cpp \ + places/qplacerestreply.cpp \ + places/qplacerestmanager.cpp \ + places/qplacesuppliersrepository.cpp + + diff --git a/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.cpp new file mode 100644 index 00000000..e312813e --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.cpp @@ -0,0 +1,77 @@ +#include "qplacecategoriesreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +/*! + Constructor. +*/ +QPlaceCategoriesReplyImpl::QPlaceCategoriesReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonCategoriesParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(QString)), + parser, SLOT(processData(QString))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceCategoriesReplyImpl::~QPlaceCategoriesReplyImpl() +{ +} + +QList<QPlaceCategory> QPlaceCategoriesReplyImpl::categories() +{ + return m_categories; +} + +void QPlaceCategoriesReplyImpl::abort() +{ + if (restReply) { + restReply->cancelProcessing(); + } +} + +void QPlaceCategoriesReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceCategoriesReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + m_categories = parser->resultCategories(); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.h new file mode 100644 index 00000000..51a0c16d --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacecategoriesreplyimpl.h @@ -0,0 +1,38 @@ +#ifndef QPLACECATEGORIESREPLYIMPL_H +#define QPLACECATEGORIESREPLYIMPL_H + +#include <QObject> +#include <QList> + +#include <qplacereply.h> +#include "qplacerestreply.h" +#include "qplacejsoncategoriesparser.h" + +class QPlaceCategoriesReplyImpl : public QPlaceReply +{ + Q_OBJECT +public: + explicit QPlaceCategoriesReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceCategoriesReplyImpl(); + + QList<QPlaceCategory> categories(); + + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonCategoriesParser *parser; + + QList<QPlaceCategory> m_categories; +}; + +#endif // QPLACECATEGORIESREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.cpp b/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.cpp new file mode 100644 index 00000000..4304f3c0 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacecategoriesrepository.h" +#include "qplacejsoncategoriesparser.h" + +#include "qplacerestmanager.h" + +QT_USE_NAMESPACE + +static QMap<QString, QString> categoriesMap; +static QPlaceCategory *secondSearchCenter = NULL; + +QPlaceCategoriesRepository *QPlaceCategoriesRepository::repositoryInstance = NULL; + +QPlaceCategoriesRepository *QPlaceCategoriesRepository::instance() +{ + if (!repositoryInstance) { + repositoryInstance = new QPlaceCategoriesRepository(); + } + return repositoryInstance; +} + +QPlaceCategoriesRepository::QPlaceCategoriesRepository(QObject *parent) + : QObject(parent), + categoriesReply(NULL) +{ + setupCategoriesMapper(); +} + +QPlaceCategoriesRepository::~QPlaceCategoriesRepository() +{ +} + +QPlaceReply *QPlaceCategoriesRepository::initializeCategories() +{ + if (!categoriesReply) { + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendCategoriesTreeRequest(); + if (restReply) { + categoriesReply = new QPlaceCategoriesReplyImpl(restReply); + connect(categoriesReply, SIGNAL(finished()), + this, SLOT(replyFinished())); + } + } + return categoriesReply; +} + +QList<QPlaceCategory> QPlaceCategoriesRepository::categories() const +{ + return allCategories.values(); +} + +QPlaceCategory QPlaceCategoriesRepository::mapCategory(const QString &number) +{ + QString categoryId = categoriesMap.value(number, ""); + if (categoryId == "second-search-center") { + if (!secondSearchCenter) { + secondSearchCenter = new QPlaceCategory(); + secondSearchCenter->setCategoryId("second-search-center"); + } + return *secondSearchCenter; + } else if (!categoryId.isEmpty()) { + return findCategoryById(categoryId); + } + return QPlaceCategory(); +} + +QString QPlaceCategoriesRepository::getCategoryTagId(const QPlaceCategory &category) +{ + return categoriesMap.key(category.categoryId(), QString()); +} + +QPlaceCategory QPlaceCategoriesRepository::findCategoryById(const QString &id) +{ + return allCategories.value(id, QPlaceCategory()); +} + +void QPlaceCategoriesRepository::replyFinished() +{ + if (!categoriesReply.isNull()) { + foreach (QPlaceCategory cat, categoriesReply->categories()) { + allCategories.insert(cat.categoryId(), cat); + } + } + categoriesReply = NULL; +} + +void QPlaceCategoriesRepository::setupCategoriesMapper() +{ + // setup mapper + if (!categoriesMap.count()) { + //BusinessServices + categoriesMap.insert(QString("9000269"),QString("business-services")); + categoriesMap.insert(QString("9000005"),QString("business-industry")); + categoriesMap.insert(QString("9000277"),QString("travel-agency")); + categoriesMap.insert(QString("9000028"),QString("tourist-information")); + categoriesMap.insert(QString("9000040"),QString("police-emergency")); + categoriesMap.insert(QString("9000017"),QString("petrol-station")); + categoriesMap.insert(QString("9000278"),QString("communication-media")); + categoriesMap.insert(QString("9000047"),QString("atm-bank-exchange")); + categoriesMap.insert(QString("9000002"),QString("car-dealer-repair")); + categoriesMap.insert(QString("9000020"),QString("car-rental")); + categoriesMap.insert(QString("9000215"),QString("service")); + categoriesMap.insert(QString("9000019"),QString("post-office")); + // Transport + categoriesMap.insert(QString("9000272"),QString("transport")); + categoriesMap.insert(QString("9000216"),QString("taxi-stand")); + categoriesMap.insert(QString("9000043"),QString("airport")); + categoriesMap.insert(QString("9000041"),QString("railway-station")); + categoriesMap.insert(QString("9000058"),QString("public-transport")); + categoriesMap.insert(QString("9000035"),QString("ferry-terminal")); + // Shopping + categoriesMap.insert(QString("9000270"),QString("shopping")); + categoriesMap.insert(QString("9000205"),QString("clothing-accessories-shop")); + categoriesMap.insert(QString("9000276"),QString("bookshop")); + categoriesMap.insert(QString("9000194"),QString("hardware-house-garden-shop")); + categoriesMap.insert(QString("9000049"),QString("pharmacy")); + categoriesMap.insert(QString("9000024"),QString("mall")); + categoriesMap.insert(QString("9000197"),QString("kiosk-convenience-store")); + categoriesMap.insert(QString("9000196"),QString("electronics-shop")); + categoriesMap.insert(QString("9000191"),QString("sport-outdoor-shop")); + categoriesMap.insert(QString("9000189"),QString("department-store")); + // Accomodation + categoriesMap.insert(QString("9000271"),QString("accommodation")); + categoriesMap.insert(QString("9000032"),QString("camping")); + categoriesMap.insert(QString("9000174"),QString("motel")); + categoriesMap.insert(QString("9000038"),QString("hotel")); + categoriesMap.insert(QString("9000173"),QString("hostel")); + // GoingOut + categoriesMap.insert(QString("9000274"),QString("going-out")); + categoriesMap.insert(QString("9000203"),QString("dance-night-club")); + categoriesMap.insert(QString("9000003"),QString("casino")); + categoriesMap.insert(QString("9000004"),QString("cinema")); + categoriesMap.insert(QString("9000181"),QString("theatre-music-culture")); + // Facility + categoriesMap.insert(QString("9000261"),QString("facilities")); + categoriesMap.insert(QString("9000039"),QString("parking-facility")); + categoriesMap.insert(QString("9000007"),QString("fair-convention-facility")); + categoriesMap.insert(QString("9000012"),QString("government-community-facility")); + categoriesMap.insert(QString("9000200"),QString("hospital-health-care-facility")); + categoriesMap.insert(QString("9000106"),QString("education-facility")); + categoriesMap.insert(QString("9000220"),QString("sports-facility-venue")); + categoriesMap.insert(QString("9000031"),QString("library")); + // NatureGeography + categoriesMap.insert(QString("9000265"),QString("natural-geographical")); + categoriesMap.insert(QString("9000262"),QString("body-of-water")); + categoriesMap.insert(QString("9000045"),QString("mountain-hill")); + categoriesMap.insert(QString("9000259"),QString("forest-health-vegetation")); + categoriesMap.insert(QString("9000260"),QString("undersea-feature")); + // AreasInfrastructure + categoriesMap.insert(QString("9000266"),QString("administrative-areas-buildings")); + categoriesMap.insert(QString("9000279"),QString("administrative-region")); + categoriesMap.insert(QString("9000263"),QString("outdoor-area-complex")); + categoriesMap.insert(QString("9000283"),QString("city-town-village")); + categoriesMap.insert(QString("9000280"),QString("building")); + // EatDrink + categoriesMap.insert(QString("9000275"),QString("eat-drink")); + categoriesMap.insert(QString("9000063"),QString("coffee-tea")); + categoriesMap.insert(QString("9000022"),QString("restaurant")); + categoriesMap.insert(QString("9000064"),QString("snacks-fast-food")); + categoriesMap.insert(QString("9000033"),QString("bar-pub")); + categoriesMap.insert(QString("9000143"),QString("food-drink")); + // Leisure + categoriesMap.insert(QString("9000267"),QString("leisure-outdoor")); + categoriesMap.insert(QString("9000048"),QString("recreation")); + categoriesMap.insert(QString("9000001"),QString("amusement-holiday-park")); + // SightsMuseums + categoriesMap.insert(QString("9000273"),QString("sights-museums")); + categoriesMap.insert(QString("9000014"),QString("museum")); + categoriesMap.insert(QString("9000158"),QString("religious-place")); + categoriesMap.insert(QString("9000211"),QString("landmark-attraction")); + // SSC + categoriesMap.insert(QString("9000282"),QString("second-search-center")); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.h b/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.h new file mode 100644 index 00000000..e0a14725 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacecategoriesrepository.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACECATEGORIESREPOSITORY_H +#define QPLACECATEGORIESREPOSITORY_H + +#include <QObject> +#include <QPointer> +#include <QList> + +#include <qmobilityglobal.h> +#include <qplacecategory.h> +#include <qplacereply.h> +#include "qplacejsoncategoriesparser.h" +#include "qplacecategoriesreplyimpl.h" + +QT_BEGIN_NAMESPACE + +class QPlaceCategoriesRepository : public QObject +{ + Q_OBJECT +public: + static QPlaceCategoriesRepository *instance(); + + ~QPlaceCategoriesRepository(); + + QPlaceReply *initializeCategories(); + QList<QPlaceCategory> categories() const; + + QPlaceCategory mapCategory(const QString &number); + QString getCategoryTagId(const QPlaceCategory &category); + QPlaceCategory findCategoryById(const QString &id); + +public slots: + void replyFinished(); + +private: + void setupCategoriesMapper(); + +private: + QPlaceCategoriesRepository(QObject *parent = 0); + + QHash<QString, QPlaceCategory> allCategories; + static QPlaceCategoriesRepository *repositoryInstance; + QPointer<QPlaceCategoriesReplyImpl> categoriesReply; +}; + +QT_END_NAMESPACE + +#endif // QPLACECATEGORIESREPOSITORY_H diff --git a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp new file mode 100644 index 00000000..06a6e228 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacedetailsreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceDetailsReplyImpl::QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceDetailsReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonDetailsParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(QString)), parser, SLOT(processData(QString))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceDetailsReplyImpl::~QPlaceDetailsReplyImpl() +{ +} + +void QPlaceDetailsReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceDetailsReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceDetailsReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + QGeoPlace place = parser->result(); + place.setDetailsFetched(true); + setResult(place); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h new file mode 100644 index 00000000..e08233e9 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEDETAILSREPLYIMPL_H +#define QPLACEDETAILSREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacedetailsreply.h> +#include "qplacerestreply.h" +#include "qplacejsondetailsparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceDetailsReplyImpl : public QPlaceDetailsReply +{ + Q_OBJECT +public: + explicit QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceDetailsReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonDetailsParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACEDETAILSREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.cpp new file mode 100644 index 00000000..18e875a9 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsoncategoriesparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> +#include <qmobilityglobal.h> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +static const char *place_categories_element = "categories"; +static const char *place_category_element = "category"; +static const char *place_category_name_element = "displayName"; +static const char *place_category_id_element = "name"; + +static const char *place_group_element = "group"; +static const char *place_groupingcategory_element = "groupingCategory"; + +QT_USE_NAMESPACE + +QPlaceJSonCategoriesParser::QPlaceJSonCategoriesParser(QObject *parent) : + QPlaceJSonParser(parent) +{ +} + +QPlaceJSonCategoriesParser::~QPlaceJSonCategoriesParser() +{ + allCategories.clear(); +} + +QList<QPlaceCategory> QPlaceJSonCategoriesParser::resultCategories() +{ + return allCategories; +} + +void QPlaceJSonCategoriesParser::processJSonData(const QScriptValue &sv) +{ + allCategories.clear(); + + if (sv.isValid()) { + QScriptValue sv2 = sv.property(place_categories_element); + if (sv2.isValid()) { + allCategories = processCategories(sv2); + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +QList<QPlaceCategory> QPlaceJSonCategoriesParser::processCategories(const QScriptValue &categories) +{ + QHash<QString, QPlaceCategory> results; + QPlaceCategory cat; + QScriptValue value = categories.property(place_category_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + cat = processCategory(it.value()); + if (!cat.categoryId().isEmpty() && !results.contains(cat.categoryId())) { + results.insert(cat.categoryId(), cat); + } + } + } + } else { + cat = processCategory(value); + if (!cat.categoryId().isEmpty() && !results.contains(cat.categoryId())) { + results.insert(cat.categoryId(), cat); + } + } + } + foreach (cat, processGroups(categories)) { + if (!results.contains(cat.categoryId())) { + results.insert(cat.categoryId(), cat); + } + } + + return results.values(); +} + +QPlaceCategory QPlaceJSonCategoriesParser::processCategory(const QScriptValue &categoryValue) +{ + QPlaceCategory category; + QScriptValue value = categoryValue.property(place_category_id_element); + if (value.isValid() && !value.toString().isEmpty()) { + category.setCategoryId(value.toString()); + value = categoryValue.property(place_category_name_element); + if (value.isValid() && !value.toString().isEmpty()) { + category.setName(value.toString()); + } + } + return category; +} + +QList<QPlaceCategory> QPlaceJSonCategoriesParser::processGroups(const QScriptValue &categories) +{ + QList<QPlaceCategory> results; + QScriptValue value = categories.property(place_group_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + results.append(processGroup(it.value())); + } + } + } else { + results.append(processGroup(value)); + } + } + return results; +} + +QList<QPlaceCategory> QPlaceJSonCategoriesParser::processGroup(const QScriptValue &group) +{ + QList<QPlaceCategory> results; + QPlaceCategory parentCategory; + + QScriptValue value = group.property(place_groupingcategory_element); + if (value.isValid()) { + parentCategory = processCategory(value); + } + if (!parentCategory.categoryId().isEmpty()) { + results = processCategories(group); + } + + return results; +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.h b/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.h new file mode 100644 index 00000000..c6c95717 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsoncategoriesparser.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONCATEGORIESPARSER_H +#define QPLACEJSONCATEGORIESPARSER_H + +#include <QObject> +#include <QList> +#include <QHash> + +#include <qplacecategory.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonCategoriesParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonCategoriesParser(QObject *parent = 0); + virtual ~QPlaceJSonCategoriesParser(); + + static QList<QPlaceCategory> processCategories(const QScriptValue &categories); + + QList<QPlaceCategory> resultCategories(); + +private: + void processJSonData(const QScriptValue &sv); + static QPlaceCategory processCategory(const QScriptValue &categoryValue); + static QList<QPlaceCategory> processGroups(const QScriptValue &categories); + static QList<QPlaceCategory> processGroup(const QScriptValue &group); +private: + QList<QPlaceCategory> allCategories; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONCATEGORIESPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp new file mode 100644 index 00000000..6995c635 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp @@ -0,0 +1,1038 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsondetailsparser.h" + +#include <QtCore/QUrl> +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include <qgeoaddress.h> +#include <qgeocoordinate.h> +#include <qgeoplace.h> +#include <qplacecontact.h> +#include <qplacecategory.h> +#include <qplacedescription.h> +#include <qplacerating.h> +#include <qplacebusinessinformation.h> +#include <qgeolocation.h> +#include <qplacemediaobject.h> +#include <qplaceperiod.h> +#include <qplaceweekdayhours.h> +#include <qplacesupplier.h> +#include "qplacejsoncategoriesparser.h" +#include "qplacesuppliersrepository.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +//search const +static const char *place_place_element = "place"; +static const char *place_id_element = "a_id"; +static const char *place_is_ad_place_value = "isAdPlace"; + +static const char *place_provider = "provider"; +static const char *place_provider_url = "providerUrl"; + +static const char *place_categories_element = "categories"; + +static const char *place_contact_element = "contact"; +static const char *place_contact_email_element = "email"; +static const char *place_contact_fax_element = "fax"; +static const char *place_contact_phone_element = "phone"; +static const char *place_contact_website_element = "website"; +static const char *place_contact_im_element = "im"; + +static const char *place_tags_element = "tags"; +static const char *place_tags_value_element = "value"; + +static const char *place_names_element = "names"; +static const char *place_alternativenames_element = "alternativeNames"; +static const char *place_name_default_element = "defaultName"; +static const char *place_name_localized_element = "localizedName"; +static const char *place_name_value_element = "name"; +static const char *place_name_language_element = "language"; + +static const char *place_ratings_element = "averageRatings"; +static const char *place_rating_element = "averageRating"; +static const char *place_rating_rating_element = "rating"; +static const char *place_rating_count_element = "ratingCount"; +static const char *place_rating_type_element = "ratingType"; +static const char *place_rating_type_overall_element = "OVERALL"; + +static const char *place_location_element = "location"; +static const char *place_geoCoordinates_element = "geoCoordinates"; +static const char *place_geoCoordinates_longitude_value = "longitude"; +static const char *place_geoCoordinates_latitude_value = "latitude"; +//! @todo check if bounding box should be supported +//static const char *place_geoCoordinates_longitude_bb1_value = "GEO_BBX_LONGITUDE_1"; +//static const char *place_geoCoordinates_latitude_bb1_value = "GEO_BBX_LATITUDE_1"; +//static const char *place_geoCoordinates_longitude_bb2_value = "GEO_BBX_LONGITUDE_2"; +//static const char *place_geoCoordinates_latitude_bb2_value = "GEO_BBX_LATITUDE_2"; + +static const char *place_address_element = "address"; +static const char *place_address_country = "localizedCountryName"; +static const char *place_address_county = "county"; +static const char *place_address_country_code = "countryCode3L"; +static const char *place_address_state = "state"; +static const char *place_address_code = "zipCode"; +static const char *place_address_city = "city"; +static const char *place_address_district = "district"; +static const char *place_address_street = "street"; +static const char *place_address_house_number = "houseNumber"; + +static const char *place_adcontent_element = "adPlaceContent"; +static const char *place_adcontent_descriptions_element = "descriptions"; +static const char *place_adcontent_description_element = "description"; +static const char *place_adcontent_localizedDescription_element = "localizedDescription"; +static const char *place_adcontent_descriptionLanguage_element = "languageOfDescription"; +static const char *place_adcontent_medias_element = "mediaTypes"; +static const char *place_adcontent_media_element = "adPlaceMedia"; +static const char *place_adcontent_media_mime_element = "mediaMimeType"; +static const char *place_adcontent_media_url_element = "mediaUrl"; +static const char *place_adcontent_paymentmethods_element = "paymentMethods"; +static const char *place_adcontent_paymentmethod_element = "paymentMetod"; +static const char *place_adcontent_paymentmethod_name_element = "name"; +static const char *place_adcontent_hours_element = "businessHours"; +static const char *place_adcontent_hours_annualclosingsnotes_element = "annualclosingsnotes"; +static const char *place_adcontent_hours_annualclosingsnote_element = "annualclosingsnote"; +static const char *place_adcontent_hours_annualclosingsnote_v_element = "_v"; +static const char *place_adcontent_hours_open_element = "openingSchedule"; +static const char *place_adcontent_hours_open_hours_element = "openingHours"; +static const char *place_adcontent_hours_open_day_element = "dayOfWeek"; +static const char *place_adcontent_hours_open_from_element = "openFrom"; +static const char *place_adcontent_hours_open_to_element = "openTo"; +static const char *place_adcontent_hours_openingnotes_element = "openingnotes"; +static const char *place_adcontent_hours_openingnote_element = "openingnote"; +static const char *place_adcontent_hours_openingnote_v_element = "_v"; +static const char *place_adcontent_packages_element = "packages"; +static const char *place_adcontent_package_element = "package"; +static const char *place_adcontent_package_type_element = "packageType"; +static const char *place_adcontent_package_type_plus_value = "PLUS"; +static const char *place_adcontent_package_type_plus_plus_value = "PLUS+"; + +static const char *place_package_type = "type"; +static const char *place_package_type_ad_place = "ADPLACE"; +static const char *place_package_type_ad_place_prime_plus = "ADPLACE, PRIME_PLUS"; +static const char *place_package_type_ad_place_prime_plus_plus = "ADPLACE, PRIME_PLUS_PLUS"; +static const char *place_package_type_place = "PLACE"; + +static const char *place_premiumcontent_element = "premiumContent"; +static const char *place_premiumcontent_version_element = "version"; +static const char *place_premiumcontent_content_element = "content"; +static const char *place_premiumcontent_content_desc_element = "description"; +static const char *place_premiumcontent_content_shortdesc_element = "short-description"; +static const char *place_premiumcontent_content_name_element = "name"; +static const char *place_premiumcontent_content_providername_element = "providerDisplayName"; +static const char *place_premiumcontent_content_provider_element = "provider"; +static const char *place_premiumcontent_content_vendorurl_element = "vendor-url"; +static const char *place_premiumcontent_content_providerIconUrl_element = "providerIconUrl"; +static const char *place_premiumcontent_content_language_element = "language"; +static const char *place_premiumcontent_content_media_element = "media"; +static const char *place_premiumcontent_content_mediaurl_element = "content"; +static const char *place_premiumcontent_content_mediamimetype_element = "mimeType"; + +static const char *place_premiumcontent_content_monday = "MON"; +static const char *place_premiumcontent_content_tuesday = "TUE"; +static const char *place_premiumcontent_content_wednesday = "WED"; +static const char *place_premiumcontent_content_thursday = "THU"; +static const char *place_premiumcontent_content_friday = "FRI"; +static const char *place_premiumcontent_content_saturday = "SAT"; +static const char *place_premiumcontent_content_sunday = "SUN"; + +QT_USE_NAMESPACE + +QPlaceJSonDetailsParser::QPlaceJSonDetailsParser(QObject *parent) : + QPlaceJSonParser(parent) +{ +} + +QPlaceJSonDetailsParser::~QPlaceJSonDetailsParser() +{ +} + +QGeoPlace QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue) +{ + QGeoPlace newPlace; + if (placeValue.isValid()) { + buildPlace(placeValue, &newPlace); + } + return newPlace; +} + +QGeoPlace QPlaceJSonDetailsParser::result() +{ + return place; +} + +void QPlaceJSonDetailsParser::processJSonData(const QScriptValue &sv) +{ + if (sv.isValid()) { + QScriptValue placeProperty = sv.property(place_place_element); + if (placeProperty.isValid()) { + buildPlace(placeProperty, &place); + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +void QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue, QGeoPlace*targetPlace) +{ + if (placeValue.isValid()) { + QScriptValue value = placeValue.property(place_id_element); + if (value.isValid() && !value.toString().isEmpty()) { + targetPlace->setPlaceId(value.toString()); + } + processMainProvider(placeValue, targetPlace); + value = placeValue.property(place_categories_element); + if (value.isValid()) { + processCategories(value, targetPlace); + } + value = placeValue.property(place_contact_element); + if (value.isValid()) { + processContacts(value, targetPlace); + } + value = placeValue.property(place_tags_element); + if (value.isValid()) { + processTags(value, targetPlace); + } + value = placeValue.property(place_names_element); + if (value.isValid()) { + processNames(value, targetPlace); + } + value = placeValue.property(place_ratings_element); + if (value.isValid()) { + processRatings(value, targetPlace); + } + value = placeValue.property(place_location_element); + if (value.isValid()) { + processLocation(value, targetPlace); + } + value = placeValue.property(place_adcontent_element); + if (value.isValid()) { + processAdContent(value, targetPlace); + } + value = placeValue.property(place_premiumcontent_element); + if (value.isValid()) { + processPremiumContents(value, targetPlace); + } + } +} + +void QPlaceJSonDetailsParser::processMainProvider(const QScriptValue &placeValue, QGeoPlace*targetPlace) +{ + QPlaceSupplier sup; + QScriptValue value = placeValue.property(place_provider); + if (value.isValid() && !value.toString().isEmpty()) { + sup.setName(value.toString()); + } + else { + return; + } + value = placeValue.property(place_provider_url); + if (value.isValid() && !value.toString().isEmpty()){ + sup.setSupplierIconUrl(value.toString()); + } + QList<QPlaceSupplier> list; + list.append(QPlaceSuppliersRepository::instance()->addSupplier(sup)); + targetPlace->setSuppliers(list); +} + +void QPlaceJSonDetailsParser::processContacts(const QScriptValue &contactsValue, QGeoPlace*targetPlace) +{ + QList<QPlaceContact> contacts; + QScriptValueIterator it(contactsValue); + while (it.hasNext()) { + it.next(); + QPlaceContact contact; + if (it.name() == place_contact_website_element) { + contact.setType(QPlaceContact::Url); + } + if (it.name() == place_contact_phone_element) { + contact.setType(QPlaceContact::Phone); + } + if (it.name() == place_contact_fax_element) { + contact.setType(QPlaceContact::Fax); + } + if (it.name() == place_contact_im_element) { + contact.setType(QPlaceContact::IM); + } + if (it.name() == place_contact_email_element) { + contact.setType(QPlaceContact::Email); + } + contact.setValue(it.value().toString()); + contacts.append(contact); + } + targetPlace->setContacts(contacts); +} + +void QPlaceJSonDetailsParser::processCategories(const QScriptValue &categories, QGeoPlace*targetPlace) +{ + targetPlace->setCategories(QPlaceJSonCategoriesParser::processCategories(categories)); +} + +void QPlaceJSonDetailsParser::processRatings(const QScriptValue &ratings, QGeoPlace*targetPlace) +{ + QPlaceRating *rating = NULL; + QScriptValue value = ratings.property(place_rating_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + rating = processRating(it.value()); + if (rating) { + break; + } + } + } + } else { + rating = processRating(value); + } + } + if (rating) { + targetPlace->setRating(*rating); + delete rating; + rating = NULL; + } +} + +QPlaceRating *QPlaceJSonDetailsParser::processRating(const QScriptValue &ratingElement) +{ + QPlaceRating *rating = NULL; + QScriptValue value = ratingElement.property(place_rating_type_element); + // Only overall elements are interesting + if (value.isValid() && value.toString() == place_rating_type_overall_element) { + rating = new QPlaceRating(); + value = ratingElement.property(place_rating_count_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + uint ratingValue = value.toString().toInt(&isConverted); + if (isConverted) { + rating->setCount(ratingValue); + } + } + value = ratingElement.property(place_rating_rating_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + double ratingValue = value.toString().toDouble(&isConverted); + if (isConverted) { + rating->setValue(ratingValue); + } + } + } + return rating; +} + +void QPlaceJSonDetailsParser::processAddress(const QScriptValue &address, QGeoLocation *location) +{ + QGeoAddress newAddress; + QScriptValue value = address.property(place_address_street); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setStreet(value.toString()); + } + value = address.property(place_address_country); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCountry(value.toString()); + } + value = address.property(place_address_county); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCounty(value.toString()); + } + value = address.property(place_address_country_code); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCountry(value.toString()); + } + value = address.property(place_address_state); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setState(value.toString()); + } + value = address.property(place_address_city); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCity(value.toString()); + } + value = address.property(place_address_code); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setPostcode(value.toString()); + } + value = address.property(place_address_district); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setDistrict(value.toString()); + } + value = address.property(place_address_house_number); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setStreet(value.toString() + " " + newAddress.street()); + } + location->setAddress(newAddress); +} + +void QPlaceJSonDetailsParser::processLocation(const QScriptValue &location, QGeoPlace *targetPlace) +{ + QGeoLocation newLocation; + QScriptValue property = location.property(place_geoCoordinates_element); + if (property.isValid()) { + QGeoCoordinate pos; + QScriptValue value = property.property(place_geoCoordinates_longitude_value); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + double longitude = value.toString().toDouble(&isConverted); + if (isConverted) { + pos.setLongitude(longitude); + } + } + value = property.property(place_geoCoordinates_latitude_value); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + double latitude = value.toString().toDouble(&isConverted); + if (isConverted) { + pos.setLatitude(latitude); + } + } + newLocation.setCoordinate(pos); + } + property = location.property(place_address_element); + if (property.isValid()) { + processAddress(property, &newLocation); + } + targetPlace->setLocation(newLocation); +} + +void QPlaceJSonDetailsParser::processTags(const QScriptValue &tags, QGeoPlace*targetPlace) +{ + QStringList newTags; + if (tags.isValid()) { + if (tags.isArray()) { + QScriptValueIterator it(tags); + while (it.hasNext()) { + it.next(); + QScriptValue value = it.value().property(place_tags_value_element); + if (value.isValid() && !value.toString().isEmpty()) { + newTags.append(value.toString()); + } + } + } else { + QScriptValue value = tags.property(place_tags_value_element); + if (value.isValid() && !value.toString().isEmpty()) { + newTags.append(value.toString()); + } + } + } + targetPlace->setTags(newTags); +} + +void QPlaceJSonDetailsParser::processNames(const QScriptValue &names, QGeoPlace*targetPlace) +{ + QScriptValue value = names.property(place_alternativenames_element); + if (value.isValid()) { + value = value.property(place_name_localized_element); + if (value.isValid()) { + QStringList list; + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QString name = processName(it.value()); + if (!name.isEmpty()) { + list.append(name); + } + } + } + } else { + QString name = processName(value); + if (!name.isEmpty()) { + list.append(name); + } + } + //The JSON data specification defines + //an alternative names element, + //but our api doesn't expose alternative names + //so we parse and skip assignment to a place here. + } + } + value = names.property(place_name_default_element); + if (value.isValid()) { + QString name = processName(value); + if (!name.isEmpty()) { + targetPlace->setName(name); + } + } +} + +QString QPlaceJSonDetailsParser::processName(const QScriptValue &nameValue) +{ + QString name; + QScriptValue value = nameValue.property(place_name_value_element); + if (value.isValid() && !value.toString().isEmpty()) { + name = value.toString(); + } + return name; +} + +void QPlaceJSonDetailsParser::processPremiumContents(const QScriptValue &premiumContent, QGeoPlace*targetPlace) +{ + QScriptValue value = premiumContent.property(place_premiumcontent_version_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + processPremiumVersion(it.value(), targetPlace); + } + } + } else { + processPremiumVersion(value, targetPlace); + } + } +} + +void QPlaceJSonDetailsParser::processPremiumVersion(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_premiumcontent_content_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + processPremiumContent(it.value(), targetPlace); + } + } + } else { + processPremiumContent(value, targetPlace); + } + } +} + +void QPlaceJSonDetailsParser::processPremiumContent(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QString name, id, iconUrl; + QScriptValue value = content.property(place_premiumcontent_content_providername_element); + if (value.isValid() && !value.toString().isEmpty()) { + name = value.toString(); + } + value = content.property(place_premiumcontent_content_provider_element); + if (value.isValid() && !value.toString().isEmpty()) { + id = value.toString(); + } + value = content.property(place_premiumcontent_content_providerIconUrl_element); + if (value.isValid() && !value.toString().isEmpty()) { + iconUrl = value.toString(); + } + QPlaceSupplier supplier; + if (!name.isEmpty() || !id.isEmpty()) { + supplier.setName(name); + supplier.setSupplierId(id); + supplier.setSupplierIconUrl(iconUrl); + supplier = QPlaceSuppliersRepository::instance()->addSupplier(supplier); + } + processPremiumContentDescription(content, supplier, targetPlace); + processPremiumContentMediaObjects(content, supplier, targetPlace); +} + +void QPlaceJSonDetailsParser::processPremiumContentDescription(const QScriptValue &content, + const QPlaceSupplier &supplier, + QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_premiumcontent_content_desc_element); + QPlaceDescription desc; + if (value.isValid() && !value.toString().isEmpty()) { + desc.setContent(value.toString()); + } else { + value = content.property(place_premiumcontent_content_shortdesc_element); + if (value.isValid() && !value.toString().isEmpty()) { + desc.setContent(value.toString()); + } + } + // if no description do not continue + if (desc.content().isEmpty()) { + return; + } + value = content.property(place_premiumcontent_content_name_element); + if (value.isValid() && !value.toString().isEmpty()) { + desc.setContentTitle(value.toString()); + } + value = content.property(place_premiumcontent_content_vendorurl_element); + if (value.isValid() && !value.toString().isEmpty()) { + desc.setSourceUrl(value.toString()); + } + value = content.property(place_premiumcontent_content_language_element); + if (value.isValid() && !value.toString().isEmpty()) { + desc.setLanguage(value.toString()); + } + desc.setSupplier(supplier); + QList<QPlaceDescription> list = targetPlace->descriptions(); + list.append(desc); + targetPlace->setDescriptions(list); +} + +void QPlaceJSonDetailsParser::processPremiumContentMediaObjects(const QScriptValue &content, + const QPlaceSupplier &supplier, + QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_premiumcontent_content_media_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceMediaObject *obj = processPremiumContentMediaObject(it.value()); + if (obj) { + obj->setSupplier(supplier); + QPlacePaginationList<QPlaceMediaObject> list = targetPlace->media(); + list.addItem(*obj); + targetPlace->setMedia(list); + delete obj; + obj = NULL; + } + } + } + } else { + QPlaceMediaObject *obj = processPremiumContentMediaObject(value); + if (obj) { + obj->setSupplier(supplier); + QPlacePaginationList<QPlaceMediaObject> list = targetPlace->media(); + list.addItem(*obj); + targetPlace->setMedia(list); + delete obj; + obj = NULL; + } + } + } +} + +QPlaceMediaObject *QPlaceJSonDetailsParser::processPremiumContentMediaObject(const QScriptValue &content) +{ + QPlaceMediaObject *obj = NULL; + QScriptValue value = content.property(place_premiumcontent_content_mediaurl_element); + if (value.isValid() && !value.toString().isEmpty()) { + obj = new QPlaceMediaObject(); + obj->setUrl(QUrl::fromEncoded(value.toString().toAscii())); + obj->setId(value.toString()); + value = content.property(place_premiumcontent_content_mediamimetype_element); + if (value.isValid() && !value.toString().isEmpty()) { + obj->setMimeType(value.toString()); + } + } + return obj; +} + +void QPlaceJSonDetailsParser::processAdContent(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_descriptions_element); + if (value.isValid()) { + processAdContentDescriptions(value, targetPlace); + } + value = content.property(place_adcontent_medias_element); + if (value.isValid()) { + processAdContentMediaObjects(value, targetPlace); + } + value = content.property(place_adcontent_paymentmethods_element); + if (value.isValid()) { + processAdContentPaymentMethods(value, targetPlace); + } + value = content.property(place_adcontent_hours_element); + if (value.isValid()) { + processAdContentBusinessHours(value, targetPlace); + } + value = content.property(place_adcontent_packages_element); + if (value.isValid()) { + processAdContentPackages(value, targetPlace); + } +} + +void QPlaceJSonDetailsParser::processAdContentPackages(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_package_element); + if (value.isValid()) { + value = value.property(place_adcontent_package_type_element); + if (value.isValid() && !value.toString().isEmpty()) { + QString package = value.toString(); + QVariantHash data = targetPlace->additionalData(); + if (package == place_adcontent_package_type_plus_value) { + data[place_package_type] = place_package_type_ad_place_prime_plus; + } else if (package == place_adcontent_package_type_plus_plus_value) { + data[place_package_type] = place_package_type_ad_place_prime_plus_plus; + } + targetPlace->setAdditionalData(data); + } + } +} + +void QPlaceJSonDetailsParser::processAdContentDescriptions(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_description_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceDescription *des = processAdContentDescription(it.value()); + if (des) { + QList<QPlaceDescription> list = targetPlace->descriptions(); + list.append(*des); + targetPlace->setDescriptions(list); + delete des; + des = NULL; + } + } + } + } else { + QPlaceDescription *des = processAdContentDescription(value); + if (des) { + QList<QPlaceDescription> list = targetPlace->descriptions(); + list.append(*des); + targetPlace->setDescriptions(list); + delete des; + des = NULL; + } + } + } +} + +QPlaceDescription *QPlaceJSonDetailsParser::processAdContentDescription(const QScriptValue &content) +{ + QPlaceDescription *description = NULL; + QScriptValue value = content.property(place_adcontent_localizedDescription_element); + if (value.isValid() && !value.toString().isEmpty()) { + description = new QPlaceDescription(); + description->setContent(value.toString()); + value = content.property(place_adcontent_descriptionLanguage_element); + if (value.isValid() && !value.toString().isEmpty()) { + description->setLanguage(value.toString()); + } + } + return description; +} + +void QPlaceJSonDetailsParser::processAdContentMediaObjects(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_media_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceMediaObject *obj = processAdContentMediaObject(it.value()); + if (obj) { + QPlacePaginationList<QPlaceMediaObject> list = targetPlace->media(); + list.addItem(*obj); + targetPlace->setMedia(list); + delete obj; + obj = NULL; + } + } + } + } else { + QPlaceMediaObject *obj = processAdContentMediaObject(value); + if (obj) { + QPlacePaginationList<QPlaceMediaObject> list = targetPlace->media(); + list.addItem(*obj); + targetPlace->setMedia(list); + delete obj; + obj = NULL; + } + } + } +} + +QPlaceMediaObject *QPlaceJSonDetailsParser::processAdContentMediaObject(const QScriptValue &content) +{ + QPlaceMediaObject *obj = NULL; + QString mediaMimeType; + QString mediaUrl; + + QScriptValue value = content.property(place_adcontent_media_mime_element); + if (value.isValid() && !value.toString().isEmpty()) { + mediaMimeType = value.toString(); + } + value = content.property(place_adcontent_media_url_element); + if (value.isValid() && !value.toString().isEmpty()) { + mediaUrl = value.toString(); + } + if (!mediaMimeType.isEmpty() || !mediaUrl.isEmpty()) { + obj = new QPlaceMediaObject(); + obj->setUrl(QUrl::fromEncoded(mediaUrl.toAscii())); + obj->setId(mediaUrl); + obj->setMimeType(mediaMimeType); + } + return obj; +} + +void QPlaceJSonDetailsParser::processAdContentPaymentMethods(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_paymentmethod_element); + if (value.isValid()) { + QStringList list; + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QString obj = processAdContentPaymentMethod(it.value()); + if (!obj.isEmpty()) { + list.append(obj); + } + } + } + } else { + QString obj = processAdContentPaymentMethod(value); + if (!obj.isEmpty()) { + list.append(obj); + } + } + if (list.count()) { + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setPaymentMethods(list); + targetPlace->setBusinessInformation(busInfo); + } + } +} + +QString QPlaceJSonDetailsParser::processAdContentPaymentMethod(const QScriptValue &content) +{ + QString obj; + QScriptValue value = content.property(place_adcontent_paymentmethod_name_element); + if (value.isValid() && !value.toString().isEmpty()) { + obj = value.toString(); + } + return obj; +} + +void QPlaceJSonDetailsParser::processAdContentBusinessHours(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_hours_annualclosingsnotes_element); + if (value.isValid()) { + processAdContentClosingsNotes(value, targetPlace); + } + value = content.property(place_adcontent_hours_open_element); + if (value.isValid()) { + processAdContentOpeningHours(value, targetPlace); + } + value = content.property(place_adcontent_hours_openingnotes_element); + if (value.isValid()) { + processAdContentOpeningNotes(value, targetPlace); + } +} + +void QPlaceJSonDetailsParser::processAdContentClosingsNotes(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_hours_annualclosingsnote_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QString obj = processAdContentClosingsNote(it.value()); + if (!obj.isEmpty()) { + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setAnnualClosingNote(obj); + targetPlace->setBusinessInformation(busInfo); + //! @todo only one is used + break; + } + } + } + } else { + QString obj = processAdContentClosingsNote(value); + if (!obj.isEmpty()) { + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setAnnualClosingNote(obj); + targetPlace->setBusinessInformation(busInfo); + } + } + } +} + +QString QPlaceJSonDetailsParser::processAdContentClosingsNote(const QScriptValue &content) +{ + QString ret; + QScriptValue value = content.property(place_adcontent_hours_annualclosingsnote_v_element); + if (value.isValid() && !value.toString().isEmpty()) { + ret = value.toString(); + } + return ret; +} + +void QPlaceJSonDetailsParser::processAdContentOpeningHours(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_hours_open_hours_element); + if (value.isValid()) { + QList<QPlaceWeekdayHours> list; + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceWeekdayHours *obj = processAdContentOpeningHoursElement(it.value()); + if (obj) { + list.append(*obj); + delete obj; + obj = NULL; + } + } + } + } else { + QPlaceWeekdayHours *obj = processAdContentOpeningHoursElement(value); + if (obj) { + list.append(*obj); + delete obj; + obj = NULL; + } + } + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setOpeningHours(list); + targetPlace->setBusinessInformation(busInfo); + } +} + +QPlaceWeekdayHours *QPlaceJSonDetailsParser::processAdContentOpeningHoursElement(const QScriptValue &content) +{ + QPlaceWeekdayHours *openH = new QPlaceWeekdayHours(); + QScriptValue value = content.property(place_adcontent_hours_open_day_element); + if (value.isValid() && !value.toString().isEmpty()) { + QString day = value.toString(); + if (place_premiumcontent_content_monday == day) { + openH->setWeekday(Qt::Monday); + } else if (place_premiumcontent_content_tuesday == day) { + openH->setWeekday(Qt::Tuesday); + } else if (place_premiumcontent_content_wednesday == day) { + openH->setWeekday(Qt::Wednesday); + } else if (place_premiumcontent_content_thursday == day) { + openH->setWeekday(Qt::Thursday); + } else if (place_premiumcontent_content_friday == day) { + openH->setWeekday(Qt::Friday); + } else if (place_premiumcontent_content_saturday == day) { + openH->setWeekday(Qt::Saturday); + } else if (place_premiumcontent_content_sunday == day) { + openH->setWeekday(Qt::Sunday); + } + } + QTime start, end; + value = content.property(place_adcontent_hours_open_from_element); + if (value.isValid() && !value.toString().isEmpty()) { + start = QTime::fromString(value.toString(),"hh:mm"); + } + value = content.property(place_adcontent_hours_open_to_element); + if (value.isValid() && !value.toString().isEmpty()) { + end = QTime::fromString(value.toString(),"hh:mm"); + } + + QTime startTime; + startTime.setHMS(start.hour(), start.minute(), 0); + QTime endTime; + endTime.setHMS(end.hour(), end.minute(), 0); + QPlacePeriod period; + period.setStartTime(startTime); + period.setEndTime(endTime); + openH->setPeriod(period); + return openH; +} + +void QPlaceJSonDetailsParser::processAdContentOpeningNotes(const QScriptValue &content, QGeoPlace*targetPlace) +{ + QScriptValue value = content.property(place_adcontent_hours_openingnote_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QString obj = processAdContentOpeningNote(it.value()); + if (!obj.isEmpty()) { + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setOpeningNote(obj); + targetPlace->setBusinessInformation(busInfo); + //! @todo only one is used + break; + } + } + } + } else { + QString obj = processAdContentOpeningNote(value); + if (!obj.isEmpty()) { + QPlaceBusinessInformation busInfo = targetPlace->businessInformation(); + busInfo.setOpeningNote(obj); + targetPlace->setBusinessInformation(busInfo); + } + } + } +} + +QString QPlaceJSonDetailsParser::processAdContentOpeningNote(const QScriptValue &content) +{ + QString ret; + QScriptValue value = content.property(place_adcontent_hours_openingnote_v_element); + if (value.isValid() && !value.toString().isEmpty()) { + ret = value.toString(); + } + return ret; +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h new file mode 100644 index 00000000..8c255827 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONDETAILSPARSER_H +#define QPLACEJSONDETAILSPARSER_H + +#include <QObject> +#include <QList> + +#include <qgeoplace.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonDetailsParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonDetailsParser(QObject *parent = 0); + virtual ~QPlaceJSonDetailsParser(); + + static QGeoPlace buildPlace(const QScriptValue &place); + QGeoPlace result(); + +private: + void processJSonData(const QScriptValue &sv); + static void buildPlace(const QScriptValue &place, QGeoPlace *targetPlace); + static void processMainProvider(const QScriptValue &place, QGeoPlace *targetPlace); + static void processContacts(const QScriptValue &contacts, QGeoPlace *targetPlace); + static void processCategories(const QScriptValue &categories, QGeoPlace *targetPlace); + static QPlaceCategory processCategory(const QScriptValue &category); + static void processRatings(const QScriptValue &ratings, QGeoPlace *targetPlace); + static QPlaceRating *processRating(const QScriptValue &rating); + static void processAddress(const QScriptValue &address, QGeoLocation *location); + static void processLocation(const QScriptValue &location, QGeoPlace *targetPlace); + static void processTags(const QScriptValue &locations, QGeoPlace *targetPlace); + static void processNames(const QScriptValue &locations, QGeoPlace *targetPlace); + static QString processName(const QScriptValue &nameValue); + static void processPremiumContents(const QScriptValue &content, QGeoPlace *targetPlace); + static void processPremiumVersion(const QScriptValue &content, QGeoPlace *targetPlace); + static void processPremiumContent(const QScriptValue &content, QGeoPlace *targetPlace); + static void processPremiumContentDescription(const QScriptValue &content, + const QPlaceSupplier &supplier, + QGeoPlace *targetPlace); + static void processPremiumContentMediaObjects(const QScriptValue &content, + const QPlaceSupplier &supplier, + QGeoPlace *targetPlace); + static QPlaceMediaObject *processPremiumContentMediaObject(const QScriptValue &content); + static void processAdContent(const QScriptValue &content, QGeoPlace *targetPlace); + static void processAdContentPackages(const QScriptValue &content, QGeoPlace *targetPlace); + static void processAdContentDescriptions(const QScriptValue &content, QGeoPlace *targetPlace); + static QPlaceDescription *processAdContentDescription(const QScriptValue &content); + static void processAdContentMediaObjects(const QScriptValue &content, QGeoPlace *targetPlace); + static QPlaceMediaObject *processAdContentMediaObject(const QScriptValue &content); + static void processAdContentPaymentMethods(const QScriptValue &content, QGeoPlace *targetPlace); + static QString processAdContentPaymentMethod(const QScriptValue &content); + static void processAdContentBusinessHours(const QScriptValue &content, QGeoPlace *targetPlace); + static void processAdContentClosingsNotes(const QScriptValue &content, QGeoPlace *targetPlace); + static QString processAdContentClosingsNote(const QScriptValue &content); + static void processAdContentOpeningHours(const QScriptValue &content, QGeoPlace *targetPlace); + static QPlaceWeekdayHours *processAdContentOpeningHoursElement(const QScriptValue &content); + static void processAdContentOpeningNotes(const QScriptValue &content, QGeoPlace *targetPlace); + static QString processAdContentOpeningNote(const QScriptValue &content); + +private: + QGeoPlace place; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONDETAILSPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.cpp new file mode 100644 index 00000000..7931ec4e --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsonmediaparser.h" + +#include <QtCore/QUrl> +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include <qplacemediaobject.h> +#include <qplacesupplier.h> +#include "qplacesuppliersrepository.h" + +#include <QtCore/QDebug> + +#if defined(QT_PLACE_LIBRARY) + #include <QDebug> +#endif + +static const char *media_objects_element = "images"; +static const char *media_element = "image"; +static const char *media_count = "totalNumberOfImages"; +static const char *media_url = "url"; +static const char *media_provider_id = "provider"; +static const char *media_provider_name = "providerDisplayName"; + +QT_USE_NAMESPACE + +QPlaceJSonMediaParser::QPlaceJSonMediaParser(QObject *parent) : + QPlaceJSonParser(parent), + allMedia(0) +{ +} + +QPlaceJSonMediaParser::~QPlaceJSonMediaParser() +{ +} + +QList<QPlaceMediaObject> QPlaceJSonMediaParser::resultMedia() +{ + return media; +} + +int QPlaceJSonMediaParser::allMediaCount() +{ + return allMedia; +} + +QPlaceMediaObject QPlaceJSonMediaParser::buildMediaObject(const QScriptValue &media) +{ + QPlaceMediaObject newMedia; + QScriptValue value = media.property(media_url); + if (value.isValid() && !value.toString().isEmpty()) { + newMedia.setUrl(QUrl::fromEncoded(value.toString().toAscii())); + newMedia.setId(value.toString()); + } + + QString name, id, icon; + value = media.property(media_provider_name); + if (value.isValid() && !value.toString().isEmpty()) { + name = value.toString(); + } + value = media.property(media_provider_id); + if (value.isValid() && !value.toString().isEmpty()) { + id = value.toString(); + } + if (!name.isEmpty() || !id.isEmpty()) { + QPlaceSupplier sup; + sup.setName(name); + sup.setSupplierId(id); + newMedia.setSupplier(QPlaceSuppliersRepository::instance()->addSupplier(sup)); + } + + return newMedia; +} + +void QPlaceJSonMediaParser::processJSonData(const QScriptValue &sv) +{ + media.clear(); + + if (sv.isValid()) { + QScriptValue sv2 = sv.property(media_objects_element); + if (sv2.isValid()) { + processMedia(sv2); + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +void QPlaceJSonMediaParser::processMedia(const QScriptValue &mediaElement) +{ + QScriptValue value = mediaElement.property(media_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + media.append(buildMediaObject(it.value())); + } + } + } else { + media.append(buildMediaObject(value)); + } + } + value = mediaElement.property(media_count); + if (value.isValid()) { + allMedia = value.toInt32(); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.h b/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.h new file mode 100644 index 00000000..28265994 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonmediaparser.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONMEDIAPARSER_H +#define QPLACEJSONMEDIAPARSER_H + +#include <QObject> +#include <QList> + +#include <qplacemediaobject.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonMediaParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonMediaParser(QObject *parent = 0); + virtual ~QPlaceJSonMediaParser(); + + QList<QPlaceMediaObject> resultMedia(); + int allMediaCount(); + static QPlaceMediaObject buildMediaObject(const QScriptValue &place); + +private: + void processJSonData(const QScriptValue &sv); + void processMedia(const QScriptValue &contacts); + +private: + QList<QPlaceMediaObject> media; + int allMedia; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONMEDIAPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsonparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonparser.cpp new file mode 100644 index 00000000..c23a4d67 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonparser.cpp @@ -0,0 +1,23 @@ +#include "qplacejsonparser_p.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QPlaceJSonParser::QPlaceJSonParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +void QPlaceJSonParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + QScriptValue sv = engine->evaluate("(" + data + ")"); + processJSonData(sv); +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsonparser_p.h b/src/plugins/geoservices/nokia/places/qplacejsonparser_p.h new file mode 100644 index 00000000..5daa22f0 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonparser_p.h @@ -0,0 +1,33 @@ +#ifndef QPLACEJSONPARSER_P_H +#define QPLACEJSONPARSER_P_H + +#include <QObject> +#include <QStringList> +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> + +class QPlaceJSonParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonParser(QObject *parent = 0); + +signals: + void finished(const QPlaceJSonParser::Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + virtual void processJSonData(const QScriptValue &sv) = 0; + +protected: + QScriptEngine *engine; +}; + +#endif // QPLACEJSONPARSER_P_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp new file mode 100644 index 00000000..c596fe59 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsonrecommendationparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include "qplacejsondetailsparser.h" +#include <qgeoplace.h> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +static const char *recommendations_element = "recommendations"; +static const char *recommendations_nearby_element = "nearby"; +static const char *recommendations_distance_element = "distance"; +static const char *recommendations_place_element = "place"; + +QT_USE_NAMESPACE + +QPlaceJSonRecommendationParser::QPlaceJSonRecommendationParser(QObject *parent) : + QPlaceJSonParser(parent) +{ +} + +QPlaceJSonRecommendationParser::~QPlaceJSonRecommendationParser() +{ +} + +QList<QPlaceSearchResult> QPlaceJSonRecommendationParser::results() +{ + return searchResults; +} + +void QPlaceJSonRecommendationParser::processJSonData(const QScriptValue &sv) +{ + searchResults.clear(); + + if (sv.isValid()) { + QScriptValue sv2 = sv.property(recommendations_element); + if (sv2.isValid()) { + QScriptValueIterator it(sv2.property(recommendations_nearby_element)); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + processResultElement(it.value()); + } + } + emit finished(NoError, QString()); + return; + } + } + emit finished(ParsingError, QString("JSON data are invalid")); +} + +void QPlaceJSonRecommendationParser::processResultElement(const QScriptValue &value) +{ + QPlaceSearchResult result; + result.setType(QPlaceSearchResult::Place); + + // Processing properties + QScriptValue distance = value.property(recommendations_distance_element); + if (distance.isValid() && !distance.toString().isEmpty()) { + bool isConverted; + double distanceValue = distance.toString().toDouble(&isConverted); + if (isConverted) { + result.setDistance(distanceValue); + } + } + QScriptValue place = value.property(recommendations_place_element); + if (place.isValid()) { + QGeoPlace newPlace = QPlaceJSonDetailsParser::buildPlace(place); + result.setPlace(newPlace); + searchResults.append(result); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h new file mode 100644 index 00000000..09f6d783 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONRECOMENDATIONPARSER_H +#define QPLACEJSONRECOMENDATIONPARSER_H + +#include <QObject> +#include <QList> + +#include <qplacesearchresult.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonRecommendationParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonRecommendationParser(QObject *parent = 0); + virtual ~QPlaceJSonRecommendationParser(); + + QList<QPlaceSearchResult> results(); + +private: + void processJSonData(const QScriptValue &sv); + void processResultElement(const QScriptValue &value); + +private: + QList<QPlaceSearchResult> searchResults; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONRECOMENDATIONPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp new file mode 100644 index 00000000..447536a8 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsonreviewparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include <qplacereview.h> +#include <qplacesupplier.h> +#include "qplacesuppliersrepository.h" + +#if defined(QT_PLACES_LIBRARY) + #include <QDebug> +#endif + +static const char *reviews_element = "reviews"; +static const char *review_element = "review"; +static const char *review_count = "totalNumberOfReviews"; +static const char *review_id_element = "a_id"; +static const char *review_date_element = "creationDate"; +static const char *review_description_element = "description"; +static const char *review_minus_element = "minusCount"; +static const char *review_originator_element = "originatorUrl"; +static const char *review_plus_element = "plusCount"; +static const char *review_rating_element = "rating"; +static const char *review_title_element = "title"; +static const char *review_username_element = "user"; +static const char *review_userid_element = "uuid"; +static const char *review_vendor_element = "vendor"; +static const char *review_vendorname_element = "vendorDisplayName"; +static const char *review_vendoricon_element = "vendorIconUrl"; + +QT_USE_NAMESPACE + +QPlaceJSonReviewParser::QPlaceJSonReviewParser(QObject *parent) : + QPlaceJSonParser(parent), + allReviews(0) +{ +} + +QPlaceJSonReviewParser::~QPlaceJSonReviewParser() +{ +} + +QList<QPlaceReview> QPlaceJSonReviewParser::results() +{ + return reviews; +} + +int QPlaceJSonReviewParser::allReviewsCount() +{ + return allReviews; +} + +QPlaceReview QPlaceJSonReviewParser::buildReview(const QScriptValue &review) +{ + QPlaceReview newReview; + QScriptValue value = review.property(review_id_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setReviewId(value.toString()); + } + value = review.property(review_date_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setDate(value.toString()); + } + value = review.property(review_minus_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + int number = value.toString().toInt(&isConverted); + if (isConverted) { + newReview.setUnhelpfulVotings(number); + } + } + value = review.property(review_plus_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + int number = value.toString().toInt(&isConverted); + if (isConverted) { + newReview.setHelpfulVotings(number); + } + } + value = review.property(review_originator_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setOriginatorUrl(value.toString()); + } + value = review.property(review_description_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setDescription(value.toString()); + } + value = review.property(review_title_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setTitle(value.toString()); + } + value = review.property(review_username_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setUserName(value.toString()); + } + value = review.property(review_userid_element); + if (value.isValid() && !value.toString().isEmpty()) { + newReview.setUserId(value.toString()); + } + + QString name, id, icon; + value = review.property(review_vendorname_element); + if (value.isValid() && !value.toString().isEmpty()) { + name = value.toString(); + } + value = review.property(review_vendor_element); + if (value.isValid() && !value.toString().isEmpty()) { + id = value.toString(); + } + value = review.property(review_vendoricon_element); + if (value.isValid() && !value.toString().isEmpty()) { + icon = value.toString(); + } + if (!name.isEmpty() || !id.isEmpty()) { + QPlaceSupplier sup; + sup.setName(name); + sup.setSupplierId(id); + sup.setSupplierIconUrl(icon); + newReview.setSupplier(QPlaceSuppliersRepository::instance()->addSupplier(sup)); + } + + value = review.property(review_rating_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + double number = value.toString().toDouble(&isConverted); + if (isConverted) { + newReview.setRating(number); + } + } + return newReview; +} + +void QPlaceJSonReviewParser::processJSonData(const QScriptValue &sv) +{ + reviews.clear(); + + if (sv.isValid()) { + QScriptValue sv2 = sv.property(reviews_element); + if (sv2.isValid()) { + processReviews(sv2); + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +void QPlaceJSonReviewParser::processReviews(const QScriptValue &reviewsElement) +{ + QScriptValue value = reviewsElement.property(review_element); + if (value.isValid()) { + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + reviews.append(buildReview(it.value())); + } + } + } else { + reviews.append(buildReview(value)); + } + } + value = reviewsElement.property(review_count); + if (value.isValid()) { + allReviews = value.toInt32(); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h new file mode 100644 index 00000000..a72dac1b --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONREVIEWPARSER_H +#define QPLACEJSONREVIEWPARSER_H + +#include <QObject> +#include <QList> + +#include <qplacesearchresult.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonReviewParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonReviewParser(QObject *parent = 0); + virtual ~QPlaceJSonReviewParser(); + + QList<QPlaceReview> results(); + int allReviewsCount(); + static QPlaceReview buildReview(const QScriptValue &place); + +private: + void processJSonData(const QScriptValue &sv); + void processReviews(const QScriptValue &contacts); + +private: + QList<QPlaceReview> reviews; + int allReviews; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONREVIEWPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp new file mode 100644 index 00000000..8e821b03 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.cpp @@ -0,0 +1,400 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsonsearchparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include <qgeocoordinate.h> +#include <qgeoaddress.h> +#include <qgeolocation.h> +#include <qgeoplace.h> +#include <qplacecontact.h> +#include <qplacerating.h> +#include <qplacecategory.h> +#include <qplacesupplier.h> +#include <qplacesearchresult.h> + +#include "qplacesuppliersrepository.h" +#include "qplacecategoriesrepository.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +//search const +static const char *search_results_element = "results"; +static const char *search_type_element = "type"; +static const char *search_type_dym_value = "DID_YOU_MEAN_SEARCH"; +static const char *search_type_addplace_value = "ADPLACE"; + +static const char *search_categories_element = "categories"; +static const char *search_categories_id_value = "id"; +static const char *search_properties_element = "properties"; +static const char *search_properties_title_value = "title"; +static const char *search_properties_distance_value = "geoDistance"; + +static const char *search_properties_placeid_value = "placesId"; +static const char *search_properties_description_value = "description"; +static const char *search_properties_supliers_value = "dataProvider"; +static const char *search_properties_phone_value = "phoneNumber"; +static const char *search_properties_url_value = "url"; +static const char *search_properties_rating_value = "placesRating"; + +static const char *search_properties_longitude_value = "geoLongitude"; +static const char *search_properties_latitude_value = "geoLatitude"; +static const char *search_properties_longitude_bb1_value = "GEO_BBX_LONGITUDE_1"; +static const char *search_properties_latitude_bb1_value = "GEO_BBX_LATITUDE_1"; +static const char *search_properties_longitude_bb2_value = "GEO_BBX_LONGITUDE_2"; +static const char *search_properties_latitude_bb2_value = "GEO_BBX_LATITUDE_2"; + +static const char *search_properties_address_country = "addrCountryName"; +static const char *search_properties_address_county = "addrCountyName"; +static const char *search_properties_address_country_code = "addrCountryCode"; +static const char *search_properties_address_state = "addrStateName"; +static const char *search_properties_address_code = "addrPostalCode"; +static const char *search_properties_address_city = "addrCityName"; +static const char *search_properties_address_district = "addrDistrictName"; +static const char *search_properties_address_street = "addrStreetName"; +static const char *search_properties_address_house_number = "addrHouseNumber"; + +QT_USE_NAMESPACE + +QPlaceJSonSearchParser::QPlaceJSonSearchParser(QObject *parent) : + QPlaceJSonParser(parent) +{ +} + +QPlaceJSonSearchParser::~QPlaceJSonSearchParser() +{ + searchResultsList.clear(); +} + +QList<QPlaceSearchResult> QPlaceJSonSearchParser::searchResults() +{ + return searchResultsList; +} + +void QPlaceJSonSearchParser::processJSonData(const QScriptValue &sv) +{ + searchResultsList.clear(); + + if (sv.isValid()) { + QScriptValue results = sv.property(search_results_element); + if (results.isValid()) { + QScriptValueIterator it(results); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != QLatin1String("length")) { + processResultElement(it.value()); + } + } + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +void QPlaceJSonSearchParser::processResultElement(const QScriptValue &value) +{ + // Procesing DYM string + QScriptValue type = value.property(search_type_element); + if (type.isValid() && type.toString() == search_type_dym_value) { + QScriptValue properties = value.property(search_properties_element); + if (properties.isValid()) { + QScriptValue title = properties.property(search_properties_title_value); + if (title.isValid() && !title.toString().isEmpty()) { + QPlaceSearchResult result; + QScriptValue type = properties.property(search_type_element); + if (type.isValid()) { + result = processPlaceElement(value); + } + result.setType(QPlaceSearchResult::DidYouMeanSuggestion); + result.setDidYouMeanSuggestion(title.toString()); + searchResultsList.append(result); + } + } + // processing place element + } else { + searchResultsList.append(processPlaceElement(value)); + } +} + +QPlaceSearchResult QPlaceJSonSearchParser::processPlaceElement(const QScriptValue &results) +{ + QPlaceSearchResult result; + result.setType(QPlaceSearchResult::Place); + QGeoPlace newPlace; + + // Processing properties + QScriptValue properties = results.property(search_properties_element); + if (properties.isValid()) { + // QSearchResult properties + QScriptValue distance = properties.property(search_properties_distance_value); + if (distance.isValid() && !distance.toString().isEmpty()) { + bool isConverted; + double distanceValue = distance.toString().toDouble(&isConverted); + if (isConverted) { + result.setDistance(distanceValue); + } + } + // Place properties + QScriptValue value = properties.property(search_properties_title_value); + if (value.isValid() && !value.toString().isEmpty()) { + newPlace.setName(value.toString()); + } + value = properties.property(search_type_element); + if (value.isValid() && !value.toString().isEmpty()) { + QVariantHash addData; + QString type = value.toString(); + addData.insert(search_type_element, type); + newPlace.setAdditionalData(addData); + } + value = properties.property(search_properties_placeid_value); + if (value.isValid() && !value.toString().isEmpty()) { + newPlace.setPlaceId(value.toString()); + } + value = properties.property(search_properties_description_value); + if (value.isValid() && !value.toString().isEmpty()) { + newPlace.setShortDescription(value.toString()); + } + value = properties.property(search_properties_supliers_value); + if (value.isValid() && !value.toString().isEmpty()) { + QPlaceSupplier sup; + sup.setName(value.toString()); + QList<QPlaceSupplier> list; + list.append(QPlaceSuppliersRepository::instance()->addSupplier(sup)); + newPlace.setSuppliers(list); + } + processContacts(properties, &newPlace); + processRating(properties, &newPlace); + processLocation(properties, &newPlace); + + value = results.property(search_categories_element); + if (value.isValid()) { + processCategories(value, &newPlace); + } + } + result.setPlace(newPlace); + return result; +} + +void QPlaceJSonSearchParser::processContacts(const QScriptValue &properties, QGeoPlace *place) +{ + QList<QPlaceContact> contacts; + QScriptValue value = properties.property(search_properties_url_value); + if (value.isValid() && !value.toString().isEmpty()) { + QPlaceContact contact; + contact.setType(QPlaceContact::Url); + contact.setValue(value.toString()); + contacts.append(contact); + } + value = properties.property(search_properties_phone_value); + if (value.isValid() && !value.toString().isEmpty()) { + QPlaceContact contact; + contact.setType(QPlaceContact::Phone); + contact.setValue(value.toString()); + contacts.append(contact); + } + place->setContacts(contacts); +} + + +void QPlaceJSonSearchParser::processCategories(const QScriptValue &categories, QGeoPlace *place) +{ + QList<QPlaceCategory> categoriesList; + QScriptValueIterator it(categories); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QScriptValue value = it.value().property(search_categories_id_value); + if (value.isValid() && !value.toString().isEmpty()) { + QPlaceCategory category = QPlaceCategoriesRepository::instance()->mapCategory( + value.toString()); + if (!category.categoryId().isEmpty()) { + categoriesList.append(category); + } + } + } + } + place->setCategories(categoriesList); +} + +void QPlaceJSonSearchParser::processRating(const QScriptValue &properties, QGeoPlace *place) +{ + QScriptValue value = properties.property(search_properties_rating_value); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + double ratingValue = value.toString().toDouble(&isConverted); + if (isConverted) { + QPlaceRating rating; + rating.setValue(ratingValue); + place->setRating(rating); + } + } +} + +void QPlaceJSonSearchParser::processAddress(const QScriptValue &properties, QGeoLocation *location) +{ + QGeoAddress newAddress; + QScriptValue value = properties.property(search_properties_address_country); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCountry(value.toString()); + } + value = properties.property(search_properties_address_county); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCounty(value.toString()); + } + value = properties.property(search_properties_address_country_code); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCountry(value.toString()); + } + value = properties.property(search_properties_address_state); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setState(value.toString()); + } + value = properties.property(search_properties_address_code); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setPostcode(value.toString()); + } + value = properties.property(search_properties_address_city); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCity(value.toString()); + } + value = properties.property(search_properties_address_district); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setDistrict(value.toString()); + } + value = properties.property(search_properties_address_street); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setStreet(value.toString()); + } + value = properties.property(search_properties_address_house_number); + if (value.isValid() && !value.toString().isEmpty()) { + //TODO: need to figure out how to deal with street number + //and whether to keep it separate from street. + newAddress.setStreet(value.toString() + " " + newAddress.street()); + } + location->setAddress(newAddress); +} + +void QPlaceJSonSearchParser::processLocation(const QScriptValue &properties, QGeoPlace *place) +{ + QGeoLocation location; + + bool latOK(false); + bool lonOK(false); + double latitude; + double longitude; + + // display position + QScriptValue value = properties.property(search_properties_latitude_value); + if (value.isValid() && !value.toString().isEmpty()) { + latitude = value.toString().toDouble(&latOK); + } + value = properties.property(search_properties_longitude_value); + if (value.isValid() && !value.toString().isEmpty()) { + longitude = value.toString().toDouble(&lonOK); + } + if (latOK && lonOK) { + QGeoCoordinate pos; + pos.setLatitude(latitude); + pos.setLongitude(longitude); + location.setCoordinate(pos); + } + + // bounding box + QGeoCoordinate bottomRight; + QGeoCoordinate topLeft; + latOK = false; + lonOK = false; + value = properties.property(search_properties_latitude_bb1_value); + if (value.isValid() && !value.toString().isEmpty()) { + latitude = value.toString().toDouble(&latOK); + } + value = properties.property(search_properties_longitude_bb1_value); + if (value.isValid() && !value.toString().isEmpty()) { + longitude = value.toString().toDouble(&lonOK); + } + if (latOK && lonOK) { + topLeft.setLatitude(latitude); + topLeft.setLongitude(longitude); + } + + latOK = false; + lonOK = false; + value = properties.property(search_properties_latitude_bb2_value); + if (value.isValid() && !value.toString().isEmpty()) { + latitude = value.toString().toDouble(&latOK); + } + value = properties.property(search_properties_longitude_bb2_value); + if (value.isValid() && !value.toString().isEmpty()) { + longitude = value.toString().toDouble(&lonOK); + } + if (latOK && lonOK) { + bottomRight.setLatitude(latitude); + bottomRight.setLongitude(longitude); + } + + if (topLeft.isValid() && bottomRight.isValid()) { + QGeoBoundingBox boundingBox; + boundingBox.setTopLeft(topLeft); + boundingBox.setBottomRight(bottomRight); + location.setViewport(boundingBox); + } + + processAddress(properties, &location); + place->setLocation(location); +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.h b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.h new file mode 100644 index 00000000..866c49eb --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsonsearchparser.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONSEARCHPARSER_H +#define QPLACEJSONSEARCHPARSER_H + +#include <QObject> +#include <QList> + +#include <qplacecategory.h> +#include <qplacesearchresult.h> + +#include "qplacejsonparser_p.h" + +class QScriptEngine; +class QScriptValue; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonSearchParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonSearchParser(QObject *parent = 0); + virtual ~QPlaceJSonSearchParser(); + + QList<QPlaceSearchResult> searchResults(); + +private: + void processJSonData(const QScriptValue &sv); + void processResultElement(const QScriptValue &value); + QPlaceSearchResult processPlaceElement(const QScriptValue &value); + void processContacts(const QScriptValue &properties, QGeoPlace *place); + void processCategories(const QScriptValue &categories, QGeoPlace *place); + void processRating(const QScriptValue &properties, QGeoPlace *place); + void processAddress(const QScriptValue &properties, QGeoLocation *location); + void processLocation(const QScriptValue &properties, QGeoPlace *place); +private: + QList<QPlaceSearchResult> searchResultsList; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONSEARCHPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.cpp new file mode 100644 index 00000000..1b4e64b4 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacejsontextpredictionparser.h" + +#include <QtScript/QScriptEngine> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +QPlaceJSonTextPredictionParser::QPlaceJSonTextPredictionParser(QObject *parent) : + QPlaceJSonParser(parent) +{ +} + +QStringList QPlaceJSonTextPredictionParser::predictions() +{ + return suggestions; +} + +void QPlaceJSonTextPredictionParser::processJSonData(const QScriptValue &sv) +{ + suggestions.clear(); + + if (sv.isValid() && sv.isArray()) { + qScriptValueToSequence(sv, suggestions); + +#if defined(QT_PLACES_LOGGING) + qDebug() << "QJSonParserSuggestions::processData - list value: "; + foreach (QString str, suggestions) { + qDebug() << str; + } +#endif + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.h b/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.h new file mode 100644 index 00000000..d12b087a --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacejsontextpredictionparser.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEJSONTEXTPREDICTIONPARSER_H +#define QPLACEJSONTEXTPREDICTIONPARSER_H + +#include <QObject> +#include <QStringList> + +#include <qmobilityglobal.h> +#include "qplacejsonparser_p.h" + +class QScriptEngine; + +QT_BEGIN_NAMESPACE + +class QPlaceJSonTextPredictionParser : public QPlaceJSonParser +{ + Q_OBJECT +public: + explicit QPlaceJSonTextPredictionParser(QObject *parent = 0); + + QStringList predictions(); + +private: + void processJSonData(const QScriptValue &sv); + QStringList suggestions; +}; + +QT_END_NAMESPACE + +#endif // QPLACEJSONTEXTPREDICTIONPARSER_H diff --git a/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.cpp new file mode 100644 index 00000000..4a179e39 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacemediareplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceMediaReplyImpl::QPlaceMediaReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceMediaReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonMediaParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + parser, SLOT(processData(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceMediaReplyImpl::~QPlaceMediaReplyImpl() +{ +} + +void QPlaceMediaReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceMediaReplyImpl::setStartNumber(int number) +{ + setOffset(number); +} + +void QPlaceMediaReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceMediaReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + setMediaObjects(parser->resultMedia()); + setTotalCount(parser->allMediaCount()); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.h b/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.h new file mode 100644 index 00000000..80b78bc2 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacemediareplyimpl.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEMEDIAREPLYIMPL_H +#define QPLACEMEDIAREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacemediareply.h> +#include "qplacerestreply.h" +#include "qplacejsonmediaparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceMediaReplyImpl : public QPlaceMediaReply +{ + Q_OBJECT +public: + explicit QPlaceMediaReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceMediaReplyImpl(); + void abort(); + void setStartNumber(int number); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonMediaParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACEMEDIAREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.cpp new file mode 100644 index 00000000..5e479e43 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplaceratingreplyimpl.h" + +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceRatingReplyImpl::QPlaceRatingReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceReply(parent), + restReply(reply) +{ + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + this, SLOT(restFinished(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + } +} + +/*! + Destructor. +*/ +QPlaceRatingReplyImpl::~QPlaceRatingReplyImpl() +{ +} + +void QPlaceRatingReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceRatingReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceRatingReplyImpl::restFinished(const QString &data) +{ + Q_UNUSED(data); + setFinished(true); + emit finished(); + emit processingFinished(this); + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.h b/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.h new file mode 100644 index 00000000..b9e9b080 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplaceratingreplyimpl.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACERATINGREPLYIMPL_H +#define QPLACERATINGREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacereply.h> +#include "qplacerestreply.h" + +QT_BEGIN_NAMESPACE + +class QPlaceRatingReplyImpl : public QPlaceReply +{ + Q_OBJECT +public: + explicit QPlaceRatingReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceRatingReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void restFinished(const QString &data); + +private: + QPlaceRestReply *restReply; +}; + +QT_END_NAMESPACE + +#endif // QPLACERATINGREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp new file mode 100644 index 00000000..0873f640 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacerecommendationreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceRecommendationReplyImpl::QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceSearchReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonRecommendationParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + parser, SLOT(processData(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceRecommendationReplyImpl::~QPlaceRecommendationReplyImpl() +{ +} + +void QPlaceRecommendationReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceRecommendationReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceRecommendationReplyImpl::resultReady(const QPlaceJSonRecommendationParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + setResults(parser->results()); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h new file mode 100644 index 00000000..ff689769 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACERECOMMENDATIONREPLYIMPL_H +#define QPLACERECOMMENDATIONREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacesearchreply.h> +#include "qplacerestreply.h" +#include "qplacejsonrecommendationparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceRecommendationReplyImpl : public QPlaceSearchReply +{ + Q_OBJECT +public: + explicit QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceRecommendationReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonRecommendationParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACERECOMMENDATIONREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacerestmanager.cpp b/src/plugins/geoservices/nokia/places/qplacerestmanager.cpp new file mode 100644 index 00000000..35fd4129 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerestmanager.cpp @@ -0,0 +1,289 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacerestmanager.h" + +#include <QtNetwork> +#include <QHash> + +#include <qplacesearchquery.h> +#include <qgeoboundingcircle.h> +#include <qgeoboundingbox.h> +#include "qplacerestreply.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +const char *placesServerUrl = "http://places.maps.ovi.com/rest/v1/places/"; +const char *searchServerUrl = "http://where.desktop.mos.svc.ovi.com/NOSe/json"; +const char *recomendation = "/recommendations/nearby"; +const char *reviews = "/reviews"; +const char *images = "/images"; +const char *categoriesTree = "categories/find-places/grouped"; + +const char *const_query = "&q="; +const char *const_lat = "&lat="; +const char *const_lon = "&lon="; +const char *const_top = "&vpn="; +const char *const_bottom = "&vps="; +const char *const_left = "&vpw="; +const char *const_right = "&vpe="; +const char *const_limit = "&to="; +const char *const_offset = "&of="; +const char *const_dym = "&dym="; +const char *const_views = "?vi=where"; // address, poi or where (both) +const char *const_deviceproductid = "&dv=oviMaps"; // oviMaps, ml, rv + +const char *const_review_start = ";start="; +const char *const_review_limit = ";limit="; + +static QString searchServer; +static QString placeServer; + +QPlaceRestManager *QPlaceRestManager::mInstance = NULL; + +/*! + Constructor. +*/ +QPlaceRestManager::QPlaceRestManager(QObject *parent) : + QObject(parent) +{ + mManager = new QNetworkAccessManager(this); + + if (searchServer.isNull()) { + QSettings settings("Nokia"); + // no app name, they are in Nokia/OrganizationDefaults + searchServer = settings.value("searchURI").toString(); + if (searchServer.isEmpty()) { + searchServer = searchServerUrl; + } + placeServer = settings.value("placesURI").toString(); + if (placeServer.isEmpty()) { + placeServer = placesServerUrl; + } + } +} + +/*! + Method creating instance of rest provider. +*/ +QPlaceRestManager *QPlaceRestManager::instance() +{ + if (!mInstance) { + mInstance = new QPlaceRestManager(); + } + return mInstance; +} + +/*! + Predefines a places request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendPlaceRequest(const QString &placeId) +{ + return sendGeneralRequest(placeServer + placeId); +} + +QPlaceRestReply *QPlaceRestManager::sendPlaceImagesRequest(const QString &placeId, const QPlaceQuery ¶ms) +{ + QString query = placeServer + placeId + images; + if (params.offset() > -1) { + query += const_review_start + QString::number(params.offset()); + } + if (params.limit() > 0) { + query += const_review_limit + QString::number(params.limit()); + } + return sendGeneralRequest(query); +} + +/*! + Predefines a review request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendPlaceReviewRequest(const QString &placeId, const QPlaceQuery ¶ms) +{ + QString query = placeServer + placeId + reviews; + if (params.offset() > -1) { + query += const_review_start + QString::number(params.offset()); + } + if (params.limit() > 0) { + query += const_review_limit + QString::number(params.limit()); + } + + return sendGeneralRequest(query); +} + +/*! + Predefines a recomendation request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendRecommendationRequest(const QPlaceSearchQuery &query, const QString &userId) +{ + Q_UNUSED(userId); + return sendGeneralRequest(placeServer + query.searchTerm() + recomendation); +} + +/*! + Predefines a categories tree request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendCategoriesTreeRequest() +{ + return sendGeneralRequest(placeServer + categoriesTree); +} + +/*! + Predefines a suggestion request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendSuggestionRequest(const QPlaceSearchQuery &query) +{ + return sendGeneralRequest(prepareSearchRequest(query) + + const_query + query.searchTerm() + "&lh=1"); +} + +/*! + Predefines a search request and executes sendGeneralRequest(). +*/ +QPlaceRestReply *QPlaceRestManager::sendSearchRequest(const QPlaceSearchQuery &query) +{ + return sendGeneralRequest(prepareSearchRequest(query) + + const_query + query.searchTerm()); +} + +QPlaceRestReply *QPlaceRestManager::postRatingRequest(const QString &placeId, const QString &userId, const int &value) +{ + QNetworkRequest request; + + QString url = placesServerUrl + placeId + "/ugc/ratings"; + request.setUrl(url); + + QByteArray language; + language.append(QLocale::system().name().toLatin1()); + language.append(","); + language.append(QLocale::system().name().left(2).toLatin1()); + + request.setRawHeader("Accept-Language", language); + request.setRawHeader("Content-Type", "application/json"); + request.setRawHeader("Accept", "application/json"); + request.setRawHeader("X-Ovi-NcimUser", userId.toUtf8()); + +#if defined(QPLACES_LOGGING) + qDebug() << "QRestDataProvider::sendGeneralRequest: " + url; +#endif + QByteArray data = "{ratings:{rating:[{value:" + QString::number(value).toAscii() + ",type:OVERALL}]}}"; + return new QPlaceRestReply(mManager->post(request, data)); +} + +/*! + Sends a general predefined request. Is private. +*/ +QPlaceRestReply *QPlaceRestManager::sendGeneralRequest(const QUrl &url) +{ + QNetworkRequest request; + request.setUrl(url); + + QByteArray language; + language.append(QLocale::system().name().toLatin1()); + language.append(","); + language.append(QLocale::system().name().toLatin1()); + +#if defined(QPLACES_LOGGING) + qDebug() << "QRestDataProvider::sendGeneralRequest: Language - " + language; +#endif + + request.setRawHeader("Accept-Language", language); + +#if defined(QPLACES_LOGGING) + qDebug() << "QRestDataProvider::sendGeneralRequest: " + url.toString(); +#endif + + return new QPlaceRestReply(mManager->get(request)); +} + +/*! + Returns prepared search string. +*/ +QString QPlaceRestManager::prepareSearchRequest(const QPlaceSearchQuery &query) +{ + QString searchString(searchServer); + // add view and device parameters + searchString += const_views; + searchString += const_deviceproductid; + // process search center + if (query.searchArea() != NULL) { + if (query.searchArea()->type() == QGeoBoundingArea::CircleType) { + QGeoBoundingCircle * circle = static_cast<QGeoBoundingCircle *>(query.searchArea()); + searchString += const_lat + QString::number(circle->center().latitude()); + searchString += const_lon + QString::number(circle->center().longitude()); + } else if (query.searchArea()->type() == QGeoBoundingArea::BoxType) { + QGeoBoundingBox *box = static_cast<QGeoBoundingBox *> (query.searchArea()); + searchString += const_top + QString::number(box->topLeft().latitude()); + searchString += const_left + QString::number(box->topLeft().longitude()); + searchString += const_bottom + QString::number(box->bottomRight().latitude()); + searchString += const_right + QString::number(box->bottomRight().longitude()); + } + } + + // processing limit + if (query.limit() > 0){ + searchString += const_limit + QString::number(query.limit()); + } + // processing offset + if (query.offset() > -1){ + searchString += const_offset + QString::number(query.offset()); + } + // process DYM + if (query.didYouMeanSuggestionNumber() > 0){ + searchString += const_dym + QString::number(query.didYouMeanSuggestionNumber()); + } + +#if defined(QPLACES_LOGGING) + qDebug() << "QRestDataProvider::prepareSearchRequest: " + searchString; +#endif + + return searchString; +} diff --git a/src/plugins/geoservices/nokia/places/qplacerestmanager.h b/src/plugins/geoservices/nokia/places/qplacerestmanager.h new file mode 100644 index 00000000..b86d0473 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerestmanager.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACERESTMANAGER_H +#define QPLACERESTMANAGER_H + +#include <QObject> + +#include <QtNetwork/QNetworkProxy> +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkReply> + +#include <qmobilityglobal.h> +#include <qplacesearchquery.h> +#include "qplacerestreply.h" + +QT_BEGIN_NAMESPACE + +class QPlaceRestManager : public QObject +{ + Q_OBJECT + +public: + static QPlaceRestManager *instance(); + + QPlaceRestReply *sendPlaceRequest(const QString &placeId); + QPlaceRestReply *sendPlaceImagesRequest(const QString &placeId, const QPlaceQuery ¶ms); + QPlaceRestReply *sendPlaceReviewRequest(const QString &placeId, const QPlaceQuery ¶ms); + QPlaceRestReply *sendRecommendationRequest(const QPlaceSearchQuery &query, const QString &userId); + QPlaceRestReply *sendCategoriesTreeRequest(); + QPlaceRestReply *sendSearchRequest(const QPlaceSearchQuery &query); + QPlaceRestReply *sendSuggestionRequest(const QPlaceSearchQuery &query); + + QPlaceRestReply *postRatingRequest(const QString &placeId, const QString &userId, const int &value); + +private: + explicit QPlaceRestManager(QObject *parent = 0); + QPlaceRestReply *sendGeneralRequest(const QUrl &url); + //TODO: remove when engine is refactored out + QPlaceRestReply *sendGeneralRequest(const QString &url) { + return sendGeneralRequest(QUrl(url)); + } + + QString prepareSearchRequest(const QPlaceSearchQuery &query); + +private: + QNetworkAccessManager *mManager; + static QPlaceRestManager *mInstance; +}; + +QT_END_NAMESPACE + +#endif // QPLACERESTMANAGER_H diff --git a/src/plugins/geoservices/nokia/places/qplacerestreply.cpp b/src/plugins/geoservices/nokia/places/qplacerestreply.cpp new file mode 100644 index 00000000..f08e57f4 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerestreply.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacerestreply.h" + +#include <QtNetwork> +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceRestReply::QPlaceRestReply(QNetworkReply *reply, QObject *parent) : + QObject(parent), + mReply(reply), + mCanceled(false) +{ + if (mReply) { + connect(mReply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(replyError(QNetworkReply::NetworkError))); + connect(mReply, SIGNAL(finished()), this, SLOT(replyFinished())); + } +} + +/*! + Destructor. +*/ +QPlaceRestReply::~QPlaceRestReply() +{ +#if defined(QT_PLACES_LOGGING) + qDebug() << "QRestReply::~QRestReply"; +#endif + if (mReply) { + if (!mReply->isFinished()) { + mReply->disconnect(this); + mReply->abort(); + } + mReply->deleteLater(); + } +} + +/*! + Emits signal 'replyReady' if request is done. +*/ +void QPlaceRestReply::replyFinished() +{ +#if defined(QT_PLACES_LOGGING) + qDebug() << "QRestReply::replyFinished"; +#endif + if (!mCanceled && (mReply->error() == QNetworkReply::NoError)) { + QByteArray response = mReply->readAll(); + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); + QString string = codec->toUnicode(response); +#if defined(QT_PLACES_LOGGING) + qDebug() << "Data received: " + string; +#endif + emit finished(string); + } else if (mCanceled) { +#if defined(QT_PLACES_LOGGING) + qDebug() << "Canceled"; +#endif + emit error(QPlaceRestReply::Canceled); + } else { +#if defined(QT_PLACES_LOGGING) + qDebug() << "Network Error - " + QString::number(error); +#endif + emit error(QPlaceRestReply::NetworkError); + } + + mReply->deleteLater(); + mReply = NULL; +} + +void QPlaceRestReply::replyError(QNetworkReply::NetworkError error) +{ +#if defined(QT_PLACES_LOGGING) + qDebug() << "QRestReply::replyError: Network Error - " + QString::number(error); +#else + Q_UNUSED(error); +#endif +} + +void QPlaceRestReply::cancelProcessing() +{ +#if defined(QT_PLACES_LOGGING) + qDebug() << "QRestReply::cancelProcessing"; +#endif + mCanceled = true; + if (mReply && mReply->isRunning()) { + mReply->abort(); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacerestreply.h b/src/plugins/geoservices/nokia/places/qplacerestreply.h new file mode 100644 index 00000000..9429583f --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacerestreply.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACERESTREPLY_H +#define QPLACERESTREPLY_H + +#include <QObject> +#include <QHash> +#include <QtNetwork/QNetworkProxy> +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkReply> + +#include <qmobilityglobal.h> + +QT_BEGIN_NAMESPACE + +class QPlaceRestReply : public QObject +{ + Q_OBJECT +public: + explicit QPlaceRestReply(QNetworkReply *reply, QObject *parent = 0); + enum Error { + NoError, + Canceled, + NetworkError + }; + + ~QPlaceRestReply(); + + void cancelProcessing(); + +signals: + void finished(const QString &reply); + void error(QPlaceRestReply::Error error); + +public slots: + void replyFinished(); + void replyError(QNetworkReply::NetworkError error); + +private: + QNetworkReply *mReply; + bool mCanceled; + +friend class QRestManager; +}; + +QT_END_NAMESPACE + +#endif // QPLACERESTREPLY_H diff --git a/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.cpp new file mode 100644 index 00000000..ffeade55 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacereviewreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceReviewReplyImpl::QPlaceReviewReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceReviewReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonReviewParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + parser, SLOT(processData(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceReviewReplyImpl::~QPlaceReviewReplyImpl() +{ +} + +void QPlaceReviewReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceReviewReplyImpl::setStartNumber(int number) +{ + setOffset(number); +} + +void QPlaceReviewReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceReviewReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + setReviews(parser->results()); + setTotalCount(parser->allReviewsCount()); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.h new file mode 100644 index 00000000..fd374074 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacereviewreplyimpl.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEREVIEWREPLYIMPL_H +#define QPLACEREVIEWREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacereviewreply.h> +#include "qplacerestreply.h" +#include "qplacejsonreviewparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceReviewReplyImpl : public QPlaceReviewReply +{ + Q_OBJECT +public: + explicit QPlaceReviewReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceReviewReplyImpl(); + void abort(); + void setStartNumber(int number); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonReviewParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACEREVIEWREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.cpp new file mode 100644 index 00000000..43952055 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacesearchreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceSearchReplyImpl::QPlaceSearchReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceSearchReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonSearchParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + parser, SLOT(processData(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceSearchReplyImpl::~QPlaceSearchReplyImpl() +{ +} + +void QPlaceSearchReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceSearchReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceSearchReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + setResults(filterSecondSearchCenter(parser->searchResults())); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} + +QList<QPlaceSearchResult> QPlaceSearchReplyImpl::filterSecondSearchCenter(const QList<QPlaceSearchResult> &list) +{ + QList<QPlaceSearchResult> newList; + foreach (QPlaceSearchResult res, list) { + if (res.type() == QPlaceSearchResult::Place) { + bool isNotSeconSearchCenter = true; + foreach (QPlaceCategory cat, res.place().categories()) { + if (cat.categoryId() == "second-search-center") { + isNotSeconSearchCenter = false; + break; + } + } + if (isNotSeconSearchCenter) { + newList.append(res); + } + } else if (res.type() == QPlaceSearchResult::DidYouMeanSuggestion) { + newList.append(res); + } + } + return newList; +} + diff --git a/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.h new file mode 100644 index 00000000..d55973f0 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacesearchreplyimpl.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACESEARCHREPLYIMPL_H +#define QPLACESEARCHREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacesearchreply.h> +#include "qplacerestreply.h" +#include "qplacejsonsearchparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceSearchReplyImpl : public QPlaceSearchReply +{ + Q_OBJECT +public: + explicit QPlaceSearchReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceSearchReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QList<QPlaceSearchResult> filterSecondSearchCenter(const QList<QPlaceSearchResult> &list); + QPlaceRestReply *restReply; + QPlaceJSonSearchParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACESEARCHREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp new file mode 100644 index 00000000..e60b7b4a --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacesuppliersrepository.h" + +#include <qplacesupplier.h> + +QT_USE_NAMESPACE + +QPlaceSuppliersRepository *QPlaceSuppliersRepository::instance() +{ + static QPlaceSuppliersRepository instance; + return &instance; +} + +QPlaceSuppliersRepository::QPlaceSuppliersRepository(QObject *parent) + : QObject(parent) +{ +} + +QPlaceSuppliersRepository::~QPlaceSuppliersRepository() +{ + suppliers.clear(); +} + +QPlaceSupplier QPlaceSuppliersRepository::addSupplier(const QPlaceSupplier &src) +{ + QPlaceSupplier res; + QPlaceSupplier tmp; + + foreach (tmp, suppliers) { + if ((!src.supplierId().isEmpty() && src.supplierId() == tmp.supplierId()) + || (!src.name().isEmpty() && src.name() == tmp.name())) { + copyMissingData(src, tmp); + res = tmp; + break; + } + } + if (res.supplierId().isEmpty() && res.name().isEmpty()) { + res = src; + suppliers.append(res); + } + return res; +} + +void QPlaceSuppliersRepository::copyMissingData(const QPlaceSupplier &src, + QPlaceSupplier &target) +{ + if (target.name().isEmpty() && !src.name().isEmpty()) { + target.setName(src.name()); + } + if (target.supplierId().isEmpty() && !src.supplierId().isEmpty()) { + target.setSupplierId(src.supplierId()); + } + if (target.url().isEmpty() && !src.url().isEmpty()) { + target.setUrl(src.url()); + } + if (target.supplierIconUrl().isEmpty() && !src.supplierIconUrl().isEmpty()) { + target.setSupplierIconUrl(src.supplierIconUrl()); + } +} diff --git a/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.h b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.h new file mode 100644 index 00000000..99d21bd8 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACESUPPLIERSREPOSITORY_H +#define QPLACESUPPLIERSREPOSITORY_H + +#include <QObject> +#include <QList> + +#include <qplacesupplier.h> +#include <qmobilityglobal.h> + +QT_BEGIN_NAMESPACE + +class QPlaceSuppliersRepository : public QObject +{ +public: + static QPlaceSuppliersRepository *instance(); + ~QPlaceSuppliersRepository(); + + QPlaceSupplier addSupplier(const QPlaceSupplier &src); +private: + explicit QPlaceSuppliersRepository(QObject *parent = 0); + +private: + void copyMissingData(const QPlaceSupplier &src, QPlaceSupplier &target); + + QList<QPlaceSupplier> suppliers; +}; + +QT_END_NAMESPACE + +#endif // QPLACESUPPLIERSREPOSITORY_H diff --git a/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.cpp new file mode 100644 index 00000000..d4104701 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacetextpredictionreplyimpl.h" + +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +QT_USE_NAMESPACE + +/*! + Constructor. +*/ +QPlaceTextPredictionReplyImpl::QPlaceTextPredictionReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceTextPredictionReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonTextPredictionParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &)), + parser, SLOT(processData(const QString &))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonParser::Error,QString)), + this, SLOT(resultReady(QPlaceJSonParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceTextPredictionReplyImpl::~QPlaceTextPredictionReplyImpl() +{ +} + +void QPlaceTextPredictionReplyImpl::abort() +{ + if (restReply) + restReply->cancelProcessing(); +} + +void QPlaceTextPredictionReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "RequestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + setFinished(true); + emit finished(); + emit processingFinished(this); +} + +void QPlaceTextPredictionReplyImpl::resultReady(const QPlaceJSonParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonParser::NoError) { + setTextPredictions(parser->predictions()); + } else if (errorId == QPlaceJSonParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + setFinished(true); + emit finished(); + emit processingFinished(this); + parser->deleteLater(); + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.h new file mode 100644 index 00000000..bc660b02 --- /dev/null +++ b/src/plugins/geoservices/nokia/places/qplacetextpredictionreplyimpl.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACETEXTPREDICTIONREPLYIMPL_H +#define QPLACETEXTPREDICTIONREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include <qplacetextpredictionreply.h> +#include "qplacerestreply.h" +#include "qplacejsontextpredictionparser.h" + +QT_BEGIN_NAMESPACE + +class QPlaceTextPredictionReplyImpl : public QPlaceTextPredictionReply +{ + Q_OBJECT +public: + explicit QPlaceTextPredictionReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceTextPredictionReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, + const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void resultReady(const QPlaceJSonParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonTextPredictionParser *parser; +}; + +QT_END_NAMESPACE + +#endif // QPLACETEXTPREDICTIONREPLYIMPL_H diff --git a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp index ae6d9a1a..bd79ee8d 100644 --- a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp @@ -51,6 +51,7 @@ #include "qgeosearchmanagerengine_nokia.h" #include "qgeoroutingmanagerengine_nokia.h" #include "qgeomappingmanagerengine_nokia.h" +#include "qplacemanagerengine_nokia.h" #include <QtPlugin> #include <QNetworkProxy> @@ -92,6 +93,13 @@ QGeoRoutingManagerEngine* QGeoServiceProviderFactoryNokia::createRoutingManagerE return new QGeoRoutingManagerEngineNokia(parameters, error, errorString); } +QPlaceManagerEngine *QGeoServiceProviderFactoryNokia::createPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const +{ + return new QPlaceManagerEngineNokia(parameters, error, errorString); +} + 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 0013f40d..97496fdf 100644 --- a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h +++ b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.h @@ -74,6 +74,9 @@ public: QGeoRoutingManagerEngine* createRoutingManagerEngine(const QMap<QString, QVariant> ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const; + QPlaceManagerEngine *createPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; static const QString defaultToken; static const QString defaultReferer; diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp new file mode 100644 index 00000000..c7281adb --- /dev/null +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 "qplacemanagerengine_nokia.h" + +#include "places/qplacecategoriesrepository.h" +#include "places/qplacetextpredictionreplyimpl.h" +#include "places/qplacesearchreplyimpl.h" +#include "places/qplacereviewreplyimpl.h" +#include "places/qplacemediareplyimpl.h" +#include "places/qplacerecommendationreplyimpl.h" +#include "places/qplacedetailsreplyimpl.h" +#include "places/qplaceratingreplyimpl.h" +#include "places/qplacerestmanager.h" +#include "places/qplacerestreply.h" + +QT_USE_NAMESPACE + +QPlaceManagerEngineNokia::QPlaceManagerEngineNokia(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) +: QPlaceManagerEngine(parameters) +{ + if (error) + *error = QGeoServiceProvider::NoError; + + if (errorString) + errorString->clear(); +} + +QPlaceManagerEngineNokia::~QPlaceManagerEngineNokia() +{ +} + +QPlaceDetailsReply *QPlaceManagerEngineNokia::getPlaceDetails(const QString &placeId) +{ + QPlaceDetailsReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceRequest(placeId); + if (restReply) { + reply = new QPlaceDetailsReplyImpl(restReply, this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceMediaReply *QPlaceManagerEngineNokia::getMedia(const QGeoPlace &place, const QPlaceQuery &query) +{ + QPlaceMediaReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceImagesRequest(place.placeId(), + query); + if (restReply) { + reply = new QPlaceMediaReplyImpl(restReply, this); + reply->setStartNumber(query.offset()); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceReply *QPlaceManagerEngineNokia::postRating(const QString &placeId, qreal value) +{ + QPlaceRatingReplyImpl *reply = NULL; + //TODO: need to post user name + QPlaceRestReply *restReply = QPlaceRestManager::instance()->postRatingRequest(placeId, + QString(), + value); + if (restReply) { + reply = new QPlaceRatingReplyImpl(restReply, this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceReviewReply *QPlaceManagerEngineNokia::getReviews(const QGeoPlace &place, const QPlaceQuery &query) +{ + QPlaceReviewReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceReviewRequest(place.placeId(), + query); + if (restReply) { + reply = new QPlaceReviewReplyImpl(restReply, this); + reply->setStartNumber(query.offset()); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceSearchReply *QPlaceManagerEngineNokia::searchForPlaces(const QPlaceSearchQuery &query, QPlaceManager::VisibilityScope scope) +{ + //TODO: handling of scope + QPlaceSearchReplyImpl *reply = NULL; + QPlaceSearchQuery newQuery = query; + // search by category + if (newQuery.categories().count()) { + newQuery.setSearchTerm(query.categories().at(0).name()); + } + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendSearchRequest(newQuery); + + if (restReply) { + reply = new QPlaceSearchReplyImpl(restReply, this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceManager::VisibilityScopes QPlaceManagerEngineNokia::supportedSearchVisibilityScopes() const +{ + return QPlaceManager::PublicScope; +} + +QPlaceSearchReply *QPlaceManagerEngineNokia::recommendations(const QGeoPlace &place, const QPlaceSearchQuery &query) +{ + QPlaceRecommendationReplyImpl *reply = NULL; + QPlaceSearchQuery newQuery = query; + newQuery.setSearchTerm(place.placeId()); + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendRecommendationRequest(newQuery, QString()); + if (restReply) { + reply = new QPlaceRecommendationReplyImpl(restReply, this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceTextPredictionReply *QPlaceManagerEngineNokia::textPredictions(const QPlaceSearchQuery &query) +{ + QPlaceTextPredictionReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendSuggestionRequest(query); + if (restReply) { + reply = new QPlaceTextPredictionReplyImpl(restReply, this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QPlaceManager::ConnectivityModes QPlaceManagerEngineNokia::connectivityMode() const +{ + return QPlaceManager::OnlineMode; +} + +void QPlaceManagerEngineNokia::setConnectivityMode(QPlaceManager::ConnectivityModes mode) +{ + Q_UNUSED(mode) + // only QPlaceManager::OnlineMode is suppoerted +} + +QPlaceManager::ConnectivityModes QPlaceManagerEngineNokia::supportedConnectivityModes() const +{ + return QPlaceManager::OnlineMode; +} + +QPlaceReply *QPlaceManagerEngineNokia::savePlace(QGeoPlace *place, QPlaceManager::VisibilityScope scope) { + //TODO: implementation + return NULL; +} + +QPlaceManager::VisibilityScopes QPlaceManagerEngineNokia::supportedSaveVisibilityScopes() const { + return QPlaceManager::NoScope; +} + +QPlaceReply *QPlaceManagerEngineNokia::removePlace(const QGeoPlace &place) { + //TODO: implementation + return NULL; +} + +QPlaceReply *QPlaceManagerEngineNokia::initializeCategories() +{ + QPlaceReply *reply = QPlaceCategoriesRepository::instance()->initializeCategories(); + if (reply) { + reply->setParent(this); + connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), + this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); + connect(reply, SIGNAL(processingFinished(QPlaceReply*)), + this, SLOT(processingFinished(QPlaceReply*))); + } + return reply; +} + +QList<QPlaceCategory> QPlaceManagerEngineNokia::categories() const +{ + return QPlaceCategoriesRepository::instance()->categories(); +} + +void QPlaceManagerEngineNokia::processingError(QPlaceReply *reply, + const QPlaceReply::Error &errorId, + const QString &errorMessage) +{ + emit error(reply, errorId, errorMessage); +} + +void QPlaceManagerEngineNokia::processingFinished(QPlaceReply *reply) +{ + emit finished(reply); +} diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h new file mode 100644 index 00000000..691eff02 --- /dev/null +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QPLACEMANAGERENGINE_NOKIA_H +#define QPLACEMANAGERENGINE_NOKIA_H + +#include <qplacemanagerengine.h> +#include <qgeoserviceprovider.h> + +QT_BEGIN_NAMESPACE + +class QPlaceManagerEngineNokia : public QPlaceManagerEngine +{ + Q_OBJECT +public: + + QPlaceManagerEngineNokia(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString); + ~QPlaceManagerEngineNokia(); + + QPlaceDetailsReply *getPlaceDetails(const QString &placeId); + + QPlaceMediaReply *getMedia(const QGeoPlace &place, const QPlaceQuery &query); + + QPlaceReply *postRating(const QString &placeId, qreal value); + + QPlaceReviewReply *getReviews(const QGeoPlace &place, const QPlaceQuery &query); + + QPlaceSearchReply *searchForPlaces(const QPlaceSearchQuery &query, QPlaceManager::VisibilityScope scope); + QPlaceManager::VisibilityScopes supportedSearchVisibilityScopes() const; + + QPlaceSearchReply *recommendations(const QGeoPlace &place, const QPlaceSearchQuery &query); + QPlaceTextPredictionReply *textPredictions(const QPlaceSearchQuery &query); + + QPlaceManager::ConnectivityModes connectivityMode() const; + void setConnectivityMode(QPlaceManager::ConnectivityModes connectivityMode); + QPlaceManager::ConnectivityModes supportedConnectivityModes() const; + + QPlaceReply *savePlace(QGeoPlace *place, QPlaceManager::VisibilityScope scope); + QPlaceManager::VisibilityScopes supportedSaveVisibilityScopes() const; + + QPlaceReply *removePlace(const QGeoPlace &place); + + QPlaceReply *initializeCategories(); + QList<QPlaceCategory> categories() const; + +private slots: + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + void processingFinished(QPlaceReply *reply); +}; + +QT_END_NAMESPACE + +#endif // QPLACEMANAGERENGINEIMPL_H |