From 88d92af3c14c0b0b9149440c1b5d38e8fb7cbd79 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 26 Mar 2022 23:54:14 +0900 Subject: hwmanager: use tdeio_media_mounthelper process to mount/unmout/lock/unlock/ejct media devices. This ensures a consistent media device status also with complex partition structures and LUKS encryption. Signed-off-by: Michele Calgaro --- kcontrol/hwmanager/devicepropsdlg.cpp | 103 +++++++++------------------------- 1 file changed, 25 insertions(+), 78 deletions(-) (limited to 'kcontrol/hwmanager/devicepropsdlg.cpp') diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index 1056aec57..e0f673de5 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #undef Unsorted // Required for --enable-final (tqdir.h) @@ -253,7 +254,7 @@ void SensorDisplayWidget::updateDisplay() { } DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidget *parent) - : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true), m_passDlg(NULL) + : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true) { m_device = device; enableButtonOK( false ); @@ -350,10 +351,6 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge DevicePropertiesDialog::~DevicePropertiesDialog() { - if (m_passDlg) - { - delete m_passDlg; - } } void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) { @@ -909,99 +906,49 @@ void DevicePropertiesDialog::setHibernationMethod(int value) { void DevicePropertiesDialog::mountDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call instead of a tdehw call for consistent behavior across TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("mountByNode", sdevice->deviceNode()); - TQStringVariantMap mountResult; - if (reply.isValid()) { - reply.get(mountResult); - } - if (!mountResult.contains("result") || mountResult["result"].toBool() == false) { - // Mount failed! - TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unable to mount the device."); - KMessageBox::error(this, "" + errStr + "", i18n("Mount failed")); + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-m" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - - populateDeviceInformation(); } void DevicePropertiesDialog::unmountDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call instead of a tdehw call for consistent behavior across TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("unmountByNode", sdevice->deviceNode()); - TQStringVariantMap unmountResult; - if (reply.isValid()) { - reply.get(unmountResult); - } - if (!unmountResult.contains("result") || unmountResult["result"].toBool() == false) { - // Unmount failed! - TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device."); - KMessageBox::error(this, "" + errStr + "", i18n("Unmount failed")); - } - - populateDeviceInformation(); -} - -void DevicePropertiesDialog::unlockDisk() { - TDEStorageDevice* sdevice = static_cast(m_device); - - if (!m_passDlg) + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-u" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) { - m_passDlg = new PasswordDlg(); - connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - m_passDlg->setDevice(sdevice->deviceNode()); - m_passDlg->clearPassword(); - m_passDlg->show(); } -void DevicePropertiesDialog::doUnlockDisk() { +void DevicePropertiesDialog::unlockDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call instead of a tdehw call for consistent behavior across TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword()); - TQStringVariantMap unlockResult; - if (reply.isValid()) { - reply.get(unlockResult); - } - if (!unlockResult.contains("result") || !unlockResult["result"].toBool()) + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-k" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) { - TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; - if (errStr.isEmpty()) - { - errStr = i18n("Unable to unlock the device.

Potential reasons include:
Wrong password " - "and/or user privilege level.
Corrupt data on storage device."); - } - KMessageBox::error(this, errStr, i18n("Unlock failed")); - m_passDlg->clearPassword(); - } - else { - m_passDlg->hide(); + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - - populateDeviceInformation(); } void DevicePropertiesDialog::lockDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call instead of a tdehw call for consistent behavior across TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode(), true); - TQStringVariantMap lockResult; - if (reply.isValid()) { - reply.get(lockResult); - } - if (!lockResult.contains("result") || lockResult["result"].toBool() == false) { - // Lock failed! - TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device."); - KMessageBox::error(this, "" + errStr + "", i18n("Lock failed")); + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-l" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - - populateDeviceInformation(); } void DevicePropertiesDialog::cryptLUKSAddKey() { -- cgit v1.2.1