BluetoothDiscovery is not a member of Engine any more rather a standalone tool
This commit is contained in:
parent
56a87e9e97
commit
647edaf72e
@ -71,11 +71,6 @@ BasicConfiguration *Engine::basicConfiguration() const
|
||||
return m_basicConfiguration;
|
||||
}
|
||||
|
||||
BluetoothDiscovery *Engine::bluetoothDiscovery() const
|
||||
{
|
||||
return m_bluetoothDiscovery;
|
||||
}
|
||||
|
||||
AWSClient *Engine::awsClient() const
|
||||
{
|
||||
return m_aws;
|
||||
@ -111,7 +106,6 @@ Engine::Engine(QObject *parent) :
|
||||
m_logManager(new LogManager(m_jsonRpcClient, this)),
|
||||
m_tagsManager(new TagsManager(m_jsonRpcClient, this)),
|
||||
m_basicConfiguration(new BasicConfiguration(m_jsonRpcClient, this)),
|
||||
m_bluetoothDiscovery(new BluetoothDiscovery(this)),
|
||||
m_aws(new AWSClient(this))
|
||||
{
|
||||
m_connection->registerTransport(new TcpSocketTransportFactory());
|
||||
|
||||
@ -43,7 +43,6 @@ class Engine : public QObject
|
||||
Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT)
|
||||
Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient CONSTANT)
|
||||
Q_PROPERTY(BasicConfiguration* basicConfiguration READ basicConfiguration CONSTANT)
|
||||
Q_PROPERTY(BluetoothDiscovery* bluetoothDiscovery READ bluetoothDiscovery CONSTANT)
|
||||
Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
|
||||
|
||||
public:
|
||||
@ -59,7 +58,6 @@ public:
|
||||
JsonRpcClient *jsonRpcClient() const;
|
||||
LogManager *logManager() const;
|
||||
BasicConfiguration *basicConfiguration() const;
|
||||
BluetoothDiscovery *bluetoothDiscovery() const;
|
||||
AWSClient* awsClient() const;
|
||||
|
||||
Q_INVOKABLE void deployCertificate();
|
||||
@ -75,7 +73,6 @@ private:
|
||||
LogManager *m_logManager;
|
||||
TagsManager *m_tagsManager;
|
||||
BasicConfiguration *m_basicConfiguration;
|
||||
BluetoothDiscovery *m_bluetoothDiscovery;
|
||||
AWSClient *m_aws;
|
||||
|
||||
private slots:
|
||||
|
||||
@ -165,7 +165,7 @@ void registerQmlTypes() {
|
||||
qmlRegisterType<TagsProxyModel>(uri, 1, 0, "TagsProxyModel");
|
||||
|
||||
qmlRegisterType<NetworkManagerControler>(uri, 1, 0, "NetworkManagerControler");
|
||||
qmlRegisterUncreatableType<BluetoothDiscovery>(uri, 1, 0, "BluetoothDiscovery", "Can't create this in QML. Get it from the Engine instance.");
|
||||
qmlRegisterType<BluetoothDiscovery>(uri, 1, 0, "BluetoothDiscovery");
|
||||
qmlRegisterUncreatableType<BluetoothDeviceInfo>(uri, 1, 0, "BluetoothDeviceInfo", "Can't create this in QML. Get it from the DeviceInfos.");
|
||||
qmlRegisterUncreatableType<BluetoothDeviceInfos>(uri, 1, 0, "BluetoothDeviceInfos", "Can't create this in QML. Get it from the BluetoothDiscovery.");
|
||||
qmlRegisterUncreatableType<WirelessSetupManager>(uri, 1, 0, "WirelessSetupManager", "Can't create this in QML. Get it from the NetworkManagerControler.");
|
||||
|
||||
@ -38,7 +38,7 @@ public:
|
||||
BluetoothDeviceInfoRoleLe
|
||||
};
|
||||
|
||||
explicit BluetoothDeviceInfos(QObject *parent = 0);
|
||||
explicit BluetoothDeviceInfos(QObject *parent = nullptr);
|
||||
|
||||
QList<BluetoothDeviceInfo *> deviceInfos();
|
||||
|
||||
|
||||
@ -28,25 +28,17 @@ NetworkManagerControler::NetworkManagerControler(QObject *parent) : QObject(pare
|
||||
|
||||
}
|
||||
|
||||
QString NetworkManagerControler::name() const
|
||||
BluetoothDeviceInfo *NetworkManagerControler::bluetoothDeviceInfo() const
|
||||
{
|
||||
return m_name;
|
||||
return m_bluetoothDeviceInfo;
|
||||
}
|
||||
|
||||
void NetworkManagerControler::setName(const QString &name)
|
||||
void NetworkManagerControler::setBluetoothDeviceInfo(BluetoothDeviceInfo *bluetoothDeviceInfo)
|
||||
{
|
||||
m_name = name;
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
QString NetworkManagerControler::address() const
|
||||
{
|
||||
return m_address;
|
||||
}
|
||||
|
||||
void NetworkManagerControler::setAddress(const QString &address)
|
||||
{
|
||||
m_address = address;
|
||||
if (m_bluetoothDeviceInfo != bluetoothDeviceInfo) {
|
||||
m_bluetoothDeviceInfo = bluetoothDeviceInfo;
|
||||
emit bluetoothDeviceInfoChanged();
|
||||
}
|
||||
}
|
||||
|
||||
WirelessSetupManager *NetworkManagerControler::manager()
|
||||
@ -56,26 +48,23 @@ WirelessSetupManager *NetworkManagerControler::manager()
|
||||
|
||||
void NetworkManagerControler::connectDevice()
|
||||
{
|
||||
if (!m_bluetoothDeviceInfo) {
|
||||
qWarning() << "Can't connect to device. bluetoothDeviceInfo not set.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_wirelessSetupManager) {
|
||||
delete m_wirelessSetupManager;
|
||||
m_wirelessSetupManager = nullptr;
|
||||
emit managerChanged();
|
||||
}
|
||||
|
||||
// find device info for this address and name
|
||||
BluetoothDeviceInfo *deviceInfo = nullptr;
|
||||
foreach (BluetoothDeviceInfo *deviceInformation, Engine::instance()->bluetoothDiscovery()->deviceInfos()->deviceInfos()) {
|
||||
if (deviceInformation->address() == address() && deviceInformation->name() == name()) {
|
||||
deviceInfo = deviceInformation;
|
||||
}
|
||||
}
|
||||
|
||||
if (!deviceInfo) {
|
||||
qDebug() << "Could not connect to device. There is no device info for" << name() << address();
|
||||
if (!m_bluetoothDeviceInfo) {
|
||||
qDebug() << "Could not connect to device. There is no device info for" << m_bluetoothDeviceInfo->name() << m_bluetoothDeviceInfo->address();
|
||||
return;
|
||||
}
|
||||
|
||||
m_wirelessSetupManager = new WirelessSetupManager(deviceInfo->getBluetoothDeviceInfo(), this);
|
||||
m_wirelessSetupManager = new WirelessSetupManager(m_bluetoothDeviceInfo->getBluetoothDeviceInfo(), this);
|
||||
emit managerChanged();
|
||||
|
||||
m_wirelessSetupManager->connectDevice();
|
||||
|
||||
@ -26,38 +26,34 @@
|
||||
#include <QObject>
|
||||
#include <QBluetoothDeviceInfo>
|
||||
|
||||
#include "bluetoothdeviceinfo.h"
|
||||
#include "wirelesssetupmanager.h"
|
||||
|
||||
class NetworkManagerControler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
|
||||
Q_PROPERTY(BluetoothDeviceInfo* bluetoothDeviceInfo READ bluetoothDeviceInfo WRITE setBluetoothDeviceInfo)
|
||||
Q_PROPERTY(WirelessSetupManager *manager READ manager NOTIFY managerChanged)
|
||||
|
||||
public:
|
||||
explicit NetworkManagerControler(QObject *parent = nullptr);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QString address() const;
|
||||
void setAddress(const QString &address);
|
||||
BluetoothDeviceInfo* bluetoothDeviceInfo() const;
|
||||
void setBluetoothDeviceInfo(BluetoothDeviceInfo* bluetoothDeviceInfo);
|
||||
|
||||
WirelessSetupManager *manager();
|
||||
|
||||
Q_INVOKABLE void connectDevice();
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_address;
|
||||
BluetoothDeviceInfo* m_bluetoothDeviceInfo = nullptr;
|
||||
|
||||
WirelessSetupManager *m_wirelessSetupManager = nullptr;
|
||||
|
||||
signals:
|
||||
void managerChanged();
|
||||
void nameChanged();
|
||||
void addressChanged();
|
||||
void bluetoothDeviceInfoChanged();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -12,18 +12,22 @@ Page {
|
||||
onBackPressed: pageStack.pop()
|
||||
}
|
||||
|
||||
Component.onCompleted: Engine.bluetoothDiscovery.start()
|
||||
Component.onCompleted: bluetoothDiscovery.start()
|
||||
|
||||
function setupDevice(name, btAddress) {
|
||||
Engine.bluetoothDiscovery.stop()
|
||||
pageStack.push(connectingPageComponent, { name: name, address: btAddress } )
|
||||
BluetoothDiscovery {
|
||||
id: bluetoothDiscovery
|
||||
}
|
||||
|
||||
function setupDevice(btDeviceInfo) {
|
||||
bluetoothDiscovery.stop()
|
||||
pageStack.push(connectingPageComponent, { bluetoothDeviceInfo: btDeviceInfo } )
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: pageStack
|
||||
onCurrentItemChanged: {
|
||||
if (pageStack.currentItem === root) {
|
||||
Engine.bluetoothDiscovery.start();
|
||||
bluetoothDiscovery.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,17 +47,17 @@ Page {
|
||||
text: {
|
||||
|
||||
if (Qt.platform.os === "ios") {
|
||||
if (Engine.bluetoothDiscovery.bluetoothAvailable && Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||
if (bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled) {
|
||||
return qsTr("Searching for %1 boxes via Bluetooth LE.").arg(app.systemName)
|
||||
} if (Engine.bluetoothDiscovery.bluetoothAvailable && !Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||
} if (bluetoothDiscovery.bluetoothAvailable && !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.")
|
||||
}
|
||||
} else {
|
||||
if (Engine.bluetoothDiscovery.bluetoothAvailable && Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||
if (bluetoothDiscovery.bluetoothAvailable && bluetoothDiscovery.bluetoothEnabled) {
|
||||
return qsTr("Searching for %1 boxes via Bluetooth LE.").arg(app.systemName)
|
||||
} if (Engine.bluetoothDiscovery.bluetoothAvailable && !Engine.bluetoothDiscovery.bluetoothEnabled) {
|
||||
} if (bluetoothDiscovery.bluetoothAvailable && !bluetoothDiscovery.bluetoothEnabled) {
|
||||
return qsTr("Uh oh! Bluetooth is not enabled. Please enable the Bluetooth on this device.")
|
||||
} else {
|
||||
return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device.")
|
||||
@ -67,7 +71,7 @@ Page {
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
running: Engine.bluetoothDiscovery.discovering
|
||||
running: bluetoothDiscovery.discovering
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +81,7 @@ Page {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
model: Engine.bluetoothDiscovery.deviceInfos
|
||||
model: bluetoothDiscovery.deviceInfos
|
||||
clip: true
|
||||
|
||||
delegate: MeaListItemDelegate {
|
||||
@ -87,7 +91,7 @@ Page {
|
||||
subText: model.address
|
||||
|
||||
onClicked: {
|
||||
root.setupDevice(model.name, model.address)
|
||||
root.setupDevice(bluetoothDiscovery.deviceInfos.get(index))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,13 +202,11 @@ Page {
|
||||
onBackPressed: pageStack.pop()
|
||||
}
|
||||
|
||||
property string name
|
||||
property string address
|
||||
property var bluetoothDeviceInfo
|
||||
|
||||
NetworkManagerControler {
|
||||
id: networkManger
|
||||
name: connectingPage.name
|
||||
address: connectingPage.address
|
||||
bluetoothDeviceInfo: connectingPage.bluetoothDeviceInfo
|
||||
|
||||
Component.onCompleted: networkManger.connectDevice()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user