diff --git a/src/modules/partition/Config.cpp b/src/modules/partition/Config.cpp index 05975213e..155622570 100644 --- a/src/modules/partition/Config.cpp +++ b/src/modules/partition/Config.cpp @@ -221,6 +221,14 @@ Config::setEraseFsTypeChoice( const QString& choice ) } } +bool +Config::acceptPartitionTableType( PartitionTable::TableType tableType ) const +{ + return m_requiredPartitionTableType.empty() + || m_requiredPartitionTableType.contains( PartitionTable::tableTypeToName( tableType ) ); +} + + static void fillGSConfigurationEFI( Calamares::GlobalStorage* gs, const QVariantMap& configurationMap ) { @@ -235,18 +243,18 @@ fillGSConfigurationEFI( Calamares::GlobalStorage* gs, const QVariantMap& configu if ( configurationMap.contains( "efiSystemPartitionSize" ) ) { const QString sizeString = CalamaresUtils::getString( configurationMap, "efiSystemPartitionSize" ); - CalamaresUtils::Partition::PartitionSize part_size - = CalamaresUtils::Partition::PartitionSize( sizeString ); - if (part_size.isValid()) + CalamaresUtils::Partition::PartitionSize part_size = CalamaresUtils::Partition::PartitionSize( sizeString ); + if ( part_size.isValid() ) { // Insert once as string, once as a size-in-bytes; // changes to these keys should be synchronized with PartUtils.cpp - gs->insert( "efiSystemPartitionSize", sizeString ); - gs->insert( "efiSystemPartitionSize_i", part_size.toBytes()); + gs->insert( "efiSystemPartitionSize", sizeString ); + gs->insert( "efiSystemPartitionSize_i", part_size.toBytes() ); - if (part_size.toBytes() != PartUtils::efiFilesystemMinimumSize()) + if ( part_size.toBytes() != PartUtils::efiFilesystemMinimumSize() ) { - cWarning() << "EFI partition size" << sizeString << "has been adjusted to" << PartUtils::efiFilesystemMinimumSize() << "bytes"; + cWarning() << "EFI partition size" << sizeString << "has been adjusted to" + << PartUtils::efiFilesystemMinimumSize() << "bytes"; } } else @@ -342,11 +350,9 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) setSwapChoice( m_initialSwapChoice ); m_allowManualPartitioning = CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ); + m_requiredPartitionTableType = CalamaresUtils::getStringList( configurationMap, "requiredPartitionTableType" ); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - m_requiredPartitionTableType = CalamaresUtils::getStringList( configurationMap, "requiredPartitionTableType" ); - gs->insert( "requiredPartitionTableType", m_requiredPartitionTableType ); - fillGSConfigurationEFI( gs, configurationMap ); fillConfigurationFSTypes( configurationMap ); } diff --git a/src/modules/partition/Config.h b/src/modules/partition/Config.h index 5f7e46821..2ac44b424 100644 --- a/src/modules/partition/Config.h +++ b/src/modules/partition/Config.h @@ -12,6 +12,7 @@ #include "utils/NamedEnum.h" +#include #include #include @@ -127,9 +128,18 @@ public: */ FileSystem::Type defaultFsType() const { return m_defaultFsType; } - ///@brief Is manual partitioning allowed (not explicitly disabled in the config file)? + /// @brief Is manual partitioning allowed (not explicitly disabled in the config file)? bool allowManualPartitioning() const { return m_allowManualPartitioning; } + /** @brief Will @p tableType be ok? + * + * If no required types are specified, it's ok, otherwise the + * type must be named in the list of required types. + */ + bool acceptPartitionTableType( PartitionTable::TableType tableType ) const; + /// @brief Returns list of acceptable types. May be empty. + QStringList partitionTableTypes() const { return m_requiredPartitionTableType; } + public Q_SLOTS: void setInstallChoice( int ); ///< Translates a button ID or so to InstallChoice void setInstallChoice( InstallChoice ); diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 5f3832fa0..9226eb3b6 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -42,7 +42,6 @@ #include "widgets/PrettyRadioButton.h" #include -#include #ifdef WITH_KPMCORE4API #include #endif @@ -90,7 +89,6 @@ ChoicePage::ChoicePage( Config* config, QWidget* parent ) auto gs = Calamares::JobQueue::instance()->globalStorage(); - m_requiredPartitionTableType = gs->value( "requiredPartitionTableType" ).toStringList(); m_enableEncryptionWidget = gs->value( "enableLuksAutomatedPartitioning" ).toBool(); // Set up drives combo @@ -1252,6 +1250,28 @@ operator<<( QDebug& s, PartitionIterator& it ) return s; } +QString +describePartitionTypes( const QStringList& types ) +{ + if ( types.empty() ) + { + return QCoreApplication::translate( + ChoicePage::staticMetaObject.className(), "any", "any partition-table type" ); + } + if ( types.size() == 1 ) + { + return types.first(); + } + if ( types.size() == 2 ) + { + return QCoreApplication::translate( + ChoicePage::staticMetaObject.className(), "%1 or %2", "partition-table types" ) + .arg( types.at( 0 ), types.at( 1 ) ); + } + // More than two, rather unlikely + return types.join( ", " ); +} + /** * @brief ChoicePage::setupActions happens every time a new Device* is selected in the * device picker. Sets up the text and visibility of the partitioning actions based @@ -1305,8 +1325,7 @@ ChoicePage::setupActions() if ( currentDevice->partitionTable() ) { tableType = currentDevice->partitionTable()->type(); - matchTableType = m_requiredPartitionTableType.size() == 0 - || m_requiredPartitionTableType.contains( PartitionTable::tableTypeToName( tableType ) ); + matchTableType = m_config->acceptPartitionTableType( tableType ); } for ( auto it = PartitionIterator::begin( currentDevice ); it != PartitionIterator::end( currentDevice ); ++it ) @@ -1487,11 +1506,11 @@ ChoicePage::setupActions() "but the partition table %1 is different from the " "needed %2.
" ) .arg( PartitionTable::tableTypeToName( tableType ) ) - .arg( m_requiredPartitionTableType.join( " or " ) ) ); + .arg( describePartitionTypes( m_config->partitionTableTypes() ) ) ); m_messageLabel->show(); cWarning() << "Partition table" << PartitionTable::tableTypeToName( tableType ) - << "does not match the requirement " << m_requiredPartitionTableType.join( " or " ) + << "does not match the requirement " << m_config->partitionTableTypes().join( ',' ) << ", ENABLING erase feature and DISABLING alongside, replace and manual features."; m_eraseButton->show(); m_alongsideButton->hide(); @@ -1642,7 +1661,8 @@ ChoicePage::updateSwapChoicesTr() } else { - cWarning() << "Box item" << index << m_eraseSwapChoiceComboBox->itemText( index ) << "has non-integer role."; + cWarning() << "Box item" << index << m_eraseSwapChoiceComboBox->itemText( index ) + << "has non-integer role."; } break; case SwapChoice::ReuseSwap: diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 3892b4a23..12222ac63 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -159,7 +159,6 @@ private: int m_lastSelectedDeviceIndex = -1; int m_lastSelectedActionIndex = -1; - QStringList m_requiredPartitionTableType; bool m_enableEncryptionWidget; QMutex m_coreMutex;