From c7645af358b548597def0d676e0a38b4b8dd4309 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 11 Oct 2018 06:27:39 -0400 Subject: [PATCH] [partition] Translate swap-choice-strings to enum - Handle legacy and modern config, mixed-configs, - Translate strings to enum values, - Default and warn as appropriate. - Doesn't **do** anything with the config, though. --- .../partition/gui/PartitionViewStep.cpp | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 9e8a120a7..bfd52b35e 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -21,6 +21,7 @@ #include "gui/PartitionViewStep.h" #include "core/DeviceModel.h" +#include "core/PartitionActions.h" #include "core/PartitionCoreModule.h" #include "core/PartitionModel.h" #include "core/KPMHelpers.h" @@ -470,6 +471,31 @@ PartitionViewStep::onLeave() } +static PartitionActions::Choices::SwapChoice +nameToChoice( QString name, bool& ok ) +{ + ok = false; + name = name.toLower(); + + using namespace PartitionActions::Choices; + + // Each return here first sets ok to true, returns enum value + if ( name == QStringLiteral( "none" ) ) + return( ok=true, SwapChoice::NoSwap ); + else if ( name == QStringLiteral( "small" ) ) + return( ok=true, SwapChoice::SmallSwap); + else if ( name == QStringLiteral( "suspend" ) ) + return( ok=true, SwapChoice::FullSwap ); + else if ( name == QStringLiteral( "reuse" ) ) + return( ok=true, SwapChoice::ReuseSwap ); + else if ( name == QStringLiteral( "file" ) ) + return( ok=true, SwapChoice::SwapFile ); + + ok = false; + return SwapChoice::NoSwap; +} + + void PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -497,6 +523,43 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) 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 = 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 ); + } + // These gs settings seem to be unused (in upstream Calamares) outside of // the partition module itself. gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); @@ -524,7 +587,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) // and remove the spinner. QFutureWatcher< void >* watcher = new QFutureWatcher< void >(); connect( watcher, &QFutureWatcher< void >::finished, - this, [ this, watcher ] + this, [ this, watcher, choices ] { continueLoading(); watcher->deleteLater();