Fix segfault. Remove debug output. Change UI Layout.w
[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
29
30     Column {
31         anchors.centerIn: parent
32         spacing: 10
33
34         Label {
35             id: label
36
37             text: "Press to connect."
38         }
39
40         Button{
41             id: connectButton
42
43             text: "Connect"
44
45             onClicked: {
46                 btDiscovery.discovery = true
47             }
48         }
49
50         Button{
51             id: disconnectButton
52
53             text: "Disconnect"
54
55             onClicked: {
56                 btConn.disconnect()
57             }
58         }
59     }
60
61     BluetoothDiscoveryModel{
62         id: btDiscovery
63
64         discovery: false
65         minimalDiscovery: true
66
67         onDiscoveryChanged: {
68             if(discovery){
69                 label.text = "Scanning for devices..."
70                 connectButton.enabled = false
71                 disconnectButton.enabled = false
72             }else{
73                 connectButton.enabled = true
74                 disconnectButton.enabled = false
75             }
76         }
77
78         onNewServiceDiscovered: {
79             console.log("Service " + service.serviceName + " found on " + service.deviceName + " at address " + service.deviceAddress + " on port " + service.servicePort + ".")
80             //btSocket.service = service
81             btConn.connect(service.deviceAddress, service.servicePort)
82         }
83     }
84
85     /*
86     BluetoothSocket{
87         id: btSocket
88
89         onDataAvailable: {
90             console.log("Data available: " + stringData.charCodeAt(0) + data)
91         }
92
93         onServiceChanged: {
94             console.log("Service changed. Connecting...")
95             connected = true
96         }
97
98         onConnectedChanged: {
99             console.log("Connected.")
100         }
101     }*/
102
103     BtConnector{
104         id: btConn
105
106         onConnected: {
107             connectButton.enabled = false
108             disconnectButton.enabled = true
109             label.text = "Connected."
110         }
111
112         onDisconnected: {
113             connectButton.enabled = true
114             disconnectButton.enabled = false
115             label.text = "Press to connect."
116         }
117
118         onStickMoved: {
119             console.log("Stick moved. x: " + x + " y: " + y)
120         }
121
122         onButtonsChanged: {
123             console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
124         }
125     }
126 }