2 * Copyright 2012 Ruediger Gad
4 * This file is part of QZeeControl.
6 * QZeeControl is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * QZeeControl is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with QZeeControl. If not, see <http://www.gnu.org/licenses/>.
21 import com.nokia.meego 1.0
22 import QtMobility.connectivity 1.2
23 import QtMobility.systeminfo 1.2
24 import "settingsstorage.js" as SettingsStorage
25 import qzeecontrol 1.0
31 orientationLock: PageOrientation.LockPortrait
33 property bool initializing: true
35 Component.onCompleted: {
36 SettingsStorage.initialize();
38 var address = SettingsStorage.getSetting("address");
39 var port = SettingsStorage.getSetting("port");
40 if(address !== "Unknown" && port !== "Unknown"){
41 console.log("Loaded address " + address + " and port " + port + " from DB.")
42 addressField.text = address
46 if(SettingsStorage.getSetting("A") === "Unknown"){
47 console.log("Initializing key bindings.")
48 setKeyBindingsToDefault()
52 updateConnectAndScanButton()
56 function setKeyBindingsToDefault(){
57 console.log("Setting key bindings to default.")
58 SettingsStorage.setSetting("A", "a")
59 SettingsStorage.setSetting("B", "b")
60 SettingsStorage.setSetting("C", "c")
61 SettingsStorage.setSetting("D", "d")
63 SettingsStorage.setSetting("Up", "Up")
64 SettingsStorage.setSetting("Down", "Down")
65 SettingsStorage.setSetting("Left", "Left")
66 SettingsStorage.setSetting("Right", "Right")
69 function loadKeyBindings(){
70 console.log("Loading key bindings.")
71 btConn.keyBindingA = SettingsStorage.getSetting("A")
72 btConn.keyBindingB = SettingsStorage.getSetting("B")
73 btConn.keyBindingC = SettingsStorage.getSetting("C")
74 btConn.keyBindingD = SettingsStorage.getSetting("D")
76 btConn.keyBindingUp = SettingsStorage.getSetting("Up")
77 btConn.keyBindingDown = SettingsStorage.getSetting("Down")
78 btConn.keyBindingLeft = SettingsStorage.getSetting("Left")
79 btConn.keyBindingRight = SettingsStorage.getSetting("Right")
82 function updateConnectAndScanButton(){
83 if(!deviceInfo.currentBluetoothPowerState){
84 scanButton.enabled = false
85 connectButton.enabled = false
87 addressField.enabled = false
88 portField.enabled = false
90 infoText.text = "To get started please turn Bluetooth on."
94 scanButton.enabled = true
96 addressField.enabled = true
97 portField.enabled = true
99 connectButton.enabled = (addressField.text !== "No device found yet.")
100 infoText.text = (addressField.text !== "No device found yet.") ?
101 "To enable remote control please press \"Connect\" when ready." :
102 "Please scan for a Zeemote first."
110 target: cursorRectangle
111 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
112 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
116 color: btConn.a ? "red" : "blue"
120 color: btConn.b ? "red" : "blue"
124 color: btConn.c ? "red" : "blue"
128 color: btConn.d ? "red" : "blue"
134 target: cursorRectangle
135 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
136 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
170 target: connectButton
174 target: disconnectButton
179 text: "Connecting..."
197 target: connectButton
201 target: disconnectButton
206 text: "Press \"Connect\" to connect to the device."
212 target: platformWindow
215 if(platformWindow.active){
225 anchors{top: parent.top; left: parent.left; right: parent.right}
226 height: header.height
232 source: "image://theme/color8-meegotouch-view-header-fixed"
238 font.family: "Nokia Pure Text Light"
240 anchors.left: parent.left
241 anchors.leftMargin: 20
242 anchors.verticalCenter: parent.verticalCenter
248 anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
249 contentHeight: contentColumn.height
254 anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
260 anchors.horizontalCenter: parent.horizontalCenter
264 btDiscovery.discovery = true
270 anchors.horizontalCenter: parent.horizontalCenter
275 text: "No device found yet."
278 if(mainPage.initializing)
281 if(text === "No device found yet.")
284 updateConnectAndScanButton();
286 console.log("Storing address in DB: " + text)
287 SettingsStorage.setSetting("address", text)
294 validator: IntValidator{}
297 if(mainPage.initializing)
303 console.log("Storing port in DB: " + text)
304 SettingsStorage.setSetting("port", text)
313 horizontalAlignment: Text.AlignHCenter
314 wrapMode: Text.WordWrap
319 anchors.horizontalCenter: parent.horizontalCenter
325 mainPage.state = "connecting"
326 btConn.connect(addressField.text, parseInt(portField.text))
332 anchors.horizontalCenter: parent.horizontalCenter
343 anchors.horizontalCenter: parent.horizontalCenter
350 color: btConn.a ? "red" : "blue"
355 color: btConn.b ? "red" : "blue"
360 color: btConn.c ? "red" : "blue"
365 color: btConn.d ? "red" : "blue"
371 anchors.horizontalCenter: parent.horizontalCenter
372 height: moveArea.height
373 width: moveArea.width
389 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
390 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
399 monitorBluetoothStateChanges: true
401 onBluetoothStateChanged: {
402 updateConnectAndScanButton()
406 BluetoothDiscoveryModel{
410 minimalDiscovery: true
412 onDiscoveryChanged: {
414 infoText.text = "Scanning for a device..."
415 scanButton.enabled = false
416 connectButton.enabled = false
417 disconnectButton.enabled = false
418 addressField.enabled = false
419 portField.enabled = false
421 scanButton.enabled = true
422 disconnectButton.enabled = false
423 addressField.enabled = true
424 portField.enabled = true
426 if(addressField.text !== "No device found yet." && portField.text !== "na"){
427 infoText.text = "Device found. You can now connect."
428 connectButton.enabled = true
433 onNewServiceDiscovered: {
434 console.log("Service " + service.serviceName + " found on "
435 + service.deviceName + " at address " + service.deviceAddress
436 + " on port " + service.servicePort + ".")
437 if(service.serviceName === "Zeemote"){
438 addressField.text = service.deviceAddress
439 portField.text = service.servicePort
441 console.log("Found device. Stopped further discovery.")
451 property string keyBindingA
452 property string keyBindingB
453 property string keyBindingC
454 property string keyBindingD
456 property string keyBindingUp
457 property string keyBindingDown
458 property string keyBindingLeft
459 property string keyBindingRight
462 disconnectButton.enabled = true
463 infoText.text = "Connected. Have fun."
467 mainPage.state = "disconnected"
471 // console.log("Stick moved. x: " + x + " y: " + y)
474 // onButtonsChanged: {
475 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
479 // console.log("A changed to: " + val)
480 xtstAdapter.sendKey(keyBindingA, val);
483 // console.log("B changed to: " + val)
484 xtstAdapter.sendKey(keyBindingB, val);
487 // console.log("C changed to: " + val)
488 xtstAdapter.sendKey(keyBindingC, val);
491 // console.log("D changed to: " + val)
492 xtstAdapter.sendKey(keyBindingD, val);
495 onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
496 onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
497 onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
498 onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
501 // if(val > joystickThreshold){
502 // xtstAdapter.sendKey("Right", true);
503 // }else if(val < -joystickThreshold){
504 // xtstAdapter.sendKey("Left", true);
506 // xtstAdapter.sendKey("Right", false);
507 // xtstAdapter.sendKey("Left", false);
512 // if(val > joystickThreshold){
513 // xtstAdapter.sendKey("Down", true);
514 // }else if(val < -joystickThreshold){
515 // xtstAdapter.sendKey("Up", true);
517 // xtstAdapter.sendKey("Down", false);
518 // xtstAdapter.sendKey("Up", false);