From c30ed3c9c133660b1536e05d8df9824beaf22bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Tue, 15 Jul 2014 14:40:08 +0200 Subject: [PATCH] Let the user recreate the partition table (mbr or gpt) Closes #20 --- src/modules/partition/CMakeLists.txt | 2 + .../partition/CreatePartitionTableDialog.ui | 138 ++++++++++++++++++ .../partition/CreatePartitionTableJob.cpp | 10 +- .../partition/CreatePartitionTableJob.h | 7 +- src/modules/partition/PartitionCoreModule.cpp | 4 +- src/modules/partition/PartitionCoreModule.h | 2 +- src/modules/partition/PartitionPage.cpp | 24 +-- 7 files changed, 165 insertions(+), 22 deletions(-) create mode 100644 src/modules/partition/CreatePartitionTableDialog.ui diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index b220ed46e..3f9b60eb7 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -31,6 +31,7 @@ calamares_add_plugin( partition PMUtils.cpp UI CreatePartitionDialog.ui + CreatePartitionTableDialog.ui PartitionPage.ui LINK_LIBRARIES calapm @@ -55,6 +56,7 @@ set( partview_SRCS ) qt5_wrap_ui( partview_SRCS CreatePartitionDialog.ui + CreatePartitionTableDialog.ui PartitionPage.ui ) diff --git a/src/modules/partition/CreatePartitionTableDialog.ui b/src/modules/partition/CreatePartitionTableDialog.ui new file mode 100644 index 000000000..ca1255e41 --- /dev/null +++ b/src/modules/partition/CreatePartitionTableDialog.ui @@ -0,0 +1,138 @@ + + + CreatePartitionTableDialog + + + + 0 + 0 + 297 + 182 + + + + + 0 + 0 + + + + Create Partition Table + + + + + + + 75 + true + + + + [are-you-sure-message] + + + + + + + Creating a new partition table will delete all existing data on the disk. + + + true + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 24 + + + + + + + + What kind of partition table do you want to create? + + + + + + + Master Boot Record (MBR) + + + true + + + + + + + GUID Partition Table (GPT) + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + mbrRadioButton + gptRadioButton + buttonBox + + + + + buttonBox + accepted() + CreatePartitionTableDialog + accept() + + + 222 + 141 + + + 157 + 155 + + + + + buttonBox + rejected() + CreatePartitionTableDialog + reject() + + + 290 + 147 + + + 286 + 155 + + + + + diff --git a/src/modules/partition/CreatePartitionTableJob.cpp b/src/modules/partition/CreatePartitionTableJob.cpp index f214d2ffc..92d6a47e0 100644 --- a/src/modules/partition/CreatePartitionTableJob.cpp +++ b/src/modules/partition/CreatePartitionTableJob.cpp @@ -35,8 +35,9 @@ // Qt #include -CreatePartitionTableJob::CreatePartitionTableJob( Device* device ) +CreatePartitionTableJob::CreatePartitionTableJob( Device* device, PartitionTable::TableType type ) : m_device( device ) + , m_type( type ) { } @@ -88,9 +89,8 @@ CreatePartitionTableJob::updatePreview() PartitionTable* CreatePartitionTableJob::createTable() { - PartitionTable::TableType type = PartitionTable::msdos; - return new PartitionTable( type, - PartitionTable::defaultFirstUsable( *m_device, type ), - PartitionTable::defaultLastUsable( *m_device, type ) + return new PartitionTable( m_type, + PartitionTable::defaultFirstUsable( *m_device, m_type ), + PartitionTable::defaultLastUsable( *m_device, m_type ) ); } diff --git a/src/modules/partition/CreatePartitionTableJob.h b/src/modules/partition/CreatePartitionTableJob.h index 50eb9727a..25854b855 100644 --- a/src/modules/partition/CreatePartitionTableJob.h +++ b/src/modules/partition/CreatePartitionTableJob.h @@ -21,14 +21,16 @@ #include +// CalaPM +#include + class Device; -class PartitionTable; class CreatePartitionTableJob : public Calamares::Job { Q_OBJECT public: - CreatePartitionTableJob( Device* device ); + CreatePartitionTableJob( Device* device, PartitionTable::TableType type ); QString prettyName() const override; Calamares::JobResult exec() override; @@ -40,6 +42,7 @@ public: private: Device* m_device; + PartitionTable::TableType m_type; PartitionTable* createTable(); }; diff --git a/src/modules/partition/PartitionCoreModule.cpp b/src/modules/partition/PartitionCoreModule.cpp index a4ac3620a..bedc66f3d 100644 --- a/src/modules/partition/PartitionCoreModule.cpp +++ b/src/modules/partition/PartitionCoreModule.cpp @@ -128,14 +128,14 @@ PartitionCoreModule::partitionModelForDevice( Device* device ) const } void -PartitionCoreModule::createPartitionTable( Device* device ) +PartitionCoreModule::createPartitionTable( Device* device, PartitionTable::TableType type ) { DeviceInfo* info = infoForDevice( device ); // Creating a partition table wipes all the disk, so there is no need to // keep previous changes info->forgetChanges(); - CreatePartitionTableJob* job = new CreatePartitionTableJob( device ); + CreatePartitionTableJob* job = new CreatePartitionTableJob( device, type ); job->updatePreview(); info->jobs << Calamares::job_ptr( job ); diff --git a/src/modules/partition/PartitionCoreModule.h b/src/modules/partition/PartitionCoreModule.h index 5c404868a..4f07e4cd4 100644 --- a/src/modules/partition/PartitionCoreModule.h +++ b/src/modules/partition/PartitionCoreModule.h @@ -50,7 +50,7 @@ public: PartitionModel* partitionModelForDevice( Device* device ) const; - void createPartitionTable( Device* device ); + void createPartitionTable( Device* device, PartitionTable::TableType type ); /** * Takes ownership of partitionInfo diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index b759c930c..20993b166 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -25,6 +25,7 @@ #include #include #include +#include // CalaPM #include @@ -108,18 +109,17 @@ PartitionPage::onNewPartitionTableClicked() Q_ASSERT( index.isValid() ); Device* device = m_core->deviceModel()->deviceForIndex( index ); - auto answer = QMessageBox::warning( this, - tr( "New Partition Table" ), - tr( "Are you sure you want to create a new partition table on %1?\n" - "Creating a new partition table will delete all existing data on the disk." ) - .arg( device->name() ), - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel - ); - - if ( answer != QMessageBox::Ok ) - return; - m_core->createPartitionTable( device ); + QPointer dlg = new QDialog( this ); + Ui_CreatePartitionTableDialog ui; + ui.setupUi( dlg.data() ); + QString areYouSure = tr( "Are you sure you want to create a new partition table on %1?" ).arg( device->name() ); + ui.areYouSureLabel->setText( areYouSure ); + if ( dlg->exec() == QDialog::Accepted ) + { + PartitionTable::TableType type = ui.mbrRadioButton->isChecked() ? PartitionTable::msdos : PartitionTable::gpt; + m_core->createPartitionTable( device, type ); + } + delete dlg; } void