diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-04-05 09:15:43 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-04-05 09:15:43 +0900 |
commit | 62583793601489c5aa14b57d0d12628436c20923 (patch) | |
tree | 363755fc29f9612872f6c0f23ffef4ac8b270a5e | |
parent | 58d7c360547e57857982fafd72b8a2086906c7d7 (diff) | |
download | tdebase-62583793601489c5aa14b57d0d12628436c20923.tar.gz tdebase-62583793601489c5aa14b57d0d12628436c20923.zip |
tdehwdevicetray: add 'safe remove' to the list of available actions.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r-- | kcontrol/hwmanager/hwdevicetray.cpp | 43 | ||||
-rw-r--r-- | kcontrol/hwmanager/hwdevicetray.h | 2 |
2 files changed, 45 insertions, 0 deletions
diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp index 350433b71..5bc77c306 100644 --- a/kcontrol/hwmanager/hwdevicetray.cpp +++ b/kcontrol/hwmanager/hwdevicetray.cpp @@ -88,6 +88,7 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name) new TDEActionMenu(i18n("Unlock"), SmallIcon("decrypted", TQIconSet::Automatic), actionCollection(), "unlock_menu"); new TDEActionMenu(i18n("Lock"), SmallIcon("encrypted", TQIconSet::Automatic), actionCollection(), "lock_menu"); new TDEActionMenu(i18n("Eject"), SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu"); + new TDEActionMenu(i18n("Safe remove"), SmallIcon("player_safe_removal", TQIconSet::Automatic), actionCollection(), "safe_remove_menu"); new TDEActionMenu(i18n("Properties"), SmallIcon("edit", TQIconSet::Automatic), actionCollection(), "properties_menu"); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); @@ -233,6 +234,7 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { TDEActionMenu *unlockDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unlock_menu")); TDEActionMenu *lockDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("lock_menu")); TDEActionMenu *ejectDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("eject_menu")); + TDEActionMenu *safeRemoveDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("safe_remove_menu")); TDEActionMenu *propertiesDeviceActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("properties_menu")); openDeviceActionMenu->popupMenu()->clear(); @@ -241,6 +243,7 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { unlockDeviceActionMenu->popupMenu()->clear(); lockDeviceActionMenu->popupMenu()->clear(); ejectDeviceActionMenu->popupMenu()->clear(); + safeRemoveDeviceActionMenu->popupMenu()->clear(); propertiesDeviceActionMenu->popupMenu()->clear(); m_openMenuIndexMap.clear(); @@ -249,6 +252,7 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { m_unlockMenuIndexMap.clear(); m_lockMenuIndexMap.clear(); m_ejectMenuIndexMap.clear(); + m_safeRemoveMenuIndexMap.clear(); m_propertiesMenuIndexMap.clear(); // Find all storage devices and add them to the popup menus @@ -258,6 +262,7 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { int lastUnlockIndex = -1; int lastLockIndex = -1; int lastEjectIndex = -1; + int lastSafeRemoveIndex = -1; int lastPropertiesIndex = -1; TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); @@ -346,6 +351,15 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { { m_ejectMenuIndexMap[lastEjectIndex] = sdevice->systemPath(); } + + lastSafeRemoveIndex = safeRemoveDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), + i18n("%1 (%2)").arg(friendlyName, sdevice->deviceNode())); + safeRemoveDeviceActionMenu->popupMenu()->connectItem(lastSafeRemoveIndex, this, TQT_SLOT(slotSafeRemoveDevice(int))); + m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] = sdevice->diskUUID(); + if (m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] == "") + { + m_safeRemoveMenuIndexMap[lastSafeRemoveIndex] = sdevice->systemPath(); + } } lastPropertiesIndex = propertiesDeviceActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), @@ -365,6 +379,7 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { unlockDeviceActionMenu->setEnabled(lastUnlockIndex != -1); lockDeviceActionMenu->setEnabled(lastLockIndex != -1); ejectDeviceActionMenu->setEnabled(lastEjectIndex != -1); + safeRemoveDeviceActionMenu->setEnabled(lastSafeRemoveIndex != -1); propertiesDeviceActionMenu->setEnabled(lastPropertiesIndex != -1); if (lastOpenIndex != -1) @@ -391,6 +406,10 @@ void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { { ejectDeviceActionMenu->plug(menu); } + if (lastSafeRemoveIndex != -1) + { + safeRemoveDeviceActionMenu->plug(menu); + } if (lastPropertiesIndex != -1) { propertiesDeviceActionMenu->plug(menu); @@ -549,6 +568,30 @@ void HwDeviceSystemTray::slotEjectDevice(int parameter) } } +void HwDeviceSystemTray::slotSafeRemoveDevice(int parameter) +{ + TQString uuid = m_safeRemoveMenuIndexMap[parameter]; + if (!uuid.isEmpty()) + { + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); + for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) + { + TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); + if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) + { + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-s" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); + } + } + } + } +} + void HwDeviceSystemTray::slotPropertiesDevice(int parameter) { TQString uuid = m_propertiesMenuIndexMap[parameter]; diff --git a/kcontrol/hwmanager/hwdevicetray.h b/kcontrol/hwmanager/hwdevicetray.h index ad7f46ca5..19dca21ef 100644 --- a/kcontrol/hwmanager/hwdevicetray.h +++ b/kcontrol/hwmanager/hwdevicetray.h @@ -61,6 +61,7 @@ protected slots: void slotUnlockDevice(int parameter); void slotLockDevice(int parameter); void slotEjectDevice(int parameter); + void slotSafeRemoveDevice(int parameter); void slotPropertiesDevice(int parameter); protected: @@ -95,6 +96,7 @@ private: TQStringMap m_unlockMenuIndexMap; TQStringMap m_lockMenuIndexMap; TQStringMap m_ejectMenuIndexMap; + TQStringMap m_safeRemoveMenuIndexMap; TQStringMap m_propertiesMenuIndexMap; TDEPopupMenu* m_menu; KSimpleConfig *r_config; |