Intermediate commit.
[qzeecontrol] / qml / QZeeControl / MainPage.qml
1 import QtQuick 1.1
2 import com.nokia.meego 1.0
3 import QtMobility.connectivity 1.2
4 import qzeecontrol 1.0
5
6 Page {
7     tools: commonTools
8
9     Label {
10         id: label
11         anchors.centerIn: parent
12         text: "Press to connect."
13     }
14
15     Button{
16         id: connectButton
17
18         anchors {
19             horizontalCenter: parent.horizontalCenter
20             top: label.bottom
21             topMargin: 10
22         }
23
24         text: "Connect"
25
26         onClicked: {
27             btDiscovery.discovery = true
28         }
29     }
30
31     Button{
32         id: disconnectButton
33
34         anchors {
35             horizontalCenter: parent.horizontalCenter
36             top: connectButton.bottom
37             topMargin: 10
38         }
39
40         text: "Disconnect"
41
42         onClicked: {
43             btConn.disconnect()
44         }
45     }
46
47     BluetoothDiscoveryModel{
48         id: btDiscovery
49
50         discovery: false
51         minimalDiscovery: true
52
53         onDiscoveryChanged: {
54             if(discovery){
55                 label.text = "Scanning for devices..."
56                 connectButton.enabled = false
57                 disconnectButton.enabled = false
58             }else{
59                 connectButton.enabled = true
60                 disconnectButton.enabled = false
61             }
62         }
63
64         onNewServiceDiscovered: {
65             console.log("Service " + service.serviceName + " found on " + service.deviceName + " at address " + service.deviceAddress + " on port " + service.servicePort + ".")
66             //btSocket.service = service
67             btConn.connect(service.deviceAddress, service.servicePort)
68         }
69     }
70
71     /*
72     BluetoothSocket{
73         id: btSocket
74
75         onDataAvailable: {
76             console.log("Data available: " + stringData.charCodeAt(0) + data)
77         }
78
79         onServiceChanged: {
80             console.log("Service changed. Connecting...")
81             connected = true
82         }
83
84         onConnectedChanged: {
85             console.log("Connected.")
86         }
87     }*/
88
89     BtConnector{
90         id: btConn
91
92         onConnected: {
93             connectButton.enabled = false
94             disconnectButton.enabled = true
95             label.text = "Connected."
96         }
97
98         onDisconnected: {
99             connectButton.enabled = true
100             disconnectButton.enabled = false
101             label.text = "Press to connect."
102         }
103
104         onStickMoved: {
105             console.log("Stick moved. x: " + x + " y: " + y)
106         }
107
108         onButtonsChanged: {
109             console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
110         }
111     }
112 }