diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 85602630a..101bac024 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include @@ -433,28 +435,34 @@ ChoicePage::applyActionChoice( ChoicePage::Choice choice ) connect( m_beforePartitionBarsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [ this ]( const QModelIndex& current, const QModelIndex& previous ) { - auto doReplace = [=] + QFutureWatcher< void >* watcher = new QFutureWatcher< void >(); + connect( watcher, &QFutureWatcher< void >::finished, + this, [ watcher ] { + watcher->deleteLater(); + } ); + + auto doReplace = [ this, current, dev = selectedDevice() ] + { + QMutexLocker( &( this->m_coreMutex ) ); + + if ( m_core->isDirty() ) + { + m_core->revertDevice( dev ); + } // We can't use the PartitionPtrRole because we need to make changes to the // main DeviceModel, not the immutable copy. QString partPath = current.data( PartitionModel::PartitionPathRole ).toString(); - Partition* partition = KPMHelpers::findPartitionByPath( { selectedDevice() }, + Partition* partition = KPMHelpers::findPartitionByPath( { dev }, partPath ); if ( partition ) PartitionActions::doReplacePartition( m_core, - selectedDevice(), + dev, partition ); - PartitionModel* m = qobject_cast< PartitionModel* >( m_afterPartitionBarsView->model() ); - if ( m ) - m->update(); }; - if ( m_core->isDirty() ) - { - m_core->asyncRevertDevice( selectedDevice(), doReplace ); - } - else - doReplace(); + QFuture< void > future = QtConcurrent::run( doReplace ); + watcher->setFuture( future ); } ); break; case NoChoice: diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index dc9ae1e55..ac8668c06 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -105,6 +105,8 @@ private: QPointer< PartitionLabelsView > m_afterPartitionLabelsView; int m_lastSelectedDeviceIndex; + + QMutex m_coreMutex; }; #endif // CHOICEPAGE_H