41
41
useDeprecatedToolbar: false
42
42
anchorToKeyboard: true
45
List of locations and their data, accessible through index
47
property var locationsList: []
50
Index of Location before a refresh, to go back after
52
property int indexAtRefresh: -1
55
Set default values for settings here
57
property var settings: {
58
"units": Qt.locale().measurementSystem === Locale.MetricSystem ? "metric" : "imperial",
59
"wind_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "kmh" : "mph",
60
"precip_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "mm" : "in",
61
"service": "weatherchannel"
65
Scale symbols and labels.
67
property string tempScale
68
property string speedScale
69
property string precipScale
70
property string tempUnits
71
property string windUnits
72
property string precipUnits
75
After reading the settings from storage and updating the default
76
settings with the user selected ones, (re)load pages!
44
78
Component.onCompleted: {
45
storage.getLocations(function(locations) {
46
WeatherApi.sendRequest({
51
service: "weatherchannel",
54
}, responseDataHandler)
79
storage.getSettings(function(storedSettings) {
80
for(var settingName in storedSettings) {
81
settings[settingName] = storedSettings[settingName];
88
function setScalesAndLabels() {
90
tempScale = String("°") + ((settings["units"] === "imperial") ? "F" : "C")
91
speedScale = ((settings["wind_units"] === "mph") ? "mph" : "km/h")
92
precipScale = ((settings["precip_units"] === "in") ? "in" : "mm")
93
tempUnits = ((settings["units"] === 'imperial') ? 'imperial' : 'metric')
94
windUnits = ((settings["wind_units"] === 'mph') ? 'imperial' : 'metric')
95
precipUnits = ((settings["precip_units"] === 'in') ? 'imperial' : 'metric')
99
Handle response data from data backend. Checks if a location
100
was updated and has to be stored again.
58
102
function responseDataHandler(messageObject) {
59
103
if(!messageObject.error) {
60
104
if(messageObject.action === "updateData") {
120
/* Fill the location pages with their data. */
121
function fillPages(locations) {
122
locationsList = locations;
123
// refactor this when Location are in a ListView!
124
homePage.renderData();
128
Refresh data, either directly from storage or by checking against
131
function refreshData(from_storage, force_refresh) {
132
if(from_storage === true && force_refresh !== true) {
133
storage.getLocations(fillPages);
135
storage.getLocations(function(locations) {
136
WeatherApi.sendRequest({
137
action: "updateData",
141
service:settings["service"],
144
}, responseDataHandler)