Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/DiscoveryPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public slots:
void refreshClicked();

private slots:
void onDeviceSelectionChanged(int index);
void onDeviceDiscovered(const QString &address, quint16 port);

private:
Expand Down
17 changes: 11 additions & 6 deletions src/DiscoveryPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "DiscoveryPanel.h"
#include "DiscoveryPanel.h"
#include "DiscoveryService.h"

#include <QVBoxLayout>
Expand Down Expand Up @@ -42,6 +42,8 @@ void DiscoveryPanel::setupUI() {
refreshButton->setFixedWidth(80);
devicesCombo->setMinimumWidth(200);

connectButton->setEnabled(false);

containerLayout->addWidget(devicesCombo);
containerLayout->addWidget(connectButton);
containerLayout->addWidget(refreshButton);
Expand All @@ -50,6 +52,10 @@ void DiscoveryPanel::setupUI() {
mainLayout->addStretch();
mainLayout->addWidget(container);

connect(devicesCombo,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DiscoveryPanel::onDeviceSelectionChanged);
connect(connectButton, &QPushButton::clicked, this, &DiscoveryPanel::connectClicked);
connect(refreshButton, &QPushButton::clicked, this, &DiscoveryPanel::refreshClicked);
}
Expand All @@ -59,10 +65,6 @@ void DiscoveryPanel::onDeviceDiscovered(const QString &address, quint16 port) {
discoveredDevices.insert(address, port);
devicesCombo->addItem(QString("Device @ %1").arg(address), address);

if (devicesCombo->count() == 1) {
connectButton->setEnabled(true);
}

statusLabel->setText(QString("Found %1 device(s)").arg(discoveredDevices.size()));
}
}
Expand All @@ -77,7 +79,10 @@ quint16 DiscoveryPanel::currentDevicePort() const {
if (address.isEmpty()) return 0;
return discoveredDevices.value(address);
}

void DiscoveryPanel::onDeviceSelectionChanged(int index)
{
connectButton->setEnabled(index >= 0 && !isConnected);
}
void DiscoveryPanel::updateConnectionStatus(bool connected) {
isConnected = connected;
connectButton->setEnabled(!connected && devicesCombo->count() > 0);
Expand Down