Use revertDevice in ChoicePage, and always use a fresh Device*.

main
Teo Mrnjavac 9 years ago
parent 0a0a0d58e0
commit dfededc4b4

@ -277,8 +277,8 @@ ChoicePage::setupChoices()
Device* currd = selectedDevice(); Device* currd = selectedDevice();
if ( currd ) if ( currd )
{ {
applyActionChoice( currd, currentChoice() ); applyActionChoice( currentChoice() );
updateActionChoicePreview( currd, currentChoice() ); updateActionChoicePreview( currentChoice() );
} }
} ); } );
} }
@ -302,8 +302,9 @@ ChoicePage::createBootloaderComboBox( ExpandableRadioButton* parentButton )
// If the user picks a new device, we update the bootloader choice to that // If the user picks a new device, we update the bootloader choice to that
// same device automatically. // same device automatically.
auto updateBootloaderDevice = [bcb]( Device* currd ) auto updateBootloaderDevice = [bcb, this]()
{ {
Device* currd = selectedDevice();
if ( !currd ) if ( !currd )
return; return;
QString devPath = currd->deviceNode(); QString devPath = currd->deviceNode();
@ -325,7 +326,7 @@ ChoicePage::createBootloaderComboBox( ExpandableRadioButton* parentButton )
this, [=]( bool expanded ) this, [=]( bool expanded )
{ {
if ( expanded ) if ( expanded )
updateBootloaderDevice( selectedDevice() ); updateBootloaderDevice();
}, Qt::QueuedConnection ); }, Qt::QueuedConnection );
// ^ Must be Queued so it's sure to run when the widget is already visible. // ^ Must be Queued so it's sure to run when the widget is already visible.
@ -398,10 +399,17 @@ ChoicePage::selectedDevice()
void void
ChoicePage::applyDeviceChoice() ChoicePage::applyDeviceChoice()
{ {
Device* currd = selectedDevice(); if ( !selectedDevice() )
return;
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{
m_core->revertDevice( selectedDevice() );
m_core->clearJobs(); m_core->clearJobs();
}
Device* currd = selectedDevice();
// The device should only be nullptr immediately after a PCM reset. // The device should only be nullptr immediately after a PCM reset.
// applyDeviceChoice() will be called again momentarily as soon as we handle the // applyDeviceChoice() will be called again momentarily as soon as we handle the
@ -409,35 +417,43 @@ ChoicePage::applyDeviceChoice()
if ( !currd ) if ( !currd )
return; return;
updateDeviceStatePreview( currd ); updateDeviceStatePreview();
// Preview setup done. Now we show/hide choices as needed. // Preview setup done. Now we show/hide choices as needed.
setupActions( currd ); setupActions();
m_lastSelectedDeviceIndex = m_drivesCombo->currentIndex(); m_lastSelectedDeviceIndex = m_drivesCombo->currentIndex();
emit actionChosen(); emit actionChosen();
emit deviceChosen( currd ); emit deviceChosen();
} }
void void
ChoicePage::applyActionChoice( Device* currentDevice, ChoicePage::Choice choice ) ChoicePage::applyActionChoice( ChoicePage::Choice choice )
{ {
switch ( choice ) switch ( choice )
{ {
case Erase: case Erase:
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{
m_core->revertDevice( selectedDevice() );
m_core->clearJobs(); m_core->clearJobs();
}
PartitionActions::doAutopartition( m_core, selectedDevice() ); PartitionActions::doAutopartition( m_core, selectedDevice() );
break; break;
case Replace: case Replace:
if ( m_core->isDirty() )
{
m_core->revertDevice( selectedDevice() );
m_core->clearJobs();
}
connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged, connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged,
this, [ this ]( const QModelIndex& current, const QModelIndex& previous ) this, [ this ]( const QModelIndex& current, const QModelIndex& previous )
{ {
if ( m_core->isDirty() ) m_core->revertDevice( selectedDevice() );
m_core->clearJobs();
// We can't use the PartitionPtrRole because we need to make changes to the // We can't use the PartitionPtrRole because we need to make changes to the
// main DeviceModel, not the immutable copy. // main DeviceModel, not the immutable copy.
@ -464,10 +480,11 @@ ChoicePage::applyActionChoice( Device* currentDevice, ChoicePage::Choice choice
* @param currentDevice a pointer to the selected Device. * @param currentDevice a pointer to the selected Device.
*/ */
void void
ChoicePage::updateDeviceStatePreview( Device* currentDevice ) ChoicePage::updateDeviceStatePreview()
{ {
//FIXME: this needs to be made async because the rescan can block the UI thread for //FIXME: this needs to be made async because the rescan can block the UI thread for
// a while. --Teo 10/2015 // a while. --Teo 10/2015
Device* currentDevice = selectedDevice();
Q_ASSERT( currentDevice ); Q_ASSERT( currentDevice );
QMutexLocker locker( &m_previewsMutex ); QMutexLocker locker( &m_previewsMutex );
@ -526,8 +543,9 @@ ChoicePage::updateDeviceStatePreview( Device* currentDevice )
* @param choice the chosen partitioning action. * @param choice the chosen partitioning action.
*/ */
void void
ChoicePage::updateActionChoicePreview( Device* currentDevice, ChoicePage::Choice choice ) ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice )
{ {
Device* currentDevice = selectedDevice();
Q_ASSERT( currentDevice ); Q_ASSERT( currentDevice );
QMutexLocker locker( &m_previewsMutex ); QMutexLocker locker( &m_previewsMutex );
@ -610,8 +628,9 @@ ChoicePage::updateActionChoicePreview( Device* currentDevice, ChoicePage::Choice
* @param currentDevice * @param currentDevice
*/ */
void void
ChoicePage::setupActions( Device *currentDevice ) ChoicePage::setupActions()
{ {
Device* currentDevice = selectedDevice();
OsproberEntryList osproberEntriesForCurrentDevice = OsproberEntryList osproberEntriesForCurrentDevice =
getOsproberEntriesForDevice( currentDevice ); getOsproberEntriesForDevice( currentDevice );

@ -67,7 +67,7 @@ public:
signals: signals:
void nextStatusChanged( bool ); void nextStatusChanged( bool );
void actionChosen(); void actionChosen();
void deviceChosen( Device* ); void deviceChosen();
private: private:
void setNextEnabled( bool enabled ); void setNextEnabled( bool enabled );
@ -77,10 +77,10 @@ private:
ExpandableRadioButton* createReplaceButton(); ExpandableRadioButton* createReplaceButton();
Device* selectedDevice(); Device* selectedDevice();
void applyDeviceChoice(); void applyDeviceChoice();
void updateDeviceStatePreview( Device* currentDevice ); void updateDeviceStatePreview();
void applyActionChoice( Device* currentDevice, ChoicePage::Choice choice ); void applyActionChoice( ChoicePage::Choice choice );
void updateActionChoicePreview( Device* currentDevice, ChoicePage::Choice choice ); void updateActionChoicePreview( ChoicePage::Choice choice );
void setupActions( Device* currentDevice ); void setupActions();
OsproberEntryList getOsproberEntriesForDevice( Device* device ) const; OsproberEntryList getOsproberEntriesForDevice( Device* device ) const;
bool m_nextEnabled; bool m_nextEnabled;

Loading…
Cancel
Save