From bb2ea2317532d39688d93cc0bd404436d53d0973 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 11 Aug 2021 22:02:29 +0900 Subject: Updated after changes to tdehw lib related to device notificaitons. Signed-off-by: Michele Calgaro --- kcontrol/hwmanager/hwdevicetray.cpp | 109 ++++++++++++++------- kcontrol/hwmanager/hwdevicetray.h | 8 +- .../media/mediamanager/tdehardwarebackend.cpp | 3 +- 3 files changed, 81 insertions(+), 39 deletions(-) diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp index eb4fe3270..c4089874a 100644 --- a/kcontrol/hwmanager/hwdevicetray.cpp +++ b/kcontrol/hwmanager/hwdevicetray.cpp @@ -640,10 +640,14 @@ void HwDeviceSystemTray::slotEditShortcutKeys() { void HwDeviceSystemTray::doDiskNotifications(bool scanOnly) { - TQMap deletedDevices = m_knownDiskDevices; - TQMap addedDevices; + TDEConfig config("mediamanagerrc"); + config.setGroup("Global"); + bool popupEnable = config.readBoolEntry("DeviceMonitorPopupsEnabled", true); - // Rescan known devices + // Scan devices for changes and notify new devices if needed. + // This is necessary because the device information may not be available + // at the time the hardwareAdded signal is emitted + TQMap oldKnownDevices = m_knownDiskDevices; m_knownDiskDevices.clear(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); @@ -652,60 +656,93 @@ void HwDeviceSystemTray::doDiskNotifications(bool scanOnly) TDEStorageDevice *sdevice = static_cast(hwdevice); if (isMonitoredDevice(sdevice)) { - TQString uuid = sdevice->diskUUID(); - if (uuid == "") + TQString sysPath = sdevice->systemPath(); + if (oldKnownDevices.contains(sysPath)) { - uuid = sdevice->systemPath(); - } - if (deletedDevices.contains(uuid)) - { - deletedDevices.remove(uuid); + m_knownDiskDevices[sysPath] = oldKnownDevices[sysPath]; + oldKnownDevices.remove(sysPath); } else { - addedDevices[uuid] = sdevice; + TQString friendlyName = sdevice->diskLabel(); + if (friendlyName.isEmpty()) + { + friendlyName = sdevice->friendlyName(); + } + m_knownDiskDevices[sysPath] = { friendlyName, sdevice->deviceNode() }; + if (!scanOnly && popupEnable) + { + m_hardwareNotifierContainer->displayMessage( + i18n("A disk device has been added!"), + i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()), + SmallIcon("drive-harddisk-unmounted"), 0, 0, "ADD: " + sysPath); + } } - m_knownDiskDevices[uuid] = sdevice; } } - if (scanOnly) + // Notify devices which have been removed, if necessary + if (!scanOnly && popupEnable) { - return; - } - - // Notify added/removed devices to the user if necessary - TDEConfig config("mediamanagerrc"); - config.setGroup("Global"); - if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) - { - TQMap::Iterator it; - // Added devices - for (it = addedDevices.begin(); it != addedDevices.end(); ++it) - { - 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) + TQMap::ConstIterator delIt; + for (delIt = oldKnownDevices.begin(); delIt != oldKnownDevices.end(); delIt++) { m_hardwareNotifierContainer->displayMessage( i18n("A disk device has been removed!"), - i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"), - 0, 0, "REMOVE: " + it.key()); + i18n("%1 (%2)").arg(delIt.data().friendlyName, delIt.data().node), + SmallIcon("drive-harddisk-unmounted"), 0, 0, "REMOVE: " + delIt.key()); } } } void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device) { - doDiskNotifications(false); + if (device->type() == TDEGenericDeviceType::Disk) + { + TDEStorageDevice *sdevice = static_cast(device); + // The device information may not be available at the time the hardwareAdded signal is emitted. + // In such case ignore the event and handle that at the subsequent hardwareUpdate signal emission. + TQString sysPath = sdevice->systemPath(); + if (isMonitoredDevice(sdevice) && !m_knownDiskDevices.contains(sysPath)) + { + TQString friendlyName = sdevice->diskLabel(); + if (friendlyName.isEmpty()) + { + friendlyName = sdevice->friendlyName(); + } + m_knownDiskDevices[sysPath] = { friendlyName, sdevice->deviceNode() }; + TDEConfig config("mediamanagerrc"); + config.setGroup("Global"); + if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) + { + m_hardwareNotifierContainer->displayMessage( + i18n("A disk device has been added!"), + i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode()), + SmallIcon("drive-harddisk-unmounted"), 0, 0, "ADD: " + sysPath); + } + } + } } void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device) { - doDiskNotifications(false); + if (device->type() == TDEGenericDeviceType::Disk) + { + TDEStorageDevice *sdevice = static_cast(device); + TQString sysPath = sdevice->systemPath(); + if (isMonitoredDevice(sdevice) && m_knownDiskDevices.contains(sysPath)) + { + TDEConfig config("mediamanagerrc"); + config.setGroup("Global"); + if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) + { + m_hardwareNotifierContainer->displayMessage( + i18n("A disk device has been removed!"), + i18n("%1 (%2)").arg(m_knownDiskDevices[sysPath].friendlyName, m_knownDiskDevices[sysPath].node), + SmallIcon("drive-harddisk-unmounted"), 0, 0, "REMOVE: " + sysPath); + } + m_knownDiskDevices.remove(sysPath); + } + } } void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device) diff --git a/kcontrol/hwmanager/hwdevicetray.h b/kcontrol/hwmanager/hwdevicetray.h index 57389c1de..1300ac6ec 100644 --- a/kcontrol/hwmanager/hwdevicetray.h +++ b/kcontrol/hwmanager/hwdevicetray.h @@ -100,7 +100,13 @@ private: TDEPopupMenu* m_menu; KSimpleConfig *r_config; PasswordDlg *m_passDlg; - TQMap m_knownDiskDevices; + + struct KnownDiskDeviceInfo + { + TQString friendlyName; + TQString node; + }; + TQMap m_knownDiskDevices; }; #endif diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp index ae9038a02..1da7634d0 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp @@ -320,8 +320,7 @@ void TDEBackend::ModifyDevice(TDEStorageDevice * sdevice) { kdDebug(1219) << "TDEBackend::ModifyDevice for " << sdevice->uniqueID() << endl; - bool allowNotification = false; - ResetProperties(sdevice, allowNotification); + ResetProperties(sdevice, false); } void TDEBackend::ResetProperties(TDEStorageDevice * sdevice, bool allowNotification, bool overrideIgnoreList) -- cgit v1.2.1