summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2022-03-06 16:56:54 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2022-03-06 17:04:12 +0900
commitdcbcede7239b810507d4f1c86d5f296a15095319 (patch)
treee640920f62d2ebc9e577c8cfb295fd298e6fe5c7
parent65d242a2b895c9c2867522f74c0245b806b6da34 (diff)
downloadtdebase-dcbcede7.tar.gz
tdebase-dcbcede7.zip
tdehwdevicemanager: fix SEGV caused by removing a device when the Device list
dialog is open. Also make sure to update the device list correctly when a device is removed. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit c9e2911bdb07fe817b75947c6e896552fa64cddf)
-rw-r--r--kcontrol/hwmanager/deviceiconview.h20
-rw-r--r--kcontrol/hwmanager/hwmanager.cpp18
-rw-r--r--kcontrol/hwmanager/hwmanager.h1
3 files changed, 21 insertions, 18 deletions
diff --git a/kcontrol/hwmanager/deviceiconview.h b/kcontrol/hwmanager/deviceiconview.h
index 913c4c9ef..746fb2253 100644
--- a/kcontrol/hwmanager/deviceiconview.h
+++ b/kcontrol/hwmanager/deviceiconview.h
@@ -32,31 +32,25 @@ class ConfigModuleList;
class DeviceIconItem : public TDEListViewItem
{
public:
- DeviceIconItem(TQListViewItem *parent, const TQString& text, const TQPixmap& pm, TDEGenericDevice *d = 0)
+ DeviceIconItem(TQListViewItem *parent, const TQString& text, const TQPixmap& pm, TQString deviceUid)
: TDEListViewItem(parent, text)
- , _tag(TQString::null)
- , _device(d)
+ , _deviceUid(deviceUid)
{
setPixmap(0, pm);
}
- DeviceIconItem(TQListView *parent, const TQString& text, const TQPixmap& pm, TDEGenericDevice *d = 0)
+ DeviceIconItem(TQListView *parent, const TQString& text, const TQPixmap& pm, TQString deviceUid)
: TDEListViewItem(parent, text)
- , _tag(TQString::null)
- , _device(d)
+ , _deviceUid(deviceUid)
{
setPixmap(0, pm);
}
- void setDevice(TDEGenericDevice* d) { _device = d; }
- void setTag(const TQString& t) { _tag = t; }
+ void setDevice(TQString deviceUid) { _deviceUid = deviceUid; }
- TDEGenericDevice* device() { return _device; }
- TQString tag() { return _tag; }
-
+ TDEGenericDevice* device() { return TDEGlobal::hardwareDevices()->findByUniqueID(_deviceUid); }
private:
- TQString _tag;
- TDEGenericDevice *_device;
+ TQString _deviceUid; // device unique id
};
class DeviceIconView : public TDEListView
diff --git a/kcontrol/hwmanager/hwmanager.cpp b/kcontrol/hwmanager/hwmanager.cpp
index 25b4a6e71..714dad88d 100644
--- a/kcontrol/hwmanager/hwmanager.cpp
+++ b/kcontrol/hwmanager/hwmanager.cpp
@@ -23,6 +23,7 @@
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
+#include <tqtimer.h>
#include <dcopclient.h>
@@ -93,7 +94,7 @@ TDEHWManager::TDEHWManager(TQWidget *parent, const char *name, const TQStringLis
connect(base->showByConnection, TQT_SIGNAL(clicked()), TQT_SLOT(populateTreeView()));
connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(populateTreeView()));
- connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(populateTreeView()));
+ connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(delayedPopulateTreeView()));
connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*)));
load();
@@ -148,7 +149,7 @@ void TDEHWManager::populateTreeView()
TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass(TDEGenericDeviceType::RootSystem);
TDEGenericDevice *hwdevice;
for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
- DeviceIconItem* item = new DeviceIconItem(base->deviceTree, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
+ DeviceIconItem* item = new DeviceIconItem(base->deviceTree, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice->uniqueID());
if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true);
@@ -160,11 +161,11 @@ void TDEHWManager::populateTreeView()
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
for (int i=0;i<=TDEGenericDeviceType::Last;i++) {
if (i != TDEGenericDeviceType::Root) {
- DeviceIconItem* rootitem = new DeviceIconItem(base->deviceTree, hwdevices->getFriendlyDeviceTypeStringFromType((TDEGenericDeviceType::TDEGenericDeviceType)i), hwdevices->getDeviceTypeIconFromType((TDEGenericDeviceType::TDEGenericDeviceType)i, base->deviceTree->iconSize()), 0);
+ DeviceIconItem* rootitem = new DeviceIconItem(base->deviceTree, hwdevices->getFriendlyDeviceTypeStringFromType((TDEGenericDeviceType::TDEGenericDeviceType)i), hwdevices->getDeviceTypeIconFromType((TDEGenericDeviceType::TDEGenericDeviceType)i, base->deviceTree->iconSize()), TQString::null);
TDEGenericDevice *hwdevice;
TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass((TDEGenericDeviceType::TDEGenericDeviceType)i);
for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
- DeviceIconItem* item = new DeviceIconItem(rootitem, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
+ DeviceIconItem* item = new DeviceIconItem(rootitem, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice->uniqueID());
if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true);
@@ -175,6 +176,13 @@ void TDEHWManager::populateTreeView()
}
}
+void TDEHWManager::delayedPopulateTreeView() {
+ // When hardwareRemoved() is triggered, the list of devices still contains the device which
+ // is about to be removed. Therefore we need to delay repopulating the device tree after the
+ // removal of the device.
+ TQTimer::singleShot(0, this, TQT_SLOT(populateTreeView()));
+}
+
void TDEHWManager::populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_connection, TQString selected_syspath) {
if (show_by_connection) {
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@@ -182,7 +190,7 @@ void TDEHWManager::populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_con
TDEGenericDevice *hwdevice;
for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
if (hwdevice->parentDevice() == parent->device()) {
- DeviceIconItem* item = new DeviceIconItem(parent, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice);
+ DeviceIconItem* item = new DeviceIconItem(parent, hwdevice->detailedFriendlyName(), hwdevice->icon(base->deviceTree->iconSize()), hwdevice->uniqueID());
if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true);
diff --git a/kcontrol/hwmanager/hwmanager.h b/kcontrol/hwmanager/hwmanager.h
index b75a494d9..892ed8dfe 100644
--- a/kcontrol/hwmanager/hwmanager.h
+++ b/kcontrol/hwmanager/hwmanager.h
@@ -59,6 +59,7 @@ k_dcop:
private slots:
void populateTreeView();
+ void delayedPopulateTreeView();
void populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_connection, TQString selected_syspath);
void deviceChanged(TDEGenericDevice*);