Test out a way to make the rescan asynchronous.

main
Teo Mrnjavac 9 years ago
parent 16d10afcde
commit 5f282d50dc

@ -46,6 +46,8 @@
#include <QDir> #include <QDir>
#include <QLabel> #include <QLabel>
#include <QListView> #include <QListView>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>
@ -437,21 +439,35 @@ ChoicePage::applyActionChoice( ChoicePage::Choice choice )
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 )
{ {
auto doReplace = [=]
{
// 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() },
partPath );
if ( partition )
PartitionActions::doReplacePartition( m_core,
selectedDevice(),
partition );
};
if ( m_core->isDirty() ) if ( m_core->isDirty() )
{ {
m_core->revertDevice( selectedDevice() ); QFutureWatcher< void > watcher;
m_core->clearJobs(); connect( &watcher, &QFutureWatcher< void >::finished,
this, doReplace );
QFuture< void > future = QtConcurrent::run( [=]
{
m_core->revertDevice( selectedDevice() );
m_core->clearJobs();
} );
watcher.setFuture( future );
} }
else
doReplace();
// 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() },
partPath );
if ( partition )
PartitionActions::doReplacePartition( m_core,
selectedDevice(),
partition );
} ); } );
break; break;
case NoChoice: case NoChoice:

Loading…
Cancel
Save