[partition] Apply coding style

This commit is contained in:
Adriaan de Groot 2021-07-12 15:42:54 +02:00
parent e8b17b9878
commit b43759c6a5
6 changed files with 117 additions and 100 deletions

View File

@ -227,7 +227,8 @@ fillGSConfigurationEFI( Calamares::GlobalStorage* gs, const QVariantMap& configu
QString firmwareType( PartUtils::isEfiSystem() ? QStringLiteral( "efi" ) : QStringLiteral( "bios" ) ); QString firmwareType( PartUtils::isEfiSystem() ? QStringLiteral( "efi" ) : QStringLiteral( "bios" ) );
gs->insert( "firmwareType", firmwareType ); gs->insert( "firmwareType", firmwareType );
gs->insert( "efiSystemPartition", CalamaresUtils::getString( configurationMap, "efiSystemPartition", QStringLiteral( "/boot/efi" ) ) ); gs->insert( "efiSystemPartition",
CalamaresUtils::getString( configurationMap, "efiSystemPartition", QStringLiteral( "/boot/efi" ) ) );
// Read and parse key efiSystemPartitionSize // Read and parse key efiSystemPartitionSize
if ( configurationMap.contains( "efiSystemPartitionSize" ) ) if ( configurationMap.contains( "efiSystemPartitionSize" ) )
@ -243,7 +244,7 @@ fillGSConfigurationEFI( Calamares::GlobalStorage* gs, const QVariantMap& configu
} }
void void
Config::fillConfigurationFSTypes(const QVariantMap& configurationMap) Config::fillConfigurationFSTypes( const QVariantMap& configurationMap )
{ {
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
@ -256,15 +257,16 @@ Config::fillConfigurationFSTypes(const QVariantMap& configurationMap)
if ( fsName.isEmpty() ) if ( fsName.isEmpty() )
{ {
cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4"; cWarning() << "Partition-module setting *defaultFileSystemType* is missing, will use ext4";
fsRealName = PartUtils::canonicalFilesystemName( QStringLiteral("ext4"), &fsType ); fsRealName = PartUtils::canonicalFilesystemName( QStringLiteral( "ext4" ), &fsType );
} }
else else
{ {
fsRealName = PartUtils::canonicalFilesystemName( fsName, &fsType ); fsRealName = PartUtils::canonicalFilesystemName( fsName, &fsType );
if ( fsType == FileSystem::Type::Unknown ) if ( fsType == FileSystem::Type::Unknown )
{ {
cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName << ") using ext4 instead"; cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName
fsRealName = PartUtils::canonicalFilesystemName( QStringLiteral("ext4"), &fsType ); << ") using ext4 instead";
fsRealName = PartUtils::canonicalFilesystemName( QStringLiteral( "ext4" ), &fsType );
} }
else if ( fsRealName != fsName ) else if ( fsRealName != fsName )
{ {
@ -326,7 +328,7 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
m_requiredPartitionTableType = CalamaresUtils::getStringList( configurationMap, "requiredPartitionTableType" ); m_requiredPartitionTableType = CalamaresUtils::getStringList( configurationMap, "requiredPartitionTableType" );
gs->insert( "requiredPartitionTableType", m_requiredPartitionTableType ); gs->insert( "requiredPartitionTableType", m_requiredPartitionTableType );
fillGSConfigurationEFI(gs, configurationMap); fillGSConfigurationEFI( gs, configurationMap );
fillConfigurationFSTypes( configurationMap ); fillConfigurationFSTypes( configurationMap );
} }

View File

@ -27,7 +27,8 @@ class Config : public QObject
Q_PROPERTY( SwapChoice swapChoice READ swapChoice WRITE setSwapChoice NOTIFY swapChoiceChanged ) Q_PROPERTY( SwapChoice swapChoice READ swapChoice WRITE setSwapChoice NOTIFY swapChoiceChanged )
///@brief Name of the FS that will be used when erasing type disk (e.g. "default filesystem") ///@brief Name of the FS that will be used when erasing type disk (e.g. "default filesystem")
Q_PROPERTY( QString eraseModeFilesystem READ eraseFsType WRITE setEraseFsTypeChoice NOTIFY eraseModeFilesystemChanged ) Q_PROPERTY(
QString eraseModeFilesystem READ eraseFsType WRITE setEraseFsTypeChoice NOTIFY eraseModeFilesystemChanged )
Q_PROPERTY( bool allowManualPartitioning READ allowManualPartitioning CONSTANT FINAL ) Q_PROPERTY( bool allowManualPartitioning READ allowManualPartitioning CONSTANT FINAL )
@ -134,7 +135,7 @@ public Q_SLOTS:
void setInstallChoice( InstallChoice ); void setInstallChoice( InstallChoice );
void setSwapChoice( int ); ///< Translates a button ID or so to SwapChoice void setSwapChoice( int ); ///< Translates a button ID or so to SwapChoice
void setSwapChoice( SwapChoice ); void setSwapChoice( SwapChoice );
void setEraseFsTypeChoice( const QString& filesystemName ); ///< See property eraseModeFilesystem void setEraseFsTypeChoice( const QString& filesystemName ); ///< See property eraseModeFilesystem
Q_SIGNALS: Q_SIGNALS:
void installChoiceChanged( InstallChoice ); void installChoiceChanged( InstallChoice );

View File

@ -115,10 +115,11 @@ PartitionViewStep::prettyName() const
* empty strings and duplicates. The list is in-order of how the * empty strings and duplicates. The list is in-order of how the
* jobs will be run. * jobs will be run.
*/ */
static QStringList jobDescriptions( const Calamares::JobList& jobs ) static QStringList
jobDescriptions( const Calamares::JobList& jobs )
{ {
QStringList jobsLines; QStringList jobsLines;
for( const Calamares::job_ptr& job : qAsConst( jobs ) ) for ( const Calamares::job_ptr& job : qAsConst( jobs ) )
{ {
if ( !job->prettyDescription().isEmpty() ) if ( !job->prettyDescription().isEmpty() )
{ {
@ -132,7 +133,8 @@ static QStringList jobDescriptions( const Calamares::JobList& jobs )
* *
* Returns a (branded) string describing what @p choice will do. * Returns a (branded) string describing what @p choice will do.
*/ */
static QString modeDescription( Config::InstallChoice choice ) static QString
modeDescription( Config::InstallChoice choice )
{ {
const auto* branding = Calamares::Branding::instance(); const auto* branding = Calamares::Branding::instance();
static const char context[] = "PartitionViewStep"; static const char context[] = "PartitionViewStep";
@ -141,13 +143,15 @@ static QString modeDescription( Config::InstallChoice choice )
{ {
case Config::InstallChoice::Alongside: case Config::InstallChoice::Alongside:
return QCoreApplication::translate( context, "Install %1 <strong>alongside</strong> another operating system." ) return QCoreApplication::translate( context, "Install %1 <strong>alongside</strong> another operating system." )
.arg( branding->shortVersionedName() ); .arg( branding->shortVersionedName() );
break; break;
case Config::InstallChoice::Erase: case Config::InstallChoice::Erase:
return QCoreApplication::translate( context, "<strong>Erase</strong> disk and install %1." ).arg( branding->shortVersionedName() ); return QCoreApplication::translate( context, "<strong>Erase</strong> disk and install %1." )
.arg( branding->shortVersionedName() );
break; break;
case Config::InstallChoice::Replace: case Config::InstallChoice::Replace:
return QCoreApplication::translate( context, "<strong>Replace</strong> a partition with %1." ).arg( branding->shortVersionedName() ); return QCoreApplication::translate( context, "<strong>Replace</strong> a partition with %1." )
.arg( branding->shortVersionedName() );
break; break;
case Config::InstallChoice::NoChoice: case Config::InstallChoice::NoChoice:
case Config::InstallChoice::Manual: case Config::InstallChoice::Manual:
@ -163,7 +167,8 @@ static QString modeDescription( Config::InstallChoice choice )
* is used to provide context; when more than one disk is in use, the description * is used to provide context; when more than one disk is in use, the description
* works differently. * works differently.
*/ */
static QString diskDescription( int listLength, const PartitionCoreModule::SummaryInfo& info, Config::InstallChoice choice ) static QString
diskDescription( int listLength, const PartitionCoreModule::SummaryInfo& info, Config::InstallChoice choice )
{ {
const auto* branding = Calamares::Branding::instance(); const auto* branding = Calamares::Branding::instance();
static const char context[] = "PartitionViewStep"; static const char context[] = "PartitionViewStep";
@ -172,28 +177,33 @@ static QString diskDescription( int listLength, const PartitionCoreModule::Summa
{ {
switch ( choice ) switch ( choice )
{ {
case Config::Alongside: case Config::Alongside:
return QCoreApplication::translate( context, "Install %1 <strong>alongside</strong> another operating system on disk " return QCoreApplication::translate(
"<strong>%2</strong> (%3)." ) context,
"Install %1 <strong>alongside</strong> another operating system on disk "
"<strong>%2</strong> (%3)." )
.arg( branding->shortVersionedName() ) .arg( branding->shortVersionedName() )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
case Config::Erase: case Config::Erase:
return QCoreApplication::translate( context, "<strong>Erase</strong> disk <strong>%2</strong> (%3) and install %1." ) return QCoreApplication::translate( context,
"<strong>Erase</strong> disk <strong>%2</strong> (%3) and install %1." )
.arg( branding->shortVersionedName() ) .arg( branding->shortVersionedName() )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
case Config::Replace: case Config::Replace:
return QCoreApplication::translate( context, "<strong>Replace</strong> a partition on disk <strong>%2</strong> (%3) with %1." ) return QCoreApplication::translate(
context, "<strong>Replace</strong> a partition on disk <strong>%2</strong> (%3) with %1." )
.arg( branding->shortVersionedName() ) .arg( branding->shortVersionedName() )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
case Config::NoChoice: case Config::NoChoice:
case Config::Manual: case Config::Manual:
return QCoreApplication::translate( context, "<strong>Manual</strong> partitioning on disk <strong>%1</strong> (%2)." ) return QCoreApplication::translate(
context, "<strong>Manual</strong> partitioning on disk <strong>%1</strong> (%2)." )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
} }
@ -201,7 +211,9 @@ static QString diskDescription( int listLength, const PartitionCoreModule::Summa
} }
else // multiple disk previews! else // multiple disk previews!
{ {
return QCoreApplication::translate( context, "Disk <strong>%1</strong> (%2)" ).arg( info.deviceNode ).arg( info.deviceName ) ; return QCoreApplication::translate( context, "Disk <strong>%1</strong> (%2)" )
.arg( info.deviceNode )
.arg( info.deviceName );
} }
} }
@ -216,7 +228,7 @@ PartitionViewStep::prettyStatus() const
cDebug() << "Summary for Partition" << list.length() << choice; cDebug() << "Summary for Partition" << list.length() << choice;
if ( list.length() > 1 ) // There are changes on more than one disk if ( list.length() > 1 ) // There are changes on more than one disk
{ {
modeText = modeDescription(choice); modeText = modeDescription( choice );
} }
for ( const auto& info : list ) for ( const auto& info : list )
@ -501,7 +513,7 @@ PartitionViewStep::onLeave()
#else #else
PartitionTable::FlagEsp PartitionTable::FlagEsp
#endif #endif
); );
Partition* esp = m_core->findPartitionByMountPoint( espMountPoint ); Partition* esp = m_core->findPartitionByMountPoint( espMountPoint );
QString message; QString message;
@ -644,8 +656,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
QFuture< void > future = QtConcurrent::run( this, &PartitionViewStep::initPartitionCoreModule ); QFuture< void > future = QtConcurrent::run( this, &PartitionViewStep::initPartitionCoreModule );
m_future->setFuture( future ); m_future->setFuture( future );
m_core->initLayout( m_config->defaultFsType(), m_core->initLayout( m_config->defaultFsType(), configurationMap.value( "partitionLayout" ).toList() );
configurationMap.value( "partitionLayout" ).toList() );
} }

View File

@ -447,31 +447,31 @@ isEfiSystem()
} }
bool bool
isEfiFilesystemSuitable(const Partition* candidate) isEfiFilesystemSuitable( const Partition* candidate )
{ {
auto type = candidate->fileSystem().type(); auto type = candidate->fileSystem().type();
auto size = candidate->capacity(); // bytes auto size = candidate->capacity(); // bytes
using CalamaresUtils::Units::operator""_MiB; using CalamaresUtils::Units::operator""_MiB;
switch( type ) switch ( type )
{ {
case FileSystem::Type::Fat32: case FileSystem::Type::Fat32:
if ( size >= 300_MiB ) if ( size >= 300_MiB )
{ {
return true; return true;
} }
cWarning() << "FAT32 filesystem is too small (" << size << "bytes)"; cWarning() << "FAT32 filesystem is too small (" << size << "bytes)";
return false; return false;
#ifdef WITH_KPMCORE4API #ifdef WITH_KPMCORE4API
case FileSystem::Type::Fat12: case FileSystem::Type::Fat12:
#endif #endif
case FileSystem::Type::Fat16: case FileSystem::Type::Fat16:
cWarning() << "FAT12 and FAT16 are probably not supported by EFI"; cWarning() << "FAT12 and FAT16 are probably not supported by EFI";
return false; return false;
default: default:
cWarning() << "EFI boot partition must be FAT32"; cWarning() << "EFI boot partition must be FAT32";
return false; return false;
} }
} }

View File

@ -138,61 +138,63 @@ PartitionLayout::init( FileSystem::Type defaultFsType, const QVariantList& confi
} }
void void
PartitionLayout::setDefaultFsType(FileSystem::Type defaultFsType) PartitionLayout::setDefaultFsType( FileSystem::Type defaultFsType )
{ {
using FileSystem = FileSystem::Type; using FileSystem = FileSystem::Type;
switch ( defaultFsType ) switch ( defaultFsType )
{ {
case FileSystem::Unknown: case FileSystem::Unknown:
case FileSystem::Unformatted: case FileSystem::Unformatted:
case FileSystem::Extended: case FileSystem::Extended:
case FileSystem::LinuxSwap: case FileSystem::LinuxSwap:
case FileSystem::Luks: case FileSystem::Luks:
case FileSystem::Ocfs2: case FileSystem::Ocfs2:
case FileSystem::Lvm2_PV: case FileSystem::Lvm2_PV:
case FileSystem::Udf: case FileSystem::Udf:
case FileSystem::Iso9660: case FileSystem::Iso9660:
#ifdef WITH_KPMCORE4API #ifdef WITH_KPMCORE4API
case FileSystem::Luks2: case FileSystem::Luks2:
case FileSystem::LinuxRaidMember: case FileSystem::LinuxRaidMember:
case FileSystem::BitLocker: case FileSystem::BitLocker:
#endif #endif
// bad bad // bad bad
cWarning() << "The selected default FS" << defaultFsType << "is not suitable." << "Using ext4 instead."; cWarning() << "The selected default FS" << defaultFsType << "is not suitable."
defaultFsType = FileSystem::Ext4; << "Using ext4 instead.";
break; defaultFsType = FileSystem::Ext4;
case FileSystem::Ext2: break;
case FileSystem::Ext3: case FileSystem::Ext2:
case FileSystem::Ext4: case FileSystem::Ext3:
case FileSystem::Fat32: case FileSystem::Ext4:
case FileSystem::Ntfs: case FileSystem::Fat32:
case FileSystem::Reiser4: case FileSystem::Ntfs:
case FileSystem::ReiserFS: case FileSystem::Reiser4:
case FileSystem::Xfs: case FileSystem::ReiserFS:
case FileSystem::Jfs: case FileSystem::Xfs:
case FileSystem::Btrfs: case FileSystem::Jfs:
case FileSystem::Exfat: case FileSystem::Btrfs:
case FileSystem::F2fs: case FileSystem::Exfat:
// ok case FileSystem::F2fs:
break; // ok
case FileSystem::Fat16: break;
case FileSystem::Hfs: case FileSystem::Fat16:
case FileSystem::HfsPlus: case FileSystem::Hfs:
case FileSystem::Ufs: case FileSystem::HfsPlus:
case FileSystem::Hpfs: case FileSystem::Ufs:
case FileSystem::Zfs: case FileSystem::Hpfs:
case FileSystem::Nilfs2: case FileSystem::Zfs:
case FileSystem::Nilfs2:
#ifdef WITH_KPMCORE4API #ifdef WITH_KPMCORE4API
case FileSystem::Fat12: case FileSystem::Fat12:
case FileSystem::Apfs: case FileSystem::Apfs:
case FileSystem::Minix: case FileSystem::Minix:
#endif #endif
// weird // weird
cWarning() << "The selected default FS" << defaultFsType << "is unusual, but not wrong."; cWarning() << "The selected default FS" << defaultFsType << "is unusual, but not wrong.";
break; break;
default: default:
cWarning() << "The selected default FS" << defaultFsType << "is not known to Calamares." << "Using ext4 instead."; cWarning() << "The selected default FS" << defaultFsType << "is not known to Calamares."
defaultFsType = FileSystem::Ext4; << "Using ext4 instead.";
defaultFsType = FileSystem::Ext4;
} }
m_defaultFsType = defaultFsType; m_defaultFsType = defaultFsType;
@ -278,7 +280,7 @@ PartitionLayout::createPartitions( Device* dev,
} }
} }
auto correctFS = [d=m_defaultFsType]( FileSystem::Type t ) { return t == FileSystem::Type::Unknown ? d : t; }; auto correctFS = [d = m_defaultFsType]( FileSystem::Type t ) { return t == FileSystem::Type::Unknown ? d : t; };
// Create the partitions. // Create the partitions.
currentSector = firstSector; currentSector = firstSector;

View File

@ -270,11 +270,12 @@ ChoicePage::setupChoices()
m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox );
} }
if ( m_config->eraseFsTypes().count() > 1) if ( m_config->eraseFsTypes().count() > 1 )
{ {
m_eraseFsTypesChoiceComboBox = new QComboBox; m_eraseFsTypesChoiceComboBox = new QComboBox;
m_eraseFsTypesChoiceComboBox->addItems(m_config->eraseFsTypes()); m_eraseFsTypesChoiceComboBox->addItems( m_config->eraseFsTypes() );
connect( m_eraseFsTypesChoiceComboBox, &QComboBox::currentTextChanged, m_config, &Config::setEraseFsTypeChoice ); connect(
m_eraseFsTypesChoiceComboBox, &QComboBox::currentTextChanged, m_config, &Config::setEraseFsTypeChoice );
connect( m_config, &Config::eraseModeFilesystemChanged, this, &ChoicePage::onActionChanged ); connect( m_config, &Config::eraseModeFilesystemChanged, this, &ChoicePage::onActionChanged );
m_eraseButton->addOptionsComboBox( m_eraseFsTypesChoiceComboBox ); m_eraseButton->addOptionsComboBox( m_eraseFsTypesChoiceComboBox );
} }