summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2022-02-19 16:13:03 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2022-02-19 16:13:03 +0900
commit8d0f49aeb4a37176e25c7393ad6a31b8b9e8fcf4 (patch)
treea0cb97849a1dea54c91bed8bca9bfb800bdf5019 /tdeioslave/media
parentcc236553afa96e1f2bd2dba35b9d93080e273f8c (diff)
downloadtdebase-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')
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.cpp126
-rw-r--r--tdeioslave/media/mediamanager/mediamanager.h2
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp42
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.h3
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp77
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.h2
6 files changed, 133 insertions, 119 deletions
diff --git a/tdeioslave/media/mediamanager/mediamanager.cpp b/tdeioslave/media/mediamanager/mediamanager.cpp
index 9b0ca7ceb..c3cd62524 100644
--- a/tdeioslave/media/mediamanager/mediamanager.cpp
+++ b/tdeioslave/media/mediamanager/mediamanager.cpp
@@ -189,103 +189,103 @@ TQStringList MediaManager::properties(const TQString &name)
TQStringList MediaManager::mountoptions(const TQString &name)
{
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend)
- return TQStringList();
- return m_tdebackend->mountoptions(name);
-#else
- return TQStringList();
+ if (m_tdebackend)
+ {
+ return m_tdebackend->mountoptions(name);
+ }
#endif
+ return TQStringList();
}
bool MediaManager::setMountoptions(const TQString &name, const TQStringList &options)
{
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend)
- return false;
- return m_tdebackend->setMountoptions(name, options);
-#else
- return false;
+ if (m_tdebackend)
+ {
+ return m_tdebackend->setMountoptions(name, options);
+ }
#endif
+ return false;
}
TQStringVariantMap MediaManager::mount(const TQString &uid)
{
- TQStringVariantMap result;
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_tdebackend)
+ {
+ return m_tdebackend->mount(uid);
}
- return m_tdebackend->mount(uid);
#else
- if (!m_fstabbackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_fstabbackend)
+ {
+ return m_fstabbackend->mount(uid);
}
- return m_fstabbackend->mount(uid);
#endif
+ TQStringVariantMap result;
+ result["errStr"] = i18n("Feature only available with the TDE or fstab hardware backend");
+ result["result"] = false;
+ return result;
}
TQStringVariantMap MediaManager::unmount(const TQString &uid)
{
- TQStringVariantMap result;
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_tdebackend)
+ {
+ return m_tdebackend->unmount(uid);
}
- return m_tdebackend->unmount(uid);
#else
- if (!m_fstabbackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_fstabbackend)
+ {
+ return m_fstabbackend->unmount(uid);
}
- return m_fstabbackend->unmount(uid);
#endif
+ TQStringVariantMap result;
+ result["errStr"] = i18n("Feature only available with the TDE or fstab hardware backend");
+ result["result"] = false;
+ return result;
}
TQStringVariantMap MediaManager::unlock(const TQString &uid, const TQString &password)
{
- TQStringVariantMap result;
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_tdebackend)
+ {
+ return m_tdebackend->unlock(uid, password);
}
- return m_tdebackend->unlock(uid, password);
-#else
-// if (!m_fstabbackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
-// }
-// return m_fstabbackend->unlock(uid, password);
#endif
+ TQStringVariantMap result;
+ result["errStr"] = i18n("Feature only available with the TDE hardware backend");
+ result["result"] = false;
+ return result;
}
TQStringVariantMap MediaManager::lock(const TQString &uid)
{
+#ifdef COMPILE_TDEHARDWAREBACKEND
+ if (m_tdebackend)
+ {
+ return m_tdebackend->lock(uid);
+ }
+#endif
TQStringVariantMap result;
+ result["errStr"] = i18n("Feature only available with the TDE hardware backend");
+ result["result"] = false;
+ return result;
+}
+
+TQStringVariantMap MediaManager::eject(const TQString &uid)
+{
#ifdef COMPILE_TDEHARDWAREBACKEND
- if (!m_tdebackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
+ if (m_tdebackend)
+ {
+ return m_tdebackend->eject(uid);
}
- return m_tdebackend->lock(uid);
-#else
-// if (!m_fstabbackend) {
- result["errStr"] = i18n("Feature only available with the TDE hardware backend");
- result["result"] = false;
- return result;
-// }
-// return m_fstabbackend->lock(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)
@@ -336,6 +336,18 @@ TQStringVariantMap MediaManager::lockByNode(const TQString &deviceNode)
return lock(medium->id());
}
+TQStringVariantMap MediaManager::ejectByNode(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 eject(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 08810464c..7d5e6dc24 100644
--- a/tdeioslave/media/mediamanager/mediamanager.h
+++ b/tdeioslave/media/mediamanager/mediamanager.h
@@ -52,11 +52,13 @@ k_dcop:
TQStringVariantMap unmount(const TQString &uid);
TQStringVariantMap unlock(const TQString &uid, const TQString &password);
TQStringVariantMap lock(const TQString &uid);
+ TQStringVariantMap eject(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);
+ TQStringVariantMap ejectByNode(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 1da7634d0..ba99b8c0c 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -1474,7 +1474,6 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
}
ResetProperties(sdevice, false, true);
- result["result"] = unlockResult["unlockedDevice"];
result["result"] = true;
return result;
}
@@ -1526,6 +1525,47 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
return result;
}
+TQStringVariantMap TDEBackend::eject(const TQString &id)
+{
+ kdDebug(1219) << "TDEBackend::eject 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;
+ }
+
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (!sdevice)
+ {
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
+ result["result"] = false;
+ return result;
+ }
+
+ TQStringVariantMap ejectResult = sdevice->ejectDrive();
+ if (ejectResult["result"].toBool() == false)
+ {
+ TQString qerror = i18n("<b>Unable to eject the device.</b>");
+ TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : TQString::null;
+ if (!errStr.isEmpty())
+ {
+ qerror.append(i18n("<p>Technical details:<br>").append(errStr));
+ result["errStr"] = qerror;
+ result["result"] = false;
+ return result;
+ }
+ }
+
+ result["result"] = true;
+ return result;
+}
+
void TDEBackend::slotResult(TDEIO::Job *job)
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.h b/tdeioslave/media/mediamanager/tdehardwarebackend.h
index 449d6369d..ab7eeea97 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.h
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.h
@@ -68,11 +68,12 @@ public:
bool setMountoptions(const TQString &id, const TQStringList &options);
- TQStringVariantMap mount(const TQString &id);
TQStringVariantMap mount(const Medium *medium);
+ TQStringVariantMap mount(const TQString &id);
TQStringVariantMap unmount(const TQString &id);
TQStringVariantMap unlock(const TQString &id, const TQString &password);
TQStringVariantMap lock(const TQString &id);
+ TQStringVariantMap eject(const TQString &uid);
private:
/**
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"))
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
index 5bbe594b8..eff02b1e1 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
@@ -53,7 +53,7 @@ private:
void unmount(const Medium &medium);
void unlock(const Medium &medium);
void lock(const Medium &medium);
- void eject(const TQString &device, bool quiet=false);
+ void eject(const Medium &medium);
void safeRemoval(const Medium &medium);
void releaseHolders(const Medium &medium, bool handleThis = false);
void openRealFolder(const Medium &medium);