summaryrefslogtreecommitdiffstats
path: root/kcontrol/hwmanager
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2022-03-07 16:03:45 +0900
committerMichele Calgaro <[email protected]>2022-03-07 16:03:45 +0900
commit449305f1909fa8cec59834bb42d35237495b28ce (patch)
tree44828802ed7a0ffb79e2cb38fdc23b8570835099 /kcontrol/hwmanager
parentb173191cf8edf14c7c1abc859c2bbde3b4bf3c82 (diff)
downloadtdebase-449305f1909fa8cec59834bb42d35237495b28ce.tar.gz
tdebase-449305f1909fa8cec59834bb42d35237495b28ce.zip
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 <[email protected]>
Diffstat (limited to 'kcontrol/hwmanager')
-rw-r--r--kcontrol/hwmanager/devicepropsdlg.cpp63
-rw-r--r--kcontrol/hwmanager/hwdevicetray.cpp100
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<TDEStorageDevice*>(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("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device");
- TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
- if (!errStr.isEmpty()) {
- qerror.append(i18n("<p>Technical details:<br>").append(errStr));
- }
- qerror.append("</qt>");
+
+ // 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, "<qt>" + errStr + "</qt>", i18n("Mount failed"));
}
- if (qerror != "") KMessageBox::error(this, qerror, i18n("Mount Failed"));
-
populateDeviceInformation();
}
void DevicePropertiesDialog::unmountDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(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 = "<qt>" + i18n("<b>The device could not be unmounted.</b>");
- TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
- if (!errStr.isEmpty()) {
- qerror.append(i18n("<p>Technical details:<br>").append(errStr));
- }
- qerror.append("</qt>");
+ TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device.");
+ KMessageBox::error(this, "<qt>" + errStr + "</qt>", 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<TDEStorageDevice*>(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("<qt>Unable to unlock this device.<p>Potential reasons include:<br>Wrong password "
+ errStr = i18n("<qt>Unable to unlock the device.<p>Potential reasons include:<br>Wrong password "
"and/or user privilege level.<br>Corrupt data on storage device.</qt>");
}
- 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<TDEStorageDevice*>(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, "<qt>" + errStr + "</qt>", i18n("Lock Failed"));
+ KMessageBox::error(this, "<qt>" + errStr + "</qt>", 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 <dcopclient.h>
+#include <dcopref.h>
#include <cstdlib>
#include <unistd.h>
@@ -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("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
- KMessageBox::error(0, i18n("<qt><b>Unable to mount the device.</b>") + qerror + " (error code " +
- retcodeStr + ").</qt>", 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, "<qt>" + errStr + "</qt>", 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("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
- KMessageBox::error(0, i18n("<qt><b>Unable to unmount the device.</b>") + qerror + " (error code " +
- retcodeStr + ").</qt>", i18n("Unmount failed"));
+ // Unmount failed!
+ TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device.");
+ KMessageBox::error(0, "<qt>" + errStr + "</qt>", 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<TDEStorageDevice*>(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("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
- KMessageBox::error(0, i18n("<qt><b>Unable to unlock the device.</b>") + qerror + " (error code " +
- retcodeStr + ").</qt>", i18n("Unlock failed"));
+ if (errStr.isEmpty())
+ {
+ errStr = i18n("<qt>Unable to unlock the device.<p>Potential reasons include:<br>Wrong password "
+ "and/or user privilege level.<br>Corrupt data on storage device.</qt>");
+ }
+ 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<TDEStorageDevice*>(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("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
- KMessageBox::error(0, i18n("<qt><b>Unable to lock the device.</b>") + qerror + " (error code " +
- retcodeStr + ").</qt>", i18n("Lock failed"));
+ TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device.");
+ KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Lock failed"));
}
+ return;
}
}
}
@@ -582,15 +608,19 @@ void HwDeviceSystemTray::slotEjectDevice(int parameter)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(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("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
- KMessageBox::error(0, i18n("<qt><b>Unable to eject the device.</b>") + qerror + " (error code " +
- retcodeStr + ").</qt>", i18n("Eject failed"));
+ TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : i18n("Unable to eject the device.");
+ KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Eject failed"));
}
return;
}