subsurface/core/btdiscovery.h
Jan Mulder ba4058667a mobile: enable switching BT on/off during session.
This commit implements possible switching BT on and off during a session,
so not needing a restart of the app when the user forgot to switch
it on when starting the app.

For this, the following needed to be done: 1) create a handler that
reacts on local BT device status changes. 2) repopulate the connection
list in the download screen when a BT status change is detected.

Notice the subtile change of the Q_INVOKABLE btEnabled() function
to a Q_PROPERTY. This gives a nice dynamic behaviour when
switching BT on/off with the app open.

Fixes: #556

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-10-12 09:43:40 +02:00

71 lines
1.7 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef BTDISCOVERY_H
#define BTDISCOVERY_H
#include <QObject>
#include <QString>
#include <QLoggingCategory>
#include <QAbstractListModel>
#include <QBluetoothLocalDevice>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothUuid>
#include "core/libdivecomputer.h"
#if defined(Q_OS_ANDROID)
#include <QAndroidJniObject>
#include <QAndroidJniEnvironment>
#endif
void saveBtDeviceInfo(const char* devaddr, QBluetoothDeviceInfo deviceInfo);
QBluetoothDeviceInfo getBtDeviceInfo(const char* devaddr);
class BTDiscovery : public QObject {
Q_OBJECT
public:
BTDiscovery(QObject *parent = NULL);
~BTDiscovery();
static BTDiscovery *instance();
struct btPairedDevice {
QString address;
QString name;
};
struct btVendorProduct {
btPairedDevice btpdi;
dc_descriptor_t *dcDescriptor;
int vendorIdx;
int productIdx;
};
void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
void btDeviceDiscoveredMain(const btPairedDevice &device);
bool btAvailable() const;
#if defined(Q_OS_ANDROID)
void getBluetoothDevices();
#endif
QList<btVendorProduct> getBtDcs();
QBluetoothLocalDevice localBtDevice;
void BTDiscoveryReDiscover();
private:
static BTDiscovery *m_instance;
bool m_btValid;
QList<struct btVendorProduct> btDCs; // recognized DCs
QList<struct btVendorProduct> btAllDevices; // all paired BT stuff
#if defined(Q_OS_ANDROID)
bool checkException(const char* method, const QAndroidJniObject* obj);
#endif
QList<struct btPairedDevice> btPairedDevices;
QBluetoothDeviceDiscoveryAgent *discoveryAgent;
signals:
void dcVendorChanged();
void dcProductChanged();
void dcBtChanged();
};
#endif // BTDISCOVERY_H