summaryrefslogtreecommitdiffstats
path: root/kcontrol/hwmanager
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2021-07-18 12:05:03 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2021-07-18 12:12:07 +0900
commit2d6227f197af3b1327977cf916e82eb64609e7d5 (patch)
tree963605496cbd33cd54c4134e83a1c58ec4774c85 /kcontrol/hwmanager
parent97f791add4bca93b5333fe1ec5c5f38246abe0f7 (diff)
downloadtdebase-2d6227f197af3b1327977cf916e82eb64609e7d5.tar.gz
tdebase-2d6227f197af3b1327977cf916e82eb64609e7d5.zip
tdehwdevicetray: fixed up notification logic for added/removed disk devices.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kcontrol/hwmanager')
-rw-r--r--kcontrol/hwmanager/hwdevicetray.cpp118
-rw-r--r--kcontrol/hwmanager/hwdevicetray.h7
2 files changed, 60 insertions, 65 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) {
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 <ksimpleconfig.h>
#include <tdepassivepopupstack.h>
-#ifdef WITH_TDEHWLIB
#include <tdehardwaredevices.h>
-#else
-#define TDEGenericDevice void
-#endif
+#include <tdestoragedevice.h>
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<TQString, TDEStorageDevice*> m_knownDiskDevices;
};
#endif