Merge lp:~nik90/unav/code-cleanup-part2 into lp:~costales/unav/trunk

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 7
Proposed branch: lp:~nik90/unav/code-cleanup-part2
Merge into: lp:~costales/unav/trunk
Prerequisite: lp:~nik90/unav/code-cleanup-part1
Diff against target: 548 lines (+341/-184)
2 files modified
qml/SettingsPage.qml (+254/-184)
qml/components/ExpandableListItem.qml (+87/-0)
To merge this branch: bzr merge lp:~nik90/unav/code-cleanup-part2
Reviewer Review Type Date Requested Status
costales Pending
Review via email: mp+289794@code.launchpad.net

Description of the change

Revamped Settings Page.

To post a comment you must log in.
lp:~nik90/unav/code-cleanup-part2 updated
15. By Nekhelesh Ramananthan

Updated header

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'qml/SettingsPage.qml'
--- qml/SettingsPage.qml 2016-03-22 14:03:11 +0000
+++ qml/SettingsPage.qml 2016-03-22 14:03:11 +0000
@@ -18,7 +18,6 @@
18import QtQuick 2.418import QtQuick 2.4
19import Ubuntu.Components 1.319import Ubuntu.Components 1.3
20import Ubuntu.Components.Popups 1.320import Ubuntu.Components.Popups 1.3
21import Ubuntu.Components.ListItems 1.3 as ListItems
22import QtQuick.LocalStorage 2.021import QtQuick.LocalStorage 2.0
23import "js/db.js" as UnavDB22import "js/db.js" as UnavDB
24import "components"23import "components"
@@ -26,190 +25,261 @@
26Page {25Page {
27 id: settingsPage26 id: settingsPage
2827
29 title: i18n.tr("Settings")28 header: PageHeader {
29 title: i18n.tr("Settings")
30 flickable: flickable
31 }
32
30 signal settingsChanged()33 signal settingsChanged()
3134
32 Flickable {35 ListModel {
33 id: flickable36 id: navigationModeModel
34 anchors.fill: parent37 Component.onCompleted: initialize()
35 contentHeight: settingsColumn.height + units.gu(5)38 function initialize() {
3639 navigationModeModel.append({ "mode": i18n.tr("Car"), "index": 0 })
37 Column {40 navigationModeModel.append({ "mode": i18n.tr("Walking"), "index": 1 })
38 id: settingsColumn41 navigationModeModel.append({ "mode": i18n.tr("Bicycle"), "index": 2 })
3942
40 anchors {43 _modeList.subText.text = navigationModeModel.get(navApp.settings.routingMode).mode
41 top: parent.top44 }
42 left: parent.left45 }
43 right: parent.right46
44 }47 ListModel {
4548 id: soundModel
46 HeaderListItem {49 Component.onCompleted: initialize()
47 id: mapModeHeader50 function initialize() {
48 title: i18n.tr("Navigation")51 soundModel.append({ "sound": i18n.tr("A Voice"), "index": 0 })
49 }52 soundModel.append({ "sound": i18n.tr("A Notification"), "index": 1 })
5053 soundModel.append({ "sound": i18n.tr("None"), "index": 2 })
51 ListItems.ItemSelector {54
52 id: modeList55 _soundList.subText.text = soundModel.get(navApp.settings.soundIndications).sound
53 text: i18n.tr("Mode:")56 }
54 width: parent.width57 }
55 anchors.horizontalCenter: parent.horizontalCenter58
5659 ListModel {
57 objectName: "modeList"60 id: unitModel
58 model: [i18n.tr("Car"), // index: 061 Component.onCompleted: initialize()
59 i18n.tr("Walking"), // index: 162 function initialize() {
60 i18n.tr("Bicycle") // index: 263 unitModel.append({ "unit": i18n.tr("Kilometres"), "index": 0 })
61 ]64 unitModel.append({ "unit": i18n.tr("Miles"), "index": 1 })
62 selectedIndex: navApp.settings.routingMode65
63 onSelectedIndexChanged: {66 _unitList.subText.text = unitModel.get(navApp.settings.unit).unit
64 if (navApp.settings.routingMode !== selectedIndex) {67 }
65 navApp.settings.routingMode = selectedIndex68 }
66 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no' && !nav.get_route_status().startsWith('simulate')){nav.set_route_status('waiting4signal')}; settings.set_routing_mode(" + selectedIndex +");")69
67 }70 Flickable {
68 }71 id: flickable
69 }72 anchors.fill: parent
7073 contentHeight: settingsColumn.height + units.gu(5)
71 ListItem {74
72 height: tollsLayout.height + divider.height75 Column {
73 ListItemLayout {76 id: settingsColumn
74 id: tollsLayout77
75 title.text: i18n.tr("Avoid Tolls")78 anchors {
76 Switch {79 top: parent.top
77 id: tollsSwitch80 left: parent.left
78 checked: navApp.settings.avoidTolls81 right: parent.right
79 onClicked: {82 }
80 navApp.settings.avoidTolls = checked;83
81 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no'){nav.set_route_status('waiting4signal')}; settings.set_avoid_tolls(" + checked.toString() + ");")84 ExpandableListItem {
82 }85 id: _modeList
83 SlotsLayout.position: SlotsLayout.Last86
84 }87 listViewHeight: units.gu(21)
85 }88 titleText.text: i18n.tr("Navigation Mode")
86 }89
87 90 model: navigationModeModel
88 ListItem {91
89 height: speedCameraLayout.height + divider.height92 delegate: ListItem {
90 ListItemLayout {93 ListItemLayout {
91 id: speedCameraLayout94 title.text: model.mode
92 title.text: i18n.tr("Speed Camera Alerts")95
93 Switch {96 Icon {
94 id: radarsSwitch97 SlotsLayout.position: SlotsLayout.Trailing
95 checked: navApp.settings.alertRadars98 width: units.gu(2)
96 onClicked: {99 height: width
97 navApp.settings.alertRadars = checked;100 name: "tick"
98 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no'){nav.set_route_status('waiting4signal')}; settings.set_alert_radars(" + checked.toString() + ");");101 visible: navApp.settings.routingMode === model.index
99 if (navApp.settings.legalRadarShow) {102 }
100 navApp.settings.legalRadarShow = false;103 }
101 PopupUtils.open(confirmEnableRadar);104
102 }105 onClicked: {
103 }106 navApp.settings.routingMode = model.index
104 SlotsLayout.position: SlotsLayout.Last107 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no' && !nav.get_route_status().startsWith('simulate')){nav.set_route_status('waiting4signal')}; settings.set_routing_mode(" + model.index +");")
105 }108 _modeList.subText.text = navigationModeModel.get(navApp.settings.routingMode).mode
106 }109 _modeList.toggleExpansion()
107 }110 }
108 111 }
109 ListItems.ItemSelector {112 }
110 id: soundsList113
111 text: i18n.tr("Indications:")114 ListItem {
112 width: parent.width115 visible: navApp.settings.routingMode === 0
113 anchors.horizontalCenter: parent.horizontalCenter116 height: tollsLayout.height + divider.height
114117 ListItemLayout {
115 objectName: "soundsList"118 id: tollsLayout
116 model: [i18n.tr("A Voice"), // index: 0119 title.text: i18n.tr("Avoid Tolls")
117 i18n.tr("A Notification"), // index: 1120 Switch {
118 i18n.tr("None") // index: 2121 id: tollsSwitch
119 ]122 checked: navApp.settings.avoidTolls
120 selectedIndex: navApp.settings.soundIndications123 onClicked: {
121 onSelectedIndexChanged: {124 navApp.settings.avoidTolls = checked;
122 navApp.settings.soundIndications = selectedIndex125 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no'){nav.set_route_status('waiting4signal')}; settings.set_avoid_tolls(" + checked.toString() + ");")
123 mainPageStack.executeJavaScript("settings.set_sound(" + selectedIndex + ");")126 }
124 }127 SlotsLayout.position: SlotsLayout.Last
125 }128 }
126129 }
127 HeaderListItem {130 }
128 id: mapListHeader131
129 title: i18n.tr("Map")132 ListItem {
130 }133 visible: navApp.settings.routingMode === 0
131134 height: speedCameraLayout.height + divider.height
132 ListItems.ItemSelector {135 ListItemLayout {
133 id: unitsList136 id: speedCameraLayout
134 text: i18n.tr("Units:")137 title.text: i18n.tr("Speed Camera Alerts")
135 width: parent.width138 Switch {
136 anchors.horizontalCenter: parent.horizontalCenter139 id: radarsSwitch
137140 checked: navApp.settings.alertRadars
138 objectName: "unitsList"141 onClicked: {
139 model: [i18n.tr("Kilometers"), // index: 0142 navApp.settings.alertRadars = checked;
140 i18n.tr("Miles") // index: 1143 mainPageStack.executeJavaScript("if (nav.get_route_status() != 'no'){nav.set_route_status('waiting4signal')}; settings.set_alert_radars(" + checked.toString() + ");");
141 ]144 if (navApp.settings.legalRadarShow) {
142 selectedIndex: navApp.settings.unit145 navApp.settings.legalRadarShow = false;
143 onSelectedIndexChanged: {146 PopupUtils.open(confirmEnableRadar);
144 navApp.settings.unit = selectedIndex147 }
145 mainPageStack.executeJavaScript("settings.set_unit(\'" + ( selectedIndex === 0 ? "km" : "mi" ) +"\');")148 }
146 mainPageStack.executeJavaScript("ui.set_scale_unit(\'" + ( navApp.settings.unit === 0 ? "km" : "mi" ) +"\');")149 SlotsLayout.position: SlotsLayout.Last
147 }150 }
148 }151 }
149152 }
150 HeaderListItem {153
151 id: privacyListHeader154 ExpandableListItem {
152 title: i18n.tr("History")155 id: _soundList
153 }156
154157 listViewHeight: units.gu(21)
155 ListItem {158 titleText.text: i18n.tr("Guidance")
156 height: storeSearchLayout.height + divider.height159
157 ListItemLayout {160 model: soundModel
158 id: storeSearchLayout161
159 title.text: i18n.tr("Store new searches")162 delegate: ListItem {
160 Switch {163 ListItemLayout {
161 id: saveHistorySwitch164 title.text: model.sound
162 checked: navApp.settings.saveHistory165
163 onClicked: navApp.settings.saveHistory = checked166 Icon {
164 SlotsLayout.position: SlotsLayout.Last167 SlotsLayout.position: SlotsLayout.Trailing
165 }168 width: units.gu(2)
166 }169 height: width
167 }170 name: "tick"
168171 visible: navApp.settings.soundIndications === model.index
169 ListItem {172 }
170 Label {173 }
171 anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(2) }174
172 text: i18n.tr("Clear History")175 onClicked: {
173 }176 navApp.settings.soundIndications = model.index
174 onClicked: PopupUtils.open(confirmEraseHistory)177 mainPageStack.executeJavaScript("settings.set_sound(" + model.index + ");")
175 }178 _soundList.subText.text = soundModel.get(navApp.settings.soundIndications).sound
176 }179 _soundList.toggleExpansion()
177 180 }
178 Component {181 }
179 id: confirmEraseHistory182 }
180 Dialog {183
181 id: dialogueErase184 HeaderListItem {
182 title: i18n.tr("Clear History")185 id: mapListHeader
183 text: i18n.tr("You'll delete the current history")186 title: i18n.tr("Map")
184 Button {187 }
185 text: i18n.tr("Delete")188
186 color: UbuntuColors.red189 ExpandableListItem {
187 onClicked: {190 id: _unitList
188 UnavDB.dropHistoryTables();191
189 PopupUtils.close(dialogueErase);192 listViewHeight: units.gu(14)
190 }193 titleText.text: i18n.tr("Units")
191 }194
192 Button {195 model: unitModel
193 text: i18n.tr("Cancel")196
194 onClicked: PopupUtils.close(dialogueErase)197 delegate: ListItem {
195 }198 ListItemLayout {
196 }199 title.text: model.unit
197 }200
198 201 Icon {
199 Component {202 SlotsLayout.position: SlotsLayout.Trailing
200 id: confirmEnableRadar203 width: units.gu(2)
201 Dialog {204 height: width
202 id: dialogueRadars205 name: "tick"
203 title: i18n.tr("Speed Camera alerts and the law")206 visible: navApp.settings.unit === model.index
204 text: i18n.tr("uNav is only reading the OpenStreetMap database.\nuNav will show a max speed notification and a Speed Camera marker (marker hidden for French users because of law).\n\nIn a few countries Speed Camera alerts are illegal, then enable this option only if it's legal in the country.\n\nRead more about it here:\n%1").arg("http://goo.gl/ulXvG8")207 }
205 Button {208 }
206 text: i18n.tr("OK")209
207 color: UbuntuColors.red210 onClicked: {
208 onClicked: PopupUtils.close(dialogueRadars);211 navApp.settings.unit = model.index
209 }212 mainPageStack.executeJavaScript("settings.set_unit(\'" + ( model.index === 0 ? "km" : "mi" ) +"\');")
210 }213 mainPageStack.executeJavaScript("ui.set_scale_unit(\'" + ( navApp.settings.unit === 0 ? "km" : "mi" ) +"\');")
211 }214 _unitList.subText.text = unitModel.get(navApp.settings.unit).unit
212 215 _unitList.toggleExpansion()
213 }216 }
217 }
218 }
219
220 HeaderListItem {
221 id: privacyListHeader
222 title: i18n.tr("History")
223 }
224
225 ListItem {
226 height: storeSearchLayout.height + divider.height
227 ListItemLayout {
228 id: storeSearchLayout
229 title.text: i18n.tr("Store new searches")
230 Switch {
231 id: saveHistorySwitch
232 checked: navApp.settings.saveHistory
233 onClicked: navApp.settings.saveHistory = checked
234 SlotsLayout.position: SlotsLayout.Last
235 }
236 }
237 }
238
239 ListItem {
240 Label {
241 anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(2) }
242 text: i18n.tr("Clear History")
243 }
244 onClicked: PopupUtils.open(confirmEraseHistory)
245 }
246 }
247
248 Component {
249 id: confirmEraseHistory
250 Dialog {
251 id: dialogueErase
252 title: i18n.tr("Clear History")
253 text: i18n.tr("You'll delete the current history")
254 Button {
255 text: i18n.tr("Delete")
256 color: UbuntuColors.red
257 onClicked: {
258 UnavDB.dropHistoryTables();
259 PopupUtils.close(dialogueErase);
260 }
261 }
262 Button {
263 text: i18n.tr("Cancel")
264 onClicked: PopupUtils.close(dialogueErase)
265 }
266 }
267 }
268
269 Component {
270 id: confirmEnableRadar
271 Dialog {
272 id: dialogueRadars
273 title: i18n.tr("Speed Camera alerts and the law")
274 text: i18n.tr("uNav is only reading the OpenStreetMap database.\nuNav will show a max speed notification and a Speed Camera marker (marker hidden for French users because of law).\n\nIn a few countries Speed Camera alerts are illegal, then enable this option only if it's legal in the country.\n\nRead more about it here:\n%1").arg("http://goo.gl/ulXvG8")
275 Button {
276 text: i18n.tr("OK")
277 color: UbuntuColors.red
278 onClicked: PopupUtils.close(dialogueRadars);
279 }
280 }
281 }
282
283 }
214}284}
215285
216286
=== added file 'qml/components/ExpandableListItem.qml'
--- qml/components/ExpandableListItem.qml 1970-01-01 00:00:00 +0000
+++ qml/components/ExpandableListItem.qml 2016-03-22 14:03:11 +0000
@@ -0,0 +1,87 @@
1/*
2 * uNav http://launchpad.net/unav
3 * Copyright (C) 2016 Nekhelesh Ramananthan https://launchpad.net/~nik90
4 *
5 * uNav is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * uNav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.4
19import Ubuntu.Components 1.3
20
21/*
22 Component which extends the SDK Expandable list item and provides a easy
23 to use component where the title, subtitle and a listview can be displayed. It
24 matches the design specification provided for clock.
25*/
26
27ListItem {
28 id: expandableListItem
29
30 // Public APIs
31 property ListModel model
32 property Component delegate
33 property alias titleText: expandableHeader.title
34 property alias subText: expandableHeader.subtitle
35 property alias listViewHeight: expandableListLoader.height
36
37 height: headerListItem.height
38 expansion.height: headerListItem.height + expandableListLoader.height
39 onClicked: toggleExpansion()
40
41 function toggleExpansion() {
42 expansion.expanded = !expansion.expanded
43 }
44
45 ListItem {
46 id: headerListItem
47 height: expandableHeader.height + divider.height
48
49 ListItemLayout {
50 id: expandableHeader
51
52 subtitle.textSize: Label.Medium
53
54 Icon {
55 id: arrow
56
57 width: units.gu(2)
58 height: width
59 SlotsLayout.position: SlotsLayout.Trailing
60 name: "go-down"
61 rotation: expandableListItem.expansion.expanded ? 180 : 0
62
63 Behavior on rotation {
64 UbuntuNumberAnimation {}
65 }
66 }
67 }
68 }
69
70 Loader {
71 id: expandableListLoader
72 width: parent.width
73 asynchronous: true
74 anchors.top: headerListItem.bottom
75 sourceComponent: expandableListItem.expansion.expanded ? expandableListComponent : undefined
76 }
77
78 Component {
79 id: expandableListComponent
80 ListView {
81 id: expandableList
82 interactive: false
83 model: expandableListItem.model
84 delegate: expandableListItem.delegate
85 }
86 }
87}

Subscribers

People subscribed via source and target branches