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