|
|
@ -34,6 +34,13 @@
|
|
|
|
#include <backend/corebackendmanager.h>
|
|
|
|
#include <backend/corebackendmanager.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//- DeviceInfo ---------------------------------------------
|
|
|
|
|
|
|
|
PartitionCoreModule::DeviceInfo::DeviceInfo( Device* _device )
|
|
|
|
|
|
|
|
: device( _device )
|
|
|
|
|
|
|
|
, partitionModel( new PartitionModel )
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//- PartitionCoreModule ------------------------------------
|
|
|
|
PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|
|
|
PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|
|
|
: QObject( parent )
|
|
|
|
: QObject( parent )
|
|
|
|
, m_deviceModel( new DeviceModel( this ) )
|
|
|
|
, m_deviceModel( new DeviceModel( this ) )
|
|
|
@ -45,21 +52,22 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
|
|
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
|
|
|
m_devices = backend->scanDevices();
|
|
|
|
auto devices = backend->scanDevices();
|
|
|
|
for ( auto device : m_devices )
|
|
|
|
for ( auto device : devices )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
PartitionModel* model = new PartitionModel;
|
|
|
|
auto deviceInfo = new DeviceInfo( device );
|
|
|
|
model->init( device, &m_infoForPartitionHash );
|
|
|
|
m_deviceInfos << deviceInfo;
|
|
|
|
m_partitionModelForDeviceHash[ device ] = model;
|
|
|
|
|
|
|
|
|
|
|
|
deviceInfo->partitionModel->init( device, &m_infoForPartitionHash );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_deviceModel->init( m_devices );
|
|
|
|
m_deviceModel->init( devices );
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PartitionCoreModule::~PartitionCoreModule()
|
|
|
|
PartitionCoreModule::~PartitionCoreModule()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
qDeleteAll( m_infoForPartitionHash );
|
|
|
|
qDeleteAll( m_infoForPartitionHash );
|
|
|
|
qDeleteAll( m_devices );
|
|
|
|
qDeleteAll( m_deviceInfos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceModel*
|
|
|
|
DeviceModel*
|
|
|
@ -71,7 +79,9 @@ PartitionCoreModule::deviceModel() const
|
|
|
|
PartitionModel*
|
|
|
|
PartitionModel*
|
|
|
|
PartitionCoreModule::partitionModelForDevice( Device* device ) const
|
|
|
|
PartitionCoreModule::partitionModelForDevice( Device* device ) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_partitionModelForDeviceHash[ device ];
|
|
|
|
DeviceInfo* info = infoForDevice( device );
|
|
|
|
|
|
|
|
Q_ASSERT( info );
|
|
|
|
|
|
|
|
return info->partitionModel.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
@ -83,13 +93,15 @@ PartitionCoreModule::createPartitionTable( Device* device )
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Remove all jobs queued for this device, as well as all partition
|
|
|
|
// FIXME: Remove all jobs queued for this device, as well as all partition
|
|
|
|
// info
|
|
|
|
// info
|
|
|
|
m_jobs << Calamares::job_ptr( job );
|
|
|
|
infoForDevice( device )->jobs << Calamares::job_ptr( job );
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
PartitionCoreModule::createPartition( Device* device, PartitionInfo* partitionInfo )
|
|
|
|
PartitionCoreModule::createPartition( Device* device, PartitionInfo* partitionInfo )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
auto deviceInfo = infoForDevice( device );
|
|
|
|
|
|
|
|
Q_ASSERT( deviceInfo );
|
|
|
|
auto partition = partitionInfo->partition;
|
|
|
|
auto partition = partitionInfo->partition;
|
|
|
|
Q_ASSERT( !m_infoForPartitionHash.contains( partition ) );
|
|
|
|
Q_ASSERT( !m_infoForPartitionHash.contains( partition ) );
|
|
|
|
m_infoForPartitionHash[ partition ] = partitionInfo;
|
|
|
|
m_infoForPartitionHash[ partition ] = partitionInfo;
|
|
|
@ -99,7 +111,7 @@ PartitionCoreModule::createPartition( Device* device, PartitionInfo* partitionIn
|
|
|
|
|
|
|
|
|
|
|
|
refreshPartitionModel( device );
|
|
|
|
refreshPartitionModel( device );
|
|
|
|
|
|
|
|
|
|
|
|
m_jobs << Calamares::job_ptr( job );
|
|
|
|
deviceInfo->jobs << Calamares::job_ptr( job );
|
|
|
|
|
|
|
|
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -107,21 +119,25 @@ PartitionCoreModule::createPartition( Device* device, PartitionInfo* partitionIn
|
|
|
|
void
|
|
|
|
void
|
|
|
|
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|
|
|
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
auto deviceInfo = infoForDevice( device );
|
|
|
|
|
|
|
|
Q_ASSERT( deviceInfo );
|
|
|
|
auto it = m_infoForPartitionHash.find( partition );
|
|
|
|
auto it = m_infoForPartitionHash.find( partition );
|
|
|
|
if ( it != m_infoForPartitionHash.end() )
|
|
|
|
if ( it != m_infoForPartitionHash.end() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_infoForPartitionHash.erase( it );
|
|
|
|
m_infoForPartitionHash.erase( it );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr >& jobs = deviceInfo->jobs;
|
|
|
|
|
|
|
|
|
|
|
|
if ( partition->state() == Partition::StateNew )
|
|
|
|
if ( partition->state() == Partition::StateNew )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Find matching CreatePartitionJob
|
|
|
|
// Find matching CreatePartitionJob
|
|
|
|
auto it = std::find_if( m_jobs.begin(), m_jobs.end(), [ partition ]( Calamares::job_ptr job )
|
|
|
|
auto it = std::find_if( jobs.begin(), jobs.end(), [ partition ]( Calamares::job_ptr job )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() );
|
|
|
|
CreatePartitionJob* createJob = qobject_cast< CreatePartitionJob* >( job.data() );
|
|
|
|
return createJob && createJob->partition() == partition;
|
|
|
|
return createJob && createJob->partition() == partition;
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
if ( it == m_jobs.end() )
|
|
|
|
if ( it == jobs.end() )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
|
|
|
cDebug() << "Failed to find a CreatePartitionJob matching the partition to remove";
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -133,7 +149,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device->partitionTable()->updateUnallocated( *device );
|
|
|
|
device->partitionTable()->updateUnallocated( *device );
|
|
|
|
m_jobs.erase( it );
|
|
|
|
jobs.erase( it );
|
|
|
|
// The partition is no longer referenced by either a job or the device
|
|
|
|
// The partition is no longer referenced by either a job or the device
|
|
|
|
// partition list, so we have to delete it
|
|
|
|
// partition list, so we have to delete it
|
|
|
|
delete partition;
|
|
|
|
delete partition;
|
|
|
@ -142,27 +158,42 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
|
|
|
|
DeletePartitionJob* job = new DeletePartitionJob( device, partition );
|
|
|
|
job->updatePreview();
|
|
|
|
job->updatePreview();
|
|
|
|
m_jobs << Calamares::job_ptr( job );
|
|
|
|
jobs << Calamares::job_ptr( job );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
refreshPartitionModel( device );
|
|
|
|
refreshPartitionModel( device );
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
updateHasRootMountPoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr >
|
|
|
|
|
|
|
|
PartitionCoreModule::jobs() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr > lst;
|
|
|
|
|
|
|
|
for ( auto info : m_deviceInfos )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lst << info->jobs;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return lst;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
PartitionCoreModule::dumpQueue() const
|
|
|
|
PartitionCoreModule::dumpQueue() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cDebug() << "Queue:";
|
|
|
|
cDebug() << "Queue:";
|
|
|
|
for ( auto job : m_jobs )
|
|
|
|
for ( auto info : m_deviceInfos )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cDebug() << "Device:" << info->device->name();
|
|
|
|
|
|
|
|
for ( auto job : info->jobs )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cDebug() << job->prettyName();
|
|
|
|
cDebug() << job->prettyName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
PartitionCoreModule::refreshPartitionModel( Device* device )
|
|
|
|
PartitionCoreModule::refreshPartitionModel( Device* device )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto model = m_partitionModelForDeviceHash.value( device );
|
|
|
|
auto model = partitionModelForDevice( device );
|
|
|
|
Q_ASSERT( model );
|
|
|
|
Q_ASSERT( model );
|
|
|
|
model->reload();
|
|
|
|
model->reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,3 +216,16 @@ void PartitionCoreModule::updateHasRootMountPoint()
|
|
|
|
hasRootMountPointChanged( m_hasRootMountPoint );
|
|
|
|
hasRootMountPointChanged( m_hasRootMountPoint );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PartitionCoreModule::DeviceInfo*
|
|
|
|
|
|
|
|
PartitionCoreModule::infoForDevice( Device* device ) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for ( auto deviceInfo : m_deviceInfos )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ( deviceInfo->device.data() == device )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return deviceInfo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
}
|
|
|
|