summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-03-21 11:09:03 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-26 04:54:56 +0200
commitcd08bb26ffcee2c2d43938ef259447049dd1dc2b (patch)
tree45d586d1e96ee8ab3e3a2d845f6ca7d901058dba
parentb1feee0f4af650627616df225955f836cb18a19e (diff)
downloadqtlocation-cd08bb26ffcee2c2d43938ef259447049dd1dc2b.tar.gz
Have jsondb places plugin use the user partition
Also allow specification of partition via the parameters. Change-Id: I4d311ae6c4bff437e556185a95b8c1fffcb5948f Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
-rw-r--r--doc/src/examples/declarative-places.qdoc12
-rw-r--r--doc/src/plugins/jsondb.qdoc12
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/jsondb.cpp49
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/jsondb.h7
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp10
-rw-r--r--src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h3
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbutils.cpp144
-rw-r--r--tests/auto/qplacemanager_jsondb/jsondbutils.h12
-rw-r--r--tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp88
9 files changed, 249 insertions, 88 deletions
diff --git a/doc/src/examples/declarative-places.qdoc b/doc/src/examples/declarative-places.qdoc
index 388491dd..e7be8856 100644
--- a/doc/src/examples/declarative-places.qdoc
+++ b/doc/src/examples/declarative-places.qdoc
@@ -223,4 +223,16 @@
To remove a place, invoke its \l {Place::remove()}{remove()} method. To remove a category,
invoke its \l {Category::remove()}{remove()} method.
+
+ \section1 Running the example
+ The example detects which plugins are available and has an option to show them in the via
+ the Provider button.
+
+ The \l {Qt Location JsonDb plugin} {JsonDb plugin} in particular acts as a data store for
+ user defined favorites which can be saved and removed. In order to use the JsonDb plugin however
+ the JsonDb daemon must be running in the background.
+
+ \code
+ jsondb & //run jsondb daemon in the background
+ \endcode
*/
diff --git a/doc/src/plugins/jsondb.qdoc b/doc/src/plugins/jsondb.qdoc
index 837c7ff5..c424397e 100644
--- a/doc/src/plugins/jsondb.qdoc
+++ b/doc/src/plugins/jsondb.qdoc
@@ -44,6 +44,18 @@ The JsonDb GeoServices plugin can be loaded by using the plugin key "nokia_place
Note that in order to use this plugin, the JsonDb daemon must be running in the
background.
+\section1 Parameters
+
+The following table lists optional parameters that can be passed to the Nokia plugin.
+\table
+ \header
+ \li Parameter
+ \li Description
+ \row
+ \li places.partition
+ \li Specifies which JsonDb partition to store Places and Categories. If no partition is specified, the default
+ partition is used.
+\endtable
\section1 Places
The Nokia JsonDb provider accesses places stored locally on device.
diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/jsondb.cpp
index d8f5c5ea..0e41c2a4 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/jsondb.cpp
+++ b/src/plugins/geoservices/nokia_places_jsondb/jsondb.cpp
@@ -114,14 +114,16 @@ const QLatin1String JsonDb::DeviceVisibility("device");
const QLatin1String JsonDb::CreatedDateTime("createdDateTime");
const QLatin1String JsonDb::ModifiedDateTime("modifiedDateTime");
-JsonDb::JsonDb()
+JsonDb::JsonDb(const QString &partition)
: m_connection(new QJsonDbConnection),
m_placeWatcher(new QJsonDbWatcher(this)),
- m_categoryWatcher(new QJsonDbWatcher(this))
+ m_categoryWatcher(new QJsonDbWatcher(this)),
+ m_partition(partition)
{
m_connection->connectToServer();
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)),
@@ -129,6 +131,7 @@ JsonDb::JsonDb()
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)),
@@ -624,28 +627,16 @@ QPlaceIcon JsonDb::convertJsonObjectToIcon(const QJsonObject &thumbnailsJson, co
return icon;
}
-void JsonDb::makeConnections(QJsonDbRequest *request, QObject *parent, const char *slot)
+void JsonDb::setupRequest(QJsonDbRequest *request, QObject *parent, const char *slot)
{
- if (slot)
- QObject::connect(request, SIGNAL(finished()), parent, slot);
- else
- QObject::connect(request, SIGNAL(finished()), parent, SLOT(requestFinished()));//TODO: eventually remove this
+ 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()));
-}
-
-void JsonDb::getCategory(const QString &uuid, QObject *parent)
-{
- QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
- request->setQuery(QStringLiteral("[?_type=%type][?_uuid=%uuid]"));
- request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
- request->bindValue(QStringLiteral("uuid"), uuid);
-
- makeConnections(request, parent);
- m_connection->send(request);
+ request->setPartition(m_partition);
}
void JsonDb::getCategories(const QList<QPlaceCategory> &categories, QObject *parent, const char *slot)
@@ -664,7 +655,7 @@ void JsonDb::getCategories(const QStringList &uuids, QObject *parent, const char
request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
request->bindValue(QStringLiteral("categoryUuids"), QJsonArray::fromStringList(uuids));
- JsonDb::makeConnections(request, parent, slot);
+ JsonDb::setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -675,7 +666,7 @@ void JsonDb::getChildCategories(const QString &uuid, QObject *parent, const char
request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
request->bindValue(QStringLiteral("uuid"), uuid);
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -686,7 +677,7 @@ void JsonDb::getCategory(const QString &uuid, QObject *parent, const char *slot)
request->bindValue(QStringLiteral("type"), JsonDb::CategoryType);
request->bindValue(QStringLiteral("uuid"), uuid);
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -699,7 +690,7 @@ void JsonDb::getPlace(const QString &uuid, QObject *parent, const char *slot)
request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
request->bindValue(QStringLiteral("uuid"), uuid);
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -715,7 +706,7 @@ void JsonDb::findPlacesByAlternativeId(const QString externalIdName, const QStri
+ QString::fromLatin1("[?%1 in %alternativeIds]").arg(extIdPropertyName));
request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
request->bindValue(QStringLiteral("alternativeIds"), QJsonArray::fromStringList(alternativeIds));
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -724,7 +715,7 @@ void JsonDb::findAllPlaces(QObject *parent, const char *slot)
QJsonDbReadRequest *request = new QJsonDbReadRequest(this);
request->setQuery(QStringLiteral("[?_type= %type]"));
request->bindValue(QStringLiteral("type"), JsonDb::PlaceType);
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -732,7 +723,7 @@ void JsonDb::read(const QString &query, QObject *parent, const char *slot)
{
QJsonDbReadRequest *request = new QJsonDbReadRequest(parent);
request->setQuery(query);
- makeConnections(request, parent, slot);
+ setupRequest(request, parent, slot);
m_connection->send(request);
}
@@ -754,21 +745,21 @@ void JsonDb::write(const QList<QJsonObject> &jsonObjects, QObject *parent, const
QJsonDbWriteRequest *writeRequest = new QJsonDbWriteRequest(parent);
writeRequest->setObjects(objects);
- makeConnections(writeRequest, parent, slot);
+ 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::makeConnections(removeRequest, parent, slot);
+ 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::makeConnections(removeRequest, parent, slot);
+ JsonDb::setupRequest(removeRequest, parent, slot);
m_connection->send(removeRequest);
}
@@ -801,7 +792,7 @@ void JsonDb::searchForPlaces(const QPlaceSearchRequest &request, QObject *parent
QJsonDbReadRequest *jsonDbRequest = new QJsonDbReadRequest(parent);
jsonDbRequest->setQuery(queryString);
- makeConnections(jsonDbRequest, parent, slot);
+ setupRequest(jsonDbRequest, parent, slot);
m_connection->send(jsonDbRequest);
}
diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/jsondb.h
index c66365e4..57258ba5 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/jsondb.h
+++ b/src/plugins/geoservices/nokia_places_jsondb/jsondb.h
@@ -61,7 +61,7 @@ class QPlaceIcon;
class JsonDb : public QObject {
Q_OBJECT
public:
- JsonDb();
+ JsonDb(const QString &partition);
~JsonDb();
static QString convertToQueryString(const QPlaceSearchRequest &query);
@@ -74,9 +74,7 @@ public:
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);
- static void makeConnections(QJsonDbRequest *request, QObject *parent, const char *slot = 0);
- void getCategory(const QString &uuid, QObject *parent);
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);
@@ -92,6 +90,8 @@ public:
void remove(const QList<QJsonObject> &jsonObjects, QObject *parent, const char *slot);
void searchForPlaces(const QPlaceSearchRequest &request, QObject *parent, const char *slot);
+ void setupRequest(QJsonDbRequest *request, QObject *parent, const char *slot);
+
static QStringList categoryIds(QList<QPlace> places);
static const QLatin1String Uuid;
@@ -175,6 +175,7 @@ private:
QtJsonDb::QJsonDbConnection *m_connection;
QJsonDbWatcher *m_placeWatcher;
QJsonDbWatcher *m_categoryWatcher;
+ QString m_partition;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
index 61fd5f1a..ec57e1b7 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp
@@ -58,13 +58,21 @@ QT_USE_NAMESPACE
Q_DECLARE_METATYPE(QJsonObject);
+const QLatin1String QPlaceManagerEngineJsonDb::PartitionKey("places.partition");
+
QPlaceManagerEngineJsonDb::QPlaceManagerEngineJsonDb(const QMap<QString, QVariant> &parameters,
QGeoServiceProvider::Error *error,
QString *errorString)
- : QPlaceManagerEngine(parameters), m_jsonDb(new JsonDb()), m_netManager(0)
+ : 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>)),
diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
index 4bdfee4e..779c4767 100644
--- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
+++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h
@@ -122,9 +122,10 @@ private:
mutable QMutex m_treeMutex;
CategoryTree m_tree;
-
QNetworkAccessManager *m_netManager;
+ static const QLatin1String PartitionKey;
+
friend class SaveReply;
friend class MediaReply;
friend class RemoveReply;
diff --git a/tests/auto/qplacemanager_jsondb/jsondbutils.cpp b/tests/auto/qplacemanager_jsondb/jsondbutils.cpp
index 564793dd..31ab0c87 100644
--- a/tests/auto/qplacemanager_jsondb/jsondbutils.cpp
+++ b/tests/auto/qplacemanager_jsondb/jsondbutils.cpp
@@ -52,6 +52,22 @@
#include <QLocalSocket>
#include <QDir>
#include <QTest>
+#include <QSignalSpy>
+#include <QUuid>
+
+#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");
@@ -133,11 +149,8 @@ const QLatin1String JsonDbUtils::FullscreenIconSizeParam("fullscreenSize");
const QLatin1String JsonDbUtils::CreatedDateTime("createdDateTime");
const QLatin1String JsonDbUtils::ModifiedDateTime("modifiedDateTime");
-JsonDbUtils::~JsonDbUtils()
-{
- if (m_jsondbProcess)
- m_jsondbProcess->kill();
-}
+const QLatin1String JsonDbUtils::DefaultPartition("");
+const QLatin1String JsonDbUtils::PartitionType("Partition");
JsonDbUtils::JsonDbUtils(QObject *parent)
: QObject(parent)
@@ -147,18 +160,20 @@ JsonDbUtils::JsonDbUtils(QObject *parent)
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));
- connect(getPlacesRequest, SIGNAL(finished()), this, SLOT(getPlacesFinished()));
- connect(getPlacesRequest, SIGNAL(finished()), getPlacesRequest, SLOT(deleteLater()));
- connect(getPlacesRequest, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- connect(getPlacesRequest, SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- getPlacesRequest, SLOT(deleteLater()));
+ setupRequest(getPlacesRequest, this, SLOT(getPlacesFinished()));
m_connection->send(getPlacesRequest);
}
@@ -177,23 +192,76 @@ QList<QJsonObject> JsonDbUtils::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);
- makeConnections(request, this, SLOT(fetchPlaceJsonFinished()));
+ 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);
- makeConnections(request, this, SLOT(savePlaceJsonFinished()));
+ 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())
@@ -202,16 +270,7 @@ void JsonDbUtils::getPlacesFinished()
if (!results.isEmpty()) {
QJsonDbRemoveRequest *removePlacesRequest
= new QJsonDbRemoveRequest(results, this);
- connect(removePlacesRequest, SIGNAL(finished()),
- this, SLOT(removePlacesFinished()));
- connect(removePlacesRequest, SIGNAL(finished()),
- removePlacesRequest, SLOT(deleteLater()));
- connect(removePlacesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- connect(removePlacesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- removePlacesRequest, SLOT(deleteLater()));
+ setupRequest(removePlacesRequest,this, SLOT(removePlacesFinished()));
m_connection->send(removePlacesRequest);
} else {
removePlacesFinished();
@@ -221,18 +280,10 @@ void JsonDbUtils::getPlacesFinished()
void JsonDbUtils::removePlacesFinished()
{
QJsonDbReadRequest *getCategoriesRequest = new QJsonDbReadRequest(this);
+ getCategoriesRequest->setPartition(m_currentPartition);
getCategoriesRequest->setQuery(QString::fromLatin1("[?%1=\"%2\"]")
.arg(Type).arg(CategoryType));
- connect(getCategoriesRequest, SIGNAL(finished()),
- this, SLOT(getCategoriesFinished()));
- connect(getCategoriesRequest, SIGNAL(finished()),
- getCategoriesRequest, SLOT(deleteLater()));
- connect(getCategoriesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- connect(getCategoriesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- getCategoriesRequest, SLOT(deleteLater()));
+ setupRequest(getCategoriesRequest,this, SLOT(getCategoriesFinished()));
m_connection->send(getCategoriesRequest);
}
@@ -243,16 +294,7 @@ void JsonDbUtils::getCategoriesFinished()
if (!results.isEmpty()) {
QJsonDbRemoveRequest *removeCategoriesRequest
= new QJsonDbRemoveRequest(results, this);
- connect(removeCategoriesRequest, SIGNAL(finished()),
- this, SLOT(removeCategoriesFinished()));
- connect(removeCategoriesRequest, SIGNAL(finished()),
- removeCategoriesRequest, SLOT(deleteLater()));
- connect(removeCategoriesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- this, SLOT(requestError(QtJsonDb::QJsonDbRequest::ErrorCode,QString)));
- connect(removeCategoriesRequest,
- SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
- removeCategoriesRequest, SLOT(deleteLater()));
+ setupRequest(removeCategoriesRequest, this, SLOT(removeCategoriesFinished()));
m_connection->send(removeCategoriesRequest);
} else {
removeCategoriesFinished();
@@ -267,7 +309,11 @@ void JsonDbUtils::removeCategoriesFinished()
void JsonDbUtils::fetchPlaceJsonFinished()
{
QJsonDbRequest *request = qobject_cast<QJsonDbRequest *>(sender());
- emit placeFetched(request->takeResults().first());
+ QList<QJsonObject> results = request->takeResults();
+ if (results.count() == 1)
+ emit placeFetched(results.first());
+ else
+ emit placeFetched(QJsonObject());
}
void JsonDbUtils::savePlaceJsonFinished()
@@ -282,7 +328,7 @@ void JsonDbUtils::requestError(QJsonDbRequest::ErrorCode error,
<< QStringLiteral(" Error String: ") << errorString;
}
-void JsonDbUtils::makeConnections(QJsonDbRequest *request, QObject *parent,
+void JsonDbUtils::setupRequest(QJsonDbRequest *request, QObject *parent,
const char *slot)
{
Q_ASSERT(request);
@@ -300,6 +346,7 @@ void JsonDbUtils::makeConnections(QJsonDbRequest *request, QObject *parent,
SIGNAL(error(QtJsonDb::QJsonDbRequest::ErrorCode,QString)),
request,
SLOT(deleteLater()));
+ request->setPartition(m_currentPartition);
}
QProcess* JsonDbUtils::launchJsonDbDaemon(const QStringList &args)
@@ -335,10 +382,3 @@ QProcess* JsonDbUtils::launchJsonDbDaemon(const QStringList &args)
qFatal("Unable to connect to jsondb process");
return process;
}
-
-bool JsonDbUtils::hasJsonDbConnection() const
-{
- return m_jsondbProcess &&
- m_connection &&
- m_connection->status() == QtJsonDb::QJsonDbConnection::Connected;
-}
diff --git a/tests/auto/qplacemanager_jsondb/jsondbutils.h b/tests/auto/qplacemanager_jsondb/jsondbutils.h
index 9b1ce7af..0ecae87f 100644
--- a/tests/auto/qplacemanager_jsondb/jsondbutils.h
+++ b/tests/auto/qplacemanager_jsondb/jsondbutils.h
@@ -57,8 +57,9 @@ class JsonDbUtils : public QObject
{
Q_OBJECT
public:
- ~JsonDbUtils();
JsonDbUtils(QObject *parent = 0);
+ ~JsonDbUtils();
+
void cleanDb();
void sendRequest(QJsonDbRequest *request);
@@ -66,6 +67,7 @@ public:
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;
@@ -145,7 +147,11 @@ public:
static const QLatin1String CreatedDateTime;
static const QLatin1String ModifiedDateTime;
+ static const QLatin1String DefaultPartition;
+ static const QLatin1String PartitionType;
+
public slots:
+ void setupPartition(const QString &partition);
void getPlacesFinished();
void removePlacesFinished();
void getCategoriesFinished();
@@ -159,14 +165,16 @@ signals:
void dbCleaned();
void placeFetched(QJsonObject placeJson);
void placeSaved();
+ void partitionSetupDone();
private:
- void makeConnections(QJsonDbRequest *request, QObject *parent, const char *slot);
+ 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/tst_qplacemanager_jsondb.cpp b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
index 5cffbb7b..6bc3d3a2 100644
--- a/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
+++ b/tests/auto/qplacemanager_jsondb/tst_qplacemanager_jsondb.cpp
@@ -147,6 +147,7 @@ private Q_SLOTS:
void iconDownload_data();
#endif
void constructIconUrl();
+ void specifiedPartition();
private:
bool doSavePlace(const QPlace &place,
@@ -3057,6 +3058,93 @@ void tst_QPlaceManagerJsonDb::constructIconUrl()
//TODO: edge case testing for all combinations
}
+void tst_QPlaceManagerJsonDb::specifiedPartition()
+{
+ 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("nokia_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(QtLocation::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::cleanup()
{
QSignalSpy cleanSpy(dbUtils, SIGNAL(dbCleaned()));