summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2019-06-10 15:00:20 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2020-10-17 10:48:27 +0800
commit3676cf129d85151dd430633847e3c289327405d5 (patch)
tree5ef29a2767f54ad7b642a75355bff277e47c9449 /tdeioslave/media/mediamanager/tdehardwarebackend.cpp
parent11beb5658031277ef94a1506a6668ff32b1ea111 (diff)
downloadtdebase-3676cf129d85151dd430633847e3c289327405d5.tar.gz
tdebase-3676cf129d85151dd430633847e3c289327405d5.zip
tdeioslave media: added initial support for unlocking/locking of encrypted devices.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/media/mediamanager/tdehardwarebackend.cpp')
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp89
1 files changed, 86 insertions, 3 deletions
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
index c399d280d..f0c432a37 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -1441,7 +1441,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
// Failed as BUSY
TQString processesUsingDev = listUsingProcesses(medium);
if (!processesUsingDev.isNull()) {
- if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently "
+ if (KMessageBox::warningYesNo(0, i18n("The device <b>%1</b> (%2) named <b>'%3'</b> and currently "
"mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly "
"terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" +
medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL())
@@ -1480,6 +1480,91 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
return result;
}
+TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &password)
+{
+ kdDebug(1219) << "TDEBackend::unlock for id " << id << endl;
+
+ TQStringVariantMap result;
+
+ const Medium* medium = m_mediaList.findById(id);
+ if (!medium) {
+ result["errStr"] = i18n("No such medium: %1").arg(id);
+ result["result"] = false;
+ return result;
+ }
+
+ if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
+ result["result"] = true;
+ return result;
+ }
+
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (!sdevice) {
+ result["errStr"] = i18n("Internal error. Couldn't find medium.");
+ result["result"] = false;
+ return result;
+ }
+
+ TQStringVariantMap unlockResult = sdevice->unlockDevice(password);
+ if (unlockResult["result"].toBool() == false) {
+ TQString qerror = i18n("Unable to unlock the device.");
+ TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null;
+ if (!errStr.isEmpty()) {
+ qerror.append(i18n("<p>Technical details:<br>").append(errStr));
+ result["errStr"] = qerror;
+ result["result"] = false;
+ return result;
+ }
+ }
+
+ result["result"] = unlockResult["unlockedDevice"];
+ result["result"] = true;
+ return result;
+}
+
+TQStringVariantMap TDEBackend::lock(const TQString &id)
+{
+ kdDebug(1219) << "TDEBackend::lock for id " << id << endl;
+
+ TQStringVariantMap result;
+
+ const Medium* medium = m_mediaList.findById(id);
+ if (!medium) {
+ result["errStr"] = i18n("No such medium: %1").arg(id);
+ result["result"] = false;
+ return result;
+ }
+
+ if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
+ result["result"] = true;
+ return result;
+ }
+
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (!sdevice) {
+ result["errStr"] = i18n("Internal error. Couldn't find medium.");
+ result["result"] = false;
+ return result;
+ }
+
+ TQStringVariantMap lockResult = sdevice->lockDevice();
+ if (lockResult["result"].toBool() == false) {
+ TQString qerror = i18n("Unable to lock the device.");
+ TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null;
+ if (!errStr.isEmpty()) {
+ qerror.append(i18n("<p>Technical details:<br>").append(errStr));
+ result["errStr"] = qerror;
+ result["result"] = false;
+ return result;
+ }
+ }
+
+ result["result"] = true;
+ return result;
+}
+
void TDEBackend::slotResult(TDEIO::Job *job)
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@@ -1491,7 +1576,6 @@ void TDEBackend::slotResult(TDEIO::Job *job)
if (job->error() == TDEIO::ERR_COULD_NOT_UNMOUNT) {
TQString proclist(listUsingProcesses(medium));
- qerror = "<qt>";
qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and "
"currently mounted at <b>%4</b> could not be unmounted. ").arg(
"system:/media/" + medium->name(),
@@ -1504,7 +1588,6 @@ void TDEBackend::slotResult(TDEIO::Job *job)
if (!proclist.isEmpty()) {
qerror += proclist;
}
- qerror += "</qt>";
} else if (job->error()) {
qerror = job->errorText();
}