diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-04-05 15:35:19 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-04-05 15:35:19 +0900 |
commit | b425c87ca31d9558e761cc7307ed62a4cd368348 (patch) | |
tree | 30b5b8167dfe8a5ad43d31f04e50749a1f368290 /kcontrol/hwmanager | |
parent | 62583793601489c5aa14b57d0d12628436c20923 (diff) | |
download | tdebase-b425c87ca31d9558e761cc7307ed62a4cd368348.tar.gz tdebase-b425c87ca31d9558e761cc7307ed62a4cd368348.zip |
tdehwdevicetray: add 'eject' and 'safe remove' buttons to the disk properties dialog.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kcontrol/hwmanager')
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.cpp | 104 | ||||
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.h | 4 | ||||
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlgbase.ui | 16 | ||||
-rw-r--r-- | kcontrol/hwmanager/hwdevicetray.cpp | 81 | ||||
-rw-r--r-- | kcontrol/hwmanager/hwdevicetray.h | 2 |
5 files changed, 157 insertions, 50 deletions
diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index e0f673de5..89a7e867f 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -307,6 +307,8 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge connect(base->buttonDiskUnmount, TQT_SIGNAL(clicked()), this, TQT_SLOT(unmountDisk())); connect(base->buttonDiskUnlock, TQT_SIGNAL(clicked()), this, TQT_SLOT(unlockDisk())); connect(base->buttonDiskLock, TQT_SIGNAL(clicked()), this, TQT_SLOT(lockDisk())); + connect(base->buttonDiskEject, TQT_SIGNAL(clicked()), this, TQT_SLOT(ejectDisk())); + connect(base->buttonDiskSafeRemove, TQT_SIGNAL(clicked()), this, TQT_SLOT(safeRemoveDisk())); if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { connect(base->cryptLUKSAddKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSAddKey())); connect(base->cryptLUKSDelKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSDelKey())); @@ -373,7 +375,49 @@ static TQString formatDisplayString(TQString input) { return TQStyleSheet::escape(input); } -void DevicePropertiesDialog::populateDeviceInformation() { +bool DevicePropertiesDialog::isMonitoredDevice(TDEStorageDevice *sdevice) +{ + // Type selection logic largely duplicated from the media manager tdeioslave + return ((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) && + !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) && + (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMO) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::Floppy) || + sdevice->isDiskOfType(TDEDiskDeviceType::Zip) || + sdevice->isDiskOfType(TDEDiskDeviceType::Jaz) || + sdevice->isDiskOfType(TDEDiskDeviceType::Camera))); +} + +void DevicePropertiesDialog::populateDeviceInformation() +{ if (m_device) { base->labelDeviceType->setText(m_device->friendlyDeviceType()); base->iconDeviceType->setPixmap(m_device->icon(TDEIcon::SizeSmall)); @@ -461,29 +505,53 @@ void DevicePropertiesDialog::populateDeviceInformation() { status_text += "</qt>"; base->labelDiskStatus->setText(status_text); - // Update mount/unmount button status + // Update action button status base->buttonDiskMount->setEnabled(false); base->buttonDiskUnmount->setEnabled(false); base->buttonDiskUnlock->setEnabled(false); base->buttonDiskLock->setEnabled(false); + base->buttonDiskEject->setEnabled(false); + base->buttonDiskSafeRemove->setEnabled(false); base->buttonDiskMount->setHidden(true); base->buttonDiskUnmount->setHidden(true); base->buttonDiskUnlock->setHidden(true); base->buttonDiskLock->setHidden(true); - if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable)) { - base->groupDiskActions->show(); + base->buttonDiskEject->setHidden(true); + base->buttonDiskSafeRemove->setHidden(true); + bool showGroup = false; + if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable)) + { base->buttonDiskMount->setEnabled((sdevice->mountPath() == "")); base->buttonDiskUnmount->setEnabled((sdevice->mountPath() != "")); base->buttonDiskMount->setHidden(false); base->buttonDiskUnmount->setHidden(false); + showGroup = true; } - else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { + else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || + sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted)) + { base->buttonDiskUnlock->setEnabled(!sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); base->buttonDiskLock->setEnabled(sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); base->buttonDiskUnlock->setHidden(false); base->buttonDiskLock->setHidden(false); + showGroup = true; } - else { + if (isMonitoredDevice(sdevice) && + (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable))) + { + base->buttonDiskEject->setEnabled(true); + base->buttonDiskSafeRemove->setEnabled(true); + base->buttonDiskEject->setHidden(false); + base->buttonDiskSafeRemove->setHidden(false); + showGroup = true; + } + if (showGroup) + { + base->groupDiskActions->show(); + } + else + { base->groupDiskActions->hide(); } } @@ -951,6 +1019,30 @@ void DevicePropertiesDialog::lockDisk() { } } +void DevicePropertiesDialog::ejectDisk() { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-e" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); + } +} + +void DevicePropertiesDialog::safeRemoveDisk() { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + 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 DevicePropertiesDialog::cryptLUKSAddKey() { int retcode; diff --git a/kcontrol/hwmanager/devicepropsdlg.h b/kcontrol/hwmanager/devicepropsdlg.h index a1f46e563..aabda590f 100644 --- a/kcontrol/hwmanager/devicepropsdlg.h +++ b/kcontrol/hwmanager/devicepropsdlg.h @@ -192,6 +192,8 @@ private slots: void unmountDisk(); void unlockDisk(); void lockDisk(); + void ejectDisk(); + void safeRemoveDisk(); void cryptLUKSAddKey(); void cryptLUKSDelKey(); @@ -204,6 +206,8 @@ private slots: void processLockouts(); private: + static bool isMonitoredDevice(TDEStorageDevice *sdevice); + TDEGenericDevice* m_device; DevicePropertiesDialogBase* base; diff --git a/kcontrol/hwmanager/devicepropsdlgbase.ui b/kcontrol/hwmanager/devicepropsdlgbase.ui index b5ffe362d..e7d7cee22 100644 --- a/kcontrol/hwmanager/devicepropsdlgbase.ui +++ b/kcontrol/hwmanager/devicepropsdlgbase.ui @@ -371,6 +371,22 @@ <string>Lock</string> </property> </widget> + <widget class="KPushButton" row="1" column="0" colspan="1"> + <property name="name"> + <cstring>buttonDiskEject</cstring> + </property> + <property name="text"> + <string>Eject</string> + </property> + </widget> + <widget class="KPushButton" row="1" column="1" colspan="1"> + <property name="name"> + <cstring>buttonDiskSafeRemove</cstring> + </property> + <property name="text"> + <string>Safe Remove</string> + </property> + </widget> </grid> </widget> <spacer row="8" column="0"> diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp index 5bc77c306..509fe2835 100644 --- a/kcontrol/hwmanager/hwdevicetray.cpp +++ b/kcontrol/hwmanager/hwdevicetray.cpp @@ -154,50 +154,45 @@ void HwDeviceSystemTray::mousePressEvent(TQMouseEvent* e) { KSystemTray::mousePressEvent(e); } -bool HwDeviceSystemTray::isMonitoredDevice(TDEStorageDevice* sdevice) { +bool HwDeviceSystemTray::isMonitoredDevice(TDEStorageDevice* sdevice) +{ // Type selection logic largely duplicated from the media manager tdeioslave - if ((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || - sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || - sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) && - !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) && - (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDROM) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDR) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDMO) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDR) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL) || - sdevice->isDiskOfType(TDEDiskDeviceType::BDROM) || - sdevice->isDiskOfType(TDEDiskDeviceType::BDR) || - sdevice->isDiskOfType(TDEDiskDeviceType::BDRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM) || - sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR) || - sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || - sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo) || - sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo) || - sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo) || - sdevice->isDiskOfType(TDEDiskDeviceType::Floppy) || - sdevice->isDiskOfType(TDEDiskDeviceType::Zip) || - sdevice->isDiskOfType(TDEDiskDeviceType::Jaz) || - sdevice->isDiskOfType(TDEDiskDeviceType::Camera))) - { - return true; - } - else { - return false; - } + return ((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) && + !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) && + (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMO) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::Floppy) || + sdevice->isDiskOfType(TDEDiskDeviceType::Zip) || + sdevice->isDiskOfType(TDEDiskDeviceType::Jaz) || + sdevice->isDiskOfType(TDEDiskDeviceType::Camera))); } void HwDeviceSystemTray::contextMenuAboutToShow(TDEPopupMenu* menu) { diff --git a/kcontrol/hwmanager/hwdevicetray.h b/kcontrol/hwmanager/hwdevicetray.h index 19dca21ef..c0465f2bf 100644 --- a/kcontrol/hwmanager/hwdevicetray.h +++ b/kcontrol/hwmanager/hwdevicetray.h @@ -78,7 +78,7 @@ private slots: void doDiskNotifications(bool scanOnly); private: - bool isMonitoredDevice(TDEStorageDevice* sdevice); + static bool isMonitoredDevice(TDEStorageDevice *sdevice); private: void populateMenu(TDEPopupMenu* menu); |