From bd0ef7da742afa054c619a53a88f3ad8f46ba391 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 15 Dec 2021 17:43:20 +0100 Subject: [PATCH] Some more fixes in the bluetooth discovery --- libnymea-app/wifisetup/bluetoothdiscovery.cpp | 15 ++++++++++----- nymea-app/ui/components/ThingContextMenu.qml | 4 +++- .../ui/devicepages/NotificationsDevicePage.qml | 7 ------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libnymea-app/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp index ca888eff..91c996bd 100644 --- a/libnymea-app/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app/wifisetup/bluetoothdiscovery.cpp @@ -124,11 +124,10 @@ bool BluetoothDiscovery::discovering() const void BluetoothDiscovery::setDiscoveryEnabled(bool discoveryEnabled) { - if (m_discoveryEnabled == discoveryEnabled) { - return; + if (m_discoveryEnabled != discoveryEnabled) { + m_discoveryEnabled = discoveryEnabled; + emit discoveryEnabledChanged(m_discoveryEnabled); } - m_discoveryEnabled = discoveryEnabled; - emit discoveryEnabledChanged(m_discoveryEnabled); if (m_discoveryEnabled) { start(); @@ -171,6 +170,9 @@ void BluetoothDiscovery::onBluetoothHostModeChanged(const QBluetoothLocalDevice: m_discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); #endif connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothDiscovery::deviceDiscovered); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &BluetoothDiscovery::deviceDiscovered); +#endif connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BluetoothDiscovery::discoveryFinished); connect(m_discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BluetoothDiscovery::discoveryCancelled); connect(m_discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(onError(QBluetoothDeviceDiscoveryAgent::Error))); @@ -250,7 +252,10 @@ void BluetoothDiscovery::start() m_discoveryAgent->stop(); } - m_deviceInfos->clearModel(); + foreach (const QBluetoothDeviceInfo &info, m_discoveryAgent->discoveredDevices()) { + qCDebug(dcBtWiFiSetup()) << "Already discovered device:" << info.name(); + deviceDiscovered(info); + } qCDebug(dcBtWiFiSetup) << "BluetoothDiscovery: Starting discovery."; m_discoveryAgent->start(); diff --git a/nymea-app/ui/components/ThingContextMenu.qml b/nymea-app/ui/components/ThingContextMenu.qml index c4387663..85601652 100644 --- a/nymea-app/ui/components/ThingContextMenu.qml +++ b/nymea-app/ui/components/ThingContextMenu.qml @@ -12,7 +12,9 @@ AutoSizeMenu { property bool showLogs: true Component.onCompleted: { - root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Magic"), iconSource: "../images/magic.svg", functionName: "openThingMagicPage"})) + if (Configuration.magicEnabled) { + root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Magic"), iconSource: "../images/magic.svg", functionName: "openThingMagicPage"})) + } if (root.showDetails) { root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Details"), iconSource: "../images/info.svg", functionName: "openGenericThingPage"})) diff --git a/nymea-app/ui/devicepages/NotificationsDevicePage.qml b/nymea-app/ui/devicepages/NotificationsDevicePage.qml index 4d89a8b1..7be0d1a3 100644 --- a/nymea-app/ui/devicepages/NotificationsDevicePage.qml +++ b/nymea-app/ui/devicepages/NotificationsDevicePage.qml @@ -160,13 +160,6 @@ ThingPageBase { readonly property string title: model.value.trim().replace(/, ?.*/, "") readonly property string text: model.value.trim().replace(/.*, ?/, "") - onPressAndHold: { - var contextMenuComponent = Qt.createComponent("../components/ThingContextMenu.qml"); - var contextMenu = contextMenuComponent.createObject(root, { thing: root.thing }) - contextMenu.x = Qt.binding(function() { return (root.width - contextMenu.width) / 2 }) - contextMenu.open() - } - contentItem: RowLayout { ColumnLayout { Label {