summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2013-09-16 18:01:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-18 17:24:18 +0200
commit8e86bc19f4be7d2d01181ab45a8cadd4320887ec (patch)
tree06ef4b435f0dd6b5b518d4f784bbe4e64ad450db /examples
parent2d8378e49807ef3bf6e6662fbfcec96e95ee328f (diff)
Refactor QBluetoothDiscoveryModel
- Add the option to discover devices - Clear the model when a new discovery is started. In the previous implementation the model was only cleared if new data was available. This can lead to some funny results. - Change some property types to enums - Enhance the qmlscanner example Change-Id: I94f33e3eabd7440b5c0c6c83f3e8158009bd2dbd Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/scanner/Button.qml79
-rw-r--r--examples/bluetooth/scanner/scanner.pro3
-rw-r--r--examples/bluetooth/scanner/scanner.qml82
-rw-r--r--examples/bluetooth/scanner/scanner.qrc1
4 files changed, 122 insertions, 43 deletions
diff --git a/examples/bluetooth/scanner/Button.qml b/examples/bluetooth/scanner/Button.qml
new file mode 100644
index 00000000..a3debfca
--- /dev/null
+++ b/examples/bluetooth/scanner/Button.qml
@@ -0,0 +1,79 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the QtBluetooth module.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ id: button
+
+ property bool active: buttonGroup.activeButton == button
+ property bool fullDiscovery: false
+ property alias text: label.text
+
+ signal clicked()
+
+ height: 60
+ width: 105
+
+ color: active ? "#1c56f3" : "white"
+
+ radius: 5
+ border.width: 2
+
+ Text {
+ id: label
+ text: "Full Discovery"
+ font.bold: true
+ anchors.fill: parent
+ wrapMode: Text.WordWrap
+ horizontalAlignment: Text.AlignHCenter
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ button.clicked()
+ //Reset the model
+ btModel.running = false
+ btModel.running = true
+ buttonGroup.activeButton = button
+ }
+ }
+}
diff --git a/examples/bluetooth/scanner/scanner.pro b/examples/bluetooth/scanner/scanner.pro
index 0d9b1e99..7e5c00f7 100644
--- a/examples/bluetooth/scanner/scanner.pro
+++ b/examples/bluetooth/scanner/scanner.pro
@@ -11,3 +11,6 @@ OTHER_FILES += \
scanner.qml
#DEFINES += QMLJSDEBUGGER
+
+OTHER_FILES += \
+ Button.qml
diff --git a/examples/bluetooth/scanner/scanner.qml b/examples/bluetooth/scanner/scanner.qml
index 86d1477b..52182362 100644
--- a/examples/bluetooth/scanner/scanner.qml
+++ b/examples/bluetooth/scanner/scanner.qml
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the QtBluetooth module.
@@ -48,21 +49,22 @@ Item {
BluetoothDiscoveryModel {
id: btModel
- minimalDiscovery: true
- onDiscoveryChanged: console.log("Discovery mode: " + discovery)
+ running: true
+ discoveryMode: BluetoothDiscoveryModel.DeviceDiscovery
+ onDiscoveryModeChanged: console.log("Discovery mode: " + discoveryMode)
onNewServiceDiscovered: console.log("Found new service " + service.deviceAddress + " " + service.deviceName + " " + service.serviceName);
}
Rectangle {
id: busy
- width: top.width * 0.8;
+ width: top.width * 0.7;
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: top.top;
- height: 20;
+ height: 30;
radius: 5
color: "#1c56f3"
- visible: btModel.discovery
+ visible: btModel.running
Text {
id: text
@@ -83,7 +85,7 @@ Item {
id: mainList
width: top.width
anchors.top: busy.bottom
- anchors.bottom: fullDiscoveryButton.top
+ anchors.bottom: buttonGroup.top
model: btModel
delegate: Rectangle {
@@ -117,12 +119,18 @@ Item {
Text {
id: details
function get_details(s) {
- var str = "Address: " + s.deviceAddress;
- if (s.serviceName) { str += "<br>Service: " + s.serviceName; }
- if (s.serviceDescription) { str += "<br>Description: " + s.serviceDescription; }
- if (s.serviceProtocol) { str += "<br>Protocol: " + s.serviceProtocol; }
- if (s.servicePort) { str += "<br>Port: " + s.servicePort; }
- return str;
+ if (btModel.discoveryMode == BluetoothDiscoveryModel.DeviceDiscovery) {
+ //We are doing a device discovery
+ var str = "Address: " + remoteAddress;
+ return str;
+ } else {
+ var str = "Address: " + s.deviceAddress;
+ if (s.serviceName) { str += "<br>Service: " + s.serviceName; }
+ if (s.serviceDescription) { str += "<br>Description: " + s.serviceDescription; }
+ if (s.serviceProtocol) { str += "<br>Protocol: " + s.serviceProtocol; }
+ if (s.servicePort) { str += "<br>Port: " + s.servicePort; }
+ return str;
+ }
}
visible: opacity !== 0
opacity: btDelegate.expended ? 1 : 0.0
@@ -143,41 +151,29 @@ Item {
focus: true
}
- Rectangle {
- id: fullDiscoveryButton
-
- property bool fullDiscovery: false
-
- onFullDiscoveryChanged: {
- btModel.minimalDiscovery = !fullDiscovery;
- //reset discovery since we changed the discovery mode
- btModel.discovery = false;
- btModel.discovery = true;
- }
+ Row {
+ id: buttonGroup
+ property var activeButton: devButton
- anchors.bottom: top.bottom
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.margins: 3
-
- height: 20
-
- color: fullDiscovery ? "#1c56f3" : "white"
-
- radius: 5
- border.width: 1
+ anchors.bottom: parent.bottom
+ anchors.horizontalCenter: parent.horizontalCenter
+ spacing: 20
- Text {
- id: label
+ Button {
+ id: fdButton
text: "Full Discovery"
- anchors.centerIn: parent
+ onClicked: btModel.discoveryMode = BluetoothDiscoveryModel.FullServiceDiscovery
}
-
- MouseArea {
- anchors.fill: parent
- onClicked: parent.fullDiscovery = !parent.fullDiscovery
+ Button {
+ id: mdButton
+ text: "Minimal Discovery"
+ onClicked: btModel.discoveryMode = BluetoothDiscoveryModel.MinimalServiceDiscovery
+ }
+ Button {
+ id: devButton
+ text: "Device Discovery"
+ onClicked: btModel.discoveryMode = BluetoothDiscoveryModel.DeviceDiscovery
}
-
- Behavior on color { ColorAnimation { duration: 200 } }
}
+
}
diff --git a/examples/bluetooth/scanner/scanner.qrc b/examples/bluetooth/scanner/scanner.qrc
index 9543f065..46232c8a 100644
--- a/examples/bluetooth/scanner/scanner.qrc
+++ b/examples/bluetooth/scanner/scanner.qrc
@@ -2,5 +2,6 @@
<qresource prefix="/">
<file>scanner.qml</file>
<file>default.png</file>
+ <file>Button.qml</file>
</qresource>
</RCC>