summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabcd <qt-info@nokia.com>2011-08-25 14:27:04 +1000
committerabcd <qt_abcd1@ovi.com>2011-08-29 09:44:29 +0200
commitccabac44e735b787ee3d3f867d1e1ee0adff3f63 (patch)
tree2889f0d37b2fa68e5659d43cca03fe0bbf7aab0d
parent8df5d444bdcd62e5a6a236dfccd7c8507ee4d11f (diff)
downloadqtlocation-ccabac44e735b787ee3d3f867d1e1ee0adff3f63.tar.gz
Add initial jsondb plugin
Currently the plugin does not use proper location schema to store place objects. Also the plugin does some filtering in code rather than with jsondb queries because it seems the comparison operators are not working correctly. These issues are to be addressed in future commits. Currently only basic place information is stored consisting of name, address and coordinate. Change-Id: Icc59f4fe50f5ecdd61d4d9565789d813a41a749f Reviewed-on: http://codereview.qt.nokia.com/3555 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com> Reviewed-by: abcd <qt_abcd1@ovi.com>
-rw-r--r--config.tests/jsondb/jsondb.pro6
-rw-r--r--config.tests/jsondb/main.cpp48
-rw-r--r--src/location/places/qplacedetailsreply.cpp8
-rw-r--r--src/location/places/qplacemanager.cpp8
-rw-r--r--src/location/places/qplacemanager.h4
-rw-r--r--src/location/places/qplacereply.h1
-rw-r--r--src/location/places/qplacesavereply.cpp18
-rw-r--r--src/location/places/qplacesavereply.h4
-rw-r--r--src/location/places/qplacesearchrequest.cpp2
-rw-r--r--src/location/qgeoplace.cpp1
-rw-r--r--src/plugins/geoservices/geoservices.pro4
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/detailsreply.cpp57
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/detailsreply.h65
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp192
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h109
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/macro.h56
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/nokia_places_jsondb.pro50
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.cpp95
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.h76
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp372
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h104
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/reply.cpp52
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/reply.h63
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/savereply.cpp56
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/savereply.h64
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp61
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/searchreply.h67
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/unsupportedreplies.h84
-rw-r--r--sync.profile5
-rw-r--r--tests/auto/auto.pro4
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbcleaner.cpp69
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbcleaner.h74
-rw-r--r--tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro18
-rw-r--r--tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp800
34 files changed, 2679 insertions, 18 deletions
diff --git a/config.tests/jsondb/jsondb.pro b/config.tests/jsondb/jsondb.pro
new file mode 100644
index 00000000..a54ef9e5
--- /dev/null
+++ b/config.tests/jsondb/jsondb.pro
@@ -0,0 +1,6 @@
+TEMPLATE = app
+
+DEFINES += QT_ADDON_JSONDB_LIB
+QT += jsondb
+
+SOURCES += main.cpp
diff --git a/config.tests/jsondb/main.cpp b/config.tests/jsondb/main.cpp
new file mode 100644
index 00000000..1f28f2d0
--- /dev/null
+++ b/config.tests/jsondb/main.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the FOO module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <jsondb-error.h>
+
+int main()
+{
+ return 0;
+}
diff --git a/src/location/places/qplacedetailsreply.cpp b/src/location/places/qplacedetailsreply.cpp
index f83ae53b..042abadc 100644
--- a/src/location/places/qplacedetailsreply.cpp
+++ b/src/location/places/qplacedetailsreply.cpp
@@ -90,7 +90,7 @@ QPlaceReply::Type QPlaceDetailsReply::type() const
}
/*!
- Returns a place result;
+ Returns a place result
*/
QGeoPlace QPlaceDetailsReply::result() const
{
@@ -99,10 +99,10 @@ QGeoPlace QPlaceDetailsReply::result() const
}
/*!
- Sets place \a result.
+ Sets the \a place
*/
-void QPlaceDetailsReply::setResult(const QGeoPlace &result)
+void QPlaceDetailsReply::setResult(const QGeoPlace &place)
{
Q_D(QPlaceDetailsReply);
- d->result = result;
+ d->result = place;
}
diff --git a/src/location/places/qplacemanager.cpp b/src/location/places/qplacemanager.cpp
index 8303d4f1..e258265b 100644
--- a/src/location/places/qplacemanager.cpp
+++ b/src/location/places/qplacemanager.cpp
@@ -208,6 +208,14 @@ QPlaceSaveReply *QPlaceManager::savePlace(const QGeoPlace &place, VisibilityScop
return d->engine->savePlace(place, scope);
}
+/*!
+ Removes a \a place from the manager
+*/
+QPlaceReply *QPlaceManager::removePlace(const QGeoPlace &place)
+{
+ return d->engine->removePlace(place);
+}
+
/*
Returns the available scopes in which places can be saved.
*/
diff --git a/src/location/places/qplacemanager.h b/src/location/places/qplacemanager.h
index d4a57f55..388f6cda 100644
--- a/src/location/places/qplacemanager.h
+++ b/src/location/places/qplacemanager.h
@@ -114,9 +114,9 @@ public:
QPlaceSearchReply *searchForPlaces(const QPlaceSearchRequest &query) const;
- QPlaceSearchReply *recommendations(const QGeoPlace &place, const QPlaceSearchRequest &query) const;
+ QPlaceSearchReply *recommendations(const QGeoPlace &place, const QPlaceSearchRequest &request) const;
- QPlaceTextPredictionReply *textPredictions(const QPlaceSearchRequest &query) const;
+ QPlaceTextPredictionReply *textPredictions(const QPlaceSearchRequest &request) const;
ConnectivityModes connectivityMode() const;
void setConnectivityMode(ConnectivityModes connectivityMode);
diff --git a/src/location/places/qplacereply.h b/src/location/places/qplacereply.h
index 1796efe6..6cdc9b64 100644
--- a/src/location/places/qplacereply.h
+++ b/src/location/places/qplacereply.h
@@ -61,6 +61,7 @@ public:
ParseError,
PermissionsError,
UnsupportedError,
+ BadArgumentError,
CancelError,
UnknownError
};
diff --git a/src/location/places/qplacesavereply.cpp b/src/location/places/qplacesavereply.cpp
index d9d5f24b..294a0306 100644
--- a/src/location/places/qplacesavereply.cpp
+++ b/src/location/places/qplacesavereply.cpp
@@ -48,7 +48,7 @@ class QPlaceSaveReplyPrivate : public QPlaceReplyPrivate
public:
QPlaceSaveReplyPrivate() {}
~QPlaceSaveReplyPrivate() {}
- QGeoPlace place;
+ QString placeId;
};
QT_END_NAMESPACE
@@ -90,21 +90,21 @@ QPlaceReply::Type QPlaceSaveReply::type() const
}
/*!
- Returns the saved place. One should ensure that the reply
- is finished before calling this function, otherwise
- a default place is returned.
+ Returns the id of the saved place. One should ensure that the reply
+ is finished before calling this function, otherwise an
+ empty string is returned.
*/
-QGeoPlace QPlaceSaveReply::place() const
+QString QPlaceSaveReply::placeId() const
{
Q_D(const QPlaceSaveReply);
- return d->place;
+ return d->placeId;
}
/*!
- Sets the saved \a place.
+ Sets the saved \a placeId
*/
-void QPlaceSaveReply::setPlace(const QGeoPlace &place)
+void QPlaceSaveReply::setPlaceId(const QString &placeId)
{
Q_D(QPlaceSaveReply);
- d->place = place;
+ d->placeId = placeId;
}
diff --git a/src/location/places/qplacesavereply.h b/src/location/places/qplacesavereply.h
index bc794963..746ec2c6 100644
--- a/src/location/places/qplacesavereply.h
+++ b/src/location/places/qplacesavereply.h
@@ -57,10 +57,10 @@ public:
QPlaceReply::Type type() const;
- QGeoPlace place() const;
+ QString placeId() const;
protected:
- void setPlace(const QGeoPlace &place);
+ void setPlaceId(const QString &placeId);
private:
Q_DISABLE_COPY(QPlaceSaveReply)
Q_DECLARE_PRIVATE(QPlaceSaveReply)
diff --git a/src/location/places/qplacesearchrequest.cpp b/src/location/places/qplacesearchrequest.cpp
index c12b6c6c..c202a838 100644
--- a/src/location/places/qplacesearchrequest.cpp
+++ b/src/location/places/qplacesearchrequest.cpp
@@ -79,6 +79,8 @@ QPlaceSearchRequestPrivate::QPlaceSearchRequestPrivate(const QPlaceSearchRequest
this->categories = other.categories;
if (other.searchArea)
this->searchArea = other.searchArea->clone();
+ else
+ this->searchArea = 0;
this->dymNumber = other.dymNumber;
this->scope = other.scope;
}
diff --git a/src/location/qgeoplace.cpp b/src/location/qgeoplace.cpp
index c984912a..39ca5ec8 100644
--- a/src/location/qgeoplace.cpp
+++ b/src/location/qgeoplace.cpp
@@ -548,7 +548,6 @@ QGeoPlacePrivate& QGeoPlacePrivate::operator= (const QGeoPlacePrivate & other)
bool QGeoPlacePrivate::operator== (const QGeoPlacePrivate &other) const
{
-
#ifdef QGEOPLACE_DEBUG
qDebug() << "additionalData: " << (additionalData == other.additionalData);
qDebug() << "categories: " << (categories == other.categories);
diff --git a/src/plugins/geoservices/geoservices.pro b/src/plugins/geoservices/geoservices.pro
index 85243cc6..a27213d1 100644
--- a/src/plugins/geoservices/geoservices.pro
+++ b/src/plugins/geoservices/geoservices.pro
@@ -1,3 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = nokia
+
+contains(config_test_jsondb, yes) {
+ SUBDIRS += nokia_places_jsondb
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/detailsreply.cpp b/src/plugins/geoservices/nokia_places_jsondb/detailsreply.cpp
new file mode 100644
index 00000000..91d3cdfd
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/detailsreply.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "detailsreply.h"
+#include "qplacemanagerengine_jsondb.h"
+
+DetailsReply::DetailsReply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceDetailsReply(engine), m_engine(engine)
+{
+}
+
+DetailsReply::~DetailsReply()
+{
+}
+
+void DetailsReply::setResult(const QGeoPlace &place)
+{
+ QPlaceDetailsReply::setResult(place);
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/detailsreply.h b/src/plugins/geoservices/nokia_places_jsondb/detailsreply.h
new file mode 100644
index 00000000..dc2f3f53
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/detailsreply.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef DETAILSREPLY_H
+#define DETAILSREPLY_H
+
+#include <qplacedetailsreply.h>
+#include <qplacemanagerengine_jsondb.h>
+
+#include "macro.h"
+
+QT_USE_NAMESPACE
+
+class DetailsReply : public QPlaceDetailsReply
+{
+ Q_OBJECT
+public:
+ DetailsReply(QPlaceManagerEngineJsonDb *engine);
+ virtual ~DetailsReply();
+ void setResult(const QGeoPlace &place);
+
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp
new file mode 100644
index 00000000..7a43c60f
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "jsondbhandler.h"
+#include "qgeoboundingcircle.h"
+#include "qplacemanagerengine_jsondb.h"
+#include "reply.h"
+#include "savereply.h"
+#include "searchreply.h"
+#include "detailsreply.h"
+
+#include <qplacesearchrequest.h>
+#include <jsondb-client.h>
+
+#include <QDebug>
+#include <QString>
+
+
+JsonDbHandler::JsonDbHandler(QPlaceManagerEngineJsonDb *engine)
+ : QObject(engine), m_engine(engine)
+{
+ m_db = new JsonDbClient(m_engine);
+ if (!m_db->connected()) {
+ qWarning() << "JsonDb not connected";
+ } else {
+ connect(m_db, SIGNAL(response(int, const QVariant&)),
+ this, SIGNAL(jsonDbResponse(int, const QVariant&)), Qt::QueuedConnection);
+ connect(m_db, SIGNAL(error(int, int, const QString&)),
+ this, SIGNAL(jsonDbError(int, int, const QString&)), Qt::QueuedConnection);
+ }
+}
+
+int JsonDbHandler::write(const QVariant &jsonObj)
+{
+ return m_db->create(jsonObj);
+}
+
+int JsonDbHandler::update(const QVariant &jsonObj)
+{
+ return m_db->update(jsonObj);
+}
+
+int JsonDbHandler::query(const QVariant &jsonObj)
+{
+ return m_db->find(jsonObj);
+}
+
+int JsonDbHandler::queryPlaceDetails(const QString &placeId)
+{
+ return m_db->query(QString("[?_uuid = \"%1\"]").arg(placeId));
+}
+
+int JsonDbHandler::remove(const QString &uuid)
+{
+ QVariantMap jsonMap;
+ jsonMap.insert(UUID, uuid);
+ return m_db->remove(jsonMap);
+}
+
+QVariant JsonDbHandler::convertToJsonVariant(const QGeoPlace &place)
+{
+ QVariantMap map;
+ map.insert("_type", PLACE_TYPE);
+ if (!place.placeId().isEmpty())
+ map.insert("_uuid", place.placeId());
+ map.insert(PLACE_NAME, place.name());
+
+ QVariantMap coordMap;
+ coordMap.insert(LATITUDE, place.location().coordinate().latitude());
+ coordMap.insert(LONGITUDE, place.location().coordinate().longitude());
+ coordMap.insert(ALTITUDE, place.location().coordinate().altitude());
+
+ QVariantMap addressMap;
+ addressMap.insert(STREET, place.location().address().street());
+ addressMap.insert(DISTRICT, place.location().address().district());
+ addressMap.insert(CITY, place.location().address().city());
+ addressMap.insert(COUNTY, place.location().address().county());
+ addressMap.insert(STATE, place.location().address().state());
+ addressMap.insert(COUNTRY, place.location().address().country());
+
+ map.insert(COORDINATE, coordMap);
+ map.insert(ADDRESS, addressMap);
+
+ return map;
+}
+
+QVariant JsonDbHandler::convertToJsonVariant(const QPlaceSearchRequest &request)
+{
+ QVariantMap queryMap;
+ QString queryString;
+ if (!request.searchTerm().isEmpty())
+ queryString += QString("[?name =~ \"/%1.*/i\"]").arg(request.searchTerm());
+
+ if (queryString.isEmpty()) {
+ queryString = QLatin1String("[?_type = \"place\"]");
+ }
+ queryMap.insert(QLatin1String("query"), queryString);
+ return queryMap;
+}
+
+/* Expected response format
+ {
+ "data": <array of json objects>
+ "explantion":
+ "length": <integer>
+ "offset": <integer>
+ }
+*/
+QList<QGeoPlace> JsonDbHandler::convertJsonResponseToPlaces(const QVariant &response)
+{
+ QList<QVariant> data = response.toMap().value("data").toList();
+ QList<QGeoPlace> places;
+ foreach (const QVariant&var, data)
+ places.append(JsonDbHandler::convertJsonVariantToPlace(var));
+
+ return places;
+}
+
+QGeoPlace JsonDbHandler::convertJsonVariantToPlace(const QVariant &variant)
+{
+ QVariantMap placeJson = variant.toMap();
+
+ QGeoPlace place;
+ place.setName(placeJson.value(PLACE_NAME).toString());
+ place.setPlaceId(placeJson.value(UUID).toString());
+
+ QVariantMap coordMap = placeJson.value(COORDINATE).toMap();
+ QGeoLocation location;
+ QGeoCoordinate coord;
+ coord.setLatitude(coordMap.value(LATITUDE).toDouble());
+ coord.setLongitude(coordMap.value(LONGITUDE).toDouble());
+ coord.setAltitude(coordMap.value(ALTITUDE).toDouble());
+ location.setCoordinate(coord);
+
+ QVariantMap addressMap = placeJson.value(ADDRESS).toMap();
+ QGeoAddress address;
+ address.setStreet(addressMap.value(STREET).toString());
+ address.setDistrict(addressMap.value(DISTRICT).toString());
+ address.setCity(addressMap.value(CITY).toString());
+ address.setCounty(addressMap.value(COUNTY).toString());
+ address.setState(addressMap.value(STATE).toString());
+ address.setCountry(addressMap.value(COUNTRY).toString());
+ location.setAddress(address);
+
+ place.setLocation(location);
+
+ return place;
+}
+
+bool JsonDbHandler::isConnected()
+{
+ return m_db->connected();
+}
+
diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h
new file mode 100644
index 00000000..e9cf8631
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef JSONHANDLER_H
+#define JSONHANDLER_H
+
+#include <QObject>
+#include <QVariant>
+
+#include <jsondb-global.h>
+
+#define UUID "_uuid"
+#define TYPE "_type"
+
+#define PLACE_TYPE "place"
+#define PLACE_NAME "name"
+#define COORDINATE "coordinate"
+
+//coord
+#define COORDINATE "coordinate"
+#define LATITUDE QLatin1String("latitude")
+#define LONGITUDE QLatin1String("longitude")
+#define ALTITUDE QLatin1String("altitude")
+
+//address
+#define ADDRESS "address"
+#define STREET "street"
+#define POSTCODE "postcode"
+#define DISTRICT "district"
+#define CITY "locality"
+#define STATE "state"
+#define COUNTY "county"
+#define COUNTRY "country"
+
+Q_ADDON_JSONDB_BEGIN_NAMESPACE
+class JsonDbClient;
+Q_ADDON_JSONDB_END_NAMESPACE
+Q_USE_JSONDB_NAMESPACE
+
+class QPlaceManagerEngineJsonDb;
+class QGeoPlace;
+class QPlaceSearchRequest;
+
+class JsonDbHandler : public QObject
+{
+ Q_OBJECT
+public:
+ JsonDbHandler(QPlaceManagerEngineJsonDb *manager);
+
+ int write(const QVariant &jsonObj);
+ int update(const QVariant &jsonObj);
+ int query(const QVariant &jsonObj);
+ int queryPlaceDetails(const QString &placeId);
+ int remove(const QString &uuid);
+
+ static QVariant convertToJsonVariant(const QGeoPlace &place);
+ static QVariant convertToJsonVariant(const QPlaceSearchRequest &query);
+ static QList<QGeoPlace> convertJsonResponseToPlaces(const QVariant &response);
+ static QGeoPlace convertJsonVariantToPlace(const QVariant &variant);
+
+ bool isConnected();
+signals:
+ void jsonDbResponse( int id, const QVariant& data);
+ void jsonDbError( int id, int code, const QString& data);
+
+private:
+ JsonDbClient *m_db;
+ QPlaceManagerEngineJsonDb *m_engine;
+};
+
+#endif
+
diff --git a/src/plugins/geoservices/nokia_places_jsondb/macro.h b/src/plugins/geoservices/nokia_places_jsondb/macro.h
new file mode 100644
index 00000000..ca4d92cf
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/macro.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#define DECLARE_TRIGGER_DONE_FN inline void triggerDone(QPlaceReply::Error error = QPlaceReply::NoError, \
+ const QString &errorString = QString()) { \
+ this->setError(error,errorString); \
+ QMetaObject::invokeMethod(m_engine, "error", Qt::QueuedConnection, \
+ Q_ARG(QPlaceReply *,this), \
+ Q_ARG(QPlaceReply::Error, error),\
+ Q_ARG(QString, errorString)); \
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, \
+ Q_ARG(QPlaceReply::Error, error), \
+ Q_ARG(QString, errorString)); \
+ this->setFinished(true); \
+ QMetaObject::invokeMethod(m_engine, "finished", Qt::QueuedConnection, \
+ Q_ARG(QPlaceReply *,this)); \
+ QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); \
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/nokia_places_jsondb.pro b/src/plugins/geoservices/nokia_places_jsondb/nokia_places_jsondb.pro
new file mode 100644
index 00000000..3fe1fd57
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/nokia_places_jsondb.pro
@@ -0,0 +1,50 @@
+load(qt_module)
+
+TARGET = qtgeoservices_nokia_places_jsondb
+QT += location network script
+
+load(qt_plugin)
+
+DESTDIR = $$QT.location.plugins/geoservices
+#QTDIR_build:REQUIRES += "contains(QT_CONFIG, location)"
+
+
+HEADERS += \
+ qgeoserviceproviderplugin_jsondb.h \
+ qplacemanagerengine_jsondb.h \
+ jsondbhandler.h \
+ savereply.h \
+ searchreply.h \
+ detailsreply.h \
+ reply.h \
+ unsupportedreplies.h \
+ macro.h
+
+SOURCES += \
+ qgeoserviceproviderplugin_jsondb.cpp \
+ qplacemanagerengine_jsondb.cpp \
+ jsondbhandler.cpp \
+ savereply.cpp \
+ searchreply.cpp \
+ detailsreply.cpp \
+ reply.cpp
+
+INCLUDEPATH += $$QT.location.includes
+
+
+DEFINES += QT_ADDON_JSONDB_LIB
+QT += jsondb
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA = 1
+ TARGET.CAPABILITY = ALL -TCB
+ TARGET.UID3 = 0x2002BFCA
+ pluginDep.sources = $${TARGET}.dll
+ pluginDep.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE}
+ DEPLOYMENT += pluginDep
+ LIBS += -lefsrv
+}
+
+target.path += $$[QT_INSTALL_PLUGINS]/geoservices
+INSTALLS += target
+
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.cpp
new file mode 100644
index 00000000..98c5c86a
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeoserviceproviderplugin_jsondb.h"
+
+#include "qplacemanagerengine_jsondb.h"
+
+#include <QtPlugin>
+#include <QNetworkProxy>
+
+QT_BEGIN_NAMESPACE
+
+QGeoServiceProviderFactoryJsonDb::QGeoServiceProviderFactoryJsonDb() {}
+
+QGeoServiceProviderFactoryJsonDb::~QGeoServiceProviderFactoryJsonDb() {}
+
+QString QGeoServiceProviderFactoryJsonDb::providerName() const
+{
+ return QLatin1String("nokia_places_jsondb");
+}
+
+int QGeoServiceProviderFactoryJsonDb::providerVersion() const
+{
+ return 1;
+}
+
+QGeocodingManagerEngine* QGeoServiceProviderFactoryJsonDb::createGeocodingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ return 0;
+}
+
+QGeoMappingManagerEngine* QGeoServiceProviderFactoryJsonDb::createMappingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ return 0;
+}
+
+QGeoRoutingManagerEngine* QGeoServiceProviderFactoryJsonDb::createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ return 0;
+}
+
+QPlaceManagerEngine *QGeoServiceProviderFactoryJsonDb::createPlaceManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const
+{
+ return new QPlaceManagerEngineJsonDb(parameters, error, errorString);
+}
+
+Q_EXPORT_PLUGIN2(qtgeoservices_nokia_places_jsondb, QGeoServiceProviderFactoryJsonDb)
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.h
new file mode 100644
index 00000000..a97aaa59
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/qgeoserviceproviderplugin_jsondb.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOSERVICEPROVIDER_JSON_H
+#define QGEOSERVICEPROVIDER_JSON_H
+
+#include <qgeoserviceproviderfactory.h>
+#include <QObject>
+
+QT_USE_NAMESPACE
+
+class QGeoServiceProviderFactoryJsonDb : public QObject, public QGeoServiceProviderFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QGeoServiceProviderFactory)
+public:
+ QGeoServiceProviderFactoryJsonDb();
+ ~QGeoServiceProviderFactoryJsonDb();
+
+ QString providerName() const;
+ int providerVersion() const;
+
+ QGeocodingManagerEngine* createGeocodingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+ QGeoMappingManagerEngine* createMappingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+ QGeoRoutingManagerEngine* createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+ QPlaceManagerEngine *createPlaceManagerEngine(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString) const;
+
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
new file mode 100644
index 00000000..2aff9b68
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplacemanagerengine_jsondb.h"
+
+#include <QDebug>
+#include <qgeoboundingcircle.h>
+#include <jsondb-error.h>
+
+#include "detailsreply.h"
+#include "reply.h"
+#include "savereply.h"
+#include "searchreply.h"
+#include "unsupportedreplies.h"
+
+QT_USE_NAMESPACE
+
+Q_DECLARE_METATYPE(QPlaceReply::Error)
+
+QPlaceManagerEngineJsonDb::QPlaceManagerEngineJsonDb(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString)
+: QPlaceManagerEngine(parameters),
+ m_jsonDbHandler(this)
+
+{
+ Q_UNUSED(error)
+ Q_UNUSED(errorString)
+
+ qRegisterMetaType<QPlaceReply::Error>();
+
+ connect(&m_jsonDbHandler, SIGNAL(jsonDbResponse(int,QVariant)),
+ this, SLOT(processJsonDbResponse(int,QVariant)));
+ connect(&m_jsonDbHandler, SIGNAL(jsonDbError(int,int,QString)),
+ this, SLOT(processJsonDbError(int,int,QString)));
+
+}
+
+QPlaceManagerEngineJsonDb::~QPlaceManagerEngineJsonDb()
+{
+}
+
+QPlaceDetailsReply *QPlaceManagerEngineJsonDb::getPlaceDetails(const QString &placeId)
+{
+ DetailsReply *detailsReply = new DetailsReply(this);
+ int reqId = m_jsonDbHandler.queryPlaceDetails(placeId);
+ m_idReplyMap.insert(reqId, detailsReply);
+ return detailsReply;
+}
+
+QPlaceContentReply *QPlaceManagerEngineJsonDb::getContent(const QGeoPlace &place, const QPlaceContentRequest &request)
+{
+ ContentReply *contentReply = new ContentReply(this);
+ contentReply->triggerDone(QPlaceReply::UnsupportedError, tr("Fetching content is unsupported"));
+ return contentReply;
+}
+
+QPlaceReply *QPlaceManagerEngineJsonDb::postRating(const QString &placeId, qreal value)
+{
+ Reply *reply = new Reply(this);
+ reply->triggerDone(QPlaceReply::UnsupportedError, tr("Posting of ratings is unsupported"));
+ return reply;
+}
+
+QPlaceSearchReply *QPlaceManagerEngineJsonDb::searchForPlaces(const QPlaceSearchRequest &request)
+{
+ SearchReply *searchReply = new SearchReply(this);
+ searchReply->setRequest(request);
+
+ if (!m_jsonDbHandler.isConnected()) {
+ searchReply->triggerDone(QPlaceReply::CommunicationError, "No connection to jsondb database");
+ return searchReply;
+ }
+
+ if (request.searchArea() != 0) {
+ QGeoBoundingArea *searchArea = request.searchArea();
+ if (searchArea->type() == QGeoBoundingArea::BoxType) {
+ QGeoBoundingBox *box = static_cast<QGeoBoundingBox *>(searchArea);
+ if (!box->isValid()) {
+ searchReply->triggerDone(QPlaceReply::BadArgumentError,
+ tr("Bounding box search area is invalid"));
+ return searchReply;
+ }
+ } else if (searchArea->type() == QGeoBoundingArea::CircleType) {
+ QGeoBoundingCircle *circle = static_cast<QGeoBoundingCircle *>(searchArea);
+ if (!circle->center().isValid()) {
+ searchReply->triggerDone(QPlaceReply::BadArgumentError,
+ tr("The center of the search area is an invalid coordinate"));
+ return searchReply;
+ }
+ if (circle->contains(QGeoCoordinate(90,0)) || circle->contains(QGeoCoordinate(-90,0))) {
+ searchReply->triggerDone(QPlaceReply::BadArgumentError,
+ tr("The search area contains the north or south pole"));
+ return searchReply;
+ }
+ }
+ }
+
+ QVariant searchJson = JsonDbHandler::convertToJsonVariant(request);
+ int reqId = m_jsonDbHandler.query(searchJson);
+ m_idReplyMap.insert(reqId, searchReply);
+ return searchReply;
+}
+
+QPlaceSearchReply *QPlaceManagerEngineJsonDb::recommendations(const QGeoPlace &place, const QPlaceSearchRequest &request)
+{
+ SearchReply *searchReply = new SearchReply(this);
+ searchReply->triggerDone(QPlaceReply::UnsupportedError, tr("Recommendations is unsupported"));
+ return searchReply;
+}
+
+QPlaceTextPredictionReply *QPlaceManagerEngineJsonDb::textPredictions(const QPlaceSearchRequest &request)
+{
+ TextPredictionReply *textPredictionReply = new TextPredictionReply(this);
+ textPredictionReply->triggerDone(QPlaceReply::UnsupportedError, tr("Text prediction is unsupported"));
+ return textPredictionReply;
+}
+
+QPlaceManager::ConnectivityModes QPlaceManagerEngineJsonDb::connectivityMode() const
+{
+ return QPlaceManager::OfflineMode;
+}
+
+void QPlaceManagerEngineJsonDb::setConnectivityMode(QPlaceManager::ConnectivityModes mode)
+{
+ Q_UNUSED(mode)
+}
+
+QPlaceManager::ConnectivityModes QPlaceManagerEngineJsonDb::supportedConnectivityModes() const
+{
+ return QPlaceManager::OfflineMode;
+}
+
+QPlaceSaveReply *QPlaceManagerEngineJsonDb::savePlace(const QGeoPlace &place, QPlaceManager::VisibilityScope scope)
+{
+
+ SaveReply *saveReply = new SaveReply(this);
+ if (!m_jsonDbHandler.isConnected()) {
+ saveReply->triggerDone(QPlaceReply::CommunicationError, "No connection to jsondb database");
+ return saveReply;
+ }
+
+ if (scope == QPlaceManager::PublicScope) {
+ saveReply->triggerDone(QPlaceReply::UnsupportedError, tr("Saving to public scope in unsupported"));
+ } else {
+ QVariant jsonPlace = JsonDbHandler::convertToJsonVariant(place);
+ int reqId;
+ if (place.placeId().isEmpty())
+ reqId = m_jsonDbHandler.write(jsonPlace);
+ else
+ reqId = m_jsonDbHandler.update(jsonPlace);
+
+ m_idReplyMap.insert(reqId, saveReply);
+ }
+ return saveReply;
+}
+
+QPlaceManager::VisibilityScopes QPlaceManagerEngineJsonDb::supportedSaveVisibilityScopes() const
+{
+ return QPlaceManager::NoScope | QPlaceManager::PrivateScope;
+}
+
+QPlaceReply *QPlaceManagerEngineJsonDb::removePlace(const QGeoPlace &place)
+{
+ Reply *reply = new Reply(this);
+
+ if (!m_jsonDbHandler.isConnected()) {
+ reply->triggerDone(QPlaceReply::CommunicationError, "No connection to jsondb database");
+ return reply;
+ }
+
+ int reqId = m_jsonDbHandler.remove(place.placeId());
+ m_idReplyMap.insert(reqId, reply);
+ return reply;
+}
+
+QPlaceReply *QPlaceManagerEngineJsonDb::initializeCategories()
+{
+ Reply *reply = new Reply(this);
+ reply->triggerDone(QPlaceReply::UnsupportedError, tr("Categories are unsupported"));
+ return reply;
+}
+
+QList<QPlaceCategory> QPlaceManagerEngineJsonDb::categories(const QPlaceCategory &parent) const
+{
+ Q_UNUSED(parent);
+ return QList<QPlaceCategory>();
+}
+
+QLocale QPlaceManagerEngineJsonDb::locale() const
+{
+ return QLocale();
+}
+
+void QPlaceManagerEngineJsonDb::setLocale(const QLocale &locale)
+{
+ Q_UNUSED(locale);
+}
+
+void QPlaceManagerEngineJsonDb::processJsonDbResponse(int id, const QVariant &data)
+{
+ QPlaceReply *reply = m_idReplyMap.value(id,0);
+ if (reply) {
+ switch (reply->type()) {
+ case QPlaceReply::SaveReply: {
+
+ /*
+ Expected data format
+ {
+ "uuid":<uuid>,
+ "_version": <version>
+ }
+ */
+ SaveReply *saveReply = qobject_cast<SaveReply *>(reply);
+ saveReply->setPlaceId(data.toMap().value(UUID).toString());
+ saveReply->triggerDone();
+ break;
+ }
+ case QPlaceReply::PlaceSearchReply: {
+ SearchReply *searchReply = qobject_cast<SearchReply *>(reply);
+ QList<QGeoPlace> places = JsonDbHandler::convertJsonResponseToPlaces(data);
+ if (searchReply->request().searchArea() != 0) {
+ QGeoBoundingArea *searchArea = searchReply->request().searchArea();
+ if (searchArea->type() == QGeoBoundingArea::CircleType) {
+ QGeoBoundingCircle *circle = static_cast<QGeoBoundingCircle*>(searchArea);
+ foreach (const QGeoPlace &place, places) {
+ double dist = circle->center().distanceTo(place.location().coordinate());
+ if (dist > circle->radius())
+ places.removeAll(place);
+ }
+ //TODO: we can optimize this using a bounding box to cull candidates
+ // and then use distance comparisons for the rest.
+
+ } else if (searchArea->type() == QGeoBoundingArea::BoxType) {
+ //There seem to be some issues with using the comparison operators
+ //so for now we filter in the plugin code
+ QGeoBoundingBox *box = static_cast<QGeoBoundingBox *>(searchArea);
+ double tly = box->topLeft().latitude();
+ double bry = box->bottomRight().latitude();
+ double tlx = box->topLeft().longitude();
+ double brx = box->bottomRight().longitude();
+
+ QGeoCoordinate coord;
+ foreach (const QGeoPlace &place, places) {
+ coord = place.location().coordinate();
+ if (coord.latitude() > tly)
+ places.removeAll(place);
+ if (coord.latitude() < bry)
+ places.removeAll(place);
+
+ bool lonWrap = (tlx > brx); //box wraps over the dateline
+
+ if (!lonWrap) {
+ if (coord.longitude() < tlx || coord.longitude() > brx) {
+ places.removeAll(place);
+ }
+ } else {
+ if (coord.longitude() < tlx && coord.longitude() > brx) {
+ places.removeAll(place);
+ }
+ }
+ }
+ }
+ }
+
+ QList<QPlaceSearchResult> results;
+ QPlaceSearchResult result;
+ foreach (const QGeoPlace &place, places) {
+ result.setPlace(place);
+ results.append(result);
+ }
+
+ searchReply->setResults(results);
+ searchReply->triggerDone();
+ break;
+ }
+ case QPlaceReply::PlaceDetailsReply: {
+ QVariantMap jsonMap = data.toMap();
+ DetailsReply *detailsReply = qobject_cast<DetailsReply *>(reply);
+ if (jsonMap.value("length").toInt() <= 0) {
+ detailsReply->triggerDone(QPlaceReply::PlaceDoesNotExistError,
+ tr("Specified place does not exist"));
+ } else {
+ QList<QGeoPlace> places = JsonDbHandler::convertJsonResponseToPlaces(data);
+ Q_ASSERT(!places.isEmpty());
+ detailsReply->setResult(places.first());
+ detailsReply->triggerDone();
+ }
+ break;
+ }
+ case QPlaceReply::Reply: {
+ Reply *reply_ = qobject_cast<Reply *>(reply);
+ reply_->triggerDone();
+ break;
+ }
+ }
+ }
+ m_idReplyMap.remove(id);
+}
+
+void QPlaceManagerEngineJsonDb::processJsonDbError(int id, int code, const QString &jsonDbErrorString)
+{
+ QPlaceReply::Error error = QPlaceReply::UnknownError;
+ QString errorString = tr("Unknown error occurred operation: jsondb error code =%1, erroString=%2").
+ arg(code).arg(jsonDbErrorString);
+
+ QPlaceReply *placeReply = m_idReplyMap.value(id,0);
+ if (placeReply) {
+ switch (placeReply->type()) {
+ case QPlaceReply::SaveReply: {
+ SaveReply *saveReply = qobject_cast<SaveReply *>(placeReply);
+ switch (code) {
+ case JsonDbError::InvalidRequest:
+ error = QPlaceReply::PlaceDoesNotExistError;
+ errorString = tr("Trying to update place which does not exist");
+ break;
+ }
+ saveReply->triggerDone(error, errorString);
+ break;
+ }
+ case QPlaceReply::PlaceSearchReply: {
+ SearchReply *searchReply = qobject_cast<SearchReply*>(placeReply);
+ searchReply->triggerDone(error, errorString);
+ break;
+ }
+ case QPlaceReply::Reply: {
+ Reply *reply = qobject_cast<Reply*>(placeReply);
+ reply->triggerDone(error, errorString);
+ break;
+ }
+ }
+ m_idReplyMap.remove(id);
+ }
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
new file mode 100644
index 00000000..94f21c61
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by tOhe Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLACEMANAGERENGINE_NOKIA_JSONDB_H
+#define QPLACEMANAGERENGINE_NOKIA_JSONDB_H
+
+#include <qplacemanagerengine.h>
+#include <qgeoserviceprovider.h>
+
+#include "jsondbhandler.h"
+
+QT_USE_NAMESPACE
+
+class QPlaceManagerEngineJsonDb : public QPlaceManagerEngine
+{
+ Q_OBJECT
+public:
+
+ QPlaceManagerEngineJsonDb(const QMap<QString, QVariant> &parameters, QGeoServiceProvider::Error *error,
+ QString *errorString);
+ ~QPlaceManagerEngineJsonDb();
+
+ QPlaceDetailsReply *getPlaceDetails(const QString &placeId);
+
+ QPlaceReply *postRating(const QString &placeId, qreal value);
+
+ QPlaceContentReply *getContent(const QGeoPlace &place, const QPlaceContentRequest &request);
+
+ QPlaceSearchReply *searchForPlaces(const QPlaceSearchRequest &request);
+
+ QPlaceSearchReply *recommendations(const QGeoPlace &place, const QPlaceSearchRequest &request);
+ QPlaceTextPredictionReply *textPredictions(const QPlaceSearchRequest &request);
+
+ QPlaceManager::ConnectivityModes connectivityMode() const;
+ void setConnectivityMode(QPlaceManager::ConnectivityModes connectivityMode);
+ QPlaceManager::ConnectivityModes supportedConnectivityModes() const;
+
+ QPlaceSaveReply *savePlace(const QGeoPlace &place, QPlaceManager::VisibilityScope scope);
+ QPlaceManager::VisibilityScopes supportedSaveVisibilityScopes() const;
+
+ QPlaceReply *removePlace(const QGeoPlace &place);
+
+ QPlaceReply *initializeCategories();
+ QList<QPlaceCategory> categories(const QPlaceCategory &parent) const;
+
+ QLocale locale() const;
+ void setLocale(const QLocale &locale);
+
+public slots:
+ void processJsonDbResponse(int id, const QVariant &data);
+ void processJsonDbError(int id, int code, const QString &data);
+
+private:
+ JsonDbHandler m_jsonDbHandler;
+ QMap<int, QPlaceReply *> m_idReplyMap;
+ friend class JsonDbHandler;
+ friend class SaveReply;
+ friend class MediaReply;
+ friend class RemoveReply;
+ friend class TextPredictionReply;
+ friend class ReviewReply;
+ friend class Reply;
+ friend class SearchReply;
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/reply.cpp b/src/plugins/geoservices/nokia_places_jsondb/reply.cpp
new file mode 100644
index 00000000..382f2b97
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/reply.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "reply.h"
+#include <QTimer>
+
+Reply::Reply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceReply(engine), m_engine(engine)
+{
+}
+
+Reply::~Reply()
+{
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/reply.h b/src/plugins/geoservices/nokia_places_jsondb/reply.h
new file mode 100644
index 00000000..de375f2e
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/reply.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef REPLY_H
+#define REPLY_H
+
+#include <qplacereply.h>
+
+#include "macro.h"
+#include "qplacemanagerengine_jsondb.h"
+
+QT_USE_NAMESPACE
+
+class Reply : public QPlaceReply
+{
+ Q_OBJECT
+public:
+ Reply(QPlaceManagerEngineJsonDb *m_engine);
+ virtual ~Reply();
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/savereply.cpp b/src/plugins/geoservices/nokia_places_jsondb/savereply.cpp
new file mode 100644
index 00000000..cd31abf1
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/savereply.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "savereply.h"
+
+SaveReply::SaveReply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceSaveReply(engine),m_engine(engine)
+{
+}
+
+SaveReply::~SaveReply()
+{
+}
+
+void SaveReply::setPlaceId(const QString &placeId)
+{
+ QPlaceSaveReply::setPlaceId(placeId);
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/savereply.h b/src/plugins/geoservices/nokia_places_jsondb/savereply.h
new file mode 100644
index 00000000..615eb139
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/savereply.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef SAVEREPLY_H
+#define SAVEREPLY_H
+
+#include <qplacesavereply.h>
+
+#include "macro.h"
+#include "qplacemanagerengine_jsondb.h"
+
+QT_USE_NAMESPACE
+
+class SaveReply : public QPlaceSaveReply
+{
+ Q_OBJECT
+public:
+ SaveReply(QPlaceManagerEngineJsonDb *engine);
+ virtual ~SaveReply();
+ void setPlaceId(const QString &placeId);
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp b/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp
new file mode 100644
index 00000000..96efd4eb
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/searchreply.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "searchreply.h"
+
+SearchReply::SearchReply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceSearchReply(engine), m_engine(engine)
+{
+}
+
+SearchReply::~SearchReply()
+{
+}
+
+void SearchReply::setResults(const QList<QPlaceSearchResult> &results)
+{
+ QPlaceSearchReply::setResults(results);
+}
+
+void SearchReply::setRequest(const QPlaceSearchRequest &request)
+{
+ QPlaceSearchReply::setRequest(request);
+}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/searchreply.h b/src/plugins/geoservices/nokia_places_jsondb/searchreply.h
new file mode 100644
index 00000000..6b89bb3e
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/searchreply.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef SEARCHREPLY_H
+#define SEARCHREPLY_H
+
+#include <qplacesearchreply.h>
+
+#include "macro.h"
+#include "qplacemanagerengine_jsondb.h"
+
+QT_USE_NAMESPACE
+
+class SearchReply : public QPlaceSearchReply
+{
+ Q_OBJECT
+public:
+ SearchReply(QPlaceManagerEngineJsonDb *engine);
+ virtual ~SearchReply();
+ void setResults(const QList<QPlaceSearchResult> &results);
+ void setRequest(const QPlaceSearchRequest &request);
+
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+
+};
+
+#endif
diff --git a/src/plugins/geoservices/nokia_places_jsondb/unsupportedreplies.h b/src/plugins/geoservices/nokia_places_jsondb/unsupportedreplies.h
new file mode 100644
index 00000000..854ce720
--- /dev/null
+++ b/src/plugins/geoservices/nokia_places_jsondb/unsupportedreplies.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef UNSUPPORTED_REPLIES_H
+#define UNSUPPORTED_REPLIES_H
+
+#include <qplacecontentreply.h>
+#include <qplacetextpredictionreply.h>
+
+#include "macro.h"
+#include "qplacemanagerengine_jsondb.h"
+
+QT_USE_NAMESPACE
+
+class ContentReply : public QPlaceContentReply
+{
+ Q_OBJECT
+public:
+ ContentReply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceContentReply(engine), m_engine(engine)
+ {}
+ virtual ~ContentReply() {}
+
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+
+};
+
+class TextPredictionReply : public QPlaceTextPredictionReply
+{
+ Q_OBJECT
+public:
+ TextPredictionReply(QPlaceManagerEngineJsonDb *engine)
+ : QPlaceTextPredictionReply(engine), m_engine(engine)
+ {}
+ virtual ~TextPredictionReply() {}
+
+ DECLARE_TRIGGER_DONE_FN
+
+private:
+ QPlaceManagerEngineJsonDb *m_engine;
+};
+
+#endif
diff --git a/sync.profile b/sync.profile
index bd29e380..78ee9513 100644
--- a/sync.profile
+++ b/sync.profile
@@ -27,3 +27,8 @@
"qtxmlpatterns" => "refs/heads/master",
"qtdeclarative" => "refs/heads/master",
);
+
+# compile tests
+%configtests = (
+ "jsondb" => {}
+);
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 6a02b6bc..7e1ac347 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -27,3 +27,7 @@ SUBDIRS += geotestplugin \
qplacesearchrequest \
qplacesupplier \
declarative
+
+contains(config_test_jsondb, yes) {
+ SUBDIRS += qplacemanager_jsondb
+}
diff --git a/tests/auto/qplacemanager_jsondb/jsondbcleaner.cpp b/tests/auto/qplacemanager_jsondb/jsondbcleaner.cpp
new file mode 100644
index 00000000..fbba7ed4
--- /dev/null
+++ b/tests/auto/qplacemanager_jsondb/jsondbcleaner.cpp
@@ -0,0 +1,69 @@
+#include "jsondbcleaner.h"
+
+#include <jsondb-client.h>
+
+#include <QDebug>
+#include <QMap>
+#include <QString>
+#include <QStringList>
+
+#define UUID "_uuid"
+#define TYPE "_type"
+
+#define PLACE_TYPE "place"
+
+JsonDbCleaner::JsonDbCleaner(QObject *parent)
+ : QObject(parent)
+{
+ mDb = new JsonDbClient(this);
+ if (!mDb->connected()) {
+ qWarning() << "JsonDb not connected";
+ } else {
+ connect(mDb, SIGNAL(response(int, const QVariant&)),
+ this, SLOT(jsonDbResponse(int, const QVariant&)), Qt::QueuedConnection);
+ connect(mDb, SIGNAL(error(int, int, const QString&)),
+ this, SLOT(jsonDbError(int, int, const QString&)), Qt::QueuedConnection);
+ }
+}
+
+void JsonDbCleaner::jsonDbResponse(int id, const QVariant& data)
+{
+ if (cleanReqId.contains(id)) {
+ QVariantMap jsonMap = data.toMap();
+ QList<QVariant> dataList = jsonMap.value("data").toList();
+ if (!dataList.isEmpty()) {
+ bool placesFound = false;
+ foreach (const QVariant &var, dataList) {
+ QVariantMap placeJson = var.toMap();
+ if (placeJson.value(TYPE).toString() == QLatin1String(PLACE_TYPE)) {
+ placesFound = true;
+ QVariantMap removeMap;
+ removeMap.insert(UUID,placeJson.value(UUID).toString());
+ removeReqId.append(mDb->remove(removeMap));
+ }
+ }
+
+ if (!placesFound)
+ emit dbCleaned();
+ }
+ cleanReqId.removeAll(id);
+ }
+
+ if (removeReqId.contains(id)) {
+ removeReqId.removeAll(id);
+ if (removeReqId.isEmpty())
+ emit dbCleaned();
+ }
+}
+
+void JsonDbCleaner::jsonDbError(int id, int code, const QString& data)
+{
+ qDebug() << Q_FUNC_INFO << " id: " << id << " code: " << code << " data: " << data;
+}
+
+void JsonDbCleaner::cleanDb()
+{
+ cleanReqId.append(mDb->query(QString("[*]")));
+}
+
+
diff --git a/tests/auto/qplacemanager_jsondb/jsondbcleaner.h b/tests/auto/qplacemanager_jsondb/jsondbcleaner.h
new file mode 100644
index 00000000..3f2f0618
--- /dev/null
+++ b/tests/auto/qplacemanager_jsondb/jsondbcleaner.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the FOO module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef JSONDBCLEANER_H
+#define JSONDBCLEANER_H
+
+#include <QObject>
+#include <QMap>
+#include <QVariant>
+
+#include <jsondb-global.h>
+Q_ADDON_JSONDB_BEGIN_NAMESPACE
+class JsonDbClient;
+Q_ADDON_JSONDB_END_NAMESPACE
+Q_USE_JSONDB_NAMESPACE
+
+class JsonDbCleaner : public QObject
+{
+ Q_OBJECT
+public:
+ JsonDbCleaner(QObject *parent = 0);
+ void cleanDb();
+
+public slots:
+ void jsonDbResponse( int id, const QVariant& data);
+ void jsonDbError( int id, int code, const QString& data);
+
+signals:
+ void dbCleaned();
+
+private:
+ JsonDbClient *mDb;
+ QList<int> cleanReqId;
+ QList<int> removeReqId;
+};
+
+#endif
diff --git a/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro b/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro
new file mode 100644
index 00000000..78682935
--- /dev/null
+++ b/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+
+TARGET = tst_qplacemanager_jsondb
+
+HEADERS += jsondbcleaner.h
+
+SOURCES += tst_qplacemanager_jsondb.cpp \
+ jsondbcleaner.cpp
+
+
+
+QT += location testlib script
+CONFIG += debug
+
+DEFINES += QT_ADDON_JSONDB_LIB
+QT += jsondb
+
+
diff --git a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
new file mode 100644
index 00000000..1f2358a0
--- /dev/null
+++ b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
@@ -0,0 +1,800 @@
+#include <QCoreApplication>
+#include <QString>
+#include <QtTest/QtTest>
+
+#include <qgeoboundingbox.h>
+#include <qgeoboundingcircle.h>
+#include <qgeoserviceprovider.h>
+#include <qplacemanager.h>
+#include <qplacecontentreply.h>
+#include <qplacetextpredictionreply.h>
+#include <qplacesearchrequest.h>
+#include <qplacesearchresult.h>
+#include <qplacesearchreply.h>
+
+#include "jsondbcleaner.h"
+
+#ifndef QTRY_VERIFY
+#define QTRY_VERIFY(__expr) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if (!(__expr)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QVERIFY(__expr); \
+ } while (0)
+#endif
+
+#ifndef WAIT_UNTIL
+#define WAIT_UNTIL(__expr) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if (!(__expr)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ } while (0)
+#endif
+
+Q_DECLARE_METATYPE(QPlaceReply::Error);
+Q_DECLARE_METATYPE(QPlaceReply *);
+Q_DECLARE_METATYPE(QPlaceSaveReply *);
+
+QT_USE_NAMESPACE
+
+class tst_QPlaceManagerJsonDb : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QPlaceManagerJsonDb();
+
+private Q_SLOTS:
+ void initTestCase();
+ void cleanup();
+
+ void saveAndRemove();
+ void updatePlace();
+ void searchByName();
+ void searchByBox();
+ void searchByCircle();
+ void unsupportedFunctions();
+
+private:
+ bool doSavePlace(const QGeoPlace &place,
+ QPlaceReply::Error expectedError = QPlaceReply::NoError,
+ QString *placeId = 0,
+ QPlaceManager::VisibilityScope = QPlaceManager::NoScope);
+ void doSavePlaces(QList<QGeoPlace> &places);
+ bool doSearch(const QPlaceSearchRequest &request,
+ QList<QPlaceSearchResult> *results,
+ QPlaceReply::Error expectedError = QPlaceReply::NoError);
+
+ bool doSearch(const QPlaceSearchRequest &request,
+ QList<QGeoPlace> *results,
+ QPlaceReply::Error expectedError = QPlaceReply::NoError);
+
+ bool doFetchDetails(QString placeId,
+ QGeoPlace *place,
+ QPlaceReply::Error expectedError = QPlaceReply::NoError);
+
+ bool checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError);
+
+
+ bool compareResults(const QList<QPlaceSearchResult> &results, const QList<QGeoPlace> &expectedResults);
+
+ QGeoServiceProvider *provider;
+ QPlaceManager *placeManager;
+ QCoreApplication *coreApp;
+ JsonDbCleaner *dbCleaner ;
+};
+
+tst_QPlaceManagerJsonDb::tst_QPlaceManagerJsonDb()
+{
+ //We need a QCoreApplication instance for
+ //event dispatching
+ int argc;
+ char **argv=0;
+ coreApp = new QCoreApplication(argc, argv);
+
+ dbCleaner = new JsonDbCleaner(this);
+}
+
+void tst_QPlaceManagerJsonDb::initTestCase()
+{
+ qRegisterMetaType<QPlaceReply::Error>();
+ qRegisterMetaType<QPlaceReply *>();
+ qRegisterMetaType<QPlaceSaveReply *>();
+
+ QStringList providers = QGeoServiceProvider::availableServiceProviders();
+ providers.contains("nokia_places_jsondb");
+
+ provider = new QGeoServiceProvider("nokia_places_jsondb");
+ placeManager = provider->placeManager();
+ QVERIFY(placeManager);
+
+ QVERIFY(placeManager->connectivityMode() == QPlaceManager::OfflineMode);
+
+ cleanup();
+}
+
+void tst_QPlaceManagerJsonDb::saveAndRemove()
+{
+ QGeoPlace place;
+ place.setName("Char");
+ QGeoLocation location;
+
+ location.setCoordinate(QGeoCoordinate(10,20,30));
+
+ QGeoAddress address;
+ address.setStreet("1 test street");
+ address.setCity("New york");
+ address.setCountry("USA");
+ location.setAddress(address);
+
+ place.setLocation(location);
+
+ //Save a place
+ QString placeId;
+ QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
+
+ //ensure we can retrieve it's details
+ QGeoPlace retrievedPlace;
+ QVERIFY(doFetchDetails(placeId, &retrievedPlace));
+ place.setPlaceId(placeId);
+ QVERIFY(retrievedPlace == place);
+
+ //try remvoing a place
+ QPlaceReply *reply = placeManager->removePlace(place);
+ QSignalSpy removeSpy(reply, SIGNAL(finished()));
+ QTRY_VERIFY(removeSpy.count() == 1);
+
+ //ensure it is actually deleted
+ QVERIFY(doFetchDetails(placeId, &retrievedPlace, QPlaceReply::PlaceDoesNotExistError));
+ QCOMPARE(retrievedPlace, QGeoPlace());
+
+ QVERIFY(doSavePlace(place, QPlaceReply::UnsupportedError,0, QPlaceManager::PublicScope));
+}
+
+void tst_QPlaceManagerJsonDb::updatePlace()
+{
+ //save a place and check that we can retrieve it
+ QGeoPlace place;
+ place.setName("Sydney");
+ QGeoAddress address;
+ address.setStreet("original street");
+ QGeoLocation location;
+ location.setAddress(address);
+ place.setLocation(location);
+
+ QString placeId;
+ QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
+ QVERIFY(doFetchDetails(placeId, &place));
+
+ //update the place again with some changes
+ place.setName(QLatin1String("Brisbane"));
+ address.setStreet(QLatin1String("new street"));
+ address.setCountry(QLatin1String("Australia"));
+ location.setAddress(address);
+ place.setLocation(location);
+
+ QGeoPlace retrievedPlace;
+ QVERIFY(doSavePlace(place, QPlaceReply::NoError));
+ QVERIFY(doFetchDetails(place.placeId(), &retrievedPlace));
+ QCOMPARE(retrievedPlace.name(), QLatin1String("Brisbane"));
+ QCOMPARE(retrievedPlace.location().address().street(), QLatin1String("new street"));
+ QCOMPARE(retrievedPlace.location().address().country(), QLatin1String("Australia"));
+
+ //try updating a non-existent place
+ place.setPlaceId("Non-existent id");
+ QVERIFY(doSavePlace(place, QPlaceReply::PlaceDoesNotExistError));
+}
+
+void tst_QPlaceManagerJsonDb::searchByName()
+{
+ QGeoPlace adelaide, adel, ad, brisbane;
+ adelaide.setName("Adelaide");
+ adel.setName("adel");
+ ad.setName("ad");
+ brisbane.setName("brisbane");
+
+ QList<QGeoPlace> places;
+ places << adelaide << adel << ad << brisbane;
+ doSavePlaces(places);
+
+ //test that search has a 'startsWith' behaviour
+ //and is case insensitive
+ QPlaceSearchRequest request;
+ request.setSearchTerm("adel");
+ QList<QPlaceSearchResult> results;
+ QVERIFY(doSearch(request, &results));
+ QCOMPARE(results.count(), 2);
+
+ //Search for a non-exisent place
+ request.setSearchTerm("Nowhere");
+ QVERIFY(doSearch(request, &results));
+ QCOMPARE(results.count(), 0);
+}
+
+void tst_QPlaceManagerJsonDb::searchByBox()
+{
+ QList<QGeoCoordinate> outBox;
+ QList<QGeoCoordinate> inBox1;
+
+ inBox1 << QGeoCoordinate(-5.0, -5.0);
+ inBox1 << QGeoCoordinate(-5.0, 0.0);
+ inBox1 << QGeoCoordinate(-5.0, 5.0);
+ inBox1 << QGeoCoordinate(0.0, -5.0);
+ inBox1 << QGeoCoordinate(0.0, 0.0);
+ inBox1 << QGeoCoordinate(0.0, 5.0);
+ inBox1 << QGeoCoordinate(5.0, -5.0);
+ inBox1 << QGeoCoordinate(5.0, 0.0);
+ inBox1 << QGeoCoordinate(5.0, 5.0);
+
+ outBox << QGeoCoordinate(-5.0, -6.0);
+ outBox << QGeoCoordinate(5.0, -6.0);
+ outBox << QGeoCoordinate(-6.0, -5.0);
+ outBox << QGeoCoordinate(6.0, -5.0);
+ outBox << QGeoCoordinate(-6.0, 5.0);
+ outBox << QGeoCoordinate(6.0, 5.0);
+ outBox << QGeoCoordinate(-5.0, 6.0);
+ outBox << QGeoCoordinate(5.0, 6.0);
+
+ QList<QGeoCoordinate> inBox2;
+
+ inBox2 << QGeoCoordinate(-5.0, 10.0);
+ inBox2 << QGeoCoordinate(-5.0, 15.0);
+ inBox2 << QGeoCoordinate(-5.0, 20.0);
+ inBox2 << QGeoCoordinate(0.0, 10.0);
+ inBox2 << QGeoCoordinate(0.0, 15.0);
+ inBox2 << QGeoCoordinate(0.0, 20.0);
+ inBox2 << QGeoCoordinate(5.0, 10.0);
+ inBox2 << QGeoCoordinate(5.0, 15.0);
+ inBox2 << QGeoCoordinate(5.0, 20.0);
+
+ outBox << QGeoCoordinate(-5.0, 9.0);
+ outBox << QGeoCoordinate(5.0, 9.0);
+ outBox << QGeoCoordinate(-6.0, 10.0);
+ outBox << QGeoCoordinate(6.0, 10.0);
+ outBox << QGeoCoordinate(-6.0, 20.0);
+ outBox << QGeoCoordinate(6.0, 20.0);
+ outBox << QGeoCoordinate(-5.0, 21.0);
+ outBox << QGeoCoordinate(5.0, 21.0);
+
+ QList<QGeoCoordinate> inBox3;
+
+ inBox3 << QGeoCoordinate(10.0, -5.0);
+ inBox3 << QGeoCoordinate(10.0, 0.0);
+ inBox3 << QGeoCoordinate(10.0, 5.0);
+ inBox3 << QGeoCoordinate(15.0, -5.0);
+ inBox3 << QGeoCoordinate(15.0, 0.0);
+ inBox3 << QGeoCoordinate(15.0, 5.0);
+ inBox3 << QGeoCoordinate(20.0, -5.0);
+ inBox3 << QGeoCoordinate(20.0, 0.0);
+ inBox3 << QGeoCoordinate(20.0, 5.0);
+
+ outBox << QGeoCoordinate(10.0, -6.0);
+ outBox << QGeoCoordinate(20.0, -6.0);
+ outBox << QGeoCoordinate(9.0, -5.0);
+ outBox << QGeoCoordinate(21.0, -5.0);
+ outBox << QGeoCoordinate(9.0, 5.0);
+ outBox << QGeoCoordinate(21.0, 5.0);
+ outBox << QGeoCoordinate(10.0, 6.0);
+ outBox << QGeoCoordinate(20.0, 6.0);
+
+ QList<QGeoCoordinate> inBox4;
+
+ inBox4 << QGeoCoordinate(10.0, 10.0);
+ inBox4 << QGeoCoordinate(10.0, 15.0);
+ inBox4 << QGeoCoordinate(10.0, 20.0);
+ inBox4 << QGeoCoordinate(15.0, 10.0);
+ inBox4 << QGeoCoordinate(15.0, 15.0);
+ inBox4 << QGeoCoordinate(15.0, 20.0);
+ inBox4 << QGeoCoordinate(20.0, 10.0);
+ inBox4 << QGeoCoordinate(20.0, 15.0);
+ inBox4 << QGeoCoordinate(20.0, 20.0);
+
+ outBox << QGeoCoordinate(10.0, 9.0);
+ outBox << QGeoCoordinate(20.0, 9.0);
+ outBox << QGeoCoordinate(9.0, 10.0);
+ outBox << QGeoCoordinate(21.0, 10.0);
+ outBox << QGeoCoordinate(9.0, 20.0);
+ outBox << QGeoCoordinate(21.0, 20.0);
+ outBox << QGeoCoordinate(10.0, 21.0);
+ outBox << QGeoCoordinate(20.0, 21.0);
+
+ QList<QGeoCoordinate> inBox5;
+
+ inBox5 << QGeoCoordinate(-5.0, 175.0);
+ inBox5 << QGeoCoordinate(-5.0, 180.0);
+ inBox5 << QGeoCoordinate(-5.0, -175.0);
+ inBox5 << QGeoCoordinate(0.0, 175.0);
+ inBox5 << QGeoCoordinate(0.0, 180.0);
+ inBox5 << QGeoCoordinate(0.0, -175.0);
+ inBox5 << QGeoCoordinate(5.0, 175.0);
+ inBox5 << QGeoCoordinate(5.0, 180.0);
+ inBox5 << QGeoCoordinate(5.0, -175.0);
+
+ outBox << QGeoCoordinate(-6.0, 175.0);
+ outBox << QGeoCoordinate(-6.0, -175.0);
+ outBox << QGeoCoordinate(-5.0, 174.0);
+ outBox << QGeoCoordinate(-5.0, -174.0);
+ outBox << QGeoCoordinate(5.0, 174.0);
+ outBox << QGeoCoordinate(5.0, -174.0);
+ outBox << QGeoCoordinate(6.0, 175.0);
+ outBox << QGeoCoordinate(6.0, -175.0);
+
+ QList<QGeoCoordinate> coords = outBox;
+ coords.append(inBox1);
+ coords.append(inBox2);
+ coords.append(inBox3);
+ coords.append(inBox4);
+ coords.append(inBox5);
+
+ QList<QGeoPlace> places;
+ for (int i = 0; i < coords.size(); ++i) {
+ QGeoPlace place;
+ QGeoLocation location;
+ location.setCoordinate(coords.at(i));
+ place.setLocation(location);
+ places << place;
+ }
+ doSavePlaces(places);
+
+ QPlaceSearchRequest request;
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, -5.0), QGeoCoordinate(-5.0, 5.0)));
+
+ QList<QPlaceSearchResult> results1;
+ doSearch(request, &results1);
+ QList<QGeoPlace> places1;
+ foreach (const QPlaceSearchResult &result, results1)
+ places1.append(result.place());
+
+ QCOMPARE(places1.size(), inBox1.size());
+
+ QSet<QString> testSet1;
+ for (int i = 0; i < places1.size(); ++i)
+ testSet1.insert(places1.at(i).location().coordinate().toString());
+
+ QSet<QString> inBoxSet1;
+ for (int i = 0; i < inBox1.size(); ++i)
+ inBoxSet1.insert(inBox1.at(i).toString());
+
+ QCOMPARE(testSet1, inBoxSet1);
+
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, 10.0), QGeoCoordinate(-5.0, 20.0)));
+ QList<QGeoPlace> places2;
+ doSearch(request, &places2);
+ QCOMPARE(places2.size(), inBox2.size());
+
+ QSet<QString> testSet2;
+ for (int i = 0; i < places2.size(); ++i)
+ testSet2.insert(places2.at(i).location().coordinate().toString());
+
+ QSet<QString> inBoxSet2;
+ for (int i = 0; i < inBox2.size(); ++i)
+ inBoxSet2.insert(inBox2.at(i).toString());
+
+ QCOMPARE(testSet2, inBoxSet2);
+
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20.0, -5.0), QGeoCoordinate(10.0, 5.0)));
+ QList<QGeoPlace> places3;
+ doSearch(request, &places3);
+
+ QCOMPARE(places3.size(), inBox3.size());
+
+ QSet<QString> testSet3;
+ for (int i = 0; i < places3.size(); ++i)
+ testSet3.insert(places3.at(i).location().coordinate().toString());
+
+ QSet<QString> inBoxSet3;
+ for (int i = 0; i < inBox3.size(); ++i)
+ inBoxSet3.insert(inBox3.at(i).toString());
+
+ QCOMPARE(testSet3, inBoxSet3);
+
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20.0, 10.0), QGeoCoordinate(10.0, 20.0)));
+ QList<QGeoPlace> places4;
+ doSearch(request, &places4);
+ QCOMPARE(places4.size(), inBox4.size());
+
+ QSet<QString> testSet4;
+ for (int i = 0; i < places4.size(); ++i)
+ testSet4.insert(places4.at(i).location().coordinate().toString());
+
+ QSet<QString> inBoxSet4;
+ for (int i = 0; i < inBox4.size(); ++i)
+ inBoxSet4.insert(inBox4.at(i).toString());
+
+ QCOMPARE(testSet4, inBoxSet4);
+
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(5.0, 175.0), QGeoCoordinate(-5.0, -175.0)));
+ QList<QGeoPlace> places5;
+ doSearch(request, &places5);
+ QCOMPARE(places5.size(), inBox5.size());
+
+ QSet<QString> testSet5;
+ for (int i = 0; i < places5.size(); ++i) {
+ if (places5.at(i).location().coordinate().longitude() == -180.0) {
+ QGeoLocation location;
+ location.setCoordinate(QGeoCoordinate(places5.at(i).location().coordinate().latitude(), 180.0));
+ places5[i].setLocation(location);
+ }
+ testSet5.insert(places5.at(i).location().coordinate().toString());
+ }
+
+ QSet<QString> inBoxSet5;
+ for (int i = 0; i < inBox5.size(); ++i) {
+ if (inBox5.at(i).longitude() == -180.0) {
+ inBox5[i].setLongitude(180.0);
+ }
+ inBoxSet5.insert(inBox5.at(i).toString());
+ }
+
+ QCOMPARE(testSet5, inBoxSet5);
+
+ //try a box that finds nothing
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(-70,-70), QGeoCoordinate(-80,-60)));
+ QVERIFY(doSearch(request, &places));
+ QCOMPARE(places.count(), 0);
+
+ //--- Test error conditions
+ //bottom right latitude > top left latitude
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(20,20), QGeoCoordinate(50,30)));
+ QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
+
+ //try an invalid coordinate for one of the corners
+ request.setSearchArea(new QGeoBoundingBox(QGeoCoordinate(qQNaN(),20),QGeoCoordinate(10,30)));
+ QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
+}
+
+void tst_QPlaceManagerJsonDb::searchByCircle()
+{
+ QList<QGeoCoordinate> greenwhichFilterCoords;
+ QList<QGeoCoordinate> datelineFilterCoords;
+ QList<QGeoCoordinate> northPoleFilterCoords;
+ QList<QGeoCoordinate> southPoleFilterCoords;
+ QList<QGeoCoordinate> northFilterCoords;
+ QList<QGeoCoordinate> eastFilterCoords;
+ QList<QGeoCoordinate> northeastFilterCoords;
+
+ QList<QGeoCoordinate> greenwhichLmCoords;
+ QList<QGeoCoordinate> datelineLmCoords;
+ QList<QGeoCoordinate> northPoleLmCoords;
+ QList<QGeoCoordinate> southPoleLmCoords;
+ QList<QGeoCoordinate> northLmCoords;
+ QList<QGeoCoordinate> eastLmCoords;
+ QList<QGeoCoordinate> northeastLmCoords;
+
+ greenwhichFilterCoords << QGeoCoordinate(-0.1, -0.1);
+ greenwhichFilterCoords << QGeoCoordinate(0.1, -0.1);
+ greenwhichFilterCoords << QGeoCoordinate(-0.1, 0.1);
+ greenwhichFilterCoords << QGeoCoordinate(0.1, 0.1);
+
+ datelineFilterCoords << QGeoCoordinate(-0.1, -179.9);
+ datelineFilterCoords << QGeoCoordinate(0.1, -179.9);
+ datelineFilterCoords << QGeoCoordinate(-0.1, 179.9);
+ datelineFilterCoords << QGeoCoordinate(0.1, 179.9);
+
+ northPoleFilterCoords << QGeoCoordinate(89.9, -179.9);
+ northPoleFilterCoords << QGeoCoordinate(89.9, -0.1);
+ northPoleFilterCoords << QGeoCoordinate(89.9, 0.1);
+ northPoleFilterCoords << QGeoCoordinate(89.9, 179.9);
+
+ southPoleFilterCoords << QGeoCoordinate(-89.9, -179.9);
+ southPoleFilterCoords << QGeoCoordinate(-89.9, -0.1);
+ southPoleFilterCoords << QGeoCoordinate(-89.9, 0.1);
+ southPoleFilterCoords << QGeoCoordinate(-89.9, 179.9);
+
+ eastFilterCoords << QGeoCoordinate(-0.1, 10.0);
+ eastFilterCoords << QGeoCoordinate(0.1, 10.0);
+ northFilterCoords << QGeoCoordinate(10.0, -0.1);
+ northFilterCoords << QGeoCoordinate(10.0, 0.1);
+ northeastFilterCoords << QGeoCoordinate(10.0, 10.0);
+
+ greenwhichLmCoords << QGeoCoordinate(-1.0, -1.0);
+ greenwhichLmCoords << QGeoCoordinate(1.0, -1.0);
+ greenwhichLmCoords << QGeoCoordinate(-1.0, 1.0);
+ greenwhichLmCoords << QGeoCoordinate(1.0, 1.0);
+
+ datelineLmCoords << QGeoCoordinate(-1.0, -179.0);
+ datelineLmCoords << QGeoCoordinate(1.0, -179.0);
+ datelineLmCoords << QGeoCoordinate(-1.0, 179.0);
+ datelineLmCoords << QGeoCoordinate(1.0, 179.0);
+
+ northPoleLmCoords << QGeoCoordinate(89.0, -179.0);
+ northPoleLmCoords << QGeoCoordinate(89.0, -1.0);
+ northPoleLmCoords << QGeoCoordinate(89.0, 1.0);
+ northPoleLmCoords << QGeoCoordinate(89.0, 179.0);
+
+ southPoleLmCoords << QGeoCoordinate(-89.0, -179.0);
+ southPoleLmCoords << QGeoCoordinate(-89.0, -1.0);
+ southPoleLmCoords << QGeoCoordinate(-89.0, 1.0);
+ southPoleLmCoords << QGeoCoordinate(-89.0, 179.0);
+
+ eastLmCoords << QGeoCoordinate(-1.0, 11.0);
+ eastLmCoords << QGeoCoordinate(1.0, 11.0);
+ northLmCoords << QGeoCoordinate(11.0, -1.0);
+ northLmCoords << QGeoCoordinate(11.0, 1.0);
+ northeastLmCoords << QGeoCoordinate(11.0, 11.0);
+
+ QList<QList<QGeoCoordinate> > coords;
+ coords << greenwhichLmCoords;
+ coords << datelineLmCoords;
+
+ coords << northPoleLmCoords;
+ coords << southPoleLmCoords;
+ coords << eastLmCoords;
+ coords << northLmCoords;
+ coords << northeastLmCoords;
+
+ for (int i = 0; i < coords.size(); ++i) {
+ QList<QGeoCoordinate> c = coords.at(i);
+ for (int j = 0; j < c.size(); ++j) {
+ QGeoPlace place;
+ QGeoLocation location;
+ location.setCoordinate(c.at(j));
+ place.setLocation(location);
+ doSavePlace(place);
+ }
+ }
+
+ QList<QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> > > testSets;
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(greenwhichFilterCoords, greenwhichLmCoords);
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(datelineFilterCoords, datelineLmCoords);
+
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(northPoleFilterCoords, northPoleLmCoords);
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(southPoleFilterCoords, southPoleLmCoords);
+
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(northFilterCoords, northLmCoords);
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(eastFilterCoords, eastLmCoords);
+ testSets << QPair<QList<QGeoCoordinate>, QList<QGeoCoordinate> >(northeastFilterCoords, northeastLmCoords);
+
+ qreal dist = QGeoCoordinate(0.0, 0.0).distanceTo(QGeoCoordinate(5.0, 5.0));
+
+ QList<QPlaceSearchResult> results;
+ QList<QGeoPlace> places;
+ for (int i = 0; i < testSets.size(); ++i) {
+ QList<QGeoCoordinate> filterCoords = testSets.at(i).first;
+ QList<QGeoCoordinate> plCoords = testSets.at(i).second;
+
+ QPlaceSearchRequest request;
+ for (int j = 0; j < filterCoords.size(); ++j) {
+ request.setSearchArea(new QGeoBoundingCircle(filterCoords.at(j),dist));
+
+ if (i ==2 || i ==3) {
+ //TODO: Testing poles, ignore fo rnow
+ continue;
+ } else {
+ doSearch(request, &results);
+ foreach (const QPlaceSearchResult &result, results)
+ places.append(result.place());
+ }
+
+ if (places.size() != plCoords.size()) {
+ for (int k = 0; k < places.size(); ++k)
+ qWarning() << "pl" << places.at(k).location().coordinate().toString(QGeoCoordinate::Degrees);
+ for (int k = 0; k < plCoords.size(); ++k)
+ qWarning() << "plCoords" << plCoords.at(k).toString(QGeoCoordinate::Degrees);
+ }
+
+ QCOMPARE(places.size(), plCoords.size());
+
+ for (int k = 0; k < places.size(); ++k) {
+ QVERIFY(plCoords.contains(places.at(k).location().coordinate()));
+ }
+ results.clear();
+ places.clear();
+ }
+ }
+
+
+ //--- Test error conditions and edge cases
+ //try a circle that covers the north pole
+ QPlaceSearchRequest request;
+ request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(89.91,0),11000));
+ QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
+ QCOMPARE(places.count(), 0);
+
+ //try a circle that's close to but does not cover the north pole
+ request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(89.91,0),9000));
+ QVERIFY(doSearch(request,&places, QPlaceReply::NoError));
+
+ //try a circle that covers the south pole
+ request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-89.91,180),11000));
+ QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
+ QCOMPARE(places.count(), 0);
+
+ //try a circle that's close to but does not cover the south pole
+ request.setSearchArea(new QGeoBoundingCircle(QGeoCoordinate(-89.91,180),9000));
+ QVERIFY(doSearch(request, &places, QPlaceReply::NoError));
+}
+
+void tst_QPlaceManagerJsonDb::unsupportedFunctions()
+{
+ QGeoPlace place;
+ place.setPlaceId("id");
+ QPlaceContentRequest request;
+ request.setContentType(QPlaceContent::ImageType);
+ request.setLimit(5);
+ request.setOffset(0);
+ QPlaceContentReply *contentReply = placeManager->getContent(place, request);
+ QSignalSpy contentSpy(contentReply, SIGNAL(finished()));
+ QTRY_VERIFY(contentSpy.count() == 1);
+ QCOMPARE(contentReply->error(), QPlaceReply::UnsupportedError);
+
+ QPlaceSearchRequest searchRequest;
+ QPlaceTextPredictionReply *textPredictionReply = placeManager->textPredictions(searchRequest);
+ QSignalSpy textPredictionSpy(textPredictionReply, SIGNAL(finished()));
+ QTRY_VERIFY(textPredictionSpy.count() == 1 );
+ QCOMPARE(textPredictionReply->error(), QPlaceReply::UnsupportedError);
+}
+
+
+void tst_QPlaceManagerJsonDb::cleanup()
+{
+ QSignalSpy cleanSpy(dbCleaner, SIGNAL(dbCleaned()));
+ dbCleaner->cleanDb();
+ QTRY_VERIFY(cleanSpy.count() == 1);
+}
+
+bool tst_QPlaceManagerJsonDb::doSavePlace(const QGeoPlace &place,
+ QPlaceReply::Error expectedError,
+ QString *placeId,
+ QPlaceManager::VisibilityScope scope)
+{
+ QPlaceSaveReply *saveReply = placeManager->savePlace(place,scope);
+ bool isSuccessful = false;
+ isSuccessful = checkSignals(saveReply, expectedError);
+ if (placeId != 0)
+ *placeId = saveReply->placeId();
+ return isSuccessful;
+}
+
+void tst_QPlaceManagerJsonDb::doSavePlaces(QList<QGeoPlace> &places)
+{
+ QPlaceSaveReply *saveReply;
+
+ foreach (QGeoPlace place, places) {
+ saveReply = placeManager->savePlace(place);
+ QSignalSpy saveSpy(saveReply, SIGNAL(finished()));
+ QTRY_VERIFY(saveSpy.count() == 1);
+ QCOMPARE(saveReply->error(), QPlaceReply::NoError);
+ saveSpy.clear();
+ }
+}
+
+bool tst_QPlaceManagerJsonDb::doSearch(const QPlaceSearchRequest &request,
+ QList<QPlaceSearchResult> *results, QPlaceReply::Error expectedError)
+{
+ QPlaceSearchReply *searchReply= placeManager->searchForPlaces(request);
+ bool success = checkSignals(searchReply, expectedError);
+ *results = searchReply->results();
+ return success;
+}
+
+bool tst_QPlaceManagerJsonDb::doSearch(const QPlaceSearchRequest &request,
+ QList<QGeoPlace> *results, QPlaceReply::Error expectedError)
+{
+ bool success = false;
+ results->clear();
+ QList<QPlaceSearchResult> searchResults;
+ success = doSearch(request, &searchResults, expectedError);
+ foreach (const QPlaceSearchResult &searchResult, searchResults)
+ results->append(searchResult.place());
+ return success;
+}
+
+bool tst_QPlaceManagerJsonDb::doFetchDetails(QString placeId, QGeoPlace *place, QPlaceReply::Error expectedError)
+{
+ QPlaceDetailsReply *detailsReply = placeManager->getPlaceDetails(placeId);
+ bool success = checkSignals(detailsReply, expectedError);
+ *place = detailsReply->result();
+ return success;
+}
+
+bool tst_QPlaceManagerJsonDb::checkSignals(QPlaceReply *reply, QPlaceReply::Error expectedError)
+{
+ QSignalSpy finishedSpy(reply, SIGNAL(finished()));
+ QSignalSpy errorSpy(reply, SIGNAL(error(QPlaceReply::Error,QString)));
+ QSignalSpy managerFinishedSpy(placeManager, SIGNAL(finished(QPlaceReply*)));
+ QSignalSpy managerErrorSpy(placeManager,SIGNAL(error(QPlaceReply*,QPlaceReply::Error,QString)));
+
+ if (expectedError != QPlaceReply::NoError) {
+ //check that we get an error signal from the reply
+ WAIT_UNTIL(errorSpy.count() == 1);
+ if (errorSpy.count() != 1) {
+ qWarning() << "Error signal for search operation not received";
+ return false;
+ }
+
+ //check that we get the correct error from the reply's signal
+ QPlaceReply::Error actualError = qvariant_cast<QPlaceReply::Error>(errorSpy.at(0).at(0));
+ if (actualError != expectedError) {
+ qWarning() << "Actual error code in reply signal does not match expected error code";
+ qWarning() << "Actual error code = " << actualError;
+ qWarning() << "Expected error coe =" << expectedError;
+ return false;
+ }
+
+ //check that we get an error signal from the manager
+ WAIT_UNTIL(managerErrorSpy.count() == 1);
+ if (managerErrorSpy.count() !=1) {
+ qWarning() << "Error signal from manager for search operation not received";
+ return false;
+ }
+
+ //check that we get the correct reply instance in the error signal from the manager
+ if (qvariant_cast<QPlaceReply*>(managerErrorSpy.at(0).at(0)) != reply) {
+ qWarning() << "Reply instance in error signal from manager is incorrect";
+ return false;
+ }
+
+ //check that we get the correct error from the signal of the manager
+ actualError = qvariant_cast<QPlaceReply::Error>(managerErrorSpy.at(0).at(1));
+ if (actualError != expectedError) {
+ qWarning() << "Actual error code from manager signal does not match expected error code";
+ qWarning() << "Actual error code =" << actualError;
+ qWarning() << "Expected error code = " << expectedError;
+ return false;
+ }
+ }
+
+ //check that we get a finished signal
+ WAIT_UNTIL(finishedSpy.count() == 1);
+ if (finishedSpy.count() !=1) {
+ qWarning() << "Finished signal from reply not received";
+ return false;
+ }
+
+ if (reply->error() != expectedError) {
+ qWarning() << "Actual error code does not match expected error code";
+ qWarning() << "Actual error code: " << reply->error();
+ qWarning() << "Expected error code" << expectedError;
+ return false;
+ }
+
+ if (expectedError == QPlaceReply::NoError && !reply->errorString().isEmpty()) {
+ qWarning() << "Expected error was no error but error string was not empty";
+ qWarning() << "Error string=" << reply->errorString();
+ return false;
+ }
+
+ //check that we get the finished signal from the manager
+ WAIT_UNTIL(managerFinishedSpy.count() == 1);
+ if (managerFinishedSpy.count() != 1) {
+ qWarning() << "Finished signal from manager not received";
+ return false;
+ }
+
+ //check that the reply instance in the finished signal from the manager is correct
+ if (qvariant_cast<QPlaceReply *>(managerFinishedSpy.at(0).at(0)) != reply) {
+ qWarning() << "Reply instance in finished signal from manager is incorrect";
+ return false;
+ }
+
+ return true;
+}
+
+bool tst_QPlaceManagerJsonDb::compareResults(const QList<QPlaceSearchResult> &results,
+ const QList<QGeoPlace> &expectedResults)
+{
+ QSet<QString> actualPlaceCoords;
+ foreach (const QPlaceSearchResult &result, results)
+ actualPlaceCoords.insert(result.place().location().coordinate().toString());
+ QSet<QString> expectedPlaceCoords;
+ foreach (const QGeoPlace &place, expectedResults) {
+ expectedPlaceCoords.insert(place.location().coordinate().toString());
+ }
+ return actualPlaceCoords == expectedPlaceCoords;
+}
+
+QTEST_APPLESS_MAIN(tst_QPlaceManagerJsonDb)
+
+#include "tst_qplacemanager_jsondb.moc"