From e44487e1b855106ddf00ade92a25493e11589ca1 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 1 Jun 2019 21:55:11 +0900 Subject: Improved media manager dcop interface for mount/unmount/decrypt/undecrypt methods by returning more information. Signed-off-by: Michele Calgaro --- tdeioslave/media/mediamanager/fstabbackend.cpp | 38 +++-- tdeioslave/media/mediamanager/fstabbackend.h | 8 +- tdeioslave/media/mediamanager/halbackend.cpp | 189 ++++++++++++++------- tdeioslave/media/mediamanager/halbackend.h | 10 +- tdeioslave/media/mediamanager/mediamanager.cpp | 163 +++++++++++------- tdeioslave/media/mediamanager/mediamanager.h | 9 +- .../media/mediamanager/tdehardwarebackend.cpp | 177 ++++++++++--------- tdeioslave/media/mediamanager/tdehardwarebackend.h | 10 +- 8 files changed, 373 insertions(+), 231 deletions(-) (limited to 'tdeioslave/media/mediamanager') diff --git a/tdeioslave/media/mediamanager/fstabbackend.cpp b/tdeioslave/media/mediamanager/fstabbackend.cpp index 84910352d..c0e91c228 100644 --- a/tdeioslave/media/mediamanager/fstabbackend.cpp +++ b/tdeioslave/media/mediamanager/fstabbackend.cpp @@ -97,24 +97,34 @@ FstabBackend::~FstabBackend() KDirWatch::self()->removeFile(MTAB); } -TQString FstabBackend::mount( const TQString &_udi ) +TQStringVariantMap FstabBackend::mount(const TQString &id) { - const Medium* medium = m_mediaList.findById(_udi); - if (!medium) - return i18n("No such medium: %1").arg(_udi); - TDEIO::Job* job = TDEIO::mount( false, 0, medium->deviceNode(), medium->mountPoint()); - TDEIO::NetAccess::synchronousRun( job, 0 ); - return TQString::null; + 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; + } + 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); - if (!medium) - return i18n("No such medium: %1").arg(_udi); - TDEIO::Job* job = TDEIO::unmount( medium->mountPoint(), false); - TDEIO::NetAccess::synchronousRun( job, 0 ); - return TQString::null; + 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; + } + TDEIO::Job *job = TDEIO::unmount(medium->mountPoint(), false); + TDEIO::NetAccess::synchronousRun(job, 0); + result["result"] = true; + return result; } void FstabBackend::slotDirty(const TQString &path) diff --git a/tdeioslave/media/mediamanager/fstabbackend.h b/tdeioslave/media/mediamanager/fstabbackend.h index e43ed48c0..24529d95a 100644 --- a/tdeioslave/media/mediamanager/fstabbackend.h +++ b/tdeioslave/media/mediamanager/fstabbackend.h @@ -1,5 +1,5 @@ /* This file is part of the KDE Project - Copyright (c) 2004 Kévin Ottens + Copyright (c) 2004 Kévin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -23,7 +23,7 @@ #include #include -#include +#include #ifdef Q_OS_FREEBSD #include @@ -42,8 +42,8 @@ public: TQString &mimeType, TQString &iconName, TQString &label); - TQString mount(const TQString &id); - TQString unmount(const TQString &id); + TQStringVariantMap mount(const TQString &id); + TQStringVariantMap unmount(const TQString &id); private slots: void slotDirty(const TQString &path); diff --git a/tdeioslave/media/mediamanager/halbackend.cpp b/tdeioslave/media/mediamanager/halbackend.cpp index 637b16bf0..071752d5a 100644 --- a/tdeioslave/media/mediamanager/halbackend.cpp +++ b/tdeioslave/media/mediamanager/halbackend.cpp @@ -1449,10 +1449,13 @@ TQString HALBackend::isInFstab(const Medium *medium) return TQString::null; } -TQString HALBackend::mount(const Medium *medium) +TQStringVariantMap HALBackend::mount(const Medium *medium) { - if (medium->isMounted()) - return TQString(); // that was easy + TQStringVariantMap result; + if (medium->isMounted()) { + result["result"] = true; + return result; + } TQString mountPoint = isInFstab(medium); if (!mountPoint.isNull()) @@ -1463,24 +1466,27 @@ TQString HALBackend::mount(const Medium *medium) kdDebug() << "triggering user mount " << medium->deviceNode() << " " << mountPoint << " " << medium->id() << endl; 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; // The caller expects the device to be mounted when the function // completes. Thus block until the job completes. while (!data.completed) { kapp->eventLoop()->enterLoop(); } - // Return the error message (if any) to the caller - return (data.error) ? data.errorMessage : TQString::null; - - } else if (medium->id().startsWith("/org/kde/") ) - return i18n("Permission denied"); - - TQStringList soptions; + if (!data.error) { + result["result"] = true; + return result; + } + else { + result["errStr"] = data.errorMessage; // Return the error message (if any) to the caller + result["result"] = false; + return result; + } + } kdDebug() << "mounting " << medium->id() << "..." << endl; + TQStringList soptions; TQMap valids = MediaManagerUtils::splitOptions(mountoptions(medium->id())); if (valids["flush"] == "true") soptions << "flush"; @@ -1508,7 +1514,6 @@ TQString HALBackend::mount(const Medium *medium) if (medium->fsType() == "ntfs") { TQString fsLocale("locale="); fsLocale += setlocale(LC_ALL, ""); - soptions << fsLocale; } @@ -1549,7 +1554,6 @@ TQString HALBackend::mount(const Medium *medium) } } - const char **options = new const char*[soptions.size() + 1]; uint noptions = 0; for (TQStringList::ConstIterator it = soptions.begin(); it != soptions.end(); ++it, ++noptions) @@ -1559,13 +1563,13 @@ TQString HALBackend::mount(const Medium *medium) } options[noptions] = NULL; - TQString qerror = i18n("Cannot mount encrypted drives!"); - + TQString qerror; if (!medium->isEncrypted()) { // normal volume qerror = mount_priv(medium->id().latin1(), mount_point.utf8(), options, noptions, dbus_connection); } else { // see if we have a clear volume + error = i18n("Cannot mount encrypted drives!"); LibHalVolume* halVolume = libhal_volume_from_udi(m_halContext, medium->id().latin1()); if (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()) { kdError() << "mounting " << medium->id() << " returned " << qerror << endl; - return qerror; + result["errStr"] = qerror; + result["result"] = false; + return result; } medium->setHalMounted(true); 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); - if (!medium) - return i18n("No such medium: %1").arg(_udi); - - return mount(medium); + const Medium *medium = m_mediaList.findById(id); + if (!medium) { + TQStringVariantMap result; + result["errStr"] = i18n("No such medium: %1").arg(id); + result["result"] = false; + return result; + } + 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) - { // 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 - LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, _udi.latin1()); + LibHalDrive* halDrive = libhal_drive_from_udi(m_halContext, id.latin1()); if (halDrive) { int numVolumes; char** volumes = libhal_drive_find_all_volumes(m_halContext, halDrive, &numVolumes); if (numVolumes == 1) - medium = m_mediaList.findById( volumes[0] ); + medium = m_mediaList.findById(volumes[0]); } } - if ( !medium ) - 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()) - return TQString(); // that was easy + result["result"] = true; + return result; + } TQString mountPoint = isInFstab(medium); if (!mountPoint.isNull()) @@ -1628,16 +1646,22 @@ TQString HALBackend::unmount(const TQString &_udi) kdDebug() << "triggering user unmount " << medium->deviceNode() << " " << mountPoint << endl; 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; // The caller expects the device to be unmounted when the function // completes. Thus block until the job completes. while (!data.completed) { kapp->eventLoop()->enterLoop(); } - // Return the error message (if any) to the caller - return (data.error) ? data.errorMessage : TQString::null; + if (!data.error) { + 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; @@ -1660,7 +1684,9 @@ TQString HALBackend::unmount(const TQString &_udi) } if (udi.isNull()) { kdDebug() << "unmount failed: no udi" << endl; - return i18n("Internal Error"); + result["errStr"] = i18n("Internal error"); + result["result"] = false; + return result; } kdDebug() << "unmounting " << udi << "..." << endl; @@ -1670,14 +1696,18 @@ TQString HALBackend::unmount(const TQString &_udi) if (dbus_error_is_set(&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(), "org.freedesktop.Hal.Device.Volume", "Unmount"))) { 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"; @@ -1688,7 +1718,9 @@ TQString HALBackend::unmount(const TQString &_udi) { kdDebug() << "unmount failed for " << udi << ": could not append args to dbus message\n"; dbus_message_unref (dmesg); - return i18n("Internal Error"); + result["errStr"] = i18n("Internal error"); + result["result"] = false; + return result; } char thisunmounthasfailed = 0; @@ -1704,14 +1736,14 @@ TQString HALBackend::unmount(const TQString &_udi) if (qerror.isEmpty()) { dbus_message_unref(dmesg); dbus_error_free(&error); - return TQString(); + result["result"] = true; + return result; } // @todo handle unmount error message } kdDebug() << "unmount failed for " << udi << ": " << error.name << " " << error.message << endl; - qerror = ""; qerror += "

" + i18n("Unfortunately, the device %1 (%2) named '%3' and " "currently mounted at %4 could not be unmounted. ").arg( "system:/media/" + medium->name(), @@ -1750,7 +1782,9 @@ TQString HALBackend::unmount(const TQString &_udi) if (thisunmounthasfailed != 0) { dbus_message_unref (dmesg); 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) ; - 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); - if (!medium) - return i18n("No such medium: %1").arg(_udi); + 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; + } if (!medium->isEncrypted() || !medium->clearDeviceUdi().isNull()) - return TQString(); + result["result"] = true; + return result; + } const char *udi = medium->id().latin1(); DBusMessage *msg = NULL; @@ -1790,7 +1832,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password) "Setup"); if (msg == NULL) { 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(); @@ -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)) { kdDebug() << "decrypt failed for " << udi << ": could not append args to dbus message\n"; dbus_message_unref (msg); - return i18n("Internal Error"); + result["errStr"] = i18n("Internal error"); + result["result"] = false; + return result; } dbus_error_init (&error); @@ -1813,7 +1859,9 @@ TQString HALBackend::decrypt(const TQString &_udi, const TQString &password) dbus_error_free (&error); dbus_message_unref (msg); while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; - return qerror; + result["errStr"] = qerror; + result["result"] = false; + return result; } 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) ; - 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); - if (!medium) - return i18n("No such medium: %1").arg(_udi); + TQStringVariantMap result; - if (!medium->isEncrypted() || medium->clearDeviceUdi().isNull()) - return TQString(); + 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; + return result; + } const char *udi = medium->id().latin1(); DBusMessage *msg = NULL; @@ -1845,13 +1901,17 @@ TQString HALBackend::undecrypt(const TQString &_udi) "Teardown"); if (msg == NULL) { 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)) { kdDebug() << "teardown failed for " << udi << ": could not append args to dbus message\n"; dbus_message_unref (msg); - return i18n("Internal Error"); + result["errStr"] = i18n("Internal error"); + result["result"] = false; + return result; } dbus_error_init (&error); @@ -1863,7 +1923,9 @@ TQString HALBackend::undecrypt(const TQString &_udi) dbus_error_free (&error); dbus_message_unref (msg); while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; - return qerror; + result["errStr"] = qerror; + result["result"] = false; + return result; } dbus_message_unref (msg); @@ -1873,7 +1935,8 @@ TQString HALBackend::undecrypt(const TQString &_udi) while (dbus_connection_dispatch(dbus_connection) == DBUS_DISPATCH_DATA_REMAINS) ; - return TQString(); + result["result"] = true; + return result; } #include "halbackend.moc" diff --git a/tdeioslave/media/mediamanager/halbackend.h b/tdeioslave/media/mediamanager/halbackend.h index 8dde45580..e799ad6e0 100644 --- a/tdeioslave/media/mediamanager/halbackend.h +++ b/tdeioslave/media/mediamanager/halbackend.h @@ -83,11 +83,11 @@ public: bool setMountoptions(const TQString &id, const TQStringList &options); - TQString mount(const TQString &id); - TQString mount(const Medium *medium); - TQString unmount(const TQString &id); - TQString decrypt(const TQString &id, const TQString &password); - TQString undecrypt(const TQString &id); + TQStringVariantMap mount(const TQString &id); + TQStringVariantMap mount(const Medium *medium); + TQStringVariantMap unmount(const TQString &id); + TQStringVariantMap decrypt(const TQString &id, const TQString &password); + TQStringVariantMap undecrypt(const TQString &id); private: /** diff --git a/tdeioslave/media/mediamanager/mediamanager.cpp b/tdeioslave/media/mediamanager/mediamanager.cpp index b08c37794..ef6721999 100644 --- a/tdeioslave/media/mediamanager/mediamanager.cpp +++ b/tdeioslave/media/mediamanager/mediamanager.cpp @@ -240,76 +240,119 @@ bool MediaManager::setMountoptions(const TQString &name, const TQStringList &opt #endif // COMPILE_HALBACKEND } -TQString MediaManager::mount(const TQString &name) +TQStringVariantMap MediaManager::mount(const TQString &uid) { -#ifdef COMPILE_HALBACKEND - if (!m_halbackend) - return i18n("Feature only available with HAL"); - return m_halbackend->mount(name); -#else // COMPILE_HALBACKEND - #ifdef COMPILE_TDEHARDWAREBACKEND - if (!m_tdebackend) - return i18n("Feature only available with the TDE hardware backend"); - return m_tdebackend->mount(name); - #else // COMPILE_TDEHARDWAREBACKEND - if ( !m_fstabbackend ) // lying :) - return i18n("Feature only available with HAL or TDE hardware backend"); - return m_fstabbackend->mount( name ); - #endif // COMPILE_TDEHARDWAREBACKEND -#endif // COMPILE_HALBACKEND + TQStringVariantMap result; +#ifdef COMPILE_TDEHARDWAREBACKEND + if (!m_tdebackend) { + result["errStr"] = i18n("Feature only available with the TDE hardware backend"); + result["result"] = false; + return result; + } + return m_tdebackend->mount(uid); +#elif defined COMPILE_HALBACKEND + if (!m_halbackend) { + result["errStr"] = i18n("Feature only available with HAL"); + result["result"] = false; + return result; + } + 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 - if (!m_halbackend) - return i18n("Feature only available with HAL"); - return m_halbackend->unmount(name); -#else // COMPILE_HALBACKEND - #ifdef COMPILE_TDEHARDWAREBACKEND - if (!m_tdebackend) - return i18n("Feature only available with HAL or TDE hardware backend"); - return m_tdebackend->unmount(name); - #else // COMPILE_TDEHARDWAREBACKEND - if ( !m_fstabbackend ) // lying :) - return i18n("Feature only available with HAL or TDE hardware backend"); - return m_fstabbackend->unmount( name ); - #endif // COMPILE_TDEHARDWAREBACKEND -#endif // COMPILE_HALBACKEND + TQStringVariantMap result; +#ifdef COMPILE_TDEHARDWAREBACKEND + if (!m_tdebackend) { + result["errStr"] = i18n("Feature only available with the TDE hardware backend"); + result["result"] = false; + return result; + } + return m_tdebackend->unmount(uid); +#elif defined COMPILE_HALBACKEND + if (!m_halbackend) { + result["errStr"] = i18n("Feature only available with HAL"); + result["result"] = false; + return result; + } + 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 - if (!m_halbackend) - return i18n("Feature only available with HAL"); - return m_halbackend->decrypt(name, password); -#else // COMPILE_HALBACKEND -// #ifdef COMPILE_TDEHARDWAREBACKEND -// if (!m_tdebackend) -// return i18n("Feature only available with HAL or TDE hardware backend"); -// return m_tdebackend->decrypt(name, password); -// #else // COMPILE_TDEHARDWAREBACKEND - return i18n("Feature only available with HAL"); -// #endif // COMPILE_TDEHARDWAREBACKEND -#endif // COMPILE_HALBACKEND + TQStringVariantMap result; +/* +#ifdef COMPILE_TDEHARDWAREBACKEND + if (!m_tdebackend) { + result["errStr"] = i18n("Feature only available with the TDE hardware backend"); + result["result"] = false; + return result; + } + return m_tdebackend->decrypt(uid, password); +#elif defined COMPILE_HALBACKEND +*/ +#if defined 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 - if (!m_halbackend) - return i18n("Feature only available with HAL"); - return m_halbackend->undecrypt(name); -#else // COMPILE_HALBACKEND -// #ifdef COMPILE_TDEHARDWAREBACKEND -// if (!m_tdebackend) -// return i18n("Feature only available with HAL or TDE hardware backend"); -// return m_tdebackend->undecrypt(name); -// #else // COMPILE_TDEHARDWAREBACKEND - return i18n("Feature only available with HAL"); -// #endif // COMPILE_TDEHARDWAREBACKEND -#endif // COMPILE_HALBACKEND + TQStringVariantMap result; +/* +#ifdef COMPILE_TDEHARDWAREBACKEND + if (!m_tdebackend) { + result["errStr"] = i18n("Feature only available with the TDE hardware backend"); + result["result"] = false; + return result; + } + return m_tdebackend->undecrypt(uid); +#elif defined COMPILE_HALBACKEND +*/ +#if defined 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) diff --git a/tdeioslave/media/mediamanager/mediamanager.h b/tdeioslave/media/mediamanager/mediamanager.h index 256d11bf8..673629cf9 100644 --- a/tdeioslave/media/mediamanager/mediamanager.h +++ b/tdeioslave/media/mediamanager/mediamanager.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "medialist.h" #include "backendbase.h" @@ -46,10 +47,10 @@ k_dcop: TQStringList mountoptions(const TQString &name); bool setMountoptions(const TQString &name, const TQStringList &options); - TQString mount(const TQString &uid); - TQString unmount(const TQString &uid); - TQString decrypt(const TQString &uid, const TQString &password); - TQString undecrypt(const TQString &uid); + TQStringVariantMap mount(const TQString &uid); + TQStringVariantMap unmount(const TQString &uid); + TQStringVariantMap decrypt(const TQString &uid, const TQString &password); + TQStringVariantMap undecrypt(const TQString &uid); TQString nameForLabel(const TQString &label); ASYNC setUserLabel(const TQString &name, const TQString &label); diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp index 33d1fe455..c228caf71 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp @@ -50,15 +50,6 @@ (medium->isEncrypted() ? (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt) ? "-decrypted" : "-encrypted") : "" ) \ ) -#define CHECK_FOR_AND_EXECUTE_AUTOMOUNT(udi, medium, allowNotification) { \ - TQMap 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 */ 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; // Automount if enabled - CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification) + TQMap 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; // Automount if enabled - CHECK_FOR_AND_EXECUTE_AUTOMOUNT(sdevice->uniqueID(), medium, allowNotification) + TQMap 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 @@ -1179,49 +1186,55 @@ void TDEBackend::slotPasswordCancel() { m_decryptPasswordValid = true; } -TQString TDEBackend::mount(const Medium *medium) +TQStringVariantMap TDEBackend::mount(const Medium *medium) { + TQStringVariantMap result; if (medium->isMounted()) { - return TQString(); // that was easy + result["result"] = true; + return result; } TQString mountPoint = isInFstab(medium); - if (!mountPoint.isNull()) + if (!mountPoint.isEmpty()) { struct mount_job_data data; data.completed = false; data.medium = medium; - TDEIO::Job *job = TDEIO::mount( false, 0, medium->deviceNode(), mountPoint ); - connect(job, TQT_SIGNAL( result (TDEIO::Job *)), TQT_SLOT( slotResult( TDEIO::Job *))); + TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), mountPoint); + connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*))); mount_jobs[job] = &data; // The caller expects the device to be mounted when the function // completes. Thus block until the job completes. while (!data.completed) { kapp->eventLoop()->enterLoop(); } - // Return the error message (if any) to the caller - return (data.error) ? data.errorMessage : TQString::null; - + if (!data.error) { + 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(); - - TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id()); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); if (!sdevice) { - return i18n("Internal error"); + result["errStr"] = i18n("Internal error. Couldn't find medium."); + result["result"] = false; + return result; } - TQString diskLabel; - TQMap valids = MediaManagerUtils::splitOptions(mountoptions(medium->id())); - + TQString diskLabel; TQString mount_point = valids["mountpoint"]; if (mount_point.startsWith("/media/")) { diskLabel = mount_point.mid(7); } - - if (diskLabel == "") { + if (diskLabel.isEmpty()) { // Try to use a pretty mount point if possible TQStringList pieces = TQStringList::split("/", sdevice->deviceNode(), FALSE); TQString node = pieces[pieces.count()-1]; @@ -1229,22 +1242,17 @@ TQString TDEBackend::mount(const Medium *medium) diskLabel.replace("/", "_"); } - TQString qerror = i18n("Cannot mount encrypted drives!"); - + 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.

Potential reasons include:
Improper device and/or user privilege level
Corrupt data on storage device"); + qerror = i18n("Unable to mount this device."); TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; if (!errStr.isEmpty()) { qerror.append(i18n("

Technical details:
").append(errStr)); } - qerror.append(""); - } - else { - qerror = ""; } } else { @@ -1275,7 +1283,9 @@ TQString TDEBackend::mount(const Medium *medium) if (m_decryptionPassword.isNull()) { delete m_decryptDialog; - return TQString("Decryption aborted"); + result["errStr"] = i18n("Decryption aborted"); + result["result"] = false; + return result; } 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, @@ -1311,17 +1321,16 @@ TQString TDEBackend::mount(const Medium *medium) continue_trying_to_decrypt = true; } else { - qerror = i18n("Unable to mount this device.

Potential reasons include:
Improper device and/or user privilege level
Corrupt data on storage device
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; if (!errStr.isEmpty()) { qerror.append(i18n("

Technical details:
").append(errStr)); } - qerror.append(""); continue_trying_to_decrypt = false; } } else { - qerror = ""; continue_trying_to_decrypt = false; } @@ -1331,7 +1340,9 @@ TQString TDEBackend::mount(const Medium *medium) } if (!qerror.isEmpty()) { - return qerror; + result["errStr"] = qerror; + result["result"] = false; + return result; } ResetProperties(sdevice, false, true); @@ -1340,29 +1351,36 @@ TQString TDEBackend::mount(const Medium *medium) 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) { - 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); } -TQString TDEBackend::unmount(const TQString &_udi) +TQStringVariantMap TDEBackend::unmount(const TQString &id) { - 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->isMounted()) { - return TQString(); // that was easy + result["result"] = true; + return result; } TQString mountPoint = isInFstab(medium); @@ -1373,83 +1391,90 @@ TQString TDEBackend::unmount(const TQString &_udi) data.medium = medium; 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; // The caller expects the device to be unmounted when the function // completes. Thus block until the job completes. while (!data.completed) { kapp->eventLoop()->enterLoop(); } - // Return the error message (if any) to the caller - return (data.error) ? data.errorMessage : TQString::null; + if (!data.error) { + 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(); - - TDEStorageDevice * sdevice = hwdevices->findDiskByUID(medium->id()); + TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id()); 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 TQString uid = sdevice->uniqueID(); TQString node = sdevice->deviceNode(); + TQString qerror; TQStringVariantMap unmountResult = sdevice->unmountDevice(); if (unmountResult["result"].toBool() == false) { // Unmount failed! - qerror = "" + i18n("Unfortunately, the device %1 (%2) named '%3' and currently mounted at %4 could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); + qerror = i18n("Unfortunately, the device %1 (%2) named '%3' and currently mounted at " + "%4 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; if (!errStr.isEmpty()) { qerror.append(i18n("

Technical details:
").append(errStr)); } - qerror.append(""); - } - else { - qerror = ""; } if (unmountResult.contains("retCode") && unmountResult["retCode"].toInt() == 1280) { // Failed as BUSY TQString processesUsingDev = listUsingProcesses(medium); if (!processesUsingDev.isNull()) { - if (KMessageBox::warningYesNo(0, i18n("The device %1 (%2) named '%3' and currently mounted at %4 can not be unmounted at this time.

%5

Would you like to forcibly terminate these processes?
All unsaved data would be lost").arg("system:/media/" + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()).arg(processesUsingDev)) == KMessageBox::Yes) { + if (KMessageBox::warningYesNo(0, i18n("The device %1 (%2) named '%3' and currently " + "mounted at %4 can not be unmounted at this time.

%5

Would you like to forcibly " + "terminate these processes?
All unsaved data would be lost").arg("system:/media/" + + medium->name()).arg(medium->deviceNode()).arg(medium->prettyLabel()).arg(medium->prettyBaseURL().pathOrURL()) + .arg(processesUsingDev)) == KMessageBox::Yes) { killUsingProcesses(medium); unmountResult = sdevice->unmountDevice(); if (unmountResult["result"].toBool() == false) { // Unmount failed! - qerror = "" + i18n("Unfortunately, the device %1 (%2) named '%3' and currently mounted at %4 could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); + qerror = i18n("Unfortunately, the device %1 (%2) named '%3' and currently mounted at " + "%4 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; if (!errStr.isEmpty()) { qerror.append(i18n("

Technical details:
").append(errStr)); } - qerror.append(""); - } - else { - qerror = ""; } } } } - if (qerror != "") { - return qerror; + if (!qerror.isEmpty()) { + 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 no reliable way to know if this happened either! + // There is a possibility that the storage device was unceremoniously removed from the system immediately + // after it was unmounted. There is no reliable way to know if this happened either! // For now, see if the device node still exists TQFileInfo checkDN(node); if (!checkDN.exists()) { m_mediaList.removeMedium(uid, true); } - return TQString(); + result["result"] = true; + return result; } void TDEBackend::slotResult(TDEIO::Job *job) diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.h b/tdeioslave/media/mediamanager/tdehardwarebackend.h index 19f697a84..bc9bcca4a 100644 --- a/tdeioslave/media/mediamanager/tdehardwarebackend.h +++ b/tdeioslave/media/mediamanager/tdehardwarebackend.h @@ -68,11 +68,11 @@ public: bool setMountoptions(const TQString &id, const TQStringList &options); - TQString mount(const TQString &id); - TQString mount(const Medium *medium); - TQString unmount(const TQString &id); -// TQString decrypt(const TQString &id, const TQString &password); -// TQString undecrypt(const TQString &id); + TQStringVariantMap mount(const TQString &id); + TQStringVariantMap mount(const Medium *medium); + TQStringVariantMap unmount(const TQString &id); +// TQStringVariantMap decrypt(const TQString &id, const TQString &password); +// TQStringVariantMap undecrypt(const TQString &id); private: /** -- cgit v1.2.1