From 2d6227f197af3b1327977cf916e82eb64609e7d5 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 18 Jul 2021 12:05:03 +0900 Subject: tdehwdevicetray: fixed up notification logic for added/removed disk devices. Signed-off-by: Michele Calgaro --- kcontrol/hwmanager/hwdevicetray.cpp | 118 +++++++++++++++++------------------- kcontrol/hwmanager/hwdevicetray.h | 7 +-- 2 files changed, 60 insertions(+), 65 deletions(-) (limited to 'kcontrol') 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 deletedDevices = m_knownDiskDevices; + TQMap 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(hwdevice); + if (isMonitoredDevice(sdevice)) { - TDEStorageDevice* sdevice = static_cast(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::Iterator it; + // Added devices + for (it = addedDevices.begin(); it != addedDevices.end(); ++it) { - TDEStorageDevice* sdevice = static_cast(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(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) { diff --git a/kcontrol/hwmanager/hwdevicetray.h b/kcontrol/hwmanager/hwdevicetray.h index 4f36c797a..57389c1de 100644 --- a/kcontrol/hwmanager/hwdevicetray.h +++ b/kcontrol/hwmanager/hwdevicetray.h @@ -27,11 +27,8 @@ #include #include -#ifdef WITH_TDEHWLIB #include -#else -#define TDEGenericDevice void -#endif +#include class KHelpMenu; class PasswordDlg; @@ -78,6 +75,7 @@ private slots: void deviceChanged(TDEGenericDevice*); void devicePopupClicked(KPassivePopup*, TQPoint, TQString); void doUnlockDisk(); + void doDiskNotifications(bool scanOnly); private: bool isMonitoredDevice(TDEStorageDevice* sdevice); @@ -102,6 +100,7 @@ private: TDEPopupMenu* m_menu; KSimpleConfig *r_config; PasswordDlg *m_passDlg; + TQMap m_knownDiskDevices; }; #endif -- cgit v1.2.1