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>
pull/260/head
Michele Calgaro 2 years ago
parent c8b66185be
commit c9e2911bdb
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -32,31 +32,25 @@ class ConfigModuleList;
class DeviceIconItem : public TDEListViewItem class DeviceIconItem : public TDEListViewItem
{ {
public: 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) : TDEListViewItem(parent, text)
, _tag(TQString::null) , _deviceUid(deviceUid)
, _device(d)
{ {
setPixmap(0, pm); 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) : TDEListViewItem(parent, text)
, _tag(TQString::null) , _deviceUid(deviceUid)
, _device(d)
{ {
setPixmap(0, pm); setPixmap(0, pm);
} }
void setDevice(TDEGenericDevice* d) { _device = d; } void setDevice(TQString deviceUid) { _deviceUid = deviceUid; }
void setTag(const TQString& t) { _tag = t; }
TDEGenericDevice* device() { return _device; } TDEGenericDevice* device() { return TDEGlobal::hardwareDevices()->findByUniqueID(_deviceUid); }
TQString tag() { return _tag; }
private: private:
TQString _tag; TQString _deviceUid; // device unique id
TDEGenericDevice *_device;
}; };
class DeviceIconView : public TDEListView class DeviceIconView : public TDEListView

@ -23,6 +23,7 @@
#include <tqlayout.h> #include <tqlayout.h>
#include <tqlineedit.h> #include <tqlineedit.h>
#include <tqpushbutton.h> #include <tqpushbutton.h>
#include <tqtimer.h>
#include <dcopclient.h> #include <dcopclient.h>
@ -96,7 +97,7 @@ TDEHWManager::TDEHWManager(TQWidget *parent, const char *name, const TQStringLis
connect(base->showByConnection, TQT_SIGNAL(clicked()), TQT_SLOT(populateTreeView())); connect(base->showByConnection, TQT_SIGNAL(clicked()), TQT_SLOT(populateTreeView()));
connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, 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*))); connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*)));
load(); load();
@ -157,7 +158,7 @@ void TDEHWManager::populateTreeView()
cdevice->enableCardMonitoring(true); cdevice->enableCardMonitoring(true);
cdevice->enablePINEntryCallbacks(true); cdevice->enablePINEntryCallbacks(true);
} }
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)) { if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item); base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true); base->deviceTree->setSelected(item, true);
@ -169,7 +170,7 @@ void TDEHWManager::populateTreeView()
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
for (int i=0;i<=TDEGenericDeviceType::Last;i++) { for (int i=0;i<=TDEGenericDeviceType::Last;i++) {
if (i != TDEGenericDeviceType::Root) { 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; TDEGenericDevice *hwdevice;
TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass((TDEGenericDeviceType::TDEGenericDeviceType)i); TDEGenericHardwareList hwlist = hwdevices->listByDeviceClass((TDEGenericDeviceType::TDEGenericDeviceType)i);
for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) { for ( hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next() ) {
@ -179,7 +180,7 @@ void TDEHWManager::populateTreeView()
cdevice->enableCardMonitoring(true); cdevice->enableCardMonitoring(true);
cdevice->enablePINEntryCallbacks(true); cdevice->enablePINEntryCallbacks(true);
} }
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)) { if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item); base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true); base->deviceTree->setSelected(item, true);
@ -190,6 +191,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) { void TDEHWManager::populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_connection, TQString selected_syspath) {
if (show_by_connection) { if (show_by_connection) {
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@ -203,7 +211,7 @@ void TDEHWManager::populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_con
cdevice->enablePINEntryCallbacks(true); cdevice->enablePINEntryCallbacks(true);
} }
if (hwdevice->parentDevice() == parent->device()) { 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)) { if ((!selected_syspath.isNull()) && (hwdevice->systemPath() == selected_syspath)) {
base->deviceTree->ensureItemVisible(item); base->deviceTree->ensureItemVisible(item);
base->deviceTree->setSelected(item, true); base->deviceTree->setSelected(item, true);

@ -59,6 +59,7 @@ k_dcop:
private slots: private slots:
void populateTreeView(); void populateTreeView();
void delayedPopulateTreeView();
void populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_connection, TQString selected_syspath); void populateTreeViewLeaf(DeviceIconItem *parent, bool show_by_connection, TQString selected_syspath);
void deviceChanged(TDEGenericDevice*); void deviceChanged(TDEGenericDevice*);
void cryptographicCardPinRequested(TQString prompt, TDECryptographicCardDevice* cdevice); void cryptographicCardPinRequested(TQString prompt, TDECryptographicCardDevice* cdevice);

Loading…
Cancel
Save