Get rid of DeviceInfo

main
Aurélien Gâteau 11 years ago
parent f3f9bfc2a3
commit d54dfcfb78

@ -33,19 +33,6 @@
#include <backend/corebackendmanager.h>
//- DeviceInfo --------------------------------------------
PartitionCoreModule::DeviceInfo::DeviceInfo( Device* dev )
: device( dev )
, partitionModel( new PartitionModel )
{
}
PartitionCoreModule::DeviceInfo::~DeviceInfo()
{
delete partitionModel;
}
//- PartitionCoreModule -----------------------------------
PartitionCoreModule::PartitionCoreModule( QObject* parent )
: QObject( parent )
, m_deviceModel( new DeviceModel( this ) )
@ -57,14 +44,14 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
}
CoreBackend* backend = CoreBackendManager::self()->backend();
QList< Device* > lst = backend->scanDevices();
m_deviceModel->init( lst );
for ( auto device : lst )
m_devices = backend->scanDevices();
for ( auto device : m_devices )
{
DeviceInfo* info = new DeviceInfo( device );
info->partitionModel->init( device, &m_infoForPartitionHash );
m_devices << info;
PartitionModel* model = new PartitionModel;
model->init( device, &m_infoForPartitionHash );
m_partitionModelForDeviceHash[ device ] = model;
}
m_deviceModel->init( m_devices );
}
@ -83,45 +70,25 @@ PartitionCoreModule::deviceModel() const
PartitionModel*
PartitionCoreModule::partitionModelForDevice( Device* device ) const
{
for ( auto it : m_devices )
{
if ( it->device == device )
{
return it->partitionModel;
}
}
return nullptr;
return m_partitionModelForDeviceHash[ device ];
}
void
PartitionCoreModule::createPartition( CreatePartitionJob* job )
{
DeviceInfo* info = deviceInfoForDevice( job->device() );
Q_ASSERT( info );
Q_ASSERT( !m_infoForPartitionHash.contains( job->partition() ) );
PartitionInfo* partitionInfo = new PartitionInfo( job->partition() );
partitionInfo->mountPoint = job->mountPoint();
m_infoForPartitionHash[ job->partition() ] = partitionInfo;
job->updatePreview();
info->partitionModel->reload();
auto partitionModel = m_partitionModelForDeviceHash.value( job->device() );
Q_ASSERT( partitionModel );
partitionModel->reload();
m_jobs << Calamares::job_ptr( job );
dumpQueue();
}
PartitionCoreModule::DeviceInfo*
PartitionCoreModule::deviceInfoForDevice( Device* device ) const
{
for ( auto info : m_devices )
{
if ( info->device == device )
{
return info;
}
}
return nullptr;
}
void
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
{
@ -157,8 +124,9 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition )
m_jobs << Calamares::job_ptr( job );
}
DeviceInfo* info = deviceInfoForDevice( device );
info->partitionModel->reload();
auto partitionModel = m_partitionModelForDeviceHash.value( device );
Q_ASSERT( partitionModel );
partitionModel->reload();
dumpQueue();
}

@ -59,23 +59,16 @@ public:
}
private:
struct DeviceInfo
{
DeviceInfo( Device* dev );
~DeviceInfo();
Device* device;
PartitionModel* partitionModel;
};
QList< DeviceInfo* > m_devices;
InfoForPartitionHash m_infoForPartitionHash;
QList< Device* > m_devices;
QHash< Device*, PartitionModel* > m_partitionModelForDeviceHash;
DeviceModel* m_deviceModel;
InfoForPartitionHash m_infoForPartitionHash;
QList< Calamares::job_ptr > m_jobs;
void listDevices();
DeviceInfo* deviceInfoForDevice( Device* device ) const;
void dumpQueue() const;
};

Loading…
Cancel
Save