Merge lp:~kalikiana/ubuntu-ui-toolkit/sqlitestorage into lp:ubuntu-ui-toolkit

Proposed by Christian Dywan on 2013-09-27
Status: Merged
Approved by: Zsombor Egri on 2013-09-30
Approved revision: 770
Merged at revision: 770
Proposed branch: lp:~kalikiana/ubuntu-ui-toolkit/sqlitestorage
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 158 lines (+72/-1)
6 files modified
debian/control (+1/-0)
modules/Ubuntu/Components/plugin/plugin.cpp (+2/-0)
modules/Ubuntu/Components/plugin/ucapplication.cpp (+16/-1)
modules/Ubuntu/Components/plugin/ucapplication.h (+4/-0)
tests/unit/tst_mainview/LocalStorage.qml (+32/-0)
tests/unit/tst_mainview/tst_mainview.cpp (+17/-0)
To merge this branch: bzr merge lp:~kalikiana/ubuntu-ui-toolkit/sqlitestorage
Reviewer Review Type Date Requested Status
Zsombor Egri 2013-09-27 Approve on 2013-09-30
PS Jenkins bot continuous-integration Approve on 2013-09-27
Review via email: mp+188016@code.launchpad.net

Commit message

Set offline storage path and add a unit test

Description of the change

Basically speaking the code for offline storage was lost between branch changes and since UI toolkit doesn't require it I didn't add a unit test for local storageā€¦ this time I'm adding a build dependency to ensure that the fix is there.

To post a comment you must log in.
769. By Christian Dywan on 2013-09-27

Add a comma after qtdeclarative5-localstorage-plugin

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
770. By Christian Dywan on 2013-09-27

Empty commit

Zsombor Egri (zsombi) wrote :

Nice update, thanks for it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-09-12 06:14:08 +0000
3+++ debian/control 2013-09-27 15:32:10 +0000
4@@ -21,6 +21,7 @@
5 qtdeclarative5-test-plugin,
6 qtdeclarative5-window-plugin,
7 qtdeclarative5-unity-action-plugin,
8+ qtdeclarative5-localstorage-plugin,
9 devscripts,
10 libqt5organizer5,
11 qtpim5-dev,
12
13=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
14--- modules/Ubuntu/Components/plugin/plugin.cpp 2013-09-24 09:59:29 +0000
15+++ modules/Ubuntu/Components/plugin/plugin.cpp 2013-09-27 15:32:10 +0000
16@@ -178,6 +178,8 @@
17 new ContextPropertyChangeListener(context, "UbuntuApplication");
18 QObject::connect(&UCApplication::instance(), SIGNAL(applicationNameChanged()),
19 applicationChangeListener, SLOT(updateContextProperty()));
20+ // Give the application object access to the engine
21+ UCApplication::instance().setContext(context);
22
23 context->setContextProperty("units", &UCUnits::instance());
24 ContextPropertyChangeListener *unitsChangeListener =
25
26=== modified file 'modules/Ubuntu/Components/plugin/ucapplication.cpp'
27--- modules/Ubuntu/Components/plugin/ucapplication.cpp 2013-09-17 09:36:13 +0000
28+++ modules/Ubuntu/Components/plugin/ucapplication.cpp 2013-09-27 15:32:10 +0000
29@@ -20,6 +20,9 @@
30
31 #include <QtCore/QCoreApplication>
32 #include <QDebug>
33+#include <QtQml/QQmlContext>
34+#include <QtQml/QQmlEngine>
35+#include <QtCore/QStandardPaths>
36
37 /*!
38 * \qmltype UbuntuApplication
39@@ -30,10 +33,14 @@
40 *
41 * UbuntuApplication is a context property in QML.
42 */
43-UCApplication::UCApplication(QObject* parent) : QObject(parent)
44+UCApplication::UCApplication(QObject* parent) : QObject(parent), m_context(0)
45 {
46 }
47
48+void UCApplication::setContext(QQmlContext* context) {
49+ m_context = context;
50+}
51+
52 /*!
53 * \qmlproperty string Application::applicationName
54 * \internal
55@@ -52,6 +59,14 @@
56 QCoreApplication::setApplicationName(applicationName);
57 // Unset organization to skip an extra folder component
58 QCoreApplication::setOrganizationName("");
59+ /*
60+ Ensure that LocalStorage and WebKit use the same location
61+ Docs are ambiguous: in practise applicationName is ignored by default
62+ */
63+ QQmlEngine* engine(m_context->engine());
64+ QString dataFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
65+ engine->setOfflineStoragePath(dataFolder);
66+
67 Q_EMIT applicationNameChanged();
68 }
69
70
71=== modified file 'modules/Ubuntu/Components/plugin/ucapplication.h'
72--- modules/Ubuntu/Components/plugin/ucapplication.h 2013-09-16 15:52:16 +0000
73+++ modules/Ubuntu/Components/plugin/ucapplication.h 2013-09-27 15:32:10 +0000
74@@ -44,8 +44,12 @@
75 QString applicationName();
76
77 // setter
78+ void setContext(QQmlContext* context);
79 void setApplicationName(QString applicationName);
80
81+private:
82+ QQmlContext* m_context;
83+
84 Q_SIGNALS:
85 void applicationNameChanged();
86 };
87
88=== added file 'tests/unit/tst_mainview/LocalStorage.qml'
89--- tests/unit/tst_mainview/LocalStorage.qml 1970-01-01 00:00:00 +0000
90+++ tests/unit/tst_mainview/LocalStorage.qml 2013-09-27 15:32:10 +0000
91@@ -0,0 +1,32 @@
92+/*
93+ * Copyright 2013 Canonical Ltd.
94+ *
95+ * This program is free software; you can redistribute it and/or modify
96+ * it under the terms of the GNU Lesser General Public License as published by
97+ * the Free Software Foundation; version 3.
98+ *
99+ * This program is distributed in the hope that it will be useful,
100+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
101+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102+ * GNU Lesser General Public License for more details.
103+ *
104+ * You should have received a copy of the GNU Lesser General Public License
105+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
106+ */
107+
108+import QtQuick 2.0
109+import Ubuntu.Components 0.1
110+import QtQuick.LocalStorage 2.0
111+
112+MainView {
113+ objectName: "localStorage"
114+ applicationName: "tv.island.pacific"
115+
116+ Component.onCompleted: {
117+ var db = LocalStorage.openDatabaseSync("pacific.island.tv", "1.0", "lorem ipsum", 1000)
118+ db.transaction(function(tx){
119+ tx.executeSql('CREATE TABLE IF NOT EXISTS Island(name TEXT)')
120+ tx.executeSql('INSERT INTO Island VALUES(?)', ['Tuvalu'])
121+ })
122+ }
123+}
124
125=== modified file 'tests/unit/tst_mainview/tst_mainview.cpp'
126--- tests/unit/tst_mainview/tst_mainview.cpp 2013-09-16 15:52:16 +0000
127+++ tests/unit/tst_mainview/tst_mainview.cpp 2013-09-27 15:32:10 +0000
128@@ -30,6 +30,7 @@
129 #include <QtCore/QThread>
130 #include <QtCore/QFileInfo>
131 #include <QtCore/QDir>
132+#include <QCryptographicHash>
133
134 #include "ucapplication.h"
135 #include "ucunits.h"
136@@ -125,6 +126,22 @@
137 QString expectedCacheFolder(xdgCacheHome + "/" + appName);
138 QCOMPARE(cacheFolder, expectedCacheFolder);
139 }
140+
141+ void testLocalStorage() {
142+ QQuickItem *root = loadTest("LocalStorage.qml");
143+ QVERIFY(root);
144+ QQuickItem *mainView = root;
145+ QString applicationName(mainView->property("applicationName").toString());
146+ QCOMPARE(applicationName, QString("tv.island.pacific"));
147+ QCOMPARE(applicationName, QCoreApplication::applicationName());
148+ QCOMPARE(QString(""), QCoreApplication::organizationName());
149+ QString dataFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
150+ QString databaseFolder(dataFolder + "/Databases");
151+ QVERIFY(QFile::exists(databaseFolder));
152+ QString hash(QCryptographicHash::hash("pacific.island.tv", QCryptographicHash::Md5).toHex());
153+ QString database(databaseFolder + "/" + hash + ".sqlite");
154+ QVERIFY(QFile::exists(database));
155+ }
156 };
157
158 QTEST_MAIN(tst_MainView)

Subscribers

People subscribed via source and target branches

to status/vote changes: