BluetoothDiscovery is not a member of Engine any more rather a standalone tool

This commit is contained in:
Michael Zanetti 2018-08-31 20:00:48 +02:00
parent 56a87e9e97
commit 647edaf72e
7 changed files with 41 additions and 63 deletions

View File

@ -71,11 +71,6 @@ BasicConfiguration *Engine::basicConfiguration() const
return m_basicConfiguration; return m_basicConfiguration;
} }
BluetoothDiscovery *Engine::bluetoothDiscovery() const
{
return m_bluetoothDiscovery;
}
AWSClient *Engine::awsClient() const AWSClient *Engine::awsClient() const
{ {
return m_aws; return m_aws;
@ -111,7 +106,6 @@ Engine::Engine(QObject *parent) :
m_logManager(new LogManager(m_jsonRpcClient, this)), m_logManager(new LogManager(m_jsonRpcClient, this)),
m_tagsManager(new TagsManager(m_jsonRpcClient, this)), m_tagsManager(new TagsManager(m_jsonRpcClient, this)),
m_basicConfiguration(new BasicConfiguration(m_jsonRpcClient, this)), m_basicConfiguration(new BasicConfiguration(m_jsonRpcClient, this)),
m_bluetoothDiscovery(new BluetoothDiscovery(this)),
m_aws(new AWSClient(this)) m_aws(new AWSClient(this))
{ {
m_connection->registerTransport(new TcpSocketTransportFactory()); m_connection->registerTransport(new TcpSocketTransportFactory());

View File

@ -43,7 +43,6 @@ class Engine : public QObject
Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT) Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT)
Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient CONSTANT) Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient CONSTANT)
Q_PROPERTY(BasicConfiguration* basicConfiguration READ basicConfiguration CONSTANT) Q_PROPERTY(BasicConfiguration* basicConfiguration READ basicConfiguration CONSTANT)
Q_PROPERTY(BluetoothDiscovery* bluetoothDiscovery READ bluetoothDiscovery CONSTANT)
Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT) Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
public: public:
@ -59,7 +58,6 @@ public:
JsonRpcClient *jsonRpcClient() const; JsonRpcClient *jsonRpcClient() const;
LogManager *logManager() const; LogManager *logManager() const;
BasicConfiguration *basicConfiguration() const; BasicConfiguration *basicConfiguration() const;
BluetoothDiscovery *bluetoothDiscovery() const;
AWSClient* awsClient() const; AWSClient* awsClient() const;
Q_INVOKABLE void deployCertificate(); Q_INVOKABLE void deployCertificate();
@ -75,7 +73,6 @@ private:
LogManager *m_logManager; LogManager *m_logManager;
TagsManager *m_tagsManager; TagsManager *m_tagsManager;
BasicConfiguration *m_basicConfiguration; BasicConfiguration *m_basicConfiguration;
BluetoothDiscovery *m_bluetoothDiscovery;
AWSClient *m_aws; AWSClient *m_aws;
private slots: private slots:

View File

@ -165,7 +165,7 @@ void registerQmlTypes() {
qmlRegisterType<TagsProxyModel>(uri, 1, 0, "TagsProxyModel"); qmlRegisterType<TagsProxyModel>(uri, 1, 0, "TagsProxyModel");
qmlRegisterType<NetworkManagerControler>(uri, 1, 0, "NetworkManagerControler"); 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<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<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."); qmlRegisterUncreatableType<WirelessSetupManager>(uri, 1, 0, "WirelessSetupManager", "Can't create this in QML. Get it from the NetworkManagerControler.");

View File

@ -38,7 +38,7 @@ public:
BluetoothDeviceInfoRoleLe BluetoothDeviceInfoRoleLe
}; };
explicit BluetoothDeviceInfos(QObject *parent = 0); explicit BluetoothDeviceInfos(QObject *parent = nullptr);
QList<BluetoothDeviceInfo *> deviceInfos(); QList<BluetoothDeviceInfo *> deviceInfos();

View File

@ -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; if (m_bluetoothDeviceInfo != bluetoothDeviceInfo) {
emit nameChanged(); m_bluetoothDeviceInfo = bluetoothDeviceInfo;
} emit bluetoothDeviceInfoChanged();
}
QString NetworkManagerControler::address() const
{
return m_address;
}
void NetworkManagerControler::setAddress(const QString &address)
{
m_address = address;
} }
WirelessSetupManager *NetworkManagerControler::manager() WirelessSetupManager *NetworkManagerControler::manager()
@ -56,26 +48,23 @@ WirelessSetupManager *NetworkManagerControler::manager()
void NetworkManagerControler::connectDevice() void NetworkManagerControler::connectDevice()
{ {
if (!m_bluetoothDeviceInfo) {
qWarning() << "Can't connect to device. bluetoothDeviceInfo not set.";
return;
}
if (m_wirelessSetupManager) { if (m_wirelessSetupManager) {
delete m_wirelessSetupManager; delete m_wirelessSetupManager;
m_wirelessSetupManager = nullptr; m_wirelessSetupManager = nullptr;
emit managerChanged(); emit managerChanged();
} }
// find device info for this address and name if (!m_bluetoothDeviceInfo) {
BluetoothDeviceInfo *deviceInfo = nullptr; qDebug() << "Could not connect to device. There is no device info for" << m_bluetoothDeviceInfo->name() << m_bluetoothDeviceInfo->address();
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();
return; return;
} }
m_wirelessSetupManager = new WirelessSetupManager(deviceInfo->getBluetoothDeviceInfo(), this); m_wirelessSetupManager = new WirelessSetupManager(m_bluetoothDeviceInfo->getBluetoothDeviceInfo(), this);
emit managerChanged(); emit managerChanged();
m_wirelessSetupManager->connectDevice(); m_wirelessSetupManager->connectDevice();

View File

@ -26,38 +26,34 @@
#include <QObject> #include <QObject>
#include <QBluetoothDeviceInfo> #include <QBluetoothDeviceInfo>
#include "bluetoothdeviceinfo.h"
#include "wirelesssetupmanager.h" #include "wirelesssetupmanager.h"
class NetworkManagerControler : public QObject class NetworkManagerControler : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(BluetoothDeviceInfo* bluetoothDeviceInfo READ bluetoothDeviceInfo WRITE setBluetoothDeviceInfo)
Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
Q_PROPERTY(WirelessSetupManager *manager READ manager NOTIFY managerChanged) Q_PROPERTY(WirelessSetupManager *manager READ manager NOTIFY managerChanged)
public: public:
explicit NetworkManagerControler(QObject *parent = nullptr); explicit NetworkManagerControler(QObject *parent = nullptr);
QString name() const; BluetoothDeviceInfo* bluetoothDeviceInfo() const;
void setName(const QString &name); void setBluetoothDeviceInfo(BluetoothDeviceInfo* bluetoothDeviceInfo);
QString address() const;
void setAddress(const QString &address);
WirelessSetupManager *manager(); WirelessSetupManager *manager();
Q_INVOKABLE void connectDevice(); Q_INVOKABLE void connectDevice();
private: private:
QString m_name; BluetoothDeviceInfo* m_bluetoothDeviceInfo = nullptr;
QString m_address;
WirelessSetupManager *m_wirelessSetupManager = nullptr; WirelessSetupManager *m_wirelessSetupManager = nullptr;
signals: signals:
void managerChanged(); void managerChanged();
void nameChanged(); void nameChanged();
void addressChanged(); void bluetoothDeviceInfoChanged();
}; };

View File

@ -12,18 +12,22 @@ Page {
onBackPressed: pageStack.pop() onBackPressed: pageStack.pop()
} }
Component.onCompleted: Engine.bluetoothDiscovery.start() Component.onCompleted: bluetoothDiscovery.start()
function setupDevice(name, btAddress) { BluetoothDiscovery {
Engine.bluetoothDiscovery.stop() id: bluetoothDiscovery
pageStack.push(connectingPageComponent, { name: name, address: btAddress } ) }
function setupDevice(btDeviceInfo) {
bluetoothDiscovery.stop()
pageStack.push(connectingPageComponent, { bluetoothDeviceInfo: btDeviceInfo } )
} }
Connections { Connections {
target: pageStack target: pageStack
onCurrentItemChanged: { onCurrentItemChanged: {
if (pageStack.currentItem === root) { if (pageStack.currentItem === root) {
Engine.bluetoothDiscovery.start(); bluetoothDiscovery.start();
} }
} }
} }
@ -43,17 +47,17 @@ Page {
text: { text: {
if (Qt.platform.os === "ios") { 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) 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.") return qsTr("Uh oh! Bluetooth is not enabled. Please enable the Bluetooth on this device and restart the application.")
} else { } else {
return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device and restart the application.") return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device and restart the application.")
} }
} else { } 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) 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.") return qsTr("Uh oh! Bluetooth is not enabled. Please enable the Bluetooth on this device.")
} else { } else {
return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device.") return qsTr("Uh oh! Bluetooth is not available. Please make sure Bluetooth is enabled on this device.")
@ -67,7 +71,7 @@ Page {
} }
BusyIndicator { BusyIndicator {
running: Engine.bluetoothDiscovery.discovering running: bluetoothDiscovery.discovering
} }
} }
@ -77,7 +81,7 @@ Page {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
model: Engine.bluetoothDiscovery.deviceInfos model: bluetoothDiscovery.deviceInfos
clip: true clip: true
delegate: MeaListItemDelegate { delegate: MeaListItemDelegate {
@ -87,7 +91,7 @@ Page {
subText: model.address subText: model.address
onClicked: { onClicked: {
root.setupDevice(model.name, model.address) root.setupDevice(bluetoothDiscovery.deviceInfos.get(index))
} }
} }
} }
@ -198,13 +202,11 @@ Page {
onBackPressed: pageStack.pop() onBackPressed: pageStack.pop()
} }
property string name property var bluetoothDeviceInfo
property string address
NetworkManagerControler { NetworkManagerControler {
id: networkManger id: networkManger
name: connectingPage.name bluetoothDeviceInfo: connectingPage.bluetoothDeviceInfo
address: connectingPage.address
Component.onCompleted: networkManger.connectDevice() Component.onCompleted: networkManger.connectDevice()
} }