diff --git a/src/modules/partition/core/Config.cpp b/src/modules/partition/core/Config.cpp index 5099b48e6..d74ae504e 100644 --- a/src/modules/partition/core/Config.cpp +++ b/src/modules/partition/core/Config.cpp @@ -31,8 +31,39 @@ Config::installChoiceNames() return names; } +const NamedEnumTable< Config::SwapChoice >& +Config::swapChoiceNames() +{ + static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap }, + { QStringLiteral( "small" ), SwapChoice::SmallSwap }, + { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, + { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, + { QStringLiteral( "file" ), SwapChoice::SwapFile } }; -static PartitionActions::Choices::SwapChoiceSet + return names; +} + +Config::SwapChoice +pickOne( const Config::SwapChoiceSet& s ) +{ + if ( s.count() == 0 ) + { + return Config::SwapChoice::NoSwap; + } + if ( s.count() == 1 ) + { + return *( s.begin() ); + } + if ( s.contains( Config::SwapChoice::NoSwap ) ) + { + return Config::SwapChoice::NoSwap; + } + // Here, count > 1 but NoSwap is not a member. + return *( s.begin() ); +} + + +static Config::SwapChoiceSet getSwapChoices( const QVariantMap& configurationMap ) { // SWAP SETTINGS @@ -57,7 +88,7 @@ getSwapChoices( const QVariantMap& configurationMap ) } bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false ); - PartitionActions::Choices::SwapChoiceSet choices; // Available swap choices + Config::SwapChoiceSet choices; // Available swap choices if ( configurationMap.contains( "userSwapChoices" ) ) { // We've already warned about overlapping settings with the @@ -67,7 +98,7 @@ getSwapChoices( const QVariantMap& configurationMap ) for ( const auto& item : l ) { bool ok = false; - auto v = PartitionActions::Choices::swapChoiceNames().find( item, ok ); + auto v = Config::swapChoiceNames().find( item, ok ); if ( ok ) { choices.insert( v ); @@ -77,28 +108,28 @@ getSwapChoices( const QVariantMap& configurationMap ) if ( choices.isEmpty() ) { cWarning() << "Partition-module configuration for *userSwapChoices* is empty:" << l; - choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); + choices.insert( Config::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 ); + ensureSuspendToDisk = choices.contains( Config::SwapChoice::FullSwap ); + neverCreateSwap = ( choices.count() == 1 ) && choices.contains( Config::SwapChoice::NoSwap ); } else { // Convert the legacy settings into a single setting for now. if ( neverCreateSwap ) { - choices.insert( PartitionActions::Choices::SwapChoice::NoSwap ); + choices.insert( Config::SwapChoice::NoSwap ); } else if ( ensureSuspendToDisk ) { - choices.insert( PartitionActions::Choices::SwapChoice::FullSwap ); + choices.insert( Config::SwapChoice::FullSwap ); } else { - choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap ); + choices.insert( Config::SwapChoice::SmallSwap ); } } @@ -109,11 +140,11 @@ getSwapChoices( const QVariantMap& configurationMap ) if ( choices.contains( x ) ) \ { \ bool bogus = false; \ - cWarning() << unsupportedSetting << PartitionActions::Choices::swapChoiceNames().find( x, bogus ); \ + cWarning() << unsupportedSetting << Config::swapChoiceNames().find( x, bogus ); \ choices.remove( x ); \ } - COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap ) + COMPLAIN_UNSUPPORTED( Config::SwapChoice::ReuseSwap ) #undef COMPLAIN_UNSUPPORTED return choices; @@ -149,16 +180,16 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) m_swapChoices = getSwapChoices( configurationMap ); bool nameFound = false; // In the name table (ignored, falls back to first entry in table) - m_initialInstallChoice = Config::installChoiceNames().find( + m_initialInstallChoice = installChoiceNames().find( CalamaresUtils::getString( configurationMap, "initialPartitioningChoice" ), nameFound ); setInstallChoice( m_initialInstallChoice ); - m_initialSwapChoice = PartitionActions::Choices::swapChoiceNames().find( - CalamaresUtils::getString( configurationMap, "initialSwapChoice" ), nameFound ); + m_initialSwapChoice + = swapChoiceNames().find( CalamaresUtils::getString( configurationMap, "initialSwapChoice" ), nameFound ); if ( !m_swapChoices.contains( m_initialSwapChoice ) ) { cWarning() << "Configuration for *initialSwapChoice* is not one of the *userSwapChoices*"; - m_initialSwapChoice = PartitionActions::Choices::pickOne( m_swapChoices ); + m_initialSwapChoice = pickOne( m_swapChoices ); } } diff --git a/src/modules/partition/core/Config.h b/src/modules/partition/core/Config.h index 00f81b897..04c6a0bd0 100644 --- a/src/modules/partition/core/Config.h +++ b/src/modules/partition/core/Config.h @@ -10,7 +10,7 @@ #ifndef PARTITION_CONFIG_H #define PARTITION_CONFIG_H -#include "core/PartitionActions.h" +#include "utils/NamedEnum.h" #include #include @@ -40,10 +40,23 @@ public: Q_ENUM( InstallChoice ) static const NamedEnumTable< InstallChoice >& installChoiceNames(); + /** @brief Choice of swap (size and type) */ + enum SwapChoice + { + NoSwap, // don't create any swap, don't use any + ReuseSwap, // don't create, but do use existing + SmallSwap, // up to 8GiB of swap + FullSwap, // ensureSuspendToDisk -- at least RAM size + SwapFile // use a file (if supported) + }; + Q_ENUM( SwapChoice ) + static const NamedEnumTable< SwapChoice >& swapChoiceNames(); + using SwapChoiceSet = QSet< SwapChoice >; + void setConfigurationMap( const QVariantMap& ); void updateGlobalStorage() const; - PartitionActions::Choices::SwapChoiceSet swapChoices() const { return m_swapChoices; } + SwapChoiceSet swapChoices() const { return m_swapChoices; } /** @brief What kind of installation (partitioning) is requested **initially**? * @@ -65,7 +78,7 @@ public: * * @return The swap choice (may be @c NoSwap ) */ - PartitionActions::Choices::SwapChoice initialSwapChoice() const { return m_initialSwapChoice; } + SwapChoice initialSwapChoice() const { return m_initialSwapChoice; } public Q_SLOTS: void setInstallChoice( int ); @@ -75,12 +88,20 @@ Q_SIGNALS: void installChoiceChanged( InstallChoice ); private: - PartitionActions::Choices::SwapChoice m_initialSwapChoice; - PartitionActions::Choices::SwapChoiceSet m_swapChoices; + SwapChoice m_initialSwapChoice; + SwapChoiceSet m_swapChoices; InstallChoice m_initialInstallChoice = NoChoice; InstallChoice m_installChoice = NoChoice; qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module }; +/** @brief Given a set of swap choices, return a sensible value from it. + * + * "Sensible" here means: if there is one value, use it; otherwise, use + * NoSwap if there are no choices, or if NoSwap is one of the choices, in the set. + * If that's not possible, any value from the set. + */ +Config::SwapChoice pickOne( const Config::SwapChoiceSet& s ); + #endif diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 168c3804a..9f6e63c91 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -35,9 +35,9 @@ using CalamaresUtils::operator""_GiB; using CalamaresUtils::operator""_MiB; qint64 -swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap ) +swapSuggestion( const qint64 availableSpaceB, Config::SwapChoice swap ) { - if ( ( swap != Choices::SmallSwap ) && ( swap != Choices::FullSwap ) ) + if ( ( swap != Config::SwapChoice::SmallSwap ) && ( swap != Config::SwapChoice::FullSwap ) ) { return 0; } @@ -48,7 +48,7 @@ swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap ) qint64 availableRamB = memory.first; qreal overestimationFactor = memory.second; - bool ensureSuspendToDisk = swap == Choices::FullSwap; + bool ensureSuspendToDisk = swap == Config::SwapChoice::FullSwap; // Ramp up quickly to 8GiB, then follow memory size if ( availableRamB <= 4_GiB ) @@ -149,7 +149,8 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO core->createPartitionTable( dev, PartitionTable::msdos ); } - const bool mayCreateSwap = ( o.swap == Choices::SmallSwap ) || ( o.swap == Choices::FullSwap ); + const bool mayCreateSwap + = ( o.swap == Config::SwapChoice::SmallSwap ) || ( o.swap == Config::SwapChoice::FullSwap ); bool shouldCreateSwap = false; qint64 suggestedSwapSizeB = 0; @@ -246,39 +247,4 @@ doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition core->dumpQueue(); } -namespace Choices -{ -const NamedEnumTable< SwapChoice >& -swapChoiceNames() -{ - static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap }, - { QStringLiteral( "small" ), SwapChoice::SmallSwap }, - { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, - { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, - { QStringLiteral( "file" ), SwapChoice::SwapFile } }; - - return names; -} - -SwapChoice -pickOne( const SwapChoiceSet& s ) -{ - if ( s.count() == 0 ) - { - return SwapChoice::NoSwap; - } - if ( s.count() == 1 ) - { - return *( s.begin() ); - } - if ( s.contains( SwapChoice::NoSwap ) ) - { - return SwapChoice::NoSwap; - } - // Here, count > 1 but NoSwap is not a member. - return *( s.begin() ); -} - -} // namespace Choices - } // namespace PartitionActions diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index 12b0f682e..15b7c1e1e 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -10,7 +10,7 @@ #ifndef PARTITIONACTIONS_H #define PARTITIONACTIONS_H -#include "utils/NamedEnum.h" +#include "core/Config.h" #include #include @@ -27,26 +27,6 @@ namespace PartitionActions */ namespace Choices { -/** @brief Choice of swap (size and type) */ -enum SwapChoice -{ - NoSwap, // don't create any swap, don't use any - ReuseSwap, // don't create, but do use existing - SmallSwap, // up to 8GiB of swap - FullSwap, // ensureSuspendToDisk -- at least RAM size - SwapFile // use a file (if supported) -}; -using SwapChoiceSet = QSet< SwapChoice >; -const NamedEnumTable< SwapChoice >& swapChoiceNames(); - -/** @brief Given a set of swap choices, return a sensible value from it. - * - * "Sensible" here means: if there is one value, use it; otherwise, use - * NoSwap if there are no choices, or if NoSwap is one of the choices, in the set. - * If that's not possible, any value from the set. - */ -SwapChoice pickOne( const SwapChoiceSet& s ); - struct ReplacePartitionOptions { QString defaultFsType; // e.g. "ext4" or "btrfs" @@ -63,13 +43,13 @@ struct AutoPartitionOptions : ReplacePartitionOptions { QString efiPartitionMountPoint; // optional, e.g. "/boot" quint64 requiredSpaceB; // estimated required space for root partition - SwapChoice swap; + Config::SwapChoice swap; AutoPartitionOptions( const QString& fs, const QString& luks, const QString& efi, qint64 requiredBytes, - SwapChoice s ) + Config::SwapChoice s ) : ReplacePartitionOptions( fs, luks ) , efiPartitionMountPoint( efi ) , requiredSpaceB( requiredBytes > 0 ? static_cast< quint64 >( requiredBytes ) : 0 ) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index ccdd50251..d8926145b 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -60,7 +60,7 @@ using CalamaresUtils::Partition::findPartitionByPath; using CalamaresUtils::Partition::isPartitionFreeSpace; using CalamaresUtils::Partition::PartitionIterator; using InstallChoice = Config::InstallChoice; -using PartitionActions::Choices::SwapChoice; +using SwapChoice = Config::SwapChoice; /** * @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of @@ -433,8 +433,7 @@ ChoicePage::onEraseSwapChoiceChanged() { if ( m_eraseSwapChoiceComboBox ) { - m_eraseSwapChoice - = static_cast< PartitionActions::Choices::SwapChoice >( m_eraseSwapChoiceComboBox->currentData().toInt() ); + m_eraseSwapChoice = static_cast< Config::SwapChoice >( m_eraseSwapChoiceComboBox->currentData().toInt() ); onActionChanged(); } } diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 5c20d817a..b598c92fb 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -17,7 +17,6 @@ #include "core/Config.h" #include "core/OsproberEntry.h" -// #include "core/PartitionActions.h" #include #include @@ -43,7 +42,7 @@ class PartitionCoreModule; class Device; -using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice >; +using SwapChoiceSet = Config::SwapChoiceSet; /** * @brief The ChoicePage class is the first page of the partitioning interface. @@ -158,7 +157,7 @@ private: QString m_defaultFsType; bool m_enableEncryptionWidget; SwapChoiceSet m_availableSwapChoices; // What is available - PartitionActions::Choices::SwapChoice m_eraseSwapChoice; // what is selected + Config::SwapChoice m_eraseSwapChoice; // what is selected bool m_allowManualPartitioning;