diff options
author | Michele Calgaro <[email protected]> | 2021-07-18 12:05:03 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2021-07-18 12:12:07 +0900 |
commit | 2d6227f197af3b1327977cf916e82eb64609e7d5 (patch) | |
tree | 963605496cbd33cd54c4134e83a1c58ec4774c85 /kcontrol/hwmanager/hwdevicetray.cpp | |
parent | 97f791add4bca93b5333fe1ec5c5f38246abe0f7 (diff) | |
download | tdebase-2d6227f197af3b1327977cf916e82eb64609e7d5.tar.gz tdebase-2d6227f197af3b1327977cf916e82eb64609e7d5.zip |
tdehwdevicetray: fixed up notification logic for added/removed disk devices.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'kcontrol/hwmanager/hwdevicetray.cpp')
-rw-r--r-- | kcontrol/hwmanager/hwdevicetray.cpp | 118 |
1 files changed, 57 insertions, 61 deletions
diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp index 5ba24e563..eb4fe3270 100644 --- a/kcontrol/hwmanager/hwdevicetray.cpp +++ b/kcontrol/hwmanager/hwdevicetray.cpp @@ -88,12 +88,11 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name) new TDEActionMenu(i18n("Eject"), SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu"); new TDEActionMenu(i18n("Properties"), SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu"); -#ifdef WITH_TDEHWLIB TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + doDiskNotifications(true); connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(deviceAdded(TDEGenericDevice*))); connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(deviceRemoved(TDEGenericDevice*))); connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*))); -#endif } HwDeviceSystemTray::~HwDeviceSystemTray() @@ -639,82 +638,79 @@ void HwDeviceSystemTray::slotEditShortcutKeys() { delete dlg; } -void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device) { -#ifdef WITH_TDEHWLIB - TDEConfig config("mediamanagerrc"); - config.setGroup("Global"); - if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) +void HwDeviceSystemTray::doDiskNotifications(bool scanOnly) +{ + TQMap<TQString, TDEStorageDevice*> deletedDevices = m_knownDiskDevices; + TQMap<TQString, TDEStorageDevice*> addedDevices; + + // Rescan known devices + m_knownDiskDevices.clear(); + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); + for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) { - if (device->type() == TDEGenericDeviceType::Disk) + TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); + if (isMonitoredDevice(sdevice)) { - TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(device); - if (isMonitoredDevice(sdevice)) + TQString uuid = sdevice->diskUUID(); + if (uuid == "") { - TQString uuid = sdevice->diskUUID(); - if (uuid == "") - { - uuid = sdevice->systemPath(); - } - m_hardwareNotifierContainer->displayMessage( - i18n("A disk device has been added!"), - i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()), SmallIcon("drive-harddisk-unmounted"), - 0, 0, "ADD: " + uuid); + uuid = sdevice->systemPath(); } + if (deletedDevices.contains(uuid)) + { + deletedDevices.remove(uuid); + } + else + { + addedDevices[uuid] = sdevice; + } + m_knownDiskDevices[uuid] = sdevice; } } -#endif -} + if (scanOnly) + { + return; + } -void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device) { -#ifdef WITH_TDEHWLIB + // Notify added/removed devices to the user if necessary TDEConfig config("mediamanagerrc"); config.setGroup("Global"); if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) { - if (device->type() == TDEGenericDeviceType::Disk) + TQMap<TQString, TDEStorageDevice*>::Iterator it; + // Added devices + for (it = addedDevices.begin(); it != addedDevices.end(); ++it) { - TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(device); - if (isMonitoredDevice(sdevice)) - { - TQString uuid = sdevice->diskUUID(); - if (uuid == "") - { - uuid = sdevice->systemPath(); - } - m_hardwareNotifierContainer->displayMessage( + m_hardwareNotifierContainer->displayMessage( + i18n("A disk device has been added!"), + i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"), + 0, 0, "ADD: " + it.key()); + } + // Deleted devices + for (it = deletedDevices.begin(); it != deletedDevices.end(); ++it) + { + m_hardwareNotifierContainer->displayMessage( i18n("A disk device has been removed!"), - i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()), SmallIcon("drive-harddisk-unmounted"), - 0, 0, "REMOVE: " + uuid); - } + i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"), + 0, 0, "REMOVE: " + it.key()); } } -#endif } -void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device) { -#ifdef WITH_TDEHWLIB - TDEConfig config("mediamanagerrc"); - config.setGroup("Global"); - if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) - { - if (device->type() == TDEGenericDeviceType::Disk) - { - TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(device); - if (isMonitoredDevice(sdevice)) - { - TQString uuid = sdevice->diskUUID(); - if (uuid == "") - { - uuid = sdevice->systemPath(); - } - m_hardwareNotifierContainer->displayMessage( - i18n("A disk device has been changed!"), - i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()), SmallIcon("drive-harddisk-unmounted"), - 0, 0, "CHANGE: " + uuid); - } - } - } -#endif +void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device) +{ + doDiskNotifications(false); +} + +void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device) +{ + doDiskNotifications(false); +} + +void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device) +{ + doDiskNotifications(false); } void HwDeviceSystemTray::devicePopupClicked(KPassivePopup* popup, TQPoint point, TQString uuid) { |