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 zeeRemoteControl.keyBindingA = SettingsStorage.getSetting("A")
72 zeeRemoteControl.keyBindingB = SettingsStorage.getSetting("B")
73 zeeRemoteControl.keyBindingC = SettingsStorage.getSetting("C")
74 zeeRemoteControl.keyBindingD = SettingsStorage.getSetting("D")
76 zeeRemoteControl.keyBindingUp = SettingsStorage.getSetting("Up")
77 zeeRemoteControl.keyBindingDown = SettingsStorage.getSetting("Down")
78 zeeRemoteControl.keyBindingLeft = SettingsStorage.getSetting("Left")
79 zeeRemoteControl.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 Zeemote found yet.")
100 infoText.text = (addressField.text !== "No Zeemote found yet.") ?
101 "To enable remote control please press \"Connect\" when ready." :
102 "Please scan for a Zeemote first."
109 target: cursorRectangle
110 x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
111 y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
115 color: zeeRemoteControl.a ? "red" : "blue"
119 color: zeeRemoteControl.b ? "red" : "blue"
123 color: zeeRemoteControl.c ? "red" : "blue"
127 color: zeeRemoteControl.d ? "red" : "blue"
133 target: cursorRectangle
134 x: moveArea.x + (moveArea.width * 0.5) - (cursorRectangle.width * 0.5)
135 y: moveArea.y + (moveArea.height * 0.5) - (cursorRectangle.height * 0.5)
157 target: platformWindow
160 if(platformWindow.active){
170 anchors{top: parent.top; left: parent.left; right: parent.right}
171 height: header.height
177 source: "image://theme/color8-meegotouch-view-header-fixed"
183 font.family: "Nokia Pure Text Light"
185 anchors.left: parent.left
186 anchors.leftMargin: 20
187 anchors.verticalCenter: parent.verticalCenter
193 anchors{top: headerItem.bottom; bottom: parent.bottom; left: parent.left; right: parent.right}
194 contentHeight: contentColumn.height
199 anchors{top: parent.top; left: parent.left; right: parent.right; topMargin: 10}
205 anchors.horizontalCenter: parent.horizontalCenter
209 btDiscovery.discovery = true
215 anchors.horizontalCenter: parent.horizontalCenter
220 text: "No Zeemote found yet."
224 if(mainPage.initializing)
227 if(text === "No Zeemote found yet.")
230 updateConnectAndScanButton();
232 console.log("Storing address in DB: " + text)
233 SettingsStorage.setSetting("address", text)
240 validator: IntValidator{}
243 if(mainPage.initializing)
249 console.log("Storing port in DB: " + text)
250 SettingsStorage.setSetting("port", text)
259 horizontalAlignment: Text.AlignHCenter
260 wrapMode: Text.WordWrap
265 anchors.horizontalCenter: parent.horizontalCenter
271 scanButton.enabled = false
272 addressField.enabled = false
273 portField.enabled = false
274 connectButton.enabled = false
275 disconnectButton.enabled = false
276 infoText.text = "Connecting..."
278 zeeRemoteControl.connect(addressField.text, parseInt(portField.text))
284 anchors.horizontalCenter: parent.horizontalCenter
289 zeeRemoteControl.disconnect()
295 anchors.horizontalCenter: parent.horizontalCenter
302 color: zeeRemoteControl.a ? "red" : "blue"
307 color: zeeRemoteControl.b ? "red" : "blue"
312 color: zeeRemoteControl.c ? "red" : "blue"
317 color: zeeRemoteControl.d ? "red" : "blue"
323 anchors.horizontalCenter: parent.horizontalCenter
324 height: moveArea.height
325 width: moveArea.width
341 x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
342 y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
351 monitorBluetoothStateChanges: true
353 onBluetoothStateChanged: {
354 updateConnectAndScanButton()
358 BluetoothDiscoveryModel{
362 minimalDiscovery: true
364 onDiscoveryChanged: {
369 infoText.text = "Scanning for a Zeemote..."
370 scanButton.enabled = false
371 connectButton.enabled = false
372 disconnectButton.enabled = false
373 addressField.enabled = false
374 portField.enabled = false
376 scanButton.enabled = true
377 disconnectButton.enabled = false
378 addressField.enabled = true
379 portField.enabled = true
381 if(addressField.text !== "No Zeemote found yet." && portField.text !== "na"){
382 infoText.text = "Zeemote found. To enable remote control please press \"Connect\" when ready."
383 connectButton.enabled = true
388 onNewServiceDiscovered: {
389 console.log("Service " + service.serviceName + " found on "
390 + service.deviceName + " at address " + service.deviceAddress
391 + " on port " + service.servicePort + ".")
392 if(service.serviceName === "Zeemote"){
393 addressField.text = service.deviceAddress
394 portField.text = service.servicePort
396 console.log("Found Zeemote. Stopped further discovery.")
407 disconnectButton.enabled = true
408 infoText.text = "Connected. Have fun."
411 scanButton.enabled = true
412 addressField.enabled = true
413 portField.enabled = true
414 connectButton.enabled = true
415 disconnectButton.enabled = false
416 infoText.text = "To enable remote control please press \"Connect\" when ready."