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 "settingsstorage.js" as SettingsStorage
24 import qzeecontrol 1.0
29 orientationLock: PageOrientation.LockPortrait
31 property bool initializing: true
33 Component.onCompleted: {
34 SettingsStorage.initialize();
36 var address = SettingsStorage.getSetting("address");
37 var port = SettingsStorage.getSetting("port");
38 if(address !== "Unknown" && port !== "Unknown"){
39 console.log("Loaded address " + address + " and port " + port + " from DB.")
40 addressField.text = address
44 if(SettingsStorage.getSetting("A") === "Unknown"){
45 console.log("Initializing key bindings.")
46 setKeyBindingsToDefault()
53 function setKeyBindingsToDefault(){
54 console.log("Setting key bindings to default.")
55 SettingsStorage.setSetting("A", "a")
56 SettingsStorage.setSetting("B", "b")
57 SettingsStorage.setSetting("C", "c")
58 SettingsStorage.setSetting("D", "d")
60 SettingsStorage.setSetting("Up", "Up")
61 SettingsStorage.setSetting("Down", "Down")
62 SettingsStorage.setSetting("Left", "Left")
63 SettingsStorage.setSetting("Right", "Right")
66 function loadKeyBindings(){
67 console.log("Loading key bindings.")
68 btConn.keyBindingA = SettingsStorage.getSetting("A")
69 btConn.keyBindingB = SettingsStorage.getSetting("B")
70 btConn.keyBindingC = SettingsStorage.getSetting("C")
71 btConn.keyBindingD = SettingsStorage.getSetting("D")
73 btConn.keyBindingUp = SettingsStorage.getSetting("Up")
74 btConn.keyBindingDown = SettingsStorage.getSetting("Down")
75 btConn.keyBindingLeft = SettingsStorage.getSetting("Left")
76 btConn.keyBindingRight = SettingsStorage.getSetting("Right")
83 target: cursorRectangle
84 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
85 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
89 color: btConn.a ? "red" : "blue"
93 color: btConn.b ? "red" : "blue"
97 color: btConn.c ? "red" : "blue"
101 color: btConn.d ? "red" : "blue"
107 target: cursorRectangle
108 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
109 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
143 target: connectButton
147 target: disconnectButton
152 text: "Connecting..."
170 target: connectButton
174 target: disconnectButton
179 text: "Press \"Connect\" to connect to the device."
185 target: platformWindow
188 if(platformWindow.active){
198 anchors{top: parent.top; left: parent.left; right: parent.right}
199 height: header.height
205 source: "image://theme/color8-meegotouch-view-header-fixed"
211 font.family: "Nokia Pure Text Light"
213 anchors.left: parent.left
214 anchors.leftMargin: 20
215 anchors.verticalCenter: parent.verticalCenter
221 anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
222 contentHeight: contentColumn.height
227 anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
233 anchors.horizontalCenter: parent.horizontalCenter
237 btDiscovery.discovery = true
243 anchors.horizontalCenter: parent.horizontalCenter
248 text: "No device found yet."
254 if(text === "No device found yet.")
257 connectButton.enabled = true
258 infoText.text = "Press \"Connect\" to connect to the device."
259 console.log("Storing address in DB: " + text)
260 SettingsStorage.setSetting("address", text)
267 validator: IntValidator{}
276 console.log("Storing port in DB: " + text)
277 SettingsStorage.setSetting("port", text)
286 text: "Please scan for a device first."
287 horizontalAlignment: Text.AlignHCenter
288 wrapMode: Text.WordWrap
293 anchors.horizontalCenter: parent.horizontalCenter
299 mainPage.state = "connecting"
300 btConn.connect(addressField.text, parseInt(portField.text))
306 anchors.horizontalCenter: parent.horizontalCenter
317 anchors.horizontalCenter: parent.horizontalCenter
324 color: btConn.a ? "red" : "blue"
329 color: btConn.b ? "red" : "blue"
334 color: btConn.c ? "red" : "blue"
339 color: btConn.d ? "red" : "blue"
345 anchors.horizontalCenter: parent.horizontalCenter
346 height: moveArea.height
347 width: moveArea.width
363 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
364 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
370 BluetoothDiscoveryModel{
374 minimalDiscovery: true
376 onDiscoveryChanged: {
378 infoText.text = "Scanning for a device..."
379 scanButton.enabled = false
380 connectButton.enabled = false
381 disconnectButton.enabled = false
382 addressField.enabled = false
383 portField.enabled = false
385 scanButton.enabled = true
386 disconnectButton.enabled = false
387 addressField.enabled = true
388 portField.enabled = true
390 if(addressField.text !== "No device found yet." && portField.text !== "na"){
391 infoText.text = "Device found. You can now connect."
392 connectButton.enabled = true
397 onNewServiceDiscovered: {
398 console.log("Service " + service.serviceName + " found on "
399 + service.deviceName + " at address " + service.deviceAddress
400 + " on port " + service.servicePort + ".")
401 if(service.serviceName === "Zeemote"){
402 addressField.text = service.deviceAddress
403 portField.text = service.servicePort
405 console.log("Found device. Stopped further discovery.")
415 property string keyBindingA
416 property string keyBindingB
417 property string keyBindingC
418 property string keyBindingD
420 property string keyBindingUp
421 property string keyBindingDown
422 property string keyBindingLeft
423 property string keyBindingRight
426 disconnectButton.enabled = true
427 infoText.text = "Connected. Have fun."
431 mainPage.state = "disconnected"
435 // console.log("Stick moved. x: " + x + " y: " + y)
438 // onButtonsChanged: {
439 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
443 // console.log("A changed to: " + val)
444 xtstAdapter.sendKey(keyBindingA, val);
447 // console.log("B changed to: " + val)
448 xtstAdapter.sendKey(keyBindingB, val);
451 // console.log("C changed to: " + val)
452 xtstAdapter.sendKey(keyBindingC, val);
455 // console.log("D changed to: " + val)
456 xtstAdapter.sendKey(keyBindingD, val);
459 onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
460 onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
461 onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
462 onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
465 // if(val > joystickThreshold){
466 // xtstAdapter.sendKey("Right", true);
467 // }else if(val < -joystickThreshold){
468 // xtstAdapter.sendKey("Left", true);
470 // xtstAdapter.sendKey("Right", false);
471 // xtstAdapter.sendKey("Left", false);
476 // if(val > joystickThreshold){
477 // xtstAdapter.sendKey("Down", true);
478 // }else if(val < -joystickThreshold){
479 // xtstAdapter.sendKey("Up", true);
481 // xtstAdapter.sendKey("Down", false);
482 // xtstAdapter.sendKey("Up", false);