[partition] Move initLayout logic to object PartitionLayout

- The logic of the method initLayout belongs to the object
  PartitionLayout. Move logic to that object.
- Use a single method initLayout in object PartitionCoreModule.
- Member m_partLayout in object PartitionCoreModule is no longer
  allocated.
This commit is contained in:
Gaël PORTAY 2020-06-19 23:06:38 -04:00
parent eae1e90dce
commit d6ea30b23e
5 changed files with 81 additions and 85 deletions

View file

@ -21,6 +21,8 @@
#include "core/PartitionActions.h"
#include "core/PartitionInfo.h"
#include "utils/Variant.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
@ -135,6 +137,79 @@ PartitionLayout::addEntry( const QString& label,
return true;
}
void
PartitionLayout::init( const QVariantList& config )
{
bool ok;
QString sizeString;
QString minSizeString;
QString maxSizeString;
m_partLayout.clear();
for ( const auto& r : config )
{
QVariantMap pentry = r.toMap();
if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || !pentry.contains( "filesystem" )
|| !pentry.contains( "size" ) )
{
cError() << "Partition layout entry #" << config.indexOf( r )
<< "lacks mandatory attributes, switching to default layout.";
m_partLayout.clear();
break;
}
if ( pentry.contains( "size" ) && CalamaresUtils::getString( pentry, "size" ).isEmpty() )
{
sizeString.setNum( CalamaresUtils::getInteger( pentry, "size", 0 ) );
}
else
{
sizeString = CalamaresUtils::getString( pentry, "size" );
}
if ( pentry.contains( "minSize" ) && CalamaresUtils::getString( pentry, "minSize" ).isEmpty() )
{
minSizeString.setNum( CalamaresUtils::getInteger( pentry, "minSize", 0 ) );
}
else
{
minSizeString = CalamaresUtils::getString( pentry, "minSize" );
}
if ( pentry.contains( "maxSize" ) && CalamaresUtils::getString( pentry, "maxSize" ).isEmpty() )
{
maxSizeString.setNum( CalamaresUtils::getInteger( pentry, "maxSize", 0 ) );
}
else
{
maxSizeString = CalamaresUtils::getString( pentry, "maxSize" );
}
if ( !addEntry( CalamaresUtils::getString( pentry, "name" ),
CalamaresUtils::getString( pentry, "uuid" ),
CalamaresUtils::getString( pentry, "type" ),
CalamaresUtils::getUnsignedInteger( pentry, "attributes", 0 ),
CalamaresUtils::getString( pentry, "mountPoint" ),
CalamaresUtils::getString( pentry, "filesystem" ),
CalamaresUtils::getSubMap( pentry, "features", ok ),
sizeString,
minSizeString,
maxSizeString ) )
{
cError() << "Partition layout entry #" << config.indexOf( r ) << "is invalid, switching to default layout.";
m_partLayout.clear();
break;
}
}
if ( !m_partLayout.count() )
{
addEntry( QString( "/" ), QString( "100%" ) );
}
}
QList< Partition* >
PartitionLayout::execute( Device* dev,
qint64 firstSector,