56.1.1
by Martin Borho
Settings dialog now in a ComposerSheet, removed SettingsPage.qml, added SettingsSheet.qml |
1 |
/*
|
2 |
* Copyright (C) 2013 Canonical Ltd
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License version 3 as
|
|
6 |
* published by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
* Authored by: Raúl Yeguas <neokore@gmail.com>
|
|
17 |
* Martin Borho <martin@borho.net>
|
|
122.2.3
by Martin Borho
Added, updated licencse headers |
18 |
* Andrew Starr-Bochicchio <a.starr.b@gmail.com>
|
56.1.1
by Martin Borho
Settings dialog now in a ComposerSheet, removed SettingsPage.qml, added SettingsSheet.qml |
19 |
*/
|
1
by Michael Hall
Initial code template |
20 |
import QtQuick 2.0 |
21 |
import Ubuntu.Components 0.1 |
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
22 |
import "components" as Components |
98.1.1
by Martin Borho
added dynamic background gradient |
23 |
import "components/GradientsMap.js" as Gradients |
4.2.1
by neokore
Added another page for other forecast and a popup for adding a new |
24 |
import Ubuntu.Components.Popups 0.1 |
1
by Michael Hall
Initial code template |
25 |
|
26 |
MainView { |
|
27 |
// objectName for functional testing purposes (autopilot-qt5)
|
|
2
by Michael Hall
Modifications for Weather app |
28 |
objectName: "weather" |
133.1.5
by Sergio Schvezov
Using the packagename to write files in the proper locations when run under confinement |
29 |
applicationName: "com.ubuntu.weather" |
8.1.2
by Martin Borho
added applicationName again |
30 |
|
4.2.1
by neokore
Added another page for other forecast and a popup for adding a new |
31 |
id: mainView
|
1
by Michael Hall
Initial code template |
32 |
|
33 |
width: units.gu(50) |
|
34 |
height: units.gu(75) |
|
4.2.1
by neokore
Added another page for other forecast and a popup for adding a new |
35 |
|
137.1.4
by Martin Borho
updated default background gradient with new values |
36 |
headerColor: "#E04414" |
37 |
backgroundColor: "#E04414" |
|
38 |
footerColor: "#E1983E" |
|
69.1.3
by Martin Borho
suru gradient background added |
39 |
|
137.1.4
by Martin Borho
updated default background gradient with new values |
40 |
property string newHeaderColor: "#E04414" |
41 |
property string newBackgroundColor: "#E04414" |
|
42 |
property string newFooterColor: "#E1983E" |
|
98.1.1
by Martin Borho
added dynamic background gradient |
43 |
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
44 |
property var locationsList: [] |
45 |
property var tabsObject: null |
|
137.1.1
by Martin Borho
prevent falling back on first tab on refresh, tabs always show data for today when becoming visible (again) |
46 |
property int tabIndexAtRefresh: -1 |
47 |
||
179
by Martin Borho
TWC, for real this time |
48 |
property string twcApiKey: ""; |
49 |
||
31.2.1
by Martin Borho
possibility to save and load settings from storage, temporary table 'Settings' created. mainView property 'settings' added |
50 |
// set default values for settings here
|
119.1.2
by Andrew Starr-Bochicchio
Use the system locale to determine default units. |
51 |
property var settings: { |
119.1.5
by Andrew Starr-Bochicchio
Locale object may only be created via the Qt.locale() function. |
52 |
"units": Qt.locale().measurementSystem === Locale.MetricSystem ? "metric" : "imperial", |
122.3.1
by Martin Borho
added setting for precipitation unit, mm or in |
53 |
"wind_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "kmh" : "mph", |
176
by Martin Borho
added setting for changing weather data service between TWC or OWM |
54 |
"precip_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "mm" : "in", |
55 |
"service": "weatherchannel" |
|
119.1.2
by Andrew Starr-Bochicchio
Use the system locale to determine default units. |
56 |
}
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
57 |
|
10.3.1
by Martin Borho
add WorkerScript for data API requests |
58 |
WorkerScript { |
59 |
id: locationDataWorker
|
|
60 |
source: "components/WeatherApi.js" |
|
61 |
onMessage: { |
|
10.3.4
by Martin Borho
added a second retry when a first location data api request fails, handling of errors in WorkerScript |
62 |
if(!messageObject.error) { |
63 |
if(messageObject.action === "updateData") { |
|
64 |
messageObject.result.forEach(function(loc) { |
|
37.1.2
by Martin Borho
don't refresh weather data unless stored data is older than 30min or an update is forced. |
65 |
if(loc["save"] === true) { |
66 |
storage.updateLocation(loc.db.id, loc); |
|
67 |
}
|
|
10.3.4
by Martin Borho
added a second retry when a first location data api request fails, handling of errors in WorkerScript |
68 |
});
|
69 |
buildTabs(messageObject.result); |
|
70 |
}
|
|
71 |
} else { |
|
120.1.1
by Martin Borho
added componenet for notifications, loading indicator moved in own component, default gradient now with values from color scheme |
72 |
console.log(messageObject.error.msg+" / "+messageObject.error.request.url) |
73 |
httpFailedSplash.show() |
|
86.2.2
by Martin Borho
added ActivityIndicator for search, added Dialog when http calls are failing |
74 |
refreshData(true, null); |
10.3.1
by Martin Borho
add WorkerScript for data API requests |
75 |
}
|
76 |
}
|
|
77 |
}
|
|
78 |
||
98.1.1
by Martin Borho
added dynamic background gradient |
79 |
ParallelAnimation { |
80 |
id: gradientAnimation
|
|
81 |
ColorAnimation { |
|
82 |
target: mainView |
|
83 |
property: "headerColor" |
|
84 |
from: headerColor |
|
85 |
to: newHeaderColor |
|
104.1.1
by Martin Borho
improved scrolling, added slow/fast scrolling for day/hour scrolling distinction |
86 |
duration:UbuntuAnimation.BriskDuration |
87 |
easing: UbuntuAnimation.StandardEasing |
|
98.1.1
by Martin Borho
added dynamic background gradient |
88 |
}
|
89 |
ColorAnimation { |
|
90 |
target: mainView |
|
91 |
property: "backgroundColor" |
|
92 |
from: backgroundColor |
|
93 |
to: newBackgroundColor |
|
104.1.1
by Martin Borho
improved scrolling, added slow/fast scrolling for day/hour scrolling distinction |
94 |
duration:UbuntuAnimation.BriskDuration |
95 |
easing: UbuntuAnimation.StandardEasing |
|
98.1.1
by Martin Borho
added dynamic background gradient |
96 |
}
|
97 |
ColorAnimation { |
|
98 |
target: mainView |
|
99 |
property: "footerColor" |
|
100 |
from: footerColor |
|
101 |
to: newFooterColor |
|
104.1.1
by Martin Borho
improved scrolling, added slow/fast scrolling for day/hour scrolling distinction |
102 |
duration:UbuntuAnimation.BriskDuration |
103 |
easing: UbuntuAnimation.StandardEasing |
|
98.1.1
by Martin Borho
added dynamic background gradient |
104 |
}
|
105 |
}
|
|
106 |
||
98.1.2
by Martin Borho
fixed background for imperial values |
107 |
function adjustBackground(degrees) { |
104.1.1
by Martin Borho
improved scrolling, added slow/fast scrolling for day/hour scrolling distinction |
108 |
gradientAnimation.stop() |
98.1.2
by Martin Borho
fixed background for imperial values |
109 |
var celsius = (settings.units === "imperial") ? Math.round((degrees-32)/1.8) : degrees, |
110 |
colors = Gradients.getGradients(celsius); |
|
98.1.1
by Martin Borho
added dynamic background gradient |
111 |
newHeaderColor = colors.header; |
112 |
newBackgroundColor = colors.body; |
|
113 |
newFooterColor = colors.footer; |
|
114 |
gradientAnimation.start() |
|
115 |
}
|
|
116 |
||
8.1.3
by Martin Borho
Locations can be added, stored and removed |
117 |
// see https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1124071, temporary workaround
|
118 |
function buildTabs(locations) { |
|
15.1.4
by Raúl Yeguas
Now tabs move to recently added location (with Martin's help) |
119 |
// check if there was a location added
|
120 |
var locLength = locations.length, |
|
121 |
locBeforeLen = locationsList.length, |
|
122 |
focusToLast = (locBeforeLen > 0 && locLength > locBeforeLen) ? true : false; |
|
104.2.3
by Andrew Starr-Bochicchio
Let's be a little more subtile. |
123 |
refresh.visible = false; |
31.3.1
by Martin Borho
first version of location manager |
124 |
// show locationmanager when no location is added
|
125 |
if(locLength === 0) { |
|
126 |
showLocationManager() |
|
127 |
return; |
|
128 |
}
|
|
129 |
||
69.1.1
by Martin Borho
LocationManager now implemented with Sheet components. PageStack removed, now flat navigation is used |
130 |
locationsList = locations; |
8.1.3
by Martin Borho
Locations can be added, stored and removed |
131 |
if(tabsObject !== null) { |
132 |
tabsObject.destroy() |
|
133 |
}
|
|
15.1.4
by Raúl Yeguas
Now tabs move to recently added location (with Martin's help) |
134 |
var tabsString = "import QtQuick 2.0; import Ubuntu.Components 0.1; import Ubuntu.Components.Popups 0.1; import \"components\" as Components; " |
43.2.9
by Martin Borho
commit files missed |
135 |
+ "Tabs {id: tabs; objectName: 'rootTabs'; anchors.fill: parent;" |
8.1.3
by Martin Borho
Locations can be added, stored and removed |
136 |
if(locLength > 0) { |
137 |
for(var x=0;x<locLength;x++) { |
|
138 |
tabsString += "Components.LocationTab {title: '"+locations[x].location.name+"'; locationIndex: "+x+"} " |
|
139 |
};
|
|
31.3.3
by Martin Borho
LocationManager is shown when no locations are defined, removed LocationTabEmpty.qml and obsolte code |
140 |
}
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
141 |
tabsString += "}"; // END Tabs componen |
142 |
tabsObject = Qt.createQmlObject(tabsString, tabPage, "tabs") |
|
137.1.1
by Martin Borho
prevent falling back on first tab on refresh, tabs always show data for today when becoming visible (again) |
143 |
if(focusToLast) { |
15.1.4
by Raúl Yeguas
Now tabs move to recently added location (with Martin's help) |
144 |
tabsObject.selectedTabIndex = locLength -1; |
137.1.1
by Martin Borho
prevent falling back on first tab on refresh, tabs always show data for today when becoming visible (again) |
145 |
} else if(tabIndexAtRefresh > -1) { |
146 |
tabsObject.selectedTabIndex = tabIndexAtRefresh |
|
147 |
tabIndexAtRefresh = -1 |
|
148 |
}
|
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
149 |
}
|
150 |
||
37.1.2
by Martin Borho
don't refresh weather data unless stored data is older than 30min or an update is forced. |
151 |
function refreshData(from_storage, force_refresh) { |
104.2.3
by Andrew Starr-Bochicchio
Let's be a little more subtile. |
152 |
refresh.visible = true; |
37.1.2
by Martin Borho
don't refresh weather data unless stored data is older than 30min or an update is forced. |
153 |
if(from_storage === true && force_refresh !== true) { |
37.1.1
by Martin Borho
precalculate imperial values in api worker script, refesh from storage after units settings was changed |
154 |
storage.getLocations(buildTabs); |
176
by Martin Borho
added setting for changing weather data service between TWC or OWM |
155 |
} else { |
179
by Martin Borho
TWC, for real this time |
156 |
storage.getLocations(function(locations) { |
37.1.1
by Martin Borho
precalculate imperial values in api worker script, refesh from storage after units settings was changed |
157 |
locationDataWorker.sendMessage({ |
158 |
action: "updateData", |
|
179
by Martin Borho
TWC, for real this time |
159 |
params: { |
160 |
locations:locations, |
|
161 |
force:force_refresh, |
|
162 |
service:settings["service"], |
|
163 |
api_key: twcApiKey |
|
164 |
}
|
|
37.1.1
by Martin Borho
precalculate imperial values in api worker script, refesh from storage after units settings was changed |
165 |
})
|
166 |
});
|
|
167 |
}
|
|
8.1.5
by Martin Borho
automatic refresh of data at start |
168 |
}
|
169 |
||
31.3.1
by Martin Borho
first version of location manager |
170 |
function showLocationManager() { |
69.1.1
by Martin Borho
LocationManager now implemented with Sheet components. PageStack removed, now flat navigation is used |
171 |
PopupUtils.open(locationManager) |
31.3.1
by Martin Borho
first version of location manager |
172 |
}
|
173 |
||
56.1.1
by Martin Borho
Settings dialog now in a ComposerSheet, removed SettingsPage.qml, added SettingsSheet.qml |
174 |
function showSettings() { |
175 |
PopupUtils.open(settingsSheet) |
|
43.1.1
by Raúl Yeguas
Conversion from SettingsDialog to SettingsPage |
176 |
}
|
177 |
||
8.1.3
by Martin Borho
Locations can be added, stored and removed |
178 |
Component.onCompleted: { |
179 |
//storage.clearDB();
|
|
31.2.1
by Martin Borho
possibility to save and load settings from storage, temporary table 'Settings' created. mainView property 'settings' added |
180 |
//storage.clearSetting('units');
|
141.1.1
by Raúl Yeguas
Forced white color for location tabs and added shadow to forecast and |
181 |
|
182 |
//Theme.palette.selected.backgroundText = "#000000";
|
|
183 |
Theme.palette.normal.backgroundText = "#55FFFFFF"; |
|
184 |
||
176
by Martin Borho
added setting for changing weather data service between TWC or OWM |
185 |
storage.getSettings(function(storedSettings) { |
31.2.1
by Martin Borho
possibility to save and load settings from storage, temporary table 'Settings' created. mainView property 'settings' added |
186 |
for(var settingName in storedSettings) { |
187 |
settings[settingName] = storedSettings[settingName]; |
|
188 |
}
|
|
189 |
refreshData(); |
|
190 |
})
|
|
8.1.3
by Martin Borho
Locations can be added, stored and removed |
191 |
}
|
4.2.1
by neokore
Added another page for other forecast and a popup for adding a new |
192 |
|
56.1.1
by Martin Borho
Settings dialog now in a ComposerSheet, removed SettingsPage.qml, added SettingsSheet.qml |
193 |
Components.SettingsSheet { |
194 |
id: settingsSheet
|
|
33.1.1
by Raúl Yeguas
Added the SettingsDialog (by now, only for setting Units). |
195 |
}
|
1
by Michael Hall
Initial code template |
196 |
|
5.1.4
by Martin Borho
added debug/demo output for one cycle of Api/Storage calls |
197 |
Components.Storage{ |
198 |
id: storage
|
|
69.1.1
by Martin Borho
LocationManager now implemented with Sheet components. PageStack removed, now flat navigation is used |
199 |
}
|
200 |
||
201 |
Components.LocationManagerSheet { |
|
202 |
id:locationManager
|
|
203 |
}
|
|
204 |
||
120.1.1
by Martin Borho
added componenet for notifications, loading indicator moved in own component, default gradient now with values from color scheme |
205 |
Components.SplashComponent { |
206 |
id:httpFailedSplash
|
|
207 |
objectName: "HTTPFailedSplash" |
|
208 |
}
|
|
104.2.1
by Andrew Starr-Bochicchio
Increase visablity of ActivityIndicator while refreshing data using an overlay. |
209 |
|
120.1.1
by Martin Borho
added componenet for notifications, loading indicator moved in own component, default gradient now with values from color scheme |
210 |
Components.LoadingSpinnerComponent { |
211 |
id:refresh
|
|
69.1.1
by Martin Borho
LocationManager now implemented with Sheet components. PageStack removed, now flat navigation is used |
212 |
}
|
213 |
||
137.1.5
by Martin Borho
replaced Item in MainView with Page for fixing TypeError: Cannot call method 'hasOwnProperty' of null |
214 |
Page { |
69.1.1
by Martin Borho
LocationManager now implemented with Sheet components. PageStack removed, now flat navigation is used |
215 |
id:tabPage
|
216 |
width: parent.width |
|
217 |
height:parent.height |
|
218 |
}
|
|
219 |
||
1
by Michael Hall
Initial code template |
220 |
}
|