[partition] Move required partition table type to Config

- remove from GS
- remove duplication across Config and ChoicePage
- improve translations (presumably "msdos or gpt" is the most
  complicated it will get)

FIXES #1735
This commit is contained in:
Adriaan de Groot 2021-11-09 12:24:51 +01:00
parent f62198e250
commit 575654941f
4 changed files with 54 additions and 19 deletions

View File

@ -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 );
}

View File

@ -12,6 +12,7 @@
#include "utils/NamedEnum.h"
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
#include <QObject>
@ -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 );

View File

@ -42,7 +42,6 @@
#include "widgets/PrettyRadioButton.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#ifdef WITH_KPMCORE4API
#include <kpmcore/core/softwareraid.h>
#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 <strong>%1</strong> is different from the "
"needed <strong>%2</strong>.<br/>" )
.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:

View File

@ -159,7 +159,6 @@ private:
int m_lastSelectedDeviceIndex = -1;
int m_lastSelectedActionIndex = -1;
QStringList m_requiredPartitionTableType;
bool m_enableEncryptionWidget;
QMutex m_coreMutex;