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