diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-02-19 16:13:03 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-02-19 16:13:03 +0900 |
commit | 8d0f49aeb4a37176e25c7393ad6a31b8b9e8fcf4 (patch) | |
tree | a0cb97849a1dea54c91bed8bca9bfb800bdf5019 /tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp | |
parent | cc236553afa96e1f2bd2dba35b9d93080e273f8c (diff) | |
download | tdebase-8d0f49aeb4a37176e25c7393ad6a31b8b9e8fcf4.tar.gz tdebase-8d0f49aeb4a37176e25c7393ad6a31b8b9e8fcf4.zip |
Added 'eject' and 'ejectByNode' to mediamanager DCOP interface.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp')
-rw-r--r-- | tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp | 77 |
1 files changed, 18 insertions, 59 deletions
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp index ef3f10e8e..bbfbaa6b2 100644 --- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp +++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp @@ -57,20 +57,6 @@ const Medium MountHelper::findMedium(const TQString &device) void MountHelper::mount(const Medium &medium) { - if (medium.id().isEmpty()) { - m_errorStr = i18n("Try to mount an unknown medium."); - errorAndExit(); - } - TQString device = medium.deviceNode(); - if (!medium.isMountable()) { - m_errorStr = i18n("%1 is not a mountable media.").arg(device); - errorAndExit(); - } - else if (medium.isMounted()) { - m_errorStr = i18n("%1 is already mounted to %2.").arg(device).arg(medium.mountPoint()); - errorAndExit(); - } - DCOPReply reply = m_mediamanager.call("mount", medium.id()); TQStringVariantMap mountResult; if (reply.isValid()) { @@ -84,20 +70,6 @@ void MountHelper::mount(const Medium &medium) void MountHelper::unmount(const Medium &medium) { - if (medium.id().isEmpty()) { - m_errorStr = i18n("Try to unmount an unknown medium."); - errorAndExit(); - } - TQString device = medium.deviceNode(); - if (!medium.isMountable()) { - m_errorStr = i18n("%1 is not a mountable media.").arg(device); - errorAndExit(); - } - else if (!medium.isMounted()) { - m_errorStr = i18n("%1 is already unmounted.").arg(device); - errorAndExit(); - } - DCOPReply reply = m_mediamanager.call("unmount", medium.id()); TQStringVariantMap unmountResult; if (reply.isValid()) { @@ -112,19 +84,9 @@ void MountHelper::unmount(const Medium &medium) void MountHelper::unlock(const Medium &medium) { - if (medium.id().isEmpty()) { - m_errorStr = i18n("Try to unlock an unknown medium."); - errorAndExit(); - } TQString device = medium.deviceNode(); - if (!medium.isEncrypted()) - { - m_errorStr = i18n("%1 is not an encrypted media.").arg(device); - errorAndExit(); - } - if (!medium.needUnlocking()) - { - m_errorStr = i18n("%1 is already unlocked.").arg(device); + if (device.isEmpty()) { + m_errorStr = i18n("Try to unlock an unknown medium."); errorAndExit(); } @@ -175,32 +137,29 @@ void MountHelper::lock(const Medium &medium) } } -void MountHelper::eject(const TQString &device, bool quiet) +void MountHelper::eject(const Medium &medium) { #ifdef WITH_TDEHWLIB - // Try TDE HW library eject first... - TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); - TDEGenericDevice *hwdevice = hwdevices->findByDeviceNode(device); - if (hwdevice->type() == TDEGenericDeviceType::Disk) + DCOPReply reply = m_mediamanager.call("eject", medium.id()); + TQStringVariantMap ejectResult; + if (reply.isValid()) { + reply.get(ejectResult); + } + if (!ejectResult.contains("result") || !ejectResult["result"].toBool()) { + m_errorStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : i18n("Unknown eject error."); + kdDebug() << "medium eject " << m_errorStr << endl; + errorAndExit(); + } + else { - TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); - TQStringVariantMap ejectResult = sdevice->ejectDrive(); - if (ejectResult["result"].toBool() == true) - { - // Success! - ::exit(0); - } + ::exit(0); // Success! } #endif // Otherwise fall back to tdeeject TDEProcess *proc = new TDEProcess(TQT_TQOBJECT(this)); *proc << "tdeeject"; - if (quiet) - { - *proc << "-q"; - } - *proc << device; + *proc << medium.deviceNode(); connect(proc, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(ejectFinished(TDEProcess*))); proc->start(); } @@ -356,13 +315,13 @@ MountHelper::MountHelper() : TDEApplication(), m_mediamanager("kded", "mediamana } else if (args->isSet("e")) { - eject(device, true); + eject(medium); ::exit(0); } else if (args->isSet("s")) { safeRemoval(medium); - eject(device, true); + eject(medium); ::exit(0); } else if (args->isSet("f")) |