[partition] set the right buttons if an action is pre-selected

This commit is contained in:
Adriaan de Groot 2020-09-28 17:46:42 +02:00
parent b518ef7dfe
commit a92cb32cef
2 changed files with 62 additions and 20 deletions

View File

@ -83,7 +83,6 @@ ChoicePage::ChoicePage( Config* config, QWidget* parent )
, m_beforePartitionBarsView( nullptr ) , m_beforePartitionBarsView( nullptr )
, m_beforePartitionLabelsView( nullptr ) , m_beforePartitionLabelsView( nullptr )
, m_bootloaderComboBox( nullptr ) , m_bootloaderComboBox( nullptr )
, m_lastSelectedDeviceIndex( -1 )
, m_enableEncryptionWidget( true ) , m_enableEncryptionWidget( true )
, m_availableSwapChoices( config->swapChoices() ) , m_availableSwapChoices( config->swapChoices() )
, m_eraseSwapChoice( config->initialSwapChoice() ) , m_eraseSwapChoice( config->initialSwapChoice() )
@ -154,7 +153,7 @@ ChoicePage::init( PartitionCoreModule* core )
// We need to do this because a PCM revert invalidates the deviceModel. // We need to do this because a PCM revert invalidates the deviceModel.
connect( core, &PartitionCoreModule::reverted, this, [=] { connect( core, &PartitionCoreModule::reverted, this, [ = ] {
m_drivesCombo->setModel( core->deviceModel() ); m_drivesCombo->setModel( core->deviceModel() );
m_drivesCombo->setCurrentIndex( m_lastSelectedDeviceIndex ); m_drivesCombo->setCurrentIndex( m_lastSelectedDeviceIndex );
} ); } );
@ -275,7 +274,7 @@ ChoicePage::setupChoices()
#else #else
auto buttonSignal = &QButtonGroup::idToggled; auto buttonSignal = &QButtonGroup::idToggled;
#endif #endif
connect( m_grp, buttonSignal, this, [this]( int id, bool checked ) { connect( m_grp, buttonSignal, this, [ this ]( int id, bool checked ) {
if ( checked ) // An action was picked. if ( checked ) // An action was picked.
{ {
m_choice = static_cast< InstallChoice >( id ); m_choice = static_cast< InstallChoice >( id );
@ -339,6 +338,38 @@ ChoicePage::hideButtons()
m_somethingElseButton->hide(); m_somethingElseButton->hide();
} }
void
ChoicePage::checkInstallChoiceRadioButton( InstallChoice c )
{
QSignalBlocker b( m_grp );
PrettyRadioButton* button = nullptr;
switch ( c )
{
case InstallChoice::Alongside:
button = m_alongsideButton;
break;
case InstallChoice::Replace:
button = m_replaceButton;
break;
case InstallChoice::Erase:
button = m_eraseButton;
break;
case InstallChoice::Manual:
button = m_somethingElseButton;
break;
case InstallChoice::NoChoice:
// Nothing
;
}
m_grp->setExclusive( false );
m_eraseButton->setChecked( button == m_eraseButton );
m_replaceButton->setChecked( button == m_replaceButton );
m_alongsideButton->setChecked( button == m_alongsideButton );
m_somethingElseButton->setChecked( button == m_somethingElseButton );
m_grp->setExclusive( true );
}
/** /**
* @brief ChoicePage::applyDeviceChoice handler for the selected event of the device * @brief ChoicePage::applyDeviceChoice handler for the selected event of the device
@ -359,11 +390,11 @@ ChoicePage::applyDeviceChoice()
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{ {
ScanningDialog::run( ScanningDialog::run(
QtConcurrent::run( [=] { QtConcurrent::run( [ = ] {
QMutexLocker locker( &m_coreMutex ); QMutexLocker locker( &m_coreMutex );
m_core->revertAllDevices(); m_core->revertAllDevices();
} ), } ),
[this] { continueApplyDeviceChoice(); }, [ this ] { continueApplyDeviceChoice(); },
this ); this );
} }
else else
@ -392,7 +423,14 @@ ChoicePage::continueApplyDeviceChoice()
// Preview setup done. Now we show/hide choices as needed. // Preview setup done. Now we show/hide choices as needed.
setupActions(); setupActions();
m_lastSelectedDeviceIndex = m_drivesCombo->currentIndex(); cDebug() << "Previous device" << m_lastSelectedDeviceIndex << "new device" << m_drivesCombo->currentIndex();
if ( m_lastSelectedDeviceIndex != m_drivesCombo->currentIndex() )
{
m_lastSelectedDeviceIndex = m_drivesCombo->currentIndex();
m_lastSelectedActionIndex = -1;
m_choice = m_config->initialInstallChoice();
checkInstallChoiceRadioButton( m_choice );
}
emit actionChosen(); emit actionChosen();
emit deviceChosen(); emit deviceChosen();
@ -423,6 +461,8 @@ ChoicePage::onEraseSwapChoiceChanged()
void void
ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
{ {
cDebug() << "Prev" << m_lastSelectedActionIndex << "InstallChoice" << choice
<< PartitionActions::Choices::installChoiceNames().find( choice );
m_beforePartitionBarsView->selectionModel()->disconnect( SIGNAL( currentRowChanged( QModelIndex, QModelIndex ) ) ); m_beforePartitionBarsView->selectionModel()->disconnect( SIGNAL( currentRowChanged( QModelIndex, QModelIndex ) ) );
m_beforePartitionBarsView->selectionModel()->clearSelection(); m_beforePartitionBarsView->selectionModel()->clearSelection();
m_beforePartitionBarsView->selectionModel()->clearCurrentIndex(); m_beforePartitionBarsView->selectionModel()->clearCurrentIndex();
@ -443,11 +483,11 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{ {
ScanningDialog::run( ScanningDialog::run(
QtConcurrent::run( [=] { QtConcurrent::run( [ = ] {
QMutexLocker locker( &m_coreMutex ); QMutexLocker locker( &m_coreMutex );
m_core->revertDevice( selectedDevice() ); m_core->revertDevice( selectedDevice() );
} ), } ),
[=] { [ = ] {
PartitionActions::doAutopartition( m_core, selectedDevice(), options ); PartitionActions::doAutopartition( m_core, selectedDevice(), options );
emit deviceChosen(); emit deviceChosen();
}, },
@ -464,7 +504,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{ {
ScanningDialog::run( ScanningDialog::run(
QtConcurrent::run( [=] { QtConcurrent::run( [ = ] {
QMutexLocker locker( &m_coreMutex ); QMutexLocker locker( &m_coreMutex );
m_core->revertDevice( selectedDevice() ); m_core->revertDevice( selectedDevice() );
} ), } ),
@ -484,11 +524,11 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{ {
ScanningDialog::run( ScanningDialog::run(
QtConcurrent::run( [=] { QtConcurrent::run( [ = ] {
QMutexLocker locker( &m_coreMutex ); QMutexLocker locker( &m_coreMutex );
m_core->revertDevice( selectedDevice() ); m_core->revertDevice( selectedDevice() );
} ), } ),
[this] { [ this ] {
// We need to reupdate after reverting because the splitter widget is // We need to reupdate after reverting because the splitter widget is
// not a true view. // not a true view.
updateActionChoicePreview( currentChoice() ); updateActionChoicePreview( currentChoice() );
@ -724,7 +764,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
// doReuseHomePartition *after* the device revert, for later use. // doReuseHomePartition *after* the device revert, for later use.
ScanningDialog::run( ScanningDialog::run(
QtConcurrent::run( QtConcurrent::run(
[this, current]( QString* homePartitionPath, bool doReuseHomePartition ) { [ this, current ]( QString* homePartitionPath, bool doReuseHomePartition ) {
QMutexLocker locker( &m_coreMutex ); QMutexLocker locker( &m_coreMutex );
if ( m_core->isDirty() ) if ( m_core->isDirty() )
@ -805,7 +845,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
}, },
homePartitionPath, homePartitionPath,
doReuseHomePartition ), doReuseHomePartition ),
[=] { [ = ] {
m_reuseHomeCheckBox->setVisible( !homePartitionPath->isEmpty() ); m_reuseHomeCheckBox->setVisible( !homePartitionPath->isEmpty() );
if ( !homePartitionPath->isEmpty() ) if ( !homePartitionPath->isEmpty() )
m_reuseHomeCheckBox->setText( tr( "Reuse %1 as home partition for %2." ) m_reuseHomeCheckBox->setText( tr( "Reuse %1 as home partition for %2." )
@ -955,7 +995,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
connect( m_afterPartitionSplitterWidget, connect( m_afterPartitionSplitterWidget,
&PartitionSplitterWidget::partitionResized, &PartitionSplitterWidget::partitionResized,
this, this,
[this, sizeLabel]( const QString& path, qint64 size, qint64 sizeNext ) { [ this, sizeLabel ]( const QString& path, qint64 size, qint64 sizeNext ) {
Q_UNUSED( path ) Q_UNUSED( path )
sizeLabel->setText( sizeLabel->setText(
tr( "%1 will be shrunk to %2MiB and a new " tr( "%1 will be shrunk to %2MiB and a new "
@ -969,7 +1009,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
m_previewAfterFrame->show(); m_previewAfterFrame->show();
m_previewAfterLabel->show(); m_previewAfterLabel->show();
SelectionFilter filter = [this]( const QModelIndex& index ) { SelectionFilter filter = [ this ]( const QModelIndex& index ) {
return PartUtils::canBeResized( return PartUtils::canBeResized(
static_cast< Partition* >( index.data( PartitionModel::PartitionPtrRole ).value< void* >() ) ); static_cast< Partition* >( index.data( PartitionModel::PartitionPtrRole ).value< void* >() ) );
}; };
@ -1017,7 +1057,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); eraseBootloaderLabel->setText( tr( "Boot loader location:" ) );
m_bootloaderComboBox = createBootloaderComboBox( eraseWidget ); m_bootloaderComboBox = createBootloaderComboBox( eraseWidget );
connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, [this]() { connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, [ this ]() {
if ( !m_bootloaderComboBox.isNull() ) if ( !m_bootloaderComboBox.isNull() )
{ {
Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() );
@ -1027,7 +1067,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
m_core, m_core,
&PartitionCoreModule::deviceReverted, &PartitionCoreModule::deviceReverted,
this, this,
[this]( Device* dev ) { [ this ]( Device* dev ) {
Q_UNUSED( dev ) Q_UNUSED( dev )
if ( !m_bootloaderComboBox.isNull() ) if ( !m_bootloaderComboBox.isNull() )
{ {
@ -1058,7 +1098,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice )
} }
else else
{ {
SelectionFilter filter = [this]( const QModelIndex& index ) { SelectionFilter filter = [ this ]( const QModelIndex& index ) {
return PartUtils::canBeReplaced( return PartUtils::canBeReplaced(
static_cast< Partition* >( index.data( PartitionModel::PartitionPtrRole ).value< void* >() ) ); static_cast< Partition* >( index.data( PartitionModel::PartitionPtrRole ).value< void* >() ) );
}; };
@ -1160,7 +1200,7 @@ ChoicePage::createBootloaderComboBox( QWidget* parent )
bcb->setModel( m_core->bootLoaderModel() ); bcb->setModel( m_core->bootLoaderModel() );
// When the chosen bootloader device changes, we update the choice in the PCM // When the chosen bootloader device changes, we update the choice in the PCM
connect( bcb, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, [this]( int newIndex ) { connect( bcb, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, [ this ]( int newIndex ) {
QComboBox* bcb = qobject_cast< QComboBox* >( sender() ); QComboBox* bcb = qobject_cast< QComboBox* >( sender() );
if ( bcb ) if ( bcb )
{ {

View File

@ -114,6 +114,7 @@ private:
bool calculateNextEnabled() const; bool calculateNextEnabled() const;
void updateNextEnabled(); void updateNextEnabled();
void setupChoices(); void setupChoices();
void checkInstallChoiceRadioButton( ChoicePage::InstallChoice choice ); ///< Sets the chosen button to "on"
QComboBox* createBootloaderComboBox( QWidget* parentButton ); QComboBox* createBootloaderComboBox( QWidget* parentButton );
Device* selectedDevice(); Device* selectedDevice();
@ -161,7 +162,8 @@ private:
QPointer< QLabel > m_efiLabel; QPointer< QLabel > m_efiLabel;
QPointer< QComboBox > m_efiComboBox; QPointer< QComboBox > m_efiComboBox;
int m_lastSelectedDeviceIndex; int m_lastSelectedDeviceIndex = -1;
int m_lastSelectedActionIndex = -1;
QString m_defaultFsType; QString m_defaultFsType;
bool m_enableEncryptionWidget; bool m_enableEncryptionWidget;