Add bluetooth available check and fix discovery issue for iOS
This commit is contained in:
parent
1b42ffd3e4
commit
57b1172a88
@ -49,7 +49,7 @@ public:
|
||||
Q_INVOKABLE BluetoothDeviceInfo *get(int index) const;
|
||||
|
||||
void addBluetoothDeviceInfo(BluetoothDeviceInfo *deviceInfo);
|
||||
void clearModel();
|
||||
Q_INVOKABLE void clearModel();
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
|
||||
@ -38,6 +38,12 @@ BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
||||
return;
|
||||
}
|
||||
|
||||
if (localDevice.allDevices().isEmpty()) {
|
||||
qWarning() << "BluetoothDiscovery: there is no bluetooth device available currently.";
|
||||
setBluetoothAvailable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setBluetoothAvailable(true);
|
||||
|
||||
if (localDevice.allDevices().count() > 1) {
|
||||
@ -124,7 +130,7 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo
|
||||
|
||||
qDebug() << "BluetoothDiscovery: [+]" << deviceInformation->name() << "(" << deviceInformation->address() << ")" << (isLowEnergy ? "LE" : "");
|
||||
|
||||
//
|
||||
|
||||
if (!isLowEnergy || deviceInformation->name().isEmpty()) {
|
||||
delete deviceInformation;
|
||||
return;
|
||||
@ -148,6 +154,8 @@ void BluetoothDiscovery::discoveryFinished()
|
||||
{
|
||||
qDebug() << "BluetoothDiscovery: Discovery finished";
|
||||
setDiscovering(false);
|
||||
if (m_enabled)
|
||||
start();
|
||||
}
|
||||
|
||||
void BluetoothDiscovery::onError(const QBluetoothDeviceDiscoveryAgent::Error &error)
|
||||
@ -158,11 +166,14 @@ void BluetoothDiscovery::onError(const QBluetoothDeviceDiscoveryAgent::Error &er
|
||||
|
||||
void BluetoothDiscovery::start()
|
||||
{
|
||||
m_enabled = true;
|
||||
|
||||
if (!m_discoveryAgent)
|
||||
return;
|
||||
|
||||
if (m_discoveryAgent->isActive())
|
||||
m_discoveryAgent->stop();
|
||||
|
||||
m_deviceInfos->clearModel();
|
||||
|
||||
qDebug() << "BluetoothDiscovery: Start discovering.";
|
||||
m_discoveryAgent->start();
|
||||
setDiscovering(true);
|
||||
@ -170,6 +181,8 @@ void BluetoothDiscovery::start()
|
||||
|
||||
void BluetoothDiscovery::stop()
|
||||
{
|
||||
m_enabled = false;
|
||||
|
||||
qDebug() << "BluetoothDiscovery: Stop discovering.";
|
||||
m_discoveryAgent->stop();
|
||||
setDiscovering(false);
|
||||
|
||||
@ -54,6 +54,7 @@ private:
|
||||
QBluetoothDeviceDiscoveryAgent *m_discoveryAgent = nullptr;
|
||||
BluetoothDeviceInfos *m_deviceInfos;
|
||||
|
||||
bool m_enabled = false;
|
||||
bool m_discovering = false;
|
||||
bool m_bluetoothAvailable = false;
|
||||
bool m_bluetoothEnabled = false;
|
||||
|
||||
@ -80,8 +80,7 @@ Page {
|
||||
title: qsTr("Connect %1").arg(app.systemName)
|
||||
model: ListModel {
|
||||
ListElement { iconSource: "../images/network-vpn.svg"; text: qsTr("Manual connection"); page: "connection/ManualConnectPage.qml" }
|
||||
// Disabled for now as it's too buggy still
|
||||
// ListElement { iconSource: "../images/bluetooth.svg"; text: qsTr("Wireless setup"); page: "connection/BluetoothDiscoveryPage.qml" }
|
||||
ListElement { iconSource: "../images/bluetooth.svg"; text: qsTr("Wireless setup"); page: "connection/BluetoothDiscoveryPage.qml"; }
|
||||
ListElement { iconSource: "../images/private-browsing.svg"; text: qsTr("Demo mode"); page: "" }
|
||||
ListElement { iconSource: "../images/stock_application.svg"; text: qsTr("App settings"); page: "AppSettingsPage.qml" }
|
||||
}
|
||||
|
||||
@ -13,7 +13,13 @@ Page {
|
||||
|
||||
HeaderButton {
|
||||
imageSource: Qt.resolvedUrl("../images/refresh.svg")
|
||||
onClicked: Engine.bluetoothDiscovery.start()
|
||||
onClicked: {
|
||||
if (Engine.bluetoothDiscovery.bluetoothAvailable) {
|
||||
Engine.bluetoothDiscovery.deviceInfos.clearModel()
|
||||
Engine.bluetoothDiscovery.start()
|
||||
}
|
||||
}
|
||||
enabled: Engine.bluetoothDiscovery.bluetoothAvailable && !Engine.bluetoothDiscovery.discovering
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +43,8 @@ Page {
|
||||
pageStack.push(connectingPageComponent, { name: name, address: btAddress } )
|
||||
}
|
||||
|
||||
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: app.margins
|
||||
@ -46,9 +54,10 @@ Page {
|
||||
Layout.leftMargin: app.margins
|
||||
Layout.topMargin: app.margins
|
||||
Layout.rightMargin: app.rightMargin
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Searching for %1 boxes via Bluetooth.").arg(app.systemName)
|
||||
text: Engine.bluetoothDiscovery.bluetoothAvailable ? qsTr("Searching for %1 boxes via Bluetooth.").arg(app.systemName) : qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device.")
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
@ -88,6 +97,9 @@ Page {
|
||||
spacing: app.margins
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
maximumLineCount: 2
|
||||
elide: Text.ElideRight
|
||||
text: qsTr("Troubles finding your box? Try this!")
|
||||
}
|
||||
Button {
|
||||
|
||||
Reference in New Issue
Block a user