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
33 orientationLock: PageOrientation.LockPortrait
35 property bool connected: false
36 property alias currentAddress: addressField.text
37 property bool initializing: true
38 property string name: "none"
39 property string usedAddresses: "none"
41 Component.onCompleted: {
42 SettingsStorage.initialize();
44 var address = SettingsStorage.getSetting(name + "address");
45 var port = SettingsStorage.getSetting(name + "port");
46 if(address !== "Unknown" && port !== "Unknown"){
47 console.log("Loaded address " + address + " and port " + port + " from DB for " + name + ".")
48 addressField.text = address
52 if(SettingsStorage.getSetting(name + "A") === "Unknown"){
53 console.log("Initializing key bindings for " + name + ".")
54 setKeyBindingsToDefault()
58 updateConnectAndScanButton()
62 function setKeyBindingsToDefault(){
63 console.log("Setting key bindings to default for " + name + ".")
64 SettingsStorage.setSetting(name + "A", "a")
65 SettingsStorage.setSetting(name + "B", "b")
66 SettingsStorage.setSetting(name + "C", "c")
67 SettingsStorage.setSetting(name + "D", "d")
69 SettingsStorage.setSetting(name + "Up", "Up")
70 SettingsStorage.setSetting(name + "Down", "Down")
71 SettingsStorage.setSetting(name + "Left", "Left")
72 SettingsStorage.setSetting(name + "Right", "Right")
74 SettingsStorage.setSetting(name + "Threshold", "50")
77 * The following settings are not used right now but
78 * we initialize these anyhow for possibly later use.
80 SettingsStorage.setSetting(name + "MousePointerMode", "false")
81 SettingsStorage.setSetting(name + "AlternateActionTrigger", "none")
84 function loadKeyBindings(){
85 console.log("Loading key bindings for " + name + ".")
86 zeeRemoteControl.keyBindingA = SettingsStorage.getSetting(name + "A")
87 zeeRemoteControl.keyBindingB = SettingsStorage.getSetting(name + "B")
88 zeeRemoteControl.keyBindingC = SettingsStorage.getSetting(name + "C")
89 zeeRemoteControl.keyBindingD = SettingsStorage.getSetting(name + "D")
91 zeeRemoteControl.keyBindingUp = SettingsStorage.getSetting(name + "Up")
92 zeeRemoteControl.keyBindingDown = SettingsStorage.getSetting(name + "Down")
93 zeeRemoteControl.keyBindingLeft = SettingsStorage.getSetting(name + "Left")
94 zeeRemoteControl.keyBindingRight = SettingsStorage.getSetting(name + "Right")
96 zeeRemoteControl.threshold = SettingsStorage.getSetting(name + "Threshold")
99 function updateConnectAndScanButton(){
100 if(!deviceInfo.currentBluetoothPowerState){
101 scanButton.enabled = false
102 connectButton.enabled = false
104 addressField.enabled = false
105 portField.enabled = false
107 infoText.text = "To get started please turn Bluetooth on."
111 scanButton.enabled = true
113 addressField.enabled = true
114 portField.enabled = true
116 connectButton.enabled = (addressField.text !== "No Zeemote found yet.")
117 infoText.text = (addressField.text !== "No Zeemote found yet.") ?
118 "To enable remote control please press \"Connect\" when ready." :
119 "Please scan for a Zeemote first."
126 target: cursorRectangle
127 x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
128 y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
132 color: zeeRemoteControl.a ? "red" : "blue"
136 color: zeeRemoteControl.b ? "red" : "blue"
140 color: zeeRemoteControl.c ? "red" : "blue"
144 color: zeeRemoteControl.d ? "red" : "blue"
150 target: cursorRectangle
151 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
152 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
174 target: platformWindow
177 if(platformWindow.active){
187 anchors{top: parent.top; left: parent.left; right: parent.right}
188 height: header.height
194 source: "image://theme/color8-meegotouch-view-header-fixed"
200 font.family: "Nokia Pure Text Light"
202 anchors.left: parent.left
203 anchors.leftMargin: 20
204 anchors.verticalCenter: parent.verticalCenter
210 anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
211 contentHeight: contentColumn.height
216 anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
222 anchors.horizontalCenter: parent.horizontalCenter
226 btDiscovery.discovery = true
232 anchors.horizontalCenter: parent.horizontalCenter
237 text: "No Zeemote found yet."
241 if(zeeConnectPage.initializing)
244 if(text === "No Zeemote found yet.")
247 if(text === usedAddresses){
248 console.log("Not using address " + text + " as it is already used somewhere else.")
252 updateConnectAndScanButton();
254 console.log("Storing address in DB for " + name + ": " + text)
255 SettingsStorage.setSetting(name + "address", text)
262 validator: IntValidator{}
265 if(zeeConnectPage.initializing)
271 console.log("Storing port in DB for " + name + ": " + text)
272 SettingsStorage.setSetting(name + "port", text)
281 horizontalAlignment: Text.AlignHCenter
282 wrapMode: Text.WordWrap
287 anchors.horizontalCenter: parent.horizontalCenter
293 scanButton.enabled = false
294 addressField.enabled = false
295 portField.enabled = false
296 connectButton.enabled = false
297 disconnectButton.enabled = false
298 infoText.text = "Connecting..."
300 zeeRemoteControl.connect(addressField.text, parseInt(portField.text))
306 anchors.horizontalCenter: parent.horizontalCenter
312 zeeRemoteControl.disconnect()
318 anchors.horizontalCenter: parent.horizontalCenter
325 color: zeeRemoteControl.a ? "red" : "blue"
330 color: zeeRemoteControl.b ? "red" : "blue"
335 color: zeeRemoteControl.c ? "red" : "blue"
340 color: zeeRemoteControl.d ? "red" : "blue"
346 anchors.horizontalCenter: parent.horizontalCenter
347 height: moveArea.height
348 width: moveArea.width
364 x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
365 y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
374 monitorBluetoothStateChanges: true
376 onBluetoothStateChanged: {
377 updateConnectAndScanButton()
381 BluetoothDiscoveryModel{
385 minimalDiscovery: true
387 onDiscoveryChanged: {
392 infoText.text = "Scanning for a Zeemote..."
393 scanButton.enabled = false
394 connectButton.enabled = false
395 disconnectButton.enabled = false
396 addressField.enabled = false
397 portField.enabled = false
399 scanButton.enabled = true
400 disconnectButton.enabled = false
401 addressField.enabled = true
402 portField.enabled = true
404 if(addressField.text !== "No Zeemote found yet." && portField.text !== "na"){
405 infoText.text = "Zeemote found. To enable remote control please press \"Connect\" when ready."
406 connectButton.enabled = true
411 onNewServiceDiscovered: {
412 console.log("Service " + service.serviceName + " found on "
413 + service.deviceName + " at address " + service.deviceAddress
414 + " on port " + service.servicePort + ".")
416 if(service.serviceName !== "Zeemote")
419 if(service.deviceAddress === usedAddresses){
420 console.log("Zeemote at address " + service.deviceAddress + " already in use somewhere else. " +
421 "Not going to use this one.")
425 addressField.text = service.deviceAddress
426 portField.text = service.servicePort
428 console.log("Found Zeemote. Stopped further discovery.")
436 zeeConnectPage.connected = true
437 disconnectButton.enabled = true
438 infoText.text = "Connected. Have fun."
441 zeeConnectPage.connected = false
442 scanButton.enabled = true
443 addressField.enabled = true
444 portField.enabled = true
445 connectButton.enabled = true
446 disconnectButton.enabled = false
447 infoText.text = "To enable remote control please press \"Connect\" when ready."