diff --git a/libnymea-app/models/sortfilterproxymodel.cpp b/libnymea-app/models/sortfilterproxymodel.cpp index 87a1e447..2f65fde5 100644 --- a/libnymea-app/models/sortfilterproxymodel.cpp +++ b/libnymea-app/models/sortfilterproxymodel.cpp @@ -68,6 +68,11 @@ QVariant SortFilterProxyModel::data(int row, const QString &role) const return QSortFilterProxyModel::data(index(row, 0), roleId); } +int SortFilterProxyModel::mapToSource(int index) const +{ + return QSortFilterProxyModel::mapToSource(this->index(index, 0)).row(); +} + bool SortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!m_filterList.isEmpty() && !m_filterRoleName.isEmpty()) { diff --git a/libnymea-app/models/sortfilterproxymodel.h b/libnymea-app/models/sortfilterproxymodel.h index 559562f7..1115f1f5 100644 --- a/libnymea-app/models/sortfilterproxymodel.h +++ b/libnymea-app/models/sortfilterproxymodel.h @@ -27,6 +27,7 @@ public: void setSortOrder(Qt::SortOrder sortOrder); Q_INVOKABLE QVariant data(int row, const QString &role) const; + Q_INVOKABLE int mapToSource(int index) const; signals: void filterRoleNameChanged(); diff --git a/libnymea-app/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp index 41857bb7..f4f065c6 100644 --- a/libnymea-app/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app/wifisetup/bluetoothdiscovery.cpp @@ -124,7 +124,7 @@ void BluetoothDiscovery::setDiscoveryEnabled(bool discoveryEnabled) return; } m_discoveryEnabled = discoveryEnabled; - emit discoveringChanged(); + emit discoveryEnabledChanged(m_discoveryEnabled); if (m_discoveryEnabled) { start(); @@ -176,8 +176,7 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo { if (!deviceInfo.isValid() || !deviceInfo.coreConfigurations().testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration) - || deviceInfo.name().isEmpty() - || deviceInfo.isCached()) { + || deviceInfo.name().isEmpty()) { return; } @@ -235,7 +234,7 @@ void BluetoothDiscovery::start() m_discoveryAgent->stop(); } -// m_deviceInfos->clearModel(); + m_deviceInfos->clearModel(); qDebug() << "BluetoothDiscovery: Starting discovery."; m_discoveryAgent->start(); diff --git a/libnymea-app/wifisetup/btwifisetup.cpp b/libnymea-app/wifisetup/btwifisetup.cpp index d4bcc187..17321c8a 100644 --- a/libnymea-app/wifisetup/btwifisetup.cpp +++ b/libnymea-app/wifisetup/btwifisetup.cpp @@ -30,7 +30,7 @@ BtWiFiSetup::BtWiFiSetup(QObject *parent) : QObject(parent) void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) { - qDebug() << "device" << device; + qDebug() << "Connecting to device" << device->address() << device->name(); if (m_btController) { delete m_btController; m_currentConnection = nullptr; @@ -38,7 +38,6 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) m_accessPoints->clearModel(); m_bluetoothStatus = BluetoothStatusDisconnected; emit bluetoothStatusChanged(m_bluetoothStatus); - } m_btController = QLowEnergyController::createCentral(device->bluetoothDeviceInfo(), this); @@ -47,7 +46,7 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) m_btController->discoverServices(); m_bluetoothStatus = BluetoothStatusConnectedToBluetooth; emit bluetoothStatusChanged(m_bluetoothStatus); - }); + }, Qt::QueuedConnection); connect(m_btController, &QLowEnergyController::disconnected, this, [this](){ qDebug() << "Bluetooth disconnected"; @@ -58,13 +57,13 @@ void BtWiFiSetup::connectToDevice(const BluetoothDeviceInfo *device) m_currentConnection = nullptr; emit currentConnectionChanged(); m_accessPoints->clearModel(); - }); + }, Qt::QueuedConnection); typedef void (QLowEnergyController::*errorsSignal)(QLowEnergyController::Error); connect(m_btController, static_cast(&QLowEnergyController::error), this, [this](QLowEnergyController::Error error){ qDebug() << "Bluetooth error:" << error; emit this->bluetoothConnectionError(); - }); + }, Qt::QueuedConnection); connect(m_btController, &QLowEnergyController::discoveryFinished, this, [this](){ qDebug() << "Bluetooth service discovery finished"; @@ -85,8 +84,9 @@ void BtWiFiSetup::disconnectFromDevice() void BtWiFiSetup::connectDeviceToWiFi(const QString &ssid, const QString &password) { - if (m_bluetoothStatus != BluetoothStatusConnectedToBluetooth) { + if (m_bluetoothStatus < BluetoothStatusConnectedToBluetooth) { qWarning() << "Cannot connect to wifi in state" << m_bluetoothStatus; + return; } QVariantMap request; @@ -219,7 +219,12 @@ void BtWiFiSetup::setupServices() if (!m_wifiService || !m_deviceInformationService || !m_networkService) { qWarning() << "Required services not found on remote device."; - m_btController->disconnectFromDevice(); + if (m_btController->property("retries").toInt() < 3) { + m_btController->discoverServices(); + m_btController->setProperty("retries", m_btController->property("retries").toInt() + 1); + } else { + m_btController->disconnectFromDevice(); + } return; } @@ -322,6 +327,7 @@ void BtWiFiSetup::processWiFiPacket(const QVariantMap &data) WirelessServiceResponse responseCode = (WirelessServiceResponse)data.value("r").toInt(); if (responseCode != WirelessServiceResponseSuccess) { qWarning() << "Error in wifi command" << command << ":" << responseCode; + emit wifiSetupError(); return; }