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 Component.onCompleted: {
32 SettingsStorage.initialize();
34 var address = SettingsStorage.getSetting("address");
35 var port = SettingsStorage.getSetting("port");
36 if(address !== "Unknown" && port !== "Unknown"){
37 console.log("Loaded address " + address + " and port " + port + " from DB.")
38 addressField.text = address
42 if(SettingsStorage.getSetting("A") === "Unknown"){
43 console.log("Initializing key bindings.")
44 setKeyBindingsToDefault()
50 function setKeyBindingsToDefault(){
51 console.log("Setting key bindings to default.")
52 SettingsStorage.setSetting("A", "a")
53 SettingsStorage.setSetting("B", "b")
54 SettingsStorage.setSetting("C", "c")
55 SettingsStorage.setSetting("D", "d")
57 SettingsStorage.setSetting("Up", "Up")
58 SettingsStorage.setSetting("Down", "Down")
59 SettingsStorage.setSetting("Left", "Left")
60 SettingsStorage.setSetting("Right", "Right")
63 function loadKeyBindings(){
64 console.log("Loading key bindings.")
65 btConn.keyBindingA = SettingsStorage.getSetting("A")
66 btConn.keyBindingB = SettingsStorage.getSetting("B")
67 btConn.keyBindingC = SettingsStorage.getSetting("C")
68 btConn.keyBindingD = SettingsStorage.getSetting("D")
70 btConn.keyBindingUp = SettingsStorage.getSetting("Up")
71 btConn.keyBindingDown = SettingsStorage.getSetting("Down")
72 btConn.keyBindingLeft = SettingsStorage.getSetting("Left")
73 btConn.keyBindingRight = SettingsStorage.getSetting("Right")
80 target: cursorRectangle
81 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
82 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
86 color: btConn.a ? "red" : "blue"
90 color: btConn.b ? "red" : "blue"
94 color: btConn.c ? "red" : "blue"
98 color: btConn.d ? "red" : "blue"
104 target: cursorRectangle
105 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
106 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
140 target: connectButton
144 target: disconnectButton
149 text: "Connecting..."
167 target: connectButton
171 target: disconnectButton
176 text: "Press \"Connect\" to connect to the device."
182 target: platformWindow
185 if(platformWindow.active){
195 anchors{top: parent.top; left: parent.left; right: parent.right}
196 height: header.height
202 source: "image://theme/color8-meegotouch-view-header-fixed"
208 font.family: "Nokia Pure Text Light"
210 anchors.left: parent.left
211 anchors.leftMargin: 20
212 anchors.verticalCenter: parent.verticalCenter
218 anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
219 contentHeight: contentColumn.height
224 anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
230 anchors.horizontalCenter: parent.horizontalCenter
234 btDiscovery.discovery = true
240 anchors.horizontalCenter: parent.horizontalCenter
245 text: "No device found yet."
248 if(text === "No device found yet.")
251 connectButton.enabled = true
252 infoText.text = "Press \"Connect\" to connect to the device."
253 console.log("Storing address in DB: " + text)
254 SettingsStorage.setSetting("address", text)
261 validator: IntValidator{}
267 console.log("Storing port in DB: " + text)
268 SettingsStorage.setSetting("port", text)
277 text: "Please scan for a device first."
278 horizontalAlignment: Text.AlignHCenter
279 wrapMode: Text.WordWrap
284 anchors.horizontalCenter: parent.horizontalCenter
290 mainPage.state = "connecting"
291 btConn.connect(addressField.text, parseInt(portField.text))
297 anchors.horizontalCenter: parent.horizontalCenter
309 anchors.horizontalCenter: parent.horizontalCenter
316 color: btConn.a ? "red" : "blue"
321 color: btConn.b ? "red" : "blue"
326 color: btConn.c ? "red" : "blue"
331 color: btConn.d ? "red" : "blue"
337 anchors.horizontalCenter: parent.horizontalCenter
338 height: moveArea.height
339 width: moveArea.width
355 x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
356 y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
362 BluetoothDiscoveryModel{
366 minimalDiscovery: true
368 onDiscoveryChanged: {
370 infoText.text = "Scanning for a device..."
371 scanButton.enabled = false
372 connectButton.enabled = false
373 disconnectButton.enabled = false
374 addressField.enabled = false
375 portField.enabled = false
377 scanButton.enabled = true
378 disconnectButton.enabled = false
379 addressField.enabled = true
380 portField.enabled = true
382 if(addressField.text !== "No device found yet." && portField.text !== "na"){
383 infoText.text = "Device found. You can now connect."
384 connectButton.enabled = true
389 onNewServiceDiscovered: {
390 console.log("Service " + service.serviceName + " found on "
391 + service.deviceName + " at address " + service.deviceAddress
392 + " on port " + service.servicePort + ".")
393 if(service.serviceName === "Zeemote"){
394 addressField.text = service.deviceAddress
395 portField.text = service.servicePort
405 property string keyBindingA
406 property string keyBindingB
407 property string keyBindingC
408 property string keyBindingD
410 property string keyBindingUp
411 property string keyBindingDown
412 property string keyBindingLeft
413 property string keyBindingRight
416 disconnectButton.enabled = true
417 infoText.text = "Connected. Have fun."
421 mainPage.state = "disconnected"
425 // console.log("Stick moved. x: " + x + " y: " + y)
428 // onButtonsChanged: {
429 // console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
433 // console.log("A changed to: " + val)
434 xtstAdapter.sendKey(keyBindingA, val);
437 // console.log("B changed to: " + val)
438 xtstAdapter.sendKey(keyBindingB, val);
441 // console.log("C changed to: " + val)
442 xtstAdapter.sendKey(keyBindingC, val);
445 // console.log("D changed to: " + val)
446 xtstAdapter.sendKey(keyBindingD, val);
449 onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
450 onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
451 onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
452 onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
455 // if(val > joystickThreshold){
456 // xtstAdapter.sendKey("Right", true);
457 // }else if(val < -joystickThreshold){
458 // xtstAdapter.sendKey("Left", true);
460 // xtstAdapter.sendKey("Right", false);
461 // xtstAdapter.sendKey("Left", false);
466 // if(val > joystickThreshold){
467 // xtstAdapter.sendKey("Down", true);
468 // }else if(val < -joystickThreshold){
469 // xtstAdapter.sendKey("Up", true);
471 // xtstAdapter.sendKey("Down", false);
472 // xtstAdapter.sendKey("Up", false);