Update bluetooth enabled/disabled information
This commit is contained in:
parent
99ce137a1a
commit
ca2c36420d
@ -47,15 +47,13 @@ BluetoothDiscovery::BluetoothDiscovery(QObject *parent) :
|
|||||||
|
|
||||||
setBluetoothAvailable(true);
|
setBluetoothAvailable(true);
|
||||||
|
|
||||||
if (localDevice.allDevices().count() > 1) {
|
// FIXME: check the device with the most capabilities and check if low energy is available
|
||||||
// FIXME: check the device with the most capabilities and check if low energy is available
|
QBluetoothHostInfo adapterHostInfo = localDevice.allDevices().first();
|
||||||
} else {
|
|
||||||
QBluetoothHostInfo adapterHostInfo = localDevice.allDevices().first();
|
qDebug() << "BluetoothDiscovery: using bluetooth adapter" << adapterHostInfo.name() << adapterHostInfo.address().toString();
|
||||||
qDebug() << "BluetoothDiscovery: using bluetooth adapter" << adapterHostInfo.name() << adapterHostInfo.address().toString();
|
m_localDevice = new QBluetoothLocalDevice(adapterHostInfo.address(), this);
|
||||||
m_localDevice = new QBluetoothLocalDevice(adapterHostInfo.address(), this);
|
connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDiscovery::onBluetoothHostModeChanged);
|
||||||
connect(m_localDevice, &QBluetoothLocalDevice::hostModeStateChanged, this, &BluetoothDiscovery::onBluetoothHostModeChanged);
|
onBluetoothHostModeChanged(m_localDevice->hostMode());
|
||||||
onBluetoothHostModeChanged(m_localDevice->hostMode());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_discoveryAgent = new QBluetoothDeviceDiscoveryAgent(m_localDevice->address(), this);
|
m_discoveryAgent = new QBluetoothDeviceDiscoveryAgent(m_localDevice->address(), this);
|
||||||
#else
|
#else
|
||||||
@ -84,6 +82,12 @@ bool BluetoothDiscovery::bluetoothEnabled() const
|
|||||||
|
|
||||||
void BluetoothDiscovery::setBluetoothEnabled(bool enabled)
|
void BluetoothDiscovery::setBluetoothEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
|
m_bluetoothEnabled = enabled;
|
||||||
|
emit bluetoothEnabledChanged(m_bluetoothEnabled);
|
||||||
|
|
||||||
|
if (!m_localDevice)
|
||||||
|
return;
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
m_localDevice->powerOn();
|
m_localDevice->powerOn();
|
||||||
} else {
|
} else {
|
||||||
@ -125,6 +129,8 @@ void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice:
|
|||||||
switch (hostMode) {
|
switch (hostMode) {
|
||||||
case QBluetoothLocalDevice::HostPoweredOff:
|
case QBluetoothLocalDevice::HostPoweredOff:
|
||||||
setBluetoothEnabled(false);
|
setBluetoothEnabled(false);
|
||||||
|
stop();
|
||||||
|
m_deviceInfos->clearModel();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Note: discovery works in all other modes
|
// Note: discovery works in all other modes
|
||||||
@ -186,6 +192,10 @@ void BluetoothDiscovery::start()
|
|||||||
|
|
||||||
m_deviceInfos->clearModel();
|
m_deviceInfos->clearModel();
|
||||||
|
|
||||||
|
if (!m_bluetoothEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "BluetoothDiscovery: Start discovering.";
|
qDebug() << "BluetoothDiscovery: Start discovering.";
|
||||||
m_discoveryAgent->start();
|
m_discoveryAgent->start();
|
||||||
setDiscovering(true);
|
setDiscovering(true);
|
||||||
@ -195,6 +205,9 @@ void BluetoothDiscovery::stop()
|
|||||||
{
|
{
|
||||||
m_enabled = false;
|
m_enabled = false;
|
||||||
|
|
||||||
|
if (!m_discoveryAgent)
|
||||||
|
return;
|
||||||
|
|
||||||
qDebug() << "BluetoothDiscovery: Stop discovering.";
|
qDebug() << "BluetoothDiscovery: Stop discovering.";
|
||||||
m_discoveryAgent->stop();
|
m_discoveryAgent->stop();
|
||||||
setDiscovering(false);
|
setDiscovering(false);
|
||||||
|
|||||||
@ -18,7 +18,7 @@ Page {
|
|||||||
Engine.bluetoothDiscovery.start()
|
Engine.bluetoothDiscovery.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enabled: Engine.bluetoothDiscovery.bluetoothAvailable && !Engine.bluetoothDiscovery.discovering
|
enabled: Engine.bluetoothDiscovery.bluetoothAvailable && Engine.bluetoothDiscovery.bluetoothEnabled && !Engine.bluetoothDiscovery.discovering
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,16 @@ Page {
|
|||||||
|
|
||||||
Label {
|
Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
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.")
|
text: {
|
||||||
|
if (Engine.bluetoothDiscovery.bluetoothAvailable && Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||||
|
return qsTr("Searching for %1 boxes via Bluetooth LE.").arg(app.systemName)
|
||||||
|
} if (Engine.bluetoothDiscovery.bluetoothAvailable && !Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||||
|
return qsTr("Uh oh! Bluetooth is not enabled. Please enable the Bluetooth on this device and restart the application.")
|
||||||
|
} else {
|
||||||
|
return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device and restart the application.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user