Commit d2200025 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

do not needlessly run through Solid::Device::allDevices

Summary:
allDevice is bugging out and having duplicated entires
https://bugs.kde.org/show_bug.cgi?id=416495
this results in garbage in our tree view.
on top of that running through allDevices is entirely pointless
as we can directly construct a Device from the udi we got which
is not only faster, it also lets us bypass the aformentioned
bug since the udi is still unique it's only the objects that
get duped

BUG: 399746
FIXED-IN: 5.18.0

Test Plan: repated plug/unplug of usb drive doesn't cause bogus device entries

Reviewers: apol, ngraham

Reviewed By: apol, ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26788
parent 06d71637
......@@ -146,49 +146,50 @@ void DeviceListing::itemActivatedSlot(QTreeWidgetItem *listItemIn, const int col
void DeviceListing::deviceAddedSlot(const QString &udi)
{
SolidHelper *solhelp = new SolidHelper();
const QList<Solid::Device> list = Solid::Device::allDevices();
foreach (const Solid::Device &dev, list) {
if (dev.udi() == udi) {
Solid::DeviceInterface::Type deviceType = solhelp->deviceType(&dev);
QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this, dev.parentUdi());
// Incase of bad index
if (deviceMap[deviceType] == nullptr) {
QTreeWidgetItem *topItem = topLevelItem(0);
if (!topItem) {
delete solhelp;
return;
}
deviceMap[deviceType] = static_cast<SolDevice *>(topItem);
}
switch (deviceType) {
case Solid::DeviceInterface::Processor:
new SolProcessorDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Camera:
new SolCameraDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::PortableMediaPlayer:
new SolMediaPlayerDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Battery:
new SolBatteryDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::StorageDrive:
new SolStorageDevice(deviceMap[deviceType], dev, SolStorageDevice::NOCHILDREN);
break;
case Solid::DeviceInterface::StorageVolume:
if (parent == nullptr) {
break;
}
new SolVolumeDevice(parent, dev);
break;
default:
break;
}
Solid::Device dev(udi);
if (!dev.isValid()) {
// Probably the device already disappeared again.
return;
}
Solid::DeviceInterface::Type deviceType = solhelp->deviceType(&dev);
QTreeWidgetItem *parent = getTreeWidgetItemFromUdi(this, dev.parentUdi());
// Incase of bad index
if (deviceMap[deviceType] == nullptr) {
QTreeWidgetItem *topItem = topLevelItem(0);
if (!topItem) {
delete solhelp;
return;
}
deviceMap[deviceType] = static_cast<SolDevice *>(topItem);
}
switch (deviceType) {
case Solid::DeviceInterface::Processor:
new SolProcessorDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Camera:
new SolCameraDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::PortableMediaPlayer:
new SolMediaPlayerDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::Battery:
new SolBatteryDevice(deviceMap[deviceType], dev);
break;
case Solid::DeviceInterface::StorageDrive:
new SolStorageDevice(deviceMap[deviceType], dev, SolStorageDevice::NOCHILDREN);
break;
case Solid::DeviceInterface::StorageVolume:
if (parent == nullptr) {
break;
}
new SolVolumeDevice(parent, dev);
break;
default:
break;
}
delete solhelp;
}
......
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