diff --git a/src/libcalamares/partition/AutoMount.cpp b/src/libcalamares/partition/AutoMount.cpp index adc844816..35aa635d2 100644 --- a/src/libcalamares/partition/AutoMount.cpp +++ b/src/libcalamares/partition/AutoMount.cpp @@ -21,9 +21,23 @@ namespace Partition struct AutoMountInfo { + bool hasSolid = false; bool wasSolidModuleAutoLoaded = false; }; +/** @section Solid + * + * KDE Solid automount management. + * + * Solid can be influenced through DBus calls to kded5. The following code + * handles Solid: if Solid exists (e.g. we're in a KDE Plasma desktop) + * then try to turn off automount that way. + */ + +/** @brief Boilerplate for a call to kded5 + * + * Returns a method-call message, ready for arguments and call(). + */ static inline QDBusMessage kdedCall( const QString& method ) { @@ -31,6 +45,11 @@ kdedCall( const QString& method ) QStringLiteral( "org.kde.kded5" ), QStringLiteral( "/kded" ), QStringLiteral( "org.kde.kded5" ), method ); } +/** @brief Enables (or disables) automount for Solid + * + * If @p enable is @c true, enables automount. Otherwise, disables it. + * This throws some DBbus messages on the wire and forgets about them. + */ // This code comes, roughly, from the KCM for removable devices. static void enableSolidAutoMount( QDBusConnection& dbus, bool enable ) @@ -52,6 +71,13 @@ enableSolidAutoMount( QDBusConnection& dbus, bool enable ) } } +/** @brief Check if Solid exists and has automount set + * + * Updates the @p info object with the discovered information. + * - if there is no Solid available on DBus, sets hasSolid to @c false + * - if there is Solid available on DBusm, sets *hasSolid* to @c true + * and places the queried value of automounting in *wasSolidModuleAutoLoaded*. + */ static void querySolidAutoMount( QDBusConnection& dbus, AutoMountInfo& info ) { @@ -74,25 +100,45 @@ querySolidAutoMount( QDBusConnection& dbus, AutoMountInfo& info ) } } } + else + { + // It's an error message + cDebug() << "Solid not available:" << r.errorMessage(); + } + info.hasSolid = result.has_value(); info.wasSolidModuleAutoLoaded = result.has_value() ? result.value() : false; } std::shared_ptr< AutoMountInfo > automountDisable( bool disable ) { - auto u = std::make_shared< AutoMountInfo >(); + auto info = std::make_shared< AutoMountInfo >(); QDBusConnection dbus = QDBusConnection::sessionBus(); - querySolidAutoMount( dbus, *u ); - enableSolidAutoMount( dbus, !disable ); - return u; + + // KDE Plasma (Solid) handling + querySolidAutoMount( dbus, *info ); + if ( info->hasSolid ) + { + enableSolidAutoMount( dbus, !disable ); + } + + // TODO: other environments + return info; } void -automountRestore( const std::shared_ptr< AutoMountInfo >& t ) +automountRestore( const std::shared_ptr< AutoMountInfo >& info ) { QDBusConnection dbus = QDBusConnection::sessionBus(); - enableSolidAutoMount( dbus, t->wasSolidModuleAutoLoaded ); + + // KDE Plasma (Solid) handling + if ( info->hasSolid ) + { + enableSolidAutoMount( dbus, info->wasSolidModuleAutoLoaded ); + } + + // TODO: other environments } } // namespace Partition