Commit 5936057e authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Network Plugin: Do not list devices that are not connected

Unconnected devices do not have any useful data we can expose, so simply
hide them completely instead of showing devices that do not provide
useful data.
parent 525a21a9
...@@ -88,13 +88,8 @@ NetworkManagerDevice::~NetworkManagerDevice() ...@@ -88,13 +88,8 @@ NetworkManagerDevice::~NetworkManagerDevice()
void NetworkManagerDevice::update() void NetworkManagerDevice::update()
{ {
if (m_device->activeConnection()) {
setName(m_device->activeConnection()->connection()->name()); setName(m_device->activeConnection()->connection()->name());
m_networkSensor->setValue(name()); m_networkSensor->setValue(name());
} else {
setName(m_device->ipInterfaceName());
m_networkSensor->setValue(QString{});
}
if (m_device->ipV4Config().isValid()) { if (m_device->ipV4Config().isValid()) {
m_ipv4Sensor->setValue(m_device->ipV4Config().addresses().at(0).ip().toString()); m_ipv4Sensor->setValue(m_device->ipV4Config().addresses().at(0).ip().toString());
...@@ -177,7 +172,23 @@ void NetworkManagerBackend::onDeviceAdded(const QString& uni) ...@@ -177,7 +172,23 @@ void NetworkManagerBackend::onDeviceAdded(const QString& uni)
return; return;
} }
auto nmDevice = new NetworkManagerDevice(device->ipInterfaceName(), device); connect(device.get(), &NetworkManager::Device::activeConnectionChanged, this, [this, device, uni]() {
if (device->activeConnection()) {
onDeviceAdded(uni);
} else {
onDeviceRemoved(uni);
}
}, Qt::UniqueConnection);
if (!device->activeConnection()) {
return;
}
if (m_devices.contains(uni)) {
return;
}
auto nmDevice = new NetworkManagerDevice(device->interfaceName(), device);
m_devices.insert(uni, nmDevice); m_devices.insert(uni, nmDevice);
Q_EMIT deviceAdded(nmDevice); Q_EMIT deviceAdded(nmDevice);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment