[partition] Move 'selected installation option' to Config

This commit is contained in:
Adriaan de Groot 2020-09-29 14:00:49 +02:00
parent 10d194d693
commit b41e4624c9
5 changed files with 84 additions and 44 deletions

View File

@ -106,6 +106,29 @@ getSwapChoices( const QVariantMap& configurationMap )
return choices;
}
void
Config::setInstallChoice( int c )
{
if ( ( c < PartitionActions::Choices::InstallChoice::NoChoice )
|| ( c > PartitionActions::Choices::InstallChoice::Manual ) )
{
cWarning() << "Invalid install choice (int)" << c;
c = PartitionActions::Choices::InstallChoice::NoChoice;
}
setInstallChoice( static_cast< PartitionActions::Choices::InstallChoice >( c ) );
}
void
Config::setInstallChoice( PartitionActions::Choices::InstallChoice c )
{
if ( c != m_installChoice )
{
m_installChoice = c;
emit installChoiceChanged( c );
}
}
void
Config::setConfigurationMap( const QVariantMap& configurationMap )
{
@ -116,6 +139,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
bool nameFound = false; // In the name table (ignored, falls back to first entry in table)
m_initialInstallChoice = PartitionActions::Choices::installChoiceNames().find(
CalamaresUtils::getString( configurationMap, "initialPartitioningChoice" ), nameFound );
setInstallChoice( m_initialInstallChoice );
m_initialSwapChoice = PartitionActions::Choices::swapChoiceNames().find(
CalamaresUtils::getString( configurationMap, "initialSwapChoice" ), nameFound );
if ( !m_swapChoices.contains( m_initialSwapChoice ) )

View File

@ -23,6 +23,13 @@ public:
Config( QObject* parent );
virtual ~Config() = default;
/** @brief The installation choice (Erase, Alongside, ...)
*
* This is an int because exposing the enum values is slightly complicated
* by the source layout.
*/
Q_PROPERTY( int installChoice READ installChoice WRITE setInstallChoice NOTIFY installChoiceChanged )
void setConfigurationMap( const QVariantMap& );
void updateGlobalStorage() const;
@ -34,16 +41,34 @@ public:
*/
PartitionActions::Choices::InstallChoice initialInstallChoice() const { return m_initialInstallChoice; }
/** @brief What kind of installation (partition) is requested **now**?
*
* This changes depending on what the user selects (unlike the initial choice,
* which is fixed by the configuration).
*
* @return the partitioning choice (may be @c NoChoice)
*/
PartitionActions::Choices::InstallChoice installChoice() const { return m_installChoice; }
/** @brief What kind of swap selection is requested **initially**?
*
* @return The swap choice (may be @c NoSwap )
*/
PartitionActions::Choices::SwapChoice initialSwapChoice() const { return m_initialSwapChoice; }
public Q_SLOTS:
void setInstallChoice( int );
void setInstallChoice( PartitionActions::Choices::InstallChoice );
Q_SIGNALS:
void installChoiceChanged( PartitionActions::Choices::InstallChoice );
private:
PartitionActions::Choices::SwapChoice m_initialSwapChoice;
PartitionActions::Choices::SwapChoiceSet m_swapChoices;
PartitionActions::Choices::InstallChoice m_initialInstallChoice = PartitionActions::Choices::NoChoice;
PartitionActions::Choices::InstallChoice m_installChoice = PartitionActions::Choices::NoChoice;
qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module
};

View File

@ -71,7 +71,6 @@ ChoicePage::ChoicePage( Config* config, QWidget* parent )
, m_config( config )
, m_nextEnabled( false )
, m_core( nullptr )
, m_choice( InstallChoice::NoChoice )
, m_isEfi( false )
, m_grp( nullptr )
, m_alongsideButton( nullptr )
@ -277,7 +276,7 @@ ChoicePage::setupChoices()
connect( m_grp, buttonSignal, this, [ this ]( int id, bool checked ) {
if ( checked ) // An action was picked.
{
m_choice = static_cast< InstallChoice >( id );
m_config->setInstallChoice( id );
updateNextEnabled();
emit actionChosen();
@ -287,7 +286,7 @@ ChoicePage::setupChoices()
if ( m_grp->checkedButton() == nullptr ) // If no other action is chosen, we must
{
// set m_choice to NoChoice and reset previews.
m_choice = InstallChoice::NoChoice;
m_config->setInstallChoice( InstallChoice::NoChoice );
updateNextEnabled();
emit actionChosen();
@ -344,7 +343,7 @@ ChoicePage::checkInstallChoiceRadioButton( InstallChoice c )
QSignalBlocker b( m_grp );
m_grp->setExclusive( false );
// If c == InstallChoice::NoChoice none will match and all are deselected
m_eraseButton->setChecked( InstallChoice::Erase == c);
m_eraseButton->setChecked( InstallChoice::Erase == c );
m_replaceButton->setChecked( InstallChoice::Replace == c );
m_alongsideButton->setChecked( InstallChoice::Alongside == c );
m_somethingElseButton->setChecked( InstallChoice::Manual == c );
@ -409,8 +408,8 @@ ChoicePage::continueApplyDeviceChoice()
{
m_lastSelectedDeviceIndex = m_drivesCombo->currentIndex();
m_lastSelectedActionIndex = -1;
m_choice = m_config->initialInstallChoice();
checkInstallChoiceRadioButton( m_choice );
m_config->setInstallChoice( m_config->initialInstallChoice() );
checkInstallChoiceRadioButton( m_config->installChoice() );
}
emit actionChosen();
@ -424,7 +423,7 @@ ChoicePage::onActionChanged()
Device* currd = selectedDevice();
if ( currd )
{
applyActionChoice( currentChoice() );
applyActionChoice( m_config->installChoice() );
}
}
@ -512,7 +511,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
[ this ] {
// We need to reupdate after reverting because the splitter widget is
// not a true view.
updateActionChoicePreview( currentChoice() );
updateActionChoicePreview( m_config->installChoice() );
updateNextEnabled();
},
this );
@ -585,14 +584,14 @@ void
ChoicePage::onEncryptWidgetStateChanged()
{
EncryptWidget::Encryption state = m_encryptWidget->state();
if ( m_choice == InstallChoice::Erase )
if ( m_config->installChoice() == InstallChoice::Erase )
{
if ( state == EncryptWidget::Encryption::Confirmed || state == EncryptWidget::Encryption::Disabled )
{
applyActionChoice( m_choice );
applyActionChoice( m_config->installChoice() );
}
}
else if ( m_choice == InstallChoice::Replace )
else if ( m_config->installChoice() == InstallChoice::Replace )
{
if ( m_beforePartitionBarsView && m_beforePartitionBarsView->selectionModel()->currentIndex().isValid()
&& ( state == EncryptWidget::Encryption::Confirmed || state == EncryptWidget::Encryption::Disabled ) )
@ -607,7 +606,7 @@ ChoicePage::onEncryptWidgetStateChanged()
void
ChoicePage::onHomeCheckBoxStateChanged()
{
if ( currentChoice() == InstallChoice::Replace
if ( m_config->installChoice() == InstallChoice::Replace
&& m_beforePartitionBarsView->selectionModel()->currentIndex().isValid() )
{
doReplaceSelectedPartition( m_beforePartitionBarsView->selectionModel()->currentIndex() );
@ -618,12 +617,14 @@ ChoicePage::onHomeCheckBoxStateChanged()
void
ChoicePage::onLeave()
{
if ( m_choice == InstallChoice::Alongside )
if ( m_config->installChoice() == InstallChoice::Alongside )
{
doAlongsideApply();
}
if ( m_isEfi && ( m_choice == InstallChoice::Alongside || m_choice == InstallChoice::Replace ) )
if ( m_isEfi
&& ( m_config->installChoice() == InstallChoice::Alongside
|| m_config->installChoice() == InstallChoice::Replace ) )
{
QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions();
if ( efiSystemPartitions.count() == 1 )
@ -899,7 +900,7 @@ ChoicePage::updateDeviceStatePreview()
sm->deleteLater();
}
switch ( m_choice )
switch ( m_config->installChoice() )
{
case InstallChoice::Replace:
case InstallChoice::Alongside:
@ -1073,7 +1074,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
m_previewAfterFrame->show();
m_previewAfterLabel->show();
if ( m_choice == InstallChoice::Erase )
if ( m_config->installChoice() == InstallChoice::Erase )
{
m_selectLabel->hide();
}
@ -1102,7 +1103,9 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
break;
}
if ( m_isEfi && ( m_choice == InstallChoice::Alongside || m_choice == InstallChoice::Replace ) )
if ( m_isEfi
&& ( m_config->installChoice() == InstallChoice::Alongside
|| m_config->installChoice() == InstallChoice::Replace ) )
{
QHBoxLayout* efiLayout = new QHBoxLayout;
layout->addLayout( efiLayout );
@ -1117,7 +1120,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
// Also handle selection behavior on beforeFrame.
QAbstractItemView::SelectionMode previewSelectionMode;
switch ( m_choice )
switch ( m_config->installChoice() )
{
case InstallChoice::Replace:
case InstallChoice::Alongside:
@ -1457,19 +1460,13 @@ ChoicePage::isNextEnabled() const
}
ChoicePage::InstallChoice
ChoicePage::currentChoice() const
{
return m_choice;
}
bool
ChoicePage::calculateNextEnabled() const
{
bool enabled = false;
auto sm_p = m_beforePartitionBarsView ? m_beforePartitionBarsView->selectionModel() : nullptr;
switch ( m_choice )
switch ( m_config->installChoice() )
{
case InstallChoice::NoChoice:
cDebug() << "No partitioning choice";
@ -1495,7 +1492,9 @@ ChoicePage::calculateNextEnabled() const
}
if ( m_isEfi && ( m_choice == InstallChoice::Alongside || m_choice == InstallChoice::Replace ) )
if ( m_isEfi
&& ( m_config->installChoice() == InstallChoice::Alongside
|| m_config->installChoice() == InstallChoice::Replace ) )
{
if ( m_core->efiSystemPartitions().count() == 0 )
{
@ -1504,7 +1503,7 @@ ChoicePage::calculateNextEnabled() const
}
}
if ( m_choice != InstallChoice::Manual && m_encryptWidget->isVisible() )
if ( m_config->installChoice() != InstallChoice::Manual && m_encryptWidget->isVisible() )
{
switch ( m_encryptWidget->state() )
{

View File

@ -72,13 +72,6 @@ public:
*/
bool isNextEnabled() const;
/**
* @brief currentChoice returns the enum Choice value corresponding to the
* currently selected partitioning mode (with a PrettyRadioButton).
* @return the enum Choice value.
*/
InstallChoice currentChoice() const;
/**
* @brief onLeave runs when control passes from this page to another one.
*/
@ -139,8 +132,6 @@ private:
QMutex m_previewsMutex;
InstallChoice m_choice;
bool m_isEfi;
QComboBox* m_drivesCombo;

View File

@ -140,7 +140,7 @@ PartitionViewStep::createSummaryWidget() const
widget->setLayout( mainLayout );
mainLayout->setMargin( 0 );
ChoicePage::InstallChoice choice = m_choicePage->currentChoice();
ChoicePage::InstallChoice choice = m_config->installChoice();
QFormLayout* formLayout = new QFormLayout( widget );
const int MARGIN = CalamaresUtils::defaultFontHeight() / 2;
@ -286,7 +286,7 @@ PartitionViewStep::next()
{
if ( m_choicePage == m_widget->currentWidget() )
{
if ( m_choicePage->currentChoice() == ChoicePage::InstallChoice::Manual )
if ( m_config->installChoice() == ChoicePage::InstallChoice::Manual )
{
if ( !m_manualPartitionPage )
{
@ -301,7 +301,7 @@ PartitionViewStep::next()
m_manualPartitionPage->onRevertClicked();
}
}
cDebug() << "Choice applied: " << m_choicePage->currentChoice();
cDebug() << "Choice applied: " << m_config->installChoice();
}
}
@ -368,9 +368,9 @@ PartitionViewStep::isAtEnd() const
{
if ( m_widget->currentWidget() == m_choicePage )
{
if ( m_choicePage->currentChoice() == ChoicePage::InstallChoice::Erase
|| m_choicePage->currentChoice() == ChoicePage::InstallChoice::Replace
|| m_choicePage->currentChoice() == ChoicePage::InstallChoice::Alongside )
auto choice = m_config->installChoice();
if ( ChoicePage::InstallChoice::Erase == choice || ChoicePage::InstallChoice::Replace == choice
|| ChoicePage::InstallChoice::Alongside == choice )
{
return true;
}
@ -387,7 +387,7 @@ PartitionViewStep::onActivate()
// if we're coming back to PVS from the next VS
if ( m_widget->currentWidget() == m_choicePage
&& m_choicePage->currentChoice() == ChoicePage::InstallChoice::Alongside )
&& m_config->installChoice() == ChoicePage::InstallChoice::Alongside )
{
m_choicePage->applyActionChoice( ChoicePage::InstallChoice::Alongside );
// m_choicePage->reset();
@ -582,7 +582,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
// because it could take a while. Then when it's done, we can set up the widgets
// and remove the spinner.
m_future = new QFutureWatcher< void >();
connect( m_future, &QFutureWatcher< void >::finished, this, [this] {
connect( m_future, &QFutureWatcher< void >::finished, this, [ this ] {
continueLoading();
this->m_future->deleteLater();
this->m_future = nullptr;