Add 'safeRemove' and 'safeRemoveByNode' to mediamanager DCOP interface.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/263/head
Michele Calgaro 2 years ago
parent 88d92af3c1
commit 4974727d50
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -288,6 +288,20 @@ TQStringVariantMap MediaManager::eject(const TQString &uid)
return result;
}
TQStringVariantMap MediaManager::safeRemove(const TQString &uid)
{
#ifdef COMPILE_TDEHARDWAREBACKEND
if (m_tdebackend)
{
return m_tdebackend->safeRemove(uid);
}
#endif
TQStringVariantMap result;
result["errStr"] = i18n("Feature only available with the TDE hardware backend");
result["result"] = false;
return result;
}
TQStringVariantMap MediaManager::mountByNode(const TQString &deviceNode)
{
const Medium *medium = m_mediaList.findByNode(deviceNode);
@ -348,6 +362,18 @@ TQStringVariantMap MediaManager::ejectByNode(const TQString &deviceNode)
return eject(medium->id());
}
TQStringVariantMap MediaManager::safeRemoveByNode(const TQString &deviceNode)
{
const Medium *medium = m_mediaList.findByNode(deviceNode);
if (!medium) {
TQStringVariantMap result;
result["errStr"] = i18n("No such medium: %1").arg(deviceNode);
result["result"] = false;
return result;
}
return safeRemove(medium->id());
}
TQString MediaManager::mimeType(const TQString &name)
{
const Medium *m = getMediumByName(name);

@ -53,12 +53,14 @@ k_dcop:
TQStringVariantMap unlock(const TQString &uid, const TQString &password);
TQStringVariantMap lock(const TQString &uid, bool releaseHolders);
TQStringVariantMap eject(const TQString &uid);
TQStringVariantMap safeRemove(const TQString &uid);
TQStringVariantMap mountByNode(const TQString &deviceNode);
TQStringVariantMap unmountByNode(const TQString &deviceNode);
TQStringVariantMap unlockByNode(const TQString &deviceNode, const TQString &password);
TQStringVariantMap lockByNode(const TQString &deviceNode, bool releaseHolders);
TQStringVariantMap ejectByNode(const TQString &deviceNode);
TQStringVariantMap safeRemoveByNode(const TQString &deviceNode);
TQString mimeType(const TQString &name);
TQString nameForLabel(const TQString &label);

@ -1575,6 +1575,24 @@ TQStringVariantMap TDEBackend::eject(const TQString &id)
return result;
}
TQStringVariantMap TDEBackend::safeRemove(const TQString &id)
{
kdDebug(1219) << "TDEBackend::safeRemove 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;
}
releaseHolderDevices(medium->deviceNode(), true);
return eject(id);
}
void TDEBackend::releaseHolderDevices(const TQString &deviceNode, bool handleThis)
{
kdDebug(1219) << "TDEBackend::releaseHolderDevices for node " << deviceNode

@ -74,6 +74,7 @@ public:
TQStringVariantMap unlock(const TQString &id, const TQString &password);
TQStringVariantMap lock(const TQString &id, bool releaseHolders);
TQStringVariantMap eject(const TQString &id);
TQStringVariantMap safeRemove(const TQString &uid);
private:
/**

@ -150,89 +150,18 @@ void MountHelper::eject(const Medium &medium)
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();
}
}
@ -307,7 +236,6 @@ MountHelper::MountHelper() : TDEApplication()
else if (args->isSet("s"))
{
safeRemoval(medium);
eject(medium);
::exit(0);
}
else if (args->isSet("f"))

@ -53,7 +53,6 @@ private:
void lock(const Medium &medium);
void eject(const Medium &medium);
void safeRemoval(const Medium &medium);
void releaseHolders(const Medium &medium, bool handleThis = false);
void openRealFolder(const Medium &medium);
private slots:

Loading…
Cancel
Save