tdeio media: add releaseHolders parameter to lock/lockByNode dcop calls.

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

@ -990,7 +990,7 @@ void DevicePropertiesDialog::lockDisk() {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE // Use DCOP call instead of a tdehw call for consistent behavior across TDE
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode(), true);
TQStringVariantMap lockResult; TQStringVariantMap lockResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(lockResult); reply.get(lockResult);

@ -578,7 +578,7 @@ void HwDeviceSystemTray::slotLockDevice(int parameter)
{ {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE // Use DCOP call instead of a tdehw call for consistent behavior across TDE
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode(), true);
TQStringVariantMap lockResult; TQStringVariantMap lockResult;
if (reply.isValid()) if (reply.isValid())
{ {

@ -260,12 +260,12 @@ TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &pas
return result; return result;
} }
TQStringVariantMap MediaManager::lock(const TQString &uid) TQStringVariantMap MediaManager::lock(const TQString &uid, bool releaseHolders)
{ {
#ifdef COMPILE_TDEHARDWAREBACKEND #ifdef COMPILE_TDEHARDWAREBACKEND
if (m_tdebackend) if (m_tdebackend)
{ {
return m_tdebackend->lock(uid); return m_tdebackend->lock(uid, releaseHolders);
} }
#endif #endif
TQStringVariantMap result; TQStringVariantMap result;
@ -324,7 +324,7 @@ TQStringVariantMap MediaManager::unlockByNode(const TQString &deviceNode, const
return unlock(medium->id(), password); return unlock(medium->id(), password);
} }
TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode) TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode, bool releaseHolders)
{ {
const Medium *medium = m_mediaList.findByNode(deviceNode); const Medium *medium = m_mediaList.findByNode(deviceNode);
if (!medium) { if (!medium) {
@ -333,7 +333,7 @@ TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode)
result["result"] = false; result["result"] = false;
return result; return result;
} }
return lock(medium->id()); return lock(medium->id(), releaseHolders);
} }
TQStringVariantMap MediaManager::ejectByNode(const TQString &deviceNode) TQStringVariantMap MediaManager::ejectByNode(const TQString &deviceNode)

@ -51,13 +51,13 @@ k_dcop:
TQStringVariantMap mount(const TQString &uid); TQStringVariantMap mount(const TQString &uid);
TQStringVariantMap unmount(const TQString &uid); TQStringVariantMap unmount(const TQString &uid);
TQStringVariantMap unlock(const TQString &uid, const TQString &password); TQStringVariantMap unlock(const TQString &uid, const TQString &password);
TQStringVariantMap lock(const TQString &uid); TQStringVariantMap lock(const TQString &uid, bool releaseHolders);
TQStringVariantMap eject(const TQString &uid); TQStringVariantMap eject(const TQString &uid);
TQStringVariantMap mountByNode(const TQString &deviceNode); TQStringVariantMap mountByNode(const TQString &deviceNode);
TQStringVariantMap unmountByNode(const TQString &deviceNode); TQStringVariantMap unmountByNode(const TQString &deviceNode);
TQStringVariantMap unlockByNode(const TQString &deviceNode, const TQString &password); TQStringVariantMap unlockByNode(const TQString &deviceNode, const TQString &password);
TQStringVariantMap lockByNode(const TQString &deviceNode); TQStringVariantMap lockByNode(const TQString &deviceNode, bool releaseHolders);
TQStringVariantMap ejectByNode(const TQString &deviceNode); TQStringVariantMap ejectByNode(const TQString &deviceNode);
TQString mimeType(const TQString &name); TQString mimeType(const TQString &name);

@ -1478,9 +1478,10 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
return result; return result;
} }
TQStringVariantMap TDEBackend::lock(const TQString &id) TQStringVariantMap TDEBackend::lock(const TQString &id, bool releaseHolders)
{ {
kdDebug(1219) << "TDEBackend::lock for id " << id << endl; kdDebug(1219) << "TDEBackend::lock for id " << id << ", release holders "
<< releaseHolders << endl;
TQStringVariantMap result; TQStringVariantMap result;
@ -1509,6 +1510,12 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
return result; return result;
} }
// Release device holders if requested
if (releaseHolders)
{
releaseHolderDevices(medium->deviceNode(), false);
}
TQStringVariantMap lockResult = sdevice->lockDevice(); TQStringVariantMap lockResult = sdevice->lockDevice();
if (lockResult["result"].toBool() == false) { if (lockResult["result"].toBool() == false) {
TQString qerror = i18n("<b>Unable to lock the device.</b>"); TQString qerror = i18n("<b>Unable to lock the device.</b>");
@ -1566,6 +1573,59 @@ TQStringVariantMap TDEBackend::eject(const TQString &id)
return result; return result;
} }
void TDEBackend::releaseHolderDevices(const TQString &deviceNode, bool handleThis)
{
kdDebug(1219) << "TDEBackend::releaseHolderDevices for node " << deviceNode
<< ", handle this " << (handleThis ? "yes" : "no") << endl;
const Medium *medium = m_mediaList.findByNode(deviceNode);
if (!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 = m_mediaList.findByNode(holderSDevice->deviceNode());
if (holderMedium && !holderMedium->id().isEmpty())
{
releaseHolderDevices(holderMedium->deviceNode(), true);
}
}
}
}
if (handleThis)
{
// Unmount if necessary
if (medium->isMountable() && medium->isMounted())
{
unmount(medium->id());
// Must process udev events before continuing, to make sure all
// affected devices are properly updated
tqApp->processEvents();
}
// Lock if necessary.
if (medium->isEncrypted() && !medium->isLocked())
{
lock(medium->id(), false);
// Must process udev events before continuing, to make sure all
// affected devices are properly updated
tqApp->processEvents();
}
}
}
void TDEBackend::slotResult(TDEIO::Job *job) void TDEBackend::slotResult(TDEIO::Job *job)
{ {
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();

@ -72,8 +72,8 @@ public:
TQStringVariantMap mount(const TQString &id); TQStringVariantMap mount(const TQString &id);
TQStringVariantMap unmount(const TQString &id); TQStringVariantMap unmount(const TQString &id);
TQStringVariantMap unlock(const TQString &id, const TQString &password); TQStringVariantMap unlock(const TQString &id, const TQString &password);
TQStringVariantMap lock(const TQString &id); TQStringVariantMap lock(const TQString &id, bool releaseHolders);
TQStringVariantMap eject(const TQString &uid); TQStringVariantMap eject(const TQString &id);
private: private:
/** /**
@ -118,17 +118,13 @@ private:
*/ */
void ResetProperties(TDEStorageDevice * sdevice, bool allowNotification=false, bool overrideIgnoreList=false); void ResetProperties(TDEStorageDevice * sdevice, bool allowNotification=false, bool overrideIgnoreList=false);
/**
* Find the medium that is concerned with device udi
*/
// const char* findMediumUdiFromUdi(const char* udi);
void setVolumeProperties(Medium* medium); void setVolumeProperties(Medium* medium);
bool setFloppyProperties(Medium* medium); bool setFloppyProperties(Medium* medium);
void setFloppyMountState( Medium* medium ); void setFloppyMountState(Medium* medium);
// bool setFstabProperties(Medium* medium);
void setCameraProperties(Medium* medium); void setCameraProperties(Medium* medium);
void releaseHolderDevices(const TQString &deviceNode, bool handleThis);
TQString generateName(const TQString &devNode); TQString generateName(const TQString &devNode);
static TQString isInFstab(const Medium *medium); static TQString isInFstab(const Medium *medium);
static TQString listUsingProcesses(const Medium *medium); static TQString listUsingProcesses(const Medium *medium);
static TQString killUsingProcesses(const Medium *medium); static TQString killUsingProcesses(const Medium *medium);

@ -29,6 +29,7 @@
#include <kurl.h> #include <kurl.h>
#include <tdemessagebox.h> #include <tdemessagebox.h>
#include <dcopclient.h> #include <dcopclient.h>
#include <dcopref.h>
#include <tqtimer.h> #include <tqtimer.h>
#include <stdlib.h> #include <stdlib.h>
#include <kdebug.h> #include <kdebug.h>
@ -45,7 +46,8 @@
const Medium MountHelper::findMedium(const TQString &device) 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()) if (!reply.isValid())
{ {
m_errorStr = i18n("The TDE mediamanager is not running.\n"); m_errorStr = i18n("The TDE mediamanager is not running.\n");
@ -57,7 +59,8 @@ const Medium MountHelper::findMedium(const TQString &device)
void MountHelper::mount(const Medium &medium) void MountHelper::mount(const Medium &medium)
{ {
DCOPReply reply = m_mediamanager.call("mount", medium.id()); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("mount", medium.id());
TQStringVariantMap mountResult; TQStringVariantMap mountResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(mountResult); reply.get(mountResult);
@ -70,7 +73,8 @@ void MountHelper::mount(const Medium &medium)
void MountHelper::unmount(const Medium &medium) void MountHelper::unmount(const Medium &medium)
{ {
DCOPReply reply = m_mediamanager.call("unmount", medium.id()); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("unmount", medium.id());
TQStringVariantMap unmountResult; TQStringVariantMap unmountResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(unmountResult); reply.get(unmountResult);
@ -105,27 +109,8 @@ void MountHelper::unlock(const Medium &medium)
void MountHelper::lock(const Medium &medium) void MountHelper::lock(const Medium &medium)
{ {
if (medium.id().isEmpty()) DCOPRef mediamanager("kded", "mediamanager");
{ DCOPReply reply = mediamanager.call("lock", medium.id(), true);
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());
TQStringVariantMap lockResult; TQStringVariantMap lockResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(lockResult); reply.get(lockResult);
@ -140,7 +125,8 @@ void MountHelper::lock(const Medium &medium)
void MountHelper::eject(const Medium &medium) void MountHelper::eject(const Medium &medium)
{ {
#ifdef WITH_TDEHWLIB #ifdef WITH_TDEHWLIB
DCOPReply reply = m_mediamanager.call("eject", medium.id()); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("eject", medium.id());
TQStringVariantMap ejectResult; TQStringVariantMap ejectResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(ejectResult); reply.get(ejectResult);
@ -271,7 +257,7 @@ void MountHelper::openRealFolder(const Medium &medium)
} }
} }
MountHelper::MountHelper() : TDEApplication(), m_mediamanager("kded", "mediamanager") MountHelper::MountHelper() : TDEApplication()
{ {
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
m_errorStr = TQString::null; m_errorStr = TQString::null;
@ -377,7 +363,8 @@ void MountHelper::errorAndExit()
void MountHelper::slotSendPassword() 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; TQStringVariantMap unlockResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(unlockResult); reply.get(unlockResult);

@ -25,7 +25,6 @@
#include <tdeapplication.h> #include <tdeapplication.h>
#include <tqstring.h> #include <tqstring.h>
#include <tdeio/job.h> #include <tdeio/job.h>
#include <dcopref.h>
#include "medium.h" #include "medium.h"
@ -44,7 +43,6 @@ private:
TQString m_errorStr; TQString m_errorStr;
TQString m_mediumId; TQString m_mediumId;
Dialog *m_dialog; Dialog *m_dialog;
DCOPRef m_mediamanager;
const Medium findMedium(const TQString &device); const Medium findMedium(const TQString &device);
void error(); void error();

Loading…
Cancel
Save