diff --git a/src/modules/partition/core/Config.cpp b/src/modules/partition/core/Config.cpp index 5026169fb..b8e68a137 100644 --- a/src/modules/partition/core/Config.cpp +++ b/src/modules/partition/core/Config.cpp @@ -20,6 +20,7 @@ #include "GlobalStorage.h" #include "JobQueue.h" +#include "utils/Logger.h" #include "utils/Variant.h" Config::Config( QObject* parent ) @@ -27,11 +28,99 @@ Config::Config( QObject* parent ) { } +Config::SwapChoices +getSwapChoices( const QVariantMap& configurationMap ) +{ + // SWAP SETTINGS + // + // This is a bit convoluted because there's legacy settings to handle as well + // as the new-style list of choices, with mapping back-and-forth. + if ( configurationMap.contains( "userSwapChoices" ) + && ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) + { + cError() << "Partition-module configuration mixes old- and new-style swap settings."; + } + + if ( configurationMap.contains( "ensureSuspendToDisk" ) ) + { + cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated."; + } + bool ensureSuspendToDisk = CalamaresUtils::getBool( configurationMap, "ensureSuspendToDisk", true ); + + if ( configurationMap.contains( "neverCreateSwap" ) ) + { + cWarning() << "Partition-module setting *neverCreateSwap* is deprecated."; + } + bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false ); + + Config::SwapChoices choices; // Available swap choices + if ( configurationMap.contains( "userSwapChoices" ) ) + { + // We've already warned about overlapping settings with the + // legacy *ensureSuspendToDisk* and *neverCreateSwap*. + QStringList l = configurationMap[ "userSwapChoices" ].toStringList(); + + for ( const auto& item : l ) + { + bool ok = false; + auto v = PartitionActions::Choices::nameToChoice( item, ok ); + if ( ok ) + { + choices.insert( v ); + } + } + + if ( choices.isEmpty() ) + { + cWarning() << "Partition-module configuration for *userSwapChoices* is empty:" << l; + choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); + } + + // suspend if it's one of the possible choices; suppress swap only if it's + // the **only** choice available. + ensureSuspendToDisk = choices.contains( PartitionActions::Choices::SwapChoice::FullSwap ); + neverCreateSwap = ( choices.count() == 1 ) && choices.contains( PartitionActions::Choices::SwapChoice::NoSwap ); + } + else + { + // Convert the legacy settings into a single setting for now. + if ( neverCreateSwap ) + { + choices.insert( PartitionActions::Choices::SwapChoice::NoSwap ); + } + else if ( ensureSuspendToDisk ) + { + choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); + } + else + { + choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap ); + } + } + + // Not all are supported right now // FIXME + static const char unsupportedSetting[] = "Partition-module does not support *userSwapChoices* setting"; + +#define COMPLAIN_UNSUPPORTED( x ) \ + if ( choices.contains( x ) ) \ + { \ + cWarning() << unsupportedSetting << PartitionActions::Choices::choiceToName( x ); \ + choices.remove( x ); \ + } + + COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::SwapFile ) + COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap ) +#undef COMPLAIN_UNSUPPORTED + + return choices; +} + void Config::setConfigurationMap( const QVariantMap& configurationMap ) { // Settings that overlap with the Welcome module m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 ); + m_swapChoices = getSwapChoices( configurationMap ); } void diff --git a/src/modules/partition/core/Config.h b/src/modules/partition/core/Config.h index 2543700be..dcd8199d7 100644 --- a/src/modules/partition/core/Config.h +++ b/src/modules/partition/core/Config.h @@ -36,7 +36,10 @@ public: void updateGlobalStorage() const; + using SwapChoices = QSet< PartitionActions::Choices::SwapChoice >; + private: + SwapChoices m_swapChoices; qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module }; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 02666097b..608d8c70c 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -549,94 +549,6 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) gs->insert( "efiSystemPartitionName", CalamaresUtils::getString( configurationMap, "efiSystemPartitionName" ) ); } - // SWAP SETTINGS - // - // This is a bit convoluted because there's legacy settings to handle as well - // as the new-style list of choices, with mapping back-and-forth. - if ( configurationMap.contains( "userSwapChoices" ) - && ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) ) - { - cError() << "Partition-module configuration mixes old- and new-style swap settings."; - } - - if ( configurationMap.contains( "ensureSuspendToDisk" ) ) - { - cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated."; - } - bool ensureSuspendToDisk = CalamaresUtils::getBool( configurationMap, "ensureSuspendToDisk", true ); - - if ( configurationMap.contains( "neverCreateSwap" ) ) - { - cWarning() << "Partition-module setting *neverCreateSwap* is deprecated."; - } - bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false ); - - QSet< PartitionActions::Choices::SwapChoice > choices; // Available swap choices - if ( configurationMap.contains( "userSwapChoices" ) ) - { - // We've already warned about overlapping settings with the - // legacy *ensureSuspendToDisk* and *neverCreateSwap*. - QStringList l = configurationMap[ "userSwapChoices" ].toStringList(); - - for ( const auto& item : l ) - { - bool ok = false; - auto v = PartitionActions::Choices::nameToChoice( item, ok ); - if ( ok ) - { - choices.insert( v ); - } - } - - if ( choices.isEmpty() ) - { - cWarning() << "Partition-module configuration for *userSwapChoices* is empty:" << l; - choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); - } - - // suspend if it's one of the possible choices; suppress swap only if it's - // the **only** choice available. - ensureSuspendToDisk = choices.contains( PartitionActions::Choices::SwapChoice::FullSwap ); - neverCreateSwap = ( choices.count() == 1 ) && choices.contains( PartitionActions::Choices::SwapChoice::NoSwap ); - } - else - { - // Convert the legacy settings into a single setting for now. - if ( neverCreateSwap ) - { - choices.insert( PartitionActions::Choices::SwapChoice::NoSwap ); - } - else if ( ensureSuspendToDisk ) - { - choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); - } - else - { - choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap ); - } - } - - // Not all are supported right now // FIXME - static const char unsupportedSetting[] = "Partition-module does not support *userSwapChoices* setting"; - -#define COMPLAIN_UNSUPPORTED( x ) \ - if ( choices.contains( x ) ) \ - { \ - cWarning() << unsupportedSetting << PartitionActions::Choices::choiceToName( x ); \ - choices.remove( x ); \ - } - - COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::SwapFile ) - COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap ) -#undef COMPLAIN_UNSUPPORTED - - m_swapChoices = choices; - - // These gs settings seem to be unused (in upstream Calamares) outside of - // the partition module itself. - gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); - gs->insert( "neverCreateSwap", neverCreateSwap ); - // OTHER SETTINGS // gs->insert( "drawNestedPartitions", CalamaresUtils::getBool( configurationMap, "drawNestedPartitions", false ) ); diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index efe2cb343..c2f7afdb3 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -26,8 +26,6 @@ #include "DllMacro.h" -#include "core/PartitionActions.h" - #include #include @@ -88,8 +86,6 @@ private: WaitingWidget* m_waitingWidget; QFutureWatcher* m_future; - - QSet< PartitionActions::Choices::SwapChoice > m_swapChoices; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PartitionViewStepFactory )