mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
Refactor: group jobs and partitionModel for a device in a DeviceInfo struct
Makes it easier to clear all jobs for a specific device, which is necessary when replacing a device partition table
This commit is contained in:
parent
7034985b74
commit
61b17490eb
2 changed files with 73 additions and 25 deletions
|
@ -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() << job->prettyName();
|
cDebug() << "Device:" << info->device->name();
|
||||||
|
for ( auto job : info->jobs )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -56,10 +56,7 @@ public:
|
||||||
|
|
||||||
void deletePartition( Device* device, Partition* partition );
|
void deletePartition( Device* device, Partition* partition );
|
||||||
|
|
||||||
QList< Calamares::job_ptr > jobs() const
|
QList< Calamares::job_ptr > jobs() const;
|
||||||
{
|
|
||||||
return m_jobs;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasRootMountPoint() const
|
bool hasRootMountPoint() const
|
||||||
{
|
{
|
||||||
|
@ -70,20 +67,27 @@ Q_SIGNALS:
|
||||||
void hasRootMountPointChanged( bool value );
|
void hasRootMountPointChanged( bool value );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList< Device* > m_devices;
|
struct DeviceInfo
|
||||||
QHash< Device*, PartitionModel* > m_partitionModelForDeviceHash;
|
{
|
||||||
|
DeviceInfo( Device* );
|
||||||
|
QScopedPointer< Device > device;
|
||||||
|
QScopedPointer< PartitionModel > partitionModel;
|
||||||
|
QList< Calamares::job_ptr > jobs;
|
||||||
|
};
|
||||||
|
QList< DeviceInfo* > m_deviceInfos;
|
||||||
|
|
||||||
DeviceModel* m_deviceModel;
|
DeviceModel* m_deviceModel;
|
||||||
bool m_hasRootMountPoint = false;
|
bool m_hasRootMountPoint = false;
|
||||||
|
|
||||||
InfoForPartitionHash m_infoForPartitionHash;
|
InfoForPartitionHash m_infoForPartitionHash;
|
||||||
|
|
||||||
QList< Calamares::job_ptr > m_jobs;
|
|
||||||
|
|
||||||
void listDevices();
|
void listDevices();
|
||||||
void updateHasRootMountPoint();
|
void updateHasRootMountPoint();
|
||||||
void refreshPartitionModel( Device* device );
|
void refreshPartitionModel( Device* device );
|
||||||
|
|
||||||
void dumpQueue() const;
|
void dumpQueue() const;
|
||||||
|
|
||||||
|
DeviceInfo* infoForDevice( Device* ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARTITIONCOREMODULE_H */
|
#endif /* PARTITIONCOREMODULE_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue