From 8d0f49aeb4a37176e25c7393ad6a31b8b9e8fcf4 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 19 Feb 2022 16:13:03 +0900 Subject: Added 'eject' and 'ejectByNode' to mediamanager DCOP interface. Signed-off-by: Michele Calgaro --- .../media/mediamanager/tdehardwarebackend.cpp | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'tdeioslave/media/mediamanager/tdehardwarebackend.cpp') diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp index 1da7634d0..ba99b8c0c 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp @@ -1474,7 +1474,6 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo } ResetProperties(sdevice, false, true); - result["result"] = unlockResult["unlockedDevice"]; result["result"] = true; return result; } @@ -1526,6 +1525,47 @@ TQStringVariantMap TDEBackend::lock(const TQString &id) return result; } +TQStringVariantMap TDEBackend::eject(const TQString &id) +{ + kdDebug(1219) << "TDEBackend::eject 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; + } + + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); + if (!sdevice) + { + result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id()); + result["result"] = false; + return result; + } + + TQStringVariantMap ejectResult = sdevice->ejectDrive(); + if (ejectResult["result"].toBool() == false) + { + TQString qerror = i18n("Unable to eject the device."); + TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : TQString::null; + if (!errStr.isEmpty()) + { + qerror.append(i18n("

Technical details:
").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(); -- cgit v1.2.1