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

Proposed by Martin Borho
Status: Merged
Approved by: Raúl Yeguas
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 Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
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.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
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
=== modified file 'components/AddLocationDialog.qml'
--- components/AddLocationDialog.qml 2013-06-04 21:36:23 +0000
+++ components/AddLocationDialog.qml 2013-06-09 16:50:35 +0000
@@ -52,7 +52,7 @@
52 citiesModel.clear();52 citiesModel.clear();
53 searchWorker.sendMessage({53 searchWorker.sendMessage({
54 action: "searchByName",54 action: "searchByName",
55 params: {name:locationString.text, units:"metric"}55 params: {name:locationString.text, units:mainView.settings["units"]}
56 })56 })
57 }57 }
58 }58 }
@@ -65,7 +65,7 @@
65 citiesModel.clear();65 citiesModel.clear();
66 searchWorker.sendMessage({66 searchWorker.sendMessage({
67 action: "searchByPoint",67 action: "searchByPoint",
68 params: {coords: {"lon":10,"lat":53.549999}, units:"metric"}68 params: {coords: {"lon":10,"lat":53.549999}, units:mainView.settings["units"]}
69 })69 })
70 }70 }
71 }71 }
7272
=== modified file 'components/CurrentWeather.qml'
--- components/CurrentWeather.qml 2013-04-21 18:05:01 +0000
+++ components/CurrentWeather.qml 2013-06-09 16:50:35 +0000
@@ -11,8 +11,7 @@
11 property int currentTemp11 property int currentTemp
12 property int minTemp12 property int minTemp
13 property int maxTemp13 property int maxTemp
14 property bool metric: true14 property string scale: (mainView.settings["units"] === "imperial") ? "F" : "C"
15 property string scale: (metric) ? "C" : "F"
1615
17 width: parent.width16 width: parent.width
18 height: childrenRect.height+units.gu(10)17 height: childrenRect.height+units.gu(10)
1918
=== modified file 'components/DayWeatherComponent.qml'
--- components/DayWeatherComponent.qml 2013-04-21 18:05:01 +0000
+++ components/DayWeatherComponent.qml 2013-06-09 16:50:35 +0000
@@ -13,8 +13,7 @@
13 property string icon13 property string icon
14 property int temperature14 property int temperature
15 property int temperatureMin15 property int temperatureMin
16 property bool metric: true16 property string scale: (mainView.settings["units"] === "imperial") ? "F" : "C"
17 property string scale: (metric) ? "C" : "F"
18 property string shapeColor: "#D6D6D6"17 property string shapeColor: "#D6D6D6"
1918
20 UbuntuShape{19 UbuntuShape{
2120
=== modified file 'components/Storage.qml'
--- components/Storage.qml 2013-06-04 21:36:23 +0000
+++ components/Storage.qml 2013-06-09 16:50:35 +0000
@@ -15,7 +15,46 @@
15 tx.executeSql('CREATE TABLE IF NOT EXISTS Locations(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT, date TEXT)');15 tx.executeSql('CREATE TABLE IF NOT EXISTS Locations(id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT, date TEXT)');
16 console.log('Database created');16 console.log('Database created');
17 });17 });
18 }18 // reopen database with new version number
19 db = LocalStorage.openDatabaseSync("ubuntu-weather-app", "", "Default Ubuntu weather app", 100000);
20 }
21
22 if(db.version === "0.1") {
23 db.changeVersion("0.1", "0.2",
24 function(tx) {
25 tx.executeSql('CREATE TABLE IF NOT EXISTS settings(key TEXT UNIQUE, value TEXT)');
26 console.log('Settings table added, Database upgraded to v0.2');
27 });
28 }
29 }
30
31 function saveSetting(key, value) {
32 openDB();
33 db.transaction( function(tx){
34 tx.executeSql('INSERT OR REPLACE INTO settings VALUES(?, ?)', [key, value]);
35 });
36 }
37
38 function getSettings(callback) {
39 openDB();
40 var settings = {};
41 db.readTransaction(
42 function(tx){
43 var rs = tx.executeSql('SELECT key, value FROM Settings');
44 for(var i = 0; i < rs.rows.length; i++) {
45 var row = rs.rows.item(i);
46 settings[row.key] = row.value;
47 }
48 callback(settings);
49 }
50 );
51 }
52
53 function clearSetting(name) {
54 openDB();
55 db.transaction(function(tx){
56 tx.executeSql('DELETE FROM Settings WHERE key = ?', [name]);
57 });
19 }58 }
2059
21 function insertLocation(data) {60 function insertLocation(data) {
@@ -36,9 +75,8 @@
36 }75 }
3776
38 function getLocations(callback) {77 function getLocations(callback) {
39
40 openDB();78 openDB();
41 db.transaction(79 db.readTransaction(
42 function(tx){80 function(tx){
43 var locations = [];81 var locations = [];
44 var rs = tx.executeSql('SELECT * FROM Locations');82 var rs = tx.executeSql('SELECT * FROM Locations');
@@ -64,6 +102,7 @@
64 openDB();102 openDB();
65 db.transaction(function(tx){103 db.transaction(function(tx){
66 tx.executeSql('DELETE FROM Locations WHERE 1');104 tx.executeSql('DELETE FROM Locations WHERE 1');
105 tx.executeSql('DELETE FROM Settings WHERE 1');
67 });106 });
68 }107 }
69}108}
70109
=== modified file 'components/WeatherApi.js'
--- components/WeatherApi.js 2013-05-01 14:45:17 +0000
+++ components/WeatherApi.js 2013-06-09 16:50:35 +0000
@@ -301,10 +301,12 @@
301 finished(result);301 finished(result);
302 }302 }
303 },303 },
304 units = (message.params.units === "metric" || message.params.units === "imperial")
305 ? message.params.units : "metric",
304 params = {306 params = {
305 location:loc.location,307 location:loc.location,
306 db: loc.db,308 db: loc.db,
307 units: message.params.units309 units: units
308 };310 };
309 WeatherApi.getLocationData(params, updatedHnd, onError);311 WeatherApi.getLocationData(params, updatedHnd, onError);
310 })312 })
311313
=== modified file 'ubuntu-weather-app.qml'
--- ubuntu-weather-app.qml 2013-06-04 21:36:23 +0000
+++ ubuntu-weather-app.qml 2013-06-09 16:50:35 +0000
@@ -15,6 +15,8 @@
1515
16 property var locationsList: []16 property var locationsList: []
17 property var tabsObject: null17 property var tabsObject: null
18 // set default values for settings here
19 property var settings: {"units":"metric"}
1820
19 WorkerScript {21 WorkerScript {
20 id: locationDataWorker22 id: locationDataWorker
@@ -71,7 +73,7 @@
71 function locationAdded(locationObj) {73 function locationAdded(locationObj) {
72 locationDataWorker.sendMessage({74 locationDataWorker.sendMessage({
73 action: "newLocationData",75 action: "newLocationData",
74 params: {location:locationObj, units:"metric"}76 params: {location:locationObj, units:settings["units"]}
75 });77 });
76 }78 }
7779
@@ -84,14 +86,21 @@
84 storage.getLocations(function(locations) {86 storage.getLocations(function(locations) {
85 locationDataWorker.sendMessage({87 locationDataWorker.sendMessage({
86 action: "updateData",88 action: "updateData",
87 params: {locations:locations, units:"metric"}89 params: {locations:locations, units:settings["units"]}
88 })90 })
89 });91 });
90 }92 }
9193
92 Component.onCompleted: {94 Component.onCompleted: {
93 //storage.clearDB();95 //storage.clearDB();
94 refreshData();96 //storage.clearSetting('units');
97 //storage.saveSetting("units", "imperial")
98 storage.getSettings(function(storedSettings) {
99 for(var settingName in storedSettings) {
100 settings[settingName] = storedSettings[settingName];
101 }
102 refreshData();
103 })
95 }104 }
96105
97 Components.AddLocationDialog {106 Components.AddLocationDialog {

Subscribers

People subscribed via source and target branches