From 3ed570481802ac3a06d3b465daa78cdaf0d4f0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Fri, 4 Jul 2014 17:58:32 +0200 Subject: [PATCH] Refactor: Move creation of CreatePartitionJob to PartitionCoreModule --- src/modules/partition/CreatePartitionDialog.cpp | 15 ++++++++------- src/modules/partition/CreatePartitionDialog.h | 4 ++-- src/modules/partition/CreatePartitionJob.cpp | 3 +-- src/modules/partition/CreatePartitionJob.h | 8 +------- src/modules/partition/PartitionCoreModule.cpp | 12 +++++++----- src/modules/partition/PartitionCoreModule.h | 2 +- src/modules/partition/PartitionPage.cpp | 2 +- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index 90e49b09a..c9602c7cc 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include // CalaPM @@ -78,8 +78,8 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePar CreatePartitionDialog::~CreatePartitionDialog() {} -CreatePartitionJob* -CreatePartitionDialog::createJob() +PartitionInfo* +CreatePartitionDialog::createPartitionInfo() { if ( m_role.roles() == PartitionRole::None ) { @@ -100,7 +100,7 @@ CreatePartitionDialog::createJob() FileSystem* fs = FileSystemFactory::create( type, first, last ); PartitionNode* parent = m_freePartition->parent(); - Partition* partition = new Partition( + auto partition = new Partition( parent, *m_device, m_role, @@ -112,7 +112,8 @@ CreatePartitionDialog::createJob() PartitionTable::FlagNone /* activeFlags */, Partition::StateNew ); - return new CreatePartitionJob( m_device, partition, - m_ui->mountPointComboBox->currentText() - ); + + auto info = new PartitionInfo( partition ); + info->mountPoint = m_ui->mountPointComboBox->currentText(); + return info; } diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index b809cb15a..131c9110a 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -25,9 +25,9 @@ // CalaPM #include -class CreatePartitionJob; class Device; class Partition; +class PartitionInfo; class Ui_CreatePartitionDialog; class CreatePartitionDialog : public QDialog @@ -36,7 +36,7 @@ public: CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent = nullptr ); ~CreatePartitionDialog(); - CreatePartitionJob* createJob(); + PartitionInfo* createPartitionInfo(); private: QScopedPointer< Ui_CreatePartitionDialog > m_ui; diff --git a/src/modules/partition/CreatePartitionJob.cpp b/src/modules/partition/CreatePartitionJob.cpp index e79f64cbe..b65cb654b 100644 --- a/src/modules/partition/CreatePartitionJob.cpp +++ b/src/modules/partition/CreatePartitionJob.cpp @@ -24,10 +24,9 @@ #include #include -CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition, const QString& mountPoint ) +CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition ) : m_device( device ) , m_partition( partition ) - , m_mountPoint( mountPoint ) { } diff --git a/src/modules/partition/CreatePartitionJob.h b/src/modules/partition/CreatePartitionJob.h index 9e56b4d53..0309105ed 100644 --- a/src/modules/partition/CreatePartitionJob.h +++ b/src/modules/partition/CreatePartitionJob.h @@ -29,7 +29,7 @@ class CreatePartitionJob : public Calamares::Job { Q_OBJECT public: - CreatePartitionJob( Device* device, Partition* partition, const QString& mountPoint ); + CreatePartitionJob( Device* device, Partition* partition ); QString prettyName() override; void exec() override; @@ -44,15 +44,9 @@ public: return m_partition; } - QString mountPoint() const - { - return m_mountPoint; - } - private: Device* m_device; Partition* m_partition; - QString m_mountPoint; }; #endif /* CREATEPARTITIONJOB_H */ diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp index b3a787a8c..62b56f69c 100644 --- a/src/modules/partition/PartitionCoreModule.cpp +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -74,13 +74,15 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const } void -PartitionCoreModule::createPartition( CreatePartitionJob* job ) +PartitionCoreModule::createPartition( Device* device, PartitionInfo* partitionInfo ) { - Q_ASSERT( !m_infoForPartitionHash.contains( job->partition() ) ); - PartitionInfo* partitionInfo = new PartitionInfo( job->partition() ); - partitionInfo->mountPoint = job->mountPoint(); - m_infoForPartitionHash[ job->partition() ] = partitionInfo; + auto partition = partitionInfo->partition; + Q_ASSERT( !m_infoForPartitionHash.contains( partition ) ); + m_infoForPartitionHash[ partition ] = partitionInfo; + + CreatePartitionJob* job = new CreatePartitionJob( device, partition ); job->updatePreview(); + auto partitionModel = m_partitionModelForDeviceHash.value( job->device() ); Q_ASSERT( partitionModel ); partitionModel->reload(); diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h index a9255d48b..7640ea8d9 100644 --- a/src/modules/partition/PartitionCoreModule.h +++ b/src/modules/partition/PartitionCoreModule.h @@ -49,7 +49,7 @@ public: PartitionModel* partitionModelForDevice( Device* device ) const; - void createPartition( CreatePartitionJob* job ); + void createPartition( Device* device, PartitionInfo* partitionInfo ); void deletePartition( Device* device, Partition* partition ); diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index 291dc7f0f..ea6a66efe 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -107,7 +107,7 @@ PartitionPage::onCreateClicked() QPointer dlg = new CreatePartitionDialog( model->device(), partition, this ); if ( dlg->exec() == QDialog::Accepted ) { - m_core->createPartition( dlg->createJob() ); + m_core->createPartition( model->device(), dlg->createPartitionInfo() ); } delete dlg; }