Updated after changes to tdehw lib related to device notificaitons.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/219/head
Michele Calgaro 3 years ago
parent 6432d2c280
commit bb2ea23175
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -640,10 +640,14 @@ void HwDeviceSystemTray::slotEditShortcutKeys() {
void HwDeviceSystemTray::doDiskNotifications(bool scanOnly) void HwDeviceSystemTray::doDiskNotifications(bool scanOnly)
{ {
TQMap<TQString, TDEStorageDevice*> deletedDevices = m_knownDiskDevices; TDEConfig config("mediamanagerrc");
TQMap<TQString, TDEStorageDevice*> addedDevices; 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<TQString, KnownDiskDeviceInfo> oldKnownDevices = m_knownDiskDevices;
m_knownDiskDevices.clear(); m_knownDiskDevices.clear();
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
@ -652,60 +656,93 @@ void HwDeviceSystemTray::doDiskNotifications(bool scanOnly)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (isMonitoredDevice(sdevice)) if (isMonitoredDevice(sdevice))
{ {
TQString uuid = sdevice->diskUUID(); TQString sysPath = sdevice->systemPath();
if (uuid == "") if (oldKnownDevices.contains(sysPath))
{ {
uuid = sdevice->systemPath(); m_knownDiskDevices[sysPath] = oldKnownDevices[sysPath];
} oldKnownDevices.remove(sysPath);
if (deletedDevices.contains(uuid))
{
deletedDevices.remove(uuid);
} }
else 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; TQMap<TQString, KnownDiskDeviceInfo>::ConstIterator delIt;
} for (delIt = oldKnownDevices.begin(); delIt != oldKnownDevices.end(); delIt++)
// Notify added/removed devices to the user if necessary
TDEConfig config("mediamanagerrc");
config.setGroup("Global");
if (config.readBoolEntry("DeviceMonitorPopupsEnabled", true))
{
TQMap<TQString, TDEStorageDevice*>::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)
{ {
m_hardwareNotifierContainer->displayMessage( m_hardwareNotifierContainer->displayMessage(
i18n("A disk device has been removed!"), i18n("A disk device has been removed!"),
i18n("%1 (%2)").arg(it.data()->friendlyName(), it.data()->deviceNode()), SmallIcon("drive-harddisk-unmounted"), i18n("%1 (%2)").arg(delIt.data().friendlyName, delIt.data().node),
0, 0, "REMOVE: " + it.key()); SmallIcon("drive-harddisk-unmounted"), 0, 0, "REMOVE: " + delIt.key());
} }
} }
} }
void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device) void HwDeviceSystemTray::deviceAdded(TDEGenericDevice* device)
{ {
doDiskNotifications(false); if (device->type() == TDEGenericDeviceType::Disk)
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(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) void HwDeviceSystemTray::deviceRemoved(TDEGenericDevice* device)
{ {
doDiskNotifications(false); if (device->type() == TDEGenericDeviceType::Disk)
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(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) void HwDeviceSystemTray::deviceChanged(TDEGenericDevice* device)

@ -100,7 +100,13 @@ private:
TDEPopupMenu* m_menu; TDEPopupMenu* m_menu;
KSimpleConfig *r_config; KSimpleConfig *r_config;
PasswordDlg *m_passDlg; PasswordDlg *m_passDlg;
TQMap<TQString, TDEStorageDevice*> m_knownDiskDevices;
struct KnownDiskDeviceInfo
{
TQString friendlyName;
TQString node;
};
TQMap<TQString, KnownDiskDeviceInfo> m_knownDiskDevices;
}; };
#endif #endif

@ -320,8 +320,7 @@ void TDEBackend::ModifyDevice(TDEStorageDevice * sdevice)
{ {
kdDebug(1219) << "TDEBackend::ModifyDevice for " << sdevice->uniqueID() << endl; kdDebug(1219) << "TDEBackend::ModifyDevice for " << sdevice->uniqueID() << endl;
bool allowNotification = false; ResetProperties(sdevice, false);
ResetProperties(sdevice, allowNotification);
} }
void TDEBackend::ResetProperties(TDEStorageDevice * sdevice, bool allowNotification, bool overrideIgnoreList) void TDEBackend::ResetProperties(TDEStorageDevice * sdevice, bool allowNotification, bool overrideIgnoreList)

Loading…
Cancel
Save