mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-29 02:15:36 -04:00
[partition] Use NamedEnumTable support code
- reduce amount of custom code by using the (new) generic implementation
This commit is contained in:
parent
a51a000681
commit
fee1794924
1 changed files with 18 additions and 28 deletions
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
|
#include "utils/NamedEnum.h"
|
||||||
|
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
@ -305,43 +307,31 @@ doReplacePartition( PartitionCoreModule* core,
|
||||||
|
|
||||||
namespace Choices
|
namespace Choices
|
||||||
{
|
{
|
||||||
|
static const NamedEnumTable<SwapChoice>&
|
||||||
|
nameTable()
|
||||||
|
{
|
||||||
|
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
|
SwapChoice
|
||||||
nameToChoice( QString name, bool& ok )
|
nameToChoice( QString name, bool& ok )
|
||||||
{
|
{
|
||||||
ok = false;
|
return nameTable().find( name, ok );
|
||||||
name = name.toLower();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
choiceToName( SwapChoice c )
|
choiceToName( SwapChoice c )
|
||||||
{
|
{
|
||||||
switch ( c )
|
bool ok = false;
|
||||||
{
|
return nameTable().find( c, ok );
|
||||||
case SwapChoice::NoSwap: return QStringLiteral( "none" );
|
|
||||||
case SwapChoice::SmallSwap: return QStringLiteral( "small" );
|
|
||||||
case SwapChoice::FullSwap: return QStringLiteral( "suspend" );
|
|
||||||
case SwapChoice::ReuseSwap: return QStringLiteral( "reuse" );
|
|
||||||
case SwapChoice::SwapFile: return QStringLiteral( "file" );
|
|
||||||
}
|
|
||||||
|
|
||||||
cWarning() << "Unknown SwapChoice" << c << "treated as none";
|
|
||||||
return QStringLiteral( "none" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Choices
|
} // namespace Choices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue