summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2013-06-17 11:35:17 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-19 15:55:55 +0200
commit89aa80147be9aa6d997dcb1cbd94bdb6281c58bb (patch)
tree78c52c4e40e2ec2be4c243a75cba82a2c3567ad7
parent665a9e267b946b96dc1a685445823bb2d6422383 (diff)
Remove JsonDB specific tests and plug-ins
Task-number: QTBUG-31741 JsonDB is basically dead. Until quite recently it didn't even build. There is no platform which can use those code lines. Change-Id: I071eb8b78165dcb07d4432af1f49f800cee595dc Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/plugins/geoservices/geoservices.pro2
-rw-r--r--src/plugins/geoservices/places_jsondb/10-placesIndices.json21
-rw-r--r--src/plugins/geoservices/places_jsondb/detailsreply.cpp106
-rw-r--r--src/plugins/geoservices/places_jsondb/detailsreply.h81
-rw-r--r--src/plugins/geoservices/places_jsondb/icon.cpp258
-rw-r--r--src/plugins/geoservices/places_jsondb/icon.h138
-rw-r--r--src/plugins/geoservices/places_jsondb/iconhandler.cpp289
-rw-r--r--src/plugins/geoservices/places_jsondb/iconhandler.h98
-rw-r--r--src/plugins/geoservices/places_jsondb/idreply.cpp500
-rw-r--r--src/plugins/geoservices/places_jsondb/idreply.h186
-rw-r--r--src/plugins/geoservices/places_jsondb/initreply.cpp78
-rw-r--r--src/plugins/geoservices/places_jsondb/initreply.h82
-rw-r--r--src/plugins/geoservices/places_jsondb/jsondb.cpp906
-rw-r--r--src/plugins/geoservices/places_jsondb/jsondb.h189
-rw-r--r--src/plugins/geoservices/places_jsondb/macro.h58
-rw-r--r--src/plugins/geoservices/places_jsondb/matchreply.cpp192
-rw-r--r--src/plugins/geoservices/places_jsondb/matchreply.h81
-rw-r--r--src/plugins/geoservices/places_jsondb/places_jsondb.pro40
-rw-r--r--src/plugins/geoservices/places_jsondb/places_jsondb_plugin.json14
-rw-r--r--src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.cpp94
-rw-r--r--src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.h78
-rw-r--r--src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.cpp473
-rw-r--r--src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.h156
-rw-r--r--src/plugins/geoservices/places_jsondb/searchreply.cpp238
-rw-r--r--src/plugins/geoservices/places_jsondb/searchreply.h92
-rw-r--r--src/plugins/geoservices/places_jsondb/traverser.cpp159
-rw-r--r--src/plugins/geoservices/places_jsondb/traverser.h89
-rw-r--r--src/plugins/geoservices/places_jsondb/unsupportedreplies.h86
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbutils.cpp414
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbutils.h184
-rw-r--r--tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro21
-rw-r--r--tests/auto/qplacemanager_jsondb/resources.qrc12
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_24x24.pngbin663 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_40x40.pngbin1834 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_fullscreen.pngbin9779 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_large.pngbin389 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_medium.pngbin264 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_small.pngbin208 -> 0 bytes
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/icon_small.svg80
-rw-r--r--tests/auto/qplacemanager_jsondb/resources/offline-mapping.json131
-rw-r--r--tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp3404
42 files changed, 0 insertions, 9032 deletions
diff --git a/src/plugins/geoservices/geoservices.pro b/src/plugins/geoservices/geoservices.pro
index 9bb86b64..63c6d792 100644
--- a/src/plugins/geoservices/geoservices.pro
+++ b/src/plugins/geoservices/geoservices.pro
@@ -1,5 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = nokia osm
-
-qtHaveModule(jsondb): SUBDIRS += places_jsondb
diff --git a/src/plugins/geoservices/places_jsondb/10-placesIndices.json b/src/plugins/geoservices/places_jsondb/10-placesIndices.json
deleted file mode 100644
index f14b0711..00000000
--- a/src/plugins/geoservices/places_jsondb/10-placesIndices.json
+++ /dev/null
@@ -1,21 +0,0 @@
-[{
-"_type": "Index",
-"name": "placeDisplayNameIndex",
-"objectType": "com.nokia.mt.location.Place",
-"propertyName": "displayName",
-"propertyType": "string"
-},
-{
-"_type": "Index",
-"name": "placeLatitudeIndex",
-"objectType": "com.nokia.mt.location.Place",
-"propertyName": "location.geo.latitude",
-"propertyType": "number"
-},
-{
-"_type": "Index",
-"name": "placeLongitudeIndex",
-"objectType": "com.nokia.mt.location.Place",
-"propertyName": "location.geo.longitude",
-"propertyType": "number"
-}] \ No newline at end of file
diff --git a/src/plugins/geoservices/places_jsondb/detailsreply.cpp b/src/plugins/geoservices/places_jsondb/detailsreply.cpp
deleted file mode 100644
index 5497c0ea..00000000
--- a/src/plugins/geoservices/places_jsondb/detailsreply.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "detailsreply.h"
-#include "qplacemanagerengine_jsondb.h"
-
-DetailsReply::DetailsReply(QPlaceManagerEngineJsonDb *engine)
- : QPlaceDetailsReply(engine), m_engine(engine)
-{
-}
-
-DetailsReply::~DetailsReply()
-{
-}
-
-void DetailsReply::setPlaceId(const QString &placeId)
-{
- m_placeId = placeId;
-}
-
-void DetailsReply::start()
-{
- db()->getPlace(m_placeId, this, SLOT(getPlaceFinished()));
-}
-
-void DetailsReply::getPlaceFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::PlaceDoesNotExistError,
- QStringLiteral("Specified place does not exist"));
- return;
-
- } else {
- QJsonObject placeJson = results.takeFirst();
- setPlace(JsonDb::convertJsonObjectToPlace(placeJson, m_engine));
-
- QStringList categoryUuids = placeJson.value(JsonDb::CategoryUuids).toVariant().toStringList();
- if (!categoryUuids.isEmpty())
- db()->getCategories(categoryUuids, this, SLOT(getCategoriesForPlaceFinished()));
- else //don't need to retrieve categores so return the details
- triggerDone();
- }
-}
-
-void DetailsReply::getCategoriesForPlaceFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- QPlace p = place();
- p.setCategories(JsonDb::convertJsonObjectsToCategories(results, m_engine));
- setPlace(p);
- triggerDone();
-}
-
-void DetailsReply::requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- QString errorString = QString::fromLatin1("Unknown error during details fetch operation: jsondb error code =%1, erroString=%2").
- arg(dbCode).arg(dbErrorString);
- triggerDone(QPlaceReply::UnknownError, errorString);
-}
-
-
diff --git a/src/plugins/geoservices/places_jsondb/detailsreply.h b/src/plugins/geoservices/places_jsondb/detailsreply.h
deleted file mode 100644
index fdacd99d..00000000
--- a/src/plugins/geoservices/places_jsondb/detailsreply.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef DETAILSREPLY_H
-#define DETAILSREPLY_H
-
-#include "macro.h"
-
-#include <qplacedetailsreply.h>
-#include <qplacemanagerengine_jsondb.h>
-
-#include <QtJsonDb/QJsonDbRequest>
-
-QT_BEGIN_NAMESPACE
-
-class DetailsReply : public QPlaceDetailsReply
-{
- Q_OBJECT
-public:
- DetailsReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~DetailsReply();
-
- DECLARE_TRIGGER_DONE_FN
-
- void setPlaceId(const QString &placeId);
-
- void start();
-
-protected:
- JsonDb *db() { return m_engine->db(); }
-
-private slots:
- void getPlaceFinished();
- void getCategoriesForPlaceFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString);
-
-private:
- QPlaceManagerEngineJsonDb *m_engine;
- QString m_placeId;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/icon.cpp b/src/plugins/geoservices/places_jsondb/icon.cpp
deleted file mode 100644
index 333cd944..00000000
--- a/src/plugins/geoservices/places_jsondb/icon.cpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "icon.h"
-#include "iconhandler.h"
-
-#include <QtCore/QBuffer>
-#include <QtCore/QFile>
-#include <QtCore/QDebug>
-#include <QtGui/QImageReader>
-#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkReply>
-
-const QSize JsonDbIcon::SmallSize(QSize(20,20));
-const QSize JsonDbIcon::MediumSize(QSize(30,30));
-const QSize JsonDbIcon::LargeSize(QSize(50,50));
-const QSize JsonDbIcon::FullscreenSize(QSize(320,480));
-
-const QLatin1String JsonDbIcon::SmallSource("smallSourceUrl");
-const QLatin1String JsonDbIcon::MediumSource("mediumSourceUrl");
-const QLatin1String JsonDbIcon::LargeSource("largeSourceUrl");
-const QLatin1String JsonDbIcon::FullscreenSource("fullscreenSourceUrl");
-
-const QLatin1String JsonDbIcon::SmallDestination("smallUrl");
-const QLatin1String JsonDbIcon::MediumDestination("mediumUrl");
-const QLatin1String JsonDbIcon::LargeDestination("largeUrl");
-const QLatin1String JsonDbIcon::FullscreenDestination("fullscreenUrl");
-
-const QLatin1String JsonDbIcon::SmallDestinationSize("smallSize");
-const QLatin1String JsonDbIcon::MediumDestinationSize("mediumSize");
-const QLatin1String JsonDbIcon::LargeDestinationSize("largeSize");
-const QLatin1String JsonDbIcon::FullscreenDestinationSize("fullscreenSize");
-
-const QLatin1String JsonDbIcon::NokiaIcon("nokiaIcon");
-const QLatin1String JsonDbIcon::NokiaIconGenerated("nokiaIconGenerated");
-
-const QLatin1String JsonDbIcon::DefaultIcon("/icons/categories/06.icon");
-
-JsonDbIcon::JsonDbIcon(IconHandler *parent)
- : QObject(parent), m_iconHandler(parent), m_error(QPlaceReply::NoError)
-{
- Q_ASSERT(parent);
-}
-
-JsonDbIcon::~JsonDbIcon()
-{
-}
-
-//initialization in the case of having a source icon url involves fetching the icon
-//data and determining its size
-//initialization in the case of having a destination icon url only involves _attempting_
-//to fetch it in order to calculate its size. If this cannot be done, the
-//user specified size is used.
-void JsonDbIcon::initialize()
-{
- QNetworkAccessManager *netManager = m_iconHandler->networkAccessManager();
- QNetworkRequest request;
-
- if (m_sourceUrl.isEmpty() && !m_destinationUrl.isEmpty())
- request.setUrl(m_destinationUrl);
- else
- request.setUrl(m_sourceUrl);
- QNetworkReply *reply = netManager->get(request);
- connect(reply, SIGNAL(finished()), this, SLOT(iconFetchFinished()));
-}
-
-bool JsonDbIcon::copy() const
-{
- QFile file(m_destinationUrl.toLocalFile());
- if (!file.open(QIODevice::WriteOnly)) {
- if (file.error() == QFile::PermissionsError) {
- m_error = QPlaceReply::PermissionsError;
- m_errorString = QString::fromLatin1("Insufficient permissions to write icon to ") + m_destinationUrl.toLocalFile();
- } else {
- m_error = QPlaceReply::UnknownError;
- m_errorString = QString::fromLatin1("Could not write icon to ") + m_destinationUrl.toLocalFile();
- }
- return false;
- }
-
- if (file.write(m_payload) == -1) {
- m_error = QPlaceReply::UnknownError;
- m_errorString = QString::fromLatin1("Unable to save to icon to ") + m_destinationUrl.toLocalFile();
-
- return false;
- }
-
- return true;
-}
-
-QSize JsonDbIcon::size() const
-{
- return m_size;
-}
-
-QSize JsonDbIcon::specifiedSize() const
-{
- return m_specifiedSize;
-}
-
-void JsonDbIcon::setSpecifiedSize(const QSize &size)
-{
- m_specifiedSize = size;
-}
-
-QUrl JsonDbIcon::sourceUrl() const
-{
- return m_sourceUrl;
-}
-
-void JsonDbIcon::setSourceUrl(const QUrl &url)
-{
- m_sourceUrl = url;
-}
-
-QUrl JsonDbIcon::destinationUrl() const
-{
- return m_destinationUrl;
-}
-
-void JsonDbIcon::setDestinationUrl(const QUrl &url)
-{
- m_destinationUrl = url;
-}
-
-void JsonDbIcon::setDestinationDataUrl()
-{
- QString mimeType = imageFormatToMimeType(m_inputFormat);
- m_destinationUrl = QUrl(QString::fromLatin1("data:") + mimeType + QLatin1String(";base64,") + m_payload.toBase64());
-}
-
-QString JsonDbIcon::destination() const
-{
- return m_destination;
-}
-
-void JsonDbIcon::setDestination(const QString &destination)
-{
- m_destination = destination;
-}
-
-QPlaceReply::Error JsonDbIcon::error() const
-{
- return m_error;
-}
-
-QString JsonDbIcon::errorString() const
-{
- return m_errorString;
-}
-
-void JsonDbIcon::iconFetchFinished()
-{
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
-
- if (reply->error() == QNetworkReply::NoError) {
- m_payload = reply->readAll();
- m_size = QImage::fromData(m_payload).size();
- QBuffer buffer(&m_payload);
- buffer.open(QIODevice::ReadOnly);
- m_inputFormat = QImageReader::imageFormat(&buffer);
-
- if (m_inputFormat.isEmpty() && !m_sourceUrl.isEmpty()) {
- m_error = QPlaceReply::UnsupportedError;
- m_errorString = QString::fromLatin1("Format of source icon file could not be determined, url:") + m_sourceUrl.toString();
- }
- } else {
- m_error = QPlaceReply::CommunicationError;
- m_errorString = reply->errorString();
- }
-
- //we've tried to retrieve the destination url to try automatically calculate its size
- // this was not possible so set the size to the user specified size.
- if (m_sourceUrl.isEmpty() && !m_destinationUrl.isEmpty()) {
- if (m_specifiedSize == QSize() && m_size == QSize()) {
- m_error = QPlaceReply::BadArgumentError;
- m_errorString = QLatin1String("Cannot obtain size of destination icon url");
- } else {
- if (m_size.isEmpty())
- m_size = m_specifiedSize;
- m_error = QPlaceReply::NoError; //reset error back to empty because the inability
- m_errorString = QString(); //to access the destination url is not an error.
- }
- }
-
- reply->deleteLater();
- reply = 0;
-
- emit initializationFinished();
-}
-
-QString JsonDbIcon::imageFormatToMimeType(const QByteArray &format)
-{
- if (format == "bmp")
- return QLatin1String("image/bmp");
- else if (format == "gif")
- return QLatin1String("image/gif");
- else if (format == "jpg" || format == "jpeg")
- return QLatin1String("image/jpeg");
- else if (format == "mng")
- return QLatin1String("video/x-mng");
- else if (format == "png")
- return QLatin1String("image/png");
- else if (format == "pbm")
- return QLatin1String("image/x-portable-bitmap");
- else if (format == "pgm")
- return QLatin1String("image/x-portable-graymap");
- else if (format == "ppm")
- return QLatin1String("image/x-portable-pixmap");
- else if (format == "tiff")
- return QLatin1String("image/tiff");
- else if (format == "xbm")
- return QLatin1String("image/x-xbitmap");
- else if (format == "xpm")
- return QLatin1String("image/x-xpixmap");
- else if (format == "svg")
- return QLatin1String("image/svg+xml");
- else
- return QString();
-}
diff --git a/src/plugins/geoservices/places_jsondb/icon.h b/src/plugins/geoservices/places_jsondb/icon.h
deleted file mode 100644
index 25f9236a..00000000
--- a/src/plugins/geoservices/places_jsondb/icon.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ICON_H
-#define ICON_H
-
-#include <QtCore/QString>
-#include <QtCore/QUrl>
-#include <QtGui/QImage>
-#include <QtLocation/QPlaceReply>
-
-QT_BEGIN_NAMESPACE
-
-class IconHandler;
-
-class JsonDbIcon : public QObject
-{
- Q_OBJECT
-public:
-
- enum ErrorCode {
- NoError,
- Error
- };
-
- static const QSize SmallSize;
- static const QSize MediumSize;
- static const QSize LargeSize;
- static const QSize FullscreenSize;
-
- static const QLatin1String SmallSource;
- static const QLatin1String MediumSource;
- static const QLatin1String LargeSource;
- static const QLatin1String FullscreenSource;
-
- static const QLatin1String SmallDestination;
- static const QLatin1String MediumDestination;
- static const QLatin1String LargeDestination;
- static const QLatin1String FullscreenDestination;
-
- static const QLatin1String SmallDestinationSize;
- static const QLatin1String MediumDestinationSize;
- static const QLatin1String LargeDestinationSize;
- static const QLatin1String FullscreenDestinationSize;
-
- static const QLatin1String NokiaIcon;
- static const QLatin1String NokiaIconGenerated;
-
- static const QLatin1String DefaultIcon;
-
- JsonDbIcon(IconHandler *parent);
- ~JsonDbIcon();
-
- void initialize();
-
- bool copy() const;
-
- QSize size() const;
-
- QSize specifiedSize() const;
- void setSpecifiedSize(const QSize &size);
-
- QUrl sourceUrl() const;
- void setSourceUrl(const QUrl &url);
-
- QUrl destinationUrl() const;
- void setDestinationUrl(const QUrl &url);
- void setDestinationDataUrl();
-
- QString destination() const;
- void setDestination(const QString &destination);
-
- QPlaceReply::Error error() const;
- QString errorString() const;
-
-Q_SIGNALS:
- void initializationFinished();
-
-private slots:
- void iconFetchFinished();
-
-private:
- static QString imageFormatToMimeType(const QByteArray &format);
-
- QByteArray m_inputFormat;
- QUrl m_sourceUrl;
- QUrl m_destinationUrl;
- QString m_destination;
- QSize m_specifiedSize;
- QSize m_size;
- QByteArray m_payload;
- IconHandler *m_iconHandler;
-
- mutable QPlaceReply::Error m_error;
- mutable QString m_errorString;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/iconhandler.cpp b/src/plugins/geoservices/places_jsondb/iconhandler.cpp
deleted file mode 100644
index 8db5abee..00000000
--- a/src/plugins/geoservices/places_jsondb/iconhandler.cpp
+++ /dev/null
@@ -1,289 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "iconhandler.h"
-#include "idreply.h"
-
-#include <QtCore/QFile>
-#include <QtCore/QUrl>
-#include <QtCore/QVariantMap>
-
-IconHandler::IconHandler(const QPlaceIcon &inputIcon, const QJsonObject &thumbnailsJson,
- IdReply *parent)
- : QObject(parent), m_inputIcon(inputIcon), m_thumbnailsJson(thumbnailsJson),
- m_error(QPlaceReply::NoError), m_currIconIndex(0), m_reply(parent)
-{
- QStringList prefixes;
- prefixes << QStringLiteral("small") << QStringLiteral("medium") << QStringLiteral("large") << QStringLiteral("fullscreen");
-
- QList<QUrl> uniqueInputUrls; //unique source urls that have been supplied without associated destinations
- foreach (const QString &prefix, prefixes) {
- bool ok;
- QUrl sourceUrl = convertToUrl(m_inputIcon.parameters().value(prefix + QLatin1String("SourceUrl"), QUrl()), &ok);
- if (!ok) {
- triggerDone(QPlaceReply::BadArgumentError, QString::fromLatin1("icon parameter for key: ") + prefix + QLatin1String("SourceUrl")
- + QLatin1String(" was not a QUrl object"));
- return;
- }
- QUrl destinationUrl = convertToUrl(m_inputIcon.parameters().value(prefix + QLatin1String("Url"), QUrl()), &ok);
- if (!ok) {
- triggerDone(QPlaceReply::BadArgumentError, QString::fromLatin1("icon parameter for key: ") + prefix + QLatin1String("Url")
- + QLatin1String(" was not a QUrl object"));
- return;
- }
-
- if (destinationUrl.isEmpty()) {
- if (sourceUrl.isEmpty() || uniqueInputUrls.contains(sourceUrl))
- continue;
- else
- uniqueInputUrls.append(sourceUrl);
- }
-
- QString destination;
- if (!destinationUrl.isEmpty())
- destination = prefix + QLatin1String("Url");
-
- JsonDbIcon *icon = new JsonDbIcon(this);
- icon->setSourceUrl(sourceUrl);
- icon->setDestinationUrl(destinationUrl);
- icon->setDestination(destination);
- if (m_inputIcon.parameters().contains(prefix + QLatin1String("Size")))
- icon->setSpecifiedSize(m_inputIcon.parameters().value(prefix + QLatin1String("Size")).toSize());
-
- m_icons.append(icon);
- }
-
- processIcons();
-}
-
-IconHandler::~IconHandler()
-{
- qDeleteAll(m_icons);
-}
-
-QString IconHandler::errorString() const
-{
- return m_errorString;
-}
-
-QPlaceReply::Error IconHandler::error() const
-{
- return m_error;
-}
-
-QNetworkAccessManager *IconHandler::networkAccessManager()
-{
- return m_reply->engine()->networkAccessManager();
-}
-
-void IconHandler::processIcons()
-{
- if (JsonDbIcon *senderIcon = qobject_cast<JsonDbIcon *>(sender())) {
- if (senderIcon->error() != QPlaceReply::NoError) {
- triggerDone(senderIcon->error(), senderIcon->errorString());
- return;
- }
- }
-
- if (m_currIconIndex < m_icons.count()) {
- JsonDbIcon *icon = m_icons.at(m_currIconIndex);
- connect(icon, SIGNAL(initializationFinished()), this, SLOT(processIcons()), Qt::QueuedConnection);
- icon->initialize();
- m_currIconIndex++;
- return;
- } else {
- bool error = false;
-
- //try to set destinations for icons which were not already set
- QStringList specifiedDestinations;
- foreach (JsonDbIcon *icon, m_icons) {
- if (!icon->destination().isEmpty())
- specifiedDestinations.append(icon->destination());
- }
-
- //try to set small,medium and large destinations if they haven't already been explicitly specified
- //and there are icons with unspecified destinations. (essentially we are creating data urls if necessary)
- if (!specifiedDestinations.contains(JsonDbIcon::SmallDestination))
- trySetDestination(JsonDbIcon::SmallDestination);
-
- if (!specifiedDestinations.contains(JsonDbIcon::MediumDestination))
- trySetDestination(JsonDbIcon::MediumDestination);
-
- if (!specifiedDestinations.contains(JsonDbIcon::LargeDestination))
- trySetDestination(JsonDbIcon::LargeDestination);
-
- //Note that we don't try and set the destination for full screen thumbnails
- //since data urls are meant to be just for small images
-
- //if we have an existing place, we try to preserve existing properties
- //of the thumbnail objects, but we completely remove/replace the fields
- //that are relevant for the QtLocation API.
- m_thumbnailsJson.remove(JsonDb::Small);
- m_thumbnailsJson.remove(JsonDb::Medium);
- m_thumbnailsJson.remove(JsonDb::Large);
- m_thumbnailsJson.remove(JsonDb::Fullscreen);
- m_thumbnailsJson.remove(JsonDb::NokiaIcon);
-
- foreach (JsonDbIcon *icon, m_icons) {
- QJsonObject thumbnailJson;
- if (icon->error() != QPlaceReply::NoError) {
- triggerDone(icon->error(), icon->errorString());
- error = true;
- break;
- }
-
- if (!icon->sourceUrl().isEmpty()
- && icon->destinationUrl().scheme().compare(QLatin1String("file")) == 0) {
- if (!icon->copy()) {
- triggerDone(icon->error(), icon->errorString());
- error = true;
- break;
- }
- }
-
- thumbnailJson.insert(JsonDb::Url, icon->destinationUrl().toString());
- if (icon->size().isValid()) {
- thumbnailJson.insert(JsonDb::Height, icon->size().height());
- thumbnailJson.insert(JsonDb::Width, icon->size().width());
- } else {
- //size of icon could not be calculated, therefore rely on manually specified size
- if (!icon->specifiedSize().isValid()) {
- triggerDone(QPlaceReply::BadArgumentError, QLatin1String("Size of icon could not be generated nor was it validly specified"));
- error = true;
- break;
- }
- thumbnailJson.insert(JsonDb::Height, icon->specifiedSize().height());
- thumbnailJson.insert(JsonDb::Width, icon->specifiedSize().width());
- }
-
- if (icon->destination() == JsonDbIcon::SmallDestination)
- m_thumbnailsJson.insert(JsonDb::Small, thumbnailJson);
- else if (icon->destination() == JsonDbIcon::MediumDestination)
- m_thumbnailsJson.insert(JsonDb::Medium, thumbnailJson);
- else if (icon->destination() == JsonDbIcon::LargeDestination)
- m_thumbnailsJson.insert(JsonDb::Large, thumbnailJson);
- else
- m_thumbnailsJson.insert(JsonDb::Fullscreen, thumbnailJson);
- }
-
- QString nokiaIcon = m_inputIcon.parameters().value(JsonDbIcon::NokiaIcon).toString();
- bool nokiaIconGenerated = m_inputIcon.parameters()
- .value(JsonDbIcon::NokiaIconGenerated).toBool();
- if (!nokiaIcon.isEmpty() && !nokiaIconGenerated) {
- QString localIconPath = m_reply->engine()->localDataPath() + nokiaIcon;
- if (QFile::exists(localIconPath))
- m_thumbnailsJson.insert(JsonDb::NokiaIcon, nokiaIcon);
- }
-
- if (!error) {
- QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection,
- Q_ARG(QJsonObject,m_thumbnailsJson));
- }
-
- qDeleteAll(m_icons);
- m_icons.clear();
- }
-}
-
-void IconHandler::trySetDestination(const QString &destination)
-{
- static int threshold;
- int height;
-
- //assumption is that icons are squarish
- //so we can rely on height as a means to detect which size bucket
- //the icon belongs to
- if (destination == JsonDbIcon::SmallDestination) {
- threshold = (JsonDbIcon::SmallSize.height() + JsonDbIcon::MediumSize.height()) / 2;
- height = JsonDbIcon::SmallSize.height();
- } else if (destination == JsonDbIcon::MediumDestination) {
- threshold = (JsonDbIcon::MediumSize.height() + JsonDbIcon::LargeSize.height()) / 2;
- height = JsonDbIcon::MediumSize.height();
- } else if (destination == JsonDbIcon::LargeDestination) {
- threshold = JsonDbIcon::LargeSize.height() * 2;
- height = JsonDbIcon::LargeSize.height();
- } //note fullscreen thumbnails should not be set as data urls.
-
- JsonDbIcon *currIcon = 0;
- foreach (JsonDbIcon *icon, m_icons) {
- if (icon->destination().isEmpty()
- && icon->size().height() < threshold
- && (currIcon == 0 || qAbs(icon->size().height() - height) < qAbs(currIcon->size().height() - height))) {
- if (currIcon)
- currIcon->setDestination(QString());
- currIcon = icon;
- currIcon->setDestination(destination);
- }
- }
-
- if (currIcon)
- currIcon->setDestinationDataUrl();
-}
-
-void IconHandler::triggerDone(const QPlaceReply::Error error, const QString &errorString)
-{
- m_error = error;
- m_errorString = errorString;
- QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection,
- Q_ARG(QJsonObject,m_thumbnailsJson));
-}
-
-QUrl IconHandler::convertToUrl(const QVariant &var, bool *ok)
-{
- if (ok)
- *ok = false;
-
- switch (var.type()) {
- case (QVariant::Url): {
- if (ok)
- *ok = true;
- QUrl url = var.toUrl();
- if (url.scheme().isEmpty())
- return QUrl::fromUserInput(url.toString());
- else
- return url;
- break;
- }
- default:
- break;
- }
- return QUrl();
-}
diff --git a/src/plugins/geoservices/places_jsondb/iconhandler.h b/src/plugins/geoservices/places_jsondb/iconhandler.h
deleted file mode 100644
index 6e84faeb..00000000
--- a/src/plugins/geoservices/places_jsondb/iconhandler.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef ICONHANDLER_H
-#define ICONHANDLER_H
-
-#include "icon.h"
-#include "jsondb.h"
-
-#include <QtCore/QObject>
-#include <QtCore/QJsonObject>
-#include <QtCore/QVariant>
-#include <QtLocation/QPlaceIcon>
-#include <QtLocation/QPlaceReply>
-
-QT_BEGIN_NAMESPACE
-
-class IdReply;
-class QNetworkAccessManager;
-
-class IconHandler : public QObject
-{
- Q_OBJECT
-public:
- IconHandler(const QPlaceIcon &icon, const QJsonObject &thumbnailsJson,
- IdReply *parent);
- ~IconHandler();
-
- QPlaceReply::Error error() const;
- QString errorString() const;
-
- QNetworkAccessManager *networkAccessManager();
-
-signals:
- void finished(QJsonObject thumbnailsJson);
-
-private slots:
- void processIcons();
- void trySetDestination(const QString &destination);
-
-private:
- void triggerDone(const QPlaceReply::Error error, const QString &errorString);
- QUrl convertToUrl(const QVariant &var, bool *ok);
-
- QPlaceIcon m_inputIcon;
- QJsonObject m_thumbnailsJson;
-
- QPlaceReply::Error m_error;
- QString m_errorString;
-
- QList<JsonDbIcon *> m_icons;
- int m_currIconIndex;
-
- IdReply *m_reply;
-};
-
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/idreply.cpp b/src/plugins/geoservices/places_jsondb/idreply.cpp
deleted file mode 100644
index 69fc56a5..00000000
--- a/src/plugins/geoservices/places_jsondb/idreply.cpp
+++ /dev/null
@@ -1,500 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "idreply.h"
-#include "qplacemanagerengine_jsondb.h"
-#include "jsondb.h"
-#include "traverser.h"
-
-#include <QtCore/QDebug>
-#include <QtCore/QFile>
-#include <QtCore/QUuid>
-#include <QtCore/QDateTime>
-
-IdReply::IdReply(QPlaceIdReply::OperationType operationType,
- QPlaceManagerEngineJsonDb *engine)
- : QPlaceIdReply(operationType, engine),m_engine(engine), m_isUpdate(false)
-{
-}
-
-IdReply::~IdReply()
-{
-}
-
-void IdReply::setId(const QString &id)
-{
- QPlaceIdReply::setId(id);
-}
-
-bool IdReply::isUpdate() const
-{
- return m_isUpdate;
-}
-
-void IdReply::setIsUpdate()
-{
- m_isUpdate = true;
-}
-
-QString IdReply::parentCategoryId() const
-{
- return m_parentCategoryId;
-}
-
-void IdReply::setParentCategoryId(const QString &parentId)
-{
- m_parentCategoryId = parentId;
-}
-
-void IdReply::start()
-{
-}
-
-SavePlaceReply::SavePlaceReply(QPlaceManagerEngineJsonDb *engine)
- : IdReply(QPlaceIdReply::SavePlace, engine), m_iconHandler(0)
-{
-}
-
-SavePlaceReply::~SavePlaceReply()
-{
- delete m_iconHandler;
-}
-
-void SavePlaceReply::setPlace(const QPlace &place)
-{
- m_place = place;
- setId(m_place.placeId());
-}
-
-void SavePlaceReply::start()
-{
- if (m_place.visibility() & ~QLocation::DeviceVisibility) {
- triggerDone(QPlaceReply::UnsupportedError, QString::fromLatin1("Only saving to device (or unspecified) scope is supported"));
- return;
- } else {
- if (m_place.placeId().isEmpty())
- db()->getCategories(m_place.categories(), this, SLOT(getCategoriesForPlaceFinished()));
- else
- db()->getPlace(m_place.placeId(), this, SLOT(checkIfExistsFinished()));
- }
-}
-
-void SavePlaceReply::processIconsFinished(const QJsonObject &thumbnailsJson)
-{
- if (m_iconHandler->error() != QPlaceReply::NoError) {
- triggerDone(m_iconHandler->error(), m_iconHandler->errorString());
- return;
- }
-
- if (!thumbnailsJson.isEmpty())
- m_placeJson.insert(JsonDb::Thumbnails, thumbnailsJson);
-
- delete m_iconHandler;
- m_iconHandler = 0;
-
- QString currentDateTime = QDateTime::currentDateTime().toString(Qt::ISODate);
- if (m_place.placeId().isEmpty()) {
- m_placeJson.insert(JsonDb::CreatedDateTime, currentDateTime);
- m_placeJson.insert(JsonDb::ModifiedDateTime, currentDateTime);
- } else {
- m_placeJson.insert(JsonDb::ModifiedDateTime, currentDateTime);
- }
-
- db()->write(m_placeJson, this, SLOT(savingFinished()));
-}
-
-void SavePlaceReply::checkIfExistsFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::PlaceDoesNotExistError, QStringLiteral("Specified place does not exist"));
- return;
- }
-
- m_placeJson = results.takeFirst();
- db()->getCategories(m_place.categories(), this, SLOT(getCategoriesForPlaceFinished()));
-}
-
-void SavePlaceReply::getCategoriesForPlaceFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.count() < m_place.categories().count()) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError,
- QStringLiteral("Specified categories does not exist for place"));
- return;
- } else if (results.count() > m_place.categories().count()) {
- triggerDone(QPlaceReply::UnknownError,
- QStringLiteral("Too many categories found for a place")); //should never happen
- return;
- }
-
- JsonDb::addToJson(&m_placeJson, m_place);
-
- m_iconHandler = new IconHandler(m_place.icon(), m_placeJson.value(JsonDb::Thumbnails).toObject(),
- const_cast<SavePlaceReply *>(this));
- connect(m_iconHandler, SIGNAL(finished(QJsonObject)), this, SLOT(processIconsFinished(QJsonObject)));
-}
-
-void SavePlaceReply::savingFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.count() != 1) {
- triggerDone(QPlaceReply::UnknownError, QStringLiteral("Saving a place resulted in ") + results.count() + QStringLiteral("places being saved"));
- } else {
- setId(results.first().value(JsonDb::Uuid).toString());
- triggerDone();
- }
-}
-
-void SavePlaceReply::requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- if (dbCode == QJsonDbRequest::MissingObject) {
- triggerDone(QPlaceReply::PlaceDoesNotExistError, QStringLiteral("Place does not exist"));
- return;
- } else {
- QString errorString = QString::fromLatin1("Unknown error occurred during save place operation: jsondb error code = %1, erroString = %2")
- .arg(dbCode).arg(dbErrorString);
- triggerDone(QPlaceReply::UnknownError, errorString);
- return;
- }
-}
-
-//-------RemovePlaceReply
-
-RemovePlaceReply::RemovePlaceReply(QPlaceManagerEngineJsonDb *engine)
- : IdReply(QPlaceIdReply::RemovePlace, engine)
-{
-}
-
-RemovePlaceReply::~RemovePlaceReply()
-{
-}
-
-void RemovePlaceReply::setId(const QString &placeId)
-{
- IdReply::setId(placeId);
-}
-
-void RemovePlaceReply::start()
-{
- db()->getPlace(id(), this, SLOT(checkIfExistsFinished()));
-}
-
-void RemovePlaceReply::checkIfExistsFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::PlaceDoesNotExistError, QStringLiteral("Specified place does not exist"));
- return;
- }
-
- db()->remove(results.first(), this, SLOT(removeFinished()));
-}
-
-void RemovePlaceReply::removeFinished()
-{
- triggerDone();
-}
-
-void RemovePlaceReply::requestError(QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- if (dbCode == QJsonDbRequest::MissingObject) {
- triggerDone(QPlaceReply::PlaceDoesNotExistError, QStringLiteral("Place does not exist"));
- return;
- } else {
- QPlaceReply::Error error = QPlaceReply::UnknownError;
- QString errorString = QString::fromLatin1("Unknown error occurred during remove place operation: jsondb error code =%1, erroString=%2").
- arg(dbCode).arg(dbErrorString);
- triggerDone(error, errorString);
- return;
- }
-}
-
-//-------SaveCategoryReply
-
-SaveCategoryReply::SaveCategoryReply(QPlaceManagerEngineJsonDb *engine)
- : IdReply(QPlaceIdReply::SaveCategory, engine), m_iconHandler(0)
-{
-}
-
-SaveCategoryReply::~SaveCategoryReply()
-{
- delete m_iconHandler;
-}
-
-void SaveCategoryReply::setCategory(const QPlaceCategory &category)
-{
- m_category = category;
-}
-
-void SaveCategoryReply::setParentId(const QString &parentId)
-{
- m_parentId = parentId;
-}
-
-void SaveCategoryReply::start()
-{
- //check if parentExists
- if (!m_parentId.isEmpty())
- db()->getCategory(m_parentId, this, SLOT(checkParentExistsFinished()));
- else {
-
- if (!m_category.categoryId().isEmpty()) {
- db()->getCategory(m_category.categoryId(), this, SLOT(getCurrentCategoryFinished()));
- } else {
- m_categoryJson = prepareCategoryJson();
- processIcons();
- }
- }
-}
-
-void SaveCategoryReply::checkParentExistsFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError, QStringLiteral("Parent category does not exist"));
- return;
- } else if (results.count() > 1) {
- triggerDone(QPlaceReply::UnknownError,
- QStringLiteral("More than one category was found corresponding to (parent) id") + m_parentId);
- return;
- } else {
- if (!m_category.categoryId().isEmpty()) {
- db()->getCategory(m_category.categoryId(), this, SLOT(getCurrentCategoryFinished()));
- return;
- }
-
- m_categoryJson = prepareCategoryJson();
- processIcons();
- return;
- }
-}
-
-void SaveCategoryReply::getCurrentCategoryFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError, "Category does not exist");
- return;
- } else {
- m_categoryJson = results.first();
- JsonDb::addToJson(&m_categoryJson, m_category);
- m_categoryJson.insert(JsonDb::CategoryParentId, m_parentId);
- processIcons();
- }
-}
-
-void SaveCategoryReply::savingFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (!m_category.categoryId().isEmpty()) //must've been saving an existing category
- setId(m_category.categoryId());
- else
- setId(results.first().value(JsonDb::Uuid).toString()); //must've been saving a new category
-
- triggerDone();
-}
-
-void SaveCategoryReply::processIconsFinished(const QJsonObject &thumbnailsJson)
-{
- if (m_iconHandler->error() != QPlaceReply::NoError) {
- triggerDone(m_iconHandler->error(), m_iconHandler->errorString());
- return;
- }
-
- if (!thumbnailsJson.isEmpty())
- m_categoryJson.insert(JsonDb::Thumbnails, thumbnailsJson);
-
- delete m_iconHandler;
- m_iconHandler = 0;
-
- QList<QJsonObject> categories;
- categories << m_categoryJson << m_descendantsJson;
- db()->write(categories, this, SLOT(savingFinished()));
-}
-
-QJsonObject SaveCategoryReply::prepareCategoryJson()
-{
- //if it is a new category we need to predefine the category id so we can
- //save it in the lineage
- if (m_category.categoryId().isEmpty())
- m_category.setCategoryId(QUuid::createUuid().toString());
-
- QJsonObject categoryJson;
- JsonDb::addToJson(&categoryJson, m_category);
-
- categoryJson.insert(JsonDb::CategoryParentId, m_parentId);
-
- return categoryJson;
-}
-
-void SaveCategoryReply::processIcons()
-{
- m_iconHandler = new IconHandler(m_category.icon(), m_categoryJson.value(JsonDb::Thumbnails).toObject(),
- this);
- connect(m_iconHandler, SIGNAL(finished(QJsonObject)), this, SLOT(processIconsFinished(QJsonObject)));
-}
-
-void SaveCategoryReply::requestError(QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- if (dbCode == QJsonDbRequest::MissingObject) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError, QStringLiteral("Category does not exist"));
- return;
- } else {
- QString errorString = QString::fromLatin1("Unknown error occurred during save category operation: "
- "jsondb error code = %1, erroString = %2")
- .arg(dbCode).arg(dbErrorString);
- triggerDone(QPlaceReply::UnknownError, errorString);
- return;
- }
-}
-
-//-------RemoveCategoryReply
-
-RemoveCategoryReply::RemoveCategoryReply(QPlaceManagerEngineJsonDb *engine)
- : IdReply(QPlaceIdReply::RemovePlace, engine)
-{
-}
-
-RemoveCategoryReply::~RemoveCategoryReply()
-{
-}
-
-void RemoveCategoryReply::setId(const QString &categoryId)
-{
- IdReply::setId(categoryId);
-}
-
-void RemoveCategoryReply::start()
-{
- db()->getCategory(id(), this, SLOT(getCategoryFinished()));
-}
-
-void RemoveCategoryReply::getCategoryFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> results = request->takeResults();
-
- if (results.isEmpty()) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError,
- QStringLiteral("Trying to remove category that does not exist"));
- return;
- } else {
- QJsonObject categoryJson = results.first();
- QString uuid = categoryJson.value(JsonDb::Uuid).toString();
- if (uuid != id()) {
- triggerDone(QPlaceReply::UnknownError,
- QString::fromLatin1(" Response UUID does not match that in the request"
- "for a category removal"
- "JsonDb UUID: %1"
- "Request UUID: %2").arg(uuid).arg(id()));
- return;
- } else {
- CategoryTraverser * traverser = new CategoryTraverser(engine()->db(), this);
- connect(traverser, SIGNAL(finished()),
- this, SLOT(getCategoriesToBeRemovedFinished()));
- traverser->start(id());
- }
- }
-}
-
-void RemoveCategoryReply::getCategoriesToBeRemovedFinished()
-{
- CategoryTraverser * traverser = qobject_cast<CategoryTraverser *>(sender());
-
- if (!traverser->errorString().isEmpty()) {
- QString errorString =
- QString::fromLatin1("Unknown error occurred during remove place operation: %1")
- .arg(traverser->errorString());
- traverser->deleteLater();
-
- triggerDone(QPlaceReply::UnknownError, errorString);
- return;
- }
-
- QList<QJsonObject> catObjects = traverser->results();
- traverser->deleteLater();
-
- if (!catObjects.isEmpty())
- db()->remove(catObjects, this, SLOT(removeFinished()));
- else
- removeFinished();
-}
-
-void RemoveCategoryReply::removeFinished()
-{
- triggerDone();
-}
-
-void RemoveCategoryReply::requestError(QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- if (dbCode == QJsonDbRequest::MissingObject) {
- triggerDone(QPlaceReply::CategoryDoesNotExistError, QStringLiteral("Category does not exist"));
- return;
- } else {
- QString errorString = QString::fromLatin1("Unknown error occurred during remove place operation: jsondb error code =%1, erroString=%2").
- arg(dbCode).arg(dbErrorString);
- triggerDone(QPlaceReply::UnknownError, errorString);
- return;
- }
-}
diff --git a/src/plugins/geoservices/places_jsondb/idreply.h b/src/plugins/geoservices/places_jsondb/idreply.h
deleted file mode 100644
index 30e94f50..00000000
--- a/src/plugins/geoservices/places_jsondb/idreply.h
+++ /dev/null
@@ -1,186 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef IDREPLY_H
-#define IDREPLY_H
-
-#include <QtCore/QObject>
-#include <QtCore/QJsonArray>
-#include <QtJsonDb/QJsonDbRequest>
-#include <QtLocation/QPlaceIdReply>
-
-#include "icon.h"
-#include "macro.h"
-#include "qplacemanagerengine_jsondb.h"
-#include "iconhandler.h"
-
-QT_BEGIN_NAMESPACE
-
-class IdReply : public QPlaceIdReply
-{
- Q_OBJECT
-
-public:
- IdReply(QPlaceIdReply::OperationType operationType, QPlaceManagerEngineJsonDb *engine);
- virtual ~IdReply();
- void setId(const QString &id);
-
- DECLARE_TRIGGER_DONE_FN
-
- void setIsUpdate();
- bool isUpdate() const;
-
- QString parentCategoryId() const;
- void setParentCategoryId(const QString &parentId);
-
- virtual void start();
-
- QPlaceManagerEngineJsonDb *engine() { return m_engine; }
-
-protected:
- JsonDb *db() { return m_engine->db(); }
-
-private:
- QPlaceManagerEngineJsonDb *m_engine;
- bool m_isUpdate;
- QString m_parentCategoryId;
-};
-
-class SavePlaceReply : public IdReply
-{
- Q_OBJECT
-
- enum IconDestination {
- Small,
- Medium,
- Large,
- FullScreen
- };
-
-public:
- SavePlaceReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~SavePlaceReply();
-
- void setPlace(const QPlace &place);
- void start();
-
-private slots:
- void checkIfExistsFinished();
- void getCategoriesForPlaceFinished();
- void processIconsFinished(const QJsonObject &thumbnailsJson);
- void savingFinished();
-
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString);
-
-private:
- QPlace m_place;
- QJsonObject m_placeJson;
- QStringList m_specifiedDestinations;
- IconHandler *m_iconHandler;
-};
-
-class RemovePlaceReply : public IdReply
-{
- Q_OBJECT
-
-public:
- RemovePlaceReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~RemovePlaceReply();
- void setId(const QString &placeId);
- void start();
-
-private slots:
- void checkIfExistsFinished();
- void removeFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString);
-};
-
-class SaveCategoryReply : public IdReply
-{
- Q_OBJECT
-
-public:
- SaveCategoryReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~SaveCategoryReply();
- void setCategory(const QPlaceCategory &category);
- void setParentId(const QString &parentId);
- void start();
-
-private slots:
- void checkParentExistsFinished();
- void getCurrentCategoryFinished();
- void processIconsFinished(const QJsonObject &thumbnailsJson);
- void savingFinished();
-
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString);
-
-private:
- QJsonObject prepareCategoryJson();
- void processIcons();
-
- QPlaceCategory m_category;
- QString m_parentId;
- QJsonArray m_newAncestors;
- QJsonArray m_oldAncestors;
- QJsonObject m_categoryJson;
- QList<QJsonObject> m_descendantsJson;
- IconHandler *m_iconHandler;
-};
-
-class RemoveCategoryReply : public IdReply
-{
- Q_OBJECT
-
-public:
- RemoveCategoryReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~RemoveCategoryReply();
- void setId(const QString &categoryId);
- void start();
-
-private slots:
- void getCategoryFinished();
- void getCategoriesToBeRemovedFinished();
- void removeFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString);
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/initreply.cpp b/src/plugins/geoservices/places_jsondb/initreply.cpp
deleted file mode 100644
index f0b454a5..00000000
--- a/src/plugins/geoservices/places_jsondb/initreply.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "initreply.h"
-#include "traverser.h"
-
-CategoryInitReply::CategoryInitReply(QPlaceManagerEngineJsonDb *engine)
- : QPlaceReply(engine),
- m_engine(engine),
- m_traverser(new CategoryTraverser(m_engine->db(), this))
-{
- Q_ASSERT(m_traverser);
- connect(m_traverser, SIGNAL(finished()),
- this, SLOT(requestFinished()));
-}
-
-CategoryInitReply::~CategoryInitReply()
-{
- delete m_traverser;
-}
-
-void CategoryInitReply::start()
-{
- m_traverser->start();
-}
-
-void CategoryInitReply::requestFinished()
-{
- if (!m_traverser->errorString().isEmpty()) {
- QString errorString =
- QString::fromLatin1("Unknown error occurred during initialize catgory operation: %1")
- .arg(m_traverser->errorString());
- triggerDone(QPlaceReply::UnknownError, errorString);
- return;
- }
-
- CategoryTree tree = CategoryTraverser::convertToTree(m_traverser->results(), m_engine);
- m_engine->setCategoryTree(tree);
- triggerDone(QPlaceReply::NoError);
-}
diff --git a/src/plugins/geoservices/places_jsondb/initreply.h b/src/plugins/geoservices/places_jsondb/initreply.h
deleted file mode 100644
index 24f52ff9..00000000
--- a/src/plugins/geoservices/places_jsondb/initreply.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef INIT_REPLY_H
-#define INIT_REPLY_H
-
-#include "qplacemanagerengine_jsondb.h"
-#include "macro.h"
-
-#include <QtCore/QMap>
-#include <QtLocation/QPlaceReply>
-#include <QtLocation/QPlaceCategory>
-
-QT_BEGIN_NAMESPACE
-
-class CategoryTraverser;
-
-class CategoryInitReply : public QPlaceReply
-{
- Q_OBJECT
-public:
- CategoryInitReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~CategoryInitReply();
-
- DECLARE_TRIGGER_DONE_FN
-
- void start();
- void processNodeQueue();
-
-protected:
- JsonDb *db() { return m_engine->db(); }
-
-private slots:
- void requestFinished();
-
-private:
- QPlaceManagerEngineJsonDb *m_engine;
- CategoryTree m_tree;
- CategoryTraverser *m_traverser;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/jsondb.cpp b/src/plugins/geoservices/places_jsondb/jsondb.cpp
deleted file mode 100644
index dd95d356..00000000
--- a/src/plugins/geoservices/places_jsondb/jsondb.cpp
+++ /dev/null
@@ -1,906 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "icon.h"
-#include "jsondb.h"
-#include "qplacemanagerengine_jsondb.h"
-
-#include <QtCore/QDebug>
-#include <QtCore/QFile>
-#include <QtCore/QJsonArray>
-#include <QtCore/QJsonDocument>
-#include <QtCore/QString>
-#include <QtCore/QTimer>
-#include <QtJsonDb/QJsonDbReadRequest>
-#include <QtJsonDb/QJsonDbWriteRequest>
-#include <QtLocation/QPlaceSearchRequest>
-#include <QtLocation/QPlaceCategory>
-
-const QLatin1String JsonDb::Uuid("_uuid");
-const QLatin1String JsonDb::Type("_type");
-
-const QLatin1String JsonDb::Name("displayName");
-const QLatin1String JsonDb::PlaceType("com.nokia.mt.location.Place");
-const QLatin1String JsonDb::CategoryUuids("categoryUuids"); //only categories that are directly assigned to a place
-
-const QLatin1String JsonDb::CategoryType("com.nokia.mt.location.PlaceCategory");
-const QLatin1String JsonDb::CategoryParentId("parentUuid");
-
-//coord
-const QLatin1String JsonDb::Coordinate("geo");
-const QLatin1String JsonDb::Latitude("latitude");
-const QLatin1String JsonDb::Longitude("longitude");
-
-//address
-const QLatin1String JsonDb::Address("address");
-const QLatin1String JsonDb::Street("street");
-const QLatin1String JsonDb::District("district");
-const QLatin1String JsonDb::City("locality");
-const QLatin1String JsonDb::County("county");
-const QLatin1String JsonDb::State("region");
-const QLatin1String JsonDb::Country("country");
-const QLatin1String JsonDb::CountryCode("countryCode");
-const QLatin1String JsonDb::PostalCode("postalCode");
-
-const QLatin1String JsonDb::Location("location");
-
-//contact details
-const QLatin1String JsonDb::Phones("phones");
-const QLatin1String JsonDb::Emails("emails");
-const QLatin1String JsonDb::Websites("urls");
-
-const QLatin1String JsonDb::PhoneSubType("subType");
-const QLatin1String JsonDb::SubTypeFax("fax");
-const QLatin1String JsonDb::SubTypeLandline("landline");
-
-const QLatin1String JsonDb::Label("label");
-const QLatin1String JsonDb::Value("value");
-const QLatin1String JsonDb::Url("url");
-
-const QLatin1String JsonDb::ExtendedAttributes("extendedAttributes");
-const QLatin1String JsonDb::Text("text");
-const QLatin1String JsonDb::NokiaCategoryIds("x_nokia_category_ids");
-
-const QLatin1String JsonDb::Height("height");
-const QLatin1String JsonDb::Width("width");
-
-const QLatin1String JsonDb::Thumbnails("thumbnails");
-const QLatin1String JsonDb::Small("small");
-const QLatin1String JsonDb::Medium("medium");
-const QLatin1String JsonDb::Large("large");
-const QLatin1String JsonDb::Fullscreen("fullscreen");
-const QLatin1String JsonDb::NokiaIcon("nokiaIcon");
-
-const QLatin1String JsonDb::VisibilityScope("visibilityScope");
-const QLatin1String JsonDb::DeviceVisibility("device");
-
-const QLatin1String JsonDb::CreatedDateTime("createdDateTime");
-const QLatin1String JsonDb::ModifiedDateTime("modifiedDateTime");
-
-JsonDb::JsonDb(const QString &partition)
- : m_connection(new QJsonDbConnection),
- m_placeWatcher(new QJsonDbWatcher(this)),
- m_categoryWatcher(new QJsonDbWatcher(this)),
- m_partition(partition)
-{
- m_connection->connectToServer();
- QTimer::singleShot(5000, this, SLOT(connectionWarning())); //5000 is an arbitrarily chosen timeframe
-
- m_placeWatcher->setQuery(QString::fromLatin1("[?%1 = \"%2\"]").arg(JsonDb::Type).arg(JsonDb::PlaceType));
- m_placeWatcher->setPartition(m_partition);
- connect(m_placeWatcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(processPlaceNotifications()));
- connect(m_placeWatcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)),
- this, SIGNAL(notificationsError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
- m_connection->addWatcher(m_placeWatcher);
-
- m_categoryWatcher->setQuery(QString::fromLatin1("[?%1 = \"%2\"]").arg(JsonDb::Type).arg(JsonDb::CategoryType));
- m_categoryWatcher->setPartition(m_partition);
- connect(m_categoryWatcher, SIGNAL(notificationsAvailable(int)),
- this, SLOT(processCategoryNotifications()));
- connect(m_categoryWatcher, SIGNAL(error(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)),
- this, SIGNAL(notificationsError(QtJsonDb::QJsonDbWatcher::ErrorCode,QString)));
- m_connection->addWatcher(m_categoryWatcher);
-}
-
-JsonDb::~JsonDb()
-{
- delete m_placeWatcher;
- delete m_categoryWatcher;
- delete m_connection;
-}
-
-void JsonDb::addToJson(QJsonObject *jsonObj, const QPlaceCategory &category)
-{
- if (!category.categoryId().isEmpty())
- jsonObj->insert(JsonDb::Uuid, category.categoryId());
-
- jsonObj->insert(JsonDb::Type, JsonDb::CategoryType);
- jsonObj->insert(JsonDb::Name, category.name());
-}
-
-//Precondition: All place properties have been checked and are found to be valid.
-//Note: thumnbnails and icons are beyond the scope of this function.
-void JsonDb::addToJson(QJsonObject *jsonObj, const QPlace &place)
-{
- jsonObj->insert(JsonDb::Type, JsonDb::PlaceType);
- if (!place.placeId().isEmpty())
- jsonObj->insert(JsonDb::Uuid, place.placeId());
- if (!place.name().isEmpty())
- jsonObj->insert(JsonDb::Name, place.name());
-
- QJsonObject locationJson = jsonObj->value(JsonDb::Location).toObject();
- QJsonObject coordJson = jsonObj->value(JsonDb::Coordinate).toObject();
-
- if (place.location().coordinate() != QGeoCoordinate()) {
- coordJson.insert(JsonDb::Latitude, place.location().coordinate().latitude());
- coordJson.insert(JsonDb::Longitude, place.location().coordinate().longitude());
- locationJson.insert(JsonDb::Coordinate, coordJson);
- } else {
- locationJson.remove(JsonDb::Coordinate);
- }
-
- QJsonObject addressJson = locationJson.value(JsonDb::Address).toObject();
- if (!place.location().address().street().isEmpty())
- addressJson.insert(JsonDb::Street, place.location().address().street());
- else
- addressJson.remove(JsonDb::Street);
-
- if (!place.location().address().district().isEmpty())
- addressJson.insert(JsonDb::District, place.location().address().district());
- else
- addressJson.remove(JsonDb::District);
-
- if (!place.location().address().city().isEmpty())
- addressJson.insert(JsonDb::City, place.location().address().city());
- else
- addressJson.remove(JsonDb::City);
-
- if (!place.location().address().county().isEmpty())
- addressJson.insert(JsonDb::County, place.location().address().county());
- else
- addressJson.remove(JsonDb::County);
-
- if (!place.location().address().state().isEmpty())
- addressJson.insert(JsonDb::State, place.location().address().state());
- else
- addressJson.remove(JsonDb::State);
-
- if (!place.location().address().country().isEmpty())
- addressJson.insert(JsonDb::Country, place.location().address().country());
- else
- addressJson.remove(JsonDb::Country);
-
- if (!place.location().address().countryCode().isEmpty())
- addressJson.insert(JsonDb::CountryCode, place.location().address().countryCode());
- else
- addressJson.remove(JsonDb::CountryCode);
-
- if (!place.location().address().postalCode().isEmpty())
- addressJson.insert(JsonDb::PostalCode, place.location().address().postalCode());
- else
- addressJson.remove(JsonDb::PostalCode);
-
- if (!addressJson.isEmpty())
- locationJson.insert(JsonDb::Address, addressJson);
- else
- locationJson.remove(JsonDb::Address);
-
- //must always have a location in the schema
- jsonObj->insert(JsonDb::Location, locationJson);
-
- QStringList contactTypes = place.contactTypes();
- if (contactTypes.contains(QPlaceContactDetail::Phone) || contactTypes.contains(QPlaceContactDetail::Fax)) {
- QJsonArray phonesArray;
-
- foreach (const QPlaceContactDetail &phone, place.contactDetails(QPlaceContactDetail::Phone)) {
- QJsonObject phoneJson;
- phoneJson.insert(JsonDb::PhoneSubType, JsonDb::SubTypeLandline);
- phoneJson.insert(JsonDb::Label, phone.label());
- phoneJson.insert(JsonDb::Value, phone.value());
- phonesArray.append(phoneJson);
- }
-
- foreach (const QPlaceContactDetail &fax, place.contactDetails(QPlaceContactDetail::Fax)) {
- QJsonObject faxJson;
- faxJson.insert(JsonDb::PhoneSubType, JsonDb::SubTypeFax);
- faxJson.insert(JsonDb::Label, fax.label());
- faxJson.insert(JsonDb::Value, fax.value());
- phonesArray.append(faxJson);
- }
-
- if (!phonesArray.isEmpty())
- jsonObj->insert(JsonDb::Phones, phonesArray);
- } else {
- jsonObj->remove(JsonDb::Phones);
- }
-
- if (contactTypes.contains(QPlaceContactDetail::Website)) {
- QJsonArray websitesArray;
- foreach (const QPlaceContactDetail &website, place.contactDetails(QPlaceContactDetail::Website)) {
- QJsonObject websiteJson;
- websiteJson.insert(JsonDb::Label, website.label());
- websiteJson.insert(JsonDb::Url, website.value());
- websitesArray.append(websiteJson);
- }
-
- if (!websitesArray.isEmpty())
- jsonObj->insert(JsonDb::Websites, websitesArray);
- } else {
- jsonObj->remove(JsonDb::Websites);
- }
-
- if (contactTypes.contains(QPlaceContactDetail::Email)) {
- QJsonArray emailsArray;
- foreach (const QPlaceContactDetail &email, place.contactDetails(QPlaceContactDetail::Email)) {
- QJsonObject emailJson;
- emailJson.insert(JsonDb::Label, email.label());
- emailJson.insert(JsonDb::Value, email.value());
- emailsArray.append(emailJson);
- }
-
- if (!emailsArray.isEmpty())
- jsonObj->insert(JsonDb::Emails, emailsArray);
- } else {
- jsonObj->remove(JsonDb::Emails);
- }
-
- if (!place.categories().isEmpty()) {
- QJsonArray categoryUuidsArray;
- foreach (const QPlaceCategory &category, place.categories())
- categoryUuidsArray.append(category.categoryId());
- jsonObj->insert(JsonDb::CategoryUuids, categoryUuidsArray);
- //note all category uuids is set elsewhere
- } else {
- jsonObj->remove(JsonDb::CategoryUuids);
- }
-
- if (!place.extendedAttributeTypes().isEmpty()) {
- QJsonObject attributesJson;
- //note this is not a list but an object containing the attributes
- foreach (const QString attributeType, place.extendedAttributeTypes()) {
- QJsonObject attributeJson;
- attributeJson.insert(JsonDb::Label, place.extendedAttribute(attributeType).label());
- attributeJson.insert(JsonDb::Text, place.extendedAttribute(attributeType).text());
- attributesJson.insert(attributeType, attributeJson);
- }
- if (!attributesJson.isEmpty())
- jsonObj->insert(JsonDb::ExtendedAttributes, attributesJson);
- } else {
- jsonObj->remove(JsonDb::ExtendedAttributes);
- }
-
- jsonObj->insert(JsonDb::VisibilityScope, JsonDb::DeviceVisibility);
-}
-
-QJsonObject JsonDb::convertToJson(const QPlace &place)
-{
- QJsonObject jsonObj;
-
- jsonObj.insert(JsonDb::Type, JsonDb::PlaceType);
- if (!place.placeId().isEmpty())
- jsonObj.insert(JsonDb::Uuid, place.placeId());
- if (!place.name().isEmpty())
- jsonObj.insert(JsonDb::Name, place.name());
-
- QJsonObject locationJson;
- if (place.location().coordinate() != QGeoCoordinate()) {
- QJsonObject coordJson;
- coordJson.insert(JsonDb::Latitude, place.location().coordinate().latitude());
- coordJson.insert(JsonDb::Longitude, place.location().coordinate().longitude());
- locationJson.insert(JsonDb::Coordinate, coordJson);
- }
-
- if (!place.location().address().isEmpty()) {
- QJsonObject addressJson;
- if (!place.location().address().street().isEmpty())
- addressJson.insert(JsonDb::Street, place.location().address().street());
-
- if (!place.location().address().district().isEmpty())
- addressJson.insert(JsonDb::District, place.location().address().district());
-
- if (!place.location().address().city().isEmpty())
- addressJson.insert(JsonDb::City, place.location().address().city());
-
- if (!place.location().address().county().isEmpty())
- addressJson.insert(JsonDb::County, place.location().address().county());
-
- if (!place.location().address().state().isEmpty())
- addressJson.insert(JsonDb::State, place.location().address().state());
-
- if (!place.location().address().country().isEmpty())
- addressJson.insert(JsonDb::Country, place.location().address().country());
-
- if (!place.location().address().countryCode().isEmpty())
- addressJson.insert(JsonDb::CountryCode, place.location().address().countryCode());
-
- if (!place.location().address().postalCode().isEmpty())
- addressJson.insert(JsonDb::PostalCode, place.location().address().postalCode());
-
- locationJson.insert(JsonDb::Address, addressJson);
- }
-
- // TODO: Q_ASSERT(locationJson.isEmpty()); //it expected that at least one of the coordinates or
- //address has been filled in.
- jsonObj.insert(JsonDb::Location, locationJson);
-
- QStringList contactTypes = place.contactTypes();
- if (contactTypes.contains(QPlaceContactDetail::Phone) || contactTypes.contains(QPlaceContactDetail::Fax)) {
- QJsonArray phonesArray;
-
- foreach (const QPlaceContactDetail &phone, place.contactDetails(QPlaceContactDetail::Phone)) {
- QJsonObject phoneJson;
- phoneJson.insert(JsonDb::PhoneSubType, JsonDb::SubTypeLandline);
- phoneJson.insert(JsonDb::Label, phone.label());
- phoneJson.insert(JsonDb::Value, phone.value());
- phonesArray.append(phoneJson);
- }
-
- foreach (const QPlaceContactDetail &fax, place.contactDetails(QPlaceContactDetail::Fax)) {
- QJsonObject faxJson;
- faxJson.insert(JsonDb::PhoneSubType, JsonDb::SubTypeFax);
- faxJson.insert(JsonDb::Label, fax.label());
- faxJson.insert(JsonDb::Value, fax.value());
- phonesArray.append(faxJson);
- }
-
- if (!phonesArray.isEmpty())
- jsonObj.insert(JsonDb::Phones, phonesArray);
- } else {
- jsonObj.remove(JsonDb::Phones);
- }
-
- if (contactTypes.contains(QPlaceContactDetail::Website)) {
- QJsonArray websitesArray;
- foreach (const QPlaceContactDetail &website, place.contactDetails(QPlaceContactDetail::Website)) {
- QJsonObject websiteJson;
- websiteJson.insert(JsonDb::Label, website.label());
- websiteJson.insert(JsonDb::Url, website.value());
- websitesArray.append(websiteJson);
- }
-
- if (!websitesArray.isEmpty())
- jsonObj.insert(JsonDb::Websites, websitesArray);
- } else {
- jsonObj.remove(JsonDb::Websites);
- }
-
- if (contactTypes.contains(QPlaceContactDetail::Email)) {
- QJsonArray emailsArray;
- foreach (const QPlaceContactDetail &email, place.contactDetails(QPlaceContactDetail::Email)) {
- QJsonObject emailJson;
- emailJson.insert(JsonDb::Label, email.label());
- emailJson.insert(JsonDb::Value, email.value());
- emailsArray.append(emailJson);
- }
-
- if (!emailsArray.isEmpty())
- jsonObj.insert(JsonDb::Emails, emailsArray);
- } else {
- jsonObj.remove(JsonDb::Emails);
- }
-
- if (!place.categories().isEmpty()) {
- QJsonArray categoryUuidsArray;
- foreach (const QPlaceCategory &category, place.categories())
- categoryUuidsArray.append(category.categoryId());
- jsonObj.insert(JsonDb::CategoryUuids, categoryUuidsArray);
- }
-
- if (!place.extendedAttributeTypes().isEmpty()) {
- QJsonObject attributesJson;//note this is not a list but an object containing the attributes
-
- foreach (const QString attributeType, place.extendedAttributeTypes()) {
- if (attributeType.startsWith(QLatin1String("x_id"))) {
- QJsonObject attributeJson;
- attributeJson.insert(JsonDb::Label, place.extendedAttribute(attributeType).label());
- attributeJson.insert(JsonDb::Text, place.extendedAttribute(attributeType).text());
- attributesJson.insert(attributeType, attributeJson);
- }
-
- if (attributeType == JsonDb::NokiaCategoryIds) {
- QJsonObject attributeJson;
- attributeJson.insert(JsonDb::Text, place.extendedAttribute(JsonDb::NokiaCategoryIds).text());
- attributesJson.insert(JsonDb::NokiaCategoryIds, attributeJson);
- }
- }
-
- if (!attributesJson.isEmpty())
- jsonObj.insert(JsonDb::ExtendedAttributes, attributesJson);
- }
-
- return jsonObj;
-}
-
-/* Expected response format
- {
- "data": <array of json objects>
- "explantion":
- "length": <integer>
- "offset": <integer>
- }
-*/
-QList<QPlace> JsonDb::convertJsonObjectsToPlaces(const QList<QJsonObject> &objects,
- const QPlaceManagerEngineJsonDb *engine)
-{
- QList <QPlace> places;
- foreach (const QJsonObject &object, objects)
- places.append(JsonDb::convertJsonObjectToPlace(object,engine));
-
- return places;
-}
-
-QList<QPlaceCategory> JsonDb::convertJsonObjectsToCategories(const QList<QJsonObject> &objects,
- const QPlaceManagerEngineJsonDb *engine)
-{
- QList<QPlaceCategory> categories;
- foreach (const QJsonObject &object, objects)
- categories.append(JsonDb::convertJsonObjectToCategory(object,engine));
-
- return categories;
-}
-
-//Note the place category ids are set by this function.
-//Assigning category properties such as name etc must be handled elsewhere.
-QPlace JsonDb::convertJsonObjectToPlace(const QJsonObject &placeJson,
- const QPlaceManagerEngineJsonDb *engine)
-{
- QPlace place;
- place.setName(placeJson.value(JsonDb::Name).toString());
- place.setPlaceId(placeJson.value(JsonDb::Uuid).toString());
-
- QJsonObject locationJson = placeJson.value(JsonDb::Location).toObject();
-
- QGeoLocation location;
- if (locationJson.contains(JsonDb::Coordinate)) {
- //Note if a coordinate exists, it should not be a nan value.
- QGeoCoordinate coord;
-
- QJsonObject coordJson = locationJson.value(JsonDb::Coordinate).toObject();
- coord.setLatitude(coordJson.value(JsonDb::Latitude).toDouble());
- coord.setLongitude(coordJson.value(JsonDb::Longitude).toDouble());
-
- location.setCoordinate(coord);
- }
-
- if (locationJson.contains(JsonDb::Address)) {
- QGeoAddress address;
-
- QJsonObject addressJson = locationJson.value(JsonDb::Address).toObject();
- address.setStreet(addressJson.value(JsonDb::Street).toString());
- address.setDistrict(addressJson.value(JsonDb::District).toString());
- address.setCity(addressJson.value(JsonDb::City).toString());
- address.setCounty(addressJson.value(JsonDb::County).toString());
- address.setState(addressJson.value(JsonDb::State).toString());
- address.setCountry(addressJson.value(JsonDb::Country).toString());
- address.setCountryCode(addressJson.value(JsonDb::CountryCode).toString());
- address.setPostalCode(addressJson.value(JsonDb::PostalCode).toString());
-
- location.setAddress(address);
- }
-
- place.setLocation(location);
-
- QJsonArray phonesArray = placeJson.value(JsonDb::Phones).toArray();
- for (int i = 0; i < phonesArray.count(); ++i) {
- QPlaceContactDetail detail;
- detail.setLabel(phonesArray.at(i).toObject().value(JsonDb::Label).toString());
- detail.setValue(phonesArray.at(i).toObject().value(JsonDb::Value).toString());
-
- QString phoneType = phonesArray.at(i).toObject().value(JsonDb::PhoneSubType).toString();
- if (phoneType == JsonDb::SubTypeLandline)
- place.appendContactDetail(QPlaceContactDetail::Phone, detail);
- else if (phoneType == JsonDb::SubTypeFax)
- place.appendContactDetail(QPlaceContactDetail::Fax, detail);
- }
-
- QJsonArray websitesArray = placeJson.value(JsonDb::Websites).toArray();
- for (int i = 0; i < websitesArray.count(); ++i) {
- QPlaceContactDetail detail;
- detail.setLabel(websitesArray.at(i).toObject().value(JsonDb::Label).toString());
- detail.setValue(websitesArray.at(i).toObject().value(JsonDb::Url).toString());
- place.appendContactDetail(QPlaceContactDetail::Website, detail);
- }
-
- QJsonArray emailsArray = placeJson.value(JsonDb::Emails).toArray();
- for (int i = 0; i < emailsArray.count(); ++i) {
- QPlaceContactDetail detail;
- detail.setLabel(emailsArray.at(i).toObject().value(JsonDb::Label).toString());
- detail.setValue(emailsArray.at(i).toObject().value(JsonDb::Value).toString());
- place.appendContactDetail(QPlaceContactDetail::Email, detail);
- }
-
- QList<QPlaceCategory> categories;
- QJsonArray categoryUuidsJson = placeJson.value(JsonDb::CategoryUuids).toArray();
- for (int i = 0; i < categoryUuidsJson.count(); ++i) {
- QPlaceCategory cat;
- cat.setCategoryId(categoryUuidsJson.at(i).toString());
- categories.append(cat);
- }
-
- place.setCategories(categories);
-
- if (placeJson.contains(JsonDb::ExtendedAttributes)) {
- QJsonObject attributesJson = placeJson.value(JsonDb::ExtendedAttributes).toObject();
- foreach (const QString &attributeType, attributesJson.keys()) {
- QJsonObject attributeJson = attributesJson.value(attributeType).toObject();
- QPlaceAttribute attribute;
- attribute.setLabel(attributeJson.value(JsonDb::Label).toString());
- attribute.setText(attributeJson.value(JsonDb::Text).toString());
- place.setExtendedAttribute(attributeType, attribute);
- }
- }
-
- QPlaceIcon icon = convertJsonObjectToIcon(placeJson.value(JsonDb::Thumbnails).toObject(),
- engine,
- place.extendedAttribute(JsonDb::NokiaCategoryIds)
- .text().split(QLatin1String(",")));
- place.setIcon(icon);
-
- place.setVisibility(QLocation::DeviceVisibility);
-
- return place;
-}
-
-QPlaceCategory JsonDb::convertJsonObjectToCategory(const QJsonObject &categoryJson,
- const QPlaceManagerEngineJsonDb *engine)
-{
- Q_UNUSED(engine);
-
- QPlaceCategory category;
- if (categoryJson.value(JsonDb::Type) == JsonDb::CategoryType) {
- category.setName(categoryJson.value(JsonDb::Name).toString());
- category.setCategoryId(categoryJson.value(JsonDb::Uuid).toString());
- }
-
- QPlaceIcon icon = convertJsonObjectToIcon(categoryJson.value(JsonDb::Thumbnails).toObject(), engine);
- category.setIcon(icon);
- return category;
-}
-
-QPlaceIcon JsonDb::convertJsonObjectToIcon(const QJsonObject &thumbnailsJson,
- const QPlaceManagerEngineJsonDb *engine,
- const QStringList &nokiaCategoryIds)
-{
- QVariantMap iconParameters;
- QList<QLatin1String> sizes;
- sizes << JsonDb::Small << JsonDb::Medium << JsonDb::Large << JsonDb::Fullscreen;
-
- foreach (const QLatin1String &size, sizes) {
- if (thumbnailsJson.contains(size)) {
- QJsonObject thumbnailJson = thumbnailsJson.value(size).toObject();
- iconParameters.insert(QString(size) + QLatin1String("Url"), QUrl::fromUserInput(thumbnailJson.value(JsonDb::Url).toString()));
- QSize sizeDimensions = QSize(thumbnailJson.value(JsonDb::Width).toDouble(), thumbnailJson.value(JsonDb::Height).toDouble());
- iconParameters.insert(QString(size) + QLatin1String("Size"), sizeDimensions);
- }
- }
-
- QString nokiaIcon = thumbnailsJson.value(JsonDb::NokiaIcon).toString();
- if (!nokiaIcon.isEmpty())
- iconParameters.insert(JsonDbIcon::NokiaIcon, nokiaIcon);
-
- if (nokiaIcon.isEmpty() && !engine->useCustomIcons()) {
- const JsonDb *db = engine->db();
- Q_ASSERT(db);
-
- QString iconPrefix = engine->localDataPath();
-
- foreach (const QString &categoryId, nokiaCategoryIds) {
- if (db->m_restIdToIconHash.contains(categoryId)) {
- nokiaIcon = QString::fromLatin1("/icons/categories/")
- + db->m_restIdToIconHash.value(categoryId);
- break;
- }
- }
-
- if (nokiaIcon.isEmpty())
- nokiaIcon = JsonDbIcon::DefaultIcon;
-
- if (QFile::exists(iconPrefix + nokiaIcon)) {
- iconParameters.insert(JsonDbIcon::NokiaIcon, nokiaIcon);
- iconParameters.insert(JsonDbIcon::NokiaIconGenerated, true);
- }
- }
-
- QPlaceIcon icon;
- if (!iconParameters.isEmpty()) {
- icon.setParameters(iconParameters);
- Q_ASSERT(engine->manager());
- icon.setManager(engine->manager());
- }
-
- return icon;
-}
-
-QString JsonDb::query(const QString &expression)
-{
- return QLatin1Char('[') + expression + QLatin1Char(']');
-}
-
-void JsonDb::setupRequest(QJsonDbRequest *request, QObject *parent, const char *slot)
-{
- Q_ASSERT(slot);
- QObject::connect(request, SIGNAL(finished()), parent, slot);
- QObject::connect(request, SIGNAL(finished()), request, SLOT(deleteLater()));
- QObject::connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- parent, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- QObject::connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- request, SLOT(deleteLater()));
- request->setPartition(m_partition);
-}
-
-bool JsonDb::parseIconMapping(const QString &fileName)
-{
- QFile mappingFile(fileName);
-
- m_restIdToIconHash.clear();
- if (mappingFile.open(QIODevice::ReadOnly)) {
- QJsonDocument document = QJsonDocument::fromJson(mappingFile.readAll());
- if (document.isObject()) {
- QJsonObject docObject = document.object();
- if (docObject.contains(QLatin1String("offline_icons"))) {
- QJsonObject offlineIconsObject = docObject.value(QLatin1String("offline_icons"))
- .toObject();
- QJsonObject::const_iterator iter;
- for (iter = offlineIconsObject.constBegin(); iter != offlineIconsObject.constEnd(); ++iter) {
- m_restIdToIconHash.insert(iter.key(),
- iter.value().toString() + QLatin1String(".icon"));
- }
- return true;
- }
- }
- }
-
- return false;
-}
-
-void JsonDb::getCategories(const QList<QPlaceCategory> &categories, QObject *parent, const char *slot)
-{
- QStringList categoryUuids;
- foreach (const QPlaceCategory &category, categories)
- categoryUuids.append(category.categoryId());
-
- getCategories(categoryUuids, parent, slot);
-}
-
-void JsonDb::getCategories(const QStringList &uuids, QObject *parent, const char *slot)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(QStringLiteral("[?_type=%type][?_uuid in %categoryUuids]"));
- request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
- request->bindValue(QStringLiteral("categoryUuids"), QJsonArray::fromStringList(uuids));
-
- JsonDb::setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::getChildCategories(const QString &uuid, QObject *parent, const char *slot)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(QStringLiteral("[?_type=%type][?") + JsonDb::CategoryParentId + QStringLiteral("=%uuid]"));
- request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
- request->bindValue(QStringLiteral("uuid"), uuid);
-
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::getCategory(const QString &uuid, QObject *parent, const char *slot)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(QStringLiteral("[?_type=%type][?_uuid=%uuid]"));
- request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
- request->bindValue(QStringLiteral("uuid"), uuid);
-
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::getPlace(const QString &uuid, QObject *parent, const char *slot)
-{
- //TODO: Optimization use QJsonDbReadObject??
- // QJsonDbReadObjectRequest *request = new QJsonDbReadObjectRequest(QUuid(m_placeId), this);
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(QStringLiteral("[?_type=%type][?_uuid=%uuid]"));
- request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
- request->bindValue(QStringLiteral("uuid"), uuid);
-
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::findPlacesByAlternativeId(const QString externalIdName, const QStringList &alternativeIds,
- QObject *parent, const char *slot)
-{
- QString extIdPropertyName = QString(JsonDb::ExtendedAttributes) + QLatin1String(".")
- + externalIdName + QLatin1String(".") +
- JsonDb::Text;
-
- QJsonDbReadRequest *request = new QJsonDbReadRequest(this);
- request->setQuery(QString::fromLatin1("[?_type = %type]")
- + QString::fromLatin1("[?%1 in %alternativeIds]").arg(extIdPropertyName));
- request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
- request->bindValue(QStringLiteral("alternativeIds"), QJsonArray::fromStringList(alternativeIds));
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::findAllPlaces(QObject *parent, const char *slot)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(this);
- request->setQuery(QStringLiteral("[?_type= %type]"));
- request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::read(const QString &query, QObject *parent, const char *slot)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(query);
- setupRequest(request, parent, slot);
- m_connection->send(request);
-}
-
-void JsonDb::write(const QJsonObject &jsonObject, QObject *parent, const char *slot)
-{
- QList<QJsonObject> objects;
- objects << jsonObject;
- write(objects, parent, slot);
-}
-
-void JsonDb::write(const QList<QJsonObject> &jsonObjects, QObject *parent, const char *slot)
-{
- QList<QJsonObject> objects = jsonObjects;
-
- for (int i = 0;i < objects.count(); ++i) {
- if (!objects[i].contains(JsonDb::Uuid))
- objects[i].insert(JsonDb::Uuid, QUuid::createUuid().toString());
- }
-
- QJsonDbWriteRequest *writeRequest = new QJsonDbWriteRequest(parent);
- writeRequest->setObjects(objects);
- setupRequest(writeRequest, parent, slot);
- m_connection->send(writeRequest);
-}
-
-void JsonDb::remove(const QJsonObject &jsonObject, QObject *parent, const char *slot)
-{
- QJsonDbRemoveRequest *removeRequest = new QJsonDbRemoveRequest(jsonObject, parent);
- JsonDb::setupRequest(removeRequest, parent, slot);
- m_connection->send(removeRequest);
-}
-
-void JsonDb::remove(const QList<QJsonObject> &jsonObjects, QObject *parent, const char *slot)
-{
- QJsonDbRemoveRequest *removeRequest = new QJsonDbRemoveRequest(jsonObjects, parent);
- JsonDb::setupRequest(removeRequest, parent, slot);
- m_connection->send(removeRequest);
-}
-
-/*
- Sends off a query to jsondb requesting places which match the search parameters of
- \a request. Note that the \a catSearchIds must be populated as the set of category
- ids given in \a request in addition to all their sub-category ids.
-*/
-void JsonDb::searchForPlaces(const QPlaceSearchRequest &request, QObject *parent, const char *slot,
- const QStringList &catSearchIds)
-{
- QString queryString;
- if (!request.searchTerm().isEmpty()) {
- queryString += QString::fromLatin1("[?%1=\"%2\"][?%3 =~ \"!.*%4.*!i\"]")
- .arg(JsonDb::Type).arg(JsonDb::PlaceType).arg(JsonDb::Name).arg(request.searchTerm());
- }
-
- if (queryString.isEmpty())
- queryString = QString::fromLatin1("[?%1 = \"%2\"]").arg(JsonDb::Type).arg(JsonDb::PlaceType);
-
- if (request.relevanceHint() == QPlaceSearchRequest::LexicalPlaceNameHint)
- queryString += QString::fromLatin1("[/") + JsonDb::Name + QLatin1String("]");
-
- if (!catSearchIds.isEmpty()) {
- queryString += QString::fromLatin1("[?%1 contains \"%2\" ")
- .arg(JsonDb::CategoryUuids)
- .arg(catSearchIds.first());
- for (int i = 1; i < catSearchIds.count(); ++i)
- queryString += QString::fromLatin1(" | %1 contains \"%2\" ")
- .arg(JsonDb::CategoryUuids)
- .arg(catSearchIds.at(i));
- queryString += QLatin1Char(']');
- }
-
- if (request.searchArea().type() == QGeoShape::RectangleType) {
- const double epsilon = 0.0001;
- QGeoRectangle box(request.searchArea());
- double tly = box.topLeft().latitude();
- double bry = box.bottomRight().latitude();
- double tlx = box.topLeft().longitude();
- double brx = box.bottomRight().longitude();
-
- queryString += query(QLatin1String("?location.geo.latitude >= ") + QString::number(bry - epsilon));
- queryString += query(QLatin1String("?location.geo.latitude <= ") + QString::number(tly + epsilon));
-
- bool lonWrap = (tlx > brx); //box wraps over the dateline
-
- if (lonWrap) {
- queryString += query(QLatin1String("?location.geo.longitude >= ") + QString::number(tlx - epsilon)
- + QLatin1String(" | location.geo.longitude <= ") + QString::number(brx + epsilon));
- } else {
- queryString += query(QLatin1String("?location.geo.longitude >= ") + QString::number(tlx - epsilon));
- queryString += query(QLatin1String("?location.geo.longitude <= ") + QString::number(brx + epsilon));
- }
- }
-
- QJsonDbReadRequest *jsonDbRequest = new QJsonDbReadRequest(parent);
- jsonDbRequest->setQuery(queryString);
- setupRequest(jsonDbRequest, parent, slot);
- m_connection->send(jsonDbRequest);
-}
-
-QStringList JsonDb::categoryIds(QList<QPlace> places)
-{
- QStringList uuids;
- foreach (const QPlace &place, places) {
- foreach (const QPlaceCategory &category, place.categories()) {
- if (!category.categoryId().isEmpty() && !uuids.contains(category.categoryId()))
- uuids.append(category.categoryId());
- }
- }
-
- return uuids;
-}
-
-void JsonDb::processPlaceNotifications()
-{
- emit placeNotifications(m_placeWatcher->takeNotifications());
-}
-
-void JsonDb::processCategoryNotifications()
-{
- emit categoryNotifications(m_categoryWatcher->takeNotifications());
-}
-
-void JsonDb::connectionWarning()
-{
- if (m_connection->status() == QJsonDbConnection::Connecting)
- qWarning() << "places_jsondb plugin: could not connect to jsondb daemon, "
- "ensure jsondb daemon is running and restart";
-}
diff --git a/src/plugins/geoservices/places_jsondb/jsondb.h b/src/plugins/geoservices/places_jsondb/jsondb.h
deleted file mode 100644
index ef786bd1..00000000
--- a/src/plugins/geoservices/places_jsondb/jsondb.h
+++ /dev/null
@@ -1,189 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef JSONDB_H
-#define JSONDB_H
-
-#include <QtCore/QJsonObject>
-#include <QtCore/QVariant>
-#include <QtCore/QStringList>
-#include <QtJsonDb/QJsonDbRequest>
-#include <QtJsonDb/QJsonDbNotification>
-#include <QtJsonDb/QJsonDbConnection>
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE_JSONDB
-
-class QPlaceManagerEngineJsonDb;
-class QPlace;
-class QPlaceSearchRequest;
-class QPlaceCategory;
-class QPlaceIcon;
-
-class JsonDb : public QObject {
- Q_OBJECT
-public:
- JsonDb(const QString &partition);
- ~JsonDb();
-
- static void addToJson(QJsonObject *jsonObj, const QPlaceCategory &category);
- static void addToJson(QJsonObject *jsonObj, const QPlace &place);
- static QJsonObject convertToJson(const QPlace &place);
-
- static QList<QPlace> convertJsonObjectsToPlaces(const QList<QJsonObject> &objects, const QPlaceManagerEngineJsonDb *engine);
- static QList<QPlaceCategory> convertJsonObjectsToCategories(const QList<QJsonObject> &objects , const QPlaceManagerEngineJsonDb *engine);
- static QPlace convertJsonObjectToPlace(const QJsonObject &placeJson, const QPlaceManagerEngineJsonDb *engine);
- static QPlaceCategory convertJsonObjectToCategory(const QJsonObject &object, const QPlaceManagerEngineJsonDb *engine);
- static QPlaceIcon convertJsonObjectToIcon(const QJsonObject &thumbnailsJson, const QPlaceManagerEngineJsonDb *engine,
- const QStringList &nokiaCategoryIds = QStringList());
-
- void getCategory(const QString &uuid, QObject *parent, const char *slot);
- void getCategories(const QList<QPlaceCategory> &categories, QObject *parent, const char *slot);
- void getCategories(const QStringList &uuids, QObject *parent, const char *slot);
- void getChildCategories(const QString &uuid, QObject *parent, const char *slot);
- void getPlace(const QString &uuid,QObject *parent, const char * slot);
- void findPlacesByAlternativeId(const QString exernalIdName, const QStringList &alternativeIds, QObject *parent, const char *slot);
- void findAllPlaces(QObject *parent, const char *slot);
-
- void read(const QString &query, QObject *parent, const char *slot);
- void write(const QJsonObject &jsonObject, QObject *parent, const char *slot);
- void write(const QList<QJsonObject> &jsonObjects, QObject *parent, const char *slot);
- void remove(const QJsonObject &jsonObject, QObject *parent, const char *slot);
- void remove(const QList<QJsonObject> &jsonObjects, QObject *parent, const char *slot);
- void searchForPlaces(const QPlaceSearchRequest &request, QObject *parent, const char *slot,
- const QStringList &catSearchIds = QStringList());
-
- void setupRequest(QJsonDbRequest *request, QObject *parent, const char *slot);
-
- static QString query(const QString &expression);
-
- bool parseIconMapping(const QString &fileName);
-
- static QStringList categoryIds(QList<QPlace> places);
-
- static const QLatin1String Uuid;
- static const QLatin1String Type;
- static const QLatin1String Query;
- static const QLatin1String Bindings;
-
- static const QLatin1String Length;
- static const QLatin1String Data;
-
- static const QLatin1String Name;
- static const QLatin1String PlaceType;
- static const QLatin1String CategoryUuids; //only categories that are directly assigned to a place
-
- static const QLatin1String CategoryType;
- static const QLatin1String CategoryParentId;
-
- //coord
- static const QLatin1String Coordinate;
- static const QLatin1String Latitude;
- static const QLatin1String Longitude;
-
- //address
- static const QLatin1String Address;
- static const QLatin1String Street;
- static const QLatin1String District;
- static const QLatin1String City;
- static const QLatin1String County;
- static const QLatin1String State;
- static const QLatin1String Country;
- static const QLatin1String CountryCode;
- static const QLatin1String PostalCode;
-
- static const QLatin1String Location;
-
- //contact details
- static const QLatin1String Phones;
- static const QLatin1String Emails;
- static const QLatin1String Websites;
-
- static const QLatin1String PhoneSubType;
- static const QLatin1String SubTypeFax;
- static const QLatin1String SubTypeLandline;
-
- static const QLatin1String Label;
- static const QLatin1String Value;
- static const QLatin1String Url;
-
- static const QLatin1String ExtendedAttributes;
- static const QLatin1String Text;
- static const QLatin1String NokiaCategoryIds;
-
- static const QLatin1String Height;
- static const QLatin1String Width;
-
- static const QLatin1String Thumbnails;
- static const QLatin1String Small;
- static const QLatin1String Medium;
- static const QLatin1String Large;
- static const QLatin1String Fullscreen;
- static const QLatin1String NokiaIcon;
-
- static const QLatin1String VisibilityScope;
- static const QLatin1String DeviceVisibility;
-
- static const QLatin1String CreatedDateTime;
- static const QLatin1String ModifiedDateTime;
-
-signals:
- void placeNotifications(QList<QJsonDbNotification> notifications);
- void categoryNotifications(QList<QJsonDbNotification> notifications);
- void notificationsError(QtJsonDb::QJsonDbWatcher::ErrorCode code, const QString &errorString);
-
-private slots:
- void processPlaceNotifications();
- void processCategoryNotifications();
- void connectionWarning();
-
-private:
- QtJsonDb::QJsonDbConnection *m_connection;
- QJsonDbWatcher *m_placeWatcher;
- QJsonDbWatcher *m_categoryWatcher;
- QString m_partition;
- QHash<QString, QString> m_restIdToIconHash;
-};
-
-QT_END_NAMESPACE
-
-#endif
-
diff --git a/src/plugins/geoservices/places_jsondb/macro.h b/src/plugins/geoservices/places_jsondb/macro.h
deleted file mode 100644
index 9df50ad9..00000000
--- a/src/plugins/geoservices/places_jsondb/macro.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#define DECLARE_TRIGGER_DONE_FN inline void triggerDone(QPlaceReply::Error error = QPlaceReply::NoError, \
- const QString &errorString = QString()) { \
- if (error != QPlaceReply::NoError) { \
- 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/places_jsondb/matchreply.cpp b/src/plugins/geoservices/places_jsondb/matchreply.cpp
deleted file mode 100644
index 944a9a36..00000000
--- a/src/plugins/geoservices/places_jsondb/matchreply.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "matchreply.h"
-#include "jsondb.h"
-
-#include <QtCore/qnumeric.h>
-#include <QtCore/QJsonArray>
-#include <QtCore/QDebug>
-#include <QtJsonDb/QJsonDbReadRequest>
-
-MatchReply::MatchReply(QPlaceManagerEngineJsonDb *engine)
- : QPlaceMatchReply(engine), m_engine(engine)
-{
-}
-
-MatchReply::~MatchReply()
-{
-}
-
-void MatchReply::setPlaces(const QList<QPlace> &places)
-{
- QPlaceMatchReply::setPlaces(places);
-}
-
-void MatchReply::setRequest(const QPlaceMatchRequest &request)
-{
- QPlaceMatchReply::setRequest(request);
-}
-
-void MatchReply::start()
-{
- if (!request().places().isEmpty()) {
- if (request().parameters().contains(QPlaceMatchRequest::AlternativeId)) {
- QStringList ids;
- foreach (const QPlace &place, request().places())
- ids.append(place.placeId());
-
- db()->findPlacesByAlternativeId(request().parameters().value(QPlaceMatchRequest::AlternativeId).toString(), ids,
- this, SLOT(findByAlternativeIdFinished()));
- } else if (request().parameters().contains(QLatin1String("proximityRange"))) {
- //we need to filter in plugin code so get all places and then filter by proximity
- db()->findAllPlaces(this, SLOT(findByProximityFinished()));
- } else {
- for (int i=0; i < request().places().count(); ++i)
- m_outputPlaces.append(QPlace());
- triggerDone();
- }
- } else {
- triggerDone();
- }
-}
-
-void MatchReply::findByAlternativeIdFinished()
-{
- QJsonDbRequest *jsonDbRequest = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(jsonDbRequest);
- QList<QJsonObject> results = jsonDbRequest->takeResults();
-
- QMap<QString, QPlace> placesMap;
- foreach (const QJsonObject &placeJson, results) {
- QPlace place = JsonDb::convertJsonObjectToPlace(placeJson, m_engine);
- if (!place.placeId().isEmpty()) {
- QString alternativeIdKey = request().parameters().value(QPlaceMatchRequest::AlternativeId).toString();
- placesMap.insert(place.extendedAttribute(alternativeIdKey).text(), place);
- }
- }
-
- foreach (const QPlace &place, request().places())
- m_outputPlaces.append(placesMap.value(place.placeId()));
-
- QStringList categoryUuids = JsonDb::categoryIds(m_outputPlaces);
- if (!categoryUuids.isEmpty()) {
- db()->getCategories(categoryUuids, this, SLOT(getCategoriesForPlacesFinished()));
- } else {
- setPlaces(m_outputPlaces);
- triggerDone();
- }
-}
-
-void MatchReply::findByProximityFinished()
-{
- QJsonDbRequest *jsonDbRequest = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(jsonDbRequest);
- QList<QJsonObject> jsonDbResults = jsonDbRequest->takeResults();
-
- qreal range = request().parameters().value(QLatin1String("proximityRange")).toReal();
-
- //TODO: optimize proximity match
- if (!jsonDbResults.isEmpty()) {
- QList<QPlace> candidatePlaces = JsonDb::convertJsonObjectsToPlaces(jsonDbResults, m_engine);
- foreach (const QPlace &m_inputPlace, request().places()) {
- bool isFound = false;
- foreach (const QPlace &candidatePlace, candidatePlaces) {
- if (m_inputPlace.location().coordinate().isValid() && candidatePlace.location().coordinate().isValid()) {
- qreal dist = candidatePlace.location().coordinate().distanceTo(m_inputPlace.location().coordinate());
- if ((dist < range) || qFuzzyCompare(dist, range)) {
- m_outputPlaces.append(candidatePlace);
- isFound = true;
- break;
- }
- }
- }
- if (!isFound)
- m_outputPlaces.append(QPlace());
- }
- } else {
- //no matches, therefore output places are filled with a default constructed place for each input place
- for (int i = 0; i < request().places().count(); ++i)
- m_outputPlaces.append(QPlace());
- }
-
- QStringList categoryUuids = JsonDb::categoryIds(m_outputPlaces);
- if (!categoryUuids.isEmpty()) {
- db()->getCategories(categoryUuids, this, SLOT(getCategoriesForPlacesFinished()));
- } else {
- setPlaces(m_outputPlaces);
- triggerDone();
- }
-}
-
-void MatchReply::getCategoriesForPlacesFinished()
-{
- QJsonDbRequest *jsonDbRequest = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(jsonDbRequest);
- QList<QJsonObject> jsonDbResults = jsonDbRequest->takeResults();
-
- QMap<QString, QPlaceCategory> categoryMap;
- foreach (const QJsonObject &jsonResult, jsonDbResults) {
- QPlaceCategory category = JsonDb::convertJsonObjectToCategory(jsonResult, m_engine);
- if (!category.categoryId().isEmpty())
- categoryMap.insert(category.categoryId(), category);
- }
-
- for (int i = 0; i < m_outputPlaces.count(); ++i) {
- QList<QPlaceCategory> categories;
- foreach (const QPlaceCategory &category, m_outputPlaces[i].categories()) {
- if (categoryMap.contains(category.categoryId())) {
- categories.append(categoryMap.value(category.categoryId()));
- }
- }
- m_outputPlaces[i].setCategories(categories);
- }
-
- setPlaces(m_outputPlaces);
- triggerDone();
-}
-
-void MatchReply::requestError(QJsonDbRequest::ErrorCode code, const QString &errorString)
-{
- QString errorString_ = QString::fromLatin1("Unknown error occurred operation: jsondb error code =%1, erroString=%2").
- arg(code).arg(errorString);
- triggerDone(QPlaceReply::UnknownError, errorString_);
-}
diff --git a/src/plugins/geoservices/places_jsondb/matchreply.h b/src/plugins/geoservices/places_jsondb/matchreply.h
deleted file mode 100644
index 694558b6..00000000
--- a/src/plugins/geoservices/places_jsondb/matchreply.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef MATCHREPLY_H
-#define MATCHREPLY_H
-
-#include "macro.h"
-#include "qplacemanagerengine_jsondb.h"
-
-#include <qplacematchreply.h>
-
-#include <QObject>
-
-QT_USE_NAMESPACE
-
-class MatchReply : public QPlaceMatchReply
-{
- Q_OBJECT
-
-public:
- MatchReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~MatchReply();
- void setPlaces(const QList<QPlace> &places);
- void setRequest(const QPlaceMatchRequest &request);
-
- DECLARE_TRIGGER_DONE_FN
-
- void start();
-
-protected:
- JsonDb *db() { return m_engine->db(); }
-
-private slots:
- void findByAlternativeIdFinished();
- void findByProximityFinished();
- void getCategoriesForPlacesFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &dbErrorString);
-
-private:
- QPlaceManagerEngineJsonDb *m_engine;
- QList<QPlace> m_outputPlaces;
-};
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/places_jsondb.pro b/src/plugins/geoservices/places_jsondb/places_jsondb.pro
deleted file mode 100644
index d710ff5f..00000000
--- a/src/plugins/geoservices/places_jsondb/places_jsondb.pro
+++ /dev/null
@@ -1,40 +0,0 @@
-TARGET = qtgeoservices_places_jsondb
-QT += location gui network
-
-PLUGIN_TYPE = geoservices
-load(qt_plugin)
-
-HEADERS += \
- qgeoserviceproviderplugin_jsondb.h \
- qplacemanagerengine_jsondb.h \
- jsondb.h \
- matchreply.h \
- searchreply.h \
- detailsreply.h \
- unsupportedreplies.h \
- macro.h \
- idreply.h \
- icon.h \
- iconhandler.h \
- initreply.h \
- traverser.h
-
-SOURCES += \
- qgeoserviceproviderplugin_jsondb.cpp \
- qplacemanagerengine_jsondb.cpp \
- jsondb.cpp \
- matchreply.cpp \
- searchreply.cpp \
- detailsreply.cpp \
- idreply.cpp \
- icon.cpp \
- iconhandler.cpp \
- initreply.cpp \
- traverser.cpp
-
-INCLUDEPATH += $$QT.location.includes
-
-QT += jsondb
-
-OTHER_FILES += \
- places_jsondb_plugin.json
diff --git a/src/plugins/geoservices/places_jsondb/places_jsondb_plugin.json b/src/plugins/geoservices/places_jsondb/places_jsondb_plugin.json
deleted file mode 100644
index 0c208f1e..00000000
--- a/src/plugins/geoservices/places_jsondb/places_jsondb_plugin.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "Keys": ["places_jsondb"],
- "Provider": "places_jsondb",
- "Version": 100,
- "Experimental": false,
- "Features": [
- "OfflinePlacesFeature",
- "SavePlaceFeature",
- "RemovePlaceFeature",
- "SaveCategoryFeature",
- "RemoveCategoryFeature",
- "PlaceMatchingFeature"
- ]
-}
diff --git a/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.cpp b/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.cpp
deleted file mode 100644
index 8b938a32..00000000
--- a/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qgeoserviceproviderplugin_jsondb.h"
-
-#include "qplacemanagerengine_jsondb.h"
-
-#include <QtPlugin>
-
-QT_BEGIN_NAMESPACE
-
-QGeoServiceProviderFactoryJsonDb::QGeoServiceProviderFactoryJsonDb() {}
-
-QGeoServiceProviderFactoryJsonDb::~QGeoServiceProviderFactoryJsonDb() {}
-
-QGeocodingManagerEngine *QGeoServiceProviderFactoryJsonDb::createGeocodingManagerEngine(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString) const
-{
- Q_UNUSED(parameters)
- Q_UNUSED(error)
- Q_UNUSED(errorString)
-
- return 0;
-}
-
-QGeoMappingManagerEngine *QGeoServiceProviderFactoryJsonDb::createMappingManagerEngine(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString) const
-{
- Q_UNUSED(parameters)
- Q_UNUSED(error)
- Q_UNUSED(errorString)
-
- return 0;
-}
-
-QGeoRoutingManagerEngine *QGeoServiceProviderFactoryJsonDb::createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString) const
-{
- Q_UNUSED(parameters)
- Q_UNUSED(error)
- Q_UNUSED(errorString)
-
- return 0;
-}
-
-QPlaceManagerEngine *QGeoServiceProviderFactoryJsonDb::createPlaceManagerEngine(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString) const
-{
- return new QPlaceManagerEngineJsonDb(parameters, error, errorString);
-}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.h b/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.h
deleted file mode 100644
index c4ef8f01..00000000
--- a/src/plugins/geoservices/places_jsondb/qgeoserviceproviderplugin_jsondb.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QGEOSERVICEPROVIDER_JSON_H
-#define QGEOSERVICEPROVIDER_JSON_H
-
-#include <qgeoserviceproviderfactory.h>
-#include <QObject>
-
-QT_BEGIN_NAMESPACE
-
-class QGeoServiceProviderFactoryJsonDb : public QObject, public QGeoServiceProviderFactory
-{
- Q_OBJECT
- Q_INTERFACES(QGeoServiceProviderFactory)
- Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0"
- FILE "places_jsondb_plugin.json")
-
-public:
- QGeoServiceProviderFactoryJsonDb();
- ~QGeoServiceProviderFactoryJsonDb();
-
- 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;
-
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.cpp b/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.cpp
deleted file mode 100644
index d39c89bc..00000000
--- a/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.cpp
+++ /dev/null
@@ -1,473 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qplacemanagerengine_jsondb.h"
-
-#include "traverser.h"
-#include "detailsreply.h"
-#include "idreply.h"
-#include "initreply.h"
-#include "matchreply.h"
-#include "searchreply.h"
-#include "unsupportedreplies.h"
-
-#include <QtCore/QDebug>
-#include <QtCore/QFile>
-#include <QtCore/qnumeric.h>
-#include <QtCore/QMutex>
-#include <QtCore/QMutexLocker>
-#include <QtCore/QStandardPaths>
-#include <QtNetwork/QNetworkAccessManager>
-
-QT_USE_NAMESPACE
-
-Q_DECLARE_METATYPE(QJsonObject);
-
-const QLatin1String QPlaceManagerEngineJsonDb::PartitionKey("places.partition");
-const QLatin1String QPlaceManagerEngineJsonDb::LocalDataPathKey("places.local_data_path");
-
-const QLatin1String QPlaceManagerEngineJsonDb::IconThemeKey("places.icons.theme");
-const QLatin1String QPlaceManagerEngineJsonDb::CustomIconsKey("places.icons.custom");
-const QLatin1String QPlaceManagerEngineJsonDb::FavoriteBadgesKey("places.icons.favorite_badges");
-
-
-QPlaceManagerEngineJsonDb::QPlaceManagerEngineJsonDb(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString)
- : QPlaceManagerEngine(parameters), m_netManager(0)
-{
- qRegisterMetaType<QJsonObject>();
-
- QString partition;
- if (parameters.contains(PartitionKey))
- partition = parameters.value(PartitionKey).toString();
-
- m_jsonDb = new JsonDb(partition);
-
- connect(m_jsonDb, SIGNAL(placeNotifications(QList<QJsonDbNotification>)),
- this, SLOT(processPlaceNotifications(QList<QJsonDbNotification>)));
- connect(m_jsonDb, SIGNAL(categoryNotifications(QList<QJsonDbNotification>)),
- this, SLOT(processCategoryNotifications(QList<QJsonDbNotification>)));
-
- m_localDataPath = parameters.value(LocalDataPathKey, QString()).toString();
- if (m_localDataPath.isEmpty()) {
- QStringList dataLocations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
-
- if (!dataLocations.isEmpty() && !dataLocations.first().isEmpty()) {
- m_localDataPath = dataLocations.first()
- + QLatin1String("/nokia/qtlocation/data");
- }
- }
-
- m_theme = parameters.value(IconThemeKey, QString()).toString();
- if (m_theme == QLatin1String("default"))
- m_theme.clear();
-
- m_useFavoriteBadges = parameters.value(FavoriteBadgesKey).toBool();
-
- if (parameters.contains(CustomIconsKey))
- m_useCustomIcons = parameters.value(CustomIconsKey).toBool();
- else
- m_useCustomIcons = true;
-
- *error = QGeoServiceProvider::NoError;
- errorString->clear();
-}
-
-QPlaceManagerEngineJsonDb::~QPlaceManagerEngineJsonDb()
-{
- delete m_netManager;
- delete m_jsonDb;
-}
-
-QPlaceDetailsReply *QPlaceManagerEngineJsonDb::getPlaceDetails(const QString &placeId)
-{
- DetailsReply *detailsReply = new DetailsReply(this);
- detailsReply->setPlaceId(placeId);
- detailsReply->start();
- return detailsReply;
-}
-
-QPlaceContentReply *QPlaceManagerEngineJsonDb::getPlaceContent(const QString &placeId, const QPlaceContentRequest &request)
-{
- Q_UNUSED(placeId)
- Q_UNUSED(request)
-
- ContentReply *contentReply = new ContentReply(this);
- contentReply->triggerDone(QPlaceReply::UnsupportedError, QString::fromLatin1("Fetching content is unsupported"));
- return contentReply;
-}
-
-QPlaceSearchReply *QPlaceManagerEngineJsonDb::search(const QPlaceSearchRequest &request)
-{
- SearchReply *searchReply = new SearchReply(this);
- searchReply->setRequest(request);
- searchReply->start();
- return searchReply;
-}
-
-QPlaceSearchSuggestionReply *QPlaceManagerEngineJsonDb::searchSuggestions(const QPlaceSearchRequest &request)
-{
- Q_UNUSED(request)
-
- SearchSuggestionReply *searchSuggestionReply = new SearchSuggestionReply(this);
- searchSuggestionReply->triggerDone(QPlaceReply::UnsupportedError, QString::fromLatin1("Search suggestions are unsupported"));
- return searchSuggestionReply;
-}
-
-QPlaceIdReply *QPlaceManagerEngineJsonDb::savePlace(const QPlace &place)
-{
- SavePlaceReply *saveReply = new SavePlaceReply(this);
- saveReply->setPlace(place);
- saveReply->start();
- return saveReply;
-}
-
-QPlaceIdReply *QPlaceManagerEngineJsonDb::saveCategory(const QPlaceCategory &category, const QString &parentId)
-{
- SaveCategoryReply *reply = new SaveCategoryReply(this);
- reply->setCategory(category);
- reply->setParentId(parentId);
- reply->start();
- return reply;
-}
-
-QPlaceIdReply *QPlaceManagerEngineJsonDb::removePlace(const QString &placeId)
-{
- RemovePlaceReply *removeReply = new RemovePlaceReply(this);
- removeReply->setId(placeId);
- removeReply->start();
- return removeReply;
-}
-
-QPlaceIdReply *QPlaceManagerEngineJsonDb::removeCategory(const QString &categoryId)
-{
- RemoveCategoryReply *reply = new RemoveCategoryReply(this);
- reply->setId(categoryId);
- reply->start();
- return reply;
-}
-
-QPlaceReply *QPlaceManagerEngineJsonDb::initializeCategories()
-{
- QString mappingFile = m_localDataPath + QLatin1String("/offline/offline-mapping.json");
-
- m_jsonDb->parseIconMapping(mappingFile);
-
- CategoryInitReply *reply = new CategoryInitReply(this);
- reply->start();
- return reply;
-}
-
-QString QPlaceManagerEngineJsonDb::parentCategoryId(const QString &categoryId) const
-{
- QMutexLocker locker(&m_treeMutex);
- return m_tree.value(categoryId).parentId;
-}
-
-QStringList QPlaceManagerEngineJsonDb::childCategoryIds(const QString &categoryId) const
-{
- QMutexLocker locker(&m_treeMutex);
- QStringList childrenIds = m_tree.value(categoryId).childIds;
- return childrenIds;
-}
-
-QPlaceCategory QPlaceManagerEngineJsonDb::category(const QString &categoryId) const
-{
- QMutexLocker locker(&m_treeMutex);
-
- if (m_tree.contains(categoryId))
- return m_tree.value(categoryId).category;
- else
- return QPlaceCategory();
-}
-
-QList<QPlaceCategory> QPlaceManagerEngineJsonDb::childCategories(const QString &parentId) const
-{
- QMutexLocker locker(&m_treeMutex);
-
- QStringList childrenIds = m_tree.value(parentId).childIds;
- QList<QPlaceCategory> categories;
- foreach (const QString &childId, childrenIds) {
- if (m_tree.contains(childId))
- categories.append(m_tree.value(childId).category);
- }
-
- return categories;
-}
-
-QList<QLocale> QPlaceManagerEngineJsonDb::locales() const
-{
- return QList<QLocale>();
-}
-
-void QPlaceManagerEngineJsonDb::setLocales(const QList<QLocale> &locales)
-{
- Q_UNUSED(locales);
-}
-
-QPlace QPlaceManagerEngineJsonDb::compatiblePlace(const QPlace &original) const
-{
- QPlace place;
- place.setName(original.name());
-
- QGeoLocation location = original.location();
- QGeoCoordinate coord = original.location().coordinate();
- coord.setAltitude(qQNaN());
- location.setCoordinate(coord);
- location.setBoundingBox(QGeoRectangle());
- place.setLocation(location);
-
- QList<QPlaceContactDetail> details;
- foreach (const QString &contactType, original.contactTypes())
- place.setContactDetails(contactType, original.contactDetails(contactType));
-
- place.setVisibility(QLocation::UnspecifiedVisibility);
-
- QStringList attributeTypes = original.extendedAttributeTypes();
- foreach (const QString &attributeType, attributeTypes)
- place.setExtendedAttribute(attributeType, original.extendedAttribute(attributeType));
-
- QString provider = original.extendedAttribute(QLatin1String("x_provider")).text();
- if (!provider.isEmpty()) {
- QPlaceAttribute alternativeId;
- alternativeId.setText(original.placeId());
- place.setExtendedAttribute(QString::fromLatin1("x_id_") + provider,
- alternativeId);
-
- if (provider == QLatin1String("nokia") || provider == QLatin1String("nokia_mos")) {
- QStringList nokiaCategoryIds;
- foreach (const QPlaceCategory &cat, original.categories()) {
- if (!cat.categoryId().isEmpty())
- nokiaCategoryIds.append(cat.categoryId());
- }
-
- if (!nokiaCategoryIds.isEmpty()) {
- QPlaceAttribute nokiaCatIds;
- nokiaCatIds.setText(nokiaCategoryIds.join(QLatin1String(",")));
- place.setExtendedAttribute(QString::fromLatin1("x_nokia_category_ids"), nokiaCatIds);
- }
- }
- }
-
- QVariantMap parameters;
- QPlaceIcon originalIcon = original.icon();
- if (!originalIcon.isEmpty()) {
- if (originalIcon.parameters().contains(QPlaceIcon::SingleUrl)) {
- parameters.insert(JsonDbIcon::MediumSource, originalIcon.url(JsonDbIcon::MediumSize));
- } else if (originalIcon.manager()) {
- if (originalIcon.manager()->managerName() == QLatin1String("nokia") ||
- originalIcon.manager()->managerName() == QLatin1String("nokia_mos")) {
- QString nokiaIcon = originalIcon.parameters()
- .value(JsonDbIcon::NokiaIcon).toString();
- if (!nokiaIcon.isEmpty())
- parameters.insert(JsonDbIcon::NokiaIcon, nokiaIcon);
-
- bool nokiaIconGenerated = originalIcon.parameters()
- .value(JsonDbIcon::NokiaIconGenerated).toBool() == true;
- if (nokiaIconGenerated)
- parameters.insert(JsonDbIcon::NokiaIconGenerated, nokiaIconGenerated);
- } else if (originalIcon.manager()->managerName()
- == QLatin1String("places_jsondb")) {
- parameters = originalIcon.parameters();
- } else {
- if (!originalIcon.url(JsonDbIcon::SmallSize).isEmpty())
- parameters.insert(JsonDbIcon::SmallSource, originalIcon.url(JsonDbIcon::SmallSize));
- if (!originalIcon.url(JsonDbIcon::MediumSize).isEmpty())
- parameters.insert(JsonDbIcon::MediumSource, originalIcon.url(JsonDbIcon::MediumSize));
- if (!originalIcon.url(JsonDbIcon::LargeSize).isEmpty())
- parameters.insert(JsonDbIcon::LargeSource, originalIcon.url(JsonDbIcon::LargeSize));
- }
- }
- }
-
- if (!parameters.isEmpty()) {
- QPlaceIcon icon;
- icon.setParameters(parameters);
- icon.setManager(manager());
- place.setIcon(icon);
- }
-
- return place;
-}
-
-QUrl QPlaceManagerEngineJsonDb::constructIconUrl(const QPlaceIcon &icon, const QSize &size) const
-{
- QUrl iconUrl;
- if (m_useCustomIcons) {
- QList<QPair<int, QUrl> > candidates;
- //TODO: possible optimizations
- QMap<QString, QSize> sizeDictionary;
- sizeDictionary.insert(JsonDbIcon::SmallDestination, JsonDbIcon::SmallSize);
-
- sizeDictionary.insert(JsonDbIcon::MediumDestination, JsonDbIcon::MediumSize);
- sizeDictionary.insert(JsonDbIcon::LargeDestination, JsonDbIcon::LargeSize);
- sizeDictionary.insert(JsonDbIcon::FullscreenDestination, JsonDbIcon::FullscreenSize);
-
- QStringList sizeKeys;
- sizeKeys << "small" << "medium" << "large"
- << "fullscreen";
-
- foreach (const QString &sizeKey, sizeKeys) {
- if (icon.parameters().contains(sizeKey + QLatin1String("Url"))) {
- QSize destSize = icon.parameters().value(sizeKey + QLatin1String("Size")).toSize();
- if (destSize.isEmpty()) {
- candidates.append(QPair<int, QUrl>(sizeDictionary.value(sizeKey + QLatin1String("Url")).height(),
- icon.parameters().value(sizeKey + QLatin1String("Url")).toUrl()));
- } else {
- candidates.append(QPair<int, QUrl>(destSize.height(),
- icon.parameters().value(sizeKey + QLatin1String("Url")).toUrl()));
- }
- }
- }
-
- if (candidates.isEmpty()) {
- iconUrl = QUrl();
- } else if (candidates.count() == 1) {
- iconUrl = candidates.first().second;
- } else {
- //we assume icons are squarish so we can use height to
- //determine which particular icon to return
- int requestedHeight = size.height();
-
- for (int i = 0; i < candidates.count() - 1; ++i) {
- int thresholdHeight = (candidates.at(i).first + candidates.at(i+1).first) / 2;
- if (requestedHeight < thresholdHeight)
- return candidates.at(i).second;
- }
- iconUrl = candidates.last().second;
- }
- } else {
- QString nokiaIcon = icon.parameters().value(JsonDbIcon::NokiaIcon).toString();
- if (!nokiaIcon.isEmpty()) {
- QString nokiaIconPath = m_localDataPath + nokiaIcon;
- if (QFile::exists(nokiaIconPath)) {
- if (nokiaIconPath.contains(QLatin1String("/icons/categories"))) {
- if (m_useFavoriteBadges) {
- nokiaIconPath.replace(QStringLiteral(".icon"),
- QStringLiteral("_01.icon"));
- }
-
- if (!m_theme.isEmpty())
- nokiaIconPath += QLatin1Char('.') + m_theme;
- }
-
- iconUrl = QUrl::fromLocalFile(nokiaIconPath);
- }
- }
- }
-
- return iconUrl;
-}
-
-QPlaceMatchReply * QPlaceManagerEngineJsonDb::matchingPlaces(const QPlaceMatchRequest &request)
-{
- MatchReply *reply = new MatchReply(this);
- reply->setRequest(request);
- reply->start();
- return reply;
-}
-
-void QPlaceManagerEngineJsonDb::setCategoryTree(const CategoryTree &tree)
-{
- QMutexLocker locker(&m_treeMutex);
- m_tree = tree;
-}
-
-QNetworkAccessManager *QPlaceManagerEngineJsonDb::networkAccessManager()
-{
- if (!m_netManager)
- m_netManager = new QNetworkAccessManager(this);
- return m_netManager;
-}
-
-void QPlaceManagerEngineJsonDb::processPlaceNotifications(const QList<QJsonDbNotification> &notifications)
-{
- foreach (const QJsonDbNotification &notification, notifications) {
- if (notification.action() == QJsonDbWatcher::Created)
- emit placeAdded(notification.object().value(JsonDb::Uuid).toString());
- else if (notification.action() == QJsonDbWatcher::Updated)
- emit placeUpdated(notification.object().value(JsonDb::Uuid).toString());
- else if (notification.action() == QJsonDbWatcher::Removed)
- emit placeRemoved(notification.object().value(JsonDb::Uuid).toString());
- }
-}
-
-void QPlaceManagerEngineJsonDb::processCategoryNotifications(const QList<QJsonDbNotification> &notifications)
-{
- m_queuedNotifications.append(notifications);
-
- CategoryTraverser *traverser = new CategoryTraverser(m_jsonDb, this);
- connect(traverser, SIGNAL(finished()), this, SLOT(reinitializeCategories()));
- traverser->start();
-}
-
-void QPlaceManagerEngineJsonDb::notificationsError(QJsonDbWatcher::ErrorCode code, const QString &errorString)
-{
- qWarning() << Q_FUNC_INFO << " Error code: " << code << " Error String: " << errorString;
-}
-
-void QPlaceManagerEngineJsonDb::reinitializeCategories()
-{
- CategoryTraverser *traverser = qobject_cast<CategoryTraverser *>(sender());
- if (traverser->errorString().isEmpty()) {
- CategoryTree tree = CategoryTraverser::convertToTree(traverser->results(), this);
- setCategoryTree(tree);
- } else {
- qWarning() << QString::fromLatin1("Error trying to reinitializing categories "
- "errorString: %1").arg(traverser->errorString());
- }
- traverser->deleteLater();
-
- if (!m_queuedNotifications.isEmpty()) {
- QList<QJsonDbNotification> notifications = m_queuedNotifications.takeFirst();
- foreach (const QJsonDbNotification &notification, notifications) {
- QPlaceCategory category = JsonDb::convertJsonObjectToCategory(notification.object(), this);
- QString parentId = notification.object().value(JsonDb::CategoryParentId).toString();
- if (notification.action() == QJsonDbWatcher::Created)
- emit categoryAdded(category, parentId);
- else if (notification.action() == QJsonDbWatcher::Updated)
- emit categoryUpdated(category, parentId);
- else if (notification.action() == QJsonDbWatcher::Removed)
- emit categoryRemoved(category.categoryId(), parentId);
- }
- }
-}
diff --git a/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.h b/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.h
deleted file mode 100644
index 10a650fb..00000000
--- a/src/plugins/geoservices/places_jsondb/qplacemanagerengine_jsondb.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QPLACEMANAGERENGINE_JSONDB_H
-#define QPLACEMANAGERENGINE_JSONDB_H
-
-#include "jsondb.h"
-
-#include <qplacemanagerengine.h>
-#include <qgeoserviceprovider.h>
-
-#include <QtCore/QEventLoop>
-#include <QtCore/QMutex>
-
-#include <QtJsonDb/QJsonDbConnection>
-#include <QtJsonDb/QJsonDbWatcher>
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE_JSONDB
-
-class QNetworkAccessManager;
-
-struct CategoryNode {
- QString parentId;
- QStringList childIds;
- QPlaceCategory category;
-};
-
-typedef QMap<QString, CategoryNode> CategoryTree;
-
-class QPlaceManagerEngineJsonDb : public QPlaceManagerEngine
-{
- Q_OBJECT
-public:
-
- QPlaceManagerEngineJsonDb(const QMap<QString, QVariant> &parameters, QGeoServiceProvider::Error *error,
- QString *errorString);
- ~QPlaceManagerEngineJsonDb();
-
- QPlaceDetailsReply *getPlaceDetails(const QString &placeId);
-
- QPlaceContentReply *getPlaceContent(const QString &placeId, const QPlaceContentRequest &request);
-
- QPlaceSearchReply *search(const QPlaceSearchRequest &request);
-
- QPlaceSearchSuggestionReply *searchSuggestions(const QPlaceSearchRequest &request);
-
- QPlaceIdReply *savePlace(const QPlace &place);
- QPlaceIdReply *removePlace(const QString &placeId);
-
- QPlaceIdReply *saveCategory(const QPlaceCategory &category, const QString &parentId);
- QPlaceIdReply *removeCategory(const QString &categoryId);
-
- QPlaceMatchReply * matchingPlaces(const QPlaceMatchRequest &request);
-
- QPlaceReply *initializeCategories();
- QString parentCategoryId(const QString &categoryId) const;
- QStringList childCategoryIds(const QString &categoryId) const;
- QPlaceCategory category(const QString &categoryId) const;
-
- QList<QPlaceCategory> childCategories(const QString &parentId) const;
-
- QList<QLocale> locales() const;
- void setLocales(const QList<QLocale> &locales);
-
- QPlace compatiblePlace(const QPlace &original) const;
- QUrl constructIconUrl(const QPlaceIcon &icon, const QSize &size) const;
-
- JsonDb *db() { return m_jsonDb;}
- const JsonDb *db() const { return m_jsonDb;}
- QPlaceManager *manager() const { return QPlaceManagerEngine::manager(); }
- void setCategoryTree(const CategoryTree &tree);
-
- QNetworkAccessManager *networkAccessManager();
- QString localDataPath() const { return m_localDataPath; }
- bool useCustomIcons() const { return m_useCustomIcons; }
-
-private slots:
- void processPlaceNotifications(const QList<QJsonDbNotification> &notifications);
- void processCategoryNotifications(const QList<QJsonDbNotification> &notifications);
- void notificationsError(QtJsonDb::QJsonDbWatcher::ErrorCode code, const QString &errorString);
- void reinitializeCategories();
-
-private:
- JsonDb *m_jsonDb;
-
- mutable QMutex m_treeMutex;
- CategoryTree m_tree;
- QNetworkAccessManager *m_netManager;
-
- QString m_localDataPath;
- QString m_theme;
- bool m_useFavoriteBadges;
- bool m_useCustomIcons;
-
- QList<QList<QJsonDbNotification> > m_queuedNotifications;
-
- static const QLatin1String PartitionKey;
- static const QLatin1String LocalDataPathKey;
-
- static const QLatin1String IconThemeKey;
- static const QLatin1String CustomIconsKey;
- static const QLatin1String FavoriteBadgesKey;
-
- friend class SaveReply;
- friend class MediaReply;
- friend class RemoveReply;
- friend class SearchSuggestionReply;
- friend class ReviewReply;
- friend class Reply;
- friend class SearchReply;
- friend class CategoryInitReply;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/searchreply.cpp b/src/plugins/geoservices/places_jsondb/searchreply.cpp
deleted file mode 100644
index 0ca27d9d..00000000
--- a/src/plugins/geoservices/places_jsondb/searchreply.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "searchreply.h"
-#include "traverser.h"
-
-#include <QtCore/qnumeric.h>
-#include <QtCore/QDebug>
-#include <QtLocation/QGeoCircle>
-#include <QtJsonDb/QJsonDbReadRequest>
-#include <QtLocation/QPlaceResult>
-
-SearchReply::SearchReply(QPlaceManagerEngineJsonDb *engine)
- : QPlaceSearchReply(engine), m_engine(engine)
-{
-}
-
-SearchReply::~SearchReply()
-{
-}
-
-void SearchReply::setResults(const QList<QPlaceResult> &results)
-{
- QList<QPlaceSearchResult> searchResults;
- foreach (const QPlaceResult &placeResult, results) {
- searchResults << placeResult;
- }
-
- QPlaceSearchReply::setResults(searchResults);
-}
-
-void SearchReply::setRequest(const QPlaceSearchRequest &request)
-{
- QPlaceSearchReply::setRequest(request);
-}
-
-void SearchReply::start()
-{
- if (request().searchArea().type() == QGeoShape::RectangleType) {
- QGeoRectangle box(request().searchArea());
- if (!box.isValid()) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("Bounding box search area is invalid"));
- return;
- }
- } else if (request().searchArea().type() == QGeoShape::CircleType) {
- QGeoCircle circle(request().searchArea());
- if (!circle.center().isValid() || qIsNaN(circle.center().latitude()) || qIsNaN(circle.center().longitude())) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("The center of the search area is an invalid coordinate"));
- return;
- }
- if (circle.contains(QGeoCoordinate(90,0)) || circle.contains(QGeoCoordinate(-90,0))) {
- triggerDone(QPlaceReply::BadArgumentError,
- QString::fromLatin1("The search area contains the north or south pole"));
- return;
- }
- }
-
- if (!request().categories().isEmpty()) {
- foreach (const QPlaceCategory &category, request().categories()) {
- m_catSearchIds.append(categorySearchIds(category.categoryId()));
- db()->searchForPlaces(request(), this, SLOT(searchFinished()), m_catSearchIds);
- }
- } else {
- db()->searchForPlaces(request(), this, SLOT(searchFinished()));
- }
-}
-
-QStringList SearchReply::categorySearchIds(const QString &catId)
-{
- QStringList ids;
- ids << catId;
- QStringList childIds = m_engine->childCategoryIds(catId);
- foreach (const QString &childId, childIds)
- ids.append(categorySearchIds(childId));
-
- return ids;
-}
-
-static bool lessThanDistance(const QPlaceSearchResult &p0, const QPlaceSearchResult &p1)
-{
- Q_ASSERT(p0.type() == QPlaceSearchResult::PlaceResult);
- Q_ASSERT(p1.type() == QPlaceSearchResult::PlaceResult);
- QPlaceResult r0 = p0;
- QPlaceResult r1 = p1;
-
- return r0.distance() < r1.distance();
-}
-
-static bool lessThanName(const QPlaceSearchResult &p0, const QPlaceSearchResult &p1)
-{
- return p0.title() < p1.title();
-}
-
-void SearchReply::searchFinished()
-{
- QJsonDbRequest *jsonDbRequest = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(jsonDbRequest);
- QList<QJsonObject> jsonResults = jsonDbRequest->takeResults();
-
- QList<QPlace> places = JsonDb::convertJsonObjectsToPlaces(jsonResults, m_engine);
- QList<QPlaceResult> results;
- QPlaceResult result;
-
- const QGeoShape &area = request().searchArea();
- const QGeoShape::ShapeType &type = area.type();
- const QGeoCoordinate &center = type == QGeoShape::CircleType ? static_cast<QGeoCircle>(area).center() :
- type == QGeoShape::RectangleType ? static_cast<QGeoRectangle>(area).center() :
- QGeoCoordinate();
- const bool noDistanceFilter = type == QGeoShape::UnknownType
- || (type == QGeoShape::CircleType
- && static_cast<QGeoCircle>(area).radius() < 0.0);
-
- // First filter the results
- foreach (const QPlace &place, places) {
- const QGeoCoordinate &coord = place.location().coordinate();
- if (noDistanceFilter || area.contains(coord)) {
- // distance is invalid if center is invalid/not set
- qreal distance = center.distanceTo(coord);
- result.setTitle(place.name());
- result.setIcon(place.icon());
- result.setPlace(place);
- result.setDistance(distance);
- results.append(result);
- }
- }
-
- // Now sort the result set
- switch (request().relevanceHint() ) {
- case QPlaceSearchRequest::DistanceHint:
- qSort(results.begin(), results.end(), lessThanDistance);
- break;
- case QPlaceSearchRequest::LexicalPlaceNameHint:
- qSort(results.begin(), results.end(), lessThanName);
- break;
- default:
- break;
- }
-
- setResults(results);
-
- //See if we have to fetch any category data
- QStringList categoryUuids;
- foreach (const QPlaceResult &result, results) {
- if (!result.place().categories().isEmpty()) {
- foreach (const QPlaceCategory &category, result.place().categories())
- categoryUuids.append(category.categoryId());
- }
- categoryUuids.removeDuplicates();
- }
-
- if (!categoryUuids.isEmpty()) {
- db()->getCategories(categoryUuids,
- this, SLOT(getCategoriesForPlacesFinished()));
- return;
- } else {
- triggerDone();
- return;
- }
-}
-
-void SearchReply::getCategoriesForPlacesFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
- QList<QJsonObject> jsonResults = request->takeResults();
-
- QMap<QString, QPlaceCategory> categoriesCollection;
- foreach (const QJsonObject &categoryJson, jsonResults) {
- if (!categoriesCollection.contains(categoryJson.value(JsonDb::Uuid).toString())) {
- QPlaceCategory category = JsonDb::convertJsonObjectToCategory(categoryJson, m_engine);
- categoriesCollection.insert(category.categoryId(), category);
- }
- }
-
- QList<QPlaceSearchResult> resultList = results();
- QList<QPlaceCategory> categories;
- QPlace place;
- for (int i=0; i < resultList.count(); ++i) {
- categories.clear();
- place = static_cast<QPlaceResult>(resultList.at(i)).place();
- foreach (const QPlaceCategory &cat, place.categories()) {
- if (!cat.categoryId().isEmpty() && categoriesCollection.contains(cat.categoryId()))
- categories.append(categoriesCollection.value(cat.categoryId()));
- }
- place.setCategories(categories);
- static_cast<QPlaceResult &>(resultList[i]).setPlace(place);
- }
- setResults(resultList);
- triggerDone();
- return;
-}
-
-void SearchReply::requestError(QJsonDbRequest::ErrorCode code, const QString &errorString)
-{
- QString errorString_ = QString::fromLatin1("Unknown error occurred operation: jsondb error code =%1, erroString=%2").
- arg(code).arg(errorString);
- triggerDone(QPlaceReply::UnknownError, errorString_);
-}
diff --git a/src/plugins/geoservices/places_jsondb/searchreply.h b/src/plugins/geoservices/places_jsondb/searchreply.h
deleted file mode 100644
index 418ab76a..00000000
--- a/src/plugins/geoservices/places_jsondb/searchreply.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef SEARCHREPLY_H
-#define SEARCHREPLY_H
-
-#include "macro.h"
-#include "qplacemanagerengine_jsondb.h"
-
-
-
-#include <QtCore/QObject>
-#include <QtJsonDb/QJsonDbRequest>
-#include <QtLocation/QPlaceResult>
-#include <QtLocation/QPlaceSearchReply>
-
-QT_BEGIN_NAMESPACE
-
-class SearchReply : public QPlaceSearchReply
-{
- Q_OBJECT
-
-public:
- SearchReply(QPlaceManagerEngineJsonDb *engine);
- virtual ~SearchReply();
- void setResults(const QList<QPlaceResult> &results);
- using QPlaceSearchReply::setResults;
- void setRequest(const QPlaceSearchRequest &request);
-
- DECLARE_TRIGGER_DONE_FN
-
- void start();
-
-protected:
- JsonDb *db() { return m_engine->db(); }
-
-private slots:
- //first perform search for places, then retrieve category
- //information for received places
- void searchFinished();
- void getCategoriesForPlacesFinished();
-
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode code, const QString &dbErrorString);
-
-private:
- QJsonDbRequest *searchRequest(const QPlaceSearchRequest &request);
- QStringList categorySearchIds(const QString &childId);
-
- QPlaceManagerEngineJsonDb *m_engine;
- QStringList m_catSearchIds;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/traverser.cpp b/src/plugins/geoservices/places_jsondb/traverser.cpp
deleted file mode 100644
index dca40982..00000000
--- a/src/plugins/geoservices/places_jsondb/traverser.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "jsondb.h"
-#include "traverser.h"
-
-CategoryTraverser::CategoryTraverser(JsonDb *db, QObject *parent)
- : QObject(parent), m_db(db)
-{
- Q_ASSERT(m_db);
-}
-
-void CategoryTraverser::start(const QString &rootId)
-{
- m_rootId = rootId;
-
- if (!rootId.isEmpty()) {
- m_db->getCategory(rootId, this, SLOT(rootCategoryFinished()));
- } else {
- m_catIdQueue.append(rootId);
- processQueue();
- }
-}
-
-CategoryTree CategoryTraverser::convertToTree(const QList<QJsonObject> &catObjects,
- const QPlaceManagerEngineJsonDb *engine)
-{
- CategoryTree tree;
- tree.insert(QString(), CategoryNode());
-
- //first pass to populate the tree
- foreach (const QJsonObject &catObject, catObjects) {
- CategoryNode node;
- QPlaceCategory category = JsonDb::convertJsonObjectToCategory(catObject, engine);
- node.category = category;
- tree.insert(category.categoryId(), node);
- }
-
- //second pass to assign parent and children ids
- foreach (const QJsonObject &catObject, catObjects) {
- QString parentId = catObject.value(JsonDb::CategoryParentId).toString();
- QString childId = catObject.value(JsonDb::Uuid).toString();
- if (!tree.contains(parentId) || !tree.contains(childId))
- continue;
-
- QStringList childIds = tree.value(parentId).childIds;
- childIds += childId;
- tree[parentId].childIds = childIds;
-
- tree[childId].parentId = parentId;
- }
-
- return tree;
-}
-
-void CategoryTraverser::processQueue()
-{
- if (!m_catIdQueue.isEmpty()) {
- QString categoryId = m_catIdQueue.takeFirst();
- m_db->getChildCategories(categoryId, this, SLOT(requestFinished()));
- } else {
- emit finished();
- return;
- }
-}
-
-void CategoryTraverser::rootCategoryFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
-
- QList<QJsonObject> objects = request->takeResults();
-
- if (objects.isEmpty()) {
- m_errorString = QString::fromLatin1("Specified category not found: %1")
- .arg(m_rootId);
- emit finished();
- return;
- }
-
- QJsonObject object = objects.takeFirst();
- QString rootId = object.value(JsonDb::Uuid).toString();
- if (rootId != m_rootId) {
- m_errorString = QString::fromLatin1("Retrieved category does not match expected "
- "category, expectedId: %1, actualId %2")
- .arg(m_rootId)
- .arg(object.value(JsonDb::Uuid).toString());
- emit finished();
- return;
- }
-
- m_catObjs.append(object);
- m_catIdQueue.append(rootId);
- processQueue();
-}
-
-void CategoryTraverser::requestFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- Q_ASSERT(request);
-
- QList<QJsonObject> objects = request->takeResults();
- foreach (const QJsonObject &object, objects) {
- QString categoryId = object.value(JsonDb::Uuid).toString();
- if (object.value(JsonDb::Type).toString() == JsonDb::CategoryType
- && !categoryId.isEmpty()) {
- m_catObjs.append(object);
- m_catIdQueue.append(categoryId);
- }
- }
- processQueue();
-}
-
-void CategoryTraverser::requestError(QJsonDbRequest::ErrorCode dbCode, const QString &dbErrorString)
-{
- m_errorString = QString::fromLatin1("JsonDb error code: %1\n"
- "JsonDb error string: %2")
- .arg(dbCode).arg(dbErrorString);
- emit finished();
-}
-
diff --git a/src/plugins/geoservices/places_jsondb/traverser.h b/src/plugins/geoservices/places_jsondb/traverser.h
deleted file mode 100644
index b5815636..00000000
--- a/src/plugins/geoservices/places_jsondb/traverser.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef TRAVERSER_H
-#define TRAVERSER_H
-
-#include "qplacemanagerengine_jsondb.h"
-
-#include <QtCore/QHash>
-#include <QtCore/QJsonObject>
-#include <QtCore/QStringList>
-#include <QtJsonDb/QJsonDbRequest>
-
-QT_BEGIN_NAMESPACE
-
-class JsonDb;
-
-class CategoryTraverser : public QObject
-{
- Q_OBJECT
-public:
- CategoryTraverser(JsonDb *db, QObject *parent = 0);
- void start(const QString &rootId = QString());
- QList<QJsonObject> results() { return m_catObjs; }
-
- QString errorString() { return m_errorString; }
-
- static CategoryTree convertToTree(const QList<QJsonObject> &catObjects,
- const QPlaceManagerEngineJsonDb *engine);
-
-Q_SIGNALS:
- void finished();
-
-private slots:
- void rootCategoryFinished();
- void requestFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode dbCode,
- const QString &dbErrorString);
-
-private:
- void processQueue();
- QList<QJsonObject> m_catObjs;
- JsonDb *m_db;
- QString m_rootId;
- QStringList m_catIdQueue;
- QString m_errorString;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/plugins/geoservices/places_jsondb/unsupportedreplies.h b/src/plugins/geoservices/places_jsondb/unsupportedreplies.h
deleted file mode 100644
index e9d914e3..00000000
--- a/src/plugins/geoservices/places_jsondb/unsupportedreplies.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef UNSUPPORTED_REPLIES_H
-#define UNSUPPORTED_REPLIES_H
-
-#include <qplacecontentreply.h>
-#include <qplacesearchsuggestionreply.h>
-
-#include "macro.h"
-#include "qplacemanagerengine_jsondb.h"
-
-QT_BEGIN_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 SearchSuggestionReply : public QPlaceSearchSuggestionReply
-{
- Q_OBJECT
-public:
- SearchSuggestionReply(QPlaceManagerEngineJsonDb *engine)
- : QPlaceSearchSuggestionReply(engine), m_engine(engine)
- {}
- virtual ~SearchSuggestionReply() {}
-
- DECLARE_TRIGGER_DONE_FN
-
-private:
- QPlaceManagerEngineJsonDb *m_engine;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 9ac74891..ff6ca81c 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -73,5 +73,3 @@ qtHaveModule(3d) {
nokia_services \
qgeocameratiles
}
-
-qtHaveModule(jsondb): SUBDIRS += qplacemanager_jsondb
diff --git a/tests/auto/qplacemanager_jsondb/jsondbutils.cpp b/tests/auto/qplacemanager_jsondb/jsondbutils.cpp
deleted file mode 100644
index f328dbf1..00000000
--- a/tests/auto/qplacemanager_jsondb/jsondbutils.cpp
+++ /dev/null
@@ -1,414 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "jsondbutils.h"
-
-#include <QtJsonDb/QJsonDbReadRequest>
-#include <QtJsonDb/QJsonDbRemoveRequest>
-#include <QtJsonDb/QJsonDbWriteRequest>
-
-#include <QDebug>
-#include <QMap>
-#include <QString>
-#include <QStringList>
-#include <QLocalSocket>
-#include <QDir>
-#include <QTest>
-#include <QSignalSpy>
-#include <QUuid>
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#ifndef WAIT_UNTIL
-#define WAIT_UNTIL(__expr) \
- do { \
- const int __step = 50; \
- const int __timeout = 10000; \
- if (!(__expr)) { \
- QTest::qWait(0); \
- } \
- for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
- QTest::qWait(__step); \
- } \
- } while (0)
-#endif
-
-const QLatin1String JsonDbUtils::Uuid("_uuid");
-const QLatin1String JsonDbUtils::Type("_type");
-
-const QLatin1String JsonDbUtils::Name("displayName");
-const QLatin1String JsonDbUtils::PlaceType("com.nokia.mt.location.Place");
-
-//only categories that are directly assigned to a place
-const QLatin1String JsonDbUtils::CategoryUuids("categoryUuids");
-
-//all categories that a place belongs to,
-//it includes all ancestors of the assigned categories
-const QLatin1String JsonDbUtils::AllCategoryUuids("allCategoryUuids");
-
-const QLatin1String JsonDbUtils::CategoryType("com.nokia.mt.location.PlaceCategory");
-
-//includes all ancestor category ids and also the current category id
-//as the last object. The first category is a top level category id.
-const QLatin1String JsonDbUtils::Lineage("lineageUuids");
-
-const QLatin1String JsonDbUtils::CategoryParentId("parentUuid");
-
-const QLatin1String JsonDbUtils::NotificationType("notification");
-const QLatin1String JsonDbUtils::Actions("actions");
-
-//coord
-const QLatin1String JsonDbUtils::Coordinate("geo");
-const QLatin1String JsonDbUtils::Latitude("latitude");
-const QLatin1String JsonDbUtils::Longitude("longitude");
-
-//address
-const QLatin1String JsonDbUtils::Address("address");
-const QLatin1String JsonDbUtils::Street("street");
-const QLatin1String JsonDbUtils::District("district");
-const QLatin1String JsonDbUtils::City("locality");
-const QLatin1String JsonDbUtils::County("county");
-const QLatin1String JsonDbUtils::State("region");
-const QLatin1String JsonDbUtils::Country("country");
-const QLatin1String JsonDbUtils::CountryCode("countryCode");
-const QLatin1String JsonDbUtils::PostalCode("postalCode");
-
-const QLatin1String JsonDbUtils::Location("location");
-
-//contact details
-const QLatin1String JsonDbUtils::Phones("phones");
-const QLatin1String JsonDbUtils::Emails("emails");
-const QLatin1String JsonDbUtils::Websites("urls");
-
-const QLatin1String JsonDbUtils::PhoneSubType("subType");
-const QLatin1String JsonDbUtils::SubTypeFax("fax");
-const QLatin1String JsonDbUtils::SubTypeLandline("landline");
-
-const QLatin1String JsonDbUtils::Label("label");
-const QLatin1String JsonDbUtils::Value("value");
-const QLatin1String JsonDbUtils::Url("url");
-
-const QLatin1String JsonDbUtils::ExtendedAttributes("extendedAttributes");
-const QLatin1String JsonDbUtils::Text("text");
-
-const QLatin1String JsonDbUtils::Height("height");
-const QLatin1String JsonDbUtils::Width("width");
-
-const QLatin1String JsonDbUtils::Thumbnails("thumbnails");
-const QLatin1String JsonDbUtils::Small("small");
-const QLatin1String JsonDbUtils::Medium("medium");
-const QLatin1String JsonDbUtils::Large("large");
-const QLatin1String JsonDbUtils::Fullscreen("fullscreen");
-
-const QLatin1String JsonDbUtils::SmallIconParam("smallUrl");
-const QLatin1String JsonDbUtils::MediumIconParam("mediumUrl");
-const QLatin1String JsonDbUtils::LargeIconParam("largeUrl");
-const QLatin1String JsonDbUtils::FullscreenIconParam("fullscreenUrl");
-
-const QLatin1String JsonDbUtils::SmallIconSizeParam("smallSize");
-const QLatin1String JsonDbUtils::MediumIconSizeParam("mediumSize");
-const QLatin1String JsonDbUtils::LargeIconSizeParam("largeSize");
-const QLatin1String JsonDbUtils::FullscreenIconSizeParam("fullscreenSize");
-
-const QLatin1String JsonDbUtils::CreatedDateTime("createdDateTime");
-const QLatin1String JsonDbUtils::ModifiedDateTime("modifiedDateTime");
-
-const QLatin1String JsonDbUtils::DefaultPartition("");
-const QLatin1String JsonDbUtils::PartitionType("Partition");
-
-const QLatin1String JsonDbUtils::LongitudeIndex("placeLongitudeIndex");
-const QLatin1String JsonDbUtils::LatitudeIndex("placeLatitudeIndex");
-const QLatin1String JsonDbUtils::PlaceNameIndex("placeDisplayNameIndex");
-
-JsonDbUtils::JsonDbUtils(QObject *parent)
- : QObject(parent)
-{
- QStringList args;
- args <<"-reject-stale-updates";
- m_jsondbProcess = launchJsonDbDaemon(args);
- m_connection = new QJsonDbConnection;
- m_connection->connectToServer();
-}
-
-JsonDbUtils::~JsonDbUtils()
-{
- if (m_jsondbProcess)
- m_jsondbProcess->kill();
-}
-
-void JsonDbUtils::cleanDb()
-{
- QJsonDbReadRequest *getPlacesRequest = new QJsonDbReadRequest(this);
- getPlacesRequest->setPartition(m_currentPartition);
- getPlacesRequest->setQuery(QString::fromLatin1("[?%1=\"%2\"]")
- .arg(Type).arg(PlaceType));
-
- setupRequest(getPlacesRequest, this, SLOT(getPlacesFinished()));
- m_connection->send(getPlacesRequest);
-}
-
-void JsonDbUtils::sendRequest(QJsonDbRequest *request)
-{
- connect(request, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- m_connection->send(request);
-}
-
-QList<QJsonObject> JsonDbUtils::results()
-{
- return m_results;
-}
-
-void JsonDbUtils::fetchPlaceJson(const QString &uuid)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(this);
- request->setPartition(m_currentPartition);
- request->setQuery(QStringLiteral("[?_type=%type][?_uuid=%uuid]"));
- request->bindValue(QStringLiteral("type"), PlaceType);
- request->bindValue(QStringLiteral("uuid"), uuid);
- setupRequest(request, this, SLOT(fetchPlaceJsonFinished()));
- m_connection->send(request);
-}
-
-void JsonDbUtils::savePlaceJson(const QJsonObject &object)
-{
- QJsonDbWriteRequest *request = new QJsonDbWriteRequest(this);
- request->setPartition(m_currentPartition);
- QList<QJsonObject> objects;
- objects << object;
- request->setObjects(objects);
- setupRequest(request, this, SLOT(savePlaceJsonFinished()));
- m_connection->send(request);
-}
-
-bool JsonDbUtils::hasJsonDbConnection() const
-{
- return m_jsondbProcess &&
- m_connection &&
- m_connection->status() == QtJsonDb::QJsonDbConnection::Connected;
-}
-
-void JsonDbUtils::setCurrentPartition(const QString &partition)
-{
- m_currentPartition = partition;
-}
-
-void JsonDbUtils::setupPartition(const QString &partition)
-{
- QJsonDbReadRequest *readPartitionRequest = new QJsonDbReadRequest();
- readPartitionRequest->setQuery(QStringLiteral("[?_type=%type][?name=%name]"));
- readPartitionRequest->bindValue(QStringLiteral("type"), JsonDbUtils::PartitionType);
- readPartitionRequest->bindValue(QStringLiteral("name"), partition);
- QSignalSpy readSpy(readPartitionRequest, SIGNAL(finished()));
- sendRequest(readPartitionRequest);
- WAIT_UNTIL(readSpy.count() == 1);
- if (readSpy.isEmpty()) {
- qWarning() << "No finished signal emitted when trying to read partition: " << partition;
- return;
- }
-
- QList<QJsonObject> results = readPartitionRequest->takeResults();
- if (results.isEmpty()) {
- //create user partition because it doesn't exist
- QJsonObject userPartition;
- userPartition.insert(JsonDbUtils::Uuid, QUuid::createUuid().toString());
- userPartition.insert(JsonDbUtils::Type, JsonDbUtils::PartitionType);
- userPartition.insert(QLatin1String("name"), partition);
-
- QJsonDbWriteRequest *writePartitionRequest = new QJsonDbWriteRequest(this);
- QList<QJsonObject> objects;
- objects << userPartition;
- writePartitionRequest->setObjects(objects);
-
- QSignalSpy writeSpy(writePartitionRequest, SIGNAL(finished()));
- sendRequest(writePartitionRequest);
- WAIT_UNTIL(writeSpy.count() == 1);
- if (writeSpy.isEmpty()) {
- qWarning() << "No finished signal emitted when trying to create partition: " << partition;
- return;
- }
- }
-
- QMetaObject::invokeMethod(this, "partitionSetupDone", Qt::QueuedConnection);
-}
-
-void JsonDbUtils::getPlacesFinished()
-{
- QList<QJsonObject> results = qobject_cast<QJsonDbReadRequest *>(sender())
- ->takeResults();
-
- if (!results.isEmpty()) {
- QJsonDbRemoveRequest *removePlacesRequest
- = new QJsonDbRemoveRequest(results, this);
- setupRequest(removePlacesRequest,this, SLOT(removePlacesFinished()));
- m_connection->send(removePlacesRequest);
- } else {
- removePlacesFinished();
- }
-}
-
-void JsonDbUtils::removePlacesFinished()
-{
- QJsonDbReadRequest *getCategoriesRequest = new QJsonDbReadRequest(this);
- getCategoriesRequest->setPartition(m_currentPartition);
- getCategoriesRequest->setQuery(QString::fromLatin1("[?%1=\"%2\"]")
- .arg(Type).arg(CategoryType));
- setupRequest(getCategoriesRequest,this, SLOT(getCategoriesFinished()));
- m_connection->send(getCategoriesRequest);
-}
-
-void JsonDbUtils::getCategoriesFinished()
-{
- QList<QJsonObject> results = qobject_cast<QJsonDbReadRequest *>(sender())
- ->takeResults();
- if (!results.isEmpty()) {
- QJsonDbRemoveRequest *removeCategoriesRequest
- = new QJsonDbRemoveRequest(results, this);
- setupRequest(removeCategoriesRequest, this, SLOT(removeCategoriesFinished()));
- m_connection->send(removeCategoriesRequest);
- } else {
- removeCategoriesFinished();
- }
-}
-
-void JsonDbUtils::removeCategoriesFinished()
-{
- emit dbCleaned();
-}
-
-void JsonDbUtils::fetchPlaceJsonFinished()
-{
- QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- QList<QJsonObject> results = request->takeResults();
- if (results.count() == 1)
- emit placeFetched(results.first());
- else
- emit placeFetched(QJsonObject());
-}
-
-void JsonDbUtils::savePlaceJsonFinished()
-{
- emit placeSaved();
-}
-
-void JsonDbUtils::requestError(QJsonDbRequest::ErrorCode error,
- const QString &errorString)
-{
- qWarning() << Q_FUNC_INFO << QStringLiteral(" Error code: ") << error
- << QStringLiteral(" Error String: ") << errorString;
-}
-
-void JsonDbUtils::setupRequest(QJsonDbRequest *request, QObject *parent,
- const char *slot)
-{
- Q_ASSERT(request);
- Q_ASSERT(parent);
- Q_ASSERT(slot);
-
- QObject::connect(request, SIGNAL(finished()), parent, slot);
-
- QObject::connect(request, SIGNAL(finished()), request, SLOT(deleteLater()));
- QObject::connect(request,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- parent,
- SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- QObject::connect(request,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- request,
- SLOT(deleteLater()));
- request->setPartition(m_currentPartition);
-}
-
-QProcess* JsonDbUtils::launchJsonDbDaemon(const QStringList &args)
-{
- const QString socketName = QString("tst_qplacemanger_jsondb_%1").arg(getpid());
- QString jsondb_app = QString::fromLocal8Bit(JSONDB_DAEMON_BASE) + QDir::separator() + "jsondb";
- if (!QFile::exists(jsondb_app))
- jsondb_app = QLatin1String("jsondb"); // rely on the PATH
-
- QProcess *process = new QProcess;
- process->setProcessChannelMode( QProcess::ForwardedChannels );
-
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- env.insert("JSONDB_SOCKET", socketName);
- process->setProcessEnvironment(env);
- ::setenv("JSONDB_SOCKET", qPrintable(socketName), 1);
- qDebug() << "Starting process" << jsondb_app << args << "with socket" << socketName;
- process->start(jsondb_app, args);
- if (!process->waitForStarted())
- qFatal("Unable to start jsondb database process");
-
- /* Wait until the jsondb is accepting connections */
- int tries = 0;
- bool connected = false;
- while (!connected && tries++ < 100) {
- QLocalSocket socket;
- socket.connectToServer(socketName);
- if (socket.waitForConnected())
- connected = true;
- QTest::qWait(250);
- }
-
- if (!connected)
- qFatal("Unable to connect to jsondb process");
-
- //Start jsondb-client and get it to load a prepopulation file that contains
- //Indexes
- QProcess *prepopulateProcess = new QProcess;
- prepopulateProcess->setProcessEnvironment(env);
-
- QString jsondb_client = QString::fromLocal8Bit(JSONDB_DAEMON_BASE)
- + QDir::separator() + "jsondb-client";
- if (!QFile::exists(jsondb_client))
- jsondb_client = QLatin1String("jsondb-client"); // rely on the PATH
- QStringList clientArgs;
- clientArgs << QLatin1String("-load");
- clientArgs << QLatin1String(JSONFILE);
- clientArgs << QLatin1String("-terminate");
- prepopulateProcess->setProcessChannelMode( QProcess::ForwardedChannels);
- prepopulateProcess->start(jsondb_client, clientArgs);
-
- if (!prepopulateProcess->waitForFinished())
- qFatal("Unable to complete loading index via jsondb-client");
-
- return process;
-}
diff --git a/tests/auto/qplacemanager_jsondb/jsondbutils.h b/tests/auto/qplacemanager_jsondb/jsondbutils.h
deleted file mode 100644
index ae5802e3..00000000
--- a/tests/auto/qplacemanager_jsondb/jsondbutils.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef JSONDBUTILS_H
-#define JSONDBUTILS_H
-
-#include <QObject>
-#include <QMap>
-#include <QVariant>
-#include <QEventLoop>
-#include <QProcess>
-
-#include <QtCore/QJsonObject>
-#include <QtJsonDb/QJsonDbConnection>
-#include <QtJsonDb/QJsonDbRequest>
-
-QT_USE_NAMESPACE_JSONDB
-
-class JsonDbUtils : public QObject
-{
- Q_OBJECT
-public:
- JsonDbUtils(QObject *parent = 0);
- ~JsonDbUtils();
-
- void cleanDb();
- void sendRequest(QJsonDbRequest *request);
-
- QList<QJsonObject> results();
- void fetchPlaceJson(const QString &uuid);
- void savePlaceJson(const QJsonObject &object);
- bool hasJsonDbConnection() const;
- void setCurrentPartition(const QString &partition);
-
- static const QLatin1String Uuid;
- static const QLatin1String Type;
- static const QLatin1String Query;
- static const QLatin1String Bindings;
-
- static const QLatin1String Length;
- static const QLatin1String Data;
-
- static const QLatin1String Name;
- static const QLatin1String PlaceType;
- static const QLatin1String CategoryUuids; //only categories that are directly assigned to a place
- static const QLatin1String AllCategoryUuids; //all categories that a place belongs to,
- //it includes all ancestors of the assigned categories
-
- static const QLatin1String CategoryType;
- static const QLatin1String Lineage; //includes all ancestor category ids and also the current category id
- //as the last element. The first category is a top level category id.
- static const QLatin1String CategoryParentId;
-
- static const QLatin1String NotificationType;
- static const QLatin1String Actions;
-
- //coord
- static const QLatin1String Coordinate;
- static const QLatin1String Latitude;
- static const QLatin1String Longitude;
-
- //address
- static const QLatin1String Address;
- static const QLatin1String Street;
- static const QLatin1String District;
- static const QLatin1String City;
- static const QLatin1String County;
- static const QLatin1String State;
- static const QLatin1String Country;
- static const QLatin1String CountryCode;
- static const QLatin1String PostalCode;
-
- static const QLatin1String Location;
-
- //contact details
- static const QLatin1String Phones;
- static const QLatin1String Emails;
- static const QLatin1String Websites;
-
- static const QLatin1String PhoneSubType;
- static const QLatin1String SubTypeFax;
- static const QLatin1String SubTypeLandline;
-
- static const QLatin1String Label;
- static const QLatin1String Value;
- static const QLatin1String Url;
-
- static const QLatin1String ExtendedAttributes;
- static const QLatin1String Text;
-
- static const QLatin1String Height;
- static const QLatin1String Width;
-
- static const QLatin1String Thumbnails;
- static const QLatin1String Small;
- static const QLatin1String Medium;
- static const QLatin1String Large;
- static const QLatin1String Fullscreen;
-
- static const QLatin1String SmallIconParam;
- static const QLatin1String MediumIconParam;
- static const QLatin1String LargeIconParam;
- static const QLatin1String FullscreenIconParam;
-
- static const QLatin1String SmallIconSizeParam;
- static const QLatin1String MediumIconSizeParam;
- static const QLatin1String LargeIconSizeParam;
- static const QLatin1String FullscreenIconSizeParam;
-
- static const QLatin1String CreatedDateTime;
- static const QLatin1String ModifiedDateTime;
-
- static const QLatin1String DefaultPartition;
- static const QLatin1String PartitionType;
-
- static const QLatin1String LatitudeIndex;
- static const QLatin1String LongitudeIndex;
- static const QLatin1String PlaceNameIndex;
-
-public slots:
- void setupPartition(const QString &partition);
- void getPlacesFinished();
- void removePlacesFinished();
- void getCategoriesFinished();
- void removeCategoriesFinished();
- void requestError(QtJsonDb::QJsonDbRequest::ErrorCode error, const QString &errorString);
-
- void fetchPlaceJsonFinished();
- void savePlaceJsonFinished();
-
-signals:
- void dbCleaned();
- void placeFetched(QJsonObject placeJson);
- void placeSaved();
- void partitionSetupDone();
-
-private:
- void setupRequest(QJsonDbRequest *request, QObject *parent, const char *slot);
- static QProcess *launchJsonDbDaemon(const QStringList &args = QStringList());
-
- QProcess *m_jsondbProcess;
- QJsonDbConnection *m_connection;
- QList<QJsonObject> m_results;
- QString m_currentPartition;
-};
-
-#endif
diff --git a/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro b/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro
deleted file mode 100644
index 6d032763..00000000
--- a/tests/auto/qplacemanager_jsondb/qplacemanager_jsondb.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-!no_system_tests:CONFIG += testcase
-TARGET = tst_qplacemanager_jsondb
-
-HEADERS += jsondbutils.h \
- ../placemanager_utils/placemanager_utils.h
-
-SOURCES += tst_qplacemanager_jsondb.cpp \
- jsondbutils.cpp \
- ../placemanager_utils/placemanager_utils.cpp
-
-QT += location testlib network jsondb
-
-DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
-
-RESOURCES += resources.qrc
-
-DEFINES += JSONFILE=\\\"$$PWD/../../../src/plugins/geoservices/places_jsondb/10-placesIndices.json\\\"
-
-#Mark test as insignificant until jsondb is supported
-CONFIG+=insignificant_test
-DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qplacemanager_jsondb/resources.qrc b/tests/auto/qplacemanager_jsondb/resources.qrc
deleted file mode 100644
index 319750b2..00000000
--- a/tests/auto/qplacemanager_jsondb/resources.qrc
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>resources/icon_small.png</file>
- <file>resources/icon_small.svg</file>
- <file>resources/icon_24x24.png</file>
- <file>resources/icon_medium.png</file>
- <file>resources/icon_40x40.png</file>
- <file>resources/icon_large.png</file>
- <file>resources/icon_fullscreen.png</file>
- <file>resources/offline-mapping.json</file>
-</qresource>
-</RCC>
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_24x24.png b/tests/auto/qplacemanager_jsondb/resources/icon_24x24.png
deleted file mode 100644
index 79eff158..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_24x24.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_40x40.png b/tests/auto/qplacemanager_jsondb/resources/icon_40x40.png
deleted file mode 100644
index 56104673..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_40x40.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_fullscreen.png b/tests/auto/qplacemanager_jsondb/resources/icon_fullscreen.png
deleted file mode 100644
index 7b7623da..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_fullscreen.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_large.png b/tests/auto/qplacemanager_jsondb/resources/icon_large.png
deleted file mode 100644
index 8b5a8620..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_large.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_medium.png b/tests/auto/qplacemanager_jsondb/resources/icon_medium.png
deleted file mode 100644
index 9dcc536c..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_medium.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_small.png b/tests/auto/qplacemanager_jsondb/resources/icon_small.png
deleted file mode 100644
index 8cc6e328..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_small.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qplacemanager_jsondb/resources/icon_small.svg b/tests/auto/qplacemanager_jsondb/resources/icon_small.svg
deleted file mode 100644
index fdc33b8b..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/icon_small.svg
+++ /dev/null
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- width="20"
- height="20"
- id="svg2"
- version="1.1"
- inkscape:version="0.47 r22583"
- sodipodi:docname="New document 1">
- <defs
- id="defs4">
- <inkscape:perspective
- sodipodi:type="inkscape:persp3d"
- inkscape:vp_x="0 : 526.18109 : 1"
- inkscape:vp_y="0 : 1000 : 0"
- inkscape:vp_z="744.09448 : 526.18109 : 1"
- inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
- id="perspective10" />
- </defs>
- <sodipodi:namedview
- id="base"
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1.0"
- inkscape:pageopacity="0.0"
- inkscape:pageshadow="2"
- inkscape:zoom="3.959798"
- inkscape:cx="88.740598"
- inkscape:cy="2.2479901"
- inkscape:document-units="px"
- inkscape:current-layer="layer1"
- showgrid="false"
- inkscape:window-width="1302"
- inkscape:window-height="747"
- inkscape:window-x="211"
- inkscape:window-y="312"
- inkscape:window-maximized="0" />
- <metadata
- id="metadata7">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- <dc:title></dc:title>
- </cc:Work>
- </rdf:RDF>
- </metadata>
- <g
- inkscape:label="Layer 1"
- inkscape:groupmode="layer"
- id="layer1"
- transform="translate(0,-1032.3622)">
- <path
- sodipodi:type="star"
- style="fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:#0ee219;stroke-width:0.2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
- id="path2820"
- sodipodi:sides="3"
- sodipodi:cx="182.85715"
- sodipodi:cy="392.36218"
- sodipodi:r1="126.2327"
- sodipodi:r2="89.473007"
- sodipodi:arg1="1.6614562"
- sodipodi:arg2="2.7086538"
- inkscape:flatsided="false"
- inkscape:rounded="0.0069814382"
- inkscape:randomized="0"
- d="m 171.42858,518.07647 c -0.78186,-0.0711 -69.45999,-87.4641 -69.78937,-88.17675 -0.32937,-0.71265 -22.392028,-109.65054 -21.939542,-110.29211 0.452485,-0.64157 110.476132,-16.42207 111.257992,-16.35099 0.78186,0.0711 106.15616,35.4332 106.48554,36.14585 0.32937,0.71265 -41.01614,103.88617 -41.46863,104.52774 -0.45248,0.64157 -83.76413,74.21734 -84.54599,74.14626 z"
- transform="matrix(0.07116921,0,0,0.0639748,-3.1540812,1016.272)" />
- </g>
-</svg>
diff --git a/tests/auto/qplacemanager_jsondb/resources/offline-mapping.json b/tests/auto/qplacemanager_jsondb/resources/offline-mapping.json
deleted file mode 100644
index e4c36fe9..00000000
--- a/tests/auto/qplacemanager_jsondb/resources/offline-mapping.json
+++ /dev/null
@@ -1,131 +0,0 @@
-{
- "mos_categories" : {
- "AIRPORT" : "airport",
- "AMUSEMENT_PARK" : "amusement-holiday-park ",
- "BUS_STATION" : "public-transport",
- "CINEMA" : "cinema",
- "CAR_DEALER" : "car-dealer-repair ",
- "RENT_A_CAR_FACILITY" : "car-rental ",
- "CAR_REPAIR" : "car-dealer-repair ",
- "CASH_DISPENSER" : "atm-bank-exchange",
- "COMMUTER_RAIL_STATION" : "public-transport",
- "COMPANY" : "business-industry",
- "EDUCATION" : "education-facility",
- "EXHIBITION_CENTRE" : "fair-convention-facility",
- "FERRY_TERMINAL" : "ferry-terminal",
- "GOVERNMENT_OFFICE" : "government-community-facility",
- "HOSPITAL" : "hospital-health-care-facility",
- "HOTEL" : "hotel",
- "LAUNDRY" : "service",
- "LIBRARY" : "library",
- "MUSEUM" : "museum",
- "NIGHT_CLUB" : "dance-night-club",
- "PARKING" : "parking-facility",
- "PETROL_STATION" : "petrol-station",
- "PHARMACY" : "pharmacy",
- "POLICE" : "police-emergency",
- "POST_OFFICE" : "post-office",
- "PUBLIC_TOILET" : "toilet-rest-area",
- "RAILWAY_STATION" : "railway-station",
- "PLACE_OF_WORSHIP" : "religious-place",
- "RESIDENTIAL_AREA" : "administrative-areas-buildings",
- "REST_AREA" : "toilet-rest-area",
- "RESTAURANT" : "restaurant",
- "SPORT_OUTDOOR" : "sports-facility-venue",
- "TAXI_STAND" : "taxi-stand",
- "THEATRE" : "theatre-music-culture",
- "TOURIST_INFORMATION_CENTRE" : "tourist-information",
- "TOURIST_ATTRACTION" : "landmark-attraction",
- "SHOP" : "shopping"
- },
-
- "offline_icons" : {
- "accommodation" : "01",
- "administrative-areas-buildings" : "06",
- "airport" : "40",
- "amusement-holiday-park" : "34",
- "atm-bank-exchange" : "15",
- "business-industry" : "02",
- "business-services" : "02",
- "car-dealer-repair" : "16",
- "car-rental" : "17",
- "cinema" : "32",
- "dance-night-club" : "33",
- "education-facility" : "04",
- "facilities" : "04",
- "fair-convention-facility" : "24",
- "ferry-terminal" : "41",
- "going-out" : "05",
- "government-community-facility" : "25",
- "hospital-health-care-facility" : "26",
- "hotel" : "01",
- "landmark-attraction" : "10",
- "leisure-outdoor" : "07",
- "library" : "27",
- "museum" : "10",
- "natural-geographical" : "08",
- "parking-facility" : "28",
- "petrol-station" : "18",
- "pharmacy" : "37",
- "police-emergency" : "19",
- "post-office" : "20",
- "public-transport" : "11",
- "railway-station" : "43",
- "religious-place" : "39",
- "restaurant" : "03",
- "service" : "02",
- "shopping" : "09",
- "sights-museums" : "10",
- "sports-facility-venue" : "30",
- "taxi-stand" : "42",
- "theatre-music-culture" : "05",
- "toilet-rest-area" : "29",
- "transport" : "11",
- "tourist-information" : "21"
- },
-
-
-
- "offline_explore" : {
- "ROOT" : {
- "children" : ["eat-drink", "going-out", "sights-museums", "transport", "accommodation", "shopping", "business-services", "facilities", "leisure-outdoor"]
- },
-
- "going-out" : {
- "children" : ["dance-night-club", "cinema", "theatre-music-culture" ]
- },
-
- "sights-museums" : {
- "children" : ["landmark-attraction", "museum", "religious-place" ]
- },
-
- "transport" : {
- "children" : ["airport", "railway-station", "public-transport", "ferry-terminal", "taxi-stand" ]
- },
-
- "accommodation" : {
- "children" : [ "hotel" ],
- "final" : true
- },
-
- "shopping" : {
- "children" : [ "pharmacy" ],
- "final" : true
- },
-
- "business-services" : {
- "children" : [ "atm-bank-exchange", "police-emergency", "post-office", "tourist-information", "petrol-station", "car-rental", "car-dealer-repair", "business-industry", "service" ]
- },
-
- "facilities" : {
- "children" : [ "hospital-health-care-facility", "government-community-facility", "education-facility", "library", "fair-convention-facility", "parking-facility", "toilet-rest-area", "sports-facility-venue" ]
- },
-
- "leisure-outdoor" : {
- "children" : [ "amusement-holiday-park"],
- "final" : true
- }
-
- }
-
-}
diff --git a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
deleted file mode 100644
index a60971a7..00000000
--- a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
+++ /dev/null
@@ -1,3404 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, 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, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/QCoreApplication>
-#include <QtCore/QString>
-#include <QtTest/QtTest>
-#include <QtCore/qnumeric.h>
-#include <QtGui/QImageReader>
-#include <QtJsonDb/QJsonDbCreateRequest>
-#include <QtJsonDb/QJsonDbReadRequest>
-#include <QtLocation/QGeoCircle>
-#include <QtLocation/QGeoRectangle>
-
-#include <qgeoserviceprovider.h>
-#include <qplacemanager.h>
-#include <qplacecategory.h>
-#include <qplacecontentreply.h>
-#include <qplacematchreply.h>
-#include <qplaceresult.h>
-#include <qplacesearchsuggestionreply.h>
-#include <qplacesearchrequest.h>
-#include <qplacesearchresult.h>
-#include <qplacesearchreply.h>
-#include <qplacecontactdetail.h>
-#include <qplaceimage.h>
-#include <qplacesupplier.h>
-
-#include "jsondbutils.h"
-#include "../placemanager_utils/placemanager_utils.h"
-
-Q_DECLARE_METATYPE(QPlaceIdReply *)
-Q_DECLARE_METATYPE(QJsonObject)
-
-QT_USE_NAMESPACE
-
-class tst_QPlaceManagerJsonDb : public PlaceManagerUtils
-{
- Q_OBJECT
- enum UrlCorrectnes {
- ValidUrl,
- NoSchemeUrl
- };
-
- enum DestinationExists {
- Exists,
- DoesNotExist
- };
-
-public:
- tst_QPlaceManagerJsonDb();
-
-private Q_SLOTS:
- void initTestCase();
- void cleanup();
-
- void saveAndRemovePlace();
- void simpleUpdatePlace();
- void updatePlace();
- void updatePlace_data();
- void simpleSaveAndRemoveCategory();
- void saveAndRemoveCategory();
- void updateCategory();
- void savePlaceWithCategory();
-
- void searchByName();
- void searchByBox();
- void searchByCircle();
- void searchWithLexicalPlaceNameHint();
- void searchWithDistanceHint();
- void searchByCategory();
- void unsupportedFunctions();
- void supportedFeatures();
- void categoryFunctions();
- void contactDetails();
- void contactDetails_data();
- void mulipleDetailTypes();
- void placeNotifications();
- void categoryNotifications();
- void compatiblePlace();
- void extendedAttribute();
- void matchingPlaces();
- void matchingPlaces_data();
- void iconSourceDestination();
- void iconSourceDestination_data();
- void iconSourceOnly();
- void iconSourceOnly_data();
- void iconDestinationOnly();
- void iconDestinationOnly_data();
- void iconSavedFromDifferentManager();
- void iconFormats();
- void iconFormats_data();
- void iconUrls();
- void iconUrls_data();
-#ifdef REMOTE_TEST
- void iconDownload();
- void iconDownload_data();
-#endif
- void constructIconUrl();
- void providerIcons();
- void specifiedPartition();
- void validateIndexes();
-
-private:
- QImage dataUrlToImage(const QUrl &url);
-
- static const QString SmallSource;
- static const QString SmallDestination;
- static const QString SmallDestinationSize;
- static const QString MediumSource;
- static const QString MediumDestination;
- static const QString MediumDestinationSize;
- static const QString LargeSource;
- static const QString LargeDestination;
- static const QString LargeDestinationSize;
- static const QString FullscreenSource;
- static const QString FullscreenDestination;
- static const QString FullscreenDestinationSize;
-
- static const QString Nokiaicon;
- static const QString IconPrefix;
- static const QString NokiaIconGenerated;
-
- static const QSize SmallSize;
- static const QSize MediumSize;
- static const QSize LargeSize;
- static const QSize FullscreenSize;
- static const QString Provider;
-
- static const QString CustomIcons;
-
- QGeoServiceProvider *provider;
- QCoreApplication *coreApp;
- JsonDbUtils *dbUtils ;
- QTemporaryDir tempDir;
-};
-
-//These constants are equivalent to those from the jsondb plugin icon class
-const QString tst_QPlaceManagerJsonDb::SmallSource("smallSourceUrl");
-const QString tst_QPlaceManagerJsonDb::SmallDestination("smallUrl");
-const QString tst_QPlaceManagerJsonDb::SmallDestinationSize("smallSize");
-
-const QString tst_QPlaceManagerJsonDb::MediumSource("mediumSourceUrl");
-const QString tst_QPlaceManagerJsonDb::MediumDestination("mediumUrl");
-const QString tst_QPlaceManagerJsonDb::MediumDestinationSize("mediumSize");
-
-const QString tst_QPlaceManagerJsonDb::LargeSource("largeSourceUrl");
-const QString tst_QPlaceManagerJsonDb::LargeDestination("largeUrl");
-const QString tst_QPlaceManagerJsonDb::LargeDestinationSize("largeSize");
-
-const QString tst_QPlaceManagerJsonDb::FullscreenSource("fullscreenSourceUrl");
-const QString tst_QPlaceManagerJsonDb::FullscreenDestination("fullscreenUrl");
-const QString tst_QPlaceManagerJsonDb::FullscreenDestinationSize("fullscreenSize");
-
-const QString tst_QPlaceManagerJsonDb::Nokiaicon("nokiaIcon");
-const QString tst_QPlaceManagerJsonDb::IconPrefix("iconPrefix");
-const QString tst_QPlaceManagerJsonDb::NokiaIconGenerated("nokiaIconGenerated");
-
-const QSize tst_QPlaceManagerJsonDb::SmallSize = QSize(20,20);
-const QSize tst_QPlaceManagerJsonDb::MediumSize = QSize(30,30);
-const QSize tst_QPlaceManagerJsonDb::LargeSize = QSize(50, 50);
-const QSize tst_QPlaceManagerJsonDb::FullscreenSize = QSize(320, 480);
-
-//This constant is key for the place attribute that signifies which provider
-//a place originates from
-const QString tst_QPlaceManagerJsonDb::Provider("x_provider");
-
-const QString tst_QPlaceManagerJsonDb::CustomIcons("places.icons.custom");
-
-tst_QPlaceManagerJsonDb::tst_QPlaceManagerJsonDb()
-{
- //We need a QCoreApplication instance for
- //event dispatching
- int argc;
- char **argv=0;
- coreApp = new QCoreApplication(argc, argv);
-
- dbUtils = new JsonDbUtils(this);
-}
-
-void tst_QPlaceManagerJsonDb::initTestCase()
-{
- QVERIFY(dbUtils->hasJsonDbConnection());
-
- qRegisterMetaType<QPlaceIdReply *>();
- qRegisterMetaType<QJsonObject>();
-
- QStringList providers = QGeoServiceProvider::availableServiceProviders();
- QVERIFY(providers.contains(QLatin1String("places_jsondb")));
-
- //create dummy icon file
- QString catIconPath = tempDir.path() + "/icons/categories/";
- QDir::root().mkpath(catIconPath);
- QFile iconFile(catIconPath + "01.icon");
- iconFile.open(QIODevice::WriteOnly);
- iconFile.close();
-
- iconFile.setFileName(catIconPath + "02.icon");
- iconFile.open(QIODevice::WriteOnly);
- iconFile.close();
-
- iconFile.setFileName(catIconPath + "06.icon");//default icon
- iconFile.open(QIODevice::WriteOnly);
- iconFile.close();
-
- QString offlinePath = tempDir.path() + QStringLiteral("/offline/");
- QDir::root().mkpath(offlinePath);
- QFile mappingFile(QStringLiteral(":/resources/offline-mapping.json"));
- mappingFile.copy(offlinePath + QStringLiteral("offline-mapping.json"));
-
- provider = new QGeoServiceProvider(QLatin1String("places_jsondb"));
-
- placeManager = provider->placeManager();
- QVERIFY(placeManager);
-
- QPlaceReply * catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
- catInitReply->deleteLater();
-
- cleanup();
-}
-
-void tst_QPlaceManagerJsonDb::saveAndRemovePlace()
-{
- QPlace place;
- place.setName(QLatin1String("Char"));
- QGeoLocation location;
-
- location.setCoordinate(QGeoCoordinate(10,20));
-
- QGeoAddress address;
- address.setStreet(QLatin1String("1 test street"));
- address.setCity(QLatin1String("New york"));
- address.setCountry(QLatin1String("USA"));
- location.setAddress(address);
- place.setLocation(location);
-
- QPlaceContactDetail phone;
- phone.setValue(QLatin1String("555-5555"));
- place.appendContactDetail(QPlaceContactDetail::Phone, phone);
-
- QPlaceContactDetail fax;
- fax.setValue(QLatin1String("999-9999"));
- place.appendContactDetail(QPlaceContactDetail::Fax, fax);
-
- QPlaceContactDetail email;
- email.setValue(QLatin1String("email@adddresss.com"));
- place.appendContactDetail(QPlaceContactDetail::Email, email);
-
- QPlaceContactDetail website;
- website.setValue(QLatin1String("www.example.com"));
- place.appendContactDetail(QPlaceContactDetail::Website, website);
-
- //Save a place
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- place.setPlaceId(placeId);
- place.setVisibility(QLocation::DeviceVisibility);
-
- //ensure we can retrieve it's details
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace == place);
-
- //try removing a place
- QVERIFY(doRemovePlace(place, QPlaceReply::NoError));
-
- //ensure it is actually deleted
- QVERIFY(doFetchDetails(placeId, &retrievedPlace, QPlaceReply::PlaceDoesNotExistError));
- QCOMPARE(retrievedPlace, QPlace());
-
- //try removing a place that does not exist;
- QVERIFY(doRemovePlace(place, QPlaceReply::PlaceDoesNotExistError));
-
- place.setVisibility(QLocation::PublicVisibility);
- QVERIFY(doSavePlace(place, QPlaceReply::UnsupportedError, 0));
-
- place.setVisibility(QLocation::PrivateVisibility);
- QVERIFY(doSavePlace(place, QPlaceReply::UnsupportedError, 0));
-}
-
-void tst_QPlaceManagerJsonDb::simpleUpdatePlace()
-{
- //save a place and check that we can retrieve it
- QPlace place;
- place.setName(QLatin1String("Sydney"));
- QGeoAddress address;
- address.setStreet(QLatin1String("original street"));
- QGeoLocation location;
- location.setAddress(address);
- place.setLocation(location);
-
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
-
- //check that created and modified date time has been set
- QDateTime currentDateTime = QDateTime::currentDateTime();
- dbUtils->fetchPlaceJson(placeId);
- QSignalSpy spy(dbUtils, SIGNAL(placeFetched(QJsonObject)));
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, Timeout);
- QJsonObject placeJson = spy.at(0).at(0).value<QJsonObject>();
- spy.clear();
-
- QVERIFY(placeJson.contains(JsonDbUtils::CreatedDateTime));
- QVERIFY(placeJson.contains(JsonDbUtils::ModifiedDateTime));
- QDateTime createdDateTime = placeJson.value(JsonDbUtils::CreatedDateTime).toVariant().toDateTime();
- QDateTime modifiedDateTime = placeJson.value(JsonDbUtils::ModifiedDateTime).toVariant().toDateTime();
- QCOMPARE(createdDateTime, modifiedDateTime);
- QVERIFY(createdDateTime.secsTo(currentDateTime) < 10);
- QTest::qWait(1100); //stabilize test by waiting before updating to ensure modification
- //time will change. The DateTime is stored in ISO format which only
- //has a resolution of seconds
-
- 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);
-
- QPlace retrievedPlace;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError));
-
- //check that the created datetime is the same, while the modified date time has changed.
- currentDateTime = QDateTime::currentDateTime();
- dbUtils->fetchPlaceJson(placeId);
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, Timeout);
- placeJson = spy.at(0).at(0).value<QJsonObject>();
- spy.clear();
-
- QVERIFY(placeJson.contains(JsonDbUtils::CreatedDateTime));
- QVERIFY(placeJson.contains(JsonDbUtils::ModifiedDateTime));
- QCOMPARE(placeJson.value(JsonDbUtils::CreatedDateTime).toVariant().toDateTime(), createdDateTime);
- QVERIFY(placeJson.value(JsonDbUtils::ModifiedDateTime).toVariant().toDateTime() != modifiedDateTime);
- QVERIFY(placeJson.value(JsonDbUtils::ModifiedDateTime).toVariant().toDateTime().secsTo(currentDateTime) < 10);
-
- 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::updatePlace()
-{
- const QUrl IconUrl(QLatin1String("file://opt/myicon.png"));
- const QSize IconSize(20,20);
-
- QPlaceAttribute smoking;
- smoking.setLabel(QLatin1String("Smoking"));
- smoking.setText(QLatin1String("yes"));
-
- QPlaceAttribute noSmoking;
- noSmoking.setLabel(QLatin1String("Smoking"));
- noSmoking.setText(QLatin1String("no"));
-
- QPlaceAttribute bus;
- bus.setLabel(QLatin1String("Bus stop"));
- bus.setText(QLatin1String("yes"));
-
- QPlaceContactDetail contactDetail;
- contactDetail.setLabel(QLatin1String("contact label"));
- contactDetail.setValue(QLatin1String("contact value"));
-
- QFETCH(QString, field);
- qDebug(); //this simply provides visual output on what is being tested
-
- QString categoryId;
- QPlaceCategory pizza;
- pizza.setName(QLatin1String("pizza"));
- QVERIFY(doSaveCategory(pizza, QPlaceReply::NoError, &categoryId));
- pizza.setCategoryId(categoryId);
-
- QPlaceCategory burgers;
- burgers.setName(QLatin1String("burgers"));
- QVERIFY(doSaveCategory(burgers, QPlaceReply::NoError, &categoryId));
- burgers.setCategoryId(categoryId);
-
- //save minimal place
- QPlace place;
- place.setName(QLatin1String("place1"));
-
- QGeoAddress address;
- address.setCountryCode(QLatin1String("USA"));
-
- QGeoLocation location;
- location.setCoordinate(QGeoCoordinate(10,10));
- location.setAddress(address);
- place.setLocation(location);
-
- QPlaceIcon icon;
- QVariantMap iconParameters;
- iconParameters.insert(QLatin1String("fullscreenUrl"), QUrl("file://opt/icon.png"));
- iconParameters.insert(QLatin1String("fullscreenSize"), QSize(320, 480));
-
- place.setVisibility(QLocation::DeviceVisibility);
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- place.setPlaceId(placeId);
-
- dbUtils->fetchPlaceJson(placeId);
- QSignalSpy spy(dbUtils, SIGNAL(placeFetched(QJsonObject)));
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, Timeout);
- QJsonObject placeJson = spy.at(0).at(0).value<QJsonObject>();
- spy.clear();
-
- //we need to verify that other properties are not overwritten
- placeJson.insert(QLatin1String("description"), QLatin1String("simpson residence"));
- QJsonObject locationJson = placeJson.value(JsonDbUtils::Location).toObject();
- locationJson.insert(QLatin1String("launchUrl"), QLatin1String("http://www.example.com"));
- placeJson.insert(JsonDbUtils::Location, locationJson);
-
- dbUtils->savePlaceJson(placeJson);
- QSignalSpy saveSpy(dbUtils, SIGNAL(placeSaved()));
- QTRY_VERIFY_WITH_TIMEOUT(saveSpy.count() == 1, Timeout);
-
- //modify all fields
- if (field == QLatin1String("category")) {
- place.setCategory(pizza);
- } else if (field == QLatin1String("coordinate")) {
- location.setCoordinate(QGeoCoordinate(20,20));
- place.setLocation(location);
- } else if (field == QLatin1String("no coord with address")) {
- location.setCoordinate(QGeoCoordinate());
- address.setStreet(QLatin1String("42 Evergreen Terrace"));
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("street")) {
- address.setStreet(QLatin1String("42 Evergreen Terrace"));
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("district")) {
- address.setDistrict(QLatin1String("Henderson"));;
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("city")) {
- address.setCity("Springfield");
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("county")) {
- address.setCounty(QLatin1String("Lane County"));
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("state")) {
- address.setState(QLatin1String("Oregon"));
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("country")) {
- address.setCountry(QLatin1String("United States of America"));
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("country code")) {
- address.setCountryCode("AUS");
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("clear address")) {
- location.setAddress(QGeoAddress());
- place.setLocation(location);
- } else if (field == QLatin1String("small icon")) {
- iconParameters.insert(JsonDbUtils::SmallIconParam, IconUrl);
- iconParameters.insert(JsonDbUtils::SmallIconSizeParam, IconSize);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("medium icon")) {
- iconParameters.insert(JsonDbUtils::MediumIconParam, IconUrl);
- iconParameters.insert(JsonDbUtils::MediumIconSizeParam, IconSize);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("large icon")) {
- iconParameters.insert(JsonDbUtils::LargeIconParam, IconUrl);
- iconParameters.insert(JsonDbUtils::LargeIconSizeParam, IconSize);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("fullscreen icon")) {
- iconParameters.insert(JsonDbUtils::FullscreenIconParam, IconUrl);
- iconParameters.insert(JsonDbUtils::FullscreenIconSizeParam, IconSize);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("name")) {
- place.setName(QLatin1String("home"));
- } else if (field == QLatin1String("extended attribute") || field == QLatin1String("clear extended attributes")) {
- place.setExtendedAttribute("smoking", smoking);
- place.setExtendedAttribute("bus", bus);
- } else if (field == QLatin1String("phone")) {
- place.appendContactDetail(QPlaceContactDetail::Phone, contactDetail);
- } else if (field == QLatin1String("fax")) {
- place.appendContactDetail(QPlaceContactDetail::Fax, contactDetail);
- } else if (field == QLatin1String("email")) {
- place.appendContactDetail(QPlaceContactDetail::Email, contactDetail);
- } else if (field == QLatin1String("website")) {
- place.appendContactDetail(QPlaceContactDetail::Website, contactDetail);
- }
-
- QVERIFY(doSavePlace(place, QPlaceReply::NoError));
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- dbUtils->fetchPlaceJson(placeId);
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, Timeout);
- placeJson = spy.at(0).at(0).value<QJsonObject>();
- spy.clear();
-
- locationJson = placeJson.value(JsonDbUtils::Location).toObject();
- QJsonObject addressJson = locationJson.value(JsonDbUtils::Address).toObject();
- QJsonObject thumbnailsJson = placeJson.value(JsonDbUtils::Thumbnails).toObject();
- QJsonObject attributesJson = placeJson.value(JsonDbUtils::ExtendedAttributes).toObject();
-
- QCOMPARE(placeJson.value(QLatin1String("description")).toString(), QLatin1String("simpson residence"));
- QCOMPARE(locationJson.value(QLatin1String("launchUrl")).toString(), QLatin1String("http://www.example.com"));
-
- if (field == QLatin1String("category")) {
- QCOMPARE(retrievedPlace.categories().count(), 1);
- QVERIFY(retrievedPlace.categories().contains(pizza));
- QVERIFY(placeJson.contains(JsonDbUtils::CategoryUuids));
-
- place.setCategories(QList<QPlaceCategory>());
- } else if (field == QLatin1String("coordinate")) { iconParameters.insert(JsonDbUtils::MediumIconParam, IconUrl);
- iconParameters.insert(JsonDbUtils::MediumIconSizeParam, IconSize);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- QCOMPARE(retrievedPlace.location().coordinate(), QGeoCoordinate(20,20));
- } else if (field == QLatin1String("no coord with address")) {
- QCOMPARE(retrievedPlace.location().coordinate(), QGeoCoordinate());
- QCOMPARE(retrievedPlace.location().address().street(), QLatin1String("42 Evergreen Terrace"));
- QVERIFY(!locationJson.contains(JsonDbUtils::Coordinate));
- QVERIFY(locationJson.contains(JsonDbUtils::Address));
- } else if (field == QLatin1String("street")) {
- QCOMPARE(retrievedPlace.location().address().street(), QLatin1String("42 Evergreen Terrace"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::Street));
-
- address.setStreet(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("district")) {
- QCOMPARE(retrievedPlace.location().address().district(), QLatin1String("Henderson"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::District));
-
- address.setDistrict(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("city")) {
- QCOMPARE(retrievedPlace.location().address().city(), QLatin1String("Springfield"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::City));
-
- address.setCity(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("county")) {
- QCOMPARE(retrievedPlace.location().address().county(), QLatin1String("Lane County"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::County));
-
- address.setCounty(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("state")) {
- QCOMPARE(retrievedPlace.location().address().state(), QLatin1String("Oregon"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::State));
-
- address.setState(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("country")) {
- QCOMPARE(retrievedPlace.location().address().country(), QLatin1String("United States of America"));
- QCOMPARE(addressJson.keys().count(), 2);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::Country));
-
- address.setCountry(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("country code")) {
- QCOMPARE(retrievedPlace.location().address().countryCode(), QLatin1String("AUS"));
- QCOMPARE(addressJson.keys().count(), 1);
- QVERIFY(addressJson.keys().contains(JsonDbUtils::CountryCode));
-
- address.setStreet(QLatin1String("742 Evergreen Tce"));//this is assigned so that the entire address object
- //is not removed in jsondb
- address.setCountryCode(QString());
- location.setAddress(address);
- place.setLocation(location);
- } else if (field == QLatin1String("clear address")) {
- QVERIFY(retrievedPlace.location().address().isEmpty());
- QVERIFY(!locationJson.keys().contains(JsonDbUtils::Address));
- } else if (field == QLatin1String("small icon")) {
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::SmallIconParam).toUrl(), IconUrl);
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::SmallIconSizeParam).toSize(), IconSize);
-
- iconParameters.remove(JsonDbUtils::SmallIconParam);
- iconParameters.remove(JsonDbUtils::SmallIconSizeParam);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("medium icon")) {
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::MediumIconParam).toUrl(), IconUrl);
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::MediumIconSizeParam).toSize(), IconSize);
-
- iconParameters.remove(JsonDbUtils::MediumIconParam);
- iconParameters.remove(JsonDbUtils::MediumIconSizeParam);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("large icon")) {
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::LargeIconParam).toUrl(), IconUrl);
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::LargeIconSizeParam).toSize(), IconSize);
-
- iconParameters.remove(JsonDbUtils::LargeIconParam);
- iconParameters.remove(JsonDbUtils::LargeIconSizeParam);
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("fullscreen icon")) {
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::FullscreenIconParam).toUrl(), IconUrl);
- QCOMPARE(retrievedPlace.icon().parameters().value(JsonDbUtils::FullscreenIconSizeParam).toSize(), IconSize);
-
- iconParameters.remove(JsonDbUtils::FullscreenIconParam);
- iconParameters.remove(JsonDbUtils::FullscreenIconSizeParam);
-
- iconParameters.insert(JsonDbUtils::SmallIconParam, IconUrl); //this is assigned so the entire
- iconParameters.insert(JsonDbUtils::SmallIconSizeParam, IconSize); //thumbnails jsondb object is not removed.
-
- icon.setParameters(iconParameters);
- place.setIcon(icon);
- } else if (field == QLatin1String("name")) {
- QCOMPARE(retrievedPlace.name(), QLatin1String("home"));
- } else if (field == QLatin1String("extended attribute")) {
- QCOMPARE(retrievedPlace.extendedAttributeTypes().count(), 2);
- QCOMPARE(retrievedPlace.extendedAttribute(QLatin1String("smoking")), smoking);
- QCOMPARE(retrievedPlace.extendedAttribute("bus"), bus);
-
- QVERIFY(attributesJson.keys().contains(QLatin1String("smoking")));
- QVERIFY(attributesJson.keys().contains(QLatin1String("bus")));
-
- place.setExtendedAttribute(QLatin1String("smoking"), noSmoking);
- } else if (field == QLatin1String("clear extended attributes")) {
- QCOMPARE(retrievedPlace.extendedAttributeTypes().count(), 2);
- QCOMPARE(retrievedPlace.extendedAttribute(QLatin1String("smoking")), smoking);
- QCOMPARE(retrievedPlace.extendedAttribute(QLatin1String("bus")), bus);
-
- QVERIFY(attributesJson.keys().contains(QLatin1String("smoking")));
- QVERIFY(attributesJson.keys().contains(QLatin1String("bus")));
-
- place.removeExtendedAttribute(QLatin1String("smoking"));
- place.removeExtendedAttribute(QLatin1String("bus"));
- } else if (field == QLatin1String("phone")) {
- QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Phone));
- QCOMPARE(place.contactDetails(QPlaceContactDetail::Phone).first(), contactDetail);
- QVERIFY(placeJson.contains(JsonDbUtils::Phones));
-
- place.removeContactDetails(QPlaceContactDetail::Phone);
- } else if (field == QLatin1String("fax")) {
- QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Fax));
- QCOMPARE(place.contactDetails(QPlaceContactDetail::Fax).first(), contactDetail);
- QVERIFY(placeJson.contains(JsonDbUtils::Phones));
-
- place.removeContactDetails(QPlaceContactDetail::Fax);
- } else if (field == QLatin1String("email")) {
- QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Email));
- QCOMPARE(place.contactDetails(QPlaceContactDetail::Email).first(), contactDetail);
- QVERIFY(placeJson.contains(JsonDbUtils::Emails));
-
- place.removeContactDetails(QPlaceContactDetail::Email);
- } else if (field == QLatin1String("website")) {
- QVERIFY(place.contactTypes().contains(QPlaceContactDetail::Website));
- QCOMPARE(place.contactDetails(QPlaceContactDetail::Website).first(), contactDetail);
- QVERIFY(placeJson.contains(JsonDbUtils::Websites));
-
- place.removeContactDetails(QPlaceContactDetail::Website);
- } else {
- QFAIL("Unknown test case");
- }
-
- QVERIFY(doSavePlace(place, QPlaceReply::NoError));
-
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- dbUtils->fetchPlaceJson(placeId);
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, Timeout);
- placeJson = spy.at(0).at(0).value<QJsonObject>();
- locationJson = placeJson.value(JsonDbUtils::Location).toObject();
- addressJson = locationJson.value(JsonDbUtils::Address).toObject();
- thumbnailsJson = placeJson.value(JsonDbUtils::Thumbnails).toObject();
- attributesJson = placeJson.value(JsonDbUtils::ExtendedAttributes).toObject();
- spy.clear();
-
- QCOMPARE(placeJson.value(QLatin1String("description")).toString(), QLatin1String("simpson residence"));
- QCOMPARE(locationJson.value(QLatin1String("launchUrl")).toString(), QLatin1String("http://www.example.com"));
-
- if (field == QLatin1String("category")) {
- QCOMPARE(retrievedPlace.categories().count(), 0);
- QVERIFY(!placeJson.contains(JsonDbUtils::CategoryUuids));
- } else if (field == QLatin1String("street")) {
- QCOMPARE(retrievedPlace.location().address().street(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::Street));
- } else if (field == QLatin1String("district")) {
- QCOMPARE(retrievedPlace.location().address().district(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::District));
- } else if (field == QLatin1String("city")) {
- QCOMPARE(retrievedPlace.location().address().city(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::City));
- } else if (field == QLatin1String("county")) {
- QCOMPARE(retrievedPlace.location().address().county(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::County));
- } else if (field == QLatin1String("state")) {
- QCOMPARE(retrievedPlace.location().address().state(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::State));
- } else if (field == QLatin1String("country")) {
- QCOMPARE(retrievedPlace.location().address().country(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::Country));
- } else if (field == QLatin1String("country code")) {
- QCOMPARE(retrievedPlace.location().address().countryCode(), QString());
- QVERIFY(!addressJson.contains(JsonDbUtils::CountryCode));
- } else if (field == QLatin1String("small icon")) {
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::SmallIconParam));
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::SmallIconSizeParam));
- QVERIFY(!thumbnailsJson.contains(JsonDbUtils::Small));
- } else if (field == QLatin1String("medium icon")) {
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::MediumIconParam));
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::MediumIconSizeParam));
- QVERIFY(!thumbnailsJson.contains(JsonDbUtils::Medium));
- } else if (field == QLatin1String("large icon")) {
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::LargeIconParam));
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::LargeIconSizeParam));
- QVERIFY(!thumbnailsJson.contains(JsonDbUtils::Large));
- } else if (field == QLatin1String("fullscreen icon")) {
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::FullscreenIconParam));
- QVERIFY(!retrievedPlace.icon().parameters().contains(JsonDbUtils::FullscreenIconParam));
- QVERIFY(!thumbnailsJson.contains(JsonDbUtils::Fullscreen));
- } else if (field == QLatin1String("extended attribute")) {
- QCOMPARE(retrievedPlace.extendedAttribute("smoking"), noSmoking);
- QCOMPARE(retrievedPlace.extendedAttribute("bus"), bus);
-
- QVERIFY(attributesJson.keys().contains(QLatin1String("smoking")));
- QVERIFY(attributesJson.keys().contains(QLatin1String("bus")));
- } else if (field == QLatin1String("clear extended attributes")) {
- QVERIFY(retrievedPlace.extendedAttributeTypes().isEmpty());
- QVERIFY(!placeJson.keys().contains(JsonDbUtils::ExtendedAttributes));
- } else if (field == QLatin1String("phone")) {
- QVERIFY(retrievedPlace.contactTypes().isEmpty());
- QVERIFY(!placeJson.contains(JsonDbUtils::Phones));
- } else if (field == QLatin1String("fax")) {
- QVERIFY(retrievedPlace.contactTypes().isEmpty());
- QVERIFY(!placeJson.contains(JsonDbUtils::Phones));
- } else if (field == QLatin1String("email")) {
- QVERIFY(retrievedPlace.contactTypes().isEmpty());
- QVERIFY(!placeJson.contains(JsonDbUtils::Emails));
- } else if (field == QLatin1String("website")) {
- QVERIFY(retrievedPlace.contactTypes().isEmpty());
- QVERIFY(!placeJson.contains(JsonDbUtils::Websites));
- } else if (field == QLatin1String("coordinate") || field == QLatin1String("no coord with address")
- || field == QLatin1String("clear address") || field == QLatin1String("name")) {
- //no further tests required for these cases
- } else {
- QFAIL("Unknown test case");
- }
-}
-
-void tst_QPlaceManagerJsonDb::updatePlace_data()
-{
- QTest::addColumn<QString>("field");
-
- QTest::newRow("category") << "category";
- QTest::newRow("coordinate") << "coordinate";
- QTest::newRow("no coord with address") << "no coord with address";
- QTest::newRow("street") << "street";
- QTest::newRow("district") << "district";
- QTest::newRow("city") << "city";
- QTest::newRow("county") << "county";
- QTest::newRow("state") << "state";
- QTest::newRow("country") << "country";
- QTest::newRow("country code") << "country code";
- QTest::newRow("clear address") << "clear address";
- QTest::newRow("small icon") << "small icon";
- QTest::newRow("medium icon") << "medium icon";
- QTest::newRow("large icon") << "large icon";
- QTest::newRow("fullscreen icon") << "fullscreen icon";
- QTest::newRow("name") << "name";
- QTest::newRow("extended attribute") << "extended attribute"; //initially set two attributes, modify then remove one, verify other is unchanged
- QTest::newRow("clear extended attributes") << "clear extended attributes"; //initially set two attributes clear them,
- //ensure attribute property does not exist in jsondb
- QTest::newRow("phone") << "phone";
- QTest::newRow("fax") << "fax";
- QTest::newRow("email") << "email";
- QTest::newRow("website") << "website";
-}
-
-void tst_QPlaceManagerJsonDb::simpleSaveAndRemoveCategory()
-{
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
-
- //check saving of category
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
- QPlaceReply * catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QList<QPlaceCategory> categories = placeManager->childCategories();
- QCOMPARE(categories.count(), 1);
-
- QPlaceCategory retrievedCategory = placeManager->category(categoryId);
- QCOMPARE(retrievedCategory, restaurant);
-
- //check removal of category
- QVERIFY(doRemoveCategory(restaurant));
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QCOMPARE(placeManager->category(categoryId), QPlaceCategory());
- categories = placeManager->childCategories();
- QCOMPARE(categories.count(), 0);
-}
-
-void tst_QPlaceManagerJsonDb::saveAndRemoveCategory()
-{
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QPlaceCategory fastFood;
- fastFood.setName(QLatin1String("Fast Food"));
- QVERIFY(doSaveCategory(fastFood, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fastFood.setCategoryId(categoryId);
-
- QPlaceCategory fineDining;
- fineDining.setName(QLatin1String("Fine dining"));
- QVERIFY(doSaveCategory(fineDining, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fineDining.setCategoryId(categoryId);
-
- QPlaceCategory pancakes;
- pancakes.setName(QLatin1String("Pancakes"));
- QVERIFY(doSaveCategory(pancakes, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- pancakes.setCategoryId(categoryId);
-
- QPlaceCategory pizza;
- pizza.setName(QLatin1String("Pizza"));
- QVERIFY(doSaveCategory(pizza, fastFood.categoryId(), QPlaceReply::NoError, &categoryId));
- pizza.setCategoryId(categoryId);
-
- QPlaceCategory burgers;
- burgers.setName(QLatin1String("burgers"));
- QVERIFY(doSaveCategory(burgers, fastFood.categoryId(), QPlaceReply::NoError, &categoryId));
- burgers.setCategoryId(categoryId);
-
- QPlaceCategory accommodation;
- accommodation.setName(QLatin1String("Accommodation"));
- QVERIFY(doSaveCategory(accommodation, QPlaceReply::NoError,&categoryId));
- accommodation.setCategoryId(categoryId);
-
- QPlaceCategory hotel;
- hotel.setName(QLatin1String("Hotel"));
- QVERIFY(doSaveCategory(hotel, accommodation.categoryId(), QPlaceReply::NoError, &categoryId));
- hotel.setCategoryId(categoryId);
-
- QPlaceCategory motel;
- motel.setName(QLatin1String("Motel"));
- QVERIFY(doSaveCategory(motel, accommodation.categoryId(), QPlaceReply::NoError, &categoryId));
- motel.setCategoryId(categoryId);
- QPlaceReply *catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QList<QPlaceCategory> topLevelCategories = placeManager->childCategories();
- QVERIFY(topLevelCategories.contains(restaurant));
- QVERIFY(topLevelCategories.contains(accommodation));
- QVERIFY(topLevelCategories.count() == 2);
-
- QList<QPlaceCategory> categories = placeManager->childCategories(restaurant.categoryId());
- QVERIFY(categories.contains(fastFood));
- QVERIFY(categories.contains(fineDining));
- QVERIFY(categories.contains(pancakes));
- QCOMPARE(categories.count(), 3);
-
- categories = placeManager->childCategories(fastFood.categoryId());
- QVERIFY(categories.contains(pizza));
- QVERIFY(categories.contains(burgers));
- QCOMPARE(categories.count(), 2);
-
- categories = placeManager->childCategories(accommodation.categoryId());
- QVERIFY(categories.contains(hotel));
- QVERIFY(categories.contains(motel));
- QCOMPARE(categories.count(), 2);
-
- QVERIFY(doRemoveCategory(fastFood));
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- categories = placeManager->childCategories(restaurant.categoryId());
- QVERIFY(categories.contains(fineDining));
- QVERIFY(categories.contains(pancakes));
- QCOMPARE(categories.count(), 2);
-
- QVERIFY(placeManager->category(pizza.categoryId()) == QPlaceCategory());
- QVERIFY(placeManager->category(burgers.categoryId()) == QPlaceCategory());
-
- QVERIFY(doRemoveCategory(accommodation));
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- categories = placeManager->childCategories();
- QVERIFY(categories.contains(restaurant));
- QCOMPARE(categories.count(), 1);
-}
-
-void tst_QPlaceManagerJsonDb::updateCategory()
-{
- //Test updating a category name
- QPlaceCategory category;
- category.setName(QLatin1String("Foood"));
- QString categoryId;
- QVERIFY(doSaveCategory(category, QPlaceReply::NoError, &categoryId));
- category.setCategoryId(categoryId);
- QPlaceReply *catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QList<QPlaceCategory> categories;
- categories = placeManager->childCategories();
- QVERIFY(categories.contains(category));
-
- category.setName(QLatin1String("Food"));
- QVERIFY(doSaveCategory(category, QPlaceReply::NoError, &categoryId));
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- categories = placeManager->childCategories();
- QVERIFY(categories.contains(category));
- QCOMPARE(categories.count(), 1);
-
- //Test updating a category's parent
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QPlaceCategory fastFood;
- fastFood.setName(QLatin1String("Fast Food"));
- QVERIFY(doSaveCategory(fastFood, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fastFood.setCategoryId(categoryId);
-
- QPlaceCategory fineDining;
- fineDining.setName(QLatin1String("Fine dining"));
- QVERIFY(doSaveCategory(fineDining, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fineDining.setCategoryId(categoryId);
-
- QPlaceCategory pancakes;
- pancakes.setName(QLatin1String("Pancakes"));
- QVERIFY(doSaveCategory(pancakes, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- pancakes.setCategoryId(categoryId);
-
- QPlaceCategory pizza;
- pizza.setName(QLatin1String("Pizza"));
- QVERIFY(doSaveCategory(pizza, fastFood.categoryId(), QPlaceReply::NoError, &categoryId));
- pizza.setCategoryId(categoryId);
-
- QPlaceCategory burgers;
- burgers.setName(QLatin1String("burgers"));
- QVERIFY(doSaveCategory(burgers, fastFood.categoryId(), QPlaceReply::NoError, &categoryId));
- burgers.setCategoryId(categoryId);
-
- //resave pizza as a child of fine dining
- QVERIFY(doSaveCategory(pizza, fineDining.categoryId()));
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- //check that fast food no longer has pizza as a child
- categories = placeManager->childCategories(fastFood.categoryId());
- QVERIFY(categories.contains(burgers));
- QCOMPARE(categories.count(), 1);
-
- //check that fine dining has pizza as a child
- categories = placeManager->childCategories(fineDining.categoryId());
- QVERIFY(categories.contains(pizza));
- QCOMPARE(categories.count(), 1);
-}
-
-void tst_QPlaceManagerJsonDb::savePlaceWithCategory()
-{
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QString placeId;
- QPlace monolithBurgers;
- monolithBurgers.setName(QLatin1String("Monolith burgers"));
- monolithBurgers.setCategory(restaurant);
- QVERIFY(doSavePlace(monolithBurgers,QPlaceReply::NoError, &placeId));
- monolithBurgers.setPlaceId(placeId);
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.categories().count(), 1);
- QCOMPARE(retrievedPlace.categories().first(), restaurant);
-
- //update place with multiple categories
- QPlaceCategory facilities;
- facilities.setName(QLatin1String("facilities"));
- QVERIFY(doSaveCategory(facilities, QPlaceReply::NoError, &categoryId));
- facilities.setCategoryId(categoryId);
-
- QList<QPlaceCategory> categories;
- categories << facilities << restaurant;
- monolithBurgers.setCategories(categories);
- QVERIFY(doSavePlace(monolithBurgers,QPlaceReply::NoError, &placeId));
-
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.categories().count(), 2);
- QSet<QPlaceCategory> catSet;
-
- QVERIFY(retrievedPlace.categories().contains(facilities));
- QVERIFY(retrievedPlace.categories().contains(restaurant));
-}
-
-void tst_QPlaceManagerJsonDb::searchByName()
-{
- QPlace adelaide, adel, ad, brisbane, bradel;
- adelaide.setName(QLatin1String("Adelaide"));
- adel.setName(QLatin1String("adel"));
- ad.setName(QLatin1String("ad"));
- brisbane.setName(QLatin1String("brisbane"));
- bradel.setName(QLatin1String("bradel"));
-
- QList<QPlace *> places;
- places << &adelaide << &adel << &ad << &brisbane << &bradel;
- setVisibility(places, QLocation::DeviceVisibility);
- doSavePlaces(places);
-
- //test that search has exhibits substring behaviour
- //and is case insensitive
- QPlaceSearchRequest request;
- request.setSearchTerm(QLatin1String("adel"));
- QList<QPlace> results;
- QVERIFY(doSearch(request, &results));
- QList<QPlace> expectedPlaces;
- expectedPlaces << adelaide << adel << bradel;
- QVERIFY(PlaceManagerUtils::compare(results, expectedPlaces));
-
- //Search for a non-exisent place
- request.setSearchTerm(QLatin1String("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<QPlace> places;
- for (int i = 0; i < coords.size(); ++i) {
- QPlace place;
- QGeoLocation location;
- location.setCoordinate(coords.at(i));
- place.setLocation(location);
- places << place;
- }
- doSavePlaces(places);
-
- QPlaceSearchRequest request;
- request.setSearchArea(QGeoRectangle(QGeoCoordinate(5.0, -5.0), QGeoCoordinate(-5.0, 5.0)));
-
- QList<QPlace> places1;
- doSearch(request, &places1);
- 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(QGeoRectangle(QGeoCoordinate(5.0, 10.0), QGeoCoordinate(-5.0, 20.0)));
- QList<QPlace> 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(QGeoRectangle(QGeoCoordinate(20.0, -5.0), QGeoCoordinate(10.0, 5.0)));
- QList<QPlace> 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(QGeoRectangle(QGeoCoordinate(20.0, 10.0), QGeoCoordinate(10.0, 20.0)));
- QList<QPlace> 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(QGeoRectangle(QGeoCoordinate(5.0, 175.0), QGeoCoordinate(-5.0, -175.0)));
- QList<QPlace> 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(QGeoRectangle(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(QGeoRectangle(QGeoCoordinate(20,20), QGeoCoordinate(50,30)));
- QVERIFY(doSearch(request,&places, QPlaceReply::BadArgumentError));
-
- //try an invalid coordinate for one of the corners
- request.setSearchArea(QGeoRectangle(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) {
- QPlace 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));
-
- 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) {
- QList<QPlace> places;
- request.setSearchArea(QGeoCircle(filterCoords.at(j),dist));
-
- if (i ==2 || i ==3)
- continue; //TODO: Testing poles, ignore for now
- else
- doSearch(request, &places);
-
- if (places.size() != plCoords.size()) {
- for (int k = 0; k < places.size(); ++k)
- qWarning() << QLatin1String("pl") << places.at(k).location().coordinate().toString(QGeoCoordinate::Degrees);
- for (int k = 0; k < plCoords.size(); ++k)
- qWarning() << QLatin1String("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()));
- }
- }
- }
-
- QList<QPlace> places;
- //--- Test error conditions and edge cases
- //try a circle that covers the north pole
- QPlaceSearchRequest request;
- request.setSearchArea(QGeoCircle(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(QGeoCircle(QGeoCoordinate(89.91,0),9000));
- QVERIFY(doSearch(request,&places, QPlaceReply::NoError));
-
- //try a circle that covers the south pole
- request.setSearchArea(QGeoCircle(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(QGeoCircle(QGeoCoordinate(-89.91,180),9000));
- QVERIFY(doSearch(request, &places, QPlaceReply::NoError));
-
- //try a radius of 0
- request.setSearchArea(QGeoCircle(QGeoCoordinate(11.0,11.0), 0));
- QVERIFY(doSearch(request, &places));
- QCOMPARE(places.count(), 1);
- QCOMPARE(places.at(0).location().coordinate().latitude(), 11.0);
- QCOMPARE(places.at(0).location().coordinate().longitude(), 11.0);
-
- //try an invalid center
- request.setSearchArea(QGeoCircle(QGeoCoordinate(), 5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-
- //try an invalid latitude for the center
- request.setSearchArea(QGeoCircle(QGeoCoordinate(qQNaN(),50), 5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-
- //try a proximity filter with an out of range latitude
- request.setSearchArea(QGeoCircle(QGeoCoordinate(90,10), 5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-
- request.setSearchArea(QGeoCircle(QGeoCoordinate(150,10), 5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-
- //try a proximity filter with an out of range longitude
- request.setSearchArea(QGeoCircle(QGeoCoordinate(-12,180.1),5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-
- request.setSearchArea(QGeoCircle(QGeoCoordinate(-12,-180.1),5000));
- QVERIFY(doSearch(request, &places, QPlaceReply::BadArgumentError));
- QVERIFY(places.isEmpty());
-}
-
-void tst_QPlaceManagerJsonDb::searchWithLexicalPlaceNameHint()
-{
- QPlace melbourne, sydney, adelaide, brisbane;
- melbourne.setName(QLatin1String("Melbourne"));
- sydney.setName(QLatin1String("Sydney"));
- adelaide.setName(QLatin1String("Adelaide"));
- brisbane.setName(QLatin1String("Brisbane"));
-
- QList<QPlace *> places;
- places << &melbourne << &sydney << &adelaide << &brisbane;
- doSavePlaces(places);
- setVisibility(places, QLocation::DeviceVisibility);
-
- QPlaceSearchRequest searchRequest;
- searchRequest.setRelevanceHint(QPlaceSearchRequest::LexicalPlaceNameHint);
- QList<QPlace> results;
- QVERIFY(doSearch(searchRequest, &results));
- QCOMPARE(results.count(), places.count());
- QCOMPARE(results.at(0), adelaide);
- QCOMPARE(results.at(1), brisbane);
- QCOMPARE(results.at(2), melbourne);
- QCOMPARE(results.at(3), sydney);
-}
-
-void tst_QPlaceManagerJsonDb::searchWithDistanceHint()
-{
- QList<QPlace *> places;
-
- QPlace place1;
- place1.setName(QLatin1String("LM1"));
- QGeoLocation location;
- location.setCoordinate(QGeoCoordinate(20,19));
- place1.setLocation(location);
- places << &place1;
-
- QPlace place2;
- place2.setName(QLatin1String("LM2"));
- location.setCoordinate(QGeoCoordinate(20,50));
- place2.setLocation(location);
- places << &place2;
-
- QPlace place3;
- place3.setName(QLatin1String("LM3"));
- location.setCoordinate(QGeoCoordinate(20, 30));
- place3.setLocation(location);
- places << &place3;
-
- QPlace place4;
- place4.setName(QLatin1String("LM4"));
- location.setCoordinate(QGeoCoordinate(5,20));
- place4.setLocation(location);
- places << &place4;
-
- QPlace place5;
- place5.setName(QLatin1String("LM5"));
- location.setCoordinate(QGeoCoordinate(80,20));
- place5.setLocation(location);
- places << &place5;
-
- QPlace place6;
- place6.setName(QLatin1String("LM6"));
- location.setCoordinate(QGeoCoordinate(60,20));
- place6.setLocation(location);
- places << &place6;
-
- doSavePlaces(places);
- setVisibility(places, QLocation::DeviceVisibility);
-
- QPlaceSearchRequest searchRequest;
- QGeoCircle circle(QGeoCoordinate(20,20));
- searchRequest.setSearchArea(circle);
- searchRequest.setRelevanceHint(QPlaceSearchRequest::DistanceHint);
- QList<QPlace> results;
- QVERIFY(doSearch(searchRequest, &results));
- QCOMPARE(results.count(), 6);
- QCOMPARE(results.at(0), place1);
- QCOMPARE(results.at(1), place3);
- QCOMPARE(results.at(2), place4);
- QCOMPARE(results.at(3), place2);
- QCOMPARE(results.at(4), place6);
- QCOMPARE(results.at(5), place5);
-
- qreal radius = QGeoCoordinate(20,20).distanceTo(QGeoCoordinate(20,50));
- circle.setRadius(radius);
- searchRequest.setSearchArea(circle);
- QVERIFY(doSearch(searchRequest, &results));
-
- QCOMPARE(results.count(),4);
- QCOMPARE(results.at(0), place1);
- QCOMPARE(results.at(1), place3);
- QCOMPARE(results.at(2), place4);
- QCOMPARE(results.at(3), place2);
-
- //try radius less than 1
- circle.setRadius(-5);
- searchRequest.setSearchArea(circle);
- QVERIFY(doSearch(searchRequest, &results));
-
- QCOMPARE(results.count(), 6);
- QCOMPARE(results.at(0), place1);
- QCOMPARE(results.at(1), place3);
- QCOMPARE(results.at(2), place4);
- QCOMPARE(results.at(3), place2);
- QCOMPARE(results.at(4), place6);
- QCOMPARE(results.at(5), place5);
-}
-
-void tst_QPlaceManagerJsonDb::searchByCategory()
-{
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QString placeId;
- QPlace park;
- park.setName(QLatin1String("Park"));
- QVERIFY(doSavePlace(park, QPlaceReply::NoError, &placeId));
- park.setPlaceId(placeId);
-
- QList<QPlaceCategory> categories;
- categories << restaurant;
-
- QPlace krustyBurger;
- krustyBurger.setName(QLatin1String("Krusty burger"));
- krustyBurger.setCategories(categories);
- QVERIFY(doSavePlace(krustyBurger, QPlaceReply::NoError, &placeId));
- krustyBurger.setPlaceId(placeId);
- krustyBurger.setVisibility(QLocation::DeviceVisibility);
-
- QList<QPlace> places;
- QPlaceSearchRequest request;
- request.setCategory(restaurant);
- QVERIFY(doSearch(request, &places));
- QCOMPARE(places.count(), 1);
- QCOMPARE(places.at(0), krustyBurger);
-}
-
-void tst_QPlaceManagerJsonDb::unsupportedFunctions()
-{
- QPlace place;
- place.setPlaceId(QLatin1String("id"));
- QPlaceContentRequest request;
- request.setContentType(QPlaceContent::ImageType);
- request.setLimit(5);
- request.setOffset(0);
- QPlaceContentReply *contentReply = placeManager->getPlaceContent(place.placeId(), request);
- QSignalSpy contentSpy(contentReply, SIGNAL(finished()));
- QTRY_VERIFY_WITH_TIMEOUT(contentSpy.count() == 1, Timeout);
- QCOMPARE(contentReply->error(), QPlaceReply::UnsupportedError);
-
- QPlaceSearchRequest searchRequest;
- QPlaceSearchSuggestionReply *searchSuggestionReply = placeManager->searchSuggestions(searchRequest);
- QSignalSpy searchSuggestionSpy(searchSuggestionReply, SIGNAL(finished()));
- QTRY_VERIFY_WITH_TIMEOUT(searchSuggestionSpy.count() == 1, Timeout);
- QCOMPARE(searchSuggestionReply->error(), QPlaceReply::UnsupportedError);
-}
-
-void tst_QPlaceManagerJsonDb::supportedFeatures()
-{
- QGeoServiceProvider::PlacesFeatures f = QGeoServiceProvider::NoPlacesFeatures;
-
- f |= QGeoServiceProvider::OfflinePlacesFeature;
- f |= QGeoServiceProvider::SavePlaceFeature;
- f |= QGeoServiceProvider::RemovePlaceFeature;
- f |= QGeoServiceProvider::SaveCategoryFeature;
- f |= QGeoServiceProvider::RemoveCategoryFeature;
- f |= QGeoServiceProvider::PlaceMatchingFeature;
-
- QCOMPARE(provider->placesFeatures(), f);
-}
-
-void tst_QPlaceManagerJsonDb::categoryFunctions()
-{
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QPlaceCategory fastFood;
- fastFood.setName(QLatin1String("Fast Food"));
- QVERIFY(doSaveCategory(fastFood, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fastFood.setCategoryId(categoryId);
-
- QPlaceCategory fineDining;
- fineDining.setName(QLatin1String("Fine dining"));
- QVERIFY(doSaveCategory(fineDining, restaurant.categoryId(), QPlaceReply::NoError, &categoryId));
- fineDining.setCategoryId(categoryId);
- QPlaceReply *reply = placeManager->initializeCategories();
- QVERIFY(checkSignals(reply, QPlaceReply::NoError));
-
- //try find a parent id
- QCOMPARE(placeManager->parentCategoryId(fineDining.categoryId()), restaurant.categoryId());
-
- //try find the parent id of a top level category
- QCOMPARE(placeManager->parentCategoryId(restaurant.categoryId()), QString());
-
- //try find the parent id of a non-existent category.
- QCOMPARE(placeManager->parentCategoryId(QLatin1String("does-not-exist")), QString());
-
- //try find the child ids
- QStringList childIds = placeManager->childCategoryIds(restaurant.categoryId());
- QVERIFY(childIds.contains(fastFood.categoryId()));
- QVERIFY(childIds.contains(fineDining.categoryId()));
- QCOMPARE(childIds.count(), 2);
-
- //try find the child id of a category without a child
- QCOMPARE(placeManager->childCategoryIds(fineDining.categoryId()), QStringList());
-
- //try to find child ids of a non-existent category
- QCOMPARE(placeManager->childCategoryIds(QLatin1String("does-not-exist")), QStringList());
-
- //try to find a category by it's id
- QCOMPARE(placeManager->category(fastFood.categoryId()), fastFood);
-
- //try to find a category with a non-existent id
- QCOMPARE(placeManager->category(QLatin1String("does-not-exist")), QPlaceCategory());
-}
-
-void tst_QPlaceManagerJsonDb::contactDetails()
-{
- QFETCH(QString, contactType);
- QPlace place;
- //create a place with a single contact detail of a given type
- place.setName(QLatin1String("place"));
- QPlaceContactDetail detail;
- detail.setLabel(QLatin1String("detailLabel"));
- detail.setValue(QLatin1String("detail"));
- place.appendContactDetail(contactType, detail);
-
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- place.setPlaceId(placeId);
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace.contactTypes().contains(contactType));
- QCOMPARE(retrievedPlace.contactDetails(contactType).count(), 1);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(0), detail);
-
- //add multiple details of a given type;
- QPlaceContactDetail detail2;
- detail2.setLabel(QLatin1String("detail2Label"));
- detail2.setValue(QLatin1String("detail2"));
- QPlaceContactDetail detail3;
- detail3.setLabel(QLatin1String("detail3Label"));
- detail3.setValue(QLatin1String("detail3"));
-
- place.appendContactDetail(contactType, detail2);
- place.appendContactDetail(contactType, detail3);
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.contactDetails(contactType).count(), 3);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(0), detail);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(1), detail2);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(2), detail3);
-
- //try removing a detail
- QList<QPlaceContactDetail> details;
- details << detail <<detail3;
- place.setContactDetails(contactType, details);
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.contactDetails(contactType).count(), 2);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(0), detail);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(1), detail3);
-
- //try remove all details
- place.removeContactDetails(contactType);
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace.contactTypes().contains(contactType) == false);
- QCOMPARE(retrievedPlace.contactDetails(contactType).count(), 0);
-
- //try creating a place with multiple contact details of a given type.
- QPlace place2;
- place2.setContactDetails(contactType, details);
- QVERIFY(doSavePlace(place2, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace.contactTypes().contains(contactType) == true);
- QCOMPARE(retrievedPlace.contactDetails(contactType).count(), 2);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(0), detail);
- QCOMPARE(retrievedPlace.contactDetails(contactType).at(1), detail3);
-}
-
-void tst_QPlaceManagerJsonDb::contactDetails_data()
-{
- QTest::addColumn<QString>("contactType");
-
- QTest::newRow("phone") << QPlaceContactDetail::Phone;
- QTest::newRow("email") << QPlaceContactDetail::Email;
- QTest::newRow("website") << QPlaceContactDetail::Website;
- QTest::newRow("fax") << QPlaceContactDetail::Fax;
-}
-
-void tst_QPlaceManagerJsonDb::mulipleDetailTypes()
-{
- //try saving a place with multiple detail types simultaneously.
- QPlace place;
- place.setName(QLatin1String("Char"));
-
- QPlaceContactDetail phone;
- phone.setLabel(QLatin1String("phone1"));
- phone.setValue(QLatin1String("555-5555"));
- QPlaceContactDetail phone2;
- phone2.setLabel(QLatin1String("phone2"));
- phone2.setValue(QLatin1String("444-4444"));
- QList<QPlaceContactDetail> phones;
- place.setContactDetails(QPlaceContactDetail::Phone, phones);
-
- QPlaceContactDetail fax;
- fax.setLabel(QLatin1String("fax1"));
- fax.setValue(QLatin1String("999-9999"));
- QPlaceContactDetail fax2;
- fax2.setLabel(QLatin1String("fax2"));
- fax2.setValue(QLatin1String("999-9999"));
- QList<QPlaceContactDetail> faxes;
- place.setContactDetails(QPlaceContactDetail::Fax, faxes);
-
- QPlaceContactDetail email;
- email.setValue(QLatin1String("email@adddress.com"));
- QPlaceContactDetail email2;
- email2.setValue(QLatin1String("email2@adddress.com"));
- place.appendContactDetail(QPlaceContactDetail::Email, email);
- place.appendContactDetail(QPlaceContactDetail::Email, email2);
-
- QPlaceContactDetail website;
- website.setLabel(QLatin1String("website"));
- website.setValue(QLatin1String("www.example.com"));
- QPlaceContactDetail website2;
- website2.setLabel(QLatin1String("website2"));
- website2.setValue(QLatin1String("www.example2.com"));
- place.appendContactDetail(QPlaceContactDetail::Website, website);
- place.appendContactDetail(QPlaceContactDetail::Website, website2);
-
- //Save a place
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- place.setVisibility(QLocation::DeviceVisibility);
-
- //ensure we can retrieve it's details
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- place.setPlaceId(placeId);
- QVERIFY(retrievedPlace == place);
-
- //try adding some more, changing and removing details of different types
- //when updating a place.
- phone2.setValue(QLatin1String("222-2222")); //modify detail
- phones.clear();
- phones << phone << phone2;
- place.setContactDetails(QPlaceContactDetail::Phone, phones);
-
- //remove an entire set of details
- place.removeContactDetails(QPlaceContactDetail::Fax);
-
- //add remove one detail
- QList<QPlaceContactDetail> emails;
- emails << email2;
- place.setContactDetails(QPlaceContactDetail::Email, emails);
-
- //add more of a detail
- QPlaceContactDetail website3;
- website3.setLabel(QLatin1String("website3"));
- website3.setValue(QLatin1String("www.example3.com"));
- place.appendContactDetail(QPlaceContactDetail::Website, website3);
-
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace == place);
-}
-
-void tst_QPlaceManagerJsonDb::placeNotifications()
-{
- QSignalSpy createSpy(placeManager, SIGNAL(placeAdded(QString)));
- QSignalSpy updateSpy(placeManager, SIGNAL(placeUpdated(QString)));
- QSignalSpy removeSpy(placeManager, SIGNAL(placeRemoved(QString)));
-
- //create place
- QPlace place;
- place.setName(QLatin1String("Char"));
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- place.setPlaceId(placeId);
-
- QTRY_VERIFY_WITH_TIMEOUT(createSpy.count() == 1, Timeout);
- createSpy.clear();
- QVERIFY(updateSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
-
- //modify place
- QGeoLocation location;
- location.setCoordinate(QGeoCoordinate(10,10));
- place.setLocation(location);
- QVERIFY(doSavePlace(place, QPlaceReply::NoError));
- QTRY_VERIFY_WITH_TIMEOUT(updateSpy.count() == 1, Timeout);
- updateSpy.clear();
- QVERIFY(createSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
-
- //remove place
- QVERIFY(doRemovePlace(place, QPlaceReply::NoError));
- QTRY_VERIFY_WITH_TIMEOUT(removeSpy.count() == 1, Timeout);
- removeSpy.clear();
- QVERIFY(createSpy.count() == 0);
- QVERIFY(updateSpy.count() == 0);
-}
-
-void tst_QPlaceManagerJsonDb::categoryNotifications()
-{
- QSignalSpy createSpy(placeManager, SIGNAL(categoryAdded(QPlaceCategory,QString)));
- QSignalSpy updateSpy(placeManager, SIGNAL(categoryUpdated(QPlaceCategory,QString)));
- QSignalSpy removeSpy(placeManager, SIGNAL(categoryRemoved(QString,QString)));
-
- //create category
- QString restaurantId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &restaurantId));
- restaurant.setCategoryId(restaurantId);
- QTRY_VERIFY_WITH_TIMEOUT(createSpy.count() == 1, Timeout);
- createSpy.clear();
- QVERIFY(updateSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
-
- //modify category
- restaurant.setName(QLatin1String("RESTAURANT"));
- QVERIFY(doSaveCategory(restaurant));
- QTRY_VERIFY_WITH_TIMEOUT(updateSpy.count() == 1, Timeout);
- updateSpy.clear();
- QVERIFY(createSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
-
- QVERIFY(doRemoveCategory(restaurant));
- QTRY_VERIFY_WITH_TIMEOUT(removeSpy.count() == 1, Timeout);
- removeSpy.clear();
- QVERIFY(createSpy.count() == 0);
- QVERIFY(updateSpy.count() == 0);
-
- restaurant.setCategoryId(QString());
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &restaurantId));
- QTRY_VERIFY_WITH_TIMEOUT(createSpy.count() == 1, Timeout);
- createSpy.clear();
- QVERIFY(updateSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
-
- //save a category as a child
- QString steakId;
- QPlaceCategory steak;
- steak.setName(QLatin1String("Steak"));
-
- QVERIFY(doSaveCategory(steak, restaurantId, QPlaceReply::NoError, &steakId));
- steak.setCategoryId(steakId);
- QTRY_VERIFY_WITH_TIMEOUT(createSpy.count() == 1, Timeout);
- QVERIFY(createSpy.at(0).at(0).value<QPlaceCategory>() == steak);
- createSpy.clear();
- QVERIFY(updateSpy.count() == 0);
- QVERIFY(removeSpy.count() == 0);
- }
-
-void tst_QPlaceManagerJsonDb::compatiblePlace()
-{
- QGeoServiceProvider geoTest(QLatin1String("qmlgeo.test.plugin"));
- geoTest.setAllowExperimental(true);
- QPlaceManager *geoTestManager = geoTest.placeManager();
- QVERIFY(geoTestManager);
-
- QPlace place;
- place.setPlaceId(QLatin1String("123"));
- place.setName(QLatin1String("Moe's Tavern"));
-
- QGeoAddress address;
- address.setStreet(QLatin1String("93 Brewing Ave"));
- address.setDistrict(QLatin1String("Maine"));
- address.setCity(QLatin1String("Springfield"));
- address.setCounty(QLatin1String("Jackson"));
- address.setState(QLatin1String("Minnesota"));
- address.setCountry(QLatin1String("Unisted Statess"));
- address.setCountryCode(QLatin1String("USA"));
- QGeoCoordinate coord(56,34,5);
-
- QGeoLocation location;
- location.setAddress(address);
- location.setCoordinate(coord);
- location.setBoundingBox(QGeoRectangle(QGeoCoordinate(20,20), QGeoCoordinate(10,30)));
- place.setLocation(location);
-
- QPlaceContactDetail phone;
- phone.setLabel(QLatin1String("Phone"));
- phone.setValue(QLatin1String("555-1793"));
- place.appendContactDetail(QPlaceContactDetail::Phone, phone);
-
- QPlaceSupplier supplier;
- supplier.setName(QLatin1String("Springfield brewery"));
- supplier.setSupplierId(QLatin1String("ID"));
-
- place.setSupplier(supplier);
-
- QPlaceImage image;
- image.setImageId(QLatin1String("798"));
- image.setUrl(QUrl("http://image.com/"));
- QPlaceContent::Collection imageCollection;
- imageCollection.insert(0,image);
- place.insertContent(QPlaceContent::ImageType, imageCollection);
- place.setTotalContentCount(QPlaceContent::ImageType, 1);
-
- QPlaceAttribute attribute;
- attribute.setLabel(QLatin1String("Smoking"));
- attribute.setText(QLatin1String("Yes"));
-
- QPlaceIcon icon;
- QVariantMap iconParams;
- iconParams.insert(QLatin1String("s"), QLatin1String("www.example.com/small.png"));
- iconParams.insert(QLatin1String("m"), QLatin1String("www.example.com/medium.png"));
- iconParams.insert(QLatin1String("l"), QLatin1String("www.example.com/large.png"));
- icon.setParameters(iconParams);
- icon.setManager(geoTestManager);
- place.setIcon(icon);
-
- place.setExtendedAttribute(QLatin1String("Smoking"), attribute);
-
- place.setVisibility(QLocation::PublicVisibility);
-
- QPlace compatPlace = placeManager->compatiblePlace(place);
-
- QVERIFY(compatPlace.placeId().isEmpty());
- QCOMPARE(compatPlace.name(),QLatin1String("Moe's Tavern"));
- QCOMPARE(compatPlace.location().address(), address);
- QVERIFY(compatPlace.location().coordinate() != location.coordinate());
- location.setCoordinate(QGeoCoordinate(56,34));
- QVERIFY(compatPlace.location().coordinate() == location.coordinate());
- QVERIFY(compatPlace.location().boundingBox().isEmpty());
-
- QCOMPARE(compatPlace.contactTypes().count(), 1);
- QVERIFY(compatPlace.contactTypes().contains(QPlaceContactDetail::Phone));
- QCOMPARE(compatPlace.contactDetails(QPlaceContactDetail::Phone).count(), 1);
- QCOMPARE(compatPlace.contactDetails(QPlaceContactDetail::Phone).at(0), phone);
-
- QCOMPARE(compatPlace.supplier(), QPlaceSupplier());
- QVERIFY(compatPlace.content(QPlaceContent::ImageType).isEmpty());
- QVERIFY(compatPlace.content(QPlaceContent::ReviewType).isEmpty());
- QVERIFY(compatPlace.content(QPlaceContent::EditorialType).isEmpty());
- QCOMPARE(compatPlace.totalContentCount(QPlaceContent::ImageType), 0);
- QCOMPARE(compatPlace.totalContentCount(QPlaceContent::ReviewType), 0);
- QCOMPARE(compatPlace.totalContentCount(QPlaceContent::EditorialType), 0);
-
- QCOMPARE(compatPlace.icon().parameters().value(SmallSource).toString(), QLatin1String("www.example.com/small.png"));
- QCOMPARE(compatPlace.icon().parameters().value(MediumSource).toString(), QLatin1String("www.example.com/medium.png"));
- QCOMPARE(compatPlace.icon().parameters().value(LargeSource).toString(), QLatin1String("www.example.com/large.png"));
-
- QVERIFY(compatPlace.extendedAttributeTypes().contains(QLatin1String("Smoking")));
- QCOMPARE(compatPlace.extendedAttribute(QLatin1String("Smoking")), attribute);
-
- QCOMPARE(compatPlace.visibility(), QLocation::UnspecifiedVisibility);
-}
-
-void tst_QPlaceManagerJsonDb::extendedAttribute()
-{
- QPlaceAttribute attribute;
- attribute.setLabel(QLatin1String("x_id_nokia"));
- attribute.setText(QLatin1String("ae562"));
- QPlace place;
- place.setExtendedAttribute(QLatin1String("x_id_nokia"), attribute);
-
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId,&retrievedPlace));
- QVERIFY(retrievedPlace.extendedAttributeTypes().contains(QLatin1String("x_id_nokia")));
-}
-
-void tst_QPlaceManagerJsonDb::matchingPlaces()
-{
- QFETCH(QString, matchType);
-
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- restaurant.setCategoryId(categoryId);
-
- QPlaceCategory park;
- park.setName(QLatin1String("Park"));
- QVERIFY(doSaveCategory(park, QPlaceReply::NoError, &categoryId));
- park.setCategoryId(categoryId);
-
- QPlaceCategory travel;
- travel.setName(QLatin1String("Travel"));
- QVERIFY(doSaveCategory(travel, QPlaceReply::NoError, &categoryId));
- travel.setCategoryId(categoryId);
-
- QPlace place1;
- place1.setPlaceId(QLatin1String("abcd"));
- place1.setName(QLatin1String("place1"));
- QGeoLocation location;
- location.setCoordinate(QGeoCoordinate(1,1));
- place1.setLocation(location);
-
- if (matchType == QPlaceMatchRequest::AlternativeId) {
- QPlaceAttribute origin1;
- origin1.setText(QLatin1String("nokia"));
- place1.setExtendedAttribute(QLatin1String("x_provider"), origin1);
- }
-
- QPlace place1Saved;
- place1Saved = placeManager->compatiblePlace(place1);
-
- QString placeId;
- QVERIFY(doSavePlace(place1Saved, QPlaceReply::NoError, &placeId));
- place1Saved.setPlaceId(placeId);
- place1Saved.setVisibility(QLocation::DeviceVisibility);
-
- QPlaceResult result1;
- result1.setPlace(place1);
-
- QList<QPlaceSearchResult> results;
- results << result1;
-
- QPlaceMatchRequest matchRequest;
- QVariantMap parameters;
- if (matchType == QPlaceMatchRequest::AlternativeId)
- parameters.insert(QPlaceMatchRequest::AlternativeId, QLatin1String("x_id_nokia"));
- else
- parameters.insert(QLatin1String("proximityRange"), 0);
- matchRequest.setParameters(parameters);
- matchRequest.setResults(results);
- QList<QPlace> places;
- QVERIFY(doMatch(matchRequest,&places));
- QCOMPARE(places.count(), 1);
- QCOMPARE(place1Saved, places.at(0));
-
- //try matching multiple places
- QPlace nonMatchingPlace;
- nonMatchingPlace.setName(QLatin1String("Non matching"));
- nonMatchingPlace.setPlaceId(QLatin1String("1234"));
- QPlaceAttribute originNonMatch;
- originNonMatch.setText(QLatin1String("nokia"));
- nonMatchingPlace.setExtendedAttribute(QLatin1String("x_provider"),originNonMatch);
- QPlaceResult nonMatchingResult;
- nonMatchingResult.setPlace(nonMatchingPlace);
- results.insert(1, nonMatchingResult);
-
- QPlace place2;
- place2.setName(QLatin1String("place2"));
- place2.setPlaceId(QLatin1String("efgh"));
- location.setCoordinate(QGeoCoordinate(2,2));
- place2.setLocation(location);
-
- if (matchType == QPlaceMatchRequest::AlternativeId) {
- QPlaceAttribute origin2;
- origin2.setText(QLatin1String("nokia"));
- place2.setExtendedAttribute(QLatin1String("x_provider"), origin2);
- }
-
- QPlace place2Saved = placeManager->compatiblePlace(place2);
- QVERIFY(doSavePlace(place2Saved, QPlaceReply::NoError, &placeId));
- place2Saved.setPlaceId(placeId);
- place2Saved.setVisibility(QLocation::DeviceVisibility);
-
- QPlaceResult result2;
- result2.setPlace(place2);
- results.clear();
- results << result1 << nonMatchingResult << result2;
-
- matchRequest.setResults(results);
- QVERIFY(doMatch(matchRequest, &places));
- QCOMPARE(places.count(), 3);
- QCOMPARE(places.at(0), place1Saved);
-
- QCOMPARE(places.at(1), QPlace());
- QCOMPARE(places.at(2), place2Saved);
-
- //check that if we have assigned categories, the results with return those
- //categories in a match
- QList<QPlaceCategory> categories;
- categories << restaurant << travel;
- place2Saved.setCategories(categories);
- QVERIFY(doSavePlace(place2Saved, QPlaceReply::NoError, &placeId));
-
- QVERIFY(doMatch(matchRequest, &places));
- QCOMPARE(places.count(), 3);
- QCOMPARE(places.at(0), place1Saved);
- QCOMPARE(places.at(1), QPlace());
- QCOMPARE(places.at(2), place2Saved);
-}
-
-void tst_QPlaceManagerJsonDb::matchingPlaces_data()
-{
- QTest::addColumn<QString>("matchType");
- QTest::newRow("Alternative Id") << QPlaceMatchRequest::AlternativeId;
- QTest::newRow("Proximity") << "proximity";
-}
-
-void tst_QPlaceManagerJsonDb::iconSourceDestination()
-{
- //We test that an input source icon is correctly copied to it's specified destination
- //Source and Destination urls are provided
- QFETCH(QString, sourceIconResource);
- QFETCH(QSize, iconSize);
- QFETCH(QString, iconType);
- QFETCH(QString, source);
- QFETCH(QString, specifiedDestination);
-
- for (int destUrlCorrectness = ValidUrl; destUrlCorrectness != (NoSchemeUrl +1); ++destUrlCorrectness) {
- for (int destFileExists = Exists; destFileExists != (DoesNotExist + 1); ++destFileExists) {
- QPlace place;
- place.setName("place");
-
- QPlaceCategory category;
- category.setName("category");
-
- QPlaceIcon icon;
- QVariantMap iconParams;
-
- QTemporaryFile sourceIconFile;
-
- if (iconType.startsWith(QLatin1String("file"))) {
- QImage sourceIconImage(sourceIconResource);
- sourceIconFile.open();
- sourceIconImage.save(sourceIconFile.fileName(), QImageReader::imageFormat(sourceIconResource));
- if (iconType == QLatin1String("file"))
- iconParams.insert(source, QUrl::fromLocalFile(sourceIconFile.fileName()));
- else if (iconType == QLatin1String("file_improperUrl"))
- iconParams.insert(source, QUrl(sourceIconFile.fileName()));
- else
- qFatal("Unknown icon type");
- } else if (iconType == QLatin1String("dataUrl")) {
- QFile sourceIcon(sourceIconResource);
- sourceIcon.open(QIODevice::ReadOnly);
- QString mimeType;
- if (QImageReader::imageFormat(sourceIconResource) == "png")
- mimeType = QLatin1String("image/png");
- QUrl dataUrl(QString::fromLatin1("data:") + mimeType + QLatin1String(";base64,") + sourceIcon.readAll().toBase64());
- iconParams.insert(source, dataUrl);
- }
-
- QTemporaryDir tempDir;
- QVERIFY(tempDir.isValid());
- QString destIconFileName = tempDir.path() + QLatin1String("/tempFile");
- if (destFileExists == Exists) {
- QFile destFile(destIconFileName);
- destFile.open(QIODevice::ReadWrite);
- destFile.close();
- }//else must be creating a new destination file
-
- if (destUrlCorrectness == ValidUrl)
- iconParams.insert(specifiedDestination, QUrl::fromLocalFile(destIconFileName));
- else //must be no scheme url
- iconParams.insert(specifiedDestination, QUrl(destIconFileName));
-
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
-
- QString placeId;
- QString categoryId;
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
-
- QPlace retrievedPlace;
- QPlaceCategory retrievedCategory;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
-
- QVERIFY(retrievedPlace.icon().parameters().contains(specifiedDestination));
- QVERIFY(retrievedCategory.icon().parameters().contains(specifiedDestination));
-
- QUrl retrievedUrl = retrievedPlace.icon().parameters().value(specifiedDestination).toUrl();
- QCOMPARE(retrievedCategory.icon().parameters().value(specifiedDestination).toUrl(), retrievedUrl);
-
- QImage retrievedImage;
-
- QVERIFY(retrievedUrl.scheme().compare(QLatin1String("file"), Qt::CaseInsensitive) == 0);
- retrievedImage = QImage(retrievedUrl.toLocalFile());
-
- QCOMPARE(retrievedImage.size(), iconSize);
- }
- }
-}
-
-void tst_QPlaceManagerJsonDb::iconSourceDestination_data()
-{
- QTest::addColumn<QString>("sourceIconResource");
- QTest::addColumn<QSize>("iconSize");
- QTest::addColumn<QString>("iconType");
- QTest::addColumn<QString>("source");
- QTest::addColumn<QString>("specifiedDestination");
-
- //Specify source and destionation, expect file to be copied into destination file
- QTest::newRow("source destination small file") << ":/resources/icon_small.png" << QSize(20,20) << "file" << SmallSource << SmallDestination;
- QTest::newRow("source destination medium file") << ":/resources/icon_medium.png" << QSize(30,30) << "file" << MediumSource << MediumDestination;
- QTest::newRow("source destination large file") << ":/resources/icon_large.png" << QSize(50,50) << "file" << LargeSource << LargeDestination;
- QTest::newRow("source destination fullscreen file") << ":/resources/icon_fullscreen.png" << QSize(320,480) << "file" << FullscreenSource << FullscreenDestination;
-
- //Specify source and destination, expect data url to be copied into destination url
- QTest::newRow("source destination small dataUrl") << ":/resources/icon_small.png" << QSize(20,20) << "dataUrl" << SmallSource << SmallDestination;
- QTest::newRow("source destination medium dataUrl") << ":/resources/icon_medium.png" << QSize(30,30) << "dataUrl" << MediumSource << MediumDestination;
- QTest::newRow("source destination large dataUrl") << ":/resources/icon_large.png" << QSize(50,50) << "dataUrl" << LargeSource << LargeDestination;
- QTest::newRow("source destination fullscreen dataUrl") << ":/resources/icon_fullscreen.png" << QSize(320,480) << "dataUrl" << FullscreenSource << FullscreenDestination;
-
- //try using improper source file urls, e.g. /some/path rather than file:///some/path
- QTest::newRow("source destination small file_improperUrl") << ":/resources/icon_small.png" << QSize(20,20) << "file_improperUrl" << SmallSource << SmallDestination;
- QTest::newRow("source destination medium file_improperUrl") << ":/resources/icon_medium.png" << QSize(30,30) << "file_improperUrl" << MediumSource << MediumDestination;
- QTest::newRow("source destination large file_improperUrl") << ":/resources/icon_large.png" << QSize(50,50) << "file_improperUrl" << LargeSource << LargeDestination;
- QTest::newRow("source destination fullscreen file_improperUrl") << ":/resources/icon_fullscreen.png" << QSize(320,480) << "file_improperUrl" << FullscreenSource << FullscreenDestination;
-}
-
-void tst_QPlaceManagerJsonDb::iconSourceOnly()
-{
- //We test that a dataUrl is generated from the given input icon
- //Soucre urls are provided while destination urls
- QFETCH(QString, sourceIconResource);
- QFETCH(QSize, iconSize);
- QFETCH(QString, iconType);
- QFETCH(QString, source);
- QFETCH(QString, expectedDestination);
-
- QPlace place;
- place.setName("place");
-
- QPlaceCategory category;
- category.setName("category");
-
- QPlaceIcon icon;
- QVariantMap iconParams;
-
- QTemporaryFile sourceIconFile;
- if (iconType.startsWith(QLatin1String("file"))) {
- QImage sourceIconImage(sourceIconResource);
- sourceIconFile.open();
- sourceIconImage.save(sourceIconFile.fileName(), QImageReader::imageFormat(sourceIconResource));
- if (iconType == QLatin1String("file"))
- iconParams.insert(source, QUrl::fromLocalFile(sourceIconFile.fileName()));
- else if (iconType == QLatin1String("file_improperUrl"))
- iconParams.insert(source, QUrl(sourceIconFile.fileName()));
- else
- qFatal("Unknown iconType");
- } else if (iconType == QLatin1String("dataUrl")) {
- QFile sourceIcon(sourceIconResource);
- sourceIcon.open(QIODevice::ReadOnly);
- QString mimeType;
- if (QImageReader::imageFormat(sourceIconResource) == "png")
- mimeType = QLatin1String("image/png");
- else
- qFatal("Unexpected image format");
- QUrl dataUrl(QString::fromLatin1("data:") + mimeType + QLatin1String(";base64,") + sourceIcon.readAll().toBase64());
- iconParams.insert(source, dataUrl);
- } else if (iconType == QLatin1String("accessible_incorrectWebUrl") || iconType == QLatin1String("unaccessible_webUrl")) {
- iconParams.insert(source, QUrl(sourceIconResource));
- }
-
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
-
- QString placeId;
- QString categoryId;
-
- if (iconType == QLatin1String("accessible_incorrectWebUrl")) {
- QVERIFY(doSavePlace(place,QPlaceReply::UnsupportedError));
- QVERIFY(doSaveCategory(category,QPlaceReply::UnsupportedError));
- } else if (iconType == QLatin1String("unaccessible_webUrl")){
- QVERIFY(doSavePlace(place,QPlaceReply::CommunicationError));
- QVERIFY(doSaveCategory(category,QPlaceReply::CommunicationError));
- } else {
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
-
- QPlace retrievedPlace;
- QPlaceCategory retrievedCategory;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- if (expectedDestination != QString()) {
- QVERIFY(retrievedPlace.icon().parameters().contains(expectedDestination));
- QVERIFY(retrievedCategory.icon().parameters().contains(expectedDestination));
-
- QUrl retrievedUrl = retrievedPlace.icon().parameters().value(expectedDestination).toUrl();
- QCOMPARE(retrievedUrl, retrievedCategory.icon().parameters().value(expectedDestination).toUrl());
- QImage retrievedImage;
- if (expectedDestination != QString())
- QVERIFY(retrievedUrl.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0);
- retrievedImage = dataUrlToImage(retrievedUrl);
- QCOMPARE(retrievedImage.size(), iconSize);
- }
- }
-}
-
-void tst_QPlaceManagerJsonDb::iconSourceOnly_data()
-{
- QTest::addColumn<QString>("sourceIconResource");
- QTest::addColumn<QSize>("iconSize");
- QTest::addColumn<QString>("iconType");
- QTest::addColumn<QString>("source");
- QTest::addColumn<QString>("expectedDestination");
-
- //input icon is a file
- QTest::newRow("source small file") << ":/resources/icon_small.png" << SmallSize << "file" << SmallSource << SmallDestination;
- QTest::newRow("source medium file") << ":/resources/icon_medium.png" << MediumSize << "file" << MediumSource << MediumDestination;
- QTest::newRow("source large file") << ":/resources/icon_large.png" << LargeSize << "file" << LargeSource << LargeDestination;
- QTest::newRow("source fullscreen file") << ":/resources/icon_fullscreen.png" << FullscreenSize << "file" << FullscreenSource << ""; //fullscreen icons shouldn't be saved as data urls
-
- //input is a file but an improper url (e.g of the format /some/path instead of file:///some/path)
- QTest::newRow("source small file_improperUrl") << ":/resources/icon_small.png" << SmallSize << "file_improperUrl" << SmallSource << SmallDestination;
- QTest::newRow("source medium file_improperUrl") << ":/resources/icon_medium.png" << MediumSize << "file_improperUrl" << MediumSource << MediumDestination;
- QTest::newRow("source large file_improperUrl") << ":/resources/icon_large.png" << LargeSize << "file_improperUrl" << LargeSource << LargeDestination;
- QTest::newRow("source fullscreen file_improperUrl") << ":/resources/icon_fullscreen.png" << FullscreenSize << "file_improperUrl" << FullscreenSource << ""; //fullscreen icons shouldn't be saved as data urls
-
- //input icon is a data url
- QTest::newRow("source small dataUrl") << ":/resources/icon_small.png" << SmallSize << "dataUrl" << SmallSource << SmallDestination;
- QTest::newRow("source medium dataUrl") << ":/resources/icon_medium.png" << MediumSize << "dataUrl" << MediumSource << MediumDestination;
- QTest::newRow("source large dataUrl") << ":/resources/icon_large.png" << LargeSize << "dataUrl" << LargeSource << LargeDestination;
- QTest::newRow("source fullscreen dataUrl") << ":/resources/icon_fullscreen.png" << FullscreenSize << "dataUrl" << FullscreenSource << ""; //fullscreen icons shouldn't be saved as data urls
-
-#ifdef REMOTE_TEST
- //input icon is a reachable url, but does not reference an image
- QTest::newRow("source small accessible_incorrectWebUrl") << "www.example.com/icon_small.png" << SmallSize << "accessible_incorrectWebUrl" << SmallSource << SmallDestination;
- QTest::newRow("source medium accessible_incorrectWebUrl") << "www.example.com/icon_medium.png" << MediumSize << "accessible_incorrectWebUrl" << MediumSource << MediumDestination;
- QTest::newRow("source large accessible_incorrectWebUrl") << "www.example.com/icon_large.png" << LargeSize << "accessible_incorrectWebUrl" << LargeSource << LargeDestination;
- QTest::newRow("source fullscreen accessible_incorrectWebUrl") << "www.example.com/icon_fullscreen.png" << FullscreenSize << "accessible_incorrectWebUrl" << FullscreenSource << ""; //fullscreen icons shouldn't be saved as data urls
-#endif
-
- //input icon is an unnaccessible url
- QTest::newRow("source small unaccessible_webUrl") << "www.non-existetent-example.com/icon_small.png" << SmallSize << "unaccessible_webUrl" << SmallSource << SmallDestination;
- QTest::newRow("source medium unaccessible_webUrl") << "www.non-existetent-example.com/icon_medium.png" << MediumSize << "unaccessible_webUrl" << MediumSource << MediumDestination;
- QTest::newRow("source large unaccessible_webUrl") << "www.non-existetent-example.com/icon_large.png" << LargeSize << "unaccessible_webUrl" << LargeSource << LargeDestination;
- QTest::newRow("source fullscreen unaccessible_webUrl") << "www.non-existetent-example.com/icon_fullscreen.png" << FullscreenSize << "unaccessible_webUrl" << FullscreenSource << ""; //fullscreen icons shouldn't be saved as data urls
-}
-
-void tst_QPlaceManagerJsonDb::iconDestinationOnly()
-{
- //We test when a destination url is provided, that it is correctly saved
- //No soure urls are provided while destination urls are.
- QFETCH(QString, destination);
- QFETCH(QUrl, destinationUrl);
- QFETCH(QSize, specifiedSize);
- QFETCH(QString, iconResource); //empty reosurce indicates icon is not reachable/accessible
-
- QString destinationSize = destination;
- destinationSize.replace(QLatin1String("Url"), QLatin1String("Size"));
-
- QVariantMap iconParams;
-
- QTemporaryFile destinationFile;
- QSize size;
- if (destinationUrl.toString().startsWith("_autogenerated_file_")) {
- QImage iconImage(iconResource);
- destinationFile.open();
- iconImage.save(destinationFile.fileName(), QImageReader::imageFormat(iconResource));
- size = iconImage.size();
-
- if (destinationUrl == QUrl("_autogenerated_file_no_scheme_url_"))
- destinationUrl = QUrl::fromLocalFile(destinationFile.fileName());
- else
- destinationUrl = QUrl::fromLocalFile(destinationFile.fileName());
- } else if (destinationUrl == QUrl("_data_url_")) {
- QFile iconFile(iconResource);
- iconFile.open(QIODevice::ReadOnly);
-
- QString mimeType;
- if (QImageReader::imageFormat(iconResource) == "png")
- mimeType = QLatin1String("image/png");
-
- QImage iconImage(iconResource);
- size = iconImage.size();
-
- destinationUrl = QUrl(QString::fromLatin1("data:") + mimeType + QLatin1String(";base64,") + iconFile.readAll().toBase64());
- }
-
- iconParams.insert(destination, destinationUrl);
-
- if (!specifiedSize.isEmpty())
- iconParams.insert(destinationSize, specifiedSize);
-
- QPlace place;
- place.setName("Place");
- QPlaceIcon icon;
- icon.setParameters(iconParams);
- place.setIcon(icon);
- QString placeId;
-
- QPlaceCategory category;
- category.setName("Cat");
- category.setIcon(icon);
- QString categoryId;
-
- if (specifiedSize.isEmpty() && iconResource.isEmpty()) {
- QVERIFY(doSavePlace(place, QPlaceReply::BadArgumentError));
- QVERIFY(doSaveCategory(category, QPlaceReply::BadArgumentError));
- return;
- } else {
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
- }
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QPlaceCategory retrievedCategory;
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
-
-
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), destinationUrl);
- QCOMPARE(retrievedCategory.icon().parameters().value(destination).toUrl(), destinationUrl);
-
- if (!specifiedSize.isEmpty() && iconResource.isEmpty()) {
- QCOMPARE(retrievedPlace.icon().parameters().value(destinationSize).toSize(), specifiedSize);
- QCOMPARE(retrievedCategory.icon().parameters().value(destinationSize).toSize(), specifiedSize);
- } else {
- QCOMPARE(retrievedPlace.icon().parameters().value(destinationSize).toSize(), size);
- QCOMPARE(retrievedCategory.icon().parameters().value(destinationSize).toSize(), size);
- }
-}
-
-void tst_QPlaceManagerJsonDb::iconDestinationOnly_data()
-{
- QTest::addColumn<QString>("destination");
- QTest::addColumn<QUrl>("destinationUrl");
- QTest::addColumn<QSize>("specifiedSize");
- QTest::addColumn<QString>("iconResource");
-
- //destination url is local file, no size is specified
- QTest::newRow("destination small file no_size_provided") << SmallDestination << QUrl("_autogenerated_file_") << QSize() << ":/resources/icon_small.png";
- QTest::newRow("destination medium file no_size_provided") << MediumDestination << QUrl("_autogenerated_file_") << QSize() << ":/resources/icon_medium.png";
- QTest::newRow("destination large file no_size_provided") << LargeDestination << QUrl("_autogenerated_file_") << QSize() << ":/resources/icon_large.png";
- QTest::newRow("destination fullscreen file no_size_provided") << FullscreenDestination << QUrl("_autogenerated_file_") << QSize() << ":/resources/icon_fullscreen.png";
-
- //destination url is local file, no size is specified, the url has no scheme
- QTest::newRow("destination small file no_size_provided") << SmallDestination << QUrl("_autogenerated_file_no_scheme_url_") << QSize() << ":/resources/icon_small.png";
- QTest::newRow("destination medium file no_size_provided") << MediumDestination << QUrl("_autogenerated_file_no_scheme_url_") << QSize() << ":/resources/icon_medium.png";
- QTest::newRow("destination large file no_size_provided") << LargeDestination << QUrl("_autogenerated_file_no_scheme_url_") << QSize() << ":/resources/icon_large.png";
- QTest::newRow("destination fullscreen file no_size_provided") << FullscreenDestination << QUrl("_autogenerated_file_no_scheme_url_") << QSize() << ":/resources/icon_fullscreen.png";
-
- //destination url is local file and an (inaccurate) size is specified, (the actual size of file should take precedence)
- QTest::newRow("destination small file size_provided") << SmallDestination << QUrl("_autogenerated_file_") << QSize(86,99) << ":/resources/icon_small.png";
- QTest::newRow("destination medium file size_provided") << MediumDestination << QUrl("_autogenerated_file_") << QSize(86, 99) << ":/resources/icon_medium.png";
- QTest::newRow("destination large file size_provided") << LargeDestination << QUrl("_autogenerated_file_") << QSize(86, 99) << ":/resources/icon_large.png";
- QTest::newRow("destination fulscreen file size_provided") << FullscreenDestination << QUrl("_autogenerated_file_") << QSize(86, 99) << ":/resources/icon_fullscreen.png";
-
- //destination url is a data url, no size is specified
- QTest::newRow("destination small dataurl no_size_provided") << SmallDestination << QUrl("_data_url_") << QSize() << ":/resources/icon_small.png";
- QTest::newRow("destination medium dataurl no_size_provided") << MediumDestination << QUrl("_data_url_") << QSize() << ":/resources/icon_medium.png";
- QTest::newRow("destination large dataurl no_size_provided") << LargeDestination << QUrl("_data_url_") << QSize() << ":/resources/icon_large.png";
- QTest::newRow("destination fullscreen dataurl no_size_provided") << FullscreenDestination << QUrl("_data_url_") << QSize() << ":/resources/icon_fullscreen.png";
-
- //destination url is a data url, and an (inaccurate) size is specified, (the actual size of the icon should take precedence)
- QTest::newRow("destination small dataurl size_provided") << SmallDestination << QUrl("_data_url_") << QSize(86,99) << ":/resources/icon_small.png";
- QTest::newRow("destination medium dataurl size_provided") << MediumDestination << QUrl("_data_url_") << QSize(86, 99) << ":/resources/icon_medium.png";
- QTest::newRow("destination large dataurl size_provided") << LargeDestination << QUrl("_data_url_") << QSize(86, 99) << ":/resources/icon_large.png";
- QTest::newRow("destination fullscreen dataurl size_provided") << FullscreenDestination << QUrl("_data_url_") << QSize(86, 99) << ":/resources/icon_fullscreen.png";
-
- //destination url is unaccessible, and size is specified
- QTest::newRow("destination small unaccessible_webUrl size_provided") << SmallDestination << QUrl("http://www.non-existetent-example.com/iconS.png") << SmallSize << "";
- QTest::newRow("destination medium unaccessible_webUrl size_provided") << MediumDestination << QUrl("http://www.non-existetent-example.com/iconM.png") << MediumSize << "" ;
- QTest::newRow("destination large unaccessible_webUrl size_provided") << LargeDestination << QUrl("http://www.non-existetent-example.com/iconL.png") << LargeSize << "";
- QTest::newRow("destination fullscreen unaccessible_webUrl size_provided") << FullscreenDestination << QUrl("http://www.non-existetent-example.com/iconF.png") << FullscreenSize << "";
-
- //destination url is unaccessible and no size is provided, expect failure to save
- QTest::newRow("destination small unaccessible_webUrl no_size_provided") << SmallDestination << QUrl("http://www.non-existetent-example.com/iconS.png") << QSize() << "";
- QTest::newRow("destination medium unaccessible_webUrl no_size_provided") << MediumDestination << QUrl("http://www.non-existetent-example.com/iconM.png") << QSize() << "" ;
- QTest::newRow("destination large unaccessible_webUrl no_size_provided") << LargeDestination << QUrl("http://www.non-existetent-example.com/iconL.png") << QSize() << "";
- QTest::newRow("destination fullscreen unaccessible_webUrl no_size_provided") << FullscreenDestination << QUrl("http://www.non-existetent-example.com/iconL.png") << QSize() << "";
-}
-
-void tst_QPlaceManagerJsonDb::iconSavedFromDifferentManager()
-{
- QGeoServiceProvider geoTest("qmlgeo.test.plugin");
- geoTest.setAllowExperimental(true);
- QPlaceManager *geoTestManager = geoTest.placeManager();
-
- QPlaceIcon icon;
- icon.setManager(geoTestManager);
- QVariantMap iconParams;
-
- QTemporaryFile sourceIconFile;
- QImage sourceIconImage(":/resources/icon_small.png");
- sourceIconFile.open();
- sourceIconImage.save(sourceIconFile.fileName(), "png");
-
- //try an icon from another manager which different icons for each size variant
- //check that we get correctly generated data urls
- iconParams.insert("s", QUrl::fromLocalFile(":/resources/icon_small.png"));
- iconParams.insert("m", QUrl::fromLocalFile(":/resources/icon_medium.png"));
- iconParams.insert("l", QUrl::fromLocalFile(":/resources/icon_large.png"));
- iconParams.insert("f", QUrl::fromLocalFile(":/resources/icon_fullscreen.png"));
- icon.setParameters(iconParams);
-
- QPlace place;
- place.setName("Place");
- place.setIcon(icon);
-
- QPlace compatiblePlace = placeManager->compatiblePlace(place);
- QString placeId;
- QVERIFY(doSavePlace(compatiblePlace,QPlaceReply::NoError, &placeId));
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestinationSize));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(MediumDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(MediumDestinationSize));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(LargeDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(LargeDestinationSize));
-
- //we don't expect fullscreen icon urls to be download into data urls
- //data urls are only meant for small icons
- QVERIFY(!retrievedPlace.icon().parameters().keys().contains(FullscreenDestination));
-
- QImage smallImage = dataUrlToImage(retrievedPlace.icon().parameters().value(SmallDestination).toUrl());
- QImage mediumImage = dataUrlToImage(retrievedPlace.icon().parameters().value(MediumDestination).toUrl());
- QImage largeImage = dataUrlToImage(retrievedPlace.icon().parameters().value(LargeDestination).toUrl());
-
- QCOMPARE(smallImage.size(), SmallSize);
- QCOMPARE(mediumImage.size(), MediumSize);
- QCOMPARE(largeImage.size(), LargeSize);
-
- QCOMPARE(retrievedPlace.icon().parameters().value(SmallDestinationSize).toSize(), SmallSize);
- QCOMPARE(retrievedPlace.icon().parameters().value(MediumDestinationSize).toSize(), MediumSize);
- QCOMPARE(retrievedPlace.icon().parameters().value(LargeDestinationSize).toSize(), LargeSize);
-
- //try an icon from another manaager which has only a single size variant
- //check that we get only one size variant
- iconParams.clear();
- iconParams.insert("s", QUrl::fromLocalFile(":/resources/icon_small.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- compatiblePlace = placeManager->compatiblePlace(place);
- QVERIFY(doSavePlace(compatiblePlace,QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QCOMPARE(retrievedPlace.icon().parameters().keys().count(), 2);
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestinationSize));
- smallImage = dataUrlToImage(retrievedPlace.icon().parameters().value(SmallDestination).toUrl());
- QCOMPARE(smallImage.size(), SmallSize);
- QSize size = retrievedPlace.icon().parameters().value(SmallDestinationSize).toSize();
- QCOMPARE(size, SmallSize);
-
- //try an icon from a manager which has sizes which don't exactly match the standard expected icons
- //sizes, check that dataUrls are generated for the appropriate size variant
- iconParams.clear();
- iconParams.insert("m", QUrl::fromLocalFile(":/resources/icon_24x24.png"));
- iconParams.insert("l", QUrl::fromLocalFile(":/resources/icon_40x40.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- compatiblePlace = placeManager->compatiblePlace(place);
- QVERIFY(doSavePlace(compatiblePlace,QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().parameters().keys().count(), 4);
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(SmallDestinationSize));
- smallImage = dataUrlToImage(retrievedPlace.icon().parameters().value(SmallDestination).toUrl());
- QCOMPARE(smallImage.size(), QSize(24,24));
- size = retrievedPlace.icon().parameters().value(SmallDestinationSize).toSize();
- QCOMPARE(size, QSize(24,24));
-
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(LargeDestination));
- QVERIFY(retrievedPlace.icon().parameters().keys().contains(LargeDestinationSize));
- smallImage = dataUrlToImage(retrievedPlace.icon().parameters().value(LargeDestination).toUrl());
- QCOMPARE(smallImage.size(), QSize(40,40));
- size = retrievedPlace.icon().parameters().value(LargeDestinationSize).toSize();
- QCOMPARE(size, QSize(40,40));
-}
-
-void tst_QPlaceManagerJsonDb::iconFormats()
-{
- QFETCH(QByteArray, imageFormat);
- QFETCH(QString, mimeType);
-
- if (imageFormat == "svg")
- QSKIP("There is currently a crash issue with QImage and svg, see QTBUG-24468, so skip for now");
-
- if (imageFormat == "tiff")
- QSKIP("This test currently fails, investigate");
-
- QTemporaryFile sourceIconFile;
- sourceIconFile.open();
- QImage sourceIconImage;
-
- if (imageFormat == "svg") {
- QFile file(":/resources/icon_small.svg");
- file.open(QIODevice::ReadOnly);
- sourceIconFile.write(file.readAll());
- sourceIconFile.close();
- } else {
- QVERIFY(sourceIconImage.load(":/resources/icon_small.png"));
- QVERIFY(sourceIconImage.save(&sourceIconFile, imageFormat));
- }
-
- QVariantMap iconParams;
- iconParams.insert(SmallSource, QUrl::fromLocalFile(sourceIconFile.fileName()));
-
- QPlace place;
- place.setName("place");
-
- QPlaceCategory category;
- category.setName("category");
-
- QPlaceIcon icon;
- icon.setParameters(iconParams);
-
- place.setIcon(icon);
- category.setIcon(icon);
-
-
- QString placeId;
- QString categoryId;
-
- if (imageFormat == "svg" && !QImageReader::supportedImageFormats().contains("svg")) {
- //svg format is not supported therefore saving of the icon should fail
- //in this instance we are creating a data url and therefore need to be
- //able to detect the image format and mime type.
- QVERIFY(doSavePlace(place,QPlaceReply::BadArgumentError));
- QVERIFY(doSaveCategory(category,QPlaceReply::BadArgumentError));
- } else {
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QPlaceCategory retrievedCategory;
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
-
- QRegExp regExp("^data:(.*);.*$");
- regExp.indexIn(retrievedPlace.icon().parameters().value(SmallDestination).toUrl().toString());
- QCOMPARE(regExp.cap(1), mimeType);
- QCOMPARE(dataUrlToImage(retrievedPlace.icon().parameters().value(SmallDestination).toUrl()).size(), SmallSize);
- }
-}
-
-void tst_QPlaceManagerJsonDb::iconFormats_data()
-{
- QTest::addColumn<QByteArray>("imageFormat");
- QTest::addColumn<QString>("mimeType");
-
- QTest::newRow("bmp") << QByteArray("bmp") << "image/bmp";
- QTest::newRow("jpg") << QByteArray("jpg") << "image/jpeg";
- QTest::newRow("jpeg") << QByteArray("jpeg") << "image/jpeg";
- QTest::newRow("png") << QByteArray("png") << "image/png";
- QTest::newRow("pbm") << QByteArray("pbm") << "image/x-portable-bitmap";
- QTest::newRow("pgm") << QByteArray("pgm") << "image/x-portable-graymap";
- QTest::newRow("ppm") << QByteArray("ppm") << "image/x-portable-pixmap";
- QTest::newRow("tiff") << QByteArray("tiff") << "image/tiff";
- QTest::newRow("xbm") << QByteArray("xbm") << "image/x-xbitmap";
- QTest::newRow("xpm") << QByteArray("xpm") << "image/x-xpixmap";
- QTest::newRow("svg") << QByteArray("svg") << "image/svg+xml";
-}
-
-void tst_QPlaceManagerJsonDb::iconUrls()
-{
- QFETCH(QString, sizeType);
- QFETCH(QSize, size);
-
- QString source = sizeType + QLatin1String("SourceUrl");
- QString destination = sizeType + QLatin1String("Url");
- QString destinationSize = sizeType + QLatin1String("Size");
-
- QPlace place;
- place.setName("place");
-
- QPlaceCategory category;
- category.setName("category");
-
- QPlaceIcon icon;
- QVariantMap iconParams;
-
- //test conversion to valid url, in this care using a valid file scheme
- iconParams.insert(destination, QUrl("/home/user/icon.png"));
- iconParams.insert(destinationSize, size);
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
-
- QString placeId;
- QString categoryId;
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
-
- QPlace retrievedPlace;
- QPlaceCategory retrievedCategory;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), QUrl("file:///home/user/icon.png"));
-
- //test conversion to valid url,
- iconParams.insert(destination, QUrl("qrc:/home/user/icon.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), QUrl("qrc:///home/user/icon.png"));
-
- iconParams.insert(destination, QUrl("qrc:///home/user/icon.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
-
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), QUrl("qrc:///home/user/icon.png"));
-
- //test urls that are non-encoded and encoded
- iconParams.insert(destination, QUrl("qrc:///home/user/i con.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), QUrl("qrc:///home/user/i con.png"));
-
- iconParams.insert(destination, QUrl("qrc:///home/user/ico%20n.png"));
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
- QVERIFY(doSavePlace(place,QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::NoError, &categoryId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon(), retrievedCategory.icon());
- QCOMPARE(retrievedPlace.icon().parameters().value(destination).toUrl(), QUrl("qrc:///home/user/ico n.png"));
-
- //try using a QString instead of a url in the parameters
- iconParams.insert(destination, "www.example.com");
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
- QVERIFY(doSavePlace(place,QPlaceReply::BadArgumentError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::BadArgumentError, &categoryId));
-
- //try using a QString instead of a url in the parameters
- iconParams.insert(source, "www.example.com");
- icon.setParameters(iconParams);
- place.setIcon(icon);
- category.setIcon(icon);
- QVERIFY(doSavePlace(place,QPlaceReply::BadArgumentError, &placeId));
- QVERIFY(doSaveCategory(category,QPlaceReply::BadArgumentError, &categoryId));
-}
-
-void tst_QPlaceManagerJsonDb::iconUrls_data()
-{
- QTest::addColumn<QString>("sizeType");
- QTest::addColumn<QSize>("size");
-
- QTest::newRow("small") << "small" << SmallSize;
- QTest::newRow("medium") << "medium" << MediumSize;
- QTest::newRow("large") << "large" << LargeSize;
- QTest::newRow("fullscreen") << "fullscreen" << FullscreenSize;
-}
-
-#ifdef REMOTE_TEST
-void tst_QPlaceManagerJsonDb::iconDownload()
-{
- QFETCH(QString, sizeType);
- QFETCH(QString, destinationType);
- QFETCH(QString, errorCondition);
-
- QPlace place;
- place.setName("place");
- QGeoCoordinate coord(10,10);
- QGeoLocation location;
- location.setCoordinate((coord));
- place.setLocation(location);
-
- QPlaceCategory category;
- category.setName("category");
-
- QPlaceIcon icon;
- QVariantMap parameters;
-
- QString source = sizeType + QLatin1String("SourceUrl");
- if (errorCondition == "no error")
- parameters.insert(source, QUrl("http://download.ch1.qa.vcdn.nokia.com/p/d/places2/icons/categories/01.icon"));
- else if (errorCondition == "unreachable host")
- parameters.insert(source, QUrl("http://doesnotexist_aef32.com/01.icon"));
- else
- QFAIL("Unknown error condition");
-
- QTemporaryDir tempDir;
- if (destinationType.startsWith(QLatin1String("file"))) {
- QVERIFY(tempDir.isValid());
- QString destIconFileName = tempDir.path() + QLatin1String("/tempFile");
-
- if (destinationType == QLatin1String("file existing")) {
- QFile destFile(destIconFileName);
- destFile.open(QIODevice::ReadWrite);
- destFile.close();
- }
- parameters.insert(sizeType + QLatin1String("Url"), QUrl::fromLocalFile(destIconFileName));
- }
-
- icon.setParameters(parameters);
- place.setIcon(icon);
- category.setIcon(icon);
-
- QString placeId;
- QString categoryId;
-
- if (errorCondition == "no error") {
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QVERIFY(doSaveCategory(category, QPlaceReply::NoError, &categoryId));
-
- QPlace retrievedPlace;
- QPlaceCategory retrievedCategory;
-
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(doFetchCategory(categoryId, &retrievedCategory));
- QCOMPARE(retrievedPlace.icon().url(), retrievedCategory.icon().url());
-
- QImage image;
- if (destinationType == "dataUrl")
- image = dataUrlToImage(retrievedPlace.icon().url());
- else if (destinationType.startsWith("file"))
- image = QImage(retrievedPlace.icon().url().toLocalFile());
-
- QCOMPARE(image.size(), QSize(60, 65));
- } else if (errorCondition == "unreachable host") {
- QVERIFY(doSavePlace(place, QPlaceReply::CommunicationError));
- QVERIFY(doSaveCategory(category, QPlaceReply::CommunicationError));
- }
-
- //Hardening Extension: Potentially there could be more thorough tests here to handle
- //different icon sizes coming from the server
-}
-
-void tst_QPlaceManagerJsonDb::iconDownload_data()
-{
- QTest::addColumn<QString>("sizeType");
- QTest::addColumn<QString>("destinationType");
- QTest::addColumn<QString>("errorCondition");
-
- QStringList sizeTypes;
- sizeTypes << JsonDbUtils::Small << JsonDbUtils::Medium << JsonDbUtils::Large;
-
- QStringList destinationTypes;
- destinationTypes << QLatin1String("dataUrl") << QLatin1String("file new") << QLatin1String("file existing");
-
- QStringList errorConditions;
- errorConditions << QLatin1String("no error") << QLatin1String("unreachable host");
-
- foreach (const QString &sizeType, sizeTypes) {
- foreach (const QString &destinationType, destinationTypes) {
- foreach (const QString &errorCondition, errorConditions) {
- QByteArray dataTag = (sizeType + QLatin1String(" ") + destinationType + QLatin1String(" ") + errorCondition).toLatin1();
- QTest::newRow(dataTag.constData()) << sizeType << destinationType << errorCondition;
- }
- }
- }
-}
-#endif
-
-void tst_QPlaceManagerJsonDb::constructIconUrl()
-{
- QPlaceIcon icon;
- QVariantMap iconParams;
-
- //try with all possible size buckets set
- iconParams.insert(SmallDestination, QUrl("http://www.example.com/icon_small.png"));
- iconParams.insert(SmallDestinationSize, SmallSize);
- iconParams.insert(MediumDestination, QUrl("http://www.example.com/icon_medium.png"));
- iconParams.insert(MediumDestinationSize, MediumSize);
- iconParams.insert(LargeDestination, QUrl("http://www.example.com/icon_large.png"));
- iconParams.insert(LargeDestinationSize, LargeSize);
- iconParams.insert(FullscreenDestination, QUrl("http://www.example.com/icon_fullscreen.png"));
- iconParams.insert(FullscreenDestinationSize, FullscreenSize);
-
- icon.setParameters(iconParams);
- icon.setManager(placeManager);
-
- QCOMPARE(icon.url(SmallSize), QUrl("http://www.example.com/icon_small.png"));
- QCOMPARE(icon.url(MediumSize), QUrl("http://www.example.com/icon_medium.png"));
- QCOMPARE(icon.url(LargeSize), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(FullscreenSize), QUrl("http://www.example.com/icon_fullscreen.png"));
-
- //try with only a single destination icon set
- iconParams.clear();
- iconParams.insert(LargeDestination, QUrl("http://www.example.com/icon_large.png"));
- iconParams.insert(LargeDestinationSize, LargeSize);
- icon.setParameters(iconParams);
-
- QCOMPARE(icon.url(SmallSize), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(MediumSize), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(LargeSize), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(FullscreenSize), QUrl("http://www.example.com/icon_large.png"));
-
- //try requesting non-standard sizes and don't populate all size buckets
- iconParams.clear();
- iconParams.insert(SmallDestination, QUrl("http://www.example.com/icon_small.png"));
- iconParams.insert(SmallDestinationSize, SmallSize);
- iconParams.insert(LargeDestination, QUrl("http://www.example.com/icon_large.png"));
- iconParams.insert(LargeDestinationSize, LargeSize);
- icon.setParameters(iconParams);
-
- QCOMPARE(icon.url(QSize(10,10)), QUrl("http://www.example.com/icon_small.png"));
- QCOMPARE(icon.url(QSize(34,34)), QUrl("http://www.example.com/icon_small.png"));
- QCOMPARE(icon.url(QSize(35,35)), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(QSize(60,60)), QUrl("http://www.example.com/icon_large.png"));
-
- //try the icons themselves haveing non standard sizes
- iconParams.clear();
- iconParams.insert(SmallDestination, QUrl("http://www.example.com/icon_small.png"));
- iconParams.insert(SmallDestinationSize, QSize(25,25));
- iconParams.insert(LargeDestination, QUrl("http://www.example.com/icon_large.png"));
- iconParams.insert(LargeDestinationSize, QSize(35,35));
- icon.setParameters(iconParams);
-
- QCOMPARE(icon.url(QSize(24,24)), QUrl("http://www.example.com/icon_small.png"));
- QCOMPARE(icon.url(QSize(29,29)), QUrl("http://www.example.com/icon_small.png"));
- QCOMPARE(icon.url(QSize(30,30)), QUrl("http://www.example.com/icon_large.png"));
- QCOMPARE(icon.url(QSize(60,60)), QUrl("http://www.example.com/icon_large.png"));
-
- //TODO: edge case testing for all combinations
-}
-
-void tst_QPlaceManagerJsonDb::providerIcons()
-{
- QGeoServiceProvider *oldProvider = provider;
- QPlaceManager *oldManager = placeManager;
-
- QVariantMap providerParams;
- providerParams.insert(CustomIcons, false);
- providerParams.insert(QLatin1String("places.local_data_path"), tempDir.path());
-
- provider = new QGeoServiceProvider(QLatin1String("places_jsondb"), providerParams);
- placeManager = provider->placeManager();
-
- QPlaceReply * catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QMap<QString,QVariant> credentials;
- credentials.insert("app_id", "stub");
- credentials.insert("token", "stub");
- QGeoServiceProvider *nokiaProvider = new QGeoServiceProvider(QLatin1String("nokia"), credentials);
- QPlaceManager *nokiaManager = nokiaProvider->placeManager();
- Q_ASSERT(nokiaManager);
-
- QPlaceIcon icon;
- QVariantMap params;
- QPlaceCategory accommodation;
- accommodation.setCategoryId("accommodation");
- params.insert(Nokiaicon, QLatin1String("/icons/categories/01.icon"));
- params.insert(IconPrefix, QLatin1String("www.server.com/foo"));
- icon.setParameters(params);
- icon.setManager(nokiaManager);
- accommodation.setIcon(icon);
-
- QPlaceCategory businessIndustry;
- businessIndustry.setCategoryId("business-industry");
- params.insert(Nokiaicon, QLatin1String("/icons/categories/02.icon"));
- params.insert(IconPrefix, QLatin1String("www.server.com/foo"));
- icon.setParameters(params);
- icon.setManager(nokiaManager);
- businessIndustry.setIcon(icon);
-
- //Check the compatible place for an icon that was generated from its categories
- QPlace place;
- place.setName(QStringLiteral("Gotham City"));
- QGeoCoordinate coord(31.516, 74.316);
- QGeoLocation location;
- location.setCoordinate(coord);
- place.setLocation(location);
- place.setCategory(accommodation);
-
- QPlaceAttribute providerAttr;
- providerAttr.setText("nokia");
- place.setExtendedAttribute(Provider, providerAttr);
-
- params.clear();
- params.insert(Nokiaicon, QLatin1String("/icons/categories/01.icon"));
- params.insert(IconPrefix, QLatin1String("www.server.com/foo"));
- params.insert(NokiaIconGenerated, true);
- icon.setParameters(params);
-
- place.setIcon(icon);
-
- QPlace compatiblePlace = placeManager->compatiblePlace(place);
- QVariantMap compatParams = compatiblePlace.icon().parameters();
- QCOMPARE(compatParams.value(Nokiaicon).toString(),
- QLatin1String("/icons/categories/01.icon"));
-
- QCOMPARE(compatParams.value(NokiaIconGenerated).toBool(), true);
-
- QString placeId;
- QVERIFY(doSavePlace(compatiblePlace, QPlaceReply::NoError, &placeId));
- compatiblePlace.setPlaceId(placeId);
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QCOMPARE(retrievedPlace.icon().url(),
- QUrl(QString::fromLatin1("file://")
- + tempDir.path() + QLatin1String("/icons/categories/01.icon")));
- QCOMPARE(retrievedPlace.icon().parameters().value(NokiaIconGenerated).toBool(), true);
-
- //Try explicitly setting an icon that is not generated.
- place.setIcon(businessIndustry.icon());
- compatiblePlace = placeManager->compatiblePlace(place);
- compatParams = compatiblePlace.icon().parameters();
- QCOMPARE(compatParams.value(Nokiaicon).toString(),
- QLatin1String("/icons/categories/02.icon"));
-
- QVERIFY(doSavePlace(compatiblePlace, QPlaceReply::NoError, &placeId));
-
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().url(),
- QUrl(QString::fromLatin1("file://")
- + tempDir.path() + QLatin1String("/icons/categories/02.icon")));
- QCOMPARE(retrievedPlace.icon().parameters().value(Nokiaicon).toString(),
- QLatin1String("/icons/categories/02.icon"));
- QVERIFY(!retrievedPlace.icon().parameters().contains(NokiaIconGenerated));
-
-
- QStringList sizes;
- sizes << QLatin1String("small") << QLatin1String("medium")
- << QLatin1String("large");
- foreach (const QString &size, sizes) {
- //save an icon with a custom field populated
- //ensure a generated provider icon is returned.
- params.clear();
- params.insert(size + QLatin1String("Url"), QUrl("file:///opt/icon.png"));
- params.insert(size + QLatin1String("Size"), QSize(40,40));
- icon.setParameters(params);
- icon.setManager(placeManager);
- compatiblePlace.setIcon(icon);
- QVERIFY(doSavePlace(compatiblePlace, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().url(),
- QUrl(QString::fromLatin1("file://")
- + tempDir.path() + QLatin1String("/icons/categories/01.icon")));
- QCOMPARE(retrievedPlace.icon().parameters().value(NokiaIconGenerated).toBool(), true);
-
- //verify that retriving the same place via a plugin configured to return custom
- //icons will return the custom icon
- QVERIFY(doFetchDetails(oldManager, placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().url(), QUrl("file:///opt/icon.png"));
- QCOMPARE(retrievedPlace.icon().parameters()
- .value(size + QLatin1String("Url")).toUrl(),
- QUrl("file:///opt/icon.png"));
-
- //save an icon with a custom icon populated and a provider icon explicitly populated
- //ensure the explicitly set provider icon is returned.
- params.clear();
- params.insert(size + QLatin1String("Url"), QUrl("file:///opt/icon.png"));
- params.insert(size + QLatin1String("Size"), QSize(40,40));
- params.insert(Nokiaicon, QLatin1String("/icons/categories/02.icon"));
-
- icon.setParameters(params);
- icon.setManager(placeManager);
- compatiblePlace.setIcon(icon);
-
- QVERIFY(doSavePlace(compatiblePlace, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().url(),
- QUrl(QString::fromLatin1("file://")
- + tempDir.path() + QLatin1String("/icons/categories/02.icon")));
- QCOMPARE(retrievedPlace.icon().parameters().value(NokiaIconGenerated).toBool(),
- false);
-
- //verify that retriving the same place via a plugin configured to return custom
- //icons will return the custom icon
- QVERIFY(doFetchDetails(oldManager, placeId, &retrievedPlace));
- QCOMPARE(retrievedPlace.icon().url(), QUrl("file:///opt/icon.png"));
- QCOMPARE(retrievedPlace.icon().parameters()
- .value(size + QLatin1String("Url")).toUrl(),
- QUrl("file:///opt/icon.png"));
- }
-
- //try saving a place with no icon set and no provider category information either
- //we expect that a default icon is returned
- place.setIcon(QPlaceIcon());
- place.setCategories(QList<QPlaceCategory>());
- compatiblePlace = placeManager->compatiblePlace(place);
- QVERIFY(compatiblePlace.icon().isEmpty());
- QVERIFY(!compatiblePlace.extendedAttributeTypes()
- .contains(QLatin1String("x_nokia_category_ids")));
-
- QVERIFY(doSavePlace(compatiblePlace, QPlaceReply::NoError, &placeId));
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
-
- QCOMPARE(retrievedPlace.icon().url(),
- QUrl(QString::fromLatin1("file://")
- + tempDir.path() + QLatin1String("/icons/categories/06.icon")));
- QCOMPARE(retrievedPlace.icon().parameters().value(NokiaIconGenerated).toBool(),
- true);
-
- //restore old state
- delete provider;
-
- provider = oldProvider;
- placeManager = oldManager;
-}
-
-void tst_QPlaceManagerJsonDb::specifiedPartition()
-{
- QSKIP("The behavior for creating partitions has changed, test needs to be updated");
-
- const QLatin1String ArbitraryPartition("com.nokia.arbitraryPartition");
- dbUtils->setupPartition(ArbitraryPartition);
- dbUtils->setCurrentPartition(ArbitraryPartition);
- QSignalSpy spy(dbUtils, SIGNAL(partitionSetupDone()));
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() ==1, 10000);
-
- QGeoServiceProvider *oldProvider = provider;
- QPlaceManager *oldManager = placeManager;
-
- QVariantMap parameters;
- parameters.insert(QLatin1String("partition"), ArbitraryPartition);
- provider = new QGeoServiceProvider(QLatin1String("places_jsondb"), parameters);
- placeManager = provider->placeManager();
-
- QSignalSpy createPlaceSpy(placeManager, SIGNAL(placeAdded(QString)));
- QSignalSpy updatePlaceSpy(placeManager, SIGNAL(placeUpdated(QString)));
- QSignalSpy removePlaceSpy(placeManager, SIGNAL(placeRemoved(QString)));
-
- QSignalSpy createCategorySpy(placeManager, SIGNAL(categoryAdded(QPlaceCategory,QString)));
- QSignalSpy updateCategorySpy(placeManager, SIGNAL(categoryUpdated(QPlaceCategory,QString)));
- QSignalSpy removeCategorySpy(placeManager, SIGNAL(categoryRemoved(QString,QString)));
-
- //Test saving, updating and removing a place
- QPlace place;
- place.setName(QLatin1String("Place"));
- QGeoLocation location;
- location.setCoordinate(QGeoCoordinate(10,20));
-
- QString placeId;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QCOMPARE(createPlaceSpy.count(), 1);
- place.setPlaceId(placeId);
- place.setVisibility(QLocation::DeviceVisibility);
-
- QPlace retrievedPlace;
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace == place);
-
- place.setName(QLatin1String("place2"));
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId));
- QCOMPARE(updatePlaceSpy.count(), 1);
- QVERIFY(doFetchDetails(placeId, &retrievedPlace));
- QVERIFY(retrievedPlace == place);
-
- QVERIFY(doRemovePlace(place, QPlaceReply::NoError));
- QCOMPARE(removePlaceSpy.count(), 1);
-
- //test saving, updating and removing a category
- QString categoryId;
- QPlaceCategory restaurant;
- restaurant.setName(QLatin1String("Restaurant"));
-
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- QCOMPARE(createCategorySpy.count(), 1);
- restaurant.setCategoryId(categoryId);
- QPlaceReply * catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- QList<QPlaceCategory> categories = placeManager->childCategories();
- QCOMPARE(categories.count(), 1);
-
- restaurant.setName(QLatin1String("Restaurant2"));
- QVERIFY(doSaveCategory(restaurant, QPlaceReply::NoError, &categoryId));
- QCOMPARE(updateCategorySpy.count(), 1);
- catInitReply = placeManager->initializeCategories();
- QVERIFY(checkSignals(catInitReply, QPlaceReply::NoError));
-
- categories = placeManager->childCategories();
- QCOMPARE(categories.count(), 1);
-
- QVERIFY(doRemoveCategory(restaurant));
- QCOMPARE(removeCategorySpy.count(), 1);
-
- QSignalSpy cleanSpy(dbUtils, SIGNAL(dbCleaned()));
- dbUtils->cleanDb();
- QTRY_VERIFY(cleanSpy.count() == 1);
-
- //restore old state
- delete provider;
-
- provider = oldProvider;
- placeManager = oldManager;
- dbUtils->setCurrentPartition(JsonDbUtils::DefaultPartition);
-}
-
-void tst_QPlaceManagerJsonDb::validateIndexes()
-{
- QPlace place;
- place.setName(QLatin1String("Winterfell"));
- QGeoLocation location;
-
- location.setCoordinate(QGeoCoordinate(1,-30));
- place.setLocation(location);
-
- QString placeId1;
- QVERIFY(doSavePlace(place, QPlaceReply::NoError, &placeId1));
-
- QPlace place2;
- place2.setName(QLatin1String("Casterly Rock"));
- location.setCoordinate(QGeoCoordinate(11,-20));
- place2.setLocation(location);
-
- QString placeId2;
- QVERIFY(doSavePlace(place2, QPlaceReply::NoError, &placeId2));
-
- QPlace place3;
- place3.setName(QLatin1String("Qarth"));
- location.setCoordinate(QGeoCoordinate(5,5));
- place3.setLocation(location);
-
- QString placeId3;
- QVERIFY(doSavePlace(place3, QPlaceReply::NoError, &placeId3));
-
- QPlace place4;
- place4.setName(QLatin1String("Wall"));
- location.setCoordinate(QGeoCoordinate(7,20));
- place4.setLocation(location);
-
- QString placeId4;
- QVERIFY(doSavePlace(place4, QPlaceReply::NoError, &placeId4));
-
- //validate latitude index
- QJsonDbReadRequest *request = new QJsonDbReadRequest();
- request->setQuery(QStringLiteral("[?_type=%type][?placeLatitudeIndex < 10]"));
- request->bindValue(QStringLiteral("type"), JsonDbUtils::PlaceType);
- dbUtils->sendRequest(request);
-
- QSignalSpy readSpy(request, SIGNAL(finished()));
- WAIT_UNTIL(readSpy.count() == 1);
- readSpy.clear();
- QCOMPARE(request->takeResults().count(), 3);
- QCOMPARE(request->sortKey(), JsonDbUtils::LatitudeIndex);
-
- //validate longitude index
- request->setQuery(QStringLiteral("[?_type=%type][?placeLongitudeIndex < -25]"));
- request->bindValue(QStringLiteral("type"), JsonDbUtils::PlaceType);
- dbUtils->sendRequest(request);
-
- WAIT_UNTIL(readSpy.count() == 1);
- readSpy.clear();
- QCOMPARE(request->takeResults().count(), 1);
- QCOMPARE(request->sortKey(), JsonDbUtils::LongitudeIndex);
-
- //verify place display name index
- request->setQuery(QStringLiteral("[?_type=%type][/placeDisplayNameIndex]"));
- request->bindValue(QStringLiteral("type"), JsonDbUtils::PlaceType);
- dbUtils->sendRequest(request);
-
- WAIT_UNTIL(readSpy.count() == 1);
- QList<QJsonObject> results= request->takeResults();
- QCOMPARE(results.count(), 4);
- QCOMPARE(results.at(0).value(JsonDbUtils::Uuid).toString(), placeId2);
- QCOMPARE(results.at(1).value(JsonDbUtils::Uuid).toString(), placeId3);
- QCOMPARE(results.at(2).value(JsonDbUtils::Uuid).toString(), placeId4);
- QCOMPARE(results.at(3).value(JsonDbUtils::Uuid).toString(), placeId1);
-
- QCOMPARE(request->sortKey(), JsonDbUtils::PlaceNameIndex);
-}
-
-void tst_QPlaceManagerJsonDb::cleanup()
-{
- QSignalSpy cleanSpy(dbUtils, SIGNAL(dbCleaned()));
- dbUtils->cleanDb();
- QTRY_VERIFY_WITH_TIMEOUT(cleanSpy.count() == 1, Timeout);
-}
-
-QImage tst_QPlaceManagerJsonDb::dataUrlToImage(const QUrl &url)
-{
- QByteArray data = QByteArray::fromPercentEncoding(url.toEncoded());
- data.remove(0,5);
- int pos = data.indexOf(',');
- if (pos != -1) {
- QByteArray payload = QByteArray::fromBase64(data.mid(pos + 1));
- data.truncate(pos);
-
- if (!data.endsWith(";base64")) {
- qWarning() << "Data url payload not base64 encoded";
- return QImage();
- }
-
- return QImage::fromData(payload);
- }
-
- return QImage();
-}
-
-QTEST_APPLESS_MAIN(tst_QPlaceManagerJsonDb)
-
-#include "tst_qplacemanager_jsondb.moc"