Work in progress: hacks at vienna, do not use it
[googlelatitude] / latitude.qml / MainPage.qml
index caeb84f..8916389 100644 (file)
@@ -1,45 +1,32 @@
-import QtQuick 1.0
-import com.meego 1.0
+import QtQuick 1.1
+import com.nokia.meego 1.0
+import QtWebKit 1.0
 
 Page {
     id: mainPage
-    orientationLock: PageOrientation.LockLandscape
+    orientationLock: PageOrientation.LockPortrait
     Column {
         spacing: 16
         Row {
-            width: rootWindow.width
+//            width: rootWindow.width
             Button {
-                id: do_auth
+                id: do_staff
                 width: rootWindow.width / 3
-                text: "Auth"
+                text: "..."
                 enabled: false
                 onClicked: {
-                    Qt.openUrlExternally(latitude.getUserAuthorization())
-                }
-            }
-            Button {
-                id: do_start
-                width: rootWindow.width / 3
-                text: "Start"
-                enabled: false
-                onClicked: {
-                    do_start.enabled = false;
-                    do_stop.enabled = true;
-                    if (!demonio.demonio_start()) {
-                        gps.startUpdates()
-                    }
-                }
-            }
-            Button {
-                id: do_stop
-                width: rootWindow.width / 3
-                text: "Stop"
-                enabled: false
-                onClicked: {
-                    do_start.enabled = true;
-                    do_stop.enabled = false;
-                    if (!demonio.demonio_stop()) {
-                        gps.stopUpdates(true)
+                    if (text.match("Start")) {
+                        console.log("match start")
+                        if (!demonio.demonio_start()) {
+                            gps.startUpdates()
+                        }
+                        text = "Stop"
+                    } else if (text.match("Stop")) {
+                        console.log("match stop")
+                        if (!demonio.demonio_stop()) {
+                            gps.stopUpdates(true)
+                        }
+                        text = "Start"
                     }
                 }
             }
@@ -48,12 +35,12 @@ Page {
             Label {
                 id: method_label
                 text: "Method"
-                width: rootWindow.width / 4
+                width: mainPage.width / 4
                 anchors.verticalCenter: method_button.verticalCenter
             }
-            ButtonRow {
+            ButtonColumn {
                 id: method_button
-                width: rootWindow.width * 2 / 3
+                width: mainPage.width * 1 / 3
                 Button {
                     id: method_cell
                     text: "Cell Tower"
@@ -83,7 +70,7 @@ Page {
             }
             Slider {
                 id: timeout_slider
-                width: rootWindow.width / 2
+                width: rootWindow.width / 4
                 valueIndicatorVisible: true
                 minimumValue: 5
                 maximumValue: 120
@@ -113,7 +100,7 @@ Page {
             }
             Slider {
                 id: interval_slider
-                width: rootWindow.width / 2
+                width: rootWindow.width / 4
                 valueIndicatorVisible: true
                 minimumValue: 5
                 maximumValue: 60
@@ -143,7 +130,7 @@ Page {
             }
             Switch {
                 id: connect_switch
-                width: rootWindow.width / 2
+                width: rootWindow.width / 4
                 checked: latitude.getAutoConnect() ? true : false
                 onCheckedChanged: {
                     connect_value.text = checked
@@ -157,35 +144,58 @@ Page {
                 anchors.verticalCenter: connect_switch.verticalCenter
             }
         }
+        Row {
+            Label {
+                id: daemon_label
+                text: "Daemon at boot time"
+                width: rootWindow.width / 4
+                anchors.verticalCenter: daemon_switch.verticalCenter
+            }
+            Switch {
+                id: daemon_switch
+                width: rootWindow.width / 4
+                checked: latitude.getDaemonMode() ? true : false
+                onCheckedChanged: {
+                    daemon_value.text = checked
+                    latitude.setDaemonMode(checked)                }
+            }
+            Label {
+                id: daemon_value
+                text:  daemon_switch.checked
+                width: rootWindow.width / 4
+                anchors.verticalCenter: daemon_switch.verticalCenter
+            }
+        }
 
         Connections {
             target: latitude
             onGotToken: {
-                do_auth.enabled = false;
                 if (demonio.demonio_status()) {
-                    do_start.enabled = false;
-                    do_stop.enabled = true;
+                    do_staff.text = "Stop"
+                    do_staff.enabled = true;
                 } else {
-                    do_start.enabled = true;
-                    do_stop.enabled = false;
+                    do_staff.text = "Start"
+                    do_staff.enabled = true;
                 }
+                pageStack.pop(login)
             }
         }
+
         Connections {
             target: latitude
             onNotToken: {
-                do_auth.enabled = true;
-                do_start.enabled = false;
-                do_stop.enabled = false;
+                do_staff.text = "..."
+                do_staff.enabled = false;
                 if (!demonio.demonio_stop()) {
                     gps.stopUpdates(true)
                 }
+                latitude.getAccess()
             }
         }
         Connections {
             target: latitude
             onNeedAuth: {
-                do_auth.enabled = true;
+                pageStack.push(login)
             }
         }
 
@@ -199,4 +209,35 @@ Page {
             }
         }
     }
+
+    Component {
+        id: login
+        Page {
+            orientationLock: PageOrientation.LockPortrait
+            Flickable {
+                id: flickable
+                width: parent.width
+                height: parent.height
+                contentWidth: webView.width
+                contentHeight: webView.height
+                WebView {
+                    id: webView
+                    url: latitude.getUserAuthorization()
+                    preferredWidth: parent.width
+                    preferredHeight: parent.height
+                    onLoadFinished: {
+                        console.log(url)
+                        flickable.contentY = 0;
+                        if (url.toString().match("ServiceLogin")) {
+                            console.log("* QML WebView go w/2,0")
+                            flickable.contentX = width/2;
+                        } else {
+                            console.log("* QML WebView go 0,0")
+                            flickable.contentX = 0;
+                        }
+                    }
+                }
+            }
+        }
+    }
 }