tdehwdevicetray: fixed up notification logic for added/removed disk devices.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/216/head
Michele Calgaro 3 years ago
parent 97f791add4
commit 2d6227f197
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -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("Eject"), SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu");
new TDEActionMenu(i18n("Properties"), SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu"); new TDEActionMenu(i18n("Properties"), SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu");
#ifdef WITH_TDEHWLIB
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
doDiskNotifications(true);
connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(deviceAdded(TDEGenericDevice*))); 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(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(deviceRemoved(TDEGenericDevice*)));
connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*))); connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(deviceChanged(TDEGenericDevice*)));
#endif
} }
HwDeviceSystemTray::~HwDeviceSystemTray() HwDeviceSystemTray::~HwDeviceSystemTray()
@ -639,82 +638,79 @@ void HwDeviceSystemTray::slotEditShortcutKeys() {
delete dlg; delete dlg;
} }
void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device) { void HwDeviceSystemTray::doDiskNotifications(bool scanOnly)
#ifdef WITH_TDEHWLIB {
TDEConfig config("mediamanagerrc"); TQMap<TQString, TDEStorageDevice*> deletedDevices = m_knownDiskDevices;
config.setGroup("Global"); TQMap<TQString, TDEStorageDevice*> addedDevices;
if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true))
// 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); TQString uuid = sdevice->diskUUID();
if (isMonitoredDevice(sdevice)) if (uuid == "")
{ {
TQString uuid = sdevice->diskUUID(); uuid = sdevice->systemPath();
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);
} }
if (deletedDevices.contains(uuid))
{
deletedDevices.remove(uuid);
}
else
{
addedDevices[uuid] = sdevice;
}
m_knownDiskDevices[uuid] = sdevice;
} }
} }
#endif if (scanOnly)
} {
return;
}
void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device) { // Notify added/removed devices to the user if necessary
#ifdef WITH_TDEHWLIB
TDEConfig config("mediamanagerrc"); TDEConfig config("mediamanagerrc");
config.setGroup("Global"); config.setGroup("Global");
if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true)) 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); m_hardwareNotifierContainer->displayMessage(
if (isMonitoredDevice(sdevice)) i18n("A disk device has been added!"),
{ i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"),
TQString uuid = sdevice->diskUUID(); 0, 0, "ADD: " + it.key());
if (uuid == "") }
{ // Deleted devices
uuid = sdevice->systemPath(); for (it = deletedDevices.begin(); it != deletedDevices.end(); ++it)
} {
m_hardwareNotifierContainer->displayMessage( m_hardwareNotifierContainer->displayMessage(
i18n("A disk device has been removed!"), i18n("A disk device has been removed!"),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()), SmallIcon("drive-harddisk-unmounted"), i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"),
0, 0, "REMOVE: " + uuid); 0, 0, "REMOVE: " + it.key());
}
} }
} }
#endif
} }
void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device) { void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device)
#ifdef WITH_TDEHWLIB {
TDEConfig config("mediamanagerrc"); doDiskNotifications(false);
config.setGroup("Global"); }
if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true))
{ void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device)
if (device->type() == TDEGenericDeviceType::Disk) {
{ doDiskNotifications(false);
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(device); }
if (isMonitoredDevice(sdevice))
{ void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device)
TQString uuid = sdevice->diskUUID(); {
if (uuid == "") doDiskNotifications(false);
{
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::devicePopupClicked(KPassivePopup* popup, TQPoint point, TQString uuid) { void HwDeviceSystemTray::devicePopupClicked(KPassivePopup* popup, TQPoint point, TQString uuid) {

@ -27,11 +27,8 @@
#include <ksimpleconfig.h> #include <ksimpleconfig.h>
#include <tdepassivepopupstack.h> #include <tdepassivepopupstack.h>
#ifdef WITH_TDEHWLIB
#include <tdehardwaredevices.h> #include <tdehardwaredevices.h>
#else #include <tdestoragedevice.h>
#define TDEGenericDevice void
#endif
class KHelpMenu; class KHelpMenu;
class PasswordDlg; class PasswordDlg;
@ -78,6 +75,7 @@ private slots:
void deviceChanged(TDEGenericDevice*); void deviceChanged(TDEGenericDevice*);
void devicePopupClicked(KPassivePopup*, TQPoint, TQString); void devicePopupClicked(KPassivePopup*, TQPoint, TQString);
void doUnlockDisk(); void doUnlockDisk();
void doDiskNotifications(bool scanOnly);
private: private:
bool isMonitoredDevice(TDEStorageDevice* sdevice); bool isMonitoredDevice(TDEStorageDevice* sdevice);
@ -102,6 +100,7 @@ private:
TDEPopupMenu* m_menu; TDEPopupMenu* m_menu;
KSimpleConfig *r_config; KSimpleConfig *r_config;
PasswordDlg *m_passDlg; PasswordDlg *m_passDlg;
TQMap<TQString, TDEStorageDevice*> m_knownDiskDevices;
}; };
#endif #endif

Loading…
Cancel
Save