Fix init. Fix button enabling.
authorRuediger Gad <rgad@fb2.fh-frankfurt.de>
Sun, 15 Apr 2012 10:52:54 +0000 (12:52 +0200)
committerRuediger Gad <rgad@fb2.fh-frankfurt.de>
Sun, 15 Apr 2012 10:52:54 +0000 (12:52 +0200)
qml/QZeeControl/MainPage.qml

index 4021400..0032145 100644 (file)
@@ -25,6 +25,7 @@ import "settingsstorage.js" as SettingsStorage
 import qzeecontrol 1.0
 
 Page {
+    id: mainPage
     tools: commonTools
 
     orientationLock: PageOrientation.LockPortrait
@@ -77,11 +78,20 @@ Page {
         btConn.keyBindingRight = SettingsStorage.getSetting("Right")
     }
 
-    function updateConnectButton(){
-        if((addressField.text !== "No device found yet.") && deviceInfo.currentBluetoothPowerState){
-            connectButton.enabled = true
-            infoText.text = "Press \"Connect\" to connect to the device."
+    function updateConnectAndScanButton(){
+        if(!deviceInfo.currentBluetoothPowerState){
+            scanButton.enabled = false
+            connectButton.enabled = false
+            infoText.text = "To get started please turn Bluetooth on."
+            return
         }
+
+        scanButton.enabled = true
+        connectButton.enabled = (addressField.text !== "No device found yet.")
+        infoText = (addressField.text !== "No device found yet.") ?
+                    "To enable remote control please press \"Connect\" when ready." :
+                    "Please scan for a Zeemote first."
+
     }
 
     states: [
@@ -236,7 +246,7 @@ Page {
 
             Button{
                 id: scanButton
-                enabled: deviceInfo.currentBluetoothPowerState
+                enabled: false
 
                 anchors.horizontalCenter: parent.horizontalCenter
                 text: "Scan"
@@ -256,13 +266,13 @@ Page {
                     text: "No device found yet."
 
                     onTextChanged: {
-                        if(initializing)
+                        if(mainPage.initializing)
                             return
 
                         if(text === "No device found yet.")
                             return
 
-                        updateConnectButton();
+                        updateConnectAndScanButton();
 
                         console.log("Storing address in DB: " + text)
                         SettingsStorage.setSetting("address", text)
@@ -275,7 +285,7 @@ Page {
                     validator: IntValidator{}
 
                     onTextChanged: {
-                        if(initializing)
+                        if(mainPage.initializing)
                             return
 
                         if(text === "na")
@@ -381,7 +391,7 @@ Page {
         monitorBluetoothStateChanges: true
 
         onBluetoothStateChanged: {
-            updateConnectButton()
+            updateConnectAndScanButton()
         }
     }