[partition] Consolidate SwapChoice handling
- pickOne() may be useful, given a set of swap choices; expose it - move type definitions to PartitionActions, where some of them come from.
This commit is contained in:
parent
4ae398c18d
commit
68bb066755
@ -28,7 +28,7 @@ Config::Config( QObject* parent )
|
||||
{
|
||||
}
|
||||
|
||||
Config::SwapChoices
|
||||
static PartitionActions::Choices::SwapChoiceSet
|
||||
getSwapChoices( const QVariantMap& configurationMap )
|
||||
{
|
||||
// SWAP SETTINGS
|
||||
@ -53,7 +53,7 @@ getSwapChoices( const QVariantMap& configurationMap )
|
||||
}
|
||||
bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false );
|
||||
|
||||
Config::SwapChoices choices; // Available swap choices
|
||||
PartitionActions::Choices::SwapChoiceSet choices; // Available swap choices
|
||||
if ( configurationMap.contains( "userSwapChoices" ) )
|
||||
{
|
||||
// We've already warned about overlapping settings with the
|
||||
|
@ -36,10 +36,8 @@ public:
|
||||
|
||||
void updateGlobalStorage() const;
|
||||
|
||||
using SwapChoices = QSet< PartitionActions::Choices::SwapChoice >;
|
||||
|
||||
private:
|
||||
SwapChoices m_swapChoices;
|
||||
PartitionActions::Choices::SwapChoiceSet m_swapChoices;
|
||||
qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module
|
||||
};
|
||||
|
||||
|
@ -293,6 +293,25 @@ choiceToName( SwapChoice c )
|
||||
return nameTable().find( c, ok );
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef PARTITIONACTIONS_H
|
||||
#define PARTITIONACTIONS_H
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
class PartitionCoreModule;
|
||||
@ -42,10 +43,19 @@ enum SwapChoice
|
||||
FullSwap, // ensureSuspendToDisk -- at least RAM size
|
||||
SwapFile // use a file (if supported)
|
||||
};
|
||||
using SwapChoiceSet = QSet< SwapChoice >;
|
||||
|
||||
SwapChoice nameToChoice( QString name, bool& ok );
|
||||
QString choiceToName( SwapChoice );
|
||||
|
||||
/** @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"
|
||||
|
@ -70,24 +70,6 @@ using CalamaresUtils::Partition::isPartitionFreeSpace;
|
||||
using CalamaresUtils::Partition::findPartitionByPath;
|
||||
using Calamares::PrettyRadioButton;
|
||||
|
||||
/** @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 )
|
||||
{
|
||||
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() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of
|
||||
* the module loading code path.
|
||||
@ -112,7 +94,7 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent )
|
||||
, m_lastSelectedDeviceIndex( -1 )
|
||||
, m_enableEncryptionWidget( true )
|
||||
, m_availableSwapChoices( swapChoices )
|
||||
, m_eraseSwapChoice( pickOne( swapChoices ) )
|
||||
, m_eraseSwapChoice( PartitionActions::Choices::pickOne( swapChoices ) )
|
||||
, m_allowManualPartitioning( true )
|
||||
{
|
||||
setupUi( this );
|
||||
|
Loading…
Reference in New Issue
Block a user