Improved media manager dcop interface for mount/unmount/decrypt/undecrypt methods by returning more information.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/39/head
Michele Calgaro 5 years ago
parent 7d2c7f0621
commit e44487e1b8
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -266,12 +266,16 @@ bool MediaImpl::ensureMediumMounted(Medium &medium)
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call( "mount", medium.id()); DCOPReply reply = mediamanager.call( "mount", medium.id());
if (reply.isValid()) TQStringVariantMap mountResult;
reply.get(m_lastErrorMessage); if (reply.isValid()) {
else reply.get(mountResult);
m_lastErrorMessage = i18n("Internal Error"); }
if (!m_lastErrorMessage.isEmpty()) if (!mountResult.contains("result") || !mountResult["result"].toBool()) {
m_lastErrorMessage = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
}
if (!m_lastErrorMessage.isEmpty()) {
m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED; m_lastErrorCode = TDEIO::ERR_SLAVE_DEFINED;
}
else { else {
tqApp->eventLoop()->enterLoop(); tqApp->eventLoop()->enterLoop();
} }

@ -97,24 +97,34 @@ FstabBackend::~FstabBackend()
KDirWatch::self()->removeFile(MTAB); KDirWatch::self()->removeFile(MTAB);
} }
TQString FstabBackend::mount( const TQString &_udi ) TQStringVariantMap FstabBackend::mount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
if (!medium) const Medium *medium = m_mediaList.findById(id);
return i18n("No such medium: %1").arg(_udi); if (!medium) {
TDEIO::Job* job = TDEIO::mount( false, 0, medium->deviceNode(), medium->mountPoint()); result["errStr"] = i18n("No such medium: %1").arg(id);
TDEIO::NetAccess::synchronousRun( job, 0 ); result["result"] = false;
return TQString::null; return result;
}
TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), medium->mountPoint());
TDEIO::NetAccess::synchronousRun(job, 0);
result["result"] = true;
return result;
} }
TQString FstabBackend::unmount( const TQString &_udi ) TQStringVariantMap FstabBackend::unmount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
if (!medium) const Medium *medium = m_mediaList.findById(id);
return i18n("No such medium: %1").arg(_udi); if (!medium) {
TDEIO::Job* job = TDEIO::unmount( medium->mountPoint(), false); result["errStr"] = i18n("No such medium: %1").arg(id);
TDEIO::NetAccess::synchronousRun( job, 0 ); result["result"] = false;
return TQString::null; return result;
}
TDEIO::Job *job = TDEIO::unmount(medium->mountPoint(), false);
TDEIO::NetAccess::synchronousRun(job, 0);
result["result"] = true;
return result;
} }
void FstabBackend::slotDirty(const TQString &path) void FstabBackend::slotDirty(const TQString &path)

@ -1,5 +1,5 @@
/* This file is part of the KDE Project /* This file is part of the KDE Project
Copyright (c) 2004 Kévin Ottens <ervin ipsquad net> Copyright (c) 2004 Kévin Ottens <ervin ipsquad net>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
@ -23,7 +23,7 @@
#include <tqobject.h> #include <tqobject.h>
#include <tqstringlist.h> #include <tqstringlist.h>
#include <tqmap.h> #include <tqvariant.h>
#ifdef Q_OS_FREEBSD #ifdef Q_OS_FREEBSD
#include <tqtimer.h> #include <tqtimer.h>
@ -42,8 +42,8 @@ public:
TQString &mimeType, TQString &iconName, TQString &mimeType, TQString &iconName,
TQString &label); TQString &label);
TQString mount(const TQString &id); TQStringVariantMap mount(const TQString &id);
TQString unmount(const TQString &id); TQStringVariantMap unmount(const TQString &id);
private slots: private slots:
void slotDirty(const TQString &path); void slotDirty(const TQString &path);

@ -1449,10 +1449,13 @@ TQString HALBackend::isInFstab(const Medium *medium)
return TQString::null; return TQString::null;
} }
TQString HALBackend::mount(const Medium *medium) TQStringVariantMap HALBackend::mount(const Medium *medium)
{ {
if (medium->isMounted()) TQStringVariantMap result;
return TQString(); // that was easy if (medium->isMounted()) {
result["result"] = true;
return result;
}
TQString mountPoint = isInFstab(medium); TQString mountPoint = isInFstab(medium);
if (!mountPoint.isNull()) if (!mountPoint.isNull())
@ -1463,24 +1466,27 @@ TQString HALBackend::mount(const Medium *medium)
kdDebug() << "triggering user mount " << medium->deviceNode() << " " << mountPoint << " " << medium->id() << endl; kdDebug() << "triggering user mount " << medium->deviceNode() << " " << mountPoint << " " << medium->id() << endl;
TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint ); TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint );
connect(job, TQT_SIGNAL( result (TDEIO::Job *)), connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
TQT_SLOT( slotResult( TDEIO::Job *)));
mount_jobs[job] = &data; mount_jobs[job] = &data;
// The caller expects the device to be mounted when the function // The caller expects the device to be mounted when the function
// completes. Thus block until the job completes. // completes. Thus block until the job completes.
while (!data.completed) { while (!data.completed) {
kapp->eventLoop()->enterLoop(); kapp->eventLoop()->enterLoop();
} }
// Return the error message (if any) to the caller if (!data.error) {
return (data.error) ? data.errorMessage : TQString::null; result["result"] = true;
return result;
} else if (medium->id().startsWith("/org/kde/") ) }
return i18n("Permission denied"); else {
result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
TQStringList soptions; result["result"] = false;
return result;
}
}
kdDebug() << "mounting " << medium->id() << "..." << endl; kdDebug() << "mounting " << medium->id() << "..." << endl;
TQStringList soptions;
TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id())); TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id()));
if (valids["flush"] == "true") if (valids["flush"] == "true")
soptions << "flush"; soptions << "flush";
@ -1508,7 +1514,6 @@ TQString HALBackend::mount(const Medium *medium)
if (medium->fsType() == "ntfs") { if (medium->fsType() == "ntfs") {
TQString fsLocale("locale="); TQString fsLocale("locale=");
fsLocale += setlocale(LC_ALL, ""); fsLocale += setlocale(LC_ALL, "");
soptions << fsLocale; soptions << fsLocale;
} }
@ -1549,7 +1554,6 @@ TQString HALBackend::mount(const Medium *medium)
} }
} }
const char **options = new const char*[soptions.size() + 1]; const char **options = new const char*[soptions.size() + 1];
uint noptions = 0; uint noptions = 0;
for (TQStringList::ConstIterator it = soptions.begin(); it != soptions.end(); ++it, ++noptions) for (TQStringList::ConstIterator it = soptions.begin(); it != soptions.end(); ++it, ++noptions)
@ -1559,13 +1563,13 @@ TQString HALBackend::mount(const Medium *medium)
} }
options[noptions] = NULL; options[noptions] = NULL;
TQString qerror = i18n("Cannot mount encrypted drives!"); TQString qerror;
if (!medium->isEncrypted()) { if (!medium->isEncrypted()) {
// normal volume // normal volume
qerror = mount_priv(medium->id().latin1(), mount_point.utf8(), options, noptions, dbus_connection); qerror = mount_priv(medium->id().latin1(), mount_point.utf8(), options, noptions, dbus_connection);
} else { } else {
// see if we have a clear volume // see if we have a clear volume
error = i18n("Cannot mount encrypted drives!");
LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1()); LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1());
if (halVolume) { if (halVolume) {
char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume); char* clearUdi = libhal_volume_crypto_get_clear_volume_udi(m_halContext, halVolume);
@ -1579,45 +1583,59 @@ TQString HALBackend::mount(const Medium *medium)
if (!qerror.isEmpty()) { if (!qerror.isEmpty()) {
kdError() << "mounting " << medium->id() << " returned " << qerror << endl; kdError() << "mounting " << medium->id() << " returned " << qerror << endl;
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
medium->setHalMounted(true); medium->setHalMounted(true);
ResetProperties(medium->id().latin1()); ResetProperties(medium->id().latin1());
return TQString(); result["result"] = true;
return result;
} }
TQString HALBackend::mount(const TQString &_udi) TQStringVariantMap HALBackend::mount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); const Medium *medium = m_mediaList.findById(id);
if (!medium) if (!medium) {
return i18n("No such medium: %1").arg(_udi); TQStringVariantMap result;
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
}
return mount(medium); return mount(medium);
} }
TQString HALBackend::unmount(const TQString &_udi) TQStringVariantMap HALBackend::unmount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
const Medium* medium = m_mediaList.findById(id);
if (!medium) if (!medium)
{ // now we get fancy: if the udi is no volume, it _might_ be a device with only one {
// now we get fancy: if the udi is no volume, it _might_ be a device with only one
// volume on it (think CDs) - so we're so nice to the caller to unmount that volume // volume on it (think CDs) - so we're so nice to the caller to unmount that volume
LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, _udi.latin1()); LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, id.latin1());
if (halDrive) if (halDrive)
{ {
int numVolumes; int numVolumes;
char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes);
if (numVolumes == 1) if (numVolumes == 1)
medium = m_mediaList.findById( volumes[0] ); medium = m_mediaList.findById(volumes[0]);
} }
} }
if ( !medium ) if (!medium) {
return i18n("No such medium: %1").arg(_udi); result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
}
if (!medium->isMounted()) if (!medium->isMounted())
return TQString(); // that was easy result["result"] = true;
return result;
}
TQString mountPoint = isInFstab(medium); TQString mountPoint = isInFstab(medium);
if (!mountPoint.isNull()) if (!mountPoint.isNull())
@ -1628,16 +1646,22 @@ TQString HALBackend::unmount(const TQString &_udi)
kdDebug() << "triggering user unmount " << medium->deviceNode() << " " << mountPoint << endl; kdDebug() << "triggering user unmount " << medium->deviceNode() << " " << mountPoint << endl;
TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false ); TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false );
connect(job, TQT_SIGNAL( result (TDEIO::Job *)), connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
TQT_SLOT( slotResult( TDEIO::Job *)));
mount_jobs[job] = &data; mount_jobs[job] = &data;
// The caller expects the device to be unmounted when the function // The caller expects the device to be unmounted when the function
// completes. Thus block until the job completes. // completes. Thus block until the job completes.
while (!data.completed) { while (!data.completed) {
kapp->eventLoop()->enterLoop(); kapp->eventLoop()->enterLoop();
} }
// Return the error message (if any) to the caller if (!data.error) {
return (data.error) ? data.errorMessage : TQString::null; result["result"] = true;
return result;
}
else {
result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
result["result"] = false;
return result;
}
} }
DBusMessage *dmesg, *reply; DBusMessage *dmesg, *reply;
@ -1660,7 +1684,9 @@ TQString HALBackend::unmount(const TQString &_udi)
} }
if (udi.isNull()) { if (udi.isNull()) {
kdDebug() << "unmount failed: no udi" << endl; kdDebug() << "unmount failed: no udi" << endl;
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
kdDebug() << "unmounting " << udi << "..." << endl; kdDebug() << "unmounting " << udi << "..." << endl;
@ -1670,14 +1696,18 @@ TQString HALBackend::unmount(const TQString &_udi)
if (dbus_error_is_set(&error)) if (dbus_error_is_set(&error))
{ {
dbus_error_free(&error); dbus_error_free(&error);
return TQString(); result["errStr"] = i18n("Unknown error");
result["result"] = false;
return result;
} }
if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi.latin1(), if (!(dmesg = dbus_message_new_method_call ("org.freedesktop.Hal", udi.latin1(),
"org.freedesktop.Hal.Device.Volume", "org.freedesktop.Hal.Device.Volume",
"Unmount"))) { "Unmount"))) {
kdDebug() << "unmount failed for " << udi << ": could not create dbus message\n"; kdDebug() << "unmount failed for " << udi << ": could not create dbus message\n";
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
options[0] = "force"; options[0] = "force";
@ -1688,7 +1718,9 @@ TQString HALBackend::unmount(const TQString &_udi)
{ {
kdDebug() << "unmount failed for " << udi << ": could not append args to dbus message\n"; kdDebug() << "unmount failed for " << udi << ": could not append args to dbus message\n";
dbus_message_unref (dmesg); dbus_message_unref (dmesg);
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
char thisunmounthasfailed = 0; char thisunmounthasfailed = 0;
@ -1704,14 +1736,14 @@ TQString HALBackend::unmount(const TQString &_udi)
if (qerror.isEmpty()) { if (qerror.isEmpty()) {
dbus_message_unref(dmesg); dbus_message_unref(dmesg);
dbus_error_free(&error); dbus_error_free(&error);
return TQString(); result["result"] = true;
return result;
} }
// @todo handle unmount error message // @todo handle unmount error message
} }
kdDebug() << "unmount failed for " << udi << ": " << error.name << " " << error.message << endl; kdDebug() << "unmount failed for " << udi << ": " << error.name << " " << error.message << endl;
qerror = "<qt>";
qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and " qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and "
"currently mounted at <b>%4</b> could not be unmounted. ").arg( "currently mounted at <b>%4</b> could not be unmounted. ").arg(
"system:/media/" + medium->name(), "system:/media/" + medium->name(),
@ -1750,7 +1782,9 @@ TQString HALBackend::unmount(const TQString &_udi)
if (thisunmounthasfailed != 0) { if (thisunmounthasfailed != 0) {
dbus_message_unref (dmesg); dbus_message_unref (dmesg);
dbus_error_free (&error); dbus_error_free (&error);
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
} }
@ -1766,17 +1800,25 @@ TQString HALBackend::unmount(const TQString &_udi)
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
return TQString(); result["result"] = true;
return result;
} }
TQString HALBackend::decrypt(const TQString &_udi, const TQString &password) TQStringVariantMap HALBackend::decrypt(const TQString &id, const TQString &password)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
if (!medium)
return i18n("No such medium: %1").arg(_udi); 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()) if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull())
return TQString(); result["result"] = true;
return result;
}
const char *udi = medium->id().latin1(); const char *udi = medium->id().latin1();
DBusMessage *msg = NULL; DBusMessage *msg = NULL;
@ -1790,7 +1832,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
"Setup"); "Setup");
if (msg == NULL) { if (msg == NULL) {
kdDebug() << "decrypt failed for " << udi << ": could not create dbus message\n"; kdDebug() << "decrypt failed for " << udi << ": could not create dbus message\n";
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
TQCString pwdUtf8 = password.utf8(); TQCString pwdUtf8 = password.utf8();
@ -1798,7 +1842,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &pwd_utf8, DBUS_TYPE_INVALID)) { if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, &pwd_utf8, DBUS_TYPE_INVALID)) {
kdDebug() << "decrypt failed for " << udi << ": could not append args to dbus message\n"; kdDebug() << "decrypt failed for " << udi << ": could not append args to dbus message\n";
dbus_message_unref (msg); dbus_message_unref (msg);
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
dbus_error_init (&error); dbus_error_init (&error);
@ -1813,7 +1859,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
dbus_error_free (&error); dbus_error_free (&error);
dbus_message_unref (msg); dbus_message_unref (msg);
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
dbus_message_unref (msg); dbus_message_unref (msg);
@ -1821,17 +1869,25 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password)
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
return TQString(); result["result"] = true;
return result;
} }
TQString HALBackend::undecrypt(const TQString &_udi) TQStringVariantMap HALBackend::undecrypt(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
if (!medium)
return i18n("No such medium: %1").arg(_udi);
if (!medium->isEncrypted() || medium->clearDeviceUdi().isNull()) const Medium *medium = m_mediaList.findById(id);
return TQString(); 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;
return result;
}
const char *udi = medium->id().latin1(); const char *udi = medium->id().latin1();
DBusMessage *msg = NULL; DBusMessage *msg = NULL;
@ -1845,13 +1901,17 @@ TQString HALBackend::undecrypt(const TQString &_udi)
"Teardown"); "Teardown");
if (msg == NULL) { if (msg == NULL) {
kdDebug() << "teardown failed for " << udi << ": could not create dbus message\n"; kdDebug() << "teardown failed for " << udi << ": could not create dbus message\n";
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
if (!dbus_message_append_args (msg, DBUS_TYPE_INVALID)) { if (!dbus_message_append_args (msg, DBUS_TYPE_INVALID)) {
kdDebug() << "teardown failed for " << udi << ": could not append args to dbus message\n"; kdDebug() << "teardown failed for " << udi << ": could not append args to dbus message\n";
dbus_message_unref (msg); dbus_message_unref (msg);
return i18n("Internal Error"); result["errStr"] = i18n("Internal error");
result["result"] = false;
return result;
} }
dbus_error_init (&error); dbus_error_init (&error);
@ -1863,7 +1923,9 @@ TQString HALBackend::undecrypt(const TQString &_udi)
dbus_error_free (&error); dbus_error_free (&error);
dbus_message_unref (msg); dbus_message_unref (msg);
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
dbus_message_unref (msg); dbus_message_unref (msg);
@ -1873,7 +1935,8 @@ TQString HALBackend::undecrypt(const TQString &_udi)
while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ;
return TQString(); result["result"] = true;
return result;
} }
#include "halbackend.moc" #include "halbackend.moc"

@ -83,11 +83,11 @@ public:
bool setMountoptions(const TQString &id, const TQStringList &options); bool setMountoptions(const TQString &id, const TQStringList &options);
TQString mount(const TQString &id); TQStringVariantMap mount(const TQString &id);
TQString mount(const Medium *medium); TQStringVariantMap mount(const Medium *medium);
TQString unmount(const TQString &id); TQStringVariantMap unmount(const TQString &id);
TQString decrypt(const TQString &id, const TQString &password); TQStringVariantMap decrypt(const TQString &id, const TQString &password);
TQString undecrypt(const TQString &id); TQStringVariantMap undecrypt(const TQString &id);
private: private:
/** /**

@ -240,76 +240,119 @@ bool MediaManager::setMountoptions(const TQString &name, const TQStringList &opt
#endif // COMPILE_HALBACKEND #endif // COMPILE_HALBACKEND
} }
TQString MediaManager::mount(const TQString &name) TQStringVariantMap MediaManager::mount(const TQString &uid)
{ {
#ifdef COMPILE_HALBACKEND TQStringVariantMap result;
if (!m_halbackend) #ifdef COMPILE_TDEHARDWAREBACKEND
return i18n("Feature only available with HAL"); if (!m_tdebackend) {
return m_halbackend->mount(name); result["errStr"] = i18n("Feature only available with the TDE hardware backend");
#else // COMPILE_HALBACKEND result["result"] = false;
#ifdef COMPILE_TDEHARDWAREBACKEND return result;
if (!m_tdebackend) }
return i18n("Feature only available with the TDE hardware backend"); return m_tdebackend->mount(uid);
return m_tdebackend->mount(name); #elif defined COMPILE_HALBACKEND
#else // COMPILE_TDEHARDWAREBACKEND if (!m_halbackend) {
if ( !m_fstabbackend ) // lying :) result["errStr"] = i18n("Feature only available with HAL");
return i18n("Feature only available with HAL or TDE hardware backend"); result["result"] = false;
return m_fstabbackend->mount( name ); return result;
#endif // COMPILE_TDEHARDWAREBACKEND }
#endif // COMPILE_HALBACKEND return m_halbackend->mount(uid);
#else
if (!m_fstabbackend) {
result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
result["result"] = false;
return result;
}
return m_fstabbackend->mount(uid);
#endif
} }
TQString MediaManager::unmount(const TQString &name) TQStringVariantMap MediaManager::unmount(const TQString &uid)
{ {
#ifdef COMPILE_HALBACKEND TQStringVariantMap result;
if (!m_halbackend) #ifdef COMPILE_TDEHARDWAREBACKEND
return i18n("Feature only available with HAL"); if (!m_tdebackend) {
return m_halbackend->unmount(name); result["errStr"] = i18n("Feature only available with the TDE hardware backend");
#else // COMPILE_HALBACKEND result["result"] = false;
#ifdef COMPILE_TDEHARDWAREBACKEND return result;
if (!m_tdebackend) }
return i18n("Feature only available with HAL or TDE hardware backend"); return m_tdebackend->unmount(uid);
return m_tdebackend->unmount(name); #elif defined COMPILE_HALBACKEND
#else // COMPILE_TDEHARDWAREBACKEND if (!m_halbackend) {
if ( !m_fstabbackend ) // lying :) result["errStr"] = i18n("Feature only available with HAL");
return i18n("Feature only available with HAL or TDE hardware backend"); result["result"] = false;
return m_fstabbackend->unmount( name ); return result;
#endif // COMPILE_TDEHARDWAREBACKEND }
#endif // COMPILE_HALBACKEND return m_halbackend->unmount(uid);
#else
if (!m_fstabbackend) {
result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
result["result"] = false;
return result;
}
return m_fstabbackend->unmount(uid);
#endif
} }
TQString MediaManager::decrypt(const TQString &name, const TQString &password) TQStringVariantMap MediaManager::decrypt(const TQString &uid, const TQString &password)
{ {
#ifdef COMPILE_HALBACKEND TQStringVariantMap result;
if (!m_halbackend) /*
return i18n("Feature only available with HAL"); #ifdef COMPILE_TDEHARDWAREBACKEND
return m_halbackend->decrypt(name, password); if (!m_tdebackend) {
#else // COMPILE_HALBACKEND result["errStr"] = i18n("Feature only available with the TDE hardware backend");
// #ifdef COMPILE_TDEHARDWAREBACKEND result["result"] = false;
// if (!m_tdebackend) return result;
// return i18n("Feature only available with HAL or TDE hardware backend"); }
// return m_tdebackend->decrypt(name, password); return m_tdebackend->decrypt(uid, password);
// #else // COMPILE_TDEHARDWAREBACKEND #elif defined COMPILE_HALBACKEND
return i18n("Feature only available with HAL"); */
// #endif // COMPILE_TDEHARDWAREBACKEND #if defined COMPILE_HALBACKEND
#endif // COMPILE_HALBACKEND if (!m_halbackend) {
result["errStr"] = i18n("Feature only available with HAL");
result["result"] = false;
return result;
}
return m_halbackend->decrypt(uid, password);
#else
// if (!m_fstabbackend) {
result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
result["result"] = false;
return result;
// }
// return m_fstabbackend->decrypt(uid, password);
#endif
} }
TQString MediaManager::undecrypt(const TQString &name) TQStringVariantMap MediaManager::undecrypt(const TQString &uid)
{ {
#ifdef COMPILE_HALBACKEND TQStringVariantMap result;
if (!m_halbackend) /*
return i18n("Feature only available with HAL"); #ifdef COMPILE_TDEHARDWAREBACKEND
return m_halbackend->undecrypt(name); if (!m_tdebackend) {
#else // COMPILE_HALBACKEND result["errStr"] = i18n("Feature only available with the TDE hardware backend");
// #ifdef COMPILE_TDEHARDWAREBACKEND result["result"] = false;
// if (!m_tdebackend) return result;
// return i18n("Feature only available with HAL or TDE hardware backend"); }
// return m_tdebackend->undecrypt(name); return m_tdebackend->undecrypt(uid);
// #else // COMPILE_TDEHARDWAREBACKEND #elif defined COMPILE_HALBACKEND
return i18n("Feature only available with HAL"); */
// #endif // COMPILE_TDEHARDWAREBACKEND #if defined COMPILE_HALBACKEND
#endif // COMPILE_HALBACKEND if (!m_halbackend) {
result["errStr"] = i18n("Feature only available with HAL");
result["result"] = false;
return result;
}
return m_halbackend->undecrypt(uid);
#else
// if (!m_fstabbackend) {
result["errStr"] = i18n("Feature only available with HAL or TDE hardware backend");
result["result"] = false;
return result;
// }
// return m_fstabbackend->undecrypt(uid);
#endif
} }
TQString MediaManager::nameForLabel(const TQString &label) TQString MediaManager::nameForLabel(const TQString &label)

@ -22,6 +22,7 @@
#include <kdedmodule.h> #include <kdedmodule.h>
#include <tqstring.h> #include <tqstring.h>
#include <tqstringlist.h> #include <tqstringlist.h>
#include <tqvariant.h>
#include "medialist.h" #include "medialist.h"
#include "backendbase.h" #include "backendbase.h"
@ -46,10 +47,10 @@ k_dcop:
TQStringList mountoptions(const TQString &name); TQStringList mountoptions(const TQString &name);
bool setMountoptions(const TQString &name, const TQStringList &options); bool setMountoptions(const TQString &name, const TQStringList &options);
TQString mount(const TQString &uid); TQStringVariantMap mount(const TQString &uid);
TQString unmount(const TQString &uid); TQStringVariantMap unmount(const TQString &uid);
TQString decrypt(const TQString &uid, const TQString &password); TQStringVariantMap decrypt(const TQString &uid, const TQString &password);
TQString undecrypt(const TQString &uid); TQStringVariantMap undecrypt(const TQString &uid);
TQString nameForLabel(const TQString &label); TQString nameForLabel(const TQString &label);
ASYNC setUserLabel(const TQString &name, const TQString &label); ASYNC setUserLabel(const TQString &name, const TQString &label);

@ -50,15 +50,6 @@
(medium->isEncrypted() ? (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt) ? "-decrypted" : "-encrypted") : "" ) \ (medium->isEncrypted() ? (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt) ? "-decrypted" : "-encrypted") : "" ) \
) )
#define CHECK_FOR_AND_EXECUTE_AUTOMOUNT(udi, medium, allowNotification) { \
TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(udi)); \
kdDebug(1219) << "automount " << options["automount"] << endl; \
if (options["automount"] == "true" && allowNotification ) { \
TQString error = mount(medium); \
if (!error.isEmpty()) \
kdDebug(1219) << "error " << error << endl; \
} \
}
/* Constructor */ /* Constructor */
TDEBackend::TDEBackend(MediaList &list, TQObject* parent) TDEBackend::TDEBackend(MediaList &list, TQObject* parent)
@ -208,7 +199,15 @@ void TDEBackend::AddDevice(TDEStorageDevice * sdevice, bool allowNotification)
kdDebug(1219) << "TDEBackend::AddDevice inserted hard medium for " << sdevice->uniqueID() << endl; kdDebug(1219) << "TDEBackend::AddDevice inserted hard medium for " << sdevice->uniqueID() << endl;
// Automount if enabled // Automount if enabled
CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification) TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(sdevice->uniqueID()));
kdDebug(1219) << "automount " << options["automount"] << endl;
if (options["automount"] == "true" && allowNotification ) {
TQStringVariantMap mountResult = mount(medium);
if (!mountResult["result"].toBool()) {
TQString error = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
kdDebug(1219) << "error " << error << endl;
}
}
} }
} }
@ -251,7 +250,15 @@ void TDEBackend::AddDevice(TDEStorageDevice * sdevice, bool allowNotification)
kdDebug(1219) << "TDEBackend::AddDevice inserted optical medium for " << sdevice->uniqueID() << endl; kdDebug(1219) << "TDEBackend::AddDevice inserted optical medium for " << sdevice->uniqueID() << endl;
// Automount if enabled // Automount if enabled
CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification) TQMap<TQString,TQString> options = MediaManagerUtils::splitOptions(mountoptions(sdevice->uniqueID()));
kdDebug(1219) << "automount " << options["automount"] << endl;
if (options["automount"] == "true" && allowNotification ) {
TQStringVariantMap mountResult = mount(medium);
if (!mountResult["result"].toBool()) {
TQString error = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
kdDebug(1219) << "error " << error << endl;
}
}
} }
// Floppy & zip drives // Floppy & zip drives
@ -1179,49 +1186,55 @@ void TDEBackend::slotPasswordCancel() {
m_decryptPasswordValid = true; m_decryptPasswordValid = true;
} }
TQString TDEBackend::mount(const Medium *medium) TQStringVariantMap TDEBackend::mount(const Medium *medium)
{ {
TQStringVariantMap result;
if (medium->isMounted()) { if (medium->isMounted()) {
return TQString(); // that was easy result["result"] = true;
return result;
} }
TQString mountPoint = isInFstab(medium); TQString mountPoint = isInFstab(medium);
if (!mountPoint.isNull()) if (!mountPoint.isEmpty())
{ {
struct mount_job_data data; struct mount_job_data data;
data.completed = false; data.completed = false;
data.medium = medium; data.medium = medium;
TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint ); TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), mountPoint);
connect(job, TQT_SIGNAL( result (TDEIO::Job *)), TQT_SLOT( slotResult( TDEIO::Job *))); connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
mount_jobs[job] = &data; mount_jobs[job] = &data;
// The caller expects the device to be mounted when the function // The caller expects the device to be mounted when the function
// completes. Thus block until the job completes. // completes. Thus block until the job completes.
while (!data.completed) { while (!data.completed) {
kapp->eventLoop()->enterLoop(); kapp->eventLoop()->enterLoop();
} }
// Return the error message (if any) to the caller if (!data.error) {
return (data.error) ? data.errorMessage : TQString::null; result["result"] = true;
return result;
}
else {
result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
result["result"] = false;
return result;
}
} }
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id());
if (!sdevice) { if (!sdevice) {
return i18n("Internal error"); result["errStr"] = i18n("Internal error. Couldn't find medium.");
result["result"] = false;
return result;
} }
TQString diskLabel;
TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id())); TQMap<TQString,TQString> valids = MediaManagerUtils::splitOptions(mountoptions(medium->id()));
TQString diskLabel;
TQString mount_point = valids["mountpoint"]; TQString mount_point = valids["mountpoint"];
if (mount_point.startsWith("/media/")) { if (mount_point.startsWith("/media/")) {
diskLabel = mount_point.mid(7); diskLabel = mount_point.mid(7);
} }
if (diskLabel.isEmpty()) {
if (diskLabel == "") {
// Try to use a pretty mount point if possible // Try to use a pretty mount point if possible
TQStringList pieces = TQStringList::split("/", sdevice->deviceNode(), FALSE); TQStringList pieces = TQStringList::split("/", sdevice->deviceNode(), FALSE);
TQString node = pieces[pieces.count()-1]; TQString node = pieces[pieces.count()-1];
@ -1229,22 +1242,17 @@ TQString TDEBackend::mount(const Medium *medium)
diskLabel.replace("/", "_"); diskLabel.replace("/", "_");
} }
TQString qerror = i18n("Cannot mount encrypted drives!"); TQString qerror;
if (!medium->isEncrypted()) { if (!medium->isEncrypted()) {
// normal volume // normal volume
TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids); TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids);
TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null; TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
if (mountedPath.isEmpty()) { if (mountedPath.isEmpty()) {
qerror = i18n("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device"); qerror = i18n("Unable to mount this device.");
TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
} }
qerror.append("</qt>");
}
else {
qerror = "";
} }
} }
else { else {
@ -1275,7 +1283,9 @@ TQString TDEBackend::mount(const Medium *medium)
if (m_decryptionPassword.isNull()) { if (m_decryptionPassword.isNull()) {
delete m_decryptDialog; delete m_decryptDialog;
return TQString("Decryption aborted"); result["errStr"] = i18n("Decryption aborted");
result["result"] = false;
return result;
} }
else { else {
// Just for some added fun, if udev emits a medium change event, which I then forward, with mounted==0, it stops the MediaProtocol::listDir method dead in its tracks, // Just for some added fun, if udev emits a medium change event, which I then forward, with mounted==0, it stops the MediaProtocol::listDir method dead in its tracks,
@ -1311,17 +1321,16 @@ TQString TDEBackend::mount(const Medium *medium)
continue_trying_to_decrypt = true; continue_trying_to_decrypt = true;
} }
else { else {
qerror = i18n("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device<br>Incorrect encryption password"); qerror = i18n("Cannot mount encrypted drives!");
qerror = i18n("Unable to mount this device.");
TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
} }
qerror.append("</qt>");
continue_trying_to_decrypt = false; continue_trying_to_decrypt = false;
} }
} }
else { else {
qerror = "";
continue_trying_to_decrypt = false; continue_trying_to_decrypt = false;
} }
@ -1331,7 +1340,9 @@ TQString TDEBackend::mount(const Medium *medium)
} }
if (!qerror.isEmpty()) { if (!qerror.isEmpty()) {
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
ResetProperties(sdevice, false, true); ResetProperties(sdevice, false, true);
@ -1340,29 +1351,36 @@ TQString TDEBackend::mount(const Medium *medium)
m_ignoreDeviceChangeEvents.remove(sdevice->uniqueID()); m_ignoreDeviceChangeEvents.remove(sdevice->uniqueID());
} }
return TQString(); result["result"] = true;
return result;
} }
TQString TDEBackend::mount(const TQString &_udi) TQStringVariantMap TDEBackend::mount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); const Medium *medium = m_mediaList.findById(id);
if (!medium) { if (!medium) {
return i18n("No such medium: %1").arg(_udi); TQStringVariantMap result;
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
} }
return mount(medium); return mount(medium);
} }
TQString TDEBackend::unmount(const TQString &_udi) TQStringVariantMap TDEBackend::unmount(const TQString &id)
{ {
const Medium* medium = m_mediaList.findById(_udi); TQStringVariantMap result;
if ( !medium ) { const Medium* medium = m_mediaList.findById(id);
return i18n("No such medium: %1").arg(_udi); if (!medium) {
result["errStr"] = i18n("No such medium: %1").arg(id);
result["result"] = false;
return result;
} }
if (!medium->isMounted()) { if (!medium->isMounted()) {
return TQString(); // that was easy result["result"] = true;
return result;
} }
TQString mountPoint = isInFstab(medium); TQString mountPoint = isInFstab(medium);
@ -1373,83 +1391,90 @@ TQString TDEBackend::unmount(const TQString &_udi)
data.medium = medium; data.medium = medium;
TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false ); TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false );
connect(job, TQT_SIGNAL( result (TDEIO::Job *)), TQT_SLOT( slotResult( TDEIO::Job *))); connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
mount_jobs[job] = &data; mount_jobs[job] = &data;
// The caller expects the device to be unmounted when the function // The caller expects the device to be unmounted when the function
// completes. Thus block until the job completes. // completes. Thus block until the job completes.
while (!data.completed) { while (!data.completed) {
kapp->eventLoop()->enterLoop(); kapp->eventLoop()->enterLoop();
} }
// Return the error message (if any) to the caller if (!data.error) {
return (data.error) ? data.errorMessage : TQString::null; result["result"] = true;
return result;
}
else {
result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller
result["result"] = false;
return result;
}
} }
TQString udi = TQString::null;
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id());
if (!sdevice) { if (!sdevice) {
return i18n("Internal error"); result["errStr"] = i18n("Internal error. Couldn't find medium.");
result["result"] = false;
return result;
} }
TQString qerror;
TQString origqerror;
// Save these for later // Save these for later
TQString uid = sdevice->uniqueID(); TQString uid = sdevice->uniqueID();
TQString node = sdevice->deviceNode(); TQString node = sdevice->deviceNode();
TQString qerror;
TQStringVariantMap unmountResult = sdevice->unmountDevice(); TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false) {
// Unmount failed! // Unmount failed!
qerror = "<qt>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
"<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
} }
qerror.append("</qt>");
}
else {
qerror = "";
} }
if (unmountResult.contains("retCode") && unmountResult["retCode"].toInt() == 1280) { if (unmountResult.contains("retCode") && unmountResult["retCode"].toInt() == 1280) {
// Failed as BUSY // Failed as BUSY
TQString processesUsingDev = listUsingProcesses(medium); TQString processesUsingDev = listUsingProcesses(medium);
if (!processesUsingDev.isNull()) { if (!processesUsingDev.isNull()) {
if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()).arg(processesUsingDev)) == KMessageBox::Yes) { if (KMessageBox::warningYesNo(0, i18n("<qt>The device <b>%1</b> (%2) named <b>'%3'</b> and currently "
"mounted at <b>%4</b> can not be unmounted at this time.<p>%5<p><b>Would you like to forcibly "
"terminate these processes?</b><br><i>All unsaved data would be lost</i>").arg("system:/media/" +
medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL())
.arg(processesUsingDev)) == KMessageBox::Yes) {
killUsingProcesses(medium); killUsingProcesses(medium);
unmountResult = sdevice->unmountDevice(); unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false) {
// Unmount failed! // Unmount failed!
qerror = "<qt>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at <b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
"<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
} }
qerror.append("</qt>");
}
else {
qerror = "";
} }
} }
} }
} }
if (qerror != "") { if (!qerror.isEmpty()) {
return qerror; result["errStr"] = qerror;
result["result"] = false;
return result;
} }
// There is a possibility that the storage device was unceremoniously removed from the system immediately after it was unmounted // There is a possibility that the storage device was unceremoniously removed from the system immediately
// There is no reliable way to know if this happened either! // after it was unmounted. There is no reliable way to know if this happened either!
// For now, see if the device node still exists // For now, see if the device node still exists
TQFileInfo checkDN(node); TQFileInfo checkDN(node);
if (!checkDN.exists()) { if (!checkDN.exists()) {
m_mediaList.removeMedium(uid, true); m_mediaList.removeMedium(uid, true);
} }
return TQString(); result["result"] = true;
return result;
} }
void TDEBackend::slotResult(TDEIO::Job *job) void TDEBackend::slotResult(TDEIO::Job *job)

@ -68,11 +68,11 @@ public:
bool setMountoptions(const TQString &id, const TQStringList &options); bool setMountoptions(const TQString &id, const TQStringList &options);
TQString mount(const TQString &id); TQStringVariantMap mount(const TQString &id);
TQString mount(const Medium *medium); TQStringVariantMap mount(const Medium *medium);
TQString unmount(const TQString &id); TQStringVariantMap unmount(const TQString &id);
// TQString decrypt(const TQString &id, const TQString &password); // TQStringVariantMap decrypt(const TQString &id, const TQString &password);
// TQString undecrypt(const TQString &id); // TQStringVariantMap undecrypt(const TQString &id);
private: private:
/** /**

@ -73,15 +73,16 @@ MountHelper::MountHelper() : TDEApplication()
KURL url(args->url(0)); KURL url(args->url(0));
const Medium medium = findMedium(url); const Medium medium = findMedium(url);
if ( medium.id().isEmpty() ) if (medium.id().isEmpty())
{ {
if (m_errorStr.isEmpty()) if (m_errorStr.isEmpty()) {
m_errorStr+= i18n("%1 cannot be found.").arg(url.prettyURL()); m_errorStr+= i18n("%1 cannot be found.").arg(url.prettyURL());
}
TQTimer::singleShot(0, this, TQT_SLOT(error()) ); TQTimer::singleShot(0, this, TQT_SLOT(error()) );
return; return;
} }
if ( !medium.isMountable() && !args->isSet("e") && !args->isSet("s")) if (!medium.isMountable() && !args->isSet("e") && !args->isSet("s"))
{ {
m_errorStr = i18n("%1 is not a mountable media.").arg(url.prettyURL()); m_errorStr = i18n("%1 is not a mountable media.").arg(url.prettyURL());
TQTimer::singleShot(0, this, TQT_SLOT(error()) ); TQTimer::singleShot(0, this, TQT_SLOT(error()) );
@ -91,8 +92,7 @@ MountHelper::MountHelper() : TDEApplication()
TQString device = medium.deviceNode(); TQString device = medium.deviceNode();
TQString mount_point = medium.mountPoint(); TQString mount_point = medium.mountPoint();
m_isCdrom = medium.mimeType().find("dvd")!=-1 m_isCdrom = medium.mimeType().find("dvd") != -1 || medium.mimeType().find("cd") != -1;
|| medium.mimeType().find("cd")!=-1;
if (args->isSet("d")) if (args->isSet("d"))
{ {
@ -127,15 +127,20 @@ MountHelper::MountHelper() : TDEApplication()
else if (args->isSet("u")) else if (args->isSet("u"))
{ {
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call( "unmount", medium.id()); DCOPReply reply = mediamanager.call("unmount", medium.id());
if (reply.isValid()) TQStringVariantMap unmountResult;
reply.get(m_errorStr); if (reply.isValid()) {
kdDebug() << "medium unmount " << m_errorStr << endl; reply.get(unmountResult);
if (m_errorStr.isNull()) }
if (unmountResult.contains("result") && unmountResult["result"].toBool()) {
::exit(0); ::exit(0);
else }
else {
m_errorStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unknown unmount error.");
kdDebug() << "medium unmount " << m_errorStr << endl;
error(); error();
} }
}
else if (args->isSet("s") || args->isSet("e")) else if (args->isSet("s") || args->isSet("e"))
{ {
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
@ -153,9 +158,13 @@ MountHelper::MountHelper() : TDEApplication()
{ {
DCOPReply reply = mediamanager.call( "unmount", medium.id()); DCOPReply reply = mediamanager.call( "unmount", medium.id());
if (reply.isValid()) { if (reply.isValid()) {
TQStringVariantMap unmountResult;
reply.get(unmountResult);
if (unmountResult["result"].toBool()) {
reply.get(m_errorStr); reply.get(m_errorStr);
} }
} }
}
/* If this is a decrypted volume and there is no error yet /* If this is a decrypted volume and there is no error yet
* we try to teardown the decryption */ * we try to teardown the decryption */
@ -163,9 +172,13 @@ MountHelper::MountHelper() : TDEApplication()
{ {
DCOPReply reply = mediamanager.call( "undecrypt", medium.id()); DCOPReply reply = mediamanager.call( "undecrypt", medium.id());
if (reply.isValid()) { if (reply.isValid()) {
TQStringVariantMap undecryptResult;
reply.get(undecryptResult);
if (undecryptResult["result"].toBool()) {
reply.get(m_errorStr); reply.get(m_errorStr);
} }
} }
}
if (m_errorStr.isNull()) { if (m_errorStr.isNull()) {
invokeEject(device, true); invokeEject(device, true);
@ -177,14 +190,19 @@ MountHelper::MountHelper() : TDEApplication()
else else
{ {
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call( "mount", medium.id()); DCOPReply reply = mediamanager.call("mount", medium.id());
if (reply.isValid()) TQStringVariantMap mountResult;
reply.get(m_errorStr); if (reply.isValid()) {
if (m_errorStr.isNull()) reply.get(mountResult);
}
if (mountResult.contains("result") && mountResult["result"].toBool()) {
::exit(0); ::exit(0);
else }
else {
m_errorStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unknown mount error.");
error(); error();
} }
}
} }
void MountHelper::invokeEject(const TQString &device, bool quiet) void MountHelper::invokeEject(const TQString &device, bool quiet)
@ -252,16 +270,18 @@ void MountHelper::slotSendPassword()
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call( "decrypt", m_mediumId, dialog->getPassword() ); DCOPReply reply = mediamanager.call( "decrypt", m_mediumId, dialog->getPassword() );
if (!reply.isValid()) { TQStringVariantMap decryptResult;
m_errorStr = i18n("The TDE mediamanager is not running."); if (reply.isValid()) {
error(); reply.get(decryptResult);
} else {
TQString errorMsg = reply;
if (errorMsg.isNull()) {
exit(0);
} else {
emit signalPasswordError(errorMsg);
} }
if (decryptResult.contains("result") && decryptResult["result"].toBool()) {
::exit(0);
}
else {
m_errorStr = decryptResult.contains("errStr") ? decryptResult["errStr"].toString() : i18n("Unknown decrypt error.");
kdDebug() << "medium decrypt " << m_errorStr << endl;
emit signalPasswordError(m_errorStr);
error();
} }
} }

Loading…
Cancel
Save