Merge lp:~martin-borho/ubuntu-weather-app/store-settings into lp:ubuntu-weather-app/obsolete.trunk

Proposed by Martin Borho on 2013-06-09
Status: Merged
Approved by: Raúl Yeguas on 2013-06-12
Approved revision: 32
Merged at revision: 33
Proposed branch: lp:~martin-borho/ubuntu-weather-app/store-settings
Merge into: lp:ubuntu-weather-app/obsolete.trunk
Diff against target: 184 lines (+61/-13)
6 files modified
components/AddLocationDialog.qml (+2/-2)
components/CurrentWeather.qml (+1/-2)
components/DayWeatherComponent.qml (+1/-2)
components/Storage.qml (+42/-3)
components/WeatherApi.js (+3/-1)
ubuntu-weather-app.qml (+12/-3)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/store-settings
Reviewer Review Type Date Requested Status
Raúl Yeguas 2013-06-09 Approve on 2013-06-12
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-06-09
Review via email: mp+168293@code.launchpad.net

Commit message

Possibility added for storing settings into and loading settings from storage.

Description of the change

Possibility added for storing settings into and loading settings from storage.

Also a property named "settings" was added to mainView, for default values and to access the settings within the app. "imperial" has to be the "units"-value for using Fahrenheit. API calls will take the "units" setting into account.

For now the values will be saved in a new LocalStorage table. This is temporary solution until an upstream component is ready.

At startup all settings will be loaded from storage.

//To save a setting:
storage.saveSetting("units", "imperial")

The corresponding property in mainView.settings has to be updated too after changes!

@Raúl does it fit into your work?

To post a comment you must log in.
Raúl Yeguas (neokore) wrote :

It fits perfectly! Great work, Martin!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components/AddLocationDialog.qml'
2--- components/AddLocationDialog.qml 2013-06-04 21:36:23 +0000
3+++ components/AddLocationDialog.qml 2013-06-09 16:50:35 +0000
4@@ -52,7 +52,7 @@
5 citiesModel.clear();
6 searchWorker.sendMessage({
7 action: "searchByName",
8- params: {name:locationString.text, units:"metric"}
9+ params: {name:locationString.text, units:mainView.settings["units"]}
10 })
11 }
12 }
13@@ -65,7 +65,7 @@
14 citiesModel.clear();
15 searchWorker.sendMessage({
16 action: "searchByPoint",
17- params: {coords: {"lon":10,"lat":53.549999}, units:"metric"}
18+ params: {coords: {"lon":10,"lat":53.549999}, units:mainView.settings["units"]}
19 })
20 }
21 }
22
23=== modified file 'components/CurrentWeather.qml'
24--- components/CurrentWeather.qml 2013-04-21 18:05:01 +0000
25+++ components/CurrentWeather.qml 2013-06-09 16:50:35 +0000
26@@ -11,8 +11,7 @@
27 property int currentTemp
28 property int minTemp
29 property int maxTemp
30- property bool metric: true
31- property string scale: (metric) ? "C" : "F"
32+ property string scale: (mainView.settings["units"] === "imperial") ? "F" : "C"
33
34 width: parent.width
35 height: childrenRect.height+units.gu(10)
36
37=== modified file 'components/DayWeatherComponent.qml'
38--- components/DayWeatherComponent.qml 2013-04-21 18:05:01 +0000
39+++ components/DayWeatherComponent.qml 2013-06-09 16:50:35 +0000
40@@ -13,8 +13,7 @@
41 property string icon
42 property int temperature
43 property int temperatureMin
44- property bool metric: true
45- property string scale: (metric) ? "C" : "F"
46+ property string scale: (mainView.settings["units"] === "imperial") ? "F" : "C"
47 property string shapeColor: "#D6D6D6"
48
49 UbuntuShape{
50
51=== modified file 'components/Storage.qml'
52--- components/Storage.qml 2013-06-04 21:36:23 +0000
53+++ components/Storage.qml 2013-06-09 16:50:35 +0000
54@@ -15,7 +15,46 @@
55 tx.executeSql('CREATE TABLE IF NOT EXISTS Locations(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT, date TEXT)');
56 console.log('Database created');
57 });
58- }
59+ // reopen database with new version number
60+ db = LocalStorage.openDatabaseSync("ubuntu-weather-app", "", "Default Ubuntu weather app", 100000);
61+ }
62+
63+ if(db.version === "0.1") {
64+ db.changeVersion("0.1", "0.2",
65+ function(tx) {
66+ tx.executeSql('CREATE TABLE IF NOT EXISTS settings(key TEXT UNIQUE, value TEXT)');
67+ console.log('Settings table added, Database upgraded to v0.2');
68+ });
69+ }
70+ }
71+
72+ function saveSetting(key, value) {
73+ openDB();
74+ db.transaction( function(tx){
75+ tx.executeSql('INSERT OR REPLACE INTO settings VALUES(?, ?)', [key, value]);
76+ });
77+ }
78+
79+ function getSettings(callback) {
80+ openDB();
81+ var settings = {};
82+ db.readTransaction(
83+ function(tx){
84+ var rs = tx.executeSql('SELECT key, value FROM Settings');
85+ for(var i = 0; i < rs.rows.length; i++) {
86+ var row = rs.rows.item(i);
87+ settings[row.key] = row.value;
88+ }
89+ callback(settings);
90+ }
91+ );
92+ }
93+
94+ function clearSetting(name) {
95+ openDB();
96+ db.transaction(function(tx){
97+ tx.executeSql('DELETE FROM Settings WHERE key = ?', [name]);
98+ });
99 }
100
101 function insertLocation(data) {
102@@ -36,9 +75,8 @@
103 }
104
105 function getLocations(callback) {
106-
107 openDB();
108- db.transaction(
109+ db.readTransaction(
110 function(tx){
111 var locations = [];
112 var rs = tx.executeSql('SELECT * FROM Locations');
113@@ -64,6 +102,7 @@
114 openDB();
115 db.transaction(function(tx){
116 tx.executeSql('DELETE FROM Locations WHERE 1');
117+ tx.executeSql('DELETE FROM Settings WHERE 1');
118 });
119 }
120 }
121
122=== modified file 'components/WeatherApi.js'
123--- components/WeatherApi.js 2013-05-01 14:45:17 +0000
124+++ components/WeatherApi.js 2013-06-09 16:50:35 +0000
125@@ -301,10 +301,12 @@
126 finished(result);
127 }
128 },
129+ units = (message.params.units === "metric" || message.params.units === "imperial")
130+ ? message.params.units : "metric",
131 params = {
132 location:loc.location,
133 db: loc.db,
134- units: message.params.units
135+ units: units
136 };
137 WeatherApi.getLocationData(params, updatedHnd, onError);
138 })
139
140=== modified file 'ubuntu-weather-app.qml'
141--- ubuntu-weather-app.qml 2013-06-04 21:36:23 +0000
142+++ ubuntu-weather-app.qml 2013-06-09 16:50:35 +0000
143@@ -15,6 +15,8 @@
144
145 property var locationsList: []
146 property var tabsObject: null
147+ // set default values for settings here
148+ property var settings: {"units":"metric"}
149
150 WorkerScript {
151 id: locationDataWorker
152@@ -71,7 +73,7 @@
153 function locationAdded(locationObj) {
154 locationDataWorker.sendMessage({
155 action: "newLocationData",
156- params: {location:locationObj, units:"metric"}
157+ params: {location:locationObj, units:settings["units"]}
158 });
159 }
160
161@@ -84,14 +86,21 @@
162 storage.getLocations(function(locations) {
163 locationDataWorker.sendMessage({
164 action: "updateData",
165- params: {locations:locations, units:"metric"}
166+ params: {locations:locations, units:settings["units"]}
167 })
168 });
169 }
170
171 Component.onCompleted: {
172 //storage.clearDB();
173- refreshData();
174+ //storage.clearSetting('units');
175+ //storage.saveSetting("units", "imperial")
176+ storage.getSettings(function(storedSettings) {
177+ for(var settingName in storedSettings) {
178+ settings[settingName] = storedSettings[settingName];
179+ }
180+ refreshData();
181+ })
182 }
183
184 Components.AddLocationDialog {

Subscribers

People subscribed via source and target branches