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