17f91545759d9fd0deae2f6ea8e1d81b33dd28fb
[googlelatitude] / qml / MainPage.qml
1 import QtQuick 1.0
2 import com.meego 1.0
3
4 Page {
5     id: mainPage
6     Column {
7         spacing: 16
8         Row {
9             width: rootWindow.width
10             Button {
11                 id: do_auth
12                 width: rootWindow.width / 3
13                 text: "Auth"
14                 enabled: false
15                 onClicked: {
16                     Qt.openUrlExternally(latitude.getUserAuthorization())
17                 }
18             }
19             Button {
20                 id: do_start
21                 width: rootWindow.width / 3
22                 text: "Start"
23                 enabled: false
24                 onClicked: {
25                     do_start.enabled = false;
26                     do_stop.enabled = true;
27                     gps.startUpdates()
28                 }
29             }
30             Button {
31                 id: do_stop
32                 width: rootWindow.width / 3
33                 text: "Stop"
34                 enabled: false
35                 onClicked: {
36                     do_start.enabled = true;
37                     do_stop.enabled = false;
38                     gps.stopUpdates(true)
39                 }
40             }
41         }
42         Row {
43             width: rootWindow.width
44             Label {
45                 id: pos_label
46                 text: "Position"
47                 width: rootWindow.width / 4
48                 anchors.verticalCenter: position.verticalCenter
49             }
50             Row {
51                 id: position
52                 width: rootWindow.width * 3 / 4
53                 TextField  {
54                     id: pos_lat
55                     width: parent / 4
56                     placeholderText: "pos_lat"
57                     readOnly: true
58                 }
59                 TextField {
60                     id: pos_lon
61                     width: parent / 4
62                     placeholderText: "pos_lon"
63                     readOnly: true
64                 }
65                 TextField {
66                     id: pos_acc
67                     width: parent / 4
68                     placeholderText: "pos_acc"
69                     readOnly: true
70                 }
71                 TextField {
72                     id: pos_tis
73                     width: parent / 4
74                     placeholderText: "pos_tis"
75                     readOnly: true
76                 }
77             }
78         }
79         Row {
80             Label {
81                 id: method_label
82                 text: "Method"
83                 width: rootWindow.width / 4
84                 anchors.verticalCenter: method_button.verticalCenter
85             }
86             ButtonRow {
87                 id: method_button
88                 width: rootWindow.width * 2 / 3
89                 Button {
90                     id: method_cell
91                     text: "Cell Tower"
92                     checked: gps.getPositioningMethod() == "cell" ? true : false
93                     onClicked: gps.setPositioningMethod("cell")
94                 }
95                 Button {
96                     id: method_all
97                     text: "Both"
98                     checked: gps.getPositioningMethod() == "all" ? true : false
99                     onClicked: gps.setPositioningMethod("all")
100                 }
101                 Button {
102                     id: method_agps
103                     text: "Only GPS"
104                     checked: gps.getPositioningMethod() == "gps" ? true : false
105                     onClicked: gps.setPositioningMethod("gps")
106                 }
107             }
108         }
109         Row {
110             Label {
111                 id: timeout_label
112                 text: "Time Out"
113                 width: rootWindow.width / 4
114                 anchors.verticalCenter: timeout_slider.verticalCenter
115             }
116             Slider {
117                 id: timeout_slider
118                 width: rootWindow.width / 2
119                 valueIndicatorVisible: true
120                 minimumValue: 5
121                 maximumValue: 120
122                 stepSize: 5
123                 value: gps.getTimeOut()
124             }
125             Label {
126                 id: timeout_value
127                 text: timeout_slider.value + " seg."
128                 width: rootWindow.width / 4
129                 anchors.verticalCenter: timeout_slider.verticalCenter
130             }
131             Connections {
132                 target: timeout_slider
133                 onValueChanged: {
134                     timeout_value.text = timeout_slider.value + " seg."
135                     gps.setTimeOut(timeout_slider.value)
136                 }
137             }
138         }
139         Row {
140             Label {
141                 id: interval_label
142                 text: "Interval"
143                 width: rootWindow.width / 4
144                 anchors.verticalCenter: interval_slider.verticalCenter
145             }
146             Slider {
147                 id: interval_slider
148                 width: rootWindow.width / 2
149                 valueIndicatorVisible: true
150                 minimumValue: 5
151                 maximumValue: 60
152                 stepSize: 5
153                 value: gps.getInterval() / 60
154             }
155             Label {
156                 id: interval_value
157                 text:  interval_slider.value + " min."
158                 width: rootWindow.width / 4
159                 anchors.verticalCenter: interval_slider.verticalCenter
160             }
161             Connections {
162                 target: interval_slider
163                 onValueChanged: {
164                     interval_value.text = interval_slider.value + " min."
165                     gps.setInterval(interval_slider.value*60)
166                 }
167             }
168         }
169         Row {
170             Label {
171                 id: connect_label
172                 text: "Auto Connect"
173                 width: rootWindow.width / 4
174                 anchors.verticalCenter: connect_switch.verticalCenter
175             }
176             Switch {
177                 id: connect_switch
178                 width: rootWindow.width / 2
179                 checked: latitude.getAutoConnect() ? true : false
180                 onCheckedChanged: {
181                     connect_value.text = checked
182                     latitude.setAutoConnect(checked)
183                 }
184             }
185             Label {
186                 id: connect_value
187                 text:  connect_switch.checked
188                 width: rootWindow.width / 4
189                 anchors.verticalCenter: connect_switch.verticalCenter
190             }
191         }
192
193         Connections {
194             target: latitude
195             onGotToken: {
196                 do_auth.enabled = false;
197                 do_start.enabled = true;
198                 do_stop.enabled = false;
199             }
200         }
201         Connections {
202             target: latitude
203             onNotToken: {
204                 do_auth.enabled = true;
205                 do_start.enabled = false;
206                 do_stop.enabled = false;
207                 gps.stopUpdates(true)
208             }
209         }
210         Connections {
211             target: latitude
212             onNeedAuth: {
213                 do_auth.enabled = true;
214             }
215         }
216
217         Connections {
218             target: gps
219             onGotUpdate: {
220                 pos_lat.text = gps.getCurrentLatitude()
221                 pos_lon.text = gps.getCurrentLongitude()
222                 pos_acc.text = gps.getCurrentAccuracy()
223                 pos_tis.text = gps.getCurrentTimestamp()
224             }
225         }
226         Connections {
227             target: gps
228             onGotFix: {
229                 pos_lat.text = gps.getCurrentLatitude()
230                 pos_lon.text = gps.getCurrentLongitude()
231                 pos_acc.text = gps.getCurrentAccuracy()
232                 pos_tis.text = gps.getCurrentTimestamp()
233                 latitude.setCurrentLocation(pos_lat.text, pos_lon.text, pos_acc.text)
234                 latitude.sendCurrentLocation()
235             }
236         }
237     }
238 }