From b1338caf33c33b8d913939dd85af89b935fe6dfe Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 31 Aug 2018 18:42:57 +0200 Subject: [PATCH] DeviceDiscovery is not using the Engine singleton any more --- libnymea-app-core/devicediscovery.cpp | 24 +++++++++++++++++++++++- libnymea-app-core/devicediscovery.h | 8 ++++++++ nymea-app/ui/NewDeviceWizard.qml | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libnymea-app-core/devicediscovery.cpp b/libnymea-app-core/devicediscovery.cpp index e24ee23e..fb80e008 100644 --- a/libnymea-app-core/devicediscovery.cpp +++ b/libnymea-app-core/devicediscovery.cpp @@ -43,16 +43,38 @@ void DeviceDiscovery::discoverDevices(const QUuid &deviceClassId, const QVariant endResetModel(); emit countChanged(); + if (!m_jsonRpcClient) { + qWarning() << "Cannot discover devices. No JsonRpcClient set"; + return; + } + if (!m_jsonRpcClient->connected()) { + qWarning() << "Cannot discover devices. JsonRpcClient not connected."; + return; + } + QVariantMap params; params.insert("deviceClassId", deviceClassId.toString()); if (!discoveryParams.isEmpty()) { params.insert("discoveryParams", discoveryParams); } - Engine::instance()->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse"); + m_jsonRpcClient->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverDevicesResponse"); m_busy = true; emit busyChanged(); } +JsonRpcClient *DeviceDiscovery::jsonRpcClient() const +{ + return m_jsonRpcClient; +} + +void DeviceDiscovery::setJsonRpcClient(JsonRpcClient *jsonRpcClient) +{ + if (m_jsonRpcClient != jsonRpcClient) { + m_jsonRpcClient = jsonRpcClient; + emit jsonRpcClientChanged(); + } +} + bool DeviceDiscovery::busy() const { return m_busy; diff --git a/libnymea-app-core/devicediscovery.h b/libnymea-app-core/devicediscovery.h index f9bb90b6..45661b5a 100644 --- a/libnymea-app-core/devicediscovery.h +++ b/libnymea-app-core/devicediscovery.h @@ -4,9 +4,12 @@ #include #include +#include "jsonrpc/jsonrpcclient.h" + class DeviceDiscovery : public QAbstractListModel { Q_OBJECT + Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient WRITE setJsonRpcClient) Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) public: @@ -25,6 +28,9 @@ public: Q_INVOKABLE void discoverDevices(const QUuid &deviceClassId, const QVariantList &discoveryParams = {}); + JsonRpcClient* jsonRpcClient() const; + void setJsonRpcClient(JsonRpcClient *jsonRpcClient); + bool busy() const; private slots: @@ -33,6 +39,7 @@ private slots: signals: void busyChanged(); void countChanged(); + void jsonRpcClientChanged(); private: class DeviceDescriptor { @@ -43,6 +50,7 @@ private: QString m_description; }; + JsonRpcClient *m_jsonRpcClient = nullptr; bool m_busy = false; bool contains(const QUuid &deviceDescriptorId) const; diff --git a/nymea-app/ui/NewDeviceWizard.qml b/nymea-app/ui/NewDeviceWizard.qml index 1e670f70..161e6b39 100644 --- a/nymea-app/ui/NewDeviceWizard.qml +++ b/nymea-app/ui/NewDeviceWizard.qml @@ -61,6 +61,7 @@ Page { DeviceDiscovery { id: discovery + jsonRpcClient: Engine.jsonRpcClient } StackView {