Unity 8
40-location.qml
1 /*
2  * Copyright (C) 2013-2016 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 as published by
6  * the Free Software Foundation; version 3.
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 
17 import QtQuick 2.4
18 import AccountsService 0.1
19 import QMenuModel 0.1 as QMenuModel
20 import Qt.labs.folderlistmodel 2.1
21 import Ubuntu.Components 1.3
22 import ".." as LocalComponents
23 
24 LocalComponents.Page {
25  objectName: "locationPage"
26 
27  title: i18n.tr("Location Services")
28  forwardButtonSourceComponent: forwardButton
29 
30  readonly property bool pathSet: AccountsService.hereLicensePathValid
31  skipValid: pathSet && (AccountsService.hereLicensePath === "" || termsModel.count > 0)
32  skip: skipValid && (AccountsService.hereLicensePath === "" || termsModel.count === 2) // no files but . and ..
33 
34  FolderListModel {
35  id: termsModel
36  folder: AccountsService.hereLicensePath
37  nameFilters: ["*.html"]
38  showOnlyReadable: true
39  showDotAndDotDot: true // so that count == 0 means we're not done scanning yet
40  }
41 
42  QMenuModel.QDBusActionGroup {
43  id: locationActionGroup
44  objectName: "locationActionGroup"
45  busType: QMenuModel.DBus.SessionBus
46  busName: "com.canonical.indicator.location"
47  objectPath: "/com/canonical/indicator/location"
48  property variant location: action("location-detection-enabled")
49  property variant gps: action("gps-detection-enabled")
50  Component.onCompleted: start()
51  }
52 
53  Item {
54  id: column
55  anchors.fill: content
56  anchors.topMargin: customMargin
57  anchors.leftMargin: wideMode ? parent.leftMargin : 0
58  anchors.rightMargin: wideMode ? parent.rightMargin : 0
59 
60  Item {
61  id: hereCheckGroup
62  anchors {
63  left: parent.left
64  right: parent.right
65  top: parent.top
66  }
67  height: hereCheckLabel.height + hereTermsLabel.height
68 
69  Label {
70  id: hereCheckLabel
71  objectName: "hereCheckLabel"
72  anchors {
73  left: parent.left
74  right: hereTermsCheck.left
75  top: parent.top
76  leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
77  rightMargin: units.gu(2)
78  }
79  lineHeight: 1.2
80  wrapMode: Text.WordWrap
81  color: textColor
82  font.weight: checked ? Font.Normal : Font.Light
83  text: i18n.tr("Use GPS, Wi-Fi hotspots and mobile network anonymously to detect location (recommended)")
84  property bool checked: true
85  }
86 
87  Label {
88  id: hereTermsLabel
89  objectName: "hereTermsLabel"
90  anchors {
91  left: parent.left
92  right: hereTermsCheck.left
93  top: hereCheckLabel.bottom
94  topMargin: units.gu(1)
95  leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
96  rightMargin: units.gu(2)
97  }
98 
99  wrapMode: Text.WordWrap
100  color: textColor
101  font.weight: Font.Light
102  fontSize: "small"
103  lineHeight: 1.2
104  linkColor: UbuntuColors.orange
105  text: i18n.tr("By selecting this option you agree to the Nokia HERE %1.")
106  .arg("<a href='#'>" + i18n.ctr("part of: Nokia HERE terms and conditions", "terms and conditions") + "</a>")
107  Mouse.forwardTo: hereCheckArea // clicking on the link also selects this group
108  Mouse.priority: Mouse.AfterItem
109  onLinkActivated: {
110  pageStack.load(Qt.resolvedUrl("here-terms.qml"));
111  }
112  }
113 
114  Image {
115  id: hereTermsCheck
116  fillMode: Image.PreserveAspectFit
117  height: units.gu(1.5)
118  source: "data/Tick@30.png"
119  opacity: hereCheckLabel.checked ? 1 : 0
120  anchors.right: parent.right
121  anchors.verticalCenter: hereCheckLabel.verticalCenter
122  anchors.rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
123  }
124 
125  MouseArea {
126  id: hereCheckArea
127  anchors.fill: parent
128  z: hereCheckGroup.z - 1 // so that the link can be activated
129  onClicked: {
130  if (!hereCheckLabel.checked) {
131  hereCheckLabel.checked = true;
132  gpsCheckLabel.checked = false;
133  nopeCheckLabel.checked = false;
134  }
135  }
136  }
137  }
138 
139  Rectangle {
140  id: divider
141  anchors.left: parent.left
142  anchors.right: parent.right
143  anchors.top: hereCheckGroup.bottom
144  anchors.topMargin: units.gu(3)
145  height: units.dp(1)
146  color: dividerColor
147  }
148 
149  Label {
150  id: gpsCheckLabel
151  objectName: "gpsCheckLabel"
152  anchors {
153  left: parent.left
154  right: parent.right
155  top: divider.bottom
156  topMargin: units.gu(3)
157  leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
158  rightMargin: units.gu(2)
159  }
160  text: i18n.tr("GPS only")
161  wrapMode: Text.WordWrap
162  color: textColor
163  font.weight: checked ? Font.Normal : Font.Light
164  width: content.width
165  property bool checked: false
166 
167  MouseArea {
168  anchors.fill: parent
169  onClicked: {
170  if (!gpsCheckLabel.checked) {
171  hereCheckLabel.checked = false;
172  gpsCheckLabel.checked = true;
173  nopeCheckLabel.checked = false;
174  }
175  }
176  }
177  }
178 
179  Image {
180  fillMode: Image.PreserveAspectFit
181  height: units.gu(1.5)
182  source: "data/Tick@30.png"
183  opacity: gpsCheckLabel.checked ? 1 : 0
184  anchors.right: parent.right
185  anchors.verticalCenter: gpsCheckLabel.verticalCenter
186  anchors.rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
187  }
188 
189  Rectangle {
190  id: divider2
191  anchors.left: parent.left
192  anchors.right: parent.right
193  anchors.top: gpsCheckLabel.bottom
194  anchors.topMargin: units.gu(3)
195  height: units.dp(1)
196  color: dividerColor
197  }
198 
199  Label {
200  id: nopeCheckLabel
201  objectName: "nopeCheckLabel"
202  anchors {
203  left: parent.left
204  right: parent.right
205  top: divider2.bottom
206  topMargin: units.gu(3)
207  leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
208  rightMargin: units.gu(2)
209  }
210  wrapMode: Text.WordWrap
211  color: textColor
212  font.weight: checked ? Font.Normal : Font.Light
213  width: content.width
214  text: i18n.tr("Don't use my location")
215  property bool checked: false
216 
217  MouseArea {
218  anchors.fill: parent
219  onClicked: {
220  if (!nopeCheckLabel.checked) {
221  hereCheckLabel.checked = false;
222  gpsCheckLabel.checked = false;
223  nopeCheckLabel.checked = true;
224  }
225  }
226  }
227  }
228 
229  Image {
230  fillMode: Image.PreserveAspectFit
231  height: units.gu(1.5)
232  source: "data/Tick@30.png"
233  opacity: nopeCheckLabel.checked ? 1 : 0
234  anchors.right: parent.right
235  anchors.verticalCenter: nopeCheckLabel.verticalCenter
236  anchors.rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
237  }
238 
239  Rectangle {
240  id: divider3
241  anchors.left: parent.left
242  anchors.right: parent.right
243  anchors.top: nopeCheckLabel.bottom
244  anchors.topMargin: units.gu(3)
245  height: units.dp(1)
246  color: dividerColor
247  }
248 
249  Label {
250  id: infoLabel
251  anchors {
252  left: parent.left
253  right: parent.right
254  top: divider3.bottom
255  topMargin: units.gu(4)
256  leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
257  rightMargin: column.anchors.rightMargin == 0 ? staticMargin : 0
258  }
259  wrapMode: Text.Wrap
260  text: i18n.tr("You can change it later in System Settings.")
261  color: textColor
262  fontSize: "small"
263  font.weight: Font.Light
264  width: content.width
265  }
266  }
267 
268  Component {
269  id: forwardButton
270  LocalComponents.StackButton {
271  text: i18n.tr("Next")
272  onClicked: {
273  var locationOn = gpsCheckLabel.checked || hereCheckLabel.checked;
274  var gpsOn = gpsCheckLabel.checked || hereCheckLabel.checked;
275  var hereOn = hereCheckLabel.checked;
276 
277  // location service doesn't currently listen to updateState
278  // requests, so we activate the actions if needed.
279  if (locationActionGroup.location.state != locationOn) {
280  locationActionGroup.location.activate();
281  }
282  if (locationActionGroup.gps.state != gpsOn) {
283  locationActionGroup.gps.activate();
284  }
285  AccountsService.hereEnabled = hereOn;
286  pageStack.next();
287  }
288  }
289  }
290 }