#ifndef VBLUETOOTH_H #define VBLUETOOTH_H // Qt #include #include #include // Project #include "VBluetoothDeviceInfo.h" #include "GuiController.h" using namespace Gui; using namespace Storage; // forward declarations class tst_views; namespace View { /*! * \brief The VBluetooth class * Interface between the user and underlying bluetooth classes * \details Exposes a list of unpaired and paired bluetooth devices as well as the paired and connection * status of each devices. Interfaces with the bluetooth scanner class to initiate scans, pair, and connect to devices * */ class VBluetooth : public QObject { Q_OBJECT public: explicit VBluetooth(QObject *parent = nullptr); protected: Q_PROPERTY(QVariant devices READ doGetDevices NOTIFY didDevicesChanged) Q_PROPERTY(QVariant pairedDevices READ doGetPairedDevices NOTIFY didPairedDevicesChanged) Q_PROPERTY(QVariant status READ getStatus NOTIFY didStatusChanged) public slots: void doScanForDevices(); QVariant doGetDevices(); QVariant doGetPairedDevices(); void doSelectDevice(const QString &addr, const QString &name); void doSaveMyDevices(const QString &path = Bluetooth_Saved_Devices_Path_JSON); signals: void didDevicesChanged(); void didSelectDevice(const QString &addr, const QString &name); void didScanFinished(); void didStatusChanged(); void didRequestScanForDevices(); void didPairedDevicesChanged(); void didRequestConcurrentSave(QString, QString, bool); void didRequestReconnectToDevice(QBluetoothDeviceInfo); private: QList _unpairedDevices; QList _pairedDevices; QString _status; const QString _lastSelectedDeviceAddrKey = "LastSelectedDevice"; VBluetoothDeviceInfo *_lastSelectedDevice = nullptr; QString getStatus() { return _status; } QString controllerErrorToString(QLowEnergyController::Error error); bool isDeviceAlreadyPaired(const QBluetoothDeviceInfo &deviceInfo); void removeFromDevices(const VBluetoothDeviceInfo *info); void setDeviceConnected(const QBluetoothDeviceInfo &deviceInfo, const bool &connected); void notifyStatusUpdate(const QString &message); private slots: void onScanForDevicesError(QBluetoothDeviceDiscoveryAgent::Error error); void onScanForDevicesFinished(); void onDeviceDiscovered(const QBluetoothDeviceInfo &device); void onConnectingToDevice(); void onControllerError(QLowEnergyController::Error error); void onConnectedToDevice(const QBluetoothDeviceInfo &deviceInfo); void onDisconnectedFromDevice(const QBluetoothDeviceInfo &deviceInfo); void onLoadMyDevices(const QString &path = Bluetooth_Saved_Devices_Path_JSON); void onReconnectToDevice(const VBluetoothDeviceInfo *deviceInfo); void onLoadAndConnectToLastSelectedDevice(const QJsonObject &obj); }; } #endif // VBLUETOOTH_H