diff options
author | abcd <qt-info@nokia.com> | 2011-06-02 17:07:29 +1000 |
---|---|---|
committer | abcd <qt-info@nokia.com> | 2011-06-02 17:28:32 +1000 |
commit | 8fab6bcfc3ef9912852e916b852456327fba299f (patch) | |
tree | d652f611c06e9f35ea8aeaa353d1674535747e99 /src | |
parent | 1dd8b4805d108931a41eb2d58874a598281ee2c4 (diff) | |
download | qtlocation-8fab6bcfc3ef9912852e916b852456327fba299f.tar.gz |
Initial dump of places
Diffstat (limited to 'src')
116 files changed, 10836 insertions, 0 deletions
diff --git a/src/location/location.pro b/src/location/location.pro index 299e8849..77191c23 100644 --- a/src/location/location.pro +++ b/src/location/location.pro @@ -16,6 +16,7 @@ HEADERS += qtlocationversion.h include(landmarks/landmarks.pri) include(maps/maps.pri) +include(places/places.pri) contains(proj_enabled, yes) { LIBS += -lproj diff --git a/src/location/places/places.pri b/src/location/places/places.pri new file mode 100644 index 00000000..993b2244 --- /dev/null +++ b/src/location/places/places.pri @@ -0,0 +1,150 @@ +#TODO: remove when plugin is refactored out +QT += declarative +QT += script + +INCLUDEPATH += places + +PUBLIC_HEADERS += \ +#data classes + places/qplace.h \ + places/qplaceaddress.h \ + places/qplacealternativevalue.h \ + places/qplacebusinessfeature.h \ + places/qplacebusinessinformation.h \ + places/qplacecategory.h \ + places/qplacecontact.h \ + places/qplacedescription.h \ + places/qplacegeoboundingbox.h \ + places/qplacegeocoordinate.h \ + places/qplacelocation.h \ + places/qplacemediaobject.h \ + places/qplacepaginationlist.h \ + places/qplaceperiod.h \ + places/qplacerating.h \ + places/qplacereview.h \ + places/qplacesupplier.h \ + places/qplaceweekdayhours.h \ +#result + places/qplacesearchresult.h \ +#query classes + places/placequery.h \ + places/qplacesearchquery.h \ +#reply classes + places/qplacereply.h \ + places/qplacedetailsreply.h \ + places/qplacemediareply.h \ + places/qplacereviewreply.h \ + places/qplacesearchreply.h \ + places/qplacetextpredictionreply.h \ +#manager and engine + places/qplacemanager.h \ + places/qplacemanagerengine.h \ + places/qplaceglobal.h + +PRIVATE_HEADERS += \ + places/qplace_p.h \ + places/qplaceaddress_p.h \ + places/qplacealternativevalue_p.h \ + places/qplacebusinessfeature_p.h \ + places/qplacebusinessinformation_p.h \ + places/qplacecategory_p.h \ + places/qplacecontact_p.h \ + places/qplacedescription_p.h \ + places/qplacegeoboundingbox_p.h \ + places/qplacegeocoordinate_p.h \ + places/qplacelocation_p.h \ + places/qplacemediaobject_p.h \ + places/qplaceperiod_p.h \ + places/qplacerating_p.h \ + places/qplacereview_p.h \ + places/qplacesupplier_p.h \ + places/qplaceweekdayhours_p.h \ + places/qplacesearchresult_p.h + +SOURCES += \ +#data classes + places/qplace.cpp \ + places/qplaceaddress.cpp \ + places/qplacealternativevalue.cpp \ + places/qplacebusinessfeature.cpp \ + places/qplacebusinessinformation.cpp \ + places/qplacecategory.cpp \ + places/qplacecontact.cpp \ + places/qplacedescription.cpp \ + places/qplacegeoboundingbox.cpp \ + places/qplacegeocoordinate.cpp \ + places/qplacelocation.cpp \ + places/qplacemediaobject.cpp \ + places/qplaceperiod.cpp \ + places/qplacerating.cpp \ + places/qplacereview.cpp \ + places/qplacesupplier.cpp \ + places/qplaceweekdayhours.cpp \ +#result + places/qplacesearchresult.cpp \ +#query classes + places/qplacequery.cpp \ + places/qplacesearchquery.cpp \ +#reply classes + places/qplacereply.cpp \ + places/qplacedetailsreply.cpp \ + places/qplacemediareply.cpp \ + places/qplacereviewreply.cpp \ + places/qplacesearchreply.cpp \ + places/qplacetextpredictionreply.cpp \ +#manager and engine + places/qplacemanager.cpp \ + places/qplacemanagerengine.cpp + +#provider implementation +SOURCES += \ +#data classes +#parsers + places/provider/qplacejsoncategoriesparser.cpp \ + places/provider/qplacejsondetailsparser.cpp \ + places/provider/qplacejsonmediaparser.cpp \ + places/provider/qplacejsonrecommendationparser.cpp \ + places/provider/qplacejsonreviewparser.cpp \ + places/provider/qplacejsonsearchparser.cpp \ + places/provider/qplacejsontextpredictionparser.cpp \ +#query classes +#reply classes + places/provider/qplacedetailsreplyimpl.cpp \ + places/provider/qplacemediareplyimpl.cpp \ + places/provider/qplaceratingreplyimpl.cpp \ + places/provider/qplacerecommendationreplyimpl.cpp \ + places/provider/qplacereviewreplyimpl.cpp \ + places/provider/qplacesearchreplyimpl.cpp \ + places/provider/qplacetextpredictionreplyimpl.cpp \ +#manager and engine + places/provider/qplacemanagerengineimpl.cpp \ + places/provider/qplacecategoriesrepository.cpp \ + places/provider/qplacerestreply.cpp \ + places/provider/qplacerestmanager.cpp \ + places/provider/qplacesuppliersrepository.cpp + +HEADERS += \ +#data classes +#parsers + places/provider/qplacejsoncategoriesparser.h \ + places/provider/qplacejsondetailsparser.h \ + places/provider/qplacejsonmediaparser.h \ + places/provider/qplacejsonrecommendationparser.h \ + places/provider/qplacejsonreviewparser.h \ + places/provider/qplacejsonsearchparser.h \ + places/provider/qplacejsontextpredictionparser.h \ +#query classes +#reply classes + places/provider/qplacemediareplyimpl.h \ + places/provider/qplacedetailsreplyimpl.h \ + places/provider/qplaceratingreplyimpl.h \ + places/provider/qplacerecommendationreplyimpl.h \ + places/provider/qplacereviewreplyimpl.h \ + places/provider/qplacesearchreplyimpl.h \ + places/provider/qplacetextpredictionreplyimpl.h \ +#manager and engine + places/provider/qplacemanagerengineimpl.h \ + places/provider/qplacecategoriesrepository.h \ + places/provider/qplacerestreply.h \ + places/provider/qplacerestmanager.h \ + places/provider/qplacesuppliersrepository.h diff --git a/src/location/places/provider/qplacecategoriesrepository.cpp b/src/location/places/provider/qplacecategoriesrepository.cpp new file mode 100644 index 00000000..1b77d817 --- /dev/null +++ b/src/location/places/provider/qplacecategoriesrepository.cpp @@ -0,0 +1,175 @@ +#include "qplacecategoriesrepository.h" +#include "qplacejsoncategoriesparser.h" + +using namespace QT_PLACES_NAMESPACE; + +static const char *supportedCategories = "{\"categories\":{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Accommodation\",\"language\":\"en\",\"name\":\"accommodation\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Administrative Areas & Buildings\",\"language\":\"en\",\"name\":\"administrative-areas-buildings\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Business & Services\",\"language\":\"en\",\"name\":\"business-services\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Eat & Drink\",\"language\":\"en\",\"name\":\"eat-drink\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Facilities\",\"language\":\"en\",\"name\":\"facilities\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Going Out\",\"language\":\"en\",\"name\":\"going-out\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Leisure & Outdoor\",\"language\":\"en\",\"name\":\"leisure-outdoor\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Natural & Geographical\",\"language\":\"en\",\"name\":\"natural-geographical\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Shopping\",\"language\":\"en\",\"name\":\"shopping\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Sights & Museums\",\"language\":\"en\",\"name\":\"sights-museums\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Public Toilet \\/ Rest Area\",\"language\":\"en\",\"name\":\"toilet-rest-area\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Transport\",\"language\":\"en\",\"name\":\"transport\"}],\"group\":[{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Administrative Region\",\"language\":\"en\",\"name\":\"administrative-region\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Building\",\"language\":\"en\",\"name\":\"building\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"City, Town or Village\",\"language\":\"en\",\"name\":\"city-town-village\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Outdoor Area \\/ Complex\",\"language\":\"en\",\"name\":\"outdoor-area-complex\"}],\"groupingCategory\":{\"displayName\":\"Administrative Areas & Buildings\",\"language\":\"en\",\"name\":\"administrative-areas-buildings\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Airport\",\"language\":\"en\",\"name\":\"airport\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Ferry Terminal\",\"language\":\"en\",\"name\":\"ferry-terminal\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Public Transport\",\"language\":\"en\",\"name\":\"public-transport\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Train Station\",\"language\":\"en\",\"name\":\"railway-station\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Taxi Stand\",\"language\":\"en\",\"name\":\"taxi-stand\"}],\"groupingCategory\":{\"displayName\":\"Transport\",\"language\":\"en\",\"name\":\"transport\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Amusement or Holiday Park\",\"language\":\"en\",\"name\":\"amusement-holiday-park\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Recreation\",\"language\":\"en\",\"name\":\"recreation\"}],\"groupingCategory\":{\"displayName\":\"Leisure & Outdoor\",\"language\":\"en\",\"name\":\"leisure-outdoor\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"ATM \\/ Bank Exchange\",\"language\":\"en\",\"name\":\"atm-bank-exchange\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Business \\/ Industry\",\"language\":\"en\",\"name\":\"business-industry\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Car Dealer \\/ Repair\",\"language\":\"en\",\"name\":\"car-dealer-repair\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Car Rental\",\"language\":\"en\",\"name\":\"car-rental\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Communication \\/ Media\",\"language\":\"en\",\"name\":\"communication-media\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Petrol Station\",\"language\":\"en\",\"name\":\"petrol-station\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Police \\/ Emergency\",\"language\":\"en\",\"name\":\"police-emergency\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Post Office\",\"language\":\"en\",\"name\":\"post-office\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Service\",\"language\":\"en\",\"name\":\"service\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Tourist Information\",\"language\":\"en\",\"name\":\"tourist-information\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Travel Agency\",\"language\":\"en\",\"name\":\"travel-agency\"}],\"groupingCategory\":{\"displayName\":\"Business & Services\",\"language\":\"en\",\"name\":\"business-services\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Bar \\/ Pub\",\"language\":\"en\",\"name\":\"bar-pub\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Coffee \\/ Tea\",\"language\":\"en\",\"name\":\"coffee-tea\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Restaurant\",\"language\":\"en\",\"name\":\"restaurant\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Snacks \\/ Fast food\",\"language\":\"en\",\"name\":\"snacks-fast-food\"}],\"groupingCategory\":{\"displayName\":\"Eat & Drink\",\"language\":\"en\",\"name\":\"eat-drink\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Body of Water\",\"language\":\"en\",\"name\":\"body-of-water\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Forest, Heath or Other Vegetation\",\"language\":\"en\",\"name\":\"forest-heath-vegetation\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Mountain or Hill\",\"language\":\"en\",\"name\":\"mountain-hill\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Undersea Feature\",\"language\":\"en\",\"name\":\"undersea-feature\"}],\"groupingCategory\":{\"displayName\":\"Natural & Geographical\",\"language\":\"en\",\"name\":\"natural-geographical\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Bookshop\",\"language\":\"en\",\"name\":\"bookshop\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Clothing & Accessories\",\"language\":\"en\",\"name\":\"clothing-accessories-shop\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Department Store\",\"language\":\"en\",\"name\":\"department-store\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Electronics\",\"language\":\"en\",\"name\":\"electronics-shop\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Food & Drink\",\"language\":\"en\",\"name\":\"food-drink\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Hardware, House & Garden\",\"language\":\"en\",\"name\":\"hardware-house-garden-shop\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Kiosk \\/ 24\\/7 \\/ Convenience Store\",\"language\":\"en\",\"name\":\"kiosk-convenience-store\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Mall\",\"language\":\"en\",\"name\":\"mall\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Pharmacy\",\"language\":\"en\",\"name\":\"pharmacy\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Sport & Outdoor\",\"language\":\"en\",\"name\":\"sport-outdoor-shop\"}],\"groupingCategory\":{\"displayName\":\"Shopping\",\"language\":\"en\",\"name\":\"shopping\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Camping\",\"language\":\"en\",\"name\":\"camping\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Hostel\",\"language\":\"en\",\"name\":\"hostel\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Hotel\",\"language\":\"en\",\"name\":\"hotel\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Motel\",\"language\":\"en\",\"name\":\"motel\"}],\"groupingCategory\":{\"displayName\":\"Accommodation\",\"language\":\"en\",\"name\":\"accommodation\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Casino\",\"language\":\"en\",\"name\":\"casino\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Movie Theater\",\"language\":\"en\",\"name\":\"cinema\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Dance or Night Club\",\"language\":\"en\",\"name\":\"dance-night-club\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Theater, Music & Culture\",\"language\":\"en\",\"name\":\"theatre-music-culture\"}],\"groupingCategory\":{\"displayName\":\"Going Out\",\"language\":\"en\",\"name\":\"going-out\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Education Facility\",\"language\":\"en\",\"name\":\"education-facility\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Fair & Convention Facility\",\"language\":\"en\",\"name\":\"fair-convention-facility\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Government or Community Facility\",\"language\":\"en\",\"name\":\"government-community-facility\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Hospital or Health Care Facility\",\"language\":\"en\",\"name\":\"hospital-health-care-facility\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Library\",\"language\":\"en\",\"name\":\"library\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Parking Facility\",\"language\":\"en\",\"name\":\"parking-facility\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Sports Facility \\/ Venue\",\"language\":\"en\",\"name\":\"sports-facility-venue\"}],\"groupingCategory\":{\"displayName\":\"Facilities\",\"language\":\"en\",\"name\":\"facilities\"}},{\"category\":[{\"categorySystemName\":\"find-places\",\"displayName\":\"Landmark \\/ Attraction\",\"language\":\"en\",\"name\":\"landmark-attraction\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Museum\",\"language\":\"en\",\"name\":\"museum\"},{\"categorySystemName\":\"find-places\",\"displayName\":\"Religious Place\",\"language\":\"en\",\"name\":\"religious-place\"}],\"groupingCategory\":{\"displayName\":\"Sights & Museums\",\"language\":\"en\",\"name\":\"sights-museums\"}}]}}"; + +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), + categoriesParser(NULL) +{ + setupCategoriesMapper(); + + if (!categoriesParser) { + categoriesParser = new QPlaceJSonCategoriesParser(this); + } + connect(categoriesParser, SIGNAL(finished(const QPlaceJSonCategoriesParser::Error &error, const QString &errorMessage)), + this, SLOT(categoriesReady(const QPlaceJSonCategoriesParser::Error &error, const QString &errorMessage))); + categoriesParser->processData(supportedCategories); +} + +QPlaceCategoriesRepository::~QPlaceCategoriesRepository() +{ +} + +QPlaceReply *QPlaceCategoriesRepository::initializeCategories(const QString &categorySystemId) +{ + // to be implemented + return NULL; +} + +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::categoriesReady(const QPlaceJSonCategoriesParser::Error &error, const QString &errorMessage) +{ + Q_UNUSED(errorMessage); + + if (!error) { + foreach (QPlaceCategory cat, categoriesParser->resultCategories()) { + allCategories.insert(cat.categoryId(), cat); + } + } + delete categoriesParser; + categoriesParser = 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/location/places/provider/qplacecategoriesrepository.h b/src/location/places/provider/qplacecategoriesrepository.h new file mode 100644 index 00000000..b8885d19 --- /dev/null +++ b/src/location/places/provider/qplacecategoriesrepository.h @@ -0,0 +1,45 @@ +#ifndef QPLACECATEGORIESREPOSITORY_H +#define QPLACECATEGORIESREPOSITORY_H + +#include <QObject> +#include <QList> + +#include "../qplaceglobal.h" +#include "../qplacecategory.h" +#include "../qplacereply.h" +#include "qplacejsoncategoriesparser.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceCategoriesRepository : public QObject +{ + Q_OBJECT +public: + static QPlaceCategoriesRepository *instance(); + + ~QPlaceCategoriesRepository(); + + QPlaceReply *initializeCategories(const QString &categorySystemId); + QList<QPlaceCategory> categories() const; + + QPlaceCategory mapCategory(const QString &number); + QString getCategoryTagId(const QPlaceCategory &category); + QPlaceCategory findCategoryById(const QString &id); + +public slots: + void categoriesReady(const QPlaceJSonCategoriesParser::Error &error, const QString &errorMessage); + +private: + void setupCategoriesMapper(); + +private: + QPlaceCategoriesRepository(QObject *parent = 0); + + QHash<QString, QPlaceCategory> allCategories; + static QPlaceCategoriesRepository *repositoryInstance; + QPlaceJSonCategoriesParser *categoriesParser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACECATEGORIESREPOSITORY_H diff --git a/src/location/places/provider/qplacedetailsreplyimpl.cpp b/src/location/places/provider/qplacedetailsreplyimpl.cpp new file mode 100644 index 00000000..95b6eb56 --- /dev/null +++ b/src/location/places/provider/qplacedetailsreplyimpl.cpp @@ -0,0 +1,70 @@ +#include "qplacedetailsreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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(const QString &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonDetailsParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonDetailsParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceDetailsReplyImpl::~QPlaceDetailsReplyImpl() +{ +} + +void QPlaceDetailsReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceDetailsReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceDetailsReplyImpl::predictionsReady(const QPlaceJSonDetailsParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonDetailsParser::NoError) { + setResult(parser->result()); + } else if (errorId == QPlaceJSonDetailsParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacedetailsreplyimpl.h b/src/location/places/provider/qplacedetailsreplyimpl.h new file mode 100644 index 00000000..9f6f70b0 --- /dev/null +++ b/src/location/places/provider/qplacedetailsreplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACEDETAILSREPLYIMPL_H +#define QPLACEDETAILSREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacedetailsreply.h" +#include "qplacerestreply.h" +#include "qplacejsondetailsparser.h" + +namespace QT_PLACES_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 Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonDetailsParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonDetailsParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEDETAILSREPLYIMPL_H diff --git a/src/location/places/provider/qplacejsoncategoriesparser.cpp b/src/location/places/provider/qplacejsoncategoriesparser.cpp new file mode 100644 index 00000000..025270a4 --- /dev/null +++ b/src/location/places/provider/qplacejsoncategoriesparser.cpp @@ -0,0 +1,145 @@ +#include "qplacejsoncategoriesparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#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_systemname_element = "categorySystemName"; +static const char *place_category_id_element = "name"; + +static const char *place_group_element = "group"; +static const char *place_groupingcategory_element = "groupingCategory"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonCategoriesParser::QPlaceJSonCategoriesParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +QPlaceJSonCategoriesParser::~QPlaceJSonCategoriesParser() +{ + allCategories.clear(); +} + +QList<QPlaceCategory> QPlaceJSonCategoriesParser::resultCategories() +{ + return allCategories; +} + +void QPlaceJSonCategoriesParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + allCategories.clear(); + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + sv = sv.property(place_categories_element); + if (sv.isValid()) { + allCategories = processCategories(sv); + emit finished(NoError, QString()); + } + } 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.isEmpty() && !results.contains(cat.categoryId())) { + results.insert(cat.categoryId(), cat); + } + } + } + } else { + cat = processCategory(value); + if (!cat.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()); + } + value = categoryValue.property(place_category_systemname_element); + if (value.isValid() && !value.toString().isEmpty()) { + category.setCategorySystemId(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.isEmpty()) { + results = processCategories(group); + results.append(parentCategory); + } + + return results; +} diff --git a/src/location/places/provider/qplacejsoncategoriesparser.h b/src/location/places/provider/qplacejsoncategoriesparser.h new file mode 100644 index 00000000..fd702759 --- /dev/null +++ b/src/location/places/provider/qplacejsoncategoriesparser.h @@ -0,0 +1,48 @@ +#ifndef QPLACEJSONCATEGORIESPARSER_H +#define QPLACEJSONCATEGORIESPARSER_H + +#include <QObject> +#include <QList> +#include <QHash> + +#include "../qplacecategory.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonCategoriesParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonCategoriesParser(QObject *parent = 0); + virtual ~QPlaceJSonCategoriesParser(); + + static QList<QPlaceCategory> processCategories(const QScriptValue &categories); + + QList<QPlaceCategory> resultCategories(); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + static QPlaceCategory processCategory(const QScriptValue &categoryValue); + static QList<QPlaceCategory> processGroups(const QScriptValue &categories); + static QList<QPlaceCategory> processGroup(const QScriptValue &group); +private: + QScriptEngine *engine; + QList<QPlaceCategory> allCategories; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEJSONCATEGORIESPARSER_H diff --git a/src/location/places/provider/qplacejsondetailsparser.cpp b/src/location/places/provider/qplacejsondetailsparser.cpp new file mode 100644 index 00000000..765da41c --- /dev/null +++ b/src/location/places/provider/qplacejsondetailsparser.cpp @@ -0,0 +1,1018 @@ +#include "qplacejsondetailsparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include "../qplace.h" +#include "../qplacegeocoordinate.h" +#include "../qplacecontact.h" +#include "../qplacecategory.h" +#include "../qplacedescription.h" +#include "../qplacerating.h" +#include "../qplaceaddress.h" +#include "../qplacebusinessinformation.h" +#include "../qplacelocation.h" +#include "../qplacealternativevalue.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"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonDetailsParser::QPlaceJSonDetailsParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +QPlaceJSonDetailsParser::~QPlaceJSonDetailsParser() +{ +} + +QPlace QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue) +{ + QPlace newPlace; + if (placeValue.isValid()) { + buildPlace(placeValue, &newPlace); + } + return newPlace; +} + +QPlace QPlaceJSonDetailsParser::result() +{ + return place; +} + +void QPlaceJSonDetailsParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + buildPlace(sv.property(place_place_element), &place); + emit finished(NoError, QString()); + } else { + emit finished(ParsingError, QString("JSON data are invalid")); + } +} + +void QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue, QPlace *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()) { + processLocations(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, QPlace *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, QPlace *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, QPlace *targetPlace) +{ + targetPlace->setCategories(QPlaceJSonCategoriesParser::processCategories(categories)); +} + +void QPlaceJSonDetailsParser::processRatings(const QScriptValue &ratings, QPlace *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().toUInt(&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, QPlaceLocation *location) +{ + QPlaceAddress 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.setCountryName(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.setPostalCode(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.setHouseNumber(value.toString()); + } + location->setAddress(newAddress); +} + +void QPlaceJSonDetailsParser::processLocations(const QScriptValue &locations, QPlace *targetPlace) +{ + if (locations.isArray()) { + QList<QPlaceLocation> list; + bool isFirst = true; + QScriptValueIterator it(locations); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceLocation loc = processLocation(it.value()); + if (isFirst) { + targetPlace->setLocation(loc); + isFirst = false; + } else { + list.append(loc); + } + } + } + targetPlace->setAlternativeLocations(list); + } else { + QPlaceLocation loc = processLocation(locations); + targetPlace->setLocation(loc); + } +} + +QPlaceLocation QPlaceJSonDetailsParser::processLocation(const QScriptValue &location) +{ + QPlaceLocation newLocation; + QScriptValue property = location.property(place_geoCoordinates_element); + if (property.isValid()) { + QPlaceGeoCoordinate 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.setDisplayPosition(pos); + } + property = location.property(place_address_element); + if (property.isValid()) { + processAddress(property, &newLocation); + } + return newLocation; +} + +void QPlaceJSonDetailsParser::processTags(const QScriptValue &tags, QPlace *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, QPlace *targetPlace) +{ + QScriptValue value = names.property(place_alternativenames_element); + if (value.isValid()) { + value = value.property(place_name_localized_element); + if (value.isValid()) { + QList<QPlaceAlternativeValue> list; + if (value.isArray()) { + QScriptValueIterator it(value); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + QPlaceAlternativeValue *name = processName(it.value()); + if (name) { + list.append(*name); + delete name; + name = NULL; + } + } + } + } else { + QPlaceAlternativeValue *name = processName(value); + if (name) { + list.append(*name); + delete name; + name = NULL; + } + } + targetPlace->setAlternativeNames(list); + } + } + value = names.property(place_name_default_element); + if (value.isValid()) { + QPlaceAlternativeValue *name = processName(value); + if (name) { + targetPlace->setName(name->value()); + delete name; + name = NULL; + } + } +} + +QPlaceAlternativeValue *QPlaceJSonDetailsParser::processName(const QScriptValue &nameValue) +{ + QPlaceAlternativeValue *name = NULL; + QScriptValue value = nameValue.property(place_name_value_element); + if (value.isValid() && !value.toString().isEmpty()) { + name = new QPlaceAlternativeValue(); + name->setValue(value.toString()); + value = nameValue.property(place_name_language_element); + if (value.isValid() && !value.toString().isEmpty()) { + name->setLanguage(value.toString()); + } + } + return name; +} + +void QPlaceJSonDetailsParser::processPremiumContents(const QScriptValue &premiumContent, QPlace *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, QPlace *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, QPlace *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, + QPlace *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, + QPlace *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(value.toString()); + 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, QPlace *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, QPlace *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, QPlace *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, QPlace *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(mediaUrl); + obj->setId(mediaUrl); + obj->setMimeType(mediaMimeType); + } + return obj; +} + +void QPlaceJSonDetailsParser::processAdContentPaymentMethods(const QScriptValue &content, QPlace *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, QPlace *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, QPlace *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, QPlace *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"); + } + QPlacePeriod period(start.hour(), start.minute(), end.hour(), end.minute()); + openH->setPeriod(period); + return openH; +} + +void QPlaceJSonDetailsParser::processAdContentOpeningNotes(const QScriptValue &content, QPlace *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/location/places/provider/qplacejsondetailsparser.h b/src/location/places/provider/qplacejsondetailsparser.h new file mode 100644 index 00000000..80cd0f03 --- /dev/null +++ b/src/location/places/provider/qplacejsondetailsparser.h @@ -0,0 +1,82 @@ +#ifndef QPLACEJSONDETAILSPARSER_H +#define QPLACEJSONDETAILSPARSER_H + +#include <QObject> +#include <QList> + +#include "../qplace.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonDetailsParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonDetailsParser(QObject *parent = 0); + virtual ~QPlaceJSonDetailsParser(); + + static QPlace buildPlace(const QScriptValue &place); + QPlace result(); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + static void buildPlace(const QScriptValue &place, QPlace *targetPlace); + static void processMainProvider(const QScriptValue &place, QPlace *targetPlace); + static void processContacts(const QScriptValue &contacts, QPlace *targetPlace); + static void processCategories(const QScriptValue &categories, QPlace *targetPlace); + static QPlaceCategory processCategory(const QScriptValue &category); + static void processRatings(const QScriptValue &ratings, QPlace *targetPlace); + static QPlaceRating *processRating(const QScriptValue &rating); + static void processAddress(const QScriptValue &address, QPlaceLocation *location); + static void processLocations(const QScriptValue &locations, QPlace *targetPlace); + static QPlaceLocation processLocation(const QScriptValue &location); + static void processTags(const QScriptValue &locations, QPlace *targetPlace); + static void processNames(const QScriptValue &locations, QPlace *targetPlace); + static QPlaceAlternativeValue *processName(const QScriptValue &nameValue); + static void processPremiumContents(const QScriptValue &content, QPlace *targetPlace); + static void processPremiumVersion(const QScriptValue &content, QPlace *targetPlace); + static void processPremiumContent(const QScriptValue &content, QPlace *targetPlace); + static void processPremiumContentDescription(const QScriptValue &content, + const QPlaceSupplier &supplier, + QPlace *targetPlace); + static void processPremiumContentMediaObjects(const QScriptValue &content, + const QPlaceSupplier &supplier, + QPlace *targetPlace); + static QPlaceMediaObject *processPremiumContentMediaObject(const QScriptValue &content); + static void processAdContent(const QScriptValue &content, QPlace *targetPlace); + static void processAdContentPackages(const QScriptValue &content, QPlace *targetPlace); + static void processAdContentDescriptions(const QScriptValue &content, QPlace *targetPlace); + static QPlaceDescription *processAdContentDescription(const QScriptValue &content); + static void processAdContentMediaObjects(const QScriptValue &content, QPlace *targetPlace); + static QPlaceMediaObject *processAdContentMediaObject(const QScriptValue &content); + static void processAdContentPaymentMethods(const QScriptValue &content, QPlace *targetPlace); + static QString processAdContentPaymentMethod(const QScriptValue &content); + static void processAdContentBusinessHours(const QScriptValue &content, QPlace *targetPlace); + static void processAdContentClosingsNotes(const QScriptValue &content, QPlace *targetPlace); + static QString processAdContentClosingsNote(const QScriptValue &content); + static void processAdContentOpeningHours(const QScriptValue &content, QPlace *targetPlace); + static QPlaceWeekdayHours *processAdContentOpeningHoursElement(const QScriptValue &content); + static void processAdContentOpeningNotes(const QScriptValue &content, QPlace *targetPlace); + static QString processAdContentOpeningNote(const QScriptValue &content); + +private: + QScriptEngine *engine; + QPlace place; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEJSONDETAILSPARSER_H diff --git a/src/location/places/provider/qplacejsonmediaparser.cpp b/src/location/places/provider/qplacejsonmediaparser.cpp new file mode 100644 index 00000000..90b3ba0b --- /dev/null +++ b/src/location/places/provider/qplacejsonmediaparser.cpp @@ -0,0 +1,115 @@ +#include "qplacejsonmediaparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include "../qplacemediaobject.h" +#include "../qplacesupplier.h" +#include "qplacesuppliersrepository.h" + +#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"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonMediaParser::QPlaceJSonMediaParser(QObject *parent) : + QObject(parent), + engine(NULL), + allMedia(0) +{ +} + +QPlaceJSonMediaParser::~QPlaceJSonMediaParser() +{ +} + +QList<QPlaceMediaObject> QPlaceJSonMediaParser::resultMedia() +{ + return media; +} + +uint 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(value.toString()); + 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::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + media.clear(); + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + sv = sv.property(media_objects_element); + if (sv.isValid()) { + processMedia(sv); + 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.toUInt32(); + } +} diff --git a/src/location/places/provider/qplacejsonmediaparser.h b/src/location/places/provider/qplacejsonmediaparser.h new file mode 100644 index 00000000..aa07b7fa --- /dev/null +++ b/src/location/places/provider/qplacejsonmediaparser.h @@ -0,0 +1,47 @@ +#ifndef QPLACEJSONMEDIAPARSER_H +#define QPLACEJSONMEDIAPARSER_H + +#include <QObject> +#include <QList> + +#include "../qplacemediaobject.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonMediaParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonMediaParser(QObject *parent = 0); + virtual ~QPlaceJSonMediaParser(); + + QList<QPlaceMediaObject> resultMedia(); + uint allMediaCount(); + static QPlaceMediaObject buildMediaObject(const QScriptValue &place); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + void processMedia(const QScriptValue &contacts); + +private: + QScriptEngine *engine; + QList<QPlaceMediaObject> media; + uint allMedia; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEJSONMEDIAPARSER_H diff --git a/src/location/places/provider/qplacejsonrecommendationparser.cpp b/src/location/places/provider/qplacejsonrecommendationparser.cpp new file mode 100644 index 00000000..c8199144 --- /dev/null +++ b/src/location/places/provider/qplacejsonrecommendationparser.cpp @@ -0,0 +1,82 @@ +#include "qplacejsonrecommendationparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include "qplacejsondetailsparser.h" +#include "../qplace.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"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonRecommendationParser::QPlaceJSonRecommendationParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +QPlaceJSonRecommendationParser::~QPlaceJSonRecommendationParser() +{ +} + +QList<QPlaceSearchResult> QPlaceJSonRecommendationParser::results() +{ + return searchResults; +} + +void QPlaceJSonRecommendationParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + searchResults.clear(); + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + sv = sv.property(recommendations_element); + if (sv.isValid()) { + QScriptValueIterator it(sv.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()) { + QPlace newPlace = QPlaceJSonDetailsParser::buildPlace(place); + result.setPlace(newPlace); + searchResults.append(result); + } +} diff --git a/src/location/places/provider/qplacejsonrecommendationparser.h b/src/location/places/provider/qplacejsonrecommendationparser.h new file mode 100644 index 00000000..fd47151b --- /dev/null +++ b/src/location/places/provider/qplacejsonrecommendationparser.h @@ -0,0 +1,44 @@ +#ifndef QPLACEJSONRECOMENDATIONPARSER_H +#define QPLACEJSONRECOMENDATIONPARSER_H + +#include <QObject> +#include <QList> + +#include "../qplacesearchresult.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonRecommendationParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonRecommendationParser(QObject *parent = 0); + virtual ~QPlaceJSonRecommendationParser(); + + QList<QPlaceSearchResult> results(); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + void processResultElement(const QScriptValue &value); + +private: + QScriptEngine *engine; + QList<QPlaceSearchResult> searchResults; +}; + +} // QPLACEAPI_NAMESPACE + +#endif // QPLACEJSONRECOMENDATIONPARSER_H diff --git a/src/location/places/provider/qplacejsonreviewparser.cpp b/src/location/places/provider/qplacejsonreviewparser.cpp new file mode 100644 index 00000000..371ff4fa --- /dev/null +++ b/src/location/places/provider/qplacejsonreviewparser.cpp @@ -0,0 +1,177 @@ +#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"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonReviewParser::QPlaceJSonReviewParser(QObject *parent) : + QObject(parent), + engine(NULL), + allReviews(0) +{ +} + +QPlaceJSonReviewParser::~QPlaceJSonReviewParser() +{ +} + +QList<QPlaceReview> QPlaceJSonReviewParser::results() +{ + return reviews; +} + +uint 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; + uint number = value.toString().toUInt(&isConverted); + if (isConverted) { + newReview.setNotHelpfulVotings(number); + } + } + value = review.property(review_plus_element); + if (value.isValid() && !value.toString().isEmpty()) { + bool isConverted; + uint number = value.toString().toUInt(&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::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + reviews.clear(); + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + sv = sv.property(reviews_element); + if (sv.isValid()) { + processReviews(sv); + 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.toUInt32(); + } +} diff --git a/src/location/places/provider/qplacejsonreviewparser.h b/src/location/places/provider/qplacejsonreviewparser.h new file mode 100644 index 00000000..2ee5ecfa --- /dev/null +++ b/src/location/places/provider/qplacejsonreviewparser.h @@ -0,0 +1,47 @@ +#ifndef QPLACEJSONREVIEWPARSER_H +#define QPLACEJSONREVIEWPARSER_H + +#include <QObject> +#include <QList> + +#include "../qplacesearchresult.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonReviewParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonReviewParser(QObject *parent = 0); + virtual ~QPlaceJSonReviewParser(); + + QList<QPlaceReview> results(); + uint allReviewsCount(); + static QPlaceReview buildReview(const QScriptValue &place); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + void processReviews(const QScriptValue &contacts); + +private: + QScriptEngine *engine; + QList<QPlaceReview> reviews; + uint allReviews; +}; + +} // QPLACEAPI_NAMESPACE + +#endif // QPLACEJSONREVIEWPARSER_H diff --git a/src/location/places/provider/qplacejsonsearchparser.cpp b/src/location/places/provider/qplacejsonsearchparser.cpp new file mode 100644 index 00000000..1ae9b663 --- /dev/null +++ b/src/location/places/provider/qplacejsonsearchparser.cpp @@ -0,0 +1,350 @@ +#include "qplacejsonsearchparser.h" + +#include <QtScript/QScriptEngine> +#include <QtScript/QScriptValue> +#include <QtScript/QScriptValueIterator> + +#include "../qplace.h" +#include "../qplacegeocoordinate.h" +#include "../qplacecontact.h" +#include "../qplacelocation.h" +#include "../qplaceaddress.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"; + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonSearchParser::QPlaceJSonSearchParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +QPlaceJSonSearchParser::~QPlaceJSonSearchParser() +{ + searchResultsList.clear(); +} + +QList<QPlaceSearchResult> QPlaceJSonSearchParser::searchResults() +{ + return searchResultsList; +} + +void QPlaceJSonSearchParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + searchResultsList.clear(); + + QScriptValue sv = engine->evaluate("(" + data + ")"); + if (sv.isValid()) { + QScriptValueIterator it(sv.property(search_results_element)); + while (it.hasNext()) { + it.next(); + // array contains count as last element + if (it.name() != "length") { + processResultElement(it.value()); + } + } + emit finished(NoError, QString()); + } 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); + QPlace newPlace; + result.setPlace(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); + } + } + return result; +} + +void QPlaceJSonSearchParser::processContacts(const QScriptValue &properties, QPlace *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, QPlace *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.isEmpty()) { + categoriesList.append(category); + } + } + } + } + place->setCategories(categoriesList); +} + +void QPlaceJSonSearchParser::processRating(const QScriptValue &properties, QPlace *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, QPlaceLocation *location) +{ + QPlaceAddress newAddress; + QScriptValue value = properties.property(search_properties_address_country); + if (value.isValid() && !value.toString().isEmpty()) { + newAddress.setCountryName(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.setPostalCode(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()) { + newAddress.setHouseNumber(value.toString()); + } + location->setAddress(newAddress); +} + +void QPlaceJSonSearchParser::processLocation(const QScriptValue &properties, QPlace *place) +{ + QPlaceLocation 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) { + QPlaceGeoCoordinate pos; + pos.setLatitude(latitude); + pos.setLongitude(longitude); + location.setDisplayPosition(pos); + } + + // bounding box + QPlaceGeoCoordinate bottomRight; + QPlaceGeoCoordinate 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()) { + QPlaceGeoBoundingBox boundingBox; + boundingBox.setTopLeft(topLeft); + boundingBox.setBottomRight(bottomRight); + location.setMapView(boundingBox); + } + + processAddress(properties, &location); + place->setLocation(location); +} diff --git a/src/location/places/provider/qplacejsonsearchparser.h b/src/location/places/provider/qplacejsonsearchparser.h new file mode 100644 index 00000000..2417e05d --- /dev/null +++ b/src/location/places/provider/qplacejsonsearchparser.h @@ -0,0 +1,50 @@ +#ifndef QPLACEJSONSEARCHPARSER_H +#define QPLACEJSONSEARCHPARSER_H + +#include <QObject> +#include <QList> + +#include "../qplacecategory.h" +#include "../qplacesearchresult.h" + +class QScriptEngine; +class QScriptValue; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonSearchParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonSearchParser(QObject *parent = 0); + virtual ~QPlaceJSonSearchParser(); + + QList<QPlaceSearchResult> searchResults(); + +signals: + void finished(const Error &error, const QString &errorMessage); + +public slots: + void processData(const QString &data); + +private: + void processResultElement(const QScriptValue &value); + QPlaceSearchResult processPlaceElement(const QScriptValue &value); + void processContacts(const QScriptValue &properties, QPlace *place); + void processCategories(const QScriptValue &categories, QPlace *place); + void processRating(const QScriptValue &properties, QPlace *place); + void processAddress(const QScriptValue &properties, QPlaceLocation *location); + void processLocation(const QScriptValue &properties, QPlace *place); +private: + QScriptEngine *engine; + QList<QPlaceSearchResult> searchResultsList; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEJSONSEARCHPARSER_H diff --git a/src/location/places/provider/qplacejsontextpredictionparser.cpp b/src/location/places/provider/qplacejsontextpredictionparser.cpp new file mode 100644 index 00000000..42f2a0ab --- /dev/null +++ b/src/location/places/provider/qplacejsontextpredictionparser.cpp @@ -0,0 +1,43 @@ +#include "qplacejsontextpredictionparser.h" + +#include <QtScript/QScriptEngine> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_NAMESPACE; + +QPlaceJSonTextPredictionParser::QPlaceJSonTextPredictionParser(QObject *parent) : + QObject(parent), + engine(NULL) +{ +} + +QStringList QPlaceJSonTextPredictionParser::predictions() +{ + return suggestions; +} + +void QPlaceJSonTextPredictionParser::processData(const QString &data) +{ + if (!engine) { + engine = new QScriptEngine(this); + } + suggestions.clear(); + + QScriptValue sv = engine->evaluate(data); + 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/location/places/provider/qplacejsontextpredictionparser.h b/src/location/places/provider/qplacejsontextpredictionparser.h new file mode 100644 index 00000000..34bef824 --- /dev/null +++ b/src/location/places/provider/qplacejsontextpredictionparser.h @@ -0,0 +1,36 @@ +#ifndef QPLACEJSONTEXTPREDICTIONPARSER_H +#define QPLACEJSONTEXTPREDICTIONPARSER_H + +#include <QObject> +#include <QStringList> + +#include "../qplaceglobal.h" + +class QScriptEngine; + +namespace QT_PLACES_NAMESPACE { + +class QPlaceJSonTextPredictionParser : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + ParsingError + }; + + explicit QPlaceJSonTextPredictionParser(QObject *parent = 0); + + QStringList predictions(); +signals: + void finished(const QPlaceJSonTextPredictionParser::Error &error, const QString &errorMessage); +public slots: + void processData(const QString &data); +private: + QScriptEngine *engine; + QStringList suggestions; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEJSONTEXTPREDICTIONPARSER_H diff --git a/src/location/places/provider/qplacemanagerengineimpl.cpp b/src/location/places/provider/qplacemanagerengineimpl.cpp new file mode 100644 index 00000000..9c973a7b --- /dev/null +++ b/src/location/places/provider/qplacemanagerengineimpl.cpp @@ -0,0 +1,192 @@ +#include "qplacemanagerengineimpl.h" + +#include "qplacecategoriesrepository.h" +#include "qplacetextpredictionreplyimpl.h" +#include "qplacesearchreplyimpl.h" +#include "qplacereviewreplyimpl.h" +#include "qplacemediareplyimpl.h" +#include "qplacerecommendationreplyimpl.h" +#include "qplacedetailsreplyimpl.h" +#include "qplaceratingreplyimpl.h" +#include "qplacerestmanager.h" +#include "qplacerestreply.h" + +using namespace QT_PLACES_NAMESPACE; + +const char *MANAGER_NAME = "com.nokia.places/0.9"; + +QPlaceManagerEngineImpl::QPlaceManagerEngineImpl(QObject *parent) + : QPlaceManagerEngine(parent) +{ +} + +QPlaceManagerEngineImpl::~QPlaceManagerEngineImpl() +{ +} + +QString QPlaceManagerEngineImpl::managerName() const +{ + return MANAGER_NAME; +} + +QPlaceDetailsReply *QPlaceManagerEngineImpl::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 *QPlaceManagerEngineImpl::getMedia(const QPlace &place, const QPlaceQuery &query) +{ + QPlaceMediaReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceImagesRequest(place.placeId(), + query); + if (restReply) { + reply = new QPlaceMediaReplyImpl(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; +} + +QPlaceReply *QPlaceManagerEngineImpl::postRating(const QPlace &place, qreal value) +{ + QPlaceRatingReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->postRatingRequest(place.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 *QPlaceManagerEngineImpl::getReviews(const QPlace &place, const QPlaceQuery &query) +{ + QPlaceReviewReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceReviewRequest(place.placeId(), + query); + if (restReply) { + reply = new QPlaceReviewReplyImpl(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; +} + +QPlaceSearchReply *QPlaceManagerEngineImpl::searchForPlaces(const QPlaceSearchQuery &query) +{ + QPlaceSearchReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendSuggestionRequest(query); + 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; +} + +QPlaceSearchReply *QPlaceManagerEngineImpl::recommendations(const QPlace &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 *QPlaceManagerEngineImpl::textPredictions(const QPlaceSearchQuery &query) +{ + QPlaceTextPreditionReplyImpl *reply = NULL; + QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendSuggestionRequest(query); + if (restReply) { + reply = new QPlaceTextPreditionReplyImpl(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::ConnectivityMode QPlaceManagerEngineImpl::connectivityMode() const +{ + return QPlaceManager::OnlineMode; +} + +void QPlaceManagerEngineImpl::setConnectivityMode(QPlaceManager::ConnectivityMode connectivityMode) +{ + Q_UNUSED(connectivityMode) + // only QPlaceManager::OnlineMode is suppoerted +} + +QList<QPlaceManager::ConnectivityMode> QPlaceManagerEngineImpl::supportedConnectivityModes() const +{ + QList<QPlaceManager::ConnectivityMode> modes; + modes.append(QPlaceManager::OnlineMode); + return modes; +} + +QPlaceManager::SearchVisibilityScope QPlaceManagerEngineImpl::searchVisibilityScope() const +{ + return QPlaceManager::PublicSearch; +} + +void QPlaceManagerEngineImpl::setSearchVisbilityScope(QPlaceManager::SearchVisibilityScope scope) +{ + Q_UNUSED(scope) + // only QPlaceManager::PublicSearch is supported +} + +QList<QPlaceManager::SearchVisibilityScope> QPlaceManagerEngineImpl::supportedSearchVisibilityScopes() const +{ + QList<QPlaceManager::SearchVisibilityScope> modes; + modes.append(QPlaceManager::PublicSearch); + return modes; +} + +QPlaceReply *QPlaceManagerEngineImpl::initializeCategories(const QString &categorySystemId) +{ + return QPlaceCategoriesRepository::instance()->initializeCategories(categorySystemId); +} + +QList<QPlaceCategory> QPlaceManagerEngineImpl::categories() const +{ + return QPlaceCategoriesRepository::instance()->categories(); +} + +void QPlaceManagerEngineImpl::processingError(QPlaceReply *reply, + const QPlaceReply::Error &errorId, + const QString &errorMessage) +{ + emit error(reply, errorId, errorMessage); +} + +void QPlaceManagerEngineImpl::processingFinished(QPlaceReply *reply) +{ + emit finished(reply); +} diff --git a/src/location/places/provider/qplacemanagerengineimpl.h b/src/location/places/provider/qplacemanagerengineimpl.h new file mode 100644 index 00000000..28056f66 --- /dev/null +++ b/src/location/places/provider/qplacemanagerengineimpl.h @@ -0,0 +1,48 @@ +#ifndef QPLACEMANAGERENGINEIMPL_H +#define QPLACEMANAGERENGINEIMPL_H + +#include "../qplacemanagerengine.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceManagerEngineImpl : public QPlaceManagerEngine +{ + Q_OBJECT +public: + + QPlaceManagerEngineImpl(QObject *parent = 0); + ~QPlaceManagerEngineImpl(); + + QString managerName() const; + + QPlaceDetailsReply *getPlaceDetails(const QString &placeId); + + QPlaceMediaReply * getMedia(const QPlace &place, const QPlaceQuery &query); + + QPlaceReply *postRating(const QPlace &place, qreal value); + + QPlaceReviewReply *getReviews(const QPlace &place, const QPlaceQuery &query); + + QPlaceSearchReply *searchForPlaces(const QPlaceSearchQuery &query); + QPlaceSearchReply *recommendations(const QPlace &place, const QPlaceSearchQuery &query); + QPlaceTextPredictionReply *textPredictions(const QPlaceSearchQuery &query); + + QPlaceManager::ConnectivityMode connectivityMode() const; + void setConnectivityMode(QPlaceManager::ConnectivityMode connectivityMode); + QList<QPlaceManager::ConnectivityMode> supportedConnectivityModes() const; + + QPlaceManager::SearchVisibilityScope searchVisibilityScope() const; + void setSearchVisbilityScope(QPlaceManager::SearchVisibilityScope scope); + QList<QPlaceManager::SearchVisibilityScope> supportedSearchVisibilityScopes() const; + + QPlaceReply *initializeCategories(const QString &categorySystemId); + QList<QPlaceCategory> categories() const; + +private slots: + void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); + void processingFinished(QPlaceReply *reply); +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMANAGERENGINEIMPL_H diff --git a/src/location/places/provider/qplacemediareplyimpl.cpp b/src/location/places/provider/qplacemediareplyimpl.cpp new file mode 100644 index 00000000..4a078949 --- /dev/null +++ b/src/location/places/provider/qplacemediareplyimpl.cpp @@ -0,0 +1,71 @@ +#include "qplacemediareplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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 &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonMediaParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonMediaParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceMediaReplyImpl::~QPlaceMediaReplyImpl() +{ +} + +void QPlaceMediaReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceMediaReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceMediaReplyImpl::predictionsReady(const QPlaceJSonMediaParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonMediaParser::NoError) { + setMediaObjects(parser->resultMedia()); + setTotalCount(parser->allMediaCount()); + } else if (errorId == QPlaceJSonMediaParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacemediareplyimpl.h b/src/location/places/provider/qplacemediareplyimpl.h new file mode 100644 index 00000000..ec63cae8 --- /dev/null +++ b/src/location/places/provider/qplacemediareplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACEMEDIAREPLYIMPL_H +#define QPLACEMEDIAREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacemediareply.h" +#include "qplacerestreply.h" +#include "qplacejsonmediaparser.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceMediaReplyImpl : public QPlaceMediaReply +{ + Q_OBJECT +public: + explicit QPlaceMediaReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceMediaReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonMediaParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonMediaParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMEDIAREPLYIMPL_H diff --git a/src/location/places/provider/qplaceratingreplyimpl.cpp b/src/location/places/provider/qplaceratingreplyimpl.cpp new file mode 100644 index 00000000..17393043 --- /dev/null +++ b/src/location/places/provider/qplaceratingreplyimpl.cpp @@ -0,0 +1,59 @@ +#include "qplaceratingreplyimpl.h" + +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_NAMESPACE; + +/*! + Constructor. +*/ +QPlaceRatingReplyImpl::QPlaceRatingReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceReply(parent), + restReply(reply) +{ + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &reply)), + this, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + } +} + +/*! + Destructor. +*/ +QPlaceRatingReplyImpl::~QPlaceRatingReplyImpl() +{ +} + +void QPlaceRatingReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceRatingReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceRatingReplyImpl::restFinished(const QString &data) +{ + Q_UNUSED(data); + emit finished(); + emit processingFinished(this); + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplaceratingreplyimpl.h b/src/location/places/provider/qplaceratingreplyimpl.h new file mode 100644 index 00000000..dd1fea03 --- /dev/null +++ b/src/location/places/provider/qplaceratingreplyimpl.h @@ -0,0 +1,34 @@ +#ifndef QPLACERATINGREPLYIMPL_H +#define QPLACERATINGREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacereply.h" +#include "qplacerestreply.h" + +namespace QT_PLACES_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 Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void restFinished(const QString &data); + +private: + QPlaceRestReply *restReply; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACERATINGREPLYIMPL_H diff --git a/src/location/places/provider/qplacerecommendationreplyimpl.cpp b/src/location/places/provider/qplacerecommendationreplyimpl.cpp new file mode 100644 index 00000000..0f336ea7 --- /dev/null +++ b/src/location/places/provider/qplacerecommendationreplyimpl.cpp @@ -0,0 +1,70 @@ +#include "qplacerecommendationreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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 &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonRecommendationParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonRecommendationParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceRecommendationReplyImpl::~QPlaceRecommendationReplyImpl() +{ +} + +void QPlaceRecommendationReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceRecommendationReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceRecommendationReplyImpl::predictionsReady(const QPlaceJSonRecommendationParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonRecommendationParser::NoError) { + setResults(parser->results()); + } else if (errorId == QPlaceJSonRecommendationParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacerecommendationreplyimpl.h b/src/location/places/provider/qplacerecommendationreplyimpl.h new file mode 100644 index 00000000..9b7f1cf5 --- /dev/null +++ b/src/location/places/provider/qplacerecommendationreplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACERECOMMENDATIONREPLYIMPL_H +#define QPLACERECOMMENDATIONREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacesearchreply.h" +#include "qplacerestreply.h" +#include "qplacejsonrecommendationparser.h" + +namespace QT_PLACES_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 Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonRecommendationParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonRecommendationParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACERECOMMENDATIONREPLYIMPL_H diff --git a/src/location/places/provider/qplacerestmanager.cpp b/src/location/places/provider/qplacerestmanager.cpp new file mode 100644 index 00000000..dbb668a8 --- /dev/null +++ b/src/location/places/provider/qplacerestmanager.cpp @@ -0,0 +1,239 @@ +#include "qplacerestmanager.h" + +#include <QtNetwork> +#include <QHash> + +#include "../qplacesearchquery.h" +#include "qplacerestreply.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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_tag = "&ta="; +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) +{ + Q_UNUSED(params) + return sendGeneralRequest(placeServer + placeId + images); +} + +/*! + 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::sendSearchByCategoryRequest(const QPlaceSearchQuery &query) +{ + return sendGeneralRequest(prepareSearchRequest(query) + + const_tag + 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 + QPlaceGeoCoordinate searchCentre = query.searchCenter(); + if (searchCentre.isValid()) { + searchString += const_lat + QString::number(searchCentre.latitude()); + searchString += const_lon + QString::number(searchCentre.longitude()); + } + // process view port + if (query.boundingBox().isValid()) { + searchString += const_top + QString::number(query.boundingBox().topLeft().latitude()); + searchString += const_left + QString::number(query.boundingBox().topLeft().longitude()); + searchString += const_bottom + QString::number(query.boundingBox().bottomRight().latitude()); + searchString += const_right + QString::number(query.boundingBox().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/location/places/provider/qplacerestmanager.h b/src/location/places/provider/qplacerestmanager.h new file mode 100644 index 00000000..2ee71140 --- /dev/null +++ b/src/location/places/provider/qplacerestmanager.h @@ -0,0 +1,51 @@ +#ifndef QPLACERESTMANAGER_H +#define QPLACERESTMANAGER_H + +#include <QObject> + +#include <QtNetwork/QNetworkProxy> +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkReply> + +#include "../qplaceglobal.h" +#include "../qplacesearchquery.h" +#include "qplacerestreply.h" + +namespace QT_PLACES_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 *sendSearchByCategoryRequest(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_PLACES_NAMESPACE + +#endif // QPLACERESTMANAGER_H diff --git a/src/location/places/provider/qplacerestreply.cpp b/src/location/places/provider/qplacerestreply.cpp new file mode 100644 index 00000000..281a1ae8 --- /dev/null +++ b/src/location/places/provider/qplacerestreply.cpp @@ -0,0 +1,94 @@ +#include "qplacerestreply.h" + +#include <QtNetwork> +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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/location/places/provider/qplacerestreply.h b/src/location/places/provider/qplacerestreply.h new file mode 100644 index 00000000..ef194283 --- /dev/null +++ b/src/location/places/provider/qplacerestreply.h @@ -0,0 +1,46 @@ +#ifndef QPLACERESTREPLY_H +#define QPLACERESTREPLY_H + +#include <QObject> +#include <QHash> +#include <QtNetwork/QNetworkProxy> +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkReply> + +#include "../qplaceglobal.h" + +namespace QT_PLACES_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); + +private slots: + void replyFinished(); + void replyError(QNetworkReply::NetworkError error); + +private: + QNetworkReply *mReply; + bool mCanceled; + +friend class QRestManager; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACERESTREPLY_H diff --git a/src/location/places/provider/qplacereviewreplyimpl.cpp b/src/location/places/provider/qplacereviewreplyimpl.cpp new file mode 100644 index 00000000..9c651014 --- /dev/null +++ b/src/location/places/provider/qplacereviewreplyimpl.cpp @@ -0,0 +1,71 @@ +#include "qplacereviewreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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 &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonReviewParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonReviewParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceReviewReplyImpl::~QPlaceReviewReplyImpl() +{ +} + +void QPlaceReviewReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceReviewReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceReviewReplyImpl::predictionsReady(const QPlaceJSonReviewParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonReviewParser::NoError) { + setReviews(parser->results()); + setTotalCount(parser->allReviewsCount()); + } else if (errorId == QPlaceJSonReviewParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacereviewreplyimpl.h b/src/location/places/provider/qplacereviewreplyimpl.h new file mode 100644 index 00000000..be0ab4c7 --- /dev/null +++ b/src/location/places/provider/qplacereviewreplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACEREVIEWREPLYIMPL_H +#define QPLACEREVIEWREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacereviewreply.h" +#include "qplacerestreply.h" +#include "qplacejsonreviewparser.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReviewReplyImpl : public QPlaceReviewReply +{ + Q_OBJECT +public: + explicit QPlaceReviewReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceReviewReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonReviewParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonReviewParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEREVIEWREPLYIMPL_H diff --git a/src/location/places/provider/qplacesearchreplyimpl.cpp b/src/location/places/provider/qplacesearchreplyimpl.cpp new file mode 100644 index 00000000..c04f4c99 --- /dev/null +++ b/src/location/places/provider/qplacesearchreplyimpl.cpp @@ -0,0 +1,70 @@ +#include "qplacesearchreplyimpl.h" + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_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 &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonSearchParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonSearchParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceSearchReplyImpl::~QPlaceSearchReplyImpl() +{ +} + +void QPlaceSearchReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceSearchReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceSearchReplyImpl::predictionsReady(const QPlaceJSonSearchParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonSearchParser::NoError) { + setResults(parser->searchResults()); + } else if (errorId == QPlaceJSonSearchParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacesearchreplyimpl.h b/src/location/places/provider/qplacesearchreplyimpl.h new file mode 100644 index 00000000..3dccb603 --- /dev/null +++ b/src/location/places/provider/qplacesearchreplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACESEARCHREPLYIMPL_H +#define QPLACESEARCHREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacesearchreply.h" +#include "qplacerestreply.h" +#include "qplacejsonsearchparser.h" + +namespace QT_PLACES_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 Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonSearchParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonSearchParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESEARCHREPLYIMPL_H diff --git a/src/location/places/provider/qplacesuppliersrepository.cpp b/src/location/places/provider/qplacesuppliersrepository.cpp new file mode 100644 index 00000000..768023d4 --- /dev/null +++ b/src/location/places/provider/qplacesuppliersrepository.cpp @@ -0,0 +1,58 @@ +#include "qplacesuppliersrepository.h" + +#include "../qplacesupplier.h" + +using namespace QT_PLACES_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/location/places/provider/qplacesuppliersrepository.h b/src/location/places/provider/qplacesuppliersrepository.h new file mode 100644 index 00000000..68a9fb02 --- /dev/null +++ b/src/location/places/provider/qplacesuppliersrepository.h @@ -0,0 +1,30 @@ +#ifndef QPLACESUPPLIERSREPOSITORY_H +#define QPLACESUPPLIERSREPOSITORY_H + +#include <QObject> +#include <QList> + +#include "../qplaceglobal.h" +#include "../qplacesupplier.h" + +namespace QT_PLACES_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_PLACES_NAMESPACE + +#endif // QPLACESUPPLIERSREPOSITORY_H diff --git a/src/location/places/provider/qplacetextpredictionreplyimpl.cpp b/src/location/places/provider/qplacetextpredictionreplyimpl.cpp new file mode 100644 index 00000000..e7bdea4c --- /dev/null +++ b/src/location/places/provider/qplacetextpredictionreplyimpl.cpp @@ -0,0 +1,72 @@ +#include "qplacetextpredictionreplyimpl.h" + +#include <QHash> + +#if defined(QT_PLACES_LOGGING) + #include <QDebug> +#endif + +using namespace QT_PLACES_NAMESPACE; + +/*! + Constructor. +*/ +QPlaceTextPreditionReplyImpl::QPlaceTextPreditionReplyImpl(QPlaceRestReply *reply, QObject *parent) : + QPlaceTextPredictionReply(parent), + restReply(reply) +{ + parser = new QPlaceJSonTextPredictionParser(this); + + if (restReply) { + restReply->setParent(this); + connect(restReply, SIGNAL(finished(const QString &reply)), + parser, SLOT(processData(const QString &data))); + connect(restReply, SIGNAL(error(QPlaceRestReply::Error error)), + this, SLOT(restError(QPlaceRestReply::Error))); + connect(parser, SIGNAL(finished(QPlaceJSonTextPredictionParser::Error,QString)), + this, SLOT(predictionsReady(QPlaceJSonTextPredictionParser::Error,QString))); + } +} + +/*! + Destructor. +*/ +QPlaceTextPreditionReplyImpl::~QPlaceTextPreditionReplyImpl() +{ +} + +void QPlaceTextPreditionReplyImpl::abort() +{ + restReply->cancelProcessing(); +} + +void QPlaceTextPreditionReplyImpl::restError(QPlaceRestReply::Error errorId) +{ + if (errorId == QPlaceRestReply::Canceled) { + this->setError(CancelError, "ReauestCanceled"); + } else if (errorId == QPlaceRestReply::NetworkError) { + this->setError(CommunicationError, "Network error"); + } + emit error(this->error(), this->errorString()); + emit processingError(this, this->error(), this->errorString()); + emit finished(); + emit processingFinished(this); +} + +void QPlaceTextPreditionReplyImpl::predictionsReady(const QPlaceJSonTextPredictionParser::Error &errorId, + const QString &errorMessage) +{ + if (errorId == QPlaceJSonTextPredictionParser::NoError) { + setTextPredictions(parser->predictions()); + } else if (errorId == QPlaceJSonTextPredictionParser::ParsingError) { + setError(ParseError, errorMessage); + emit error(this->error(), this->errorString()); + emit processingError(this, ParseError, errorMessage); + } + emit finished(); + emit processingFinished(this); + delete parser; + parser = NULL; + restReply->deleteLater(); + restReply = NULL; +} diff --git a/src/location/places/provider/qplacetextpredictionreplyimpl.h b/src/location/places/provider/qplacetextpredictionreplyimpl.h new file mode 100644 index 00000000..0e1b7655 --- /dev/null +++ b/src/location/places/provider/qplacetextpredictionreplyimpl.h @@ -0,0 +1,37 @@ +#ifndef QPLACETEXTPREDICTIONREPLYIMPL_H +#define QPLACETEXTPREDICTIONREPLYIMPL_H + +#include <QObject> +#include <QHash> + +#include "../qplacetextpredictionreply.h" +#include "qplacerestreply.h" +#include "qplacejsontextpredictionparser.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceTextPreditionReplyImpl : public QPlaceTextPredictionReply +{ + Q_OBJECT +public: + explicit QPlaceTextPreditionReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + ~QPlaceTextPreditionReplyImpl(); + void abort(); + +Q_SIGNALS: + void processingFinished(QPlaceReply *reply); + void processingError(QPlaceReply *reply, const Error &error, const QString &errorMessage); + +private slots: + void restError(QPlaceRestReply::Error error); + void predictionsReady(const QPlaceJSonTextPredictionParser::Error &error, + const QString &errorMessage); + +private: + QPlaceRestReply *restReply; + QPlaceJSonTextPredictionParser *parser; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACETEXTPREDICTIONREPLYIMPL_H diff --git a/src/location/places/qplace.cpp b/src/location/places/qplace.cpp new file mode 100644 index 00000000..e96bef34 --- /dev/null +++ b/src/location/places/qplace.cpp @@ -0,0 +1,435 @@ +#include "qplace.h" +#include "qplace_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlacePrivate::QPlacePrivate() : QSharedData() +{ +} + +QPlacePrivate::QPlacePrivate(const QPlacePrivate &other) + : QSharedData() +{ + this->additionalData = other.additionalData; + this->alternativeNames = other.alternativeNames; + this->placeScore = other.placeScore; + this->businessInfo = other.businessInfo; + this->categories = other.categories; + this->contacts = other.contacts; + this->descriptions = other.descriptions; + this->location = other.location; + this->alternativeLocations = other.alternativeLocations; + this->rating = other.rating; + this->suppliers = other.suppliers; + this->feeds = other.feeds; + this->media = other.media; + this->mediaCount = other.mediaCount; + this->name = other.name; + this->placeId = other.placeId; + this->reviews = other.reviews; + this->reviewCount = other.reviewCount; + this->shortDescription = other.shortDescription; + this->tags = other.tags; +} + +QPlacePrivate::~QPlacePrivate() +{ +} + +bool QPlacePrivate::operator==(const QPlacePrivate &other) const +{ + return ( + this->additionalData == other.additionalData + && this->alternativeNames == other.alternativeNames + && this->placeScore == other.placeScore + && this->businessInfo == other.businessInfo + && this->categories == other.categories + && this->contacts == other.contacts + && this->descriptions == other.descriptions + && this->location == other.location + && this->alternativeLocations == other.alternativeLocations + && this->rating == other.rating + && this->suppliers == other.suppliers + && this->feeds == other.feeds + && this->media == other.media + && this->mediaCount == other.mediaCount + && this->name == other.name + && this->placeId == other.placeId + && this->reviews == other.reviews + && this->reviewCount == other.reviewCount + && this->shortDescription == other.shortDescription + && this->tags == other.tags + ); +} + +/*! + \class QPlaces::QPlace + + \inmodule QPlaces + + \brief The QPlace class represents a place object. + + Each QPlace represents a place object with a number of attributes + such as location, media, categories etc. + + Place objects are read-only, e.g. user of API might get list of media objects + associated to specific place but can not edit its content. Not all data might be + avaliable in the begining. Search response is not providing all data, they need + to be loaded later from place request. + + QPlace is an in memory representation of a place object. +*/ + + +/*! + Default constructor. Constructs an new place object. +*/ +QPlace::QPlace() + : d(new QPlacePrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlace::QPlace(const QPlace &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlace::~QPlace() +{ +} + +QPlace &QPlace::operator =(const QPlace &other) { + d = other.d; + return *this; +} + +bool QPlace::operator==(const QPlace &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns additional data. +*/ +QVariantHash QPlace::additionalData() const +{ + return d->additionalData; +} + +/*! + Sets additional data. +*/ +void QPlace::setAdditionalData(const QVariantHash &data) +{ + d->additionalData = data; +} + +/*! + Returns alternative names. +*/ +QList<QPlaceAlternativeValue> QPlace::alternativeNames() const +{ + return d->alternativeNames; +} + +/*! + Sets alternative names. +*/ +void QPlace::setAlternativeNames(const QList<QPlaceAlternativeValue> &alternativeNames) +{ + d->alternativeNames = alternativeNames; +} + +/*! + Returns place score. +*/ +double QPlace::placeScore() const +{ + return d->placeScore; +} + +/*! + Sets place score. +*/ +void QPlace::setPlaceScore(const double &data) +{ + d->placeScore = data; +} + +/*! + Returns business info. +*/ +QPlaceBusinessInformation QPlace::businessInformation() const +{ + return d->businessInfo; +} + +/*! + Sets business info. +*/ +void QPlace::setBusinessInformation(const QPlaceBusinessInformation &business) +{ + d->businessInfo = business; +} + +/*! + Returns categories. +*/ +QList<QPlaceCategory> QPlace::categories() const +{ + return d->categories; +} + +/*! + Sets categories. +*/ +void QPlace::setCategories(const QList<QPlaceCategory> &categories) +{ + d->categories = categories; +} + +/*! + Returns contacts. +*/ +QList<QPlaceContact> QPlace::contacts() const +{ + return d->contacts; +} + +/*! + Sets contacts. +*/ +void QPlace::setContacts(const QList<QPlaceContact> &contacts) +{ + d->contacts = contacts; +} + +/*! + Returns descriptions. +*/ +QList<QPlaceDescription> QPlace::descriptions() const +{ + return d->descriptions; +} + +/*! + Sets descriptions. +*/ +void QPlace::setDescriptions(const QList<QPlaceDescription> &descriptions) +{ + d->descriptions = descriptions; +} + +/*! + Returns location. +*/ +QPlaceLocation QPlace::location() const +{ + return d->location; +} + +/*! + Sets location. +*/ +void QPlace::setLocation(const QPlaceLocation &location) +{ + d->location = location; +} + +/*! + Returns alternative locations. +*/ +QList<QPlaceLocation> QPlace::alternativeLocations() const +{ + return d->alternativeLocations; +} + +/*! + Sets alternative locations. +*/ +void QPlace::setAlternativeLocations(const QList<QPlaceLocation> &locations) +{ + d->alternativeLocations = locations; +} + +/*! + Returns rating. +*/ +QPlaceRating QPlace::rating() const +{ + return d->rating; +} + +/*! + Sets rating. +*/ +void QPlace::setRating(const QPlaceRating &rating) +{ + d->rating = rating; +} + +/*! + Returns suppliers. +*/ +QList<QPlaceSupplier> QPlace::suppliers() const +{ + return d->suppliers; +} + +/*! + Sets suppliers. +*/ +void QPlace::setSuppliers(const QList<QPlaceSupplier> &data) +{ + d->suppliers = data; +} + +/*! + Returns feeds list. +*/ +QStringList QPlace::feeds() const +{ + return d->feeds; +} + +/*! + Sets feeds list. +*/ +void QPlace::setFeeds(const QStringList &feeds) +{ + d->feeds = feeds; +} + +/*! + Returns list with media objects connected to this place. +*/ +QPlacePaginationList<QPlaceMediaObject> QPlace::media() const +{ + return d->media; +} + +/*! + Sets list with media objects connected to this place. +*/ +void QPlace::setMedia(const QPlacePaginationList<QPlaceMediaObject> &media) +{ + d->media = media; +} + +/*! + Returns media count. +*/ +uint QPlace::mediaCount() const +{ + return d->mediaCount; +} + +/*! + Sets media count. +*/ +void QPlace::setMediaCount(const uint &data) +{ + d->mediaCount = data; +} + +/*! + Returns name. +*/ +QString QPlace::name() const +{ + return d->name; +} + +/*! + Sets name. +*/ +void QPlace::setName(const QString &name) +{ + d->name = name; +} + +/*! + Returns placeId. +*/ +QString QPlace::placeId() const +{ + return d->placeId; +} + +/*! + Sets placeId. +*/ +void QPlace::setPlaceId(const QString &placeId) +{ + d->placeId = placeId; +} + +/*! + Returns reviews. +*/ +QPlacePaginationList<QPlaceReview> QPlace::reviews() const +{ + return d->reviews; +} + +/*! + Sets reviews. +*/ +void QPlace::setReviews(const QPlacePaginationList<QPlaceReview> &reviews) +{ + d->reviews = reviews; +} + +/*! + Returns review count. +*/ +uint QPlace::reviewCount() const +{ + return d->reviewCount; +} + +/*! + Sets review count. +*/ +void QPlace::setReviewCount(const uint &data) +{ + d->reviewCount = data; +} + +/*! + Returns short description. +*/ +QString QPlace::shortDescription() const +{ + return d->shortDescription; +} + +/*! + Sets short description. +*/ +void QPlace::setShortDescription(const QString &description) +{ + d->shortDescription = description; +} + +/*! + Returns list of tags. +*/ +QStringList QPlace::tags() const +{ + return d->tags; +} + +/*! + Sets tags. +*/ +void QPlace::setTags(const QStringList &tags) +{ + d->tags = tags; +} diff --git a/src/location/places/qplace.h b/src/location/places/qplace.h new file mode 100644 index 00000000..82f8da8d --- /dev/null +++ b/src/location/places/qplace.h @@ -0,0 +1,86 @@ +#ifndef QPLACE_H +#define QPLACE_H + +#include <QSharedDataPointer> +#include <QString> +#include <QVariant> +#include <QList> +#include "qplaceglobal.h" +#include "qplacealternativevalue.h" +#include "qplacebusinessinformation.h" +#include "qplacecategory.h" +#include "qplacecontact.h" +#include "qplacedescription.h" +#include "qplacelocation.h" +#include "qplacerating.h" +#include "qplacepaginationlist.h" +#include "qplacemediaobject.h" +#include "qplacereview.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlacePrivate; + +class Q_PLACES_EXPORT QPlace +{ +public: + QPlace(); + QPlace(const QPlace &other); + + virtual ~QPlace(); + + QPlace &operator=(const QPlace &other); + + bool operator==(const QPlace &other) const; + bool operator!=(const QPlace &other) const { + return !(other == *this); + } + + QVariantHash additionalData() const; + void setAdditionalData(const QVariantHash &data); + QList<QPlaceAlternativeValue> alternativeNames() const; + void setAlternativeNames(const QList<QPlaceAlternativeValue> &alternativeNames); + double placeScore() const; + void setPlaceScore(const double &data); + QPlaceBusinessInformation businessInformation() const; + void setBusinessInformation(const QPlaceBusinessInformation &business); + QList<QPlaceCategory> categories() const; + void setCategories(const QList<QPlaceCategory> &categories); + QList<QPlaceContact> contacts() const; + void setContacts(const QList<QPlaceContact> &contacts); + QList<QPlaceDescription> descriptions() const; + void setDescriptions(const QList<QPlaceDescription> &descriptions); + QPlaceLocation location() const; + void setLocation(const QPlaceLocation &location); + QList<QPlaceLocation> alternativeLocations() const; + void setAlternativeLocations(const QList<QPlaceLocation> &locations); + QPlaceRating rating() const; + void setRating(const QPlaceRating &rating); + QList<QPlaceSupplier> suppliers() const; + void setSuppliers(const QList<QPlaceSupplier> &data); + QStringList feeds() const; + void setFeeds(const QStringList &feeds); + QPlacePaginationList<QPlaceMediaObject> media() const; + void setMedia(const QPlacePaginationList<QPlaceMediaObject> &media); + uint mediaCount() const; + void setMediaCount(const uint &data); + QString name() const; + void setName(const QString &name); + QString placeId() const; + void setPlaceId(const QString &placeId); + QPlacePaginationList<QPlaceReview> reviews() const; + void setReviews(const QPlacePaginationList<QPlaceReview> &reviews); + uint reviewCount() const; + void setReviewCount(const uint &data); + QString shortDescription() const; + void setShortDescription(const QString &description); + QStringList tags() const; + void setTags(const QStringList &tags); + +private: + QSharedDataPointer<QPlacePrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACE_H diff --git a/src/location/places/qplace_p.h b/src/location/places/qplace_p.h new file mode 100644 index 00000000..f67975aa --- /dev/null +++ b/src/location/places/qplace_p.h @@ -0,0 +1,44 @@ +#ifndef QPLACE_P_H +#define QPLACE_P_H + +#include <QSharedData> + +#include "qplace.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlacePrivate : public QSharedData +{ +public: + QPlacePrivate(); + QPlacePrivate(const QPlacePrivate &other); + + ~QPlacePrivate(); + + bool operator==(const QPlacePrivate &other) const; + + QVariantHash additionalData; + QList<QPlaceAlternativeValue> alternativeNames; + double placeScore; + QPlaceBusinessInformation businessInfo; + QList<QPlaceCategory> categories; + QList<QPlaceContact> contacts; + QList<QPlaceDescription> descriptions; + QPlaceLocation location; + QList<QPlaceLocation> alternativeLocations; + QPlaceRating rating; + QList<QPlaceSupplier> suppliers; + QStringList feeds; + QPlacePaginationList<QPlaceMediaObject> media; + uint mediaCount; + QString name; + QString placeId; + QPlacePaginationList<QPlaceReview> reviews; + uint reviewCount; + QString shortDescription; + QStringList tags; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACE_P_H diff --git a/src/location/places/qplaceaddress.cpp b/src/location/places/qplaceaddress.cpp new file mode 100644 index 00000000..c3d1fdc5 --- /dev/null +++ b/src/location/places/qplaceaddress.cpp @@ -0,0 +1,323 @@ +#include "qplaceaddress.h" +#include "qplaceaddress_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceAddressPrivate::QPlaceAddressPrivate() : QSharedData() +{ +} + +QPlaceAddressPrivate::QPlaceAddressPrivate(const QPlaceAddressPrivate &other) + : QSharedData() +{ + this->additionalData = other.additionalData; + this->alternativeAttributes = other.alternativeAttributes; + this->city = other.city; + this->country = other.country; + this->countryName = other.countryName; + this->county = other.county; + this->district = other.district; + this->floor = other.floor; + this->houseNumber = other.houseNumber; + this->label = other.label; + this->postalCode = other.postalCode; + this->state = other.state; + this->street = other.street; + this->suite = other.suite; +} + +QPlaceAddressPrivate::~QPlaceAddressPrivate() +{ +} + +bool QPlaceAddressPrivate::operator==(const QPlaceAddressPrivate &other) const +{ + return ( + this->additionalData == other.additionalData + && this->alternativeAttributes == other.alternativeAttributes + && this->city == other.city + && this->country == other.country + && this->countryName == other.countryName + && this->county == other.county + && this->district == other.district + && this->floor == other.floor + && this->houseNumber == other.houseNumber + && this->label == other.label + && this->postalCode == other.postalCode + && this->state == other.state + && this->street == other.street + && this->suite == other.suite + ); +} + +/*! + \class QPlaceAddress + \inmodule QPlaces + + \brief The QPlaceAddress class represents a address object. + + Each QPlaceAddress represents a address object with a number of attributes + such as street, country etc. Each QPlaceAddress is associated with location. + + Address objects are read-only, e.g. user of API might get address objects + associated to specific place but can not edit its content. User might also create new address. + + QPlaceAddress is an in memory representation of a address object. +*/ + +/*! + Default constructor. Constructs an new address object. +*/ +QPlaceAddress::QPlaceAddress() + : d(new QPlaceAddressPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceAddress::QPlaceAddress(const QPlaceAddress &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceAddress::~QPlaceAddress() +{ +} + +QPlaceAddress &QPlaceAddress::operator =(const QPlaceAddress &other) { + d = other.d; + return *this; +} + +bool QPlaceAddress::operator==(const QPlaceAddress &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns additional data. +*/ +QVariantHash QPlaceAddress::additionalData() const +{ + return d->additionalData; +} + +/*! + Sets additional data. +*/ +void QPlaceAddress::setAdditionalData(const QVariantHash &data) +{ + d->additionalData = data; +} + +/*! + Returns alternative attributes. +*/ +QList<QPlaceAlternativeValue> QPlaceAddress::alternativeAttributes() const +{ + return d->alternativeAttributes; +} + +/*! + Sets alternative attributes. +*/ +void QPlaceAddress::setAlternativeAttributes(const QList<QPlaceAlternativeValue> &attributes) +{ + d->alternativeAttributes = attributes; +} + +/*! + Returns city. +*/ +QString QPlaceAddress::city() const +{ + return d->city; +} + +/*! + Sets city. +*/ +void QPlaceAddress::setCity(const QString &city) +{ + d->city = city; +} + +/*! + Returns country. +*/ +QString QPlaceAddress::country() const +{ + return d->country; +} + +/*! + Sets country. +*/ +void QPlaceAddress::setCountry(const QString &country) +{ + d->country = country; +} + +/*! + Returns country name. +*/ +QString QPlaceAddress::countryName() const +{ + return d->countryName; +} + +/*! + Sets country name. +*/ +void QPlaceAddress::setCountryName(const QString &name) +{ + d->countryName = name; +} + +/*! + Returns county. +*/ +QString QPlaceAddress::county() const +{ + return d->county; +} + +/* + Sets county. +*/ +void QPlaceAddress::setCounty(const QString &county) +{ + d->county = county; +} + +/*! + Returns district. +*/ +QString QPlaceAddress::district() const +{ + return d->district; +} + +/*! + Sets district. +*/ +void QPlaceAddress::setDistrict(const QString &district) +{ + d->district = district; +} + +/*! + Returns floor. +*/ +QString QPlaceAddress::floor() const +{ + return d->floor; +} + +/*! + Sets floor. +*/ +void QPlaceAddress::setFloor(const QString &floor) +{ + d->floor = floor; +} + +/*! + Returns house number. +*/ +QString QPlaceAddress::houseNumber() const +{ + return d->houseNumber; +} + +/*! + Sets house number. +*/ +void QPlaceAddress::setHouseNumber(const QString &houseNumber) +{ + d->houseNumber = houseNumber; +} + +/*! + Returns label. +*/ +QString QPlaceAddress::label() const +{ + return d->label; +} + +/*! + Sets label. +*/ +void QPlaceAddress::setLabel(const QString &label) +{ + d->label = label; +} + +/*! + Returns postal code. +*/ +QString QPlaceAddress::postalCode() const +{ + return d->postalCode; +} + +/*! + Sets postal code. +*/ +void QPlaceAddress::setPostalCode(const QString &code) +{ + d->postalCode = code; +} + +/*! + Returns state. +*/ +QString QPlaceAddress::state() const +{ + return d->state; +} + +/*! + Sets state. +*/ +void QPlaceAddress::setState(const QString &state) +{ + d->state = state; +} + +/*! + Returns street. +*/ +QString QPlaceAddress::street() const +{ + return d->street; +} + +/*! + Sets street. +*/ +void QPlaceAddress::setStreet(const QString &street) +{ + d->street = street; +} + +/*! + Returns suite. +*/ +QString QPlaceAddress::suite() const +{ + return d->suite; +} + +/*! + Sets suite. +*/ +void QPlaceAddress::setSuite(const QString &suite) +{ + d->suite = suite; +} diff --git a/src/location/places/qplaceaddress.h b/src/location/places/qplaceaddress.h new file mode 100644 index 00000000..4fccc728 --- /dev/null +++ b/src/location/places/qplaceaddress.h @@ -0,0 +1,65 @@ +#ifndef QPLACEADDRESS_H +#define QPLACEADDRESS_H + +#include <QSharedDataPointer> +#include <QString> +#include <QVariant> +#include <QList> +#include "qplaceglobal.h" +#include "qplacealternativevalue.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceAddressPrivate; + +class Q_PLACES_EXPORT QPlaceAddress +{ +public: + QPlaceAddress(); + QPlaceAddress(const QPlaceAddress &other); + + virtual ~QPlaceAddress(); + + QPlaceAddress &operator=(const QPlaceAddress &other); + + bool operator==(const QPlaceAddress &other) const; + bool operator!=(const QPlaceAddress &other) const { + return !(other == *this); + } + + QVariantHash additionalData() const; + void setAdditionalData(const QVariantHash &data); + QList<QPlaceAlternativeValue> alternativeAttributes() const; + void setAlternativeAttributes(const QList<QPlaceAlternativeValue> &alternativeAttributes); + QString city() const; + void setCity(const QString &city); + QString country() const; + void setCountry(const QString &country); + QString countryName() const; + void setCountryName(const QString &countryName); + QString county() const; + void setCounty(const QString &county); + QString district() const; + void setDistrict(const QString &district); + QString floor() const; + void setFloor(const QString &floor); + QString houseNumber() const; + void setHouseNumber(const QString &houseNumber); + QString label() const; + void setLabel(const QString &label); + QString postalCode() const; + void setPostalCode(const QString &postalCode); + QString state() const; + void setState(const QString &state); + QString street() const; + void setStreet(const QString &street); + QString suite() const; + void setSuite(const QString &suite); + +private: + QSharedDataPointer<QPlaceAddressPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEADDRESS_H diff --git a/src/location/places/qplaceaddress_p.h b/src/location/places/qplaceaddress_p.h new file mode 100644 index 00000000..9909393a --- /dev/null +++ b/src/location/places/qplaceaddress_p.h @@ -0,0 +1,38 @@ +#ifndef QPLACEADDRESS_P_H +#define QPLACEADDRESS_P_H + +#include <QSharedData> + +#include "qplaceaddress.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceAddressPrivate : public QSharedData +{ +public: + QPlaceAddressPrivate(); + QPlaceAddressPrivate(const QPlaceAddressPrivate &other); + + ~QPlaceAddressPrivate(); + + bool operator==(const QPlaceAddressPrivate &other) const; + + QVariantHash additionalData; + QList<QPlaceAlternativeValue> alternativeAttributes; + QString city; + QString country; + QString countryName; + QString county; + QString district; + QString floor; + QString houseNumber; + QString label; + QString postalCode; + QString state; + QString street; + QString suite; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEADDRESS_P_H diff --git a/src/location/places/qplacealternativevalue.cpp b/src/location/places/qplacealternativevalue.cpp new file mode 100644 index 00000000..d4d0472b --- /dev/null +++ b/src/location/places/qplacealternativevalue.cpp @@ -0,0 +1,163 @@ +#include "qplacealternativevalue.h" +#include "qplacealternativevalue_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceAlternativeValuePrivate::QPlaceAlternativeValuePrivate() : QSharedData() +{ +} + +QPlaceAlternativeValuePrivate::QPlaceAlternativeValuePrivate(const QPlaceAlternativeValuePrivate &other) + : QSharedData() +{ + this->key = other.key; + this->language = other.language; + this->semantics = other.semantics; + this->type = other.type; + this->value = other.value; +} + +QPlaceAlternativeValuePrivate::~QPlaceAlternativeValuePrivate() +{ +} + +bool QPlaceAlternativeValuePrivate::operator==(const QPlaceAlternativeValuePrivate &other) const +{ + return ( + this->key == other.key + && this->language == other.language + && this->semantics == other.semantics + && this->type == other.type + && this->value == other.value + ); +} + +/*! + \class QPlaceAlternativeValue + + \inmodule QPlaces + + \brief The QPlaceAlternativeValue class represents a alternative value object. + + Each QPlaceAlternativeValue represents a alternative value object with a number of attributes + such as value, language id etc. Each QPlaceAlternativeValue is associated with place. + + Alternative value objects are read-only, e.g. user of API might get alternative value object + associated to specific place but can not edit its content. User might also create new + alternative value object and add it to place. + + QPlaceAlternativeValue is an in memory representation of a alternative value object. +*/ + +/*! + Constructs an new alternative value object. +*/ +QPlaceAlternativeValue::QPlaceAlternativeValue() + : d(new QPlaceAlternativeValuePrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceAlternativeValue::QPlaceAlternativeValue(const QPlaceAlternativeValue &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceAlternativeValue::~QPlaceAlternativeValue() +{ +} + +QPlaceAlternativeValue &QPlaceAlternativeValue::operator =(const QPlaceAlternativeValue &other) { + d = other.d; + return *this; +} + +bool QPlaceAlternativeValue::operator==(const QPlaceAlternativeValue &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns key. +*/ +QString QPlaceAlternativeValue::key() const +{ + return d->key; +} + +/*! + Sets key. +*/ +void QPlaceAlternativeValue::setKey(const QString &data) +{ + d->key = data; +} + +/*! + Returns language. +*/ +QString QPlaceAlternativeValue::language() const +{ + return d->language; +} + +/*! + Sets language. +*/ +void QPlaceAlternativeValue::setLanguage(const QString &data) +{ + d->language = data; +} + +/*! + Returns semantics. +*/ +QPlaceAlternativeValue::TextSemantics QPlaceAlternativeValue::semantics() const +{ + return d->semantics; +} + +/*! + Sets semantics. +*/ +void QPlaceAlternativeValue::setSemantics(const QPlaceAlternativeValue::TextSemantics &data) +{ + d->semantics = data; +} + +/*! + Returns type. +*/ +QPlaceAlternativeValue::NameType QPlaceAlternativeValue::type() const +{ + return d->type; +} + +/*! + Sets type. +*/ +void QPlaceAlternativeValue::setType(const QPlaceAlternativeValue::NameType &data) +{ + d->type = data; +} + +/*! + Returns value. +*/ +QString QPlaceAlternativeValue::value() const +{ + return d->value; +} + +/*! + Sets value. +*/ +void QPlaceAlternativeValue::setValue(const QString &data) +{ + d->value = data; +} diff --git a/src/location/places/qplacealternativevalue.h b/src/location/places/qplacealternativevalue.h new file mode 100644 index 00000000..bbd2dd6a --- /dev/null +++ b/src/location/places/qplacealternativevalue.h @@ -0,0 +1,56 @@ +#ifndef QPLACEALTERNATIVEVALUE_H +#define QPLACEALTERNATIVEVALUE_H + +#include <QSharedDataPointer> +#include <QString> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceAlternativeValuePrivate; + +class Q_PLACES_EXPORT QPlaceAlternativeValue +{ +public: + enum TextSemantics { + Synonim, + Exonym, + Unclassified + }; + + enum NameType { + BaseName, + ShortBaseName, + Abbrevation, + Unknown + }; + + QPlaceAlternativeValue(); + QPlaceAlternativeValue(const QPlaceAlternativeValue &other); + + virtual ~QPlaceAlternativeValue(); + + QPlaceAlternativeValue &operator=(const QPlaceAlternativeValue &other); + + bool operator==(const QPlaceAlternativeValue &other) const; + bool operator!=(const QPlaceAlternativeValue &other) const { + return !(other == *this); + } + QString key() const; + void setKey(const QString &data); + QString language() const; + void setLanguage(const QString &data); + TextSemantics semantics() const; + void setSemantics(const TextSemantics &data); + NameType type() const; + void setType(const NameType &data); + QString value() const; + void setValue(const QString &data); + +private: + QSharedDataPointer<QPlaceAlternativeValuePrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEALTERNATIVEVALUE_H diff --git a/src/location/places/qplacealternativevalue_p.h b/src/location/places/qplacealternativevalue_p.h new file mode 100644 index 00000000..8a92f56e --- /dev/null +++ b/src/location/places/qplacealternativevalue_p.h @@ -0,0 +1,30 @@ +#ifndef QPLACEALTERNATIVEVALUE_P_H +#define QPLACEALTERNATIVEVALUE_P_H + +#include <QString> +#include <QSharedData> + +#include "qplacealternativevalue.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceAlternativeValuePrivate : public QSharedData +{ +public: + QPlaceAlternativeValuePrivate(); + QPlaceAlternativeValuePrivate(const QPlaceAlternativeValuePrivate &other); + + ~QPlaceAlternativeValuePrivate(); + + bool operator==(const QPlaceAlternativeValuePrivate &other) const; + + QString key; + QString language; + QPlaceAlternativeValue::TextSemantics semantics; + QPlaceAlternativeValue::NameType type; + QString value; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEALTERNATIVEVALUE_P_H diff --git a/src/location/places/qplacebusinessfeature.cpp b/src/location/places/qplacebusinessfeature.cpp new file mode 100644 index 00000000..10106599 --- /dev/null +++ b/src/location/places/qplacebusinessfeature.cpp @@ -0,0 +1,122 @@ +#include "qplacebusinessfeature.h" +#include "qplacebusinessfeature_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceBusinessFeaturePrivate::QPlaceBusinessFeaturePrivate() : QSharedData() +{ +} + +QPlaceBusinessFeaturePrivate::QPlaceBusinessFeaturePrivate(const QPlaceBusinessFeaturePrivate &other) + : QSharedData() +{ + this->value = other.value; + this->key = other.key; + this->label = other.label; +} + +QPlaceBusinessFeaturePrivate::~QPlaceBusinessFeaturePrivate() +{ +} + +bool QPlaceBusinessFeaturePrivate::operator==(const QPlaceBusinessFeaturePrivate &other) const +{ + return ( + this->value == other.value + && this->key == other.key + && this->label == other.label + ); +} + +/*! + \class QPlaceBusinessFeature + + \inmodule QPlaces + + \brief The QPlaceBusinessFeature class represents a business services object. + + Each QPlaceBusinessFeature represents a business service object with a number of attributes + such as key etc. +*/ + + +/*! + Constructs an new "empty" business feature object. +*/ +QPlaceBusinessFeature::QPlaceBusinessFeature() + : d(new QPlaceBusinessFeaturePrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceBusinessFeature::QPlaceBusinessFeature(const QPlaceBusinessFeature &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceBusinessFeature::~QPlaceBusinessFeature() +{ +} + +QPlaceBusinessFeature &QPlaceBusinessFeature::operator =(const QPlaceBusinessFeature &other) { + d = other.d; + return *this; +} + +bool QPlaceBusinessFeature::operator==(const QPlaceBusinessFeature &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns key. +*/ +QString QPlaceBusinessFeature::key() const +{ + return d->key; +} + +/*! + Sets key. +*/ +void QPlaceBusinessFeature::setKey(const QString &data) +{ + d->key = data; +} + +/*! + Returns label. +*/ +QString QPlaceBusinessFeature::label() const +{ + return d->label; +} + +/*! + Sets label. +*/ +void QPlaceBusinessFeature::setLabel(const QString &data) +{ + d->label = data; +} + +/*! + Returns value. +*/ +QString QPlaceBusinessFeature::value() const +{ + return d->value; +} + +/*! + Sets value. +*/ +void QPlaceBusinessFeature::setValue(const QString &data) +{ + d->value = data; +} diff --git a/src/location/places/qplacebusinessfeature.h b/src/location/places/qplacebusinessfeature.h new file mode 100644 index 00000000..699aaf80 --- /dev/null +++ b/src/location/places/qplacebusinessfeature.h @@ -0,0 +1,40 @@ +#ifndef QPLACEBUSINESSFEATURE_H +#define QPLACEBUSINESSFEATURE_H + +#include <QSharedDataPointer> +#include <QString> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceBusinessFeaturePrivate; + +class Q_PLACES_EXPORT QPlaceBusinessFeature +{ +public: + QPlaceBusinessFeature(); + QPlaceBusinessFeature(const QPlaceBusinessFeature &other); + + virtual ~QPlaceBusinessFeature(); + + QPlaceBusinessFeature &operator=(const QPlaceBusinessFeature &other); + + bool operator==(const QPlaceBusinessFeature &other) const; + bool operator!=(const QPlaceBusinessFeature &other) const { + return !(other == *this); + } + + QString key() const; + void setKey(const QString &data); + QString label() const; + void setLabel(const QString &data); + QString value() const; + void setValue(const QString &data); + +private: + QSharedDataPointer<QPlaceBusinessFeaturePrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEBUSINESSFEATURE_H diff --git a/src/location/places/qplacebusinessfeature_p.h b/src/location/places/qplacebusinessfeature_p.h new file mode 100644 index 00000000..befbf13f --- /dev/null +++ b/src/location/places/qplacebusinessfeature_p.h @@ -0,0 +1,28 @@ +#ifndef QPLACEBUSINESSFEATURE_P_H +#define QPLACEBUSINESSFEATURE_P_H + +#include <QString> +#include <QSharedData> + +#include "qplacebusinessfeature.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceBusinessFeaturePrivate : public QSharedData +{ +public: + QPlaceBusinessFeaturePrivate(); + QPlaceBusinessFeaturePrivate(const QPlaceBusinessFeaturePrivate &other); + + ~QPlaceBusinessFeaturePrivate(); + + bool operator==(const QPlaceBusinessFeaturePrivate &other) const; + + QString key; + QString label; + QString value; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEBUSINESSFEATURE_P_H diff --git a/src/location/places/qplacebusinessinformation.cpp b/src/location/places/qplacebusinessinformation.cpp new file mode 100644 index 00000000..62bc3888 --- /dev/null +++ b/src/location/places/qplacebusinessinformation.cpp @@ -0,0 +1,200 @@ +#include "qplacebusinessinformation.h" +#include "qplacebusinessinformation_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceBusinessInformationPrivate::QPlaceBusinessInformationPrivate() : QSharedData() +{ +} + +QPlaceBusinessInformationPrivate::QPlaceBusinessInformationPrivate(const QPlaceBusinessInformationPrivate &other) + : QSharedData() +{ + this->additionalData = other.additionalData; + this->annualClosings = other.annualClosings; + this->openingHours = other.openingHours; + this->features = other.features; + this->annualClosingNote = other.annualClosingNote; + this->openingNote = other.openingNote; + this->paymentMethods = other.paymentMethods; +} + +QPlaceBusinessInformationPrivate::~QPlaceBusinessInformationPrivate() +{ +} + +bool QPlaceBusinessInformationPrivate::operator==(const QPlaceBusinessInformationPrivate &other) const +{ + return ( + this->additionalData == other.additionalData + && this->annualClosings == other.annualClosings + && this->openingHours == other.openingHours + && this->features == other.features + && this->annualClosingNote == other.annualClosingNote + && this->openingNote == other.openingNote + && this->paymentMethods == other.paymentMethods + ); +} + +/*! + \class QPlaceBusinessInformation + + \inmodule QPlaces + + \brief The QPlaceBusinessInformation class represents a business information object. + + Each QPlaceBusinessInformation represents a business information object with a number of attributes + such as opening hours, payment methods etc. Each QPlaceBusinessInformation is associated with place. + + Business info objects are read-only, e.g. user of API might get business info object + associated to specific place but can not edit its content. User might also create new + business info object and add it to place. + + QPlaceBusinessInformation is an in memory representation of a business info object. +*/ + + +/* + Constructs an new "empty" business info object. +*/ +QPlaceBusinessInformation::QPlaceBusinessInformation() + : d(new QPlaceBusinessInformationPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceBusinessInformation::QPlaceBusinessInformation(const QPlaceBusinessInformation &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceBusinessInformation::~QPlaceBusinessInformation() +{ +} + +QPlaceBusinessInformation &QPlaceBusinessInformation::operator =(const QPlaceBusinessInformation &other) { + d = other.d; + return *this; +} + +bool QPlaceBusinessInformation::operator==(const QPlaceBusinessInformation &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns additional data. +*/ +QVariantHash QPlaceBusinessInformation::additionalData() const +{ + return d->additionalData; +} + +/*! + Sets additional data. +*/ +void QPlaceBusinessInformation::setAdditionalData(const QVariantHash &data) +{ + d->additionalData = data; +} + +/*! + Returns annual closing. +*/ +QList<QPlacePeriod> QPlaceBusinessInformation::annualClosings() const +{ + return d->annualClosings; +} + +/*! + Sets annual closing. +*/ +void QPlaceBusinessInformation::setAnnualClosings(const QList<QPlacePeriod> &data) +{ + d->annualClosings = data; +} + +/*! + Returns opening hours. +*/ +QList<QPlaceWeekdayHours> QPlaceBusinessInformation::openingHours() const +{ + return d->openingHours; +} + +/*! + Sets opening hours. +*/ +void QPlaceBusinessInformation::setOpeningHours(const QList<QPlaceWeekdayHours> &data) +{ + d->openingHours = data; +} + +/*! + Returns annual closing note. +*/ +QString QPlaceBusinessInformation::annualClosingNote() const +{ + return d->annualClosingNote; +} + +/*! + Sets annual closing note. +*/ +void QPlaceBusinessInformation::setAnnualClosingNote(const QString &data) +{ + d->annualClosingNote = data; +} + +/*! + Returns features. +*/ +QList<QPlaceBusinessFeature> QPlaceBusinessInformation::features() const +{ + return d->features; +} + +/*! + Sets features. +*/ +void QPlaceBusinessInformation::setFeatures(const QList<QPlaceBusinessFeature> &data) +{ + d->features = data; +} + +/*! + Returns opening note. +*/ +QString QPlaceBusinessInformation::openingNote() const +{ + return d->openingNote; +} + +/*! + Sets opening note. +*/ +void QPlaceBusinessInformation::setOpeningNote(const QString &data) +{ + d->openingNote = data; +} + +/*! + Returns payment methods. +*/ +QStringList QPlaceBusinessInformation::paymentMethods() const +{ + return d->paymentMethods; +} + +/*! + Sets paymant methods. +*/ +void QPlaceBusinessInformation::setPaymentMethods(const QStringList &data) +{ + d->paymentMethods = data; +} diff --git a/src/location/places/qplacebusinessinformation.h b/src/location/places/qplacebusinessinformation.h new file mode 100644 index 00000000..32b28f5d --- /dev/null +++ b/src/location/places/qplacebusinessinformation.h @@ -0,0 +1,55 @@ +#ifndef QPLACEBUSINESSINFORMATION_H +#define QPLACEBUSINESSINFORMATION_H + +#include <QSharedDataPointer> +#include <QString> +#include <QStringList> +#include <QList> +#include <QVariant> +#include "qplaceglobal.h" + +#include "qplacebusinessfeature.h" +#include "qplaceperiod.h" +#include "qplaceweekdayhours.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceBusinessInformationPrivate; + +class Q_PLACES_EXPORT QPlaceBusinessInformation +{ +public: + QPlaceBusinessInformation(); + QPlaceBusinessInformation(const QPlaceBusinessInformation &other); + + virtual ~QPlaceBusinessInformation(); + + QPlaceBusinessInformation &operator=(const QPlaceBusinessInformation &other); + + bool operator==(const QPlaceBusinessInformation &other) const; + bool operator!=(const QPlaceBusinessInformation &other) const { + return !(other == *this); + } + + QVariantHash additionalData() const; + void setAdditionalData(const QVariantHash &data); + QList<QPlacePeriod> annualClosings() const; + void setAnnualClosings(const QList<QPlacePeriod> &data); + QList<QPlaceWeekdayHours> openingHours() const; + void setOpeningHours(const QList<QPlaceWeekdayHours> &data); + QString annualClosingNote() const; + void setAnnualClosingNote(const QString &data); + QList<QPlaceBusinessFeature> features() const; + void setFeatures(const QList<QPlaceBusinessFeature> &data); + QString openingNote() const; + void setOpeningNote(const QString &data); + QStringList paymentMethods() const; + void setPaymentMethods(const QStringList &data); + +private: + QSharedDataPointer<QPlaceBusinessInformationPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEBUSINESSINFORMATION_H diff --git a/src/location/places/qplacebusinessinformation_p.h b/src/location/places/qplacebusinessinformation_p.h new file mode 100644 index 00000000..9575da5a --- /dev/null +++ b/src/location/places/qplacebusinessinformation_p.h @@ -0,0 +1,31 @@ +#ifndef QPLACEBUSINESSINFORMATION_P_H +#define QPLACEBUSINESSINFORMATION_P_H + +#include <QSharedData> + +#include "qplacebusinessinformation.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceBusinessInformationPrivate : public QSharedData +{ +public: + QPlaceBusinessInformationPrivate(); + QPlaceBusinessInformationPrivate(const QPlaceBusinessInformationPrivate &other); + + ~QPlaceBusinessInformationPrivate(); + + bool operator==(const QPlaceBusinessInformationPrivate &other) const; + + QVariantHash additionalData; + QList<QPlacePeriod> annualClosings; + QList<QPlaceWeekdayHours> openingHours; + QList<QPlaceBusinessFeature> features; + QString annualClosingNote; + QString openingNote; + QStringList paymentMethods; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEBUSINESSINFORMATION_P_H diff --git a/src/location/places/qplacecategory.cpp b/src/location/places/qplacecategory.cpp new file mode 100644 index 00000000..2bd4727d --- /dev/null +++ b/src/location/places/qplacecategory.cpp @@ -0,0 +1,175 @@ +#include "qplacecategory.h" +#include "qplacecategory_p.h" + +#include "qplacemanagerengine.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceCategoryPrivate::QPlaceCategoryPrivate() + : QSharedData() +{ +} + +QPlaceCategoryPrivate::QPlaceCategoryPrivate(const QPlaceCategoryPrivate &other) + : QSharedData() +{ + this->alternativeNames = other.alternativeNames; + this->categoryId = other.categoryId; + this->categorySystemId = other.categorySystemId; + this->description = other.description; + this->name = other.name; +} + +QPlaceCategoryPrivate::~QPlaceCategoryPrivate() +{ +} + +bool QPlaceCategoryPrivate::operator==(const QPlaceCategoryPrivate &other) const +{ + return ( + this->alternativeNames == other.alternativeNames + && this->categoryId == other.categoryId + && this->categorySystemId == other.categorySystemId + && this->description == other.description + && this->name == other.name + ); +} + +/*! + \class QPlaceCategory + + \inmodule QPlaces + + \brief The QPlaceCategory class represents a category object. + + Each QPlaceCategory represents a category object with a number of attributes + such as description, name, id etc. Each QPlaceCategory is associated with place. + + Category objects are read-only, e.g. user of API might get business info object + associated to specific place but can not edit its content. User might also create new + contact object and add it to place. + + QPlaceCategory is an in memory representation of a contact object. +*/ + + +/* + Default constructor. Constructs a new category object. +*/ +QPlaceCategory::QPlaceCategory() + : d(new QPlaceCategoryPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceCategory::QPlaceCategory(const QPlaceCategory &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceCategory::~QPlaceCategory() +{ +} + +QPlaceCategory &QPlaceCategory::operator =(const QPlaceCategory &other) { + d = other.d; + return *this; +} + +bool QPlaceCategory::operator==(const QPlaceCategory &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns alternative names. +*/ +QList<QPlaceAlternativeValue> QPlaceCategory::alternativeNames() const +{ + return d->alternativeNames; +} + +/*! + Sets alternative names. +*/ +void QPlaceCategory::setAlternativeNames(const QList<QPlaceAlternativeValue> &names) +{ + d->alternativeNames = names; +} + +/*! + Returns category id. +*/ +QString QPlaceCategory::categoryId() const +{ + return d->categoryId; +} + +/*! + Sets description. +*/ +void QPlaceCategory::setCategoryId(const QString &catID) +{ + d->categoryId = catID; +} + +/*! + Returns category system id. +*/ +QString QPlaceCategory::categorySystemId() const +{ + return d->categorySystemId; +} + +/*! + Sets category system id. +*/ +void QPlaceCategory::setCategorySystemId(const QString &catID) +{ + d->categorySystemId = catID; +} + +/*! + Returns description. +*/ +QString QPlaceCategory::description() const +{ + return d->description; +} + +/*! + Sets category description. +*/ +void QPlaceCategory::setDescription(const QString &description) +{ + d->description = description; +} + +/*! + Returns name of category. +*/ +QString QPlaceCategory::name() const +{ + return d->name; +} + +/*! + Sets category name. +*/ +void QPlaceCategory::setName(const QString &name) +{ + d->name = name; +} + +/*! + Returns true if category is empty. +*/ +bool QPlaceCategory::isEmpty() const +{ + return !d->categoryId.isEmpty(); +} diff --git a/src/location/places/qplacecategory.h b/src/location/places/qplacecategory.h new file mode 100644 index 00000000..c78201de --- /dev/null +++ b/src/location/places/qplacecategory.h @@ -0,0 +1,49 @@ +#ifndef QPLACECATEGORY_H +#define QPLACECATEGORY_H + +#include <QSharedDataPointer> +#include <QString> +#include <QVariant> +#include <QList> +#include "qplaceglobal.h" +#include "qplacealternativevalue.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceManagerEngine; + +class QPlaceCategoryPrivate; +class Q_PLACES_EXPORT QPlaceCategory +{ +public: + QPlaceCategory(); + QPlaceCategory(const QPlaceCategory &other); + + virtual ~QPlaceCategory(); + + QPlaceCategory &operator=(const QPlaceCategory &other); + + bool operator==(const QPlaceCategory &other) const; + bool operator!=(const QPlaceCategory &other) const { + return !(other == *this); + } + + QList<QPlaceAlternativeValue> alternativeNames() const; + void setAlternativeNames(const QList<QPlaceAlternativeValue> &names); + QString categoryId() const; + void setCategoryId(const QString &catID); + QString categorySystemId() const; + void setCategorySystemId(const QString &catID); + QString description() const; + void setDescription(const QString &description); + QString name() const; + void setName(const QString &name); + + bool isEmpty() const; +private: + QSharedDataPointer<QPlaceCategoryPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACECATEGORY_H diff --git a/src/location/places/qplacecategory_p.h b/src/location/places/qplacecategory_p.h new file mode 100644 index 00000000..ffcb89b8 --- /dev/null +++ b/src/location/places/qplacecategory_p.h @@ -0,0 +1,29 @@ +#ifndef QPLACECATEGORY_P_H +#define QPLACECATEGORY_P_H + +#include <QSharedData> + +#include "qplacecategory.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceCategoryPrivate : public QSharedData +{ +public: + QPlaceCategoryPrivate(); + QPlaceCategoryPrivate(const QPlaceCategoryPrivate &other); + + ~QPlaceCategoryPrivate(); + + bool operator==(const QPlaceCategoryPrivate &other) const; + + QList<QPlaceAlternativeValue> alternativeNames; + QString categoryId; + QString categorySystemId; + QString description; + QString name; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACECATEGORY_P_H diff --git a/src/location/places/qplacecontact.cpp b/src/location/places/qplacecontact.cpp new file mode 100644 index 00000000..3fe71ae2 --- /dev/null +++ b/src/location/places/qplacecontact.cpp @@ -0,0 +1,128 @@ +#include "qplacecontact.h" +#include "qplacecontact_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceContactPrivate::QPlaceContactPrivate() : QSharedData() +{ + this->type = QPlaceContact::Undefined; +} + +QPlaceContactPrivate::QPlaceContactPrivate(const QPlaceContactPrivate &other) + : QSharedData() +{ + this->description = other.description; + this->type = other.type; + this->value = other.value; +} + +QPlaceContactPrivate::~QPlaceContactPrivate() +{ +} + +bool QPlaceContactPrivate::operator==(const QPlaceContactPrivate &other) const +{ + return ( + this->description == other.description + && this->type == other.type + && this->value == other.value + ); +} + +/*! + \class QPlaceContact + + \inmodule QPlaces + + \brief The QPlaceContact class represents a contact object. + + Each QPlaceContact represents a contact object with a number of attributes + such as type, data etc. Each QPlaceContact is associated with place. + + Contact objects are read-only, e.g. user of API might get contact object + associated to specific place but can not edit its content. User might also create new + contact object and add it to place. + + QPlaceContact is an in memory representation of a contact object. +*/ + +/*! + Constructs an new contact object. +*/ +QPlaceContact::QPlaceContact() + : d(new QPlaceContactPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceContact::QPlaceContact(const QPlaceContact &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceContact::~QPlaceContact() +{ +} + +QPlaceContact &QPlaceContact::operator =(const QPlaceContact &other) { + d = other.d; + return *this; +} + +bool QPlaceContact::operator==(const QPlaceContact &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns description. +*/ +QString QPlaceContact::description() const +{ + return d->description; +} + +/*! + Sets description. +*/ +void QPlaceContact::setDescription(const QString &data) +{ + d->description = data; +} + +/*! + Returns type. +*/ +QPlaceContact::ContactType QPlaceContact::type() const +{ + return d->type; +} + +/*! + Sets type. +*/ +void QPlaceContact::setType(const QPlaceContact::ContactType &data) +{ + d->type = data; +} + +/*! + Returns value. +*/ +QString QPlaceContact::value() const +{ + return d->value; +} + +/*! + Sets value. +*/ +void QPlaceContact::setValue(const QString &data) +{ + d->value = data; +} diff --git a/src/location/places/qplacecontact.h b/src/location/places/qplacecontact.h new file mode 100644 index 00000000..4e14495e --- /dev/null +++ b/src/location/places/qplacecontact.h @@ -0,0 +1,49 @@ +#ifndef QPLACECONTACT_H +#define QPLACECONTACT_H + +#include <QSharedDataPointer> +#include <QString> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceContactPrivate; + +class Q_PLACES_EXPORT QPlaceContact +{ +public: + enum ContactType { + Phone, + Email, + URL, + Fax, + IM, + Undefined + }; + + QPlaceContact(); + QPlaceContact(const QPlaceContact &other); + + virtual ~QPlaceContact(); + + QPlaceContact &operator=(const QPlaceContact &other); + + bool operator==(const QPlaceContact &other) const; + bool operator!=(const QPlaceContact &other) const { + return !(other == *this); + } + + QString description() const; + void setDescription(const QString& data); + ContactType type() const; + void setType(const ContactType &data); + QString value() const; + void setValue(const QString& data); + +private: + QSharedDataPointer<QPlaceContactPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACECONTACT_H diff --git a/src/location/places/qplacecontact_p.h b/src/location/places/qplacecontact_p.h new file mode 100644 index 00000000..eb976665 --- /dev/null +++ b/src/location/places/qplacecontact_p.h @@ -0,0 +1,27 @@ +#ifndef QPLACECONTACT_P_H +#define QPLACECONTACT_P_H + +#include <QSharedData> + +#include "qplacecontact.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceContactPrivate : public QSharedData +{ +public: + QPlaceContactPrivate(); + QPlaceContactPrivate(const QPlaceContactPrivate &other); + + ~QPlaceContactPrivate(); + + bool operator==(const QPlaceContactPrivate &other) const; + + QString description; + QPlaceContact::ContactType type; + QString value; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACECONTACT_P_H diff --git a/src/location/places/qplacedescription.cpp b/src/location/places/qplacedescription.cpp new file mode 100644 index 00000000..a8a717cc --- /dev/null +++ b/src/location/places/qplacedescription.cpp @@ -0,0 +1,179 @@ +#include "qplacedescription.h" +#include "qplacedescription_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceDescriptionPrivate::QPlaceDescriptionPrivate() : QSharedData() +{ +} + +QPlaceDescriptionPrivate::QPlaceDescriptionPrivate(const QPlaceDescriptionPrivate &other) + : QSharedData() +{ + this->content = other.content; + this->contentTitle = other.contentTitle; + this->contentType = other.contentType; + this->supplier = other.supplier; + this->sourceURL = other.sourceURL; + this->language = other.language; +} + +QPlaceDescriptionPrivate::~QPlaceDescriptionPrivate() +{ +} + +bool QPlaceDescriptionPrivate::operator==(const QPlaceDescriptionPrivate &other) const +{ + return ( + this->content == other.content + && this->contentTitle == other.contentTitle + && this->contentType == other.contentType + && this->supplier == other.supplier + && this->sourceURL == other.sourceURL + && this->language == other.language + ); +} + +/*! + \class QPlaceDescription + + \inmodule QPlaces + + \brief The QDescription class represents a address object. + + Each QPlaceDescription represents a description object with a number of attributes + such as title, value etc. Each QPlaceDescription is associated with place. + + Description objects are read-only, e.g. user of API might get description objects + associated to specific place but can not edit its content. User might also create new description. + +*/ + +/*! + Constructs an new place description object. +*/ +QPlaceDescription::QPlaceDescription() + : d(new QPlaceDescriptionPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceDescription::QPlaceDescription(const QPlaceDescription &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceDescription::~QPlaceDescription() +{ +} + +QPlaceDescription &QPlaceDescription::operator =(const QPlaceDescription &other) { + d = other.d; + return *this; +} + +bool QPlaceDescription::operator==(const QPlaceDescription &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns content. +*/ +QString QPlaceDescription::content() const +{ + return d->content; +} + +/*! + Sets content. +*/ +void QPlaceDescription::setContent(const QString &data) +{ + d->content = data; +} + +/*! + Returns content title. +*/ +QString QPlaceDescription::contentTitle() const +{ + return d->contentTitle; +} + +/*! + Sets content title. +*/ +void QPlaceDescription::setContentTitle(const QString &data) +{ + d->contentTitle = data; +} + +/*! + Returns content type. +*/ +QString QPlaceDescription::contentType() const +{ + return d->contentType; +} + +/*! + Sets content type. +*/ +void QPlaceDescription::setContentType(const QString &data) +{ + d->contentType = data; +} + +/*! + Returns supplier. Do not remove it. +*/ +QPlaceSupplier QPlaceDescription::supplier() const +{ + return d->supplier; +} + +/*! + Sets supplier. +*/ +void QPlaceDescription::setSupplier(const QPlaceSupplier &data) +{ + d->supplier = data; +} + +/*! + Returns source url. +*/ +QString QPlaceDescription::sourceURL() const +{ + return d->sourceURL; +} + +/*! + Sets source url. +*/ +void QPlaceDescription::setSourceURL(const QString &data) +{ + d->sourceURL = data; +} + +/*! + Returns language. +*/ +QString QPlaceDescription::language() const +{ + return d->language; +} + +/*! + Sets language. +*/ +void QPlaceDescription::setLanguage(const QString &data) +{ + d->language = data; +} diff --git a/src/location/places/qplacedescription.h b/src/location/places/qplacedescription.h new file mode 100644 index 00000000..557c763b --- /dev/null +++ b/src/location/places/qplacedescription.h @@ -0,0 +1,47 @@ +#ifndef QPLACEDESCRIPTION_H +#define QPLACEDESCRIPTION_H + +#include <QSharedDataPointer> +#include <QStringList> +#include "qplaceglobal.h" +#include "qplacesupplier.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceDescriptionPrivate; + +class Q_PLACES_EXPORT QPlaceDescription +{ +public: + QPlaceDescription(); + QPlaceDescription(const QPlaceDescription &other); + + virtual ~QPlaceDescription(); + + QPlaceDescription &operator=(const QPlaceDescription &other); + + bool operator==(const QPlaceDescription &other) const; + bool operator!=(const QPlaceDescription &other) const { + return !(other == *this); + } + + QString content() const; + void setContent(const QString &data); + QString contentTitle() const; + void setContentTitle(const QString &data); + QString contentType() const; + void setContentType(const QString &data); + QPlaceSupplier supplier() const; + void setSupplier(const QPlaceSupplier &data); + QString sourceURL() const; + void setSourceURL(const QString &data); + QString language() const; + void setLanguage(const QString &data); + +private: + QSharedDataPointer<QPlaceDescriptionPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEDESCRIPTION_H diff --git a/src/location/places/qplacedescription_p.h b/src/location/places/qplacedescription_p.h new file mode 100644 index 00000000..11412614 --- /dev/null +++ b/src/location/places/qplacedescription_p.h @@ -0,0 +1,30 @@ +#ifndef QPLACEDESCRIPTION_P_H +#define QPLACEDESCRIPTION_P_H + +#include <QSharedData> + +#include "qplacedescription.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceDescriptionPrivate : public QSharedData +{ +public: + QPlaceDescriptionPrivate(); + QPlaceDescriptionPrivate(const QPlaceDescriptionPrivate &other); + + ~QPlaceDescriptionPrivate(); + + bool operator==(const QPlaceDescriptionPrivate &other) const; + + QString content; + QString contentTitle; + QString contentType; + QPlaceSupplier supplier; + QString sourceURL; + QString language; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEDESCRIPTION_P_H diff --git a/src/location/places/qplacedetailsreply.cpp b/src/location/places/qplacedetailsreply.cpp new file mode 100644 index 00000000..5924661c --- /dev/null +++ b/src/location/places/qplacedetailsreply.cpp @@ -0,0 +1,65 @@ +#include "qplacedetailsreply.h" + +namespace QT_PLACES_NAMESPACE { +class QPlaceDetailsReplyPrivate +{ +public: + QPlaceDetailsReplyPrivate() {} + ~QPlaceDetailsReplyPrivate() {} + QPlace result; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceDetailsReply + + \brief The QPlaceDetailsReply class manages a place datails operation started by an + instance of QPlaceManager. + + \inmodule QtPlaces + + \ingroup places-main +*/ + +/*! + Constructs a search reply with a given \a parent. +*/ +QPlaceDetailsReply::QPlaceDetailsReply(QObject *parent) + : QPlaceReply(parent) +{ +} + +/*! + Destroys the search reply. +*/ +QPlaceDetailsReply::~QPlaceDetailsReply() +{ + delete d; +} + +/*! + Returns the type of reply. +*/ +QPlaceReply::Type QPlaceDetailsReply::type() const +{ + return QPlaceReply::PlaceSearchReply; +} + + /*! + Returns a place result; +*/ +QPlace QPlaceDetailsReply::result() const +{ + return d->result; +} + +/*! + Sets place \a result. +*/ +void QPlaceDetailsReply::setResult(const QPlace &result) +{ + d->result = result; +} diff --git a/src/location/places/qplacedetailsreply.h b/src/location/places/qplacedetailsreply.h new file mode 100644 index 00000000..c52a9b63 --- /dev/null +++ b/src/location/places/qplacedetailsreply.h @@ -0,0 +1,29 @@ +#ifndef QPLACEDETAILSREPLY_H +#define QPLACEDETAILSREPLY_H + +#include "qplacereply.h" +#include "qplace.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceDetailsReplyPrivate; +class Q_PLACES_EXPORT QPlaceDetailsReply : public QPlaceReply +{ + Q_OBJECT +public: + QPlaceDetailsReply(QObject *parent =0); + virtual ~QPlaceDetailsReply(); + + QPlaceReply::Type type() const; + + QPlace result() const; + +protected: + void setResult(const QPlace &result); +private: + QPlaceDetailsReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEDETAILSREPLY_H diff --git a/src/location/places/qplacegeoboundingbox.cpp b/src/location/places/qplacegeoboundingbox.cpp new file mode 100644 index 00000000..568d8482 --- /dev/null +++ b/src/location/places/qplacegeoboundingbox.cpp @@ -0,0 +1,112 @@ +#include "qplacegeoboundingbox.h" +#include "qplacegeoboundingbox_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceGeoBoundingBoxPrivate::QPlaceGeoBoundingBoxPrivate() + : QSharedData() +{ +} + +QPlaceGeoBoundingBoxPrivate::QPlaceGeoBoundingBoxPrivate(const QPlaceGeoBoundingBoxPrivate &other) + : QSharedData() +{ + this->topLeft = other.topLeft; + this->bottomRight = other.bottomRight; +} + +QPlaceGeoBoundingBoxPrivate::~QPlaceGeoBoundingBoxPrivate() +{ +} + +bool QPlaceGeoBoundingBoxPrivate::operator==(const QPlaceGeoBoundingBoxPrivate &other) const +{ + return ( + this->topLeft == other.topLeft + && this->bottomRight == other.bottomRight + ); +} + +/*! + \class QPlaceGeoBoundingBox + + \inmodule QPlaces + + \brief The QPlaceGeoBoundingBox class represents a bounding box object. + + Each QPlaceGeoBoundingBox represents a bounding box with a top/left and bottom/right point. +*/ + +/*! + Constructs a new position object. +*/ +QPlaceGeoBoundingBox::QPlaceGeoBoundingBox() + : d(new QPlaceGeoBoundingBoxPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceGeoBoundingBox::QPlaceGeoBoundingBox(const QPlaceGeoBoundingBox &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceGeoBoundingBox::~QPlaceGeoBoundingBox() +{ +} + +QPlaceGeoBoundingBox &QPlaceGeoBoundingBox::operator =(const QPlaceGeoBoundingBox &other) { + d = other.d; + return *this; +} + +bool QPlaceGeoBoundingBox::operator==(const QPlaceGeoBoundingBox &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + + +/*! + Returns coordinate of top left edge of bounding box. +*/ +QPlaceGeoCoordinate QPlaceGeoBoundingBox::topLeft() const +{ + return d->topLeft; +} + +/*! + Sets \a coordinate of top left edge of bounding box. +*/ +void QPlaceGeoBoundingBox::setTopLeft(const QPlaceGeoCoordinate &coordinate) +{ + d->topLeft = coordinate; +} + +/*! + Returns coordinate of bottom right edge of bounding box. +*/ +QPlaceGeoCoordinate QPlaceGeoBoundingBox::bottomRight() const +{ + return d->bottomRight; +} + +/*! + Sets \a coordinate of bottom right edge of bounding box. +*/ +void QPlaceGeoBoundingBox::setBottomRight(const QPlaceGeoCoordinate &coordinate) +{ + d->bottomRight = coordinate; +} + +/*! + Returns true if bounding box is valid. +*/ +bool QPlaceGeoBoundingBox::isValid() +{ + return (d->bottomRight.isValid() && d->topLeft.isValid()); +} diff --git a/src/location/places/qplacegeoboundingbox.h b/src/location/places/qplacegeoboundingbox.h new file mode 100644 index 00000000..78181a3c --- /dev/null +++ b/src/location/places/qplacegeoboundingbox.h @@ -0,0 +1,40 @@ +#ifndef QPLACEGEOBOUNDINGBOX_H +#define QPLACEGEOBOUNDINGBOX_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" +#include "qplacegeocoordinate.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceGeoBoundingBoxPrivate; + +class Q_PLACES_EXPORT QPlaceGeoBoundingBox +{ +public: + QPlaceGeoBoundingBox(); + QPlaceGeoBoundingBox(const QPlaceGeoBoundingBox &other); + + virtual ~QPlaceGeoBoundingBox(); + + QPlaceGeoBoundingBox &operator=(const QPlaceGeoBoundingBox &other); + + bool operator==(const QPlaceGeoBoundingBox &other) const; + bool operator!=(const QPlaceGeoBoundingBox &other) const { + return !(other == *this); + } + + QPlaceGeoCoordinate topLeft() const; + void setTopLeft(const QPlaceGeoCoordinate &coordinate); + QPlaceGeoCoordinate bottomRight() const; + void setBottomRight(const QPlaceGeoCoordinate &coordinate); + + bool isValid(); + +private: + QSharedDataPointer<QPlaceGeoBoundingBoxPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEGEOBOUNDINGBOX_H diff --git a/src/location/places/qplacegeoboundingbox_p.h b/src/location/places/qplacegeoboundingbox_p.h new file mode 100644 index 00000000..e4bd07a9 --- /dev/null +++ b/src/location/places/qplacegeoboundingbox_p.h @@ -0,0 +1,27 @@ +#ifndef QPLACEGEOCOORDINATE_P_H +#define QPLACEGEOCOORDINATE_P_H + +#include <QSharedData> + +#include "qplacegeoboundingbox.h" +#include "qplacegeocoordinate.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceGeoBoundingBoxPrivate : public QSharedData +{ +public: + QPlaceGeoBoundingBoxPrivate(); + QPlaceGeoBoundingBoxPrivate(const QPlaceGeoBoundingBoxPrivate &other); + + ~QPlaceGeoBoundingBoxPrivate(); + + bool operator==(const QPlaceGeoBoundingBoxPrivate &other) const; + + QPlaceGeoCoordinate topLeft; + QPlaceGeoCoordinate bottomRight; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEGEOCOORDINATE_P_H diff --git a/src/location/places/qplacegeocoordinate.cpp b/src/location/places/qplacegeocoordinate.cpp new file mode 100644 index 00000000..4664e3d7 --- /dev/null +++ b/src/location/places/qplacegeocoordinate.cpp @@ -0,0 +1,125 @@ +#include "qplacegeocoordinate.h" +#include "qplacegeocoordinate_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceGeoCoordinatePrivate::QPlaceGeoCoordinatePrivate() + : QSharedData(), + latitude(360), + longitude(180) +{ +} + +QPlaceGeoCoordinatePrivate::QPlaceGeoCoordinatePrivate(const QPlaceGeoCoordinatePrivate &other) + : QSharedData() +{ + this->latitude = other.latitude; + this->longitude = other.longitude; +} + +QPlaceGeoCoordinatePrivate::~QPlaceGeoCoordinatePrivate() +{ +} + +bool QPlaceGeoCoordinatePrivate::operator==(const QPlaceGeoCoordinatePrivate &other) const +{ + return ( + this->latitude == other.latitude + && this->longitude == other.longitude + ); +} + +bool QPlaceGeoCoordinatePrivate::isValid() const +{ + if ((this->longitude >= -180 && this->longitude <= 180 ) + && (this->latitude >=-90 && this->latitude <= 90 )) { + return true; + } + return false; +} + +/*! + \class QPlaceGeoCoordinate + + \inmodule QPlaces + + \brief The QPlaceGeoCoordinate class represents a position object. + + Each QPlaceGeoCoordinate represents a position object with a longitude and latitude. + + QPlaceGeoCoordinate is an in memory representation of a position object. +*/ + +/*! + Constructs a new position object. +*/ +QPlaceGeoCoordinate::QPlaceGeoCoordinate() + : d(new QPlaceGeoCoordinatePrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceGeoCoordinate::QPlaceGeoCoordinate(const QPlaceGeoCoordinate &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceGeoCoordinate::~QPlaceGeoCoordinate() +{ +} + +QPlaceGeoCoordinate &QPlaceGeoCoordinate::operator =(const QPlaceGeoCoordinate &other) { + d = other.d; + return *this; +} + +bool QPlaceGeoCoordinate::operator==(const QPlaceGeoCoordinate &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + + +/*! + Returns latitude. +*/ +double QPlaceGeoCoordinate::latitude() const +{ + return d->latitude; +} + +/*! + Sets latitude. +*/ +void QPlaceGeoCoordinate::setLatitude(const double &src) +{ + d->latitude = src; +} + +/*! + Returns longitude. +*/ +double QPlaceGeoCoordinate::longitude() const +{ + return d->longitude; +} + +/*! + Sets longitude. +*/ +void QPlaceGeoCoordinate::setLongitude(const double &src) +{ + d->longitude = src; +} + +/*! + Check if position is valid. +*/ +bool QPlaceGeoCoordinate::isValid() const +{ + return d->isValid(); +} diff --git a/src/location/places/qplacegeocoordinate.h b/src/location/places/qplacegeocoordinate.h new file mode 100644 index 00000000..b16bdd70 --- /dev/null +++ b/src/location/places/qplacegeocoordinate.h @@ -0,0 +1,39 @@ +#ifndef QPLACEGEOCOORDINATE_H +#define QPLACEGEOCOORDINATE_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceGeoCoordinatePrivate; + +class Q_PLACES_EXPORT QPlaceGeoCoordinate +{ +public: + QPlaceGeoCoordinate(); + QPlaceGeoCoordinate(const QPlaceGeoCoordinate &other); + + virtual ~QPlaceGeoCoordinate(); + + QPlaceGeoCoordinate &operator=(const QPlaceGeoCoordinate &other); + + bool operator==(const QPlaceGeoCoordinate &other) const; + bool operator!=(const QPlaceGeoCoordinate &other) const { + return !(other == *this); + } + + double latitude() const; + void setLatitude(const double &lat); + double longitude() const; + void setLongitude(const double &lon); + + bool isValid() const; + +private: + QSharedDataPointer<QPlaceGeoCoordinatePrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEGEOCOORDINATE_H diff --git a/src/location/places/qplacegeocoordinate_p.h b/src/location/places/qplacegeocoordinate_p.h new file mode 100644 index 00000000..35611fab --- /dev/null +++ b/src/location/places/qplacegeocoordinate_p.h @@ -0,0 +1,28 @@ +#ifndef QPLACEGEOCOORDINATE_P_H +#define QPLACEGEOCOORDINATE_P_H + +#include <QSharedData> + +#include "qplacegeocoordinate.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceGeoCoordinatePrivate : public QSharedData +{ +public: + QPlaceGeoCoordinatePrivate(); + QPlaceGeoCoordinatePrivate(const QPlaceGeoCoordinatePrivate &other); + + ~QPlaceGeoCoordinatePrivate(); + + bool operator==(const QPlaceGeoCoordinatePrivate &other) const; + + bool isValid() const; + + double latitude; + double longitude; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEGEOCOORDINATE_P_H diff --git a/src/location/places/qplaceglobal.h b/src/location/places/qplaceglobal.h new file mode 100644 index 00000000..2b0f0bb5 --- /dev/null +++ b/src/location/places/qplaceglobal.h @@ -0,0 +1,15 @@ +#ifndef QPLACEGLOBAL_H +#define QPLACEGLOBAL_H + +#include <QtCore/qglobal.h> + +#if defined(QT_BUILD_PLACES_LIB) +# define Q_PLACES_EXPORT Q_DECL_EXPORT +#else +# define Q_PLACES_EXPORT Q_DECL_IMPORT +#endif + +#define QT_PLACES_NAMESPACE QtPlaces + +#endif // QPLACEGLOBAL_H + diff --git a/src/location/places/qplacelocation.cpp b/src/location/places/qplacelocation.cpp new file mode 100644 index 00000000..c8892082 --- /dev/null +++ b/src/location/places/qplacelocation.cpp @@ -0,0 +1,235 @@ +#include "qplacelocation.h" +#include "qplacelocation_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceLocationPrivate::QPlaceLocationPrivate() : QSharedData() +{ +} + +QPlaceLocationPrivate::QPlaceLocationPrivate(const QPlaceLocationPrivate &other) + : QSharedData() +{ + this->additionalData = other.additionalData; + this->address = other.address; + this->alternativeLabels = other.alternativeLabels; + this->displayPosition = other.displayPosition; + this->navigationPositions = other.navigationPositions; + this->label = other.label; + this->locationId = other.locationId; + this->locationScore = other.locationScore; + this->mapView = other.mapView; +} + +QPlaceLocationPrivate::~QPlaceLocationPrivate() +{ +} + +bool QPlaceLocationPrivate::operator==(const QPlaceLocationPrivate &other) const +{ + return ( + this->additionalData == other.additionalData + && this->address == other.address + && this->alternativeLabels == other.alternativeLabels + && this->displayPosition == other.displayPosition + && this->navigationPositions == other.navigationPositions + && this->label == other.label + && this->locationId == other.locationId + && this->locationScore == other.locationScore + && this->mapView == other.mapView + ); +} + +/*! + \class QPlaceLocation + + \inmodule QPlaces + + \brief The QPlaceLocation class represents a location object. + + Each QPlaceLocation represents a location object with a number of attributes + such as label, display position etc. Each QPlaceLocation is associated with place. + + Location objects are read-only, e.g. user of API might get location object + associated to specific place but can not edit its content. User might also create new + location object and add it to place. + + QPlaceLocation is an in memory representation of a location object. +*/ + +/*! + Default constructor. Constructs an new location object. +*/ +QPlaceLocation::QPlaceLocation() + : d(new QPlaceLocationPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceLocation::QPlaceLocation(const QPlaceLocation &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceLocation::~QPlaceLocation() +{ +} + +QPlaceLocation &QPlaceLocation::operator =(const QPlaceLocation &other) { + d = other.d; + return *this; +} + +bool QPlaceLocation::operator==(const QPlaceLocation &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns additional data. +*/ +QVariantHash QPlaceLocation::additionalData() const +{ + return d->additionalData; +} + +/*! + Sets additional data. +*/ +void QPlaceLocation::setAdditionalData(const QVariantHash &data) +{ + d->additionalData = data; +} + +/*! + Returns address. +*/ +QPlaceAddress QPlaceLocation::address() const +{ + return d->address; +} + +/*! + Sets address. +*/ +void QPlaceLocation::setAddress(const QPlaceAddress &address) +{ + d->address = address; +} + +/*! + Returns alternative labels. +*/ +QList<QPlaceAlternativeValue> QPlaceLocation::alternativeLabels() const +{ + return d->alternativeLabels; +} + +/*! + Sets alternative labels. +*/ +void QPlaceLocation::setAlternativeLabels(const QList<QPlaceAlternativeValue> &labels) +{ + d->alternativeLabels = labels; +} + +/*! + Returns display position. +*/ +QPlaceGeoCoordinate QPlaceLocation::displayPosition() const +{ + return d->displayPosition; +} + +/*! + Sets display position. +*/ +void QPlaceLocation::setDisplayPosition(const QPlaceGeoCoordinate &position) +{ + d->displayPosition = position; +} + +/*! + Returns navigation positions. +*/ +QList<QPlaceGeoCoordinate> QPlaceLocation::navigationPositions() const +{ + return d->navigationPositions; +} + +/*! + Sets navigation positions. +*/ +void QPlaceLocation::setNavigationPositions(const QList<QPlaceGeoCoordinate> &positions) +{ + d->navigationPositions = positions; +} + +/*! + Returns label. +*/ +QString QPlaceLocation::label() const +{ + return d->label; +} + +/*! + Sets label. +*/ +void QPlaceLocation::setLabel(const QString &label) +{ + d->label = label; +} + +/*! + Returns location id. +*/ +QString QPlaceLocation::locationId() const +{ + return d->locationId; +} + +/*! + Sets location id. +*/ +void QPlaceLocation::setLocationId(const QString &locationId) +{ + d->locationId = locationId; +} + +/*! + Returns location score. +*/ +int QPlaceLocation::locationScore() const +{ + return d->locationScore; +} + +/*! + Sets location score. +*/ +void QPlaceLocation::setLocationScore(const int &score) +{ + d->locationScore = score; +} + +/*! + Returns view port. +*/ +QPlaceGeoBoundingBox QPlaceLocation::mapView() const +{ + return d->mapView; +} + +/*! + Sets view port. +*/ +void QPlaceLocation::setMapView(const QPlaceGeoBoundingBox &coordinate) +{ + d->mapView = coordinate; +} diff --git a/src/location/places/qplacelocation.h b/src/location/places/qplacelocation.h new file mode 100644 index 00000000..303445ca --- /dev/null +++ b/src/location/places/qplacelocation.h @@ -0,0 +1,58 @@ +#ifndef QPLACELOCATION_H +#define QPLACELOCATION_H + +#include <QSharedDataPointer> +#include <QString> +#include <QVariant> +#include <QList> +#include "qplaceglobal.h" +#include "qplacealternativevalue.h" +#include "qplaceaddress.h" +#include "qplacegeocoordinate.h" +#include "qplacegeoboundingbox.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceLocationPrivate; + +class Q_PLACES_EXPORT QPlaceLocation +{ +public: + QPlaceLocation(); + QPlaceLocation(const QPlaceLocation &other); + + virtual ~QPlaceLocation(); + + QPlaceLocation &operator=(const QPlaceLocation &other); + + bool operator==(const QPlaceLocation &other) const; + bool operator!=(const QPlaceLocation &other) const { + return !(other == *this); + } + + QVariantHash additionalData() const; + void setAdditionalData(const QVariantHash &data); + QPlaceAddress address() const; + void setAddress(const QPlaceAddress &address); + QList<QPlaceAlternativeValue> alternativeLabels() const; + void setAlternativeLabels(const QList<QPlaceAlternativeValue> &labels); + QPlaceGeoCoordinate displayPosition() const; + void setDisplayPosition(const QPlaceGeoCoordinate &position); + QList<QPlaceGeoCoordinate> navigationPositions() const; + void setNavigationPositions(const QList<QPlaceGeoCoordinate> &positions); + QString label() const; + void setLabel(const QString &label); + QString locationId() const; + void setLocationId(const QString &locationId); + int locationScore() const; + void setLocationScore(const int &score); + QPlaceGeoBoundingBox mapView() const; + void setMapView(const QPlaceGeoBoundingBox &coordinate); + +private: + QSharedDataPointer<QPlaceLocationPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACELOCATION_H diff --git a/src/location/places/qplacelocation_p.h b/src/location/places/qplacelocation_p.h new file mode 100644 index 00000000..0c2ddade --- /dev/null +++ b/src/location/places/qplacelocation_p.h @@ -0,0 +1,33 @@ +#ifndef QPLACELOCATION_P_H +#define QPLACELOCATION_P_H + +#include <QSharedData> + +#include "qplacelocation.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceLocationPrivate : public QSharedData +{ +public: + QPlaceLocationPrivate(); + QPlaceLocationPrivate(const QPlaceLocationPrivate &other); + + ~QPlaceLocationPrivate(); + + bool operator==(const QPlaceLocationPrivate &other) const; + + QVariantHash additionalData; + QPlaceAddress address; + QList<QPlaceAlternativeValue> alternativeLabels; + QPlaceGeoCoordinate displayPosition; + QList<QPlaceGeoCoordinate> navigationPositions; + QString label; + QString locationId; + int locationScore; + QPlaceGeoBoundingBox mapView; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACELOCATION_P_H diff --git a/src/location/places/qplacemanager.cpp b/src/location/places/qplacemanager.cpp new file mode 100644 index 00000000..17eae022 --- /dev/null +++ b/src/location/places/qplacemanager.cpp @@ -0,0 +1,244 @@ +#include "qplacemanager.h" +#include "qplacemanagerengine.h" + +#include "provider/qplacemanagerengineimpl.h" + +namespace QT_PLACES_NAMESPACE { +class QPlaceManagerEngine; + +class QPlaceManagerPrivate +{ +public: + QPlaceManagerPrivate(){ engine = new QPlaceManagerEngineImpl(); } + ~QPlaceManagerPrivate(){ delete engine; } + + QPlaceManagerEngine *engine; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; +/*! + \class QPlaceManager + + \brief The QPlaceManager class is responsible for the discovery and + management of places. + + \inmodule QtLocation + + \ingroup places-main +*/ + +/*! + \enum QPlaceManager::ConnectivityMode + + Defines the method of obtaining place data + \value NoConnectivity There is no place data. + \value OfflineMode The places data will come from an offline source. + \value OnlineMode The place data will come from an online source. + \value HybridMode The place data will come from a combination of offline and online sources. +*/ + +/*! + \enum QPlaceManager::SearchVisibilityScope + Defines the scope for searching places according to visibility. + \value PublicSearch Searches will only be conducted on public places. + \value PrivateSearch Searches will only be conducted on private places. + \value PublicAndPrivateSearch Searches will be conducted on both public and private places +*/ + +/*! + \enum QPlaceManager::ManagerFeature + Defines the possible features that the place manager can possible. + \value ImportFeature The manager supports import operations + \value ExportFeature The manager supports export operations + \value CheckInFeature The manaager supports check-in operations + \value PostMediaFeature The manager supports posting media for places + \value PostRatingFeature The manager supports posting ratings for places + \value SuggestionFeature The manager supports the providing of suggestions + \value ReportPlaceFeature The manager supports reporting a place if it is incorrect/inappropriate. + \value AuthenticationFeature The manager supports authentication of a user. + \value CreatePlaceFeature The manager supports the creation of places. + \value UpdatePlaceFeature The manager supports the updating of places. +*/ + +/*! + Constructs a new manager with the specified \a pareent and with the + implementation provided by \a engine. + + This constructor is used internally by QGeoServiceProviderFactory. Regular + users should acquire instances of QGeoRoutingManager with + QGeoServiceProvider::routingManager(); +*/ +QPlaceManager::QPlaceManager(QObject *parent) + : QObject(parent),d(new QPlaceManagerPrivate) +{ +} + +/*! + Destroys the manager. +*/ +QPlaceManager::~QPlaceManager() +{ + delete d; +} + +/*! + Returns the name of the manager +*/ +QString QPlaceManager::managerName() const +{ + return d->engine->managerName(); +} + +/*! + Retrieves a details of place with \a place id. +*/ +QPlaceDetailsReply *QPlaceManager::getPlaceDetails(const QString &placeId) const +{ + return d->engine->getPlaceDetails(placeId); +} + +/*! + Retrieves media from a given \a place according to the parameters specified in \a query. +*/ +QPlaceMediaReply *QPlaceManager::getMedia(const QPlace &place, const QPlaceQuery &query) const +{ + return d->engine->getMedia(place, query); +} + +/*! + Posts a \a rating to a \a place. +*/ +QPlaceReply* QPlaceManager::postRating(const QPlace &place, qreal rating) +{ + return d->engine->postRating(place, rating); +} + +/*! + Returns reviews for a given \a place according to the parameters specified in \a query. +*/ +QPlaceReviewReply *QPlaceManager::getReviews(const QPlace &place, const QPlaceQuery &query) const +{ + return d->engine->getReviews(place, query); +} + +/*! + Searches for places according to a given \a query. +*/ +QPlaceSearchReply *QPlaceManager::searchForPlaces(const QPlaceSearchQuery &query) const +{ + return d->engine->searchForPlaces(query); +} + +/*! + Provides recommendation based on a given \a place. +*/ +QPlaceSearchReply *QPlaceManager::recommendations(const QPlace &place, const QPlaceSearchQuery &query) const +{ + return d->engine->recommendations(place, query); +} + +/*! + Requests a set of text predictions for a given \a query string. +*/ +QPlaceTextPredictionReply *QPlaceManager::textPredictions(const QPlaceSearchQuery &query) const +{ + return d->engine->textPredictions(query); +} + +/*! + Returns the connectivity mode of the manager. +*/ +QPlaceManager::ConnectivityMode QPlaceManager::connectivityMode() const +{ + return d->engine->connectivityMode(); +} + +/*! + Sets the \a connectivityMode of the manager. +*/ +void QPlaceManager::setConnectivityMode(ConnectivityMode connectivityMode) +{ + return d->engine->setConnectivityMode(connectivityMode); +} + +/*! + Returns the list of connectivity modes that the manager supports. +*/ +QList<QPlaceManager::ConnectivityMode> QPlaceManager::supportedConnectivityModes() const +{ + return d->engine->supportedConnectivityModes(); +} + +/*! + Returns the visibility scope when searching through places, eg search + only public places or private places. +*/ +QPlaceManager::SearchVisibilityScope QPlaceManager::searchVisibilityScope() const +{ + return d->engine->searchVisibilityScope(); +} + +/*! + Sets the visibility \a scope to be used for searching for places. +*/ +void QPlaceManager::setSearchVisbilityScopes(SearchVisibilityScope scope) +{ + d->engine->setSearchVisbilityScope(scope); +} + +/*! + Returns a list of search visibility scopes that the manager supports. +*/ +QList<QPlaceManager::SearchVisibilityScope> QPlaceManager::supportedSearchVisibilityScopes() const +{ + return d->engine->supportedSearchVisibilityScopes(); +} + +/*! + Initializes the manager categories using a given + \a categorySystemId. +*/ +QPlaceReply *QPlaceManager::initializeCategories(const QString &categorySystemId) +{ + return d->engine->initializeCategories(categorySystemId); +} + +/*! + Returns a list of top level categories. +*/ +QList<QPlaceCategory> QPlaceManager::categories() const +{ + return d->engine->categories(); +} + +/*! +\fn void QPlaceManager::finished(QPlaceReply* reply) + +This signal is emitted when \a reply has finished processing. + +If reply->error() equals QPlaceReply::NoError then the processing +finished successfully. + +This signal and QPlaceReply::finished() will be emitted at the same time. + +\note Do no delete the \a reply object in the slot connected to this signal. +Use deleteLater() instead. +*/ + +/*! +\fn void QPlaceManager::error(QPlaceReply* reply, QPlaceReply::Error error, const QString &errorString) + +This signal is emitted when an error has been detected in the processing of +\a reply. The QPlaceManager::finished() signal will probably follow. + +The error will be described by the error code \a error. If \a errorString is +not empty it will contain a textual description of the error meant for developers +and not end users. + +This signal and QPlaceReply::error() will be emitted at the same time. + +\note Do no delete the \a reply object in the slot connected to this signal. +Use deleteLater() instead. +*/ diff --git a/src/location/places/qplacemanager.h b/src/location/places/qplacemanager.h new file mode 100644 index 00000000..524c0415 --- /dev/null +++ b/src/location/places/qplacemanager.h @@ -0,0 +1,92 @@ +#ifndef QPLACEMANAGER_H +#define QPLACEMANAGER_H + +#include "qplaceglobal.h" +#include "qplacemediaobject.h" +#include "qplacemediareply.h" +#include "qplacereply.h" +#include "qplacesearchquery.h" +#include "qplacesearchreply.h" +#include "qplacedetailsreply.h" +#include "qplacereviewreply.h" +#include "qplacetextpredictionreply.h" + +#include <QVector> +#include <QString> +#include <QObject> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceManagerEngine; + +class QPlaceManagerPrivate; +class Q_PLACES_EXPORT QPlaceManager : public QObject +{ + Q_OBJECT +public: + enum ConnectivityMode { + NoConnectivity, + OnlineMode, + OfflineMode, + HybridMode + }; + + enum SearchVisibilityScope { + PublicSearch, + PrivateSearch, + PublicAndPrivateSearch + }; + + enum ManagerFeature { + ImportFeature, + ExportFeature, + CheckInFeature, + PostMediaFeature, + PostRatingFeature, + SuggestionFeature, + ReportPlaceFeature, + AuthenticationFeature, + CreatePlaceFeature, + UpdatePlaceFeature + }; + + QPlaceManager(QObject *parent = 0); + ~QPlaceManager(); + QString managerName() const; + + QPlaceDetailsReply *getPlaceDetails(const QString &placeId) const; + QPlaceReply *postRating(const QPlace &place, qreal value); + + QPlaceReviewReply *getReviews(const QPlace &place, const QPlaceQuery &query) const; + + QPlaceMediaReply *getMedia(const QPlace &place, const QPlaceQuery &query) const; + + QPlaceSearchReply *searchForPlaces(const QPlaceSearchQuery &query) const; + QPlaceSearchReply *recommendations(const QPlace &place, const QPlaceSearchQuery &query) const; + + QPlaceTextPredictionReply *textPredictions(const QPlaceSearchQuery &query) const; + + ConnectivityMode connectivityMode() const; + void setConnectivityMode(ConnectivityMode connectivityMode); + QList<ConnectivityMode> supportedConnectivityModes() const; + + SearchVisibilityScope searchVisibilityScope() const; + void setSearchVisbilityScopes(SearchVisibilityScope scope); + QList<SearchVisibilityScope> supportedSearchVisibilityScopes() const; + + QPlaceReply *initializeCategories(const QString &categorySystemId = QString()); + QList<QPlaceCategory> categories() const; + QPlaceCategory createCategory() const; + +Q_SIGNALS: + void finished(QPlaceReply *reply); + void error(QPlaceReply *, QPlaceReply::Error error, const QString &errorString = QString()); + +private: + Q_DISABLE_COPY(QPlaceManager) + QPlaceManagerPrivate* d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMANAGER_H diff --git a/src/location/places/qplacemanagerengine.cpp b/src/location/places/qplacemanagerengine.cpp new file mode 100644 index 00000000..948ec9f3 --- /dev/null +++ b/src/location/places/qplacemanagerengine.cpp @@ -0,0 +1,14 @@ +#include "qplacemanagerengine.h" + +#include "qplacecategory_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceManagerEngine::QPlaceManagerEngine(QObject *parent) + : QObject(parent) +{ +} + +QPlaceManagerEngine::~QPlaceManagerEngine() +{ +} diff --git a/src/location/places/qplacemanagerengine.h b/src/location/places/qplacemanagerengine.h new file mode 100644 index 00000000..527d23b5 --- /dev/null +++ b/src/location/places/qplacemanagerengine.h @@ -0,0 +1,49 @@ +#ifndef QPLACEMANAGERENGINE_H +#define QPLACEMANAGERENGINE_H + +#include "qplacemanager.h" + +namespace QT_PLACES_NAMESPACE { + +class Q_PLACES_EXPORT QPlaceManagerEngine : public QObject +{ + Q_OBJECT +public: + + QPlaceManagerEngine(QObject *parent = 0); + virtual ~QPlaceManagerEngine(); + + virtual QString managerName() const = 0; + + virtual QPlaceDetailsReply *getPlaceDetails(const QString &placeId) = 0; + + virtual QPlaceMediaReply *getMedia(const QPlace &place, const QPlaceQuery &query) = 0; + + virtual QPlaceReply *postRating(const QPlace &place, qreal value) = 0; + + virtual QPlaceReviewReply *getReviews(const QPlace &place, const QPlaceQuery &query) = 0; + + virtual QPlaceSearchReply *searchForPlaces(const QPlaceSearchQuery &query) = 0; + virtual QPlaceSearchReply *recommendations(const QPlace &place, const QPlaceSearchQuery &query) = 0; + virtual QPlaceTextPredictionReply *textPredictions(const QPlaceSearchQuery &query) = 0; + + virtual QPlaceManager::ConnectivityMode connectivityMode() const = 0; + virtual void setConnectivityMode(QPlaceManager::ConnectivityMode connectivityMode) = 0; + virtual QList<QPlaceManager::ConnectivityMode> supportedConnectivityModes() const = 0; + + virtual QPlaceManager::SearchVisibilityScope searchVisibilityScope() const = 0; + virtual void setSearchVisbilityScope(QPlaceManager::SearchVisibilityScope scope) = 0; + virtual QList<QPlaceManager::SearchVisibilityScope> supportedSearchVisibilityScopes() const = 0; + + virtual QPlaceReply *initializeCategories(const QString &categorySystemId) = 0; + virtual QList<QPlaceCategory> categories() const = 0; + +Q_SIGNALS: + void finished(QPlaceReply *reply); + void error(QPlaceReply *, QPlaceReply::Error error, QString errorString = QString()); + +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMANAGER_H diff --git a/src/location/places/qplacemediaobject.cpp b/src/location/places/qplacemediaobject.cpp new file mode 100644 index 00000000..3dbb4047 --- /dev/null +++ b/src/location/places/qplacemediaobject.cpp @@ -0,0 +1,182 @@ +#include "qplacemediaobject.h" +#include "qplacemediaobject_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceMediaObjectPrivate::QPlaceMediaObjectPrivate() : QSharedData() +{ +} + +QPlaceMediaObjectPrivate::QPlaceMediaObjectPrivate(const QPlaceMediaObjectPrivate &other) + : QSharedData() +{ + this->url = other.url; + this->thumbnailURL = other.thumbnailURL; + this->id = other.id; + this->metaInfo = other.metaInfo; + this->mimeType = other.mimeType; + this->supplier = other.supplier; +} + +QPlaceMediaObjectPrivate::~QPlaceMediaObjectPrivate() +{ +} + +bool QPlaceMediaObjectPrivate::operator==(const QPlaceMediaObjectPrivate &other) const +{ + return ( + this->url == other.url + && this->thumbnailURL == other.thumbnailURL + && this->id == other.id + && this->metaInfo == other.metaInfo + && this->mimeType == other.mimeType + && this->supplier == other.supplier + ); +} + +/*! + \class QPlaceMediaObject + + \inmodule QPlaces + + \brief The QPlaceMediaObject class represents a media object. + + + Each QPlaceMediaObject represents a media object with a number of attributes + such as type, thumbnail, media provider etc. Each QPlaceMediaObject may be associated + with place. + + Media objects are read-only, e.g. user of API might get list of media objects + associated to specific place but can not edit its content. + + QPlaceMediaObject is an in memory representation of a media object. +*/ + +/*! + Constructs an new media object. +*/ +QPlaceMediaObject::QPlaceMediaObject() + : d(new QPlaceMediaObjectPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceMediaObject::QPlaceMediaObject(const QPlaceMediaObject &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceMediaObject::~QPlaceMediaObject() +{ +} + +QPlaceMediaObject &QPlaceMediaObject::operator =(const QPlaceMediaObject &other) { + d = other.d; + return *this; +} + +bool QPlaceMediaObject::operator==(const QPlaceMediaObject &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns media url. +*/ +QString QPlaceMediaObject::url() const +{ + return d->url; +} + +/*! + Sets media url. +*/ +void QPlaceMediaObject::setUrl(const QString &data) +{ + d->url = data; +} + +/*! + Returns media url for thumbnail. +*/ +QString QPlaceMediaObject::thumbnailUrl() const +{ + return d->thumbnailURL; +} + +/*! + Sets media url for thumbnail. +*/ +void QPlaceMediaObject::setThumbnailUrl(const QString &data) +{ + d->thumbnailURL = data; +} + +/*! + Returns media id. +*/ +QString QPlaceMediaObject::id() const +{ + return d->id; +} + +/*! + Sets media id. +*/ +void QPlaceMediaObject::setId(const QString &data) +{ + d->id = data; +} + +/*! + Returns media meta info. +*/ +QString QPlaceMediaObject::metaInfo() const +{ + return d->metaInfo; +} + +/*! + Sets media meta info. +*/ +void QPlaceMediaObject::setMetaInfo(const QString &data) +{ + d->metaInfo = data; +} + +/*! + Returns media mime type. +*/ +QString QPlaceMediaObject::mimeType() const +{ + return d->mimeType; +} + +/*! + Sets media mime type. +*/ +void QPlaceMediaObject::setMimeType(const QString &data) +{ + d->mimeType = data; +} + +/*! + Returns supplier. +*/ +QPlaceSupplier QPlaceMediaObject::supplier() const +{ + return d->supplier; +} + +/*! + Sets supplier. +*/ +void QPlaceMediaObject::setSupplier(const QPlaceSupplier &data) +{ + d->supplier = data; +} diff --git a/src/location/places/qplacemediaobject.h b/src/location/places/qplacemediaobject.h new file mode 100644 index 00000000..55cd8506 --- /dev/null +++ b/src/location/places/qplacemediaobject.h @@ -0,0 +1,47 @@ +#ifndef QPLACEMEDIAOBJECT_H +#define QPLACEMEDIAOBJECT_H + +#include <QSharedDataPointer> +#include <QString> +#include "qplaceglobal.h" +#include "qplacesupplier.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceMediaObjectPrivate; + +class Q_PLACES_EXPORT QPlaceMediaObject +{ +public: + QPlaceMediaObject(); + QPlaceMediaObject(const QPlaceMediaObject &other); + + virtual ~QPlaceMediaObject(); + + QPlaceMediaObject &operator=(const QPlaceMediaObject &other); + + bool operator==(const QPlaceMediaObject &other) const; + bool operator!=(const QPlaceMediaObject &other) const { + return !(other == *this); + } + + QString url() const; + void setUrl(const QString &data); + QString thumbnailUrl() const; + void setThumbnailUrl(const QString &data); + QString id() const; + void setId(const QString &data); + QString metaInfo() const; + void setMetaInfo(const QString &data); + QString mimeType() const; + void setMimeType(const QString &data); + QPlaceSupplier supplier() const; + void setSupplier(const QPlaceSupplier &data); + +private: + QSharedDataPointer<QPlaceMediaObjectPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMEDIAOBJECT_H diff --git a/src/location/places/qplacemediaobject_p.h b/src/location/places/qplacemediaobject_p.h new file mode 100644 index 00000000..9350ff8c --- /dev/null +++ b/src/location/places/qplacemediaobject_p.h @@ -0,0 +1,30 @@ +#ifndef QPLACEMEDIAOBJECT_P_H +#define QPLACEMEDIAOBJECT_P_H + +#include <QSharedData> + +#include "qplacemediaobject.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceMediaObjectPrivate : public QSharedData +{ +public: + QPlaceMediaObjectPrivate(); + QPlaceMediaObjectPrivate(const QPlaceMediaObjectPrivate &other); + + ~QPlaceMediaObjectPrivate(); + + bool operator==(const QPlaceMediaObjectPrivate &other) const; + + QString url; + QString thumbnailURL; + QString id; + QString metaInfo; + QString mimeType; + QPlaceSupplier supplier; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEMEDIAOBJECT_P_H diff --git a/src/location/places/qplacemediareply.cpp b/src/location/places/qplacemediareply.cpp new file mode 100644 index 00000000..d3e0d7ae --- /dev/null +++ b/src/location/places/qplacemediareply.cpp @@ -0,0 +1,85 @@ +#include "qplacemediareply.h" + +#include "qplace.h" + +namespace QT_PLACES_NAMESPACE { +class QPlaceMediaReplyPrivate +{ +public: + QPlaceMediaReplyPrivate() {} + QList<QPlaceMediaObject> mediaObjects; + int totalCount; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceMediaReply + + \brief The QPlaceMediaReply class manages a media retrieval operation started by an + instance of QPlaceManager. + + \inmodule QtLocation + + \ingroup places-main +*/ + +/*! + Constructs a media reply with a given \a parent. +*/ +QPlaceMediaReply::QPlaceMediaReply(QObject *parent) + : QPlaceReply(parent) +{ + d = new QPlaceMediaReplyPrivate; +} + +/*! + Destroys the reply. +*/ +QPlaceMediaReply::~QPlaceMediaReply() +{ + delete d; +} + + /*! + Returns the media objects. +*/ +QList<QPlaceMediaObject> QPlaceMediaReply::mediaObjects() const +{ + return d->mediaObjects; +} + +/*! + Returns the type of reply. +*/ +QPlaceReply::Type QPlaceMediaReply::type() const +{ + return QPlaceReply::MediaReply; +} + +/*! + Sets the media \a objects. +*/ +void QPlaceMediaReply::setMediaObjects(const QList<QPlaceMediaObject> &objects) +{ + d->mediaObjects = objects; +} + +/*! + Returns the total number of media objects for a place. If the total number of + media objects cannot be counted a value of -1 is returned. +*/ +int QPlaceMediaReply::totalCount() +{ + return d->totalCount; +} + +/*! + Sets the \a total number of media objects for a place. +*/ +void QPlaceMediaReply::setTotalCount(int total) +{ + d->totalCount = total; +} diff --git a/src/location/places/qplacemediareply.h b/src/location/places/qplacemediareply.h new file mode 100644 index 00000000..fa1882c0 --- /dev/null +++ b/src/location/places/qplacemediareply.h @@ -0,0 +1,35 @@ +#ifndef QPLACEMEDIAREPLY_H +#define QPLACEMEDIAREPLY_H + +#include "qplacereply.h" +#include "qplacemediaobject.h" + +#include <QStringList> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceMediaReplyPrivate; +class Q_PLACES_EXPORT QPlaceMediaReply : public QPlaceReply +{ + Q_OBJECT +public: + QPlaceMediaReply(QObject *parent =0); + virtual ~QPlaceMediaReply(); + + QPlaceReply::Type type() const; + + QList<QPlaceMediaObject> mediaObjects() const; + + int totalCount(); + +protected: + void setMediaObjects(const QList<QPlaceMediaObject> &objects); + void setTotalCount(int total); + +private: + QPlaceMediaReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif diff --git a/src/location/places/qplacepaginationlist.h b/src/location/places/qplacepaginationlist.h new file mode 100644 index 00000000..18f1704a --- /dev/null +++ b/src/location/places/qplacepaginationlist.h @@ -0,0 +1,85 @@ +#ifndef QPLACEPAGINATIONLIST_H +#define QPLACEPAGINATIONLIST_H + +#include <QSharedDataPointer> +#include <QList> +#include "qplaceglobal.h" +#include "qplacesupplier.h" + +namespace QT_PLACES_NAMESPACE { + +/*! + \class QPlacePaginationList + + \inmodule QPlaces + + \brief The QPlacePaginationList class represents a list object. + + Each QPlacePaginationList represents a pagination-enabled list. It contais list + of items on current page and ifnormations about indexes of those items. + +*/ +template <typename T> +class Q_PLACES_EXPORT QPlacePaginationList +{ +public: + QPlacePaginationList() : startIndx(0) {}; + QPlacePaginationList(const QPlacePaginationList<T> &other) { + this->startIndx = other.startIndx; + this->dataList = other.dataList; + } + + ~QPlacePaginationList() {}; + + QPlacePaginationList<T> &operator=(const QPlacePaginationList<T> &other) { + this->startIndx = other.startIndx; + this->dataList = other.dataList; + return *this; + } + + bool operator==(const QPlacePaginationList<T> &other) const { + return ( + this->startIndx == other.startIndx + && this->dataList == other.dataList + ); + } + bool operator!=(const QPlacePaginationList<T> &other) const { + return !(other == *this); + } + + /*! + Returns items count on current page. + */ + int items() { return dataList.count(); } + /*! + Returns index of first item on current page. + */ + int start() { return startIndx; } + /*! + Returns index of last item on current page. + */ + int stop() { return startIndx + dataList.count(); } + /*! + Returns items list on current page. + */ + QList<T> data() { return dataList; } + /*! + Sets index of first item on current page. + */ + void setStart(const int &start) { startIndx = start; } + /*! + Sets list of items on current page. + */ + void setData(const QList<T> &data) { dataList = data; } + /*! + Append item to the list. + */ + void addItem(const T &item) { dataList.append(item); } +private: + int startIndx; + QList<T> dataList; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEPAGINATIONLIST_H diff --git a/src/location/places/qplaceperiod.cpp b/src/location/places/qplaceperiod.cpp new file mode 100644 index 00000000..6077b75b --- /dev/null +++ b/src/location/places/qplaceperiod.cpp @@ -0,0 +1,224 @@ +#include "qplaceperiod.h" +#include "qplaceperiod_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlacePeriodPrivate::QPlacePeriodPrivate() : QSharedData() +{ + this->values = QPlacePeriodPrivate::None; +} + +QPlacePeriodPrivate::QPlacePeriodPrivate(const QPlacePeriodPrivate &other) + : QSharedData() +{ + this->values = other.values; + this->begin = other.begin; + this->end = other.end; +} + +QPlacePeriodPrivate::~QPlacePeriodPrivate() +{ +} + +bool QPlacePeriodPrivate::operator==(const QPlacePeriodPrivate &other) const +{ + return ( + this->values == other.values + && this->begin == other.begin + && this->end == other.end + ); +} + +/*! + \class QPlacePeriod + + \inmodule QPlaces + + \brief The QPlacePeriod class represents a time period object. + It might contains just hours information but it might contains also + date. If some field is unasaignd it will return -1. +*/ + +/*! + Constructs an new period object. +*/ +QPlacePeriod::QPlacePeriod() + : d(new QPlacePeriodPrivate) +{ +} + + +QPlacePeriod::QPlacePeriod(int startHour, int startMinute, int endHour, int endMinute) + : d(new QPlacePeriodPrivate) +{ + QTime startTime(startHour, startMinute); + d->begin.setTime(startTime); + QTime endTime(endHour, endMinute); + d->end.setTime(endTime); + d->values = QPlacePeriodPrivate::Time; +} + +QPlacePeriod::QPlacePeriod(int startMonth, int startDay, int startHour, int startMinute, + int endMonth, int endDay, int endHour, int endMinute) + : d(new QPlacePeriodPrivate) +{ + QTime startTime(startHour, startMinute); + QDate startDate(2008, startMonth, startDay); + d->begin.setTime(startTime); + d->begin.setDate(startDate); + QTime endTime(endHour, endMinute); + QDate endDate(2008, endMonth, endDay); + d->end.setTime(endTime); + d->end.setDate(endDate); + d->values = QPlacePeriodPrivate::Time & QPlacePeriodPrivate::Date; +} + +QPlacePeriod::QPlacePeriod(int startYear, int startMonth, int startDay, int startHour, int startMinute, + int endYear, int endMonth, int endDay, int endHour, int endMinute) + : d(new QPlacePeriodPrivate) +{ + QTime startTime(startHour, startMinute); + QDate startDate(startYear, startMonth, startDay); + d->begin.setTime(startTime); + d->begin.setDate(startDate); + QTime endTime(endHour, endMinute); + QDate endDate(endYear, endMonth, endDay); + d->end.setTime(endTime); + d->end.setDate(endDate); + d->values = QPlacePeriodPrivate::Time & QPlacePeriodPrivate::Date & QPlacePeriodPrivate::Year; +} + +/*! + Constructs a copy of \a other +*/ +QPlacePeriod::QPlacePeriod(const QPlacePeriod &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlacePeriod::~QPlacePeriod() +{ +} + +QPlacePeriod &QPlacePeriod::operator =(const QPlacePeriod &other) { + d = other.d; + return *this; +} + +bool QPlacePeriod::operator==(const QPlacePeriod &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns start year. -1 returned if not set. +*/ +int QPlacePeriod::startYear() const +{ + if (d->values & QPlacePeriodPrivate::Year) { + return d->begin.date().year(); + } + return -1; +} + +/*! + Returns start month. -1 returned if not set. +*/ +int QPlacePeriod::startMonth() const +{ + if (d->values & QPlacePeriodPrivate::Date) { + return d->begin.date().month(); + } + return -1; +} + +/*! + Returns start day. -1 returned if not set. +*/ +int QPlacePeriod::startDay() const +{ + if (d->values & QPlacePeriodPrivate::Date) { + return d->begin.date().day(); + } + return -1; +} + +/*! + Returns start hour. -1 returned if not set. +*/ +int QPlacePeriod::startHour() const +{ + if (d->values & QPlacePeriodPrivate::Time) { + return d->begin.time().hour(); + } + return -1; +} + +/*! + Returns start minute. -1 returned if not set. +*/ +int QPlacePeriod::startMinute() const +{ + if (d->values & QPlacePeriodPrivate::Time) { + return d->begin.time().minute(); + } + return -1; +} + +/*! + Returns end year. -1 returned if not set. +*/ +int QPlacePeriod::endYear() const +{ + if (d->values & QPlacePeriodPrivate::Year) { + return d->end.date().year(); + } + return -1; +} + +/*! + Returns end month. -1 returned if not set. +*/ +int QPlacePeriod::endMonth() const +{ + if (d->values & QPlacePeriodPrivate::Date) { + return d->end.date().month(); + } + return -1; +} + +/*! + Returns end day. -1 returned if not set. +*/ +int QPlacePeriod::endDay() const +{ + if (d->values & QPlacePeriodPrivate::Date) { + return d->end.date().day(); + } + return -1; +} + +/*! + Returns end year. -1 returned if not set. +*/ +int QPlacePeriod::endHour() const +{ + if (d->values & QPlacePeriodPrivate::Time) { + return d->end.time().hour(); + } + return -1; +} + +/*! + Returns end year. -1 returned if not set. +*/ +int QPlacePeriod::endMinute() const +{ + if (d->values & QPlacePeriodPrivate::Time) { + return d->end.time().minute(); + } + return -1; +} diff --git a/src/location/places/qplaceperiod.h b/src/location/places/qplaceperiod.h new file mode 100644 index 00000000..fcab2dd4 --- /dev/null +++ b/src/location/places/qplaceperiod.h @@ -0,0 +1,50 @@ +#ifndef QPLACEPERIOD_H +#define QPLACEPERIOD_H + +#include <QDateTime> +#include <QSharedDataPointer> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlacePeriodPrivate; + +class Q_PLACES_EXPORT QPlacePeriod +{ +public: + QPlacePeriod(); + QPlacePeriod(int startHour, int startMinute, int endHour, int endMinute); + QPlacePeriod(int startMonth, int startDay, int startHour, int startMinute, + int endMonth, int endDay, int endHour, int endMinute); + QPlacePeriod(int startYear, int startMonth, int startDay, int startHour, int startMinute, + int endYear, int endMonth, int endDay, int endHour, int endMinute); + + QPlacePeriod(const QPlacePeriod &other); + + virtual ~QPlacePeriod(); + + QPlacePeriod &operator=(const QPlacePeriod &other); + + bool operator==(const QPlacePeriod &other) const; + bool operator!=(const QPlacePeriod &other) const { + return !(other == *this); + } + + int startYear() const; + int startMonth() const; + int startDay() const; + int startHour() const; + int startMinute() const; + int endYear() const; + int endMonth() const; + int endDay() const; + int endHour() const; + int endMinute() const; + +private: + QSharedDataPointer<QPlacePeriodPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEPERIOD_H diff --git a/src/location/places/qplaceperiod_p.h b/src/location/places/qplaceperiod_p.h new file mode 100644 index 00000000..899cdc88 --- /dev/null +++ b/src/location/places/qplaceperiod_p.h @@ -0,0 +1,35 @@ +#ifndef QPLACEPERIOD_P_H +#define QPLACEPERIOD_P_H + +#include <QSharedData> + +#include "qplaceperiod.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlacePeriodPrivate : public QSharedData +{ +public: + QPlacePeriodPrivate(); + QPlacePeriodPrivate(const QPlacePeriodPrivate &other); + + ~QPlacePeriodPrivate(); + + bool operator==(const QPlacePeriodPrivate &other) const; + + enum Value { + None = 0, + Date = 1, + Time = 2, + Year = 4 + }; + + Q_DECLARE_FLAGS(Values, Value); + Values values; + QDateTime begin; + QDateTime end; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEPERIOD_P_H diff --git a/src/location/places/qplacequery.cpp b/src/location/places/qplacequery.cpp new file mode 100644 index 00000000..f1b19d0c --- /dev/null +++ b/src/location/places/qplacequery.cpp @@ -0,0 +1,141 @@ +#include "qplacequery.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceQueryPrivate : public QSharedData +{ +public: + QPlaceQueryPrivate(); + QPlaceQueryPrivate(const QPlaceQueryPrivate &other); + + ~QPlaceQueryPrivate(); + + bool operator==(const QPlaceQueryPrivate &other) const; + + int offset; + int limit; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +QPlaceQueryPrivate::QPlaceQueryPrivate() : QSharedData() +{ +} + +QPlaceQueryPrivate::QPlaceQueryPrivate(const QPlaceQueryPrivate &other) + : QSharedData() +{ + this->offset = other.offset; + this->limit = other.limit; +} + +QPlaceQueryPrivate::~QPlaceQueryPrivate() +{ +} + +bool QPlaceQueryPrivate::operator==(const QPlaceQueryPrivate &other) const +{ + return ( + this->offset == other.offset + && this->limit == other.limit + ); +} + +/*! + \class QPlaceQuery + + \inmodule Location + + \brief The QPlaceQuery class is the base class used for various search queries. + + \ingroup places-main + +*/ + +/*! + Default constructor. Constructs an new query object. +*/ +QPlaceQuery::QPlaceQuery() + : d(new QPlaceQueryPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceQuery::QPlaceQuery(const QPlaceQuery &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceQuery::~QPlaceQuery() +{ +} + +QPlaceQuery &QPlaceQuery::operator =(const QPlaceQuery &other) { + d = other.d; + return *this; +} + +bool QPlaceQuery::operator==(const QPlaceQuery &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns the offset. By default the offset is set to 0. + The offset determines the first index which is retrieved, it is generally + used in conjunction with limit() to facilitate paging. + + Negative offests are treated as an offset of 0; +*/ +int QPlaceQuery::offset() const +{ + return d->offset; +} + +/*! + Sets the \a offset. +*/ +void QPlaceQuery::setOffset(int offset) +{ + d->offset = offset; +} + +/*! + Returns the maximum number of places to be fetched. The default + value of this limit is -1, indicating that the default limit of the + backend should be used. +*/ +int QPlaceQuery::limit() const +{ + return d->limit; +} + +/*! + Sets the maximum number of places to be fetched to \a limit. + + A limit of -1 indicates that the default limit of the backend should used. + If the backend maximum limit is less than \a limit, then only the + backend maximum limit number of places are retrieved. + + (A limit of 0 will retrieve no places). +*/ +void QPlaceQuery::setLimit(int limit) +{ + d->limit = limit; +} + +/*! + Clears the parameters of the search query. +*/ +void QPlaceQuery::clear() +{ + d->offset = -1; + d->limit = -1; +} diff --git a/src/location/places/qplacequery.h b/src/location/places/qplacequery.h new file mode 100644 index 00000000..18d0806f --- /dev/null +++ b/src/location/places/qplacequery.h @@ -0,0 +1,39 @@ +#ifndef QPLACEQUERY_H +#define QPLACEQUERY_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceQueryPrivate; + +class Q_PLACES_EXPORT QPlaceQuery +{ +public: + QPlaceQuery(); + QPlaceQuery(const QPlaceQuery &other); + + virtual ~QPlaceQuery(); + + QPlaceQuery &operator=(const QPlaceQuery &other); + + bool operator==(const QPlaceQuery &other) const; + bool operator!=(const QPlaceQuery &other) const { + return !(other == *this); + } + + int offset() const; + void setOffset(int offset); + int limit() const; + void setLimit(int limit); + + virtual void clear(); + +private: + QSharedDataPointer<QPlaceQueryPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif diff --git a/src/location/places/qplacerating.cpp b/src/location/places/qplacerating.cpp new file mode 100644 index 00000000..19c46573 --- /dev/null +++ b/src/location/places/qplacerating.cpp @@ -0,0 +1,104 @@ +#include "qplacerating.h" +#include "qplacerating_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceRatingPrivate::QPlaceRatingPrivate() : QSharedData() +{ +} + +QPlaceRatingPrivate::QPlaceRatingPrivate(const QPlaceRatingPrivate &other) + : QSharedData() +{ + this->value = other.value; + this->count = other.count; +} + +QPlaceRatingPrivate::~QPlaceRatingPrivate() +{ +} + +bool QPlaceRatingPrivate::operator==(const QPlaceRatingPrivate &other) const +{ + return ( + this->value == other.value + && this->count == other.count + ); +} + +/*! + \class QPlaceRating + + \inmodule QPlaces + + \brief The QPlaceRating class represents a rating object. + + Each QPlaceRating represents a rating object with a count and value. + + QPlaceRating is an in memory representation of a rating object. +*/ + +/*! + Constructs a new rating object. +*/ +QPlaceRating::QPlaceRating() + : d(new QPlaceRatingPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceRating::QPlaceRating(const QPlaceRating &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceRating::~QPlaceRating() +{ +} + +QPlaceRating &QPlaceRating::operator =(const QPlaceRating &other) { + d = other.d; + return *this; +} + +bool QPlaceRating::operator==(const QPlaceRating &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns value. +*/ +double QPlaceRating::value() const +{ + return d->value; +} + +/*! + Sets value. +*/ +void QPlaceRating::setValue(const double &src) +{ + d->value = src; +} + +/*! + Returns count. +*/ +uint QPlaceRating::count() const +{ + return d->count; +} + +/*! + Sets count. +*/ +void QPlaceRating::setCount(const uint &src) +{ + d->count = src; +} diff --git a/src/location/places/qplacerating.h b/src/location/places/qplacerating.h new file mode 100644 index 00000000..98b96775 --- /dev/null +++ b/src/location/places/qplacerating.h @@ -0,0 +1,37 @@ +#ifndef QPLACERATING_H +#define QPLACERATING_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceRatingPrivate; + +class Q_PLACES_EXPORT QPlaceRating +{ +public: + QPlaceRating(); + QPlaceRating(const QPlaceRating &other); + + virtual ~QPlaceRating(); + + QPlaceRating &operator=(const QPlaceRating &other); + + bool operator==(const QPlaceRating &other) const; + bool operator!=(const QPlaceRating &other) const { + return !(other == *this); + } + + double value() const; + void setValue(const double &data); + uint count() const; + void setCount(const uint &data); + +private: + QSharedDataPointer<QPlaceRatingPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACERATING_H diff --git a/src/location/places/qplacerating_p.h b/src/location/places/qplacerating_p.h new file mode 100644 index 00000000..8756fee3 --- /dev/null +++ b/src/location/places/qplacerating_p.h @@ -0,0 +1,26 @@ +#ifndef QPLACERATING_P_H +#define QPLACERATING_P_H + +#include <QSharedData> + +#include "qplacerating.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceRatingPrivate : public QSharedData +{ +public: + QPlaceRatingPrivate(); + QPlaceRatingPrivate(const QPlaceRatingPrivate &other); + + ~QPlaceRatingPrivate(); + + bool operator==(const QPlaceRatingPrivate &other) const; + + double value; + uint count; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACERATING_P_H diff --git a/src/location/places/qplacereply.cpp b/src/location/places/qplacereply.cpp new file mode 100644 index 00000000..babb191a --- /dev/null +++ b/src/location/places/qplacereply.cpp @@ -0,0 +1,183 @@ +#include "qplacereply.h" + +#include "qplace.h" +#include "qplacesearchresult.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReplyPrivate +{ +public: + QPlaceReplyPrivate() : isFinished(false) {} + QPlaceReply::Error error; + QString errorString; + bool isFinished; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceReply + + \inmodule Location + + \brief The QPlaceReply class manages an operation started by + an instance of QPlaceManager. + + \ingroup places-main +*/ + +/*! + \enum QPlaceReply::Error + + Describes an error which prevented completion of an operation. + \value NoError + No error has occurred + \value DoesNotExistError + An entity does not exist eg an import file. + \value PlaceDoesNotExistError + A specified place could not be found + \value CategoryDoesNotExistError + A specified category could not be found + \value CommunicationError + An error occurred communicating with the service provider. + \value ParseError + The response from the service provider or an import file was in an unrecognizable format + \value PermissionsError + The operation failed because of insufficient permissions. + \value UnsupportedError + The operation was not supported by the service provider. + \value CancelError + The operation was canceled. + \value UnknownError + An error occurred which does not fit into any of the other categories. +*/ + +/*! + \enum QPlaceReply::Type + + Describes the reply's type. + \value Reply + This is a generic reply. + \value TextPredictionReply + Thi is the reply for a text prediction operation. + \value ReviewReply + This is a reply for the retrieval of place reviews. + \value MediaReply + This is a reply for the retrieval of place media. + \value PlaceDetailsReply + This is a reply for the retrieval of place details. + \value PlaceSearchReply + This is a reply for a place search operation. +*/ + +/*! + Constructs a reply object with a given \a parent. +*/ +QPlaceReply::QPlaceReply(QObject *parent) + : QObject(parent) +{ +} + +/*! + Destructor. +*/ +QPlaceReply::~QPlaceReply() +{ + if (!isFinished()) { + abort(); + } +} + +/*! + Return true if the reply has completed. +*/ +bool QPlaceReply::isFinished() const +{ + return d->isFinished; +} + +/*! + Return type of operation. +*/ +QPlaceReply::Type QPlaceReply::type() const +{ + return QPlaceReply::Reply; +} + +/*! + Sets the status of whether the reply is \a finished + or not. This function does not cause the finished() signal + to be emitted. +*/ +void QPlaceReply::setFinished(bool finished) +{ + d->isFinished = finished; +} + +/*! + Sets the \a error and \a errorString of the reply. + This function does not cause the error(QPlaceReply::Error, const QString &errorString) + signal to be emitted. +*/ +void QPlaceReply::setError(QPlaceReply::Error error, const QString &errorString) +{ + d->error = error; + d->errorString = errorString; +} + +/*! + Returns the error string. +*/ +QString QPlaceReply::errorString() const +{ + return d->errorString; +} + +/*! + Returns error code. +*/ +QPlaceReply::Error QPlaceReply::error() const +{ + return d->error; +} + +/*! + Aborts the operation. +*/ +void QPlaceReply::abort() +{ +} + +/*! + \fn void QPlaceReply::finished() + + This signal is emitted when this reply has finished processing. + + If error() equals QPlaceReply::NoError then the processing + finished successfully. + + This signal and QPlaceManager::finished() will be + emitted at the same time. + + \note Do no delete this reply object in the slot connected to this + signal. Use deleteLater() instead. +*/ + +/*! + \fn void QPlaceReply::error(QPlaceReply::Error error, const QString &errorString) + + This signal is emitted when an error has been detected in the processing of + this reply. The finished() signal will probably follow. + + The error will be described by the error code \a error. If \a errorString is + not empty it will contain a textual description of the error meant for + developers and not end users. + + This signal and QPlaceManager::error() will be emitted at the same time. + + \note Do no delete this reply object in the slot connected to this + signal. Use deleteLater() instead. +*/ diff --git a/src/location/places/qplacereply.h b/src/location/places/qplacereply.h new file mode 100644 index 00000000..bba2fdbd --- /dev/null +++ b/src/location/places/qplacereply.h @@ -0,0 +1,63 @@ +#ifndef QPLACEREPLY_H +#define QPLACEREPLY_H + +#include "qplaceglobal.h" +#include <QObject> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReplyPrivate; +class Q_PLACES_EXPORT QPlaceReply : public QObject +{ + Q_OBJECT +public: + enum Error { + NoError, + DoesNotExistError, + PlaceDoesNotExistError, + CategoryDoesNotExistError, + CommunicationError, + ParseError, + PermissionsError, + UnsupportedError, + CancelError, + UnknownError + }; + + enum Type { + Reply, + PlaceDetailsReply, + PlaceSearchReply, + TextPredictionReply, + ReviewReply, + MediaReply + }; + + virtual ~QPlaceReply(); + + bool isFinished() const; + + virtual Type type() const; + + QString errorString() const; + QPlaceReply::Error error() const; + +public Q_SLOTS: + virtual void abort(); + +Q_SIGNALS: + void finished(); + void error(QPlaceReply::Error error, const QString &errorString = QString()); + +protected: + QPlaceReply(QObject *parent = 0); + void setFinished(bool finished); + void setError(QPlaceReply::Error error, const QString &errorString); + +private: + QPlaceReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEREPLY_H diff --git a/src/location/places/qplacereview.cpp b/src/location/places/qplacereview.cpp new file mode 100644 index 00000000..a8dd2f23 --- /dev/null +++ b/src/location/places/qplacereview.cpp @@ -0,0 +1,309 @@ +#include "qplacereview.h" +#include "qplacereview_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceReviewPrivate::QPlaceReviewPrivate() : QSharedData() +{ +} + +QPlaceReviewPrivate::QPlaceReviewPrivate(const QPlaceReviewPrivate &other) + : QSharedData() +{ + this->date = other.date; + this->description = other.description; + this->language = other.language; + this->helpfulVotings = other.helpfulVotings; + this->mediaIds = other.mediaIds; + this->notHelpfulVotings = other.notHelpfulVotings; + this->rating = other.rating; + this->reviewId = other.reviewId; + this->supplier = other.supplier; + this->title = other.title; + this->userId = other.userId; + this->userName = other.userName; + this->originatorURL = other.originatorURL; +} + +QPlaceReviewPrivate::~QPlaceReviewPrivate() +{ +} + +bool QPlaceReviewPrivate::operator==(const QPlaceReviewPrivate &other) const +{ + return ( + this->date == other.date + && this->description == other.description + && this->language == other.language + && this->helpfulVotings == other.helpfulVotings + && this->mediaIds == other.mediaIds + && this->notHelpfulVotings == other.notHelpfulVotings + && this->rating == other.rating + && this->reviewId == other.reviewId + && this->supplier == other.supplier + && this->title == other.title + && this->userId == other.userId + && this->userName == other.userName + && this->originatorURL == other.originatorURL + ); +} + +/*! + \class QPlaceReview + + \inmodule QPlaces + + \brief The QPlaceReview class represents a review object. + + + Each QPlaceReview represents a review object with a number of attributes + such as rating, review id, connected media etc. Each QPlaceReview is associated + with place. + + Review objects are read-only, e.g. user of API might get list of review objects + associated to specific place but can not edit its content. User might also create new review. + + QPlaceReview is an in memory representation of a review object. +*/ + + +/*! + Constructs an new review object. +*/ +QPlaceReview::QPlaceReview() + : d(new QPlaceReviewPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceReview::QPlaceReview(const QPlaceReview &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceReview::~QPlaceReview() +{ +} + +QPlaceReview &QPlaceReview::operator =(const QPlaceReview &other) { + d = other.d; + return *this; +} + +bool QPlaceReview::operator==(const QPlaceReview &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns review date. +*/ +QString QPlaceReview::date() const +{ + return d->date; +} + +/*! + Sets review date. +*/ +void QPlaceReview::setDate(const QString &data) +{ + d->date = data; +} + +/*! + Returns description. +*/ +QString QPlaceReview::description() const +{ + return d->description; +} + +/*! + Sets description. +*/ +void QPlaceReview::setDescription(const QString &data) +{ + d->description = data; +} + +/*! + Returns language. +*/ +QString QPlaceReview::language() const +{ + return d->language; +} + +/*! + Sets language. +*/ +void QPlaceReview::setLanguage(const QString &data) +{ + d->language = data; +} + +/*! + Returns "thumbs up". +*/ +uint QPlaceReview::helpfulVotings() const +{ + return d->helpfulVotings; +} + +/*! + Sets "thumbs up". +*/ +void QPlaceReview::setHelpfulVotings(const uint &data) +{ + d->helpfulVotings = data; +} + +/*! + Returns media ids associated with review. +*/ +QStringList QPlaceReview::mediaIds() const +{ + return d->mediaIds; +} + +/*! + Sets media ids. +*/ +void QPlaceReview::setMediaIds(const QStringList &data) +{ + d->mediaIds = data; +} + +/*! + Returns "thumbs down". +*/ +uint QPlaceReview::notHelpfulVotings() const +{ + return d->notHelpfulVotings; +} + +/*! + Sets "thumbs down". +*/ +void QPlaceReview::setNotHelpfulVotings(const uint &data) +{ + d->notHelpfulVotings = data; +} + +/*! + Returns rating. +*/ +double QPlaceReview::rating() const +{ + return d->rating; +} + +/*! + Sets rating. +*/ +void QPlaceReview::setRating(const double &data) +{ + d->rating = data; +} + +/*! + Returns review id. +*/ +QString QPlaceReview::reviewId() const +{ + return d->reviewId; +} + +/*! + Sets review id. +*/ +void QPlaceReview::setReviewId(const QString &data) +{ + d->reviewId = data; +} + +/*! + Returns supplier. Do not remove it. +*/ +QPlaceSupplier QPlaceReview::supplier() const +{ + return d->supplier; +} + +/*! + Sets supplier. +*/ +void QPlaceReview::setSupplier(const QPlaceSupplier &data) +{ + d->supplier = data; +} + +/*! + Returns review title. +*/ +QString QPlaceReview::title() const +{ + return d->title; +} + +/*! + Sets title. +*/ +void QPlaceReview::setTitle(const QString &data) +{ + d->title = data; +} + +/*! + Returns user id. +*/ +QString QPlaceReview::userId() const +{ + return d->userId; +} + +/*! + Sets user id. +*/ +void QPlaceReview::setUserId(const QString &data) +{ + d->userId = data; +} + +/*! + Returns user name. +*/ +QString QPlaceReview::userName() const +{ + return d->userName; +} + +/*! + Sets user name. +*/ +void QPlaceReview::setUserName(const QString &data) +{ + d->userName = data; +} + +/*! + Returns originator URL. +*/ +QString QPlaceReview::originatorURL() const +{ + return d->originatorURL; +} + +/*! + Sets originator URL. +*/ +void QPlaceReview::setOriginatorURL(const QString &data) +{ + d->originatorURL = data; +} diff --git a/src/location/places/qplacereview.h b/src/location/places/qplacereview.h new file mode 100644 index 00000000..11f86f2c --- /dev/null +++ b/src/location/places/qplacereview.h @@ -0,0 +1,61 @@ +#ifndef QPLACEREVIEW_H +#define QPLACEREVIEW_H + +#include <QSharedDataPointer> +#include <QStringList> +#include "qplaceglobal.h" +#include "qplacesupplier.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReviewPrivate; + +class Q_PLACES_EXPORT QPlaceReview +{ +public: + QPlaceReview(); + QPlaceReview(const QPlaceReview &other); + + virtual ~QPlaceReview(); + + QPlaceReview &operator=(const QPlaceReview &other); + + bool operator==(const QPlaceReview &other) const; + bool operator!=(const QPlaceReview &other) const { + return !(other == *this); + } + + QString date() const; + void setDate(const QString &data); + QString description() const; + void setDescription(const QString &data); + QString language() const; + void setLanguage(const QString &data); + uint helpfulVotings() const; + void setHelpfulVotings(const uint &data); + QStringList mediaIds() const; + void setMediaIds(const QStringList &data); + uint notHelpfulVotings() const; + void setNotHelpfulVotings(const uint &data); + double rating() const; + void setRating(const double &data); + QString reviewId() const; + void setReviewId(const QString &data); + QPlaceSupplier supplier() const; + void setSupplier(const QPlaceSupplier &data); + QString title() const; + void setTitle(const QString &data); + QString userId() const; + void setUserId(const QString &data); + QString userName() const; + void setUserName(const QString &data); + QString originatorURL() const; + void setOriginatorURL(const QString &data); + +private: + QSharedDataPointer<QPlaceReviewPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEREVIEW_H diff --git a/src/location/places/qplacereview_p.h b/src/location/places/qplacereview_p.h new file mode 100644 index 00000000..f0cf6160 --- /dev/null +++ b/src/location/places/qplacereview_p.h @@ -0,0 +1,37 @@ +#ifndef QPLACEREVIEW_P_H +#define QPLACEREVIEW_P_H + +#include <QSharedData> + +#include "qplacereview.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReviewPrivate : public QSharedData +{ +public: + QPlaceReviewPrivate(); + QPlaceReviewPrivate(const QPlaceReviewPrivate &other); + + ~QPlaceReviewPrivate(); + + bool operator==(const QPlaceReviewPrivate &other) const; + + QString date; + QString description; + QString language; + uint helpfulVotings; + QStringList mediaIds; + uint notHelpfulVotings; + double rating; + QString reviewId; + QPlaceSupplier supplier; + QString title; + QString userId; + QString userName; + QString originatorURL; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEREVIEW_P_H diff --git a/src/location/places/qplacereviewreply.cpp b/src/location/places/qplacereviewreply.cpp new file mode 100644 index 00000000..38de601f --- /dev/null +++ b/src/location/places/qplacereviewreply.cpp @@ -0,0 +1,85 @@ +#include "qplacereviewreply.h" + +#include "qplace.h" + +namespace QT_PLACES_NAMESPACE { +class QPlaceReviewReplyPrivate +{ +public: + QPlaceReviewReplyPrivate() {} + QList<QPlaceReview> reviews; + int totalCount; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceReviewReply + + \brief The QPlaceReviewReply class manages a review retrieval operation started by an + instance of QPlaceManager. + + \inmodule QtLocation + + \ingroup places-main +*/ + +/*! + Constructs a review reply with a given \a parent. +*/ +QPlaceReviewReply::QPlaceReviewReply(QObject *parent) + : QPlaceReply(parent) +{ + d = new QPlaceReviewReplyPrivate; +} + +/*! + Destroys the reply. +*/ +QPlaceReviewReply::~QPlaceReviewReply() +{ + delete d; +} + +/*! + Returns the type of reply. +*/ +QPlaceReply::Type QPlaceReviewReply::type() const +{ + return QPlaceReply::ReviewReply; +} + + /*! + Returns the reviews. +*/ +QList<QPlaceReview> QPlaceReviewReply::reviews() const +{ + return d->reviews; +} + +/*! + Sets the \a reviews. +*/ +void QPlaceReviewReply::setReviews(const QList<QPlaceReview> &reviews) +{ + d->reviews = reviews; +} + +/*! + Returns the total number of reviews for a place. If the total number of + reviews cannot be counted a value of -1 is returned. +*/ +int QPlaceReviewReply::totalCount() +{ + return d->totalCount; +} + +/*! + Sets the \a total number of media objects for a place. +*/ +void QPlaceReviewReply::setTotalCount(int total) +{ + d->totalCount = total; +} diff --git a/src/location/places/qplacereviewreply.h b/src/location/places/qplacereviewreply.h new file mode 100644 index 00000000..78347ad4 --- /dev/null +++ b/src/location/places/qplacereviewreply.h @@ -0,0 +1,35 @@ +#ifndef QPLACEREVIEWREPLY_H +#define QPLACEREVIEWREPLY_H + +#include "qplacereply.h" +#include "qplacereview.h" + +#include <QStringList> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceReviewReplyPrivate; +class Q_PLACES_EXPORT QPlaceReviewReply : public QPlaceReply +{ + Q_OBJECT +public: + QPlaceReviewReply(QObject *parent = 0); + virtual ~QPlaceReviewReply(); + + QPlaceReply::Type type() const; + + QList<QPlaceReview> reviews() const; + + int totalCount(); + +protected: + void setReviews(const QList<QPlaceReview> &objects); + void setTotalCount(int total); + +private: + QPlaceReviewReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif diff --git a/src/location/places/qplacesearchquery.cpp b/src/location/places/qplacesearchquery.cpp new file mode 100644 index 00000000..39b7c169 --- /dev/null +++ b/src/location/places/qplacesearchquery.cpp @@ -0,0 +1,215 @@ +#include "qplacesearchquery.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSearchQueryPrivate : public QSharedData +{ +public: + QPlaceSearchQueryPrivate(); + QPlaceSearchQueryPrivate(const QPlaceSearchQueryPrivate &other); + + ~QPlaceSearchQueryPrivate(); + + bool operator==(const QPlaceSearchQueryPrivate &other) const; + + QString searchTerm; + QList<QPlaceCategory> categories; + QPlaceGeoCoordinate searchCenter; + QPlaceGeoBoundingBox boundingBox; + uint dymNumber; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +QPlaceSearchQueryPrivate::QPlaceSearchQueryPrivate() + : QSharedData(), + dymNumber(0) +{ +} + +QPlaceSearchQueryPrivate::QPlaceSearchQueryPrivate(const QPlaceSearchQueryPrivate &other) + : QSharedData() +{ + this->searchTerm = other.searchTerm; + this->categories = other.categories; + this->searchCenter = other.searchCenter; + this->boundingBox = other.boundingBox; + this->dymNumber = other.dymNumber; +} + +QPlaceSearchQueryPrivate::~QPlaceSearchQueryPrivate() +{ +} + +bool QPlaceSearchQueryPrivate::operator==(const QPlaceSearchQueryPrivate &other) const +{ + return ( + this->searchTerm == other.searchTerm + && this->categories == other.categories + && this->searchCenter == other.searchCenter + && this->boundingBox == other.boundingBox + && this->dymNumber == other.dymNumber + ); +} + +/*! + \class QPlaceSearchQuery + + \inmodule Location + + \brief The QPlaceSearchQuery class represents a query parameters object. + + \ingroup places-main + + The QSearchQuery class represents a query parameters object. Each + QSearchQuery cointans search query parameters like search term. +*/ + +/*! + \enum QPlaceSearchQuery::RelevanceHint + + Defines hints to help rank place results. + \value DistanceHint + Distance to the user's current location is relevant. This is only useful + if a circular bounding area is used in the query. + \value RatingHint + The rating of the place is relevant to the user. + \value AlphabetHint + Alphabetic ordering of places is relevant to the user. +*/ + +/*! + Default constructor. Constructs an new query object. +*/ +QPlaceSearchQuery::QPlaceSearchQuery() + : QPlaceQuery(), + d(new QPlaceSearchQueryPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceSearchQuery::QPlaceSearchQuery(const QPlaceSearchQuery &other) + : QPlaceQuery(other), + d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceSearchQuery::~QPlaceSearchQuery() +{ +} + +QPlaceSearchQuery &QPlaceSearchQuery::operator =(const QPlaceSearchQuery &other) { + this->QPlaceQuery::operator =(other); + d = other.d; + return *this; +} + +bool QPlaceSearchQuery::operator==(const QPlaceSearchQuery &other) const +{ + return (this->QPlaceQuery::operator ==(other) + && (*(d.constData()) == *(other.d.constData()))); +} + + +/*! + Returns the search term. +*/ +QString QPlaceSearchQuery::searchTerm() const +{ + return d->searchTerm; +} + +/*! + Sets the search \a term. +*/ +void QPlaceSearchQuery::setSearchTerm(const QString &term) +{ + d->searchTerm = term; +} + +/*! + Return the categories to be used in the search query. + Places need only to belong to one of the categories + to be considered a match by the query. +*/ +QList<QPlaceCategory> QPlaceSearchQuery::categories() +{ + return d->categories; +} + +/*! + Sets the search query to search by a single \a category +*/ +void QPlaceSearchQuery::setCategory(const QPlaceCategory &category) +{ + d->categories.clear(); + d->categories.append(category); +} + +/*! + Returns search center. +*/ +QPlaceGeoCoordinate QPlaceSearchQuery::searchCenter() const +{ + return d->searchCenter; +} + +/*! + Sets the search query to search with search \a center. +*/ +void QPlaceSearchQuery::setSearchCenter(const QPlaceGeoCoordinate ¢er) +{ + d->searchCenter = center; +} + +/*! + Returns search bounding box. +*/ +QPlaceGeoBoundingBox QPlaceSearchQuery::boundingBox() const +{ + return d->boundingBox; +} + +/*! + Sets the search query to search with bounding box. +*/ +void QPlaceSearchQuery::setBoundingBox(const QPlaceGeoBoundingBox &boundingBox) +{ + d->boundingBox = boundingBox; +} + +/*! + Returns maximum number of "did you mean" suggestions returned by search query. +*/ +uint QPlaceSearchQuery::didYouMeanSuggestionNumber() const +{ + return d->dymNumber; +} + +/*! + Sets maximum \a number of "did you mean" suggestions returned by search query. +*/ +void QPlaceSearchQuery::setDidYouMeanSuggestionNumber(const uint &number) +{ + d->dymNumber = number; +} + +/*! + Clears the parameters of the search query. +*/ +void QPlaceSearchQuery::clear() +{ + QPlaceQuery::clear(); + d->searchTerm.clear(); + d->categories.clear(); + d->boundingBox = QPlaceGeoBoundingBox(); + d->searchCenter = QPlaceGeoCoordinate(); + d->dymNumber = 0; +} diff --git a/src/location/places/qplacesearchquery.h b/src/location/places/qplacesearchquery.h new file mode 100644 index 00000000..dbab1422 --- /dev/null +++ b/src/location/places/qplacesearchquery.h @@ -0,0 +1,60 @@ +#ifndef QPLACESEARCHQUERY_H +#define QPLACESEARCHQUERY_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" +#include "qplacecategory.h" +#include "qplacequery.h" +#include "qplacegeoboundingbox.h" + +#include <QString> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSearchQueryPrivate; + +class Q_PLACES_EXPORT QPlaceSearchQuery : public QPlaceQuery +{ +public: + enum RelevanceHint { + DistanceHint, + RatingHint, + AlphabetHint + }; + + QPlaceSearchQuery(); + QPlaceSearchQuery(const QPlaceSearchQuery &other); + + virtual ~QPlaceSearchQuery(); + + QPlaceSearchQuery &operator=(const QPlaceSearchQuery &other); + + bool operator==(const QPlaceSearchQuery &other) const; + bool operator!=(const QPlaceSearchQuery &other) const { + return !(other == *this); + } + + QString searchTerm() const; + void setSearchTerm(const QString &term); + + QList<QPlaceCategory> categories(); + void setCategory(const QPlaceCategory &category); + + QPlaceGeoCoordinate searchCenter() const; + void setSearchCenter(const QPlaceGeoCoordinate ¢er); + + QPlaceGeoBoundingBox boundingBox() const; + void setBoundingBox(const QPlaceGeoBoundingBox &boundingBox); + + uint didYouMeanSuggestionNumber() const; + void setDidYouMeanSuggestionNumber(const uint &number); + + void clear(); + +private: + QSharedDataPointer<QPlaceSearchQueryPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESEARCHQUERY_H diff --git a/src/location/places/qplacesearchreply.cpp b/src/location/places/qplacesearchreply.cpp new file mode 100644 index 00000000..ae5d6e7f --- /dev/null +++ b/src/location/places/qplacesearchreply.cpp @@ -0,0 +1,64 @@ +#include "qplacesearchreply.h" + +namespace QT_PLACES_NAMESPACE { +class QPlaceSearchReplyPrivate +{ +public: + QPlaceSearchReplyPrivate(); + QList<QPlaceSearchResult> results; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceSearchReply + + \brief The QPlaceSearchReply class manages a search operation started by an + instance of QPlaceManager. + + \inmodule QtLocation + + \ingroup places-main +*/ + +/*! + Constructs a search reply with a given \a parent. +*/ +QPlaceSearchReply::QPlaceSearchReply(QObject *parent) + : QPlaceReply(parent) +{ +} + +/*! + Destroys the search reply. +*/ +QPlaceSearchReply::~QPlaceSearchReply() +{ + delete d; +} + +/*! + Returns the type of reply. +*/ +QPlaceReply::Type QPlaceSearchReply::type() const +{ + return QPlaceReply::PlaceSearchReply; +} + + /*! + Returns a list of search results; +*/ +QList<QPlaceSearchResult> QPlaceSearchReply::results() const +{ + return d->results; +} + +/*! + Sets the list of search \a results. +*/ +void QPlaceSearchReply::setResults(const QList<QPlaceSearchResult> &results) +{ + d->results = results; +} diff --git a/src/location/places/qplacesearchreply.h b/src/location/places/qplacesearchreply.h new file mode 100644 index 00000000..aba562f6 --- /dev/null +++ b/src/location/places/qplacesearchreply.h @@ -0,0 +1,29 @@ +#ifndef QPLACESEARCHREPLY_H +#define QPLACESEARCHREPLY_H + +#include "qplacereply.h" +#include "qplacesearchresult.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSearchReplyPrivate; +class Q_PLACES_EXPORT QPlaceSearchReply : public QPlaceReply +{ + Q_OBJECT +public: + QPlaceSearchReply(QObject *parent =0); + virtual ~QPlaceSearchReply(); + + QPlaceReply::Type type() const; + + QList<QPlaceSearchResult> results() const; + +protected: + void setResults(const QList<QPlaceSearchResult> &results); +private: + QPlaceSearchReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif diff --git a/src/location/places/qplacesearchresult.cpp b/src/location/places/qplacesearchresult.cpp new file mode 100644 index 00000000..f7b886f4 --- /dev/null +++ b/src/location/places/qplacesearchresult.cpp @@ -0,0 +1,213 @@ +#include "qplacesearchresult.h" +#include "qplacesearchresult_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceSearchResultPrivate::QPlaceSearchResultPrivate() : QSharedData() +{ +} + +QPlaceSearchResultPrivate::QPlaceSearchResultPrivate(const QPlaceSearchResultPrivate &other) + : QSharedData() +{ + this->additionalData = other.additionalData; + this->relevance = other.relevance; + this->distance = other.distance; + this->heading = other.heading; + this->matchType = other.matchType; + this->type = other.type; + this->place = other.place; + this->dymString = other.dymString; +} + +QPlaceSearchResultPrivate::~QPlaceSearchResultPrivate() +{ +} + +bool QPlaceSearchResultPrivate::operator==(const QPlaceSearchResultPrivate &other) const +{ + return ( + this->additionalData == other.additionalData + && this->relevance == other.relevance + && this->distance == other.distance + && this->heading == other.heading + && this->matchType == other.matchType + && this->type == other.type + && this->place == other.place + && this->dymString == other.dymString + ); +} + +/*! + \class QPlaceSearchResult + + \inmodule QPlaces + + \brief The QPlaceSearchResult class represents a search result object. + + \ingroup places-main + + Each QPlaceSearchResult represents a place with a number of attributes + such as distance, relevance, etc. +*/ + +/*! + Default constructor. Constructs an new search result. +*/ +QPlaceSearchResult::QPlaceSearchResult() + : d(new QPlaceSearchResultPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceSearchResult::QPlaceSearchResult(const QPlaceSearchResult &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceSearchResult::~QPlaceSearchResult() +{ +} + +QPlaceSearchResult &QPlaceSearchResult::operator =(const QPlaceSearchResult &other) { + d = other.d; + return *this; +} + +bool QPlaceSearchResult::operator==(const QPlaceSearchResult &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns relevance. +*/ +qreal QPlaceSearchResult::relevance() const +{ + return d->relevance; +} + +/*! + Sets the \a relevance. +*/ +void QPlaceSearchResult::setRelevance(const qreal &relevance) +{ + d->relevance = relevance; +} + +/*! + Returns the distance. +*/ +qreal QPlaceSearchResult::distance() const +{ + return d->distance; +} + +/*! + Sets the \a distance. +*/ +void QPlaceSearchResult::setDistance(const qreal &distance) +{ + d->distance = distance; +} + +/*! + Returns heading. +*/ +qreal QPlaceSearchResult::heading() const +{ + return d->heading; +} + +/*! + Sets the \a heading. +*/ +void QPlaceSearchResult::setHeading(const qreal &heading) +{ + d->heading = heading; +} + +/*! + Returns location match type. +*/ +QPlaceSearchResult::LocationMatchType QPlaceSearchResult::matchType() const +{ + return d->matchType; +} + +/*! + Sets the location \a matchType. +*/ +void QPlaceSearchResult::setLocationMatchType(const QPlaceSearchResult::LocationMatchType &matchType) +{ + d->matchType = matchType; +} + +/*! + Returns additional data. +*/ +QVariantHash QPlaceSearchResult::additionalData() const +{ + return d->additionalData; +} + +/*! + Sets additional \a data. +*/ +void QPlaceSearchResult::setAdditionalData(const QVariantHash &data) +{ + d->additionalData = data; +} + +/*! + Returns the place. +*/ +QPlaceSearchResult::SearchResultType QPlaceSearchResult::type() const +{ + return d->type; +} + +/*! + Sets the \a place. +*/ +void QPlaceSearchResult::setType(const QPlaceSearchResult::SearchResultType &type) +{ + d->type = type; +} + +/*! + Returns the place. +*/ +QPlace QPlaceSearchResult::place() const +{ + return d->place; +} + +/*! + Sets the \a place. +*/ +void QPlaceSearchResult::setPlace(const QPlace &place) +{ + d->place = place; +} + +/*! + Returns the "did you mean" string. +*/ +QString QPlaceSearchResult::didYouMeanSuggestion() const +{ + return d->dymString; +} + +/*! + Sets the "did you mean" \a string. +*/ +void QPlaceSearchResult::setDidYouMeanSuggestion(const QString &dymString) +{ + d->dymString = dymString; +} diff --git a/src/location/places/qplacesearchresult.h b/src/location/places/qplacesearchresult.h new file mode 100644 index 00000000..fbb6e778 --- /dev/null +++ b/src/location/places/qplacesearchresult.h @@ -0,0 +1,72 @@ +#ifndef QPLACESEARCHRESULT_H +#define QPLACESEARCHRESULT_H + +#include "qplaceglobal.h" + +#include <QSharedDataPointer> +#include <QVariant> +#include <QString> +#include "qplace.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSearchResultPrivate; + +class Q_PLACES_EXPORT QPlaceSearchResult +{ +public: + QPlaceSearchResult(); + QPlaceSearchResult(const QPlaceSearchResult &other); + + virtual ~QPlaceSearchResult(); + + QPlaceSearchResult &operator=(const QPlaceSearchResult &other); + + bool operator==(const QPlaceSearchResult &other) const; + bool operator!=(const QPlaceSearchResult &other) const { + return !(other == *this); + } + + enum LocationMatchType { + PointAddress, + Interpolated, + Undefined + }; + + enum SearchResultType { + Place, + DidYouMeanSuggestion, + Unassigned + }; + + qreal relevance() const; + void setRelevance(const qreal &relevance); + + qreal distance() const; + void setDistance(const qreal &distance); + + qreal heading() const; + void setHeading(const qreal &heading); + + LocationMatchType matchType() const; + void setLocationMatchType(const LocationMatchType &matchType); + + QVariantHash additionalData() const; + void setAdditionalData(const QVariantHash &data); + + SearchResultType type() const; + void setType(const SearchResultType &type); + + QPlace place() const; + void setPlace(const QPlace &place); + + QString didYouMeanSuggestion() const; + void setDidYouMeanSuggestion(const QString &didYouMeanSuggestion); + +private: + QSharedDataPointer<QPlaceSearchResultPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESEARCHRESULT_H diff --git a/src/location/places/qplacesearchresult_p.h b/src/location/places/qplacesearchresult_p.h new file mode 100644 index 00000000..b6fbdcf2 --- /dev/null +++ b/src/location/places/qplacesearchresult_p.h @@ -0,0 +1,32 @@ +#ifndef QPLACESEARCHRESULT_P_H +#define QPLACESEARCHRESULT_P_H + +#include "qplacesearchresult.h" + +#include <QSharedData> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSearchResultPrivate : public QSharedData +{ +public: + QPlaceSearchResultPrivate(); + QPlaceSearchResultPrivate(const QPlaceSearchResultPrivate &other); + + ~QPlaceSearchResultPrivate(); + + bool operator==(const QPlaceSearchResultPrivate &other) const; + + qreal relevance; + qreal distance; + qreal heading; + QPlaceSearchResult::LocationMatchType matchType; + QVariantHash additionalData; + QPlaceSearchResult::SearchResultType type; + QPlace place; + QString dymString; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESEARCHRESULT_P_H diff --git a/src/location/places/qplacesupplier.cpp b/src/location/places/qplacesupplier.cpp new file mode 100644 index 00000000..90a25eca --- /dev/null +++ b/src/location/places/qplacesupplier.cpp @@ -0,0 +1,140 @@ +#include "qplacesupplier.h" +#include "qplacesupplier_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceSupplierPrivate::QPlaceSupplierPrivate() : QSharedData() +{ +} + +QPlaceSupplierPrivate::QPlaceSupplierPrivate(const QPlaceSupplierPrivate &other) + : QSharedData() +{ + this->name = other.name; + this->supplierId = other.supplierId; + this->url = other.url; + this->supplierIconURL = other.supplierIconURL; +} + +QPlaceSupplierPrivate::~QPlaceSupplierPrivate() +{ +} + +bool QPlaceSupplierPrivate::operator==(const QPlaceSupplierPrivate &other) const +{ + return ( + this->name == other.name + && this->supplierId == other.supplierId + && this->url == other.url + && this->supplierIconURL == other.supplierIconURL + ); +} + +/*! + \class QPlaceSupplier + + \inmodule QPlaces + + \brief The QPlaceSupplier class represents a supplier object. + + Each QPlaceSupplier represents a supplier object with a number of attributes + such as name, icon etc. Each QPlaceSupplier is associated with place, media, review or description. + +*/ + +/*! + Default constructor. Constructs an new supplier object. +*/ +QPlaceSupplier::QPlaceSupplier() + : d(new QPlaceSupplierPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceSupplier::QPlaceSupplier(const QPlaceSupplier &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceSupplier::~QPlaceSupplier() +{ +} + +QPlaceSupplier &QPlaceSupplier::operator =(const QPlaceSupplier &other) { + d = other.d; + return *this; +} + +bool QPlaceSupplier::operator==(const QPlaceSupplier &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns name. +*/ +QString QPlaceSupplier::name() const +{ + return d->name; +} + +/*! + Sets name. +*/ +void QPlaceSupplier::setName(const QString &data) +{ + d->name = data; +} + +/*! + Returns supplier id. +*/ +QString QPlaceSupplier::supplierId() const +{ + return d->supplierId; +} + +/*! + Sets supplier id. +*/ +void QPlaceSupplier::setSupplierId(const QString &data) +{ + d->supplierId = data; +} + +/*! + Returns URL. +*/ +QString QPlaceSupplier::URL() const +{ + return d->url; +} + +/*! + Sets URL of the icon. +*/ +void QPlaceSupplier::setURL(const QString &data) +{ + d->url = data; +} + +/*! + Returns URL of the icon. +*/ +QString QPlaceSupplier::supplierIconURL() const +{ + return d->supplierIconURL; +} + +/*! + Sets URL of the icon. +*/ +void QPlaceSupplier::setSupplierIconURL(const QString &data) +{ + d->supplierIconURL = data; +} diff --git a/src/location/places/qplacesupplier.h b/src/location/places/qplacesupplier.h new file mode 100644 index 00000000..d5a57bea --- /dev/null +++ b/src/location/places/qplacesupplier.h @@ -0,0 +1,41 @@ +#ifndef QPLACESUPPLIER_H +#define QPLACESUPPLIER_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSupplierPrivate; + +class Q_PLACES_EXPORT QPlaceSupplier +{ +public: + QPlaceSupplier(); + QPlaceSupplier(const QPlaceSupplier &other); + + virtual ~QPlaceSupplier(); + + QPlaceSupplier &operator=(const QPlaceSupplier &other); + + bool operator==(const QPlaceSupplier &other) const; + bool operator!=(const QPlaceSupplier &other) const { + return !(other == *this); + } + + QString name() const; + void setName(const QString &data); + QString supplierId() const; + void setSupplierId(const QString &data); + QString URL() const; + void setURL(const QString &data); + QString supplierIconURL() const; + void setSupplierIconURL(const QString &data); + +private: + QSharedDataPointer<QPlaceSupplierPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESUPPLIER_H diff --git a/src/location/places/qplacesupplier_p.h b/src/location/places/qplacesupplier_p.h new file mode 100644 index 00000000..dbbd2efb --- /dev/null +++ b/src/location/places/qplacesupplier_p.h @@ -0,0 +1,29 @@ +#ifndef QPLACESUPPLIER_P_H +#define QPLACESUPPLIER_P_H + +#include <QString> +#include <QSharedData> + +#include "qplacesupplier.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceSupplierPrivate : public QSharedData +{ +public: + QPlaceSupplierPrivate(); + QPlaceSupplierPrivate(const QPlaceSupplierPrivate &other); + + ~QPlaceSupplierPrivate(); + + bool operator==(const QPlaceSupplierPrivate &other) const; + + QString name; + QString supplierId; + QString url; + QString supplierIconURL; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACESUPPLIER_P_H diff --git a/src/location/places/qplacetextpredictionreply.cpp b/src/location/places/qplacetextpredictionreply.cpp new file mode 100644 index 00000000..cbef1fae --- /dev/null +++ b/src/location/places/qplacetextpredictionreply.cpp @@ -0,0 +1,66 @@ +#include "qplacetextpredictionreply.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceTextPredictionReplyPrivate +{ +public: + QPlaceTextPredictionReplyPrivate(){}; + QStringList textPredictions; +}; + +} // QT_PLACES_NAMESPACE + +using namespace QT_PLACES_NAMESPACE; + +/*! + \class QPlaceTextPredictionReply + + \brief The QPlaceTextPredictionReply class manages a text prediction operation started by an + instance of QPlaceManager. + + \inmodule QtLocation + + \ingroup places-main +*/ + +/*! + Constructs a text prediction reply with a given \a parent. +*/ +QPlaceTextPredictionReply::QPlaceTextPredictionReply(QObject *parent) + : QPlaceReply(parent), + d(new QPlaceTextPredictionReplyPrivate) +{ +} + +/*! + Destroys the reply. +*/ +QPlaceTextPredictionReply::~QPlaceTextPredictionReply() +{ + delete d; +} + +/*! + Returns the text predictions. +*/ +QStringList QPlaceTextPredictionReply::textPredictions() const +{ + return d->textPredictions; +} + +/*! + Returns type of reply. +*/ +QPlaceReply::Type QPlaceTextPredictionReply::type() const +{ + return QPlaceReply::TextPredictionReply; +} + +/*! + Sets the text \a predictions. +*/ +void QPlaceTextPredictionReply::setTextPredictions(const QStringList &predictions) +{ + d->textPredictions = predictions; +} diff --git a/src/location/places/qplacetextpredictionreply.h b/src/location/places/qplacetextpredictionreply.h new file mode 100644 index 00000000..9094b23e --- /dev/null +++ b/src/location/places/qplacetextpredictionreply.h @@ -0,0 +1,31 @@ +#ifndef QPLACETEXTPREDICTIONREPLY_H +#define QPLACETEXTPREDICTIONREPLY_H + +#include "qplacereply.h" + +#include <QStringList> + +namespace QT_PLACES_NAMESPACE { + +class QPlaceTextPredictionReplyPrivate; + +class Q_PLACES_EXPORT QPlaceTextPredictionReply : public QPlaceReply +{ + Q_OBJECT +public: + QPlaceTextPredictionReply(QObject *parent =0); + virtual ~QPlaceTextPredictionReply(); + + QStringList textPredictions() const; + Type type() const; + +protected: + void setTextPredictions(const QStringList &predictions); + +private: + QPlaceTextPredictionReplyPrivate *d; +}; + +} // QT_PLACES_NAMESPACE + +#endif diff --git a/src/location/places/qplaceweekdayhours.cpp b/src/location/places/qplaceweekdayhours.cpp new file mode 100644 index 00000000..c8efb4d6 --- /dev/null +++ b/src/location/places/qplaceweekdayhours.cpp @@ -0,0 +1,101 @@ +#include "qplaceweekdayhours.h" +#include "qplaceweekdayhours_p.h" + +using namespace QT_PLACES_NAMESPACE; + +QPlaceWeekdayHoursPrivate::QPlaceWeekdayHoursPrivate() : QSharedData() +{ +} + +QPlaceWeekdayHoursPrivate::QPlaceWeekdayHoursPrivate(const QPlaceWeekdayHoursPrivate &other) + : QSharedData() +{ + this->period = other.period; + this->weekday = other.weekday; +} + +QPlaceWeekdayHoursPrivate::~QPlaceWeekdayHoursPrivate() +{ +} + +bool QPlaceWeekdayHoursPrivate::operator==(const QPlaceWeekdayHoursPrivate &other) const +{ + return ( + this->period == other.period + && this->weekday == other.weekday + ); +} + +/*! + \class QPlaces::QWeekdayHours + + \inmodule QPlaces + + \brief The QWeekdayHours class represents a day of week object. + It might contains hours information and day of the week that place is open. +*/ + +/*! + Constructs an new weekday object. +*/ +QPlaceWeekdayHours::QPlaceWeekdayHours() + : d(new QPlaceWeekdayHoursPrivate) +{ +} + +/*! + Constructs a copy of \a other +*/ +QPlaceWeekdayHours::QPlaceWeekdayHours(const QPlaceWeekdayHours &other) + :d(other.d) +{ +} + +/*! + Destructor. +*/ +QPlaceWeekdayHours::~QPlaceWeekdayHours() +{ +} + +QPlaceWeekdayHours &QPlaceWeekdayHours::operator =(const QPlaceWeekdayHours &other) { + d = other.d; + return *this; +} + +bool QPlaceWeekdayHours::operator==(const QPlaceWeekdayHours &other) const +{ + return (*(d.constData()) == *(other.d.constData())); +} + +/*! + Returns period. Do not delete it. +*/ +QPlacePeriod QPlaceWeekdayHours::period() const +{ + return d->period; +} +/*! + Sets period. +*/ +void QPlaceWeekdayHours::setPeriod(const QPlacePeriod &period) +{ + d->period = period; +} + +/*! + Returns day of the week. +*/ +Qt::DayOfWeek QPlaceWeekdayHours::weekday() const +{ + return d->weekday; +} + +/*! + Sets weekday. +*/ +void QPlaceWeekdayHours::setWeekday(const Qt::DayOfWeek &weekday) +{ + d->weekday = weekday; +} + diff --git a/src/location/places/qplaceweekdayhours.h b/src/location/places/qplaceweekdayhours.h new file mode 100644 index 00000000..92f1f22e --- /dev/null +++ b/src/location/places/qplaceweekdayhours.h @@ -0,0 +1,38 @@ +#ifndef QPLACEWEEKDAYHOURS_H +#define QPLACEWEEKDAYHOURS_H + +#include <QSharedDataPointer> +#include "qplaceglobal.h" +#include "qplaceperiod.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceWeekdayHoursPrivate; + +class Q_PLACES_EXPORT QPlaceWeekdayHours +{ +public: + QPlaceWeekdayHours(); + QPlaceWeekdayHours(const QPlaceWeekdayHours &other); + + virtual ~QPlaceWeekdayHours(); + + QPlaceWeekdayHours &operator=(const QPlaceWeekdayHours &other); + + bool operator==(const QPlaceWeekdayHours &other) const; + bool operator!=(const QPlaceWeekdayHours &other) const { + return !(other == *this); + } + + QPlacePeriod period() const; + void setPeriod(const QPlacePeriod &period); + Qt::DayOfWeek weekday() const; + void setWeekday(const Qt::DayOfWeek &weekday); + +private: + QSharedDataPointer<QPlaceWeekdayHoursPrivate> d; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEWEEKDAYHOURS_H diff --git a/src/location/places/qplaceweekdayhours_p.h b/src/location/places/qplaceweekdayhours_p.h new file mode 100644 index 00000000..9f9c74fb --- /dev/null +++ b/src/location/places/qplaceweekdayhours_p.h @@ -0,0 +1,26 @@ +#ifndef QPLACEWEEKDAYHOURS_P_H +#define QPLACEWEEKDAYHOURS_P_H + +#include <QSharedData> + +#include "qplaceweekdayhours.h" + +namespace QT_PLACES_NAMESPACE { + +class QPlaceWeekdayHoursPrivate : public QSharedData +{ +public: + QPlaceWeekdayHoursPrivate(); + QPlaceWeekdayHoursPrivate(const QPlaceWeekdayHoursPrivate &other); + + ~QPlaceWeekdayHoursPrivate(); + + bool operator==(const QPlaceWeekdayHoursPrivate &other) const; + + QPlacePeriod period; + Qt::DayOfWeek weekday; +}; + +} // QT_PLACES_NAMESPACE + +#endif // QPLACEWEEKDAYHOURS_P_H |