summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanth Ullattil <prasanth.ullattil@nokia.com>2012-04-12 10:26:48 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-12 10:47:21 +0200
commite0af1178858cfc0032b3441b2e655ae5d2e04990 (patch)
tree9daf122261cb9c5581e7fa8cfa3d86e7b3c7e79c
parenta067f1eb590601d1107adfd17e693c2f1f3d286f (diff)
Ensure support for partitions.json file in QML examples
Partitions can't be created using the QML API's anymore, make sure its handled correctly in the examples Change-Id: I655e66a3b7266b3c72ad7dcb91b51ce2029b04d6 Reviewed-by: Kevin Simons <kevin.simons@nokia.com>
-rw-r--r--examples/declarative/cachingmodel/cachingmodel.qml49
-rw-r--r--examples/declarative/contactsmodel/contactsmodel.qml40
-rw-r--r--examples/declarative/notifications/notifications.qml51
-rw-r--r--examples/declarative/partitions.json4
-rw-r--r--examples/declarative/simplelistmodel/simplelistmodel.qml32
5 files changed, 63 insertions, 113 deletions
diff --git a/examples/declarative/cachingmodel/cachingmodel.qml b/examples/declarative/cachingmodel/cachingmodel.qml
index 15b6c6d..0916ce4 100644
--- a/examples/declarative/cachingmodel/cachingmodel.qml
+++ b/examples/declarative/cachingmodel/cachingmodel.qml
@@ -52,7 +52,6 @@ Item {
JsonDb.Partition {
id: systemPartition
}
- // NOTE: Expect API changes
JsonDb.JsonDbCachingListModel {
id: contacts
query: '[?_type="MyContacts"]'
@@ -62,17 +61,14 @@ Item {
}
function indexCreateCallback(error, response) {
- console.log("Index Create callback #############");
if (error) {
console.log("Failed to create Index "+JSON.stringify(error));
return;
}
- console.log("Index created");
}
function createIndex()
{
- console.log("createIndex ***************");
var indexDefinition = {
"_type": "Index",
"name": "firstName",
@@ -81,53 +77,32 @@ Item {
};
nokiaPartition.create(indexDefinition, indexCreateCallback);
nokiaPartition2.create(indexDefinition, indexCreateCallback);
- console.log("createIndex ***************");
- }
- function partitionCreateCallback(error, response) {
- if (error) {
- console.log("Failed to create Partitions :"+JSON.stringify(error));
- return;
- }
- console.log("Partition Create callback #############");
- nokiaPartition = JsonDb.partition("com.nokia.shared", topLevelItem);
- nokiaPartition2 = JsonDb.partition("com.nokia.shared2", topLevelItem);
- createIndex();
- contacts.partitions = [nokiaPartition, nokiaPartition2];
}
function checkForPartitions(error, result) {
- console.log("checkForPartitions");
if (error) {
console.log("Failed to list Partitions");
} else {
+ var validPartitions = 0;
// result is an array of objects describing the know partitions
- var foundNokiaPartition = false;
- var foundNokiaPartition2 = false;
for (var i = 0; i < result.length; i++) {
- console.log("["+i+"] : "+ result[i].name);
- if (result[i].name === "com.nokia.shared") {
- foundNokiaPartition = true;
- } else if (result[i].name === "com.nokia.shared2") {
- foundNokiaPartition2 = true;
+ if (result[i].name === "com.nokia.shared" || result[i].name === "com.nokia.shared2") {
+ validPartitions++;
}
}
- var partitionList = new Array();
- var idx = 0;
- if (!foundNokiaPartition) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared"};
- idx++;
- }
- if (!foundNokiaPartition2) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared2"};
- idx++;
- }
- if (idx>0) {
- systemPartition.create(partitionList, partitionCreateCallback);
+ if (validPartitions != 2) {
+ console.log("!!!!!!! No valid partitions found !!!!!!!!!!!");
+ console.log("Error : Partitions for this example are not available");
+ console.log("Run jsondb daemon in examples/declarative directory to load partiions.json");
} else {
- partitionCreateCallback(undefined, {});
+ nokiaPartition = JsonDb.partition("com.nokia.shared");
+ nokiaPartition2 = JsonDb.partition("com.nokia.shared2");
+ createIndex();
+ contacts.partitions = [nokiaPartition, nokiaPartition2];
}
}
}
+
// Logs notifications of type "MyContacts" in partition "com.nokia.shared"
JsonDb.Partition {
name: "com.nokia.shared"
diff --git a/examples/declarative/contactsmodel/contactsmodel.qml b/examples/declarative/contactsmodel/contactsmodel.qml
index da618ca..5b18925 100644
--- a/examples/declarative/contactsmodel/contactsmodel.qml
+++ b/examples/declarative/contactsmodel/contactsmodel.qml
@@ -59,45 +59,25 @@ Item {
sortOrder:"[/firstName]"
}
- function partitionCreateCallback(error, response) {
- if (error) {
- console.log("Failed to create Partitions");
- return;
- }
- nokiaPartition = JsonDb.partition("com.nokia.shared");
- nokiaPartition2 = JsonDb.partition("com.nokia.shared2");
- contacts.partitions = [nokiaPartition, nokiaPartition2];
- }
-
function checkForPartitions(error, result) {
if (error) {
console.log("Failed to list Partitions");
} else {
+ var validPartitions = 0;
// result is an array of objects describing the know partitions
- var foundNokiaPartition = false;
- var foundNokiaPartition2 = false;
for (var i = 0; i < result.length; i++) {
- console.log("["+i+"] : "+ result[i].name);
- if (result[i].name === "com.nokia.shared") {
- foundNokiaPartition = true;
- } else if (result[i].name === "com.nokia.shared2") {
- foundNokiaPartition2 = true;
+ if (result[i].name === "com.nokia.shared" || result[i].name === "com.nokia.shared2") {
+ validPartitions++;
}
}
- var partitionList = new Array();
- var idx = 0;
- if (!foundNokiaPartition) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared"};
- idx++;
- }
- if (!foundNokiaPartition2) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared2"};
- idx++;
- }
- if (idx>0) {
- systemPartition.create(partitionList, partitionCreateCallback);
+ if (validPartitions != 2) {
+ console.log("!!!!!!! No valid partitions found !!!!!!!!!!!");
+ console.log("Error : Partitions for this example are not available");
+ console.log("Run jsondb daemon in examples/declarative directory to load partiions.json");
} else {
- partitionCreateCallback(undefined, {});
+ nokiaPartition = JsonDb.partition("com.nokia.shared");
+ nokiaPartition2 = JsonDb.partition("com.nokia.shared2");
+ contacts.partitions = [nokiaPartition, nokiaPartition2];
}
}
}
diff --git a/examples/declarative/notifications/notifications.qml b/examples/declarative/notifications/notifications.qml
index 1efc90d..7b4830b 100644
--- a/examples/declarative/notifications/notifications.qml
+++ b/examples/declarative/notifications/notifications.qml
@@ -112,50 +112,31 @@ Item {
}
}
- function partitionCreateCallback(error, response) {
- if (error) {
- console.log("Error " + error.code+ " " + error.message);
- return;
- }
- nokiaPartition = JsonDb.partition("com.nokia.shared", topLevelItem);
- nokiaPartition2 = JsonDb.partition("com.nokia.shared2", topLevelItem);
- contacts.partitions = [nokiaPartition, nokiaPartition2];
- // Watch for MyContact objects in 'com.nokia.shared2'
- var createNotification = nokiaPartition2.createNotification('[?_type="MyContacts"]', topLevelItem);
- createNotification.notification.connect(onNotification);
- // Set log area title
- logRect.title = "Notifications from: " + nokiaPartition.name;
- logRect2.title = "Notifications from: " + nokiaPartition2.name;
- }
-
function checkForPartitions(error, result) {
if (error) {
console.log("Failed to list Partitions");
} else {
+ var validPartitions = 0;
// result is an array of objects describing the know partitions
- var foundNokiaPartition = false;
- var foundNokiaPartition2 = false;
for (var i = 0; i < result.length; i++) {
- if (result[i].name === "com.nokia.shared") {
- foundNokiaPartition = true;
- } else if (result[i].name === "com.nokia.shared2") {
- foundNokiaPartition2 = true;
+ if (result[i].name === "com.nokia.shared" || result[i].name === "com.nokia.shared2") {
+ validPartitions++;
}
}
- var partitionList = new Array();
- var idx = 0;
- if (!foundNokiaPartition) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared"};
- idx++;
- }
- if (!foundNokiaPartition2) {
- partitionList[idx] = {_type :"Partition", name :"com.nokia.shared2"};
- idx++;
- }
- if (idx>0) {
- systemPartition.create(partitionList, partitionCreateCallback);
+ if (validPartitions != 2) {
+ console.log("!!!!!!! No valid partitions found !!!!!!!!!!!");
+ console.log("Error : Partitions for this example are not available");
+ console.log("Run jsondb daemon in examples/declarative directory to load partiions.json");
} else {
- partitionCreateCallback(undefined, {});
+ nokiaPartition = JsonDb.partition("com.nokia.shared", topLevelItem);
+ nokiaPartition2 = JsonDb.partition("com.nokia.shared2", topLevelItem);
+ contacts.partitions = [nokiaPartition, nokiaPartition2];
+ // Watch for MyContact objects in 'com.nokia.shared2'
+ var createNotification = nokiaPartition2.createNotification('[?_type="MyContacts"]', topLevelItem);
+ createNotification.notification.connect(onNotification);
+ // Set log area title
+ logRect.title = "Notifications from: " + nokiaPartition.name;
+ logRect2.title = "Notifications from: " + nokiaPartition2.name;
}
}
}
diff --git a/examples/declarative/partitions.json b/examples/declarative/partitions.json
new file mode 100644
index 0000000..0a71596
--- /dev/null
+++ b/examples/declarative/partitions.json
@@ -0,0 +1,4 @@
+[
+ { "name" :"com.nokia.shared" },
+ { "name" :"com.nokia.shared2" }
+]
diff --git a/examples/declarative/simplelistmodel/simplelistmodel.qml b/examples/declarative/simplelistmodel/simplelistmodel.qml
index 44582e3..c255842 100644
--- a/examples/declarative/simplelistmodel/simplelistmodel.qml
+++ b/examples/declarative/simplelistmodel/simplelistmodel.qml
@@ -47,9 +47,6 @@ Item {
height: 300
JsonDb.Partition {
- id: systemPartition
- }
- JsonDb.Partition {
id: nokiaPartition
name: "com.nokia.shared"
}
@@ -60,20 +57,33 @@ Item {
roleNames: ["firstName", "lastName", "_uuid"]
limit: 40
}
- function partitionCreateCallback(error, response) {
+
+ function checkForPartitions(error, result) {
if (error) {
- console.log(JSON.stringify(error));
- }
- console.log("Partition Created id = "+response.id +" count = "+response.items.length);
- for (var i = 0; i < response.items.length; i++) {
- console.log("response._uuid = "+response.items[i]._uuid +" ._version = "+response.items[i]._version);
+ console.log("Failed to list Partitions");
+ } else {
+ var sharedPartitionAvialable = false;
+ // result is an array of objects describing the know partitions
+ for (var i = 0; i < result.length; i++) {
+ if (result[i].name === "com.nokia.shared") {
+ sharedPartitionAvialable = true;
+ break;
+ }
+ }
+ if (!sharedPartitionAvialable) {
+ console.log("!!!!!!! No valid partition found !!!!!!!!!!!");
+ console.log("Error : Partition for this example is not available");
+ console.log("Run jsondb daemon in examples/declarative directory to load partiions.json");
+ } else {
+ contacts.partition = nokiaPartition;
+ }
}
- contacts.partition = nokiaPartition;
}
Component.onCompleted: {
- systemPartition.create({_type :"Partition", name :"com.nokia.shared"}, partitionCreateCallback)
+ JsonDb.listPartitions(checkForPartitions);
}
+
Button {
id: buttonAdd
anchors.top: parent.top