BT support: track if Bluetooth is available

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-07-12 04:13:25 -07:00
parent 0c5f373ec0
commit bec5f3c44f
2 changed files with 10 additions and 0 deletions

View file

@ -61,6 +61,7 @@ BTDiscovery::BTDiscovery(QObject *parent)
localBtDevice.hostMode() == QBluetoothLocalDevice::HostConnectable) { localBtDevice.hostMode() == QBluetoothLocalDevice::HostConnectable) {
btPairedDevices.clear(); btPairedDevices.clear();
qDebug() << "localDevice " + localBtDevice.name() + " is valid, starting discovery"; qDebug() << "localDevice " + localBtDevice.name() + " is valid, starting discovery";
m_btValid = true;
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BTDiscovery::btDeviceDiscovered); connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BTDiscovery::btDeviceDiscovered);
@ -84,6 +85,7 @@ BTDiscovery::BTDiscovery(QObject *parent)
#endif #endif
} else { } else {
qDebug() << "localBtDevice isn't valid"; qDebug() << "localBtDevice isn't valid";
m_btValid = false;
} }
#endif #endif
} }
@ -175,6 +177,12 @@ QList<BTDiscovery::btVendorProduct> BTDiscovery::getBtDcs()
return btDCs; return btDCs;
} }
bool BTDiscovery::btAvailable() const
{
return m_btValid;
}
// Android: As Qt is not able to pull the pairing data from a device, i // Android: As Qt is not able to pull the pairing data from a device, i
// a lengthy discovery process is needed to see what devices are paired. On // a lengthy discovery process is needed to see what devices are paired. On
// https://forum.qt.io/topic/46075/solved-bluetooth-list-paired-devices // https://forum.qt.io/topic/46075/solved-bluetooth-list-paired-devices

View file

@ -40,6 +40,7 @@ public:
void btDeviceDiscovered(const QBluetoothDeviceInfo &device); void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
void btDeviceDiscoveredMain(const btPairedDevice &device); void btDeviceDiscoveredMain(const btPairedDevice &device);
bool btAvailable() const;
#if defined(Q_OS_ANDROID) #if defined(Q_OS_ANDROID)
void getBluetoothDevices(); void getBluetoothDevices();
#endif #endif
@ -47,6 +48,7 @@ public:
#endif #endif
private: private:
static BTDiscovery *m_instance; static BTDiscovery *m_instance;
bool m_btValid;
#if defined(BT_SUPPORT) #if defined(BT_SUPPORT)
QList<struct btVendorProduct> btDCs; // recognized DCs QList<struct btVendorProduct> btDCs; // recognized DCs
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff QList<struct btVendorProduct> btAllDevices; // all paired BT stuff