From 449305f1909fa8cec59834bb42d35237495b28ce Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 7 Mar 2022 16:03:45 +0900 Subject: [PATCH] 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 +++++++--------- kcontrol/hwmanager/hwdevicetray.cpp | 100 +++++++++++++++++--------- 2 files changed, 91 insertions(+), 72 deletions(-) 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(); diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp index 354991699..e79080072 100644 --- a/kcontrol/hwmanager/hwdevicetray.cpp +++ b/kcontrol/hwmanager/hwdevicetray.cpp @@ -45,6 +45,7 @@ #include "passworddlg.h" #include +#include #include #include @@ -439,14 +440,19 @@ void HwDeviceSystemTray::slotMountDevice(int parameter) { if (sdevice->mountPath().isEmpty()) { - TQStringVariantMap mountResult = sdevice->mountDevice(); - if (mountResult["result"].toBool() == false) + // 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()) { - TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; - TQString retcodeStr = mountResult.contains("retCode") ? mountResult["retCode"].toString() : i18n("not available"); - TQString qerror = i18n("

Technical details:
") + (!errStr.isEmpty() ? errStr : i18n("unknown")); - KMessageBox::error(0, i18n("Unable to mount the device.") + qerror + " (error code " + - retcodeStr + ").", i18n("Mount failed")); + 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(0, "" + errStr + "", i18n("Mount failed")); } return; } @@ -469,14 +475,19 @@ void HwDeviceSystemTray::slotUnmountDevice(int parameter) { if (!sdevice->mountPath().isEmpty()) { - 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) { - TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; - TQString retcodeStr = unmountResult.contains("retCode") ? unmountResult["retCode"].toString() : i18n("not available"); - TQString qerror = i18n("

Technical details:
") + (!errStr.isEmpty() ? errStr : i18n("unknown")); - KMessageBox::error(0, i18n("Unable to unmount the device.") + qerror + " (error code " + - retcodeStr + ").", i18n("Unmount failed")); + // Unmount failed! + TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device."); + KMessageBox::error(0, "" + errStr + "", i18n("Unmount failed")); } return; } @@ -506,6 +517,7 @@ void HwDeviceSystemTray::slotUnlockDevice(int parameter) m_passDlg->index = parameter; m_passDlg->clearPassword(); m_passDlg->show(); + return; } } } @@ -523,21 +535,30 @@ void HwDeviceSystemTray::doUnlockDisk() TDEStorageDevice *sdevice = static_cast(hwdevice); if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) { - TQStringVariantMap unlockResult = sdevice->unlockDevice(m_passDlg->getPassword()); - if (unlockResult["result"].toBool() == false) + // 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()) { - // Unlock failed! TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; - TQString retcodeStr = unlockResult.contains("retCode") ? unlockResult["retCode"].toString() : i18n("not available"); - TQString qerror = i18n("

Technical details:
") + (!errStr.isEmpty() ? errStr : i18n("unknown")); - KMessageBox::error(0, i18n("Unable to unlock the device.") + qerror + " (error code " + - retcodeStr + ").", i18n("Unlock failed")); + 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(0, errStr, i18n("Unlock failed")); m_passDlg->clearPassword(); } else { m_passDlg->hide(); } + return; } } } @@ -555,16 +576,21 @@ void HwDeviceSystemTray::slotLockDevice(int parameter) TDEStorageDevice *sdevice = static_cast(hwdevice); if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) { - TQStringVariantMap lockResult = sdevice->lockDevice(); - if (lockResult["result"].toBool() == false) + // 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; + if (reply.isValid()) + { + reply.get(lockResult); + } + if (!lockResult.contains("result") || lockResult["result"].toBool() == false) { // Lock failed! - TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null; - TQString retcodeStr = lockResult.contains("retCode") ? lockResult["retCode"].toString() : i18n("not available"); - TQString qerror = i18n("

Technical details:
") + (!errStr.isEmpty() ? errStr : i18n("unknown")); - KMessageBox::error(0, i18n("Unable to lock the device.") + qerror + " (error code " + - retcodeStr + ").", i18n("Lock failed")); + TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device."); + KMessageBox::error(0, "" + errStr + "", i18n("Lock failed")); } + return; } } } @@ -582,15 +608,19 @@ void HwDeviceSystemTray::slotEjectDevice(int parameter) TDEStorageDevice *sdevice = static_cast(hwdevice); if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) { - TQStringVariantMap ejectResult = sdevice->ejectDrive(); - if (ejectResult["result"].toBool() == false) + // Use DCOP call instead of a tdehw call for consistent behavior across TDE + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("ejectByNode", sdevice->deviceNode()); + TQStringVariantMap ejectResult; + if (reply.isValid()) + { + reply.get(ejectResult); + } + if (!ejectResult.contains("result") || ejectResult["result"].toBool() == false) { // Eject failed! - TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : TQString::null; - TQString retcodeStr = ejectResult.contains("retCode") ? ejectResult["retCode"].toString() : i18n("not available"); - TQString qerror = i18n("

Technical details:
") + (!errStr.isEmpty() ? errStr : i18n("unknown")); - KMessageBox::error(0, i18n("Unable to eject the device.") + qerror + " (error code " + - retcodeStr + ").", i18n("Eject failed")); + TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : i18n("Unable to eject the device."); + KMessageBox::error(0, "" + errStr + "", i18n("Eject failed")); } return; }