Unity 8
50-location.qml
1 /*
2  * Copyright (C) 2013-2015 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")
28  forwardButtonSourceComponent: forwardButton
29 
30  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  Column {
54  id: column
55  anchors.fill: content
56  spacing: units.gu(3)
57 
58  Label {
59  anchors.left: parent.left
60  anchors.right: parent.right
61  wrapMode: Text.Wrap
62  text: i18n.tr("Let the phone detect your location:")
63  }
64 
65  LocalComponents.CheckableSetting {
66  id: gpsCheck
67  objectName: "gpsCheck"
68  showDivider: false
69  text: i18n.tr("Using GPS only (less accurate)")
70  onTriggered: {
71  gpsCheck.checked = true;
72  hereCheck.checked = false;
73  nopeCheck.checked = false;
74  }
75  }
76 
77  Column {
78  anchors.left: parent.left
79  anchors.right: parent.right
80  height: childrenRect.height
81 
82  LocalComponents.CheckableSetting {
83  id: hereCheck
84  objectName: "hereCheck"
85  showDivider: false
86  text: i18n.tr("Using GPS, anonymized Wi-Fi and cellular network info (recommended)")
87  checked: true
88  onTriggered: {
89  gpsCheck.checked = false;
90  hereCheck.checked = true;
91  nopeCheck.checked = false;
92  }
93  }
94 
95  Label {
96  objectName: "hereTermsLink"
97  anchors.left: parent.left
98  anchors.leftMargin: hereCheck.labelOffset
99  anchors.right: parent.right
100  wrapMode: Text.Wrap
101  linkColor: theme.palette.normal.foregroundText
102  // Translators: HERE is a trademark for Nokia's location service, you probably shouldn't translate it
103  text: i18n.tr("By selecting this option you agree to the Nokia HERE <a href='#'>terms and conditions</a>.")
104  onLinkActivated: pageStack.load(Qt.resolvedUrl("here-terms.qml"))
105  }
106  }
107 
108  LocalComponents.CheckableSetting {
109  id: nopeCheck
110  objectName: "nopeCheck"
111  showDivider: false
112  text: i18n.tr("Not at all")
113  onTriggered: {
114  gpsCheck.checked = false;
115  hereCheck.checked = false;
116  nopeCheck.checked = true;
117  }
118  }
119 
120  Label {
121  anchors.left: parent.left
122  anchors.right: parent.right
123  wrapMode: Text.Wrap
124  text: i18n.tr("You can change your mind later in <b>System Settings</b>.")
125  }
126  }
127 
128  Component {
129  id: forwardButton
130  LocalComponents.StackButton {
131  text: i18n.tr("Continue")
132  onClicked: {
133  var locationOn = gpsCheck.checked || hereCheck.checked;
134  var gpsOn = gpsCheck.checked || hereCheck.checked;
135  var hereOn = hereCheck.checked;
136 
137  // location service doesn't currently listen to updateState
138  // requests, so we activate the actions if needed.
139  if (locationActionGroup.location.state != locationOn) {
140  locationActionGroup.location.activate();
141  }
142  if (locationActionGroup.gps.state != gpsOn) {
143  locationActionGroup.gps.activate();
144  }
145  AccountsService.hereEnabled = hereOn;
146  pageStack.next()
147  }
148  }
149  }
150 }