import QtQuick 1.1
import com.nokia.meego 1.0
import QtMobility.connectivity 1.2
+import QtMobility.systeminfo 1.2
+import "settingsstorage.js" as SettingsStorage
import qzeecontrol 1.0
Page {
+ id: mainPage
tools: commonTools
- Label {
- id: label
- anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ orientationLock: PageOrientation.LockPortrait
- text: "Press to connect."
- }
+ property bool initializing: true
- Button{
- id: connectButton
- anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ Component.onCompleted: {
+ SettingsStorage.initialize();
- text: "Connect"
+ var address = SettingsStorage.getSetting("address");
+ var port = SettingsStorage.getSetting("port");
+ if(address !== "Unknown" && port !== "Unknown"){
+ console.log("Loaded address " + address + " and port " + port + " from DB.")
+ addressField.text = address
+ portField.text = port
+ }
- onClicked: {
- btDiscovery.discovery = true
+ if(SettingsStorage.getSetting("A") === "Unknown"){
+ console.log("Initializing key bindings.")
+ setKeyBindingsToDefault()
}
+
+ loadKeyBindings()
+ updateConnectAndScanButton()
+ initializing = false
}
- Button{
- id: disconnectButton
- anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+ function setKeyBindingsToDefault(){
+ console.log("Setting key bindings to default.")
+ SettingsStorage.setSetting("A", "a")
+ SettingsStorage.setSetting("B", "b")
+ SettingsStorage.setSetting("C", "c")
+ SettingsStorage.setSetting("D", "d")
- text: "Disconnect"
+ SettingsStorage.setSetting("Up", "Up")
+ SettingsStorage.setSetting("Down", "Down")
+ SettingsStorage.setSetting("Left", "Left")
+ SettingsStorage.setSetting("Right", "Right")
+ }
- onClicked: {
- btConn.disconnect()
- }
+ function loadKeyBindings(){
+ console.log("Loading key bindings.")
+ zeeRemoteControl.keyBindingA = SettingsStorage.getSetting("A")
+ zeeRemoteControl.keyBindingB = SettingsStorage.getSetting("B")
+ zeeRemoteControl.keyBindingC = SettingsStorage.getSetting("C")
+ zeeRemoteControl.keyBindingD = SettingsStorage.getSetting("D")
+
+ zeeRemoteControl.keyBindingUp = SettingsStorage.getSetting("Up")
+ zeeRemoteControl.keyBindingDown = SettingsStorage.getSetting("Down")
+ zeeRemoteControl.keyBindingLeft = SettingsStorage.getSetting("Left")
+ zeeRemoteControl.keyBindingRight = SettingsStorage.getSetting("Right")
}
- Row{
- id: buttonRow
- anchors.centerIn: parent
- spacing: 20
+ function updateConnectAndScanButton(){
+ if(!deviceInfo.currentBluetoothPowerState){
+ scanButton.enabled = false
+ connectButton.enabled = false
+
+ addressField.enabled = false
+ portField.enabled = false
- Label{
- id: labelA
- text: "A"
- color: "blue"
+ infoText.text = "To get started please turn Bluetooth on."
+ return
}
- Label{
- id: labelB
- text: "B"
- color: "blue"
+
+ scanButton.enabled = true
+
+ addressField.enabled = true
+ portField.enabled = true
+
+ connectButton.enabled = (addressField.text !== "No Zeemote found yet.")
+ infoText.text = (addressField.text !== "No Zeemote found yet.") ?
+ "To enable remote control please press \"Connect\" when ready." :
+ "Please scan for a Zeemote first."
+ }
+
+ states: [
+ State {
+ name: "active"
+ PropertyChanges {
+ target: cursorRectangle
+ x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
+ }
+ PropertyChanges {
+ target: labelA
+ color: zeeRemoteControl.a ? "red" : "blue"
+ }
+ PropertyChanges {
+ target: labelB
+ color: zeeRemoteControl.b ? "red" : "blue"
+ }
+ PropertyChanges {
+ target: labelC
+ color: zeeRemoteControl.c ? "red" : "blue"
+ }
+ PropertyChanges {
+ target: labelD
+ color: zeeRemoteControl.d ? "red" : "blue"
+ }
+ },
+ State {
+ name: "inactive"
+ PropertyChanges {
+ target: cursorRectangle
+ x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
+ }
+ PropertyChanges {
+ target: labelA
+ color: "blue"
+ }
+ PropertyChanges {
+ target: labelB
+ color: "blue"
+ }
+ PropertyChanges {
+ target: labelC
+ color: "blue"
+ }
+ PropertyChanges {
+ target: labelD
+ color: "blue"
+ }
}
- Label{
- id: labelC
- text: "C"
- color: "blue"
+ ]
+
+ Connections {
+ target: platformWindow
+
+ onActiveChanged: {
+ if(platformWindow.active){
+ state = "active"
+ }else{
+ state = "inactive"
+ }
}
- Label{
- id: labelD
- text: "D"
- color: "blue"
+ }
+
+ Item {
+ id: headerItem
+ anchors{top: parent.top; left: parent.left; right: parent.right}
+ height: header.height
+ z: 1
+
+ Image {
+ id: header
+ height: 72
+ source: "image://theme/color8-meegotouch-view-header-fixed"
+ anchors.fill: parent
+
+ Text {
+ text: "QZeeControl"
+ color: "white"
+ font.family: "Nokia Pure Text Light"
+ font.pixelSize: 32
+ anchors.left: parent.left
+ anchors.leftMargin: 20
+ anchors.verticalCenter: parent.verticalCenter
+ }
}
}
- Rectangle{
- id: moveArea
- anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
- color: "gray"
+ Flickable {
+ anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
+ contentHeight: contentColumn.height
+
+ Column{
+ id: contentColumn
+ spacing: 10
+ anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
+
+ Button{
+ id: scanButton
+ enabled: false
+
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: "Scan"
+
+ onClicked: {
+ btDiscovery.discovery = true
+ }
+ }
+
+ Row{
+ id: addressRow
+ anchors.horizontalCenter: parent.horizontalCenter
+ spacing: 5
+
+ TextField{
+ id: addressField
+ text: "No Zeemote found yet."
+ width: 280
+
+ onTextChanged: {
+ if(mainPage.initializing)
+ return
+
+ if(text === "No Zeemote found yet.")
+ return
+
+ updateConnectAndScanButton();
+
+ console.log("Storing address in DB: " + text)
+ SettingsStorage.setSetting("address", text)
+ }
+ }
+ TextField{
+ id: portField
+ text: "na"
+ width: 60
+ validator: IntValidator{}
+
+ onTextChanged: {
+ if(mainPage.initializing)
+ return
- width: 256
- height: 256
+ if(text === "na")
+ return
+
+ console.log("Storing port in DB: " + text)
+ SettingsStorage.setSetting("port", text)
+ }
+ }
+ }
+
+ Label {
+ id: infoText
+ width: parent.width
+
+ horizontalAlignment: Text.AlignHCenter
+ wrapMode: Text.WordWrap
+ }
+
+ Button{
+ id: connectButton
+ anchors.horizontalCenter: parent.horizontalCenter
+ enabled: false
+
+ text: "Connect"
+
+ onClicked: {
+ scanButton.enabled = false
+ addressField.enabled = false
+ portField.enabled = false
+ connectButton.enabled = false
+ disconnectButton.enabled = false
+ infoText.text = "Connecting..."
+
+ zeeRemoteControl.connect(addressField.text, parseInt(portField.text))
+ }
+ }
+
+ Button{
+ id: disconnectButton
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ text: "Disconnect"
+
+ onClicked: {
+ zeeRemoteControl.disconnect()
+ }
+ }
+
+ Row{
+ id: buttonRow
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ spacing: 20
+
+ Label{
+ id: labelA
+ text: "A"
+ color: zeeRemoteControl.a ? "red" : "blue"
+ }
+ Label{
+ id: labelB
+ text: "B"
+ color: zeeRemoteControl.b ? "red" : "blue"
+ }
+ Label{
+ id: labelC
+ text: "C"
+ color: zeeRemoteControl.c ? "red" : "blue"
+ }
+ Label{
+ id: labelD
+ text: "D"
+ color: zeeRemoteControl.d ? "red" : "blue"
+ }
+ }
+
+ Item{
+ id: testArea
+ anchors.horizontalCenter: parent.horizontalCenter
+ height: moveArea.height
+ width: moveArea.width
+
+ Rectangle{
+ id: moveArea
+ color: "gray"
+
+ width: 256
+ height: 256
+ }
+
+ Rectangle{
+ id: cursorRectangle
+ width: 10
+ height: 10
+ color: "red"
+
+ x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+ y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
+ }
+ }
+ }
}
- Rectangle{
- id: cursorRectangle
- width: 10
- height: 10
- color: "red"
+ DeviceInfo{
+ id: deviceInfo
- x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
- y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
+ monitorBluetoothStateChanges: true
+
+ onBluetoothStateChanged: {
+ updateConnectAndScanButton()
+ }
}
BluetoothDiscoveryModel{
minimalDiscovery: true
onDiscoveryChanged: {
+ if(initializing)
+ return
+
if(discovery){
- label.text = "Scanning for devices..."
+ infoText.text = "Scanning for a Zeemote..."
+ scanButton.enabled = false
connectButton.enabled = false
disconnectButton.enabled = false
+ addressField.enabled = false
+ portField.enabled = false
}else{
- connectButton.enabled = true
+ scanButton.enabled = true
disconnectButton.enabled = false
+ addressField.enabled = true
+ portField.enabled = true
+
+ if(addressField.text !== "No Zeemote found yet." && portField.text !== "na"){
+ infoText.text = "Zeemote found. To enable remote control please press \"Connect\" when ready."
+ connectButton.enabled = true
+ }
}
}
onNewServiceDiscovered: {
- console.log("Service " + service.serviceName + " found on " + service.deviceName + " at address " + service.deviceAddress + " on port " + service.servicePort + ".")
- //btSocket.service = service
- btConn.connect(service.deviceAddress, service.servicePort)
+ console.log("Service " + service.serviceName + " found on "
+ + service.deviceName + " at address " + service.deviceAddress
+ + " on port " + service.servicePort + ".")
+ if(service.serviceName === "Zeemote"){
+ addressField.text = service.deviceAddress
+ portField.text = service.servicePort
+ discovery = false
+ console.log("Found Zeemote. Stopped further discovery.")
+ }
}
}
- /*
- BluetoothSocket{
- id: btSocket
+ ZeeRemoteControl{
+ id: zeeRemoteControl
- onDataAvailable: {
- console.log("Data available: " + stringData.charCodeAt(0) + data)
- }
-
- onServiceChanged: {
- console.log("Service changed. Connecting...")
- connected = true
- }
-
- onConnectedChanged: {
- console.log("Connected.")
- }
- }*/
-
- BtConnector{
- id: btConn
+ threshold: 50
onConnected: {
- connectButton.enabled = false
disconnectButton.enabled = true
- label.text = "Connected."
+ infoText.text = "Connected. Have fun."
}
-
onDisconnected: {
+ scanButton.enabled = true
+ addressField.enabled = true
+ portField.enabled = true
connectButton.enabled = true
disconnectButton.enabled = false
- label.text = "Press to connect."
- }
-
- onStickMoved: {
- console.log("Stick moved. x: " + x + " y: " + y)
- }
-
- onButtonsChanged: {
- console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
- labelA.color = a ? "red" : "blue"
- labelB.color = b ? "red" : "blue"
- labelC.color = c ? "red" : "blue"
- labelD.color = d ? "red" : "blue"
+ infoText.text = "To enable remote control please press \"Connect\" when ready."
}
+ }
- onAChanged: console.log("A changed to: " + val)
- onBChanged: console.log("B changed to: " + val)
- onCChanged: console.log("C changed to: " + val)
- onDChanged: console.log("D changed to: " + val)
+ XtstAdapter{
+ id: xtstAdapter
}
}