From 449305f1909fa8cec59834bb42d35237495b28ce Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 7 Mar 2022 16:03:45 +0900 Subject: tdehwdevicetray: use DCOP calls instead of direct tdehw calls to mount/unmount/unlock/lock/eject devices. This is for consistency of behavior and error messages. Signed-off-by: Michele Calgaro --- kcontrol/hwmanager/devicepropsdlg.cpp | 63 +++++++++++++++-------------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'kcontrol/hwmanager/devicepropsdlg.cpp') diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index ffb19da1a..9256110d2 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -908,48 +908,39 @@ void DevicePropertiesDialog::setHibernationMethod(int value) { void DevicePropertiesDialog::mountDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - TQString qerror; - TQString diskLabel = sdevice->diskLabel(); - if (diskLabel.isNull()) { - diskLabel = i18n("%1 Removable Device").arg(sdevice->deviceFriendlySize()); - } - TDEStorageMountOptions mountOptions; - TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, mountOptions); - TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null; - if (mountedPath.isEmpty()) { - qerror = i18n("Unable to mount this device.

Potential reasons include:
Improper device and/or user privilege level
Corrupt data on storage device"); - TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; - if (!errStr.isEmpty()) { - qerror.append(i18n("

Technical details:
").append(errStr)); - } - qerror.append(""); + + // 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); } - else { - qerror = ""; + 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")); } - if (qerror != "") KMessageBox::error(this, qerror, i18n("Mount Failed")); - populateDeviceInformation(); } void DevicePropertiesDialog::unmountDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - TQString qerror; - TQStringVariantMap unmountResult = sdevice->unmountDevice(); - if (unmountResult["result"].toBool() == false) { + // 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! - qerror = "" + i18n("The device could not be unmounted."); - TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; - if (!errStr.isEmpty()) { - qerror.append(i18n("

Technical details:
").append(errStr)); - } - qerror.append(""); + TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device."); + KMessageBox::error(this, "" + errStr + "", i18n("Unmount failed")); } - if (qerror != "") KMessageBox::error(this, qerror, i18n("Unmount Failed")); - populateDeviceInformation(); } @@ -969,8 +960,7 @@ void DevicePropertiesDialog::unlockDisk() { void DevicePropertiesDialog::doUnlockDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call to unlock the disk to make sure the status and mime type of the underlying medium - // is correctly updated throughout TDE + // 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; @@ -982,10 +972,10 @@ void DevicePropertiesDialog::doUnlockDisk() { TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; if (errStr.isEmpty()) { - errStr = i18n("Unable to unlock this device.

Potential reasons include:
Wrong password " + 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")); + KMessageBox::error(this, errStr, i18n("Unlock failed")); m_passDlg->clearPassword(); } else { @@ -998,8 +988,7 @@ void DevicePropertiesDialog::doUnlockDisk() { void DevicePropertiesDialog::lockDisk() { TDEStorageDevice* sdevice = static_cast(m_device); - // Use DCOP call to lock the disk to make sure the status and mime type of the underlying medium - // is correctly updated throughout TDE + // Use DCOP call instead of a tdehw call for consistent behavior across TDE DCOPRef mediamanager("kded", "mediamanager"); DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); TQStringVariantMap lockResult; @@ -1009,7 +998,7 @@ void DevicePropertiesDialog::lockDisk() { 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")); + KMessageBox::error(this, "" + errStr + "", i18n("Lock failed")); } populateDeviceInformation(); -- cgit v1.2.1