diff options
Diffstat (limited to 'tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp')
-rw-r--r-- | tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp | 212 |
1 files changed, 43 insertions, 169 deletions
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp index ef3f10e8e..90f3caa3f 100644 --- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp +++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp @@ -29,6 +29,7 @@ #include <kurl.h> #include <tdemessagebox.h> #include <dcopclient.h> +#include <dcopref.h> #include <tqtimer.h> #include <stdlib.h> #include <kdebug.h> @@ -45,7 +46,8 @@ const Medium MountHelper::findMedium(const TQString &device) { - DCOPReply reply = m_mediamanager.call("properties", device); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("properties", device); if (!reply.isValid()) { m_errorStr = i18n("The TDE mediamanager is not running.\n"); @@ -57,21 +59,8 @@ 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()); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("mount", medium.id()); TQStringVariantMap mountResult; if (reply.isValid()) { reply.get(mountResult); @@ -84,21 +73,8 @@ 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()); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("unmount", medium.id()); TQStringVariantMap unmountResult; if (reply.isValid()) { reply.get(unmountResult); @@ -112,19 +88,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(); } @@ -136,34 +102,15 @@ void MountHelper::unlock(const Medium &medium) } m_mediumId = medium.id(); m_dialog = new Dialog(device, iconName); - connect(m_dialog, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(slotSendPassword())); - connect(m_dialog, TQT_SIGNAL(cancelClicked()), this, TQT_SLOT(slotCancel())); + connect(m_dialog, TQ_SIGNAL(user1Clicked()), this, TQ_SLOT(slotSendPassword())); + connect(m_dialog, TQ_SIGNAL(cancelClicked()), this, TQ_SLOT(slotCancel())); m_dialog->show(); } void MountHelper::lock(const Medium &medium) { - if (medium.id().isEmpty()) - { - m_errorStr = i18n("Try to lock 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 locked.").arg(device); - errorAndExit(); - } - - // Release children devices - releaseHolders(medium); - - DCOPReply reply = m_mediamanager.call("lock", medium.id()); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("lock", medium.id(), true); TQStringVariantMap lockResult; if (reply.isValid()) { reply.get(lockResult); @@ -175,119 +122,46 @@ 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) + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = 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)); + TDEProcess *proc = new TDEProcess(this); *proc << "tdeeject"; - if (quiet) - { - *proc << "-q"; - } - *proc << device; - connect(proc, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(ejectFinished(TDEProcess*))); + *proc << medium.deviceNode(); + connect(proc, TQ_SIGNAL(processExited(TDEProcess*)), this, TQ_SLOT(ejectFinished(TDEProcess*))); proc->start(); } -void MountHelper::releaseHolders(const Medium &medium, bool handleThis) -{ -#ifdef WITH_TDEHWLIB - if (medium.id().isEmpty()) - { - m_errorStr = i18n("Try to release holders from an unknown medium."); - return; - } - - // Scan the holding devices and unmount/lock them if possible - TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); - TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium.id()); - if (sdevice) - { - TQStringList holdingDeviceList = sdevice->holdingDevices(); - for (TQStringList::Iterator holdingDevIt = holdingDeviceList.begin(); holdingDevIt != holdingDeviceList.end(); ++holdingDevIt) - { - TDEGenericDevice *hwHolderDevice = hwdevices->findBySystemPath(*holdingDevIt); - if (hwHolderDevice->type() == TDEGenericDeviceType::Disk) - { - TDEStorageDevice *holderSDevice = static_cast<TDEStorageDevice*>(hwHolderDevice); - const Medium holderMedium = findMedium(holderSDevice->deviceNode()); - if (!holderMedium.id().isEmpty()) - { - releaseHolders(holderMedium, true); - } - } - } - } - - if (handleThis) - { - // Unmount if necessary - if (medium.isMountable() && medium.isMounted()) - { - unmount(medium); - } - // Lock if necessary. - if (medium.isEncrypted() && !medium.isLocked()) - { - lock(medium); - } - } -#endif -} - void MountHelper::safeRemoval(const Medium &medium) { - /* - * Safely remove will performs the following tasks: - * 1) release children devices (if tdehw is available) - * 2) if the medium is mounted, unmount it - * 3) if the medium is encrypted and unlocked, lock it - * 4) invoke eject to release the medium. - * If any of the above steps fails, the procedure will interrupt and an - * error message will be displayed to the user. - * - * Note: previously eject was invoked also in case of unmount failure. This - * could lead to data loss and therefore the behaviour has been changed. - * If a user really wants to eject the medium, he needs to either unmount it - * first or invoke eject manually. - */ - if (medium.id().isEmpty()) - { - m_errorStr = i18n("Try to safe remove an unknown medium."); - errorAndExit(); - } - - // Release children devices - releaseHolders(medium); - - TQStringVariantMap opResult; - TQString device = medium.deviceNode(); - - // Unmount if necessary - if (medium.isMountable() && medium.isMounted()) - { - unmount(medium); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("safeRemove", medium.id()); + TQStringVariantMap safeRemoveResult; + if (reply.isValid()) { + reply.get(safeRemoveResult); } - // Lock if necessary. - if (medium.isEncrypted() && !medium.isLocked()) - { - lock(medium); + if (!safeRemoveResult.contains("result") || !safeRemoveResult["result"].toBool()) { + m_errorStr = safeRemoveResult.contains("errStr") ? safeRemoveResult["errStr"].toString() : i18n("Unknown safe removal error."); + kdDebug() << "medium safeRemoval " << m_errorStr << endl; + errorAndExit(); } } @@ -312,7 +186,7 @@ void MountHelper::openRealFolder(const Medium &medium) } } -MountHelper::MountHelper() : TDEApplication(), m_mediamanager("kded", "mediamanager") +MountHelper::MountHelper() : TDEApplication() { TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); m_errorStr = TQString::null; @@ -356,13 +230,12 @@ 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); ::exit(0); } else if (args->isSet("f")) @@ -418,7 +291,8 @@ void MountHelper::errorAndExit() void MountHelper::slotSendPassword() { - DCOPReply reply = m_mediamanager.call("unlock", m_mediumId, m_dialog->getPassword()); + DCOPRef mediamanager("kded", "mediamanager"); + DCOPReply reply = mediamanager.call("unlock", m_mediumId, m_dialog->getPassword()); TQStringVariantMap unlockResult; if (reply.isValid()) { reply.get(unlockResult); |