summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/tdehardwaredevices.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdecore/tdehw/tdehardwaredevices.cpp')
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp111
1 files changed, 46 insertions, 65 deletions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index b25020c04..dbeffad6c 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -210,7 +210,7 @@ TDEHardwareDevices::TDEHardwareDevices() {
m_batteryWatchTimer = new TQTimer(this);
connect( m_batteryWatchTimer, SIGNAL(timeout()), this, SLOT(processBatteryDevices()) );
- // Update internal device information
+ // Update internal device information.
queryHardwareInformation();
}
}
@@ -281,18 +281,21 @@ void TDEHardwareDevices::setBatteryUpdatesEnabled(bool enable) {
}
}
-void TDEHardwareDevices::rescanDeviceInformation(TDEGenericDevice* hwdevice) {
- rescanDeviceInformation(hwdevice, true);
-}
-
-void TDEHardwareDevices::rescanDeviceInformation(TDEGenericDevice* hwdevice, bool regenerateDeviceTree) {
- struct udev_device *dev;
- dev = udev_device_new_from_syspath(m_udevStruct, hwdevice->systemPath().ascii());
- updateExistingDeviceInformation(hwdevice);
+void TDEHardwareDevices::rescanDeviceInformation(TDEGenericDevice* hwdevice, udev_device* dev, bool regenerateDeviceTree) {
+ bool toUnref = false;
+ if (!dev)
+ {
+ dev = udev_device_new_from_syspath(m_udevStruct, hwdevice->systemPath().ascii());
+ toUnref = true;
+ }
+ updateExistingDeviceInformation(hwdevice, dev);
if (regenerateDeviceTree) {
updateParentDeviceInformation(hwdevice); // Update parent/child tables for this device
}
- udev_device_unref(dev);
+ if (toUnref)
+ {
+ udev_device_unref(dev);
+ }
}
TDEGenericDevice* TDEHardwareDevices::findBySystemPath(TQString syspath) {
@@ -389,8 +392,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
TDEGenericDevice *device = classifyUnknownDevice(dev);
// Make sure this device is not a duplicate
- TDEGenericDevice *hwdevice;
- for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
+ for (TDEGenericDevice *hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == device->systemPath()) {
delete device;
device = 0;
@@ -402,6 +404,18 @@ void TDEHardwareDevices::processHotPluggedHardware() {
m_deviceList.append(device);
updateParentDeviceInformation(device); // Update parent/child tables for this device
emit hardwareAdded(device);
+ if (device->type() == TDEGenericDeviceType::Disk) {
+ // Make sure slave status is also updated
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(device);
+ TQStringList slavedevices = sdevice->slaveDevices();
+ for (TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit) {
+ TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
+ if (slavedevice && slavedevice->type() == TDEGenericDeviceType::Disk) {
+ rescanDeviceInformation(slavedevice);
+ emit hardwareUpdated(slavedevice);
+ }
+ }
+ }
}
}
else if (actionevent == "remove") {
@@ -411,32 +425,22 @@ void TDEHardwareDevices::processHotPluggedHardware() {
TDEGenericDevice *hwdevice;
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) {
- // Temporarily disable auto-deletion to ensure object validity when calling the Removed events below
- m_deviceList.setAutoDelete(false);
-
- // If the device is a storage device and has a slave, update it as well
+ // Make sure slave status is also updated
if (hwdevice->type() == TDEGenericDeviceType::Disk) {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
TQStringList slavedevices = sdevice->slaveDevices();
- m_deviceList.remove(hwdevice);
- for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
+ for (TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit) {
TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
- if (slavedevice) {
+ if (slavedevice && slavedevice->type() == TDEGenericDeviceType::Disk) {
rescanDeviceInformation(slavedevice);
emit hardwareUpdated(slavedevice);
}
}
}
- else {
- m_deviceList.remove(hwdevice);
- }
+ rescanDeviceInformation(hwdevice, dev);
emit hardwareRemoved(hwdevice);
-
- // Reenable auto-deletion and delete the removed device object
- m_deviceList.setAutoDelete(true);
- delete hwdevice;
-
+ m_deviceList.remove(hwdevice);
break;
}
}
@@ -449,8 +453,7 @@ void TDEHardwareDevices::processHotPluggedHardware() {
for (hwdevice = m_deviceList.first(); hwdevice; hwdevice = m_deviceList.next()) {
if (hwdevice->systemPath() == systempath) {
if (!hwdevice->blacklistedForUpdate()) {
- classifyUnknownDevice(dev, hwdevice, false);
- updateParentDeviceInformation(hwdevice); // Update parent/child tables for this device
+ rescanDeviceInformation(hwdevice, dev);
emit hardwareUpdated(hwdevice);
}
}
@@ -885,7 +888,7 @@ void TDEHardwareDevices::processStatelessDevices() {
TDEGenericHardwareList devList = listAllPhysicalDevices();
for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
if ((hwdevice->type() == TDEGenericDeviceType::RootSystem) || (hwdevice->type() == TDEGenericDeviceType::Network) || (hwdevice->type() == TDEGenericDeviceType::OtherSensor) || (hwdevice->type() == TDEGenericDeviceType::Event) || (hwdevice->type() == TDEGenericDeviceType::Battery) || (hwdevice->type() == TDEGenericDeviceType::PowerSupply)) {
- rescanDeviceInformation(hwdevice, false);
+ rescanDeviceInformation(hwdevice, NULL, false);
emit hardwareUpdated(hwdevice);
#ifdef STATELESSPROFILING
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
@@ -909,13 +912,13 @@ void TDEHardwareDevices::processBatteryDevices() {
TDEGenericHardwareList devList = listAllPhysicalDevices();
for ( hwdevice = devList.first(); hwdevice; hwdevice = devList.next() ) {
if (hwdevice->type() == TDEGenericDeviceType::Battery) {
- rescanDeviceInformation(hwdevice, false);
+ rescanDeviceInformation(hwdevice, NULL, false);
emit hardwareUpdated(hwdevice);
}
else if (hwdevice->type() == TDEGenericDeviceType::PowerSupply) {
TDEMainsPowerDevice *pdevice = dynamic_cast<TDEMainsPowerDevice*>(hwdevice);
int previousOnlineState = pdevice->online();
- rescanDeviceInformation(hwdevice, false);
+ rescanDeviceInformation(hwdevice, NULL, false);
if (pdevice->online() != previousOnlineState) {
emit hardwareUpdated(hwdevice);
}
@@ -931,7 +934,6 @@ void TDEHardwareDevices::processEventDeviceKeyPressed(unsigned int keycode, TDEE
void TDEHardwareDevices::processModifiedMounts() {
// Detect what changed between the old mount table and the new one,
// and emit appropriate events
-
TQMap<TQString, bool> deletedEntries = m_mountTable;
// Read in the new mount table
@@ -957,43 +959,26 @@ void TDEHardwareDevices::processModifiedMounts() {
}
}
+ // Added devices
TQMap<TQString, bool>::Iterator it;
for ( it = addedEntries.begin(); it != addedEntries.end(); ++it ) {
- TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
// Try to find a device that matches the altered node
+ TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
- if (hwdevice) {
+ if (hwdevice && hwdevice->type() == TDEGenericDeviceType::Disk) {
+ rescanDeviceInformation(hwdevice);
emit hardwareUpdated(hwdevice);
- // If the device is a storage device and has a slave, update it as well
- if (hwdevice->type() == TDEGenericDeviceType::Disk) {
- TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
- TQStringList slavedevices = sdevice->slaveDevices();
- for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
- TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
- if (slavedevice) {
- emit hardwareUpdated(slavedevice);
- }
- }
- }
}
}
+
+ // Removed devices
for ( it = deletedEntries.begin(); it != deletedEntries.end(); ++it ) {
- TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
// Try to find a device that matches the altered node
+ TQStringList mountInfo = TQStringList::split(" ", it.key(), true);
TDEGenericDevice* hwdevice = findByDeviceNode(*mountInfo.at(0));
- if (hwdevice) {
+ if (hwdevice && hwdevice->type() == TDEGenericDeviceType::Disk) {
+ rescanDeviceInformation(hwdevice);
emit hardwareUpdated(hwdevice);
- // If the device is a storage device and has a slave, update it as well
- if (hwdevice->type() == TDEGenericDeviceType::Disk) {
- TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
- TQStringList slavedevices = sdevice->slaveDevices();
- for ( TQStringList::Iterator slaveit = slavedevices.begin(); slaveit != slavedevices.end(); ++slaveit ) {
- TDEGenericDevice* slavedevice = findBySystemPath(*slaveit);
- if (slavedevice) {
- emit hardwareUpdated(slavedevice);
- }
- }
- }
}
}
}
@@ -2466,12 +2451,6 @@ TDEGenericDevice* TDEHardwareDevices::classifyUnknownDevice(udev_device* dev, TD
udev_device_unref(dev);
}
- // Get the device mapped name if present
- TDEStorageDevice *sdevice = dynamic_cast<TDEStorageDevice*>(device);
- if (sdevice) {
- sdevice->updateMappedName();
- }
-
return device;
}
@@ -2872,6 +2851,8 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice *devic
}
sdevice->internalSetDiskLabel(disklabel);
+ sdevice->internalUpdateMountPath();
+ sdevice->internalUpdateMappedName();
}
}