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