From ec6703b9cda1f5b12410dc32c6beaeb08bf43561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 17 Jul 2014 09:49:15 +0200 Subject: [PATCH] Start creating EditExistingPartitionDialog --- src/modules/partition/CMakeLists.txt | 4 + .../partition/EditExistingPartitionDialog.cpp | 64 ++++++ .../partition/EditExistingPartitionDialog.h | 47 +++++ .../partition/EditExistingPartitionDialog.ui | 185 ++++++++++++++++++ src/modules/partition/PartitionPage.cpp | 11 +- src/modules/partition/PartitionPage.h | 2 +- 6 files changed, 310 insertions(+), 3 deletions(-) create mode 100644 src/modules/partition/EditExistingPartitionDialog.cpp create mode 100644 src/modules/partition/EditExistingPartitionDialog.h create mode 100644 src/modules/partition/EditExistingPartitionDialog.ui diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 3f9b60eb7..4d583cb23 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -22,6 +22,7 @@ calamares_add_plugin( partition CreatePartitionJob.cpp CreatePartitionTableJob.cpp DeletePartitionJob.cpp + EditExistingPartitionDialog.cpp DeviceModel.cpp PartitionCoreModule.cpp PartitionInfo.cpp @@ -32,6 +33,7 @@ calamares_add_plugin( partition UI CreatePartitionDialog.ui CreatePartitionTableDialog.ui + EditExistingPartitionDialog.ui PartitionPage.ui LINK_LIBRARIES calapm @@ -47,6 +49,7 @@ set( partview_SRCS CreatePartitionTableJob.cpp DeletePartitionJob.cpp DeviceModel.cpp + EditExistingPartitionDialog.cpp PartitionCoreModule.cpp PartitionInfo.cpp PartitionModel.cpp @@ -57,6 +60,7 @@ set( partview_SRCS qt5_wrap_ui( partview_SRCS CreatePartitionDialog.ui CreatePartitionTableDialog.ui + EditExistingPartitionDialog.ui PartitionPage.ui ) diff --git a/src/modules/partition/EditExistingPartitionDialog.cpp b/src/modules/partition/EditExistingPartitionDialog.cpp new file mode 100644 index 000000000..d58b4ce98 --- /dev/null +++ b/src/modules/partition/EditExistingPartitionDialog.cpp @@ -0,0 +1,64 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include + +#include +#include +#include + +// CalaPM +#include +#include + +// Qt +#include + +EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget ) + : QDialog( parentWidget ) + , m_ui( new Ui_EditExistingPartitionDialog ) + , m_device( device ) + , m_partition( partition ) +{ + m_ui->setupUi( this ); + + PartitionTable* table = m_device->partitionTable(); + qint64 minSector = partition->firstSector() - table->freeSectorsBefore( *partition ); + qint64 maxSector = partition->lastSector() + table->freeSectorsAfter( *partition ); + + m_ui->sizeSpinBox->setMaximum( mbSizeForSectorRange( minSector, maxSector ) ); + m_ui->sizeSpinBox->setValue( mbSizeForSectorRange( partition->firstSector(), partition->lastSector() ) ); + + // Mount point + m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) ); +} + +EditExistingPartitionDialog::~EditExistingPartitionDialog() +{} + +qint64 +EditExistingPartitionDialog::mbSizeForSectorRange( qint64 first, qint64 last ) const +{ + return ( last - first + 1 ) * m_device->logicalSectorSize() / 1024 / 1024; +} + +void +EditExistingPartitionDialog::applyChanges( PartitionCoreModule* module ) +{ + PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() ); +} diff --git a/src/modules/partition/EditExistingPartitionDialog.h b/src/modules/partition/EditExistingPartitionDialog.h new file mode 100644 index 000000000..886e00243 --- /dev/null +++ b/src/modules/partition/EditExistingPartitionDialog.h @@ -0,0 +1,47 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef EDITEXISTINGPARTITIONDIALOG_H +#define EDITEXISTINGPARTITIONDIALOG_H + +#include +#include + +class PartitionCoreModule; +class Device; +class Partition; +class Ui_EditExistingPartitionDialog; + +class EditExistingPartitionDialog : public QDialog +{ + Q_OBJECT +public: + EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget = nullptr ); + ~EditExistingPartitionDialog(); + + void applyChanges( PartitionCoreModule* module ); + +private: + QScopedPointer< Ui_EditExistingPartitionDialog > m_ui; + Device* m_device; + Partition* m_partition; + + qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const; +}; + +#endif /* EDITEXISTINGPARTITIONDIALOG_H */ diff --git a/src/modules/partition/EditExistingPartitionDialog.ui b/src/modules/partition/EditExistingPartitionDialog.ui new file mode 100644 index 000000000..276a0aa7e --- /dev/null +++ b/src/modules/partition/EditExistingPartitionDialog.ui @@ -0,0 +1,185 @@ + + + EditExistingPartitionDialog + + + + 0 + 0 + 350 + 203 + + + + + 0 + 0 + + + + Edit Existing Partition + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Si&ze: + + + sizeSpinBox + + + + + + + MB + + + + + + + Content: + + + + + + + Keep + + + true + + + + + + + Format + + + + + + + Warning: Formatting the partition will erase all existing data. + + + true + + + + + + + &Mount Point: + + + mountPointComboBox + + + + + + + true + + + -1 + + + + / + + + + + /boot + + + + + /home + + + + + /opt + + + + + /usr + + + + + /var + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + sizeSpinBox + radioButton + radioButton_2 + mountPointComboBox + buttonBox + + + + + buttonBox + accepted() + EditExistingPartitionDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditExistingPartitionDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/modules/partition/PartitionPage.cpp b/src/modules/partition/PartitionPage.cpp index c4f71474b..8aa5cafcf 100644 --- a/src/modules/partition/PartitionPage.cpp +++ b/src/modules/partition/PartitionPage.cpp @@ -20,6 +20,7 @@ // Local #include +#include #include #include #include @@ -163,7 +164,7 @@ PartitionPage::onEditClicked() if ( PMUtils::isPartitionNew( partition ) ) updatePartitionToCreate( model->device(), partition ); else - editExistingPartition( partition ); + editExistingPartition( model->device(), partition ); } void @@ -193,6 +194,12 @@ PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) } void -PartitionPage::editExistingPartition( Partition* partition ) +PartitionPage::editExistingPartition( Device* device, Partition* partition ) { + QPointer dlg = new EditExistingPartitionDialog( device, partition, this ); + if ( dlg->exec() == QDialog::Accepted ) + { + dlg->applyChanges( m_core ); + } + delete dlg; } diff --git a/src/modules/partition/PartitionPage.h b/src/modules/partition/PartitionPage.h index d4741a5ea..3e5841177 100644 --- a/src/modules/partition/PartitionPage.h +++ b/src/modules/partition/PartitionPage.h @@ -50,7 +50,7 @@ private: void onDeleteClicked(); void updatePartitionToCreate( Device*, Partition* ); - void editExistingPartition( Partition* ); + void editExistingPartition( Device*, Partition* ); }; #endif // PARTITIONPAGE_H