summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2022-03-27 20:01:48 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2022-03-27 20:01:48 +0900
commit4974727d50923a4393e5f0daddf4694c6e082a84 (patch)
tree97b2bc694bab23db107f132188ebed4fc46ac3da
parent88d92af3c14c0b0b9149440c1b5d38e8fb7cbd79 (diff)
downloadtdebase-4974727d50923a4393e5f0daddf4694c6e082a84.tar.gz
tdebase-4974727d50923a4393e5f0daddf4694c6e082a84.zip
Add 'safeRemove' and 'safeRemoveByNode' to mediamanager DCOP interface.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.cpp26
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.h2
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp18
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.h1
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp90
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.h1
6 files changed, 56 insertions, 82 deletions
diff --git a/tdeioslave/media/mediamanager/mediamanager.cpp b/tdeioslave/media/mediamanager/mediamanager.cpp
index dba4c1150..f8c2a574b 100644
--- a/tdeioslave/media/mediamanager/mediamanager.cpp
+++ b/tdeioslave/media/mediamanager/mediamanager.cpp
@@ -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);
diff --git a/tdeioslave/media/mediamanager/mediamanager.h b/tdeioslave/media/mediamanager/mediamanager.h
index dfb3e577c..7bc67b24c 100644
--- a/tdeioslave/media/mediamanager/mediamanager.h
+++ b/tdeioslave/media/mediamanager/mediamanager.h
@@ -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);
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
index bb5849149..0e6eb4ad8 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -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
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.h b/tdeioslave/media/mediamanager/tdehardwarebackend.h
index e1b3a9f85..308a9421e 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.h
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.h
@@ -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:
/**
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
index 706b5e13a..9094b8e56 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
@@ -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"))
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
index 540012ce3..e1ae0c5c2 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
@@ -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: