summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tdeioslave/media/libmediacommon/medium.cpp10
-rw-r--r--tdeioslave/media/libmediacommon/medium.h4
-rw-r--r--tdeioslave/media/mediamanager/halbackend.cpp45
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp79
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp68
-rw-r--r--tdeioslave/media/mounthelper/tdeio_media_mounthelper.h3
6 files changed, 126 insertions, 83 deletions
diff --git a/tdeioslave/media/libmediacommon/medium.cpp b/tdeioslave/media/libmediacommon/medium.cpp
index cb06a5eb8..797c409b4 100644
--- a/tdeioslave/media/libmediacommon/medium.cpp
+++ b/tdeioslave/media/libmediacommon/medium.cpp
@@ -252,16 +252,6 @@ void Medium::setLocked(bool locked)
m_properties[LOCKED] = locked ? "true" : "false";
}
-bool Medium::needMounting() const
-{
- return isMountable() && !isMounted();
-}
-
-bool Medium::needUnlocking() const
-{
- return isEncrypted() && isLocked();
-}
-
KURL Medium::prettyBaseURL() const
{
if (!baseURL().isEmpty())
diff --git a/tdeioslave/media/libmediacommon/medium.h b/tdeioslave/media/libmediacommon/medium.h
index 49a7fb980..3c9677c21 100644
--- a/tdeioslave/media/libmediacommon/medium.h
+++ b/tdeioslave/media/libmediacommon/medium.h
@@ -75,8 +75,8 @@ public:
bool softHidden() const { return m_properties[SOFT_HIDDEN] == "true"; };
bool isLocked() const { return m_properties[LOCKED] == "true"; };
- bool needMounting() const;
- bool needUnlocking() const;
+ bool needMounting() const { return isMountable() && !isMounted(); };
+ bool needUnlocking() const { return isEncrypted() && isLocked(); }
KURL prettyBaseURL() const;
TQString prettyLabel() const;
diff --git a/tdeioslave/media/mediamanager/halbackend.cpp b/tdeioslave/media/mediamanager/halbackend.cpp
index 190dda774..3c6f38af1 100644
--- a/tdeioslave/media/mediamanager/halbackend.cpp
+++ b/tdeioslave/media/mediamanager/halbackend.cpp
@@ -1488,8 +1488,14 @@ TQString HALBackend::isInFstab(const Medium *medium)
TQStringVariantMap HALBackend::mount(const Medium *medium)
{
TQStringVariantMap result;
- if (medium->isMounted()) {
- result["result"] = true;
+ if (!medium->isMountable()) {
+ result["errStr"] = i18n("%1 is not a mountable media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (medium->isMounted()) {
+ result["errStr"] = i18n("%1 is already mounted to %2.").arg(medium->deviceNode()).arg(medium->mountPoint());
+ result["result"] = false;
return result;
}
@@ -1666,14 +1672,19 @@ TQStringVariantMap HALBackend::unmount(const TQString &id)
result["result"] = false;
return result;
}
-
- if (!medium->isMounted()) {
- result["result"] = true;
+ else if (!medium->isMountable()) {
+ result["errStr"] = i18n("%1 is not a mountable media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (!medium->isMounted()) {
+ result["errStr"] = i18n("%1 is already unmounted.").arg(medium->deviceNode());
+ result["result"] = false;
return result;
}
TQString mountPoint = isInFstab(medium);
- if (!mountPoint.isNull())
+ if (!mountPoint.isEmpty())
{
struct mount_job_data data;
data.completed = false;
@@ -1848,9 +1859,14 @@ TQStringVariantMap HALBackend::unlock(const TQString &id, const TQString &passwo
result["result"] = false;
return result;
}
-
- if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
- result["result"] = true;
+ else if (!medium->isEncrypted()) {
+ result["errStr"] = i18n("%1 is not an encrypted media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (!medium->needUnlocking()) {
+ result["errStr"] = i18n("%1 is already unlocked.").arg(medium->deviceNode());
+ result["result"] = false;
return result;
}
@@ -1917,9 +1933,14 @@ TQStringVariantMap HALBackend::lock(const TQString &id)
result["result"] = false;
return result;
}
-
- if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
- result["result"] = true;
+ else if (!medium->isEncrypted()) {
+ result["errStr"] = i18n("%1 is not an encrypted media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (medium->needUnlocking()) {
+ result["errStr"] = i18n("%1 is already locked.").arg(medium->deviceNode());
+ result["result"] = false;
return result;
}
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
index bcd610ef4..b7dc942ba 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -1216,8 +1216,14 @@ TQStringVariantMap TDEBackend::mount(const Medium *medium)
kdDebug(1219) << "TDEBackend::mount for medium " << medium->name() << endl;
TQStringVariantMap result;
- if (medium->isMounted()) {
- result["result"] = true;
+ if (!medium->isMountable()) {
+ result["errStr"] = i18n("%1 is not a mountable media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (medium->isMounted()) {
+ result["errStr"] = i18n("%1 is already mounted to %2.").arg(medium->deviceNode()).arg(medium->mountPoint());
+ result["result"] = false;
return result;
}
@@ -1250,7 +1256,7 @@ TQStringVariantMap TDEBackend::mount(const Medium *medium)
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
if (!sdevice) {
- result["errStr"] = i18n("Internal error. Couldn't find medium.");
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
result["result"] = false;
return result;
}
@@ -1270,21 +1276,15 @@ TQStringVariantMap TDEBackend::mount(const Medium *medium)
}
TQString qerror;
- if (!medium->isEncrypted()) {
- // normal volume
- TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids);
- TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
- if (mountedPath.isEmpty()) {
- qerror = i18n("Unable to mount this device.");
- TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
- if (!errStr.isEmpty()) {
- qerror.append(i18n("<p>Technical details:<br>").append(errStr));
- }
+ TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids);
+ TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
+ if (mountedPath.isEmpty()) {
+ qerror = i18n("Unable to mount this device.");
+ TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
+ if (!errStr.isEmpty()) {
+ qerror.append(i18n("<p>Technical details:<br>").append(errStr));
}
}
- else {
- qerror = i18n("Unable to mount an encrypted device.");
- }
if (!qerror.isEmpty()) {
result["errStr"] = qerror;
@@ -1321,16 +1321,20 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
kdDebug(1219) << "TDEBackend::unmount for id " << id << endl;
TQStringVariantMap result;
-
- const Medium* medium = m_mediaList.findById(id);
+ const Medium *medium = m_mediaList.findById(id);
if (!medium) {
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
}
-
- if (!medium->isMounted()) {
- result["result"] = true;
+ else if (!medium->isMountable()) {
+ result["errStr"] = i18n("%1 is not a mountable media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (!medium->isMounted()) {
+ result["errStr"] = i18n("%1 is already unmounted.").arg(medium->deviceNode());
+ result["result"] = false;
return result;
}
@@ -1363,7 +1367,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
if (!sdevice) {
- result["errStr"] = i18n("Internal error. Couldn't find medium.");
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
result["result"] = false;
return result;
}
@@ -1433,23 +1437,27 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
kdDebug(1219) << "TDEBackend::unlock for id " << id << endl;
TQStringVariantMap result;
-
- const Medium* medium = m_mediaList.findById(id);
+ const Medium *medium = m_mediaList.findById(id);
if (!medium) {
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
}
-
- if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
- result["result"] = true;
+ else if (!medium->isEncrypted()) {
+ result["errStr"] = i18n("%1 is not an encrypted media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (!medium->needUnlocking()) {
+ result["errStr"] = i18n("%1 is already unlocked.").arg(medium->deviceNode());
+ 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.");
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
result["result"] = false;
return result;
}
@@ -1478,22 +1486,27 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
TQStringVariantMap result;
- const Medium* medium = m_mediaList.findById(id);
+ const Medium *medium = m_mediaList.findById(id);
if (!medium) {
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
}
-
- if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) {
- result["result"] = true;
+ else if (!medium->isEncrypted()) {
+ result["errStr"] = i18n("%1 is not an encrypted media.").arg(medium->deviceNode());
+ result["result"] = false;
+ return result;
+ }
+ else if (medium->needUnlocking()) {
+ result["errStr"] = i18n("%1 is already locked.").arg(medium->deviceNode());
+ 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.");
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
result["result"] = false;
return result;
}
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
index 564934667..dd12901cc 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp
@@ -67,7 +67,6 @@ const Medium MountHelper::findMedium(const KURL &url)
MountHelper::MountHelper() : TDEApplication()
{
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
-
m_errorStr = TQString::null;
KURL url(args->url(0));
@@ -77,25 +76,28 @@ MountHelper::MountHelper() : TDEApplication()
if (m_errorStr.isEmpty()) {
m_errorStr+= i18n("%1 cannot be found.").arg(url.prettyURL());
}
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
- return;
+ errorAndExit();
}
+ TQString device = medium.deviceNode();
if (!medium.isMountable() && !medium.isEncrypted() && !args->isSet("e") && !args->isSet("s"))
{
- m_errorStr = i18n("%1 is not a mountable or encrypted media.").arg(url.prettyURL());
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
- return;
+ m_errorStr = i18n("%1 is not a mountable or encrypted media.").arg(device);
+ errorAndExit();
}
- TQString device = medium.deviceNode();
- TQString mount_point = medium.mountPoint();
-
- m_isCdrom = medium.mimeType().find("dvd") != -1 || medium.mimeType().find("cd") != -1;
-
if (args->isSet("m"))
{
// Mount drive
+ 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();
+ }
+
DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("mount", medium.id());
TQStringVariantMap mountResult;
@@ -107,12 +109,21 @@ MountHelper::MountHelper() : TDEApplication()
}
else {
m_errorStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
}
else if (args->isSet("u"))
{
// Unmount drive
+ 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();
+ }
+
DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("unmount", medium.id());
TQStringVariantMap unmountResult;
@@ -125,7 +136,7 @@ MountHelper::MountHelper() : TDEApplication()
else {
m_errorStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unknown unmount error.");
kdDebug() << "medium unmount " << m_errorStr << endl;
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
}
else if (args->isSet("k"))
@@ -133,15 +144,13 @@ MountHelper::MountHelper() : TDEApplication()
// Unlock drive
if (!medium.isEncrypted())
{
- m_errorStr = i18n("%1 is not an encrypted media.").arg(url.prettyURL());
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
- return;
+ m_errorStr = i18n("%1 is not an encrypted media.").arg(device);
+ errorAndExit();
}
if (!medium.needUnlocking())
{
- m_errorStr = i18n("%1 is already unlocked.").arg(url.prettyURL());
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
- return;
+ m_errorStr = i18n("%1 is already unlocked.").arg(device);
+ errorAndExit();
}
TQString iconName = medium.iconName();
@@ -160,6 +169,17 @@ MountHelper::MountHelper() : TDEApplication()
else if (args->isSet("l"))
{
// Lock drive
+ 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();
+ }
+
DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("lock", medium.id());
TQStringVariantMap lockResult;
@@ -172,7 +192,7 @@ MountHelper::MountHelper() : TDEApplication()
else {
m_errorStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unknown lock error.");
kdDebug() << "medium lock " << m_errorStr << endl;
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
}
else if (args->isSet("e"))
@@ -223,7 +243,7 @@ MountHelper::MountHelper() : TDEApplication()
invokeEject(device, true);
}
else {
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
}
else
@@ -267,13 +287,13 @@ void MountHelper::ejectFinished(TDEProcess *proc)
}
else {
if (!m_errorStr.isEmpty()) {
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
::exit(0);
}
}
-void MountHelper::error()
+void MountHelper::errorAndExit()
{
TQString prettyErrorString = m_errorStr;
if (m_errorStr.contains("<") && m_errorStr.contains(">")) {
@@ -301,7 +321,7 @@ void MountHelper::slotSendPassword()
m_errorStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : i18n("Unknown unlock error.");
kdDebug() << "medium unlock " << m_errorStr << endl;
emit signalPasswordError(m_errorStr);
- TQTimer::singleShot(0, this, TQT_SLOT(error()));
+ errorAndExit();
}
}
diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
index 97df6b7e8..60cdb064d 100644
--- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
+++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h
@@ -40,7 +40,6 @@ private:
const Medium findMedium(const KURL &url);
void invokeEject(const TQString &device, bool quiet=false);
TQString m_errorStr;
- bool m_isCdrom;
TQString m_mediumId;
Dialog *dialog;
@@ -48,7 +47,7 @@ private slots:
void slotSendPassword();
void slotCancel();
void ejectFinished(TDEProcess* proc);
- void error();
+ void errorAndExit();
signals:
void signalPasswordError(TQString errorMsg);