diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt
index 92072b520..4e96e039e 100644
--- a/src/modules/partition/CMakeLists.txt
+++ b/src/modules/partition/CMakeLists.txt
@@ -37,8 +37,9 @@ calamares_add_plugin( partition
PartitionJob.cpp
PartitionModel.cpp
PartitionPage.cpp
- PartitionViewStep.cpp
PartitionPreview.cpp
+ PartitionSizeWidget.cpp
+ PartitionViewStep.cpp
PMUtils.cpp
UI
CreatePartitionDialog.ui
diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp
index 13697aa6e..7ea7a5eca 100644
--- a/src/modules/partition/CreatePartitionDialog.cpp
+++ b/src/modules/partition/CreatePartitionDialog.cpp
@@ -118,25 +118,7 @@ CreatePartitionDialog::createPartition()
);
}
- qint64 lastSector;
- int mbSize = m_ui->sizeSpinBox->value();
- if ( mbSize == m_ui->sizeSpinBox->maximum() )
- {
- // If we are at the maximum value, select the last sector to avoid
- // potential rounding errors which could leave a few sectors at the end
- // unused
- lastSector = m_maxSector;
- }
- else
- {
- lastSector = m_minSector + qint64( mbSize ) * 1024 * 1024 / m_device->logicalSectorSize();
- Q_ASSERT( lastSector <= m_maxSector );
- if ( lastSector > m_maxSector )
- {
- cDebug() << "lastSector (" << lastSector << ") > m_maxSector (" << m_maxSector << "). This should not happen!";
- lastSector = m_maxSector;
- }
- }
+ PartitionSizeWidget::SectorRange range = m_ui->sizeSpinBox->sectorRange();
FileSystem::Type fsType = m_role.has( PartitionRole::Extended )
? FileSystem::Extended
@@ -145,7 +127,7 @@ CreatePartitionDialog::createPartition()
m_parent,
*m_device,
m_role,
- fsType, m_minSector, lastSector );
+ fsType, range.first, range.second );
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
PartitionInfo::setFormat( partition, true );
@@ -165,21 +147,10 @@ CreatePartitionDialog::updateMountPointUi()
m_ui->mountPointComboBox->setEnabled( enabled );
}
-void
-CreatePartitionDialog::initSectorRange( Partition* partition )
-{
- PartitionTable* table = m_device->partitionTable();
- m_minSector = partition->firstSector() - table->freeSectorsBefore( *partition );
- m_maxSector = partition->lastSector() + table->freeSectorsAfter( *partition );
-
- m_ui->sizeSpinBox->setMaximum( mbSizeForSectorRange( m_minSector, m_maxSector ) );
- m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
-}
-
void
CreatePartitionDialog::initFromFreeSpace( Partition* freeSpacePartition )
{
- initSectorRange( freeSpacePartition );
+ m_ui->sizeSpinBox->init( m_device, freeSpacePartition );
}
void
@@ -195,10 +166,7 @@ CreatePartitionDialog::initFromPartitionToCreate( Partition* partition )
return;
}
- initSectorRange( partition );
-
- // Size
- m_ui->sizeSpinBox->setValue( mbSizeForSectorRange( partition->firstSector(), partition->lastSector() ) );
+ m_ui->sizeSpinBox->init( m_device, partition );
// File System
FileSystem::Type fsType = partition->fileSystem().type();
@@ -209,9 +177,3 @@ CreatePartitionDialog::initFromPartitionToCreate( Partition* partition )
updateMountPointUi();
}
-
-qint64
-CreatePartitionDialog::mbSizeForSectorRange( qint64 first, qint64 last ) const
-{
- return ( last - first + 1 ) * m_device->logicalSectorSize() / 1024 / 1024;
-}
diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h
index c21e4d12a..289d25c5a 100644
--- a/src/modules/partition/CreatePartitionDialog.h
+++ b/src/modules/partition/CreatePartitionDialog.h
@@ -47,16 +47,12 @@ private Q_SLOTS:
private:
QScopedPointer< Ui_CreatePartitionDialog > m_ui;
Device* m_device;
- qint64 m_minSector = 0;
- qint64 m_maxSector = 0;
PartitionNode* m_parent;
PartitionRole m_role = PartitionRole( PartitionRole::None );
void initGptPartitionTypeUi();
void initMbrPartitionTypeUi();
void initSectorRange( Partition* );
-
- qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const;
};
#endif /* CREATEPARTITIONDIALOG_H */
diff --git a/src/modules/partition/CreatePartitionDialog.ui b/src/modules/partition/CreatePartitionDialog.ui
index 222287b94..c14074c8c 100644
--- a/src/modules/partition/CreatePartitionDialog.ui
+++ b/src/modules/partition/CreatePartitionDialog.ui
@@ -91,7 +91,7 @@
-
-
+
MB
@@ -203,6 +203,13 @@
+
+
+ PartitionSizeWidget
+ QSpinBox
+
+
+
primaryRadioButton
fsComboBox
diff --git a/src/modules/partition/EditExistingPartitionDialog.cpp b/src/modules/partition/EditExistingPartitionDialog.cpp
index bd1d01d2b..c8cc1fc78 100644
--- a/src/modules/partition/EditExistingPartitionDialog.cpp
+++ b/src/modules/partition/EditExistingPartitionDialog.cpp
@@ -38,66 +38,21 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
, 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->sizeSpinBox->init( device, partition );
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* core )
{
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
- qint64 oldSize = mbSizeForSectorRange( m_partition->firstSector(), m_partition->lastSector() );
- qint64 newSize = m_ui->sizeSpinBox->value();
- if ( oldSize == newSize )
+ if ( m_ui->sizeSpinBox->isDirty() )
{
- if ( m_ui->formatRadioButton->isChecked() )
- core->formatPartition( m_device, m_partition );
- else
- core->refreshPartition( m_device, m_partition );
- }
- else
- {
- // FIXME: Duplicated from CreatePartitionDialog
- qint64 maxSector = m_partition->lastSector() + m_device->partitionTable()->freeSectorsAfter( *m_partition );
-
- qint64 lastSector;
- int mbSize = m_ui->sizeSpinBox->value();
- if ( mbSize == m_ui->sizeSpinBox->maximum() )
- {
- // If we are at the maximum value, select the last sector to avoid
- // potential rounding errors which could leave a few sectors at the end
- // unused
- lastSector = maxSector;
- }
- else
- {
- lastSector = m_partition->firstSector() + qint64( mbSize ) * 1024 * 1024 / m_device->logicalSectorSize();
- Q_ASSERT( lastSector <= maxSector );
- if ( lastSector > maxSector )
- {
- cDebug() << "lastSector (" << lastSector << ") > maxSector (" << maxSector << "). This should not happen!";
- lastSector = maxSector;
- }
- }
-
+ PartitionSizeWidget::SectorRange range = m_ui->sizeSpinBox->sectorRange();
if ( m_ui->formatRadioButton->isChecked() )
{
Partition* newPartition = PMUtils::createNewPartition(
@@ -105,8 +60,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
*m_device,
m_partition->roles(),
m_partition->fileSystem().type(),
- m_partition->firstSector(),
- lastSector);
+ range.first,
+ range.second);
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true );
@@ -118,4 +73,12 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
//core->resizePartition( m_device, m_partition );
}
}
+ else
+ {
+ // No size changes
+ if ( m_ui->formatRadioButton->isChecked() )
+ core->formatPartition( m_device, m_partition );
+ else
+ core->refreshPartition( m_device, m_partition );
+ }
}
diff --git a/src/modules/partition/EditExistingPartitionDialog.h b/src/modules/partition/EditExistingPartitionDialog.h
index 886e00243..270bbb0e5 100644
--- a/src/modules/partition/EditExistingPartitionDialog.h
+++ b/src/modules/partition/EditExistingPartitionDialog.h
@@ -40,8 +40,6 @@ 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
index 44ebaeb1a..3cbfeebd7 100644
--- a/src/modules/partition/EditExistingPartitionDialog.ui
+++ b/src/modules/partition/EditExistingPartitionDialog.ui
@@ -36,7 +36,7 @@
-
-
+
MB
@@ -143,6 +143,13 @@
+
+
+ PartitionSizeWidget
+ QSpinBox
+
+
+
sizeSpinBox
keepRadioButton
diff --git a/src/modules/partition/PartitionSizeWidget.cpp b/src/modules/partition/PartitionSizeWidget.cpp
new file mode 100644
index 000000000..485770138
--- /dev/null
+++ b/src/modules/partition/PartitionSizeWidget.cpp
@@ -0,0 +1,100 @@
+/* === 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
+
+// CalaPM
+#include
+#include
+#include
+
+PartitionSizeWidget::PartitionSizeWidget( QWidget* parent )
+ : QSpinBox( parent )
+{
+}
+
+void
+PartitionSizeWidget::init( Device* device, Partition* partition )
+{
+ m_device = device;
+ m_partition = partition;
+ Q_ASSERT( m_device->partitionTable() );
+
+ qint64 minSector = computeMinSector();
+ qint64 maxSector = computeMaxSector();
+ cLog() << minSector << maxSector;
+ setMaximum( mbSizeForSectorRange( minSector, maxSector ) );
+
+ m_initialValue = mbSizeForSectorRange( partition->firstSector(), partition->lastSector() );
+ setValue( m_initialValue );
+}
+
+PartitionSizeWidget::SectorRange
+PartitionSizeWidget::sectorRange() const
+{
+ qint64 minSector = computeMinSector();
+ qint64 maxSector = computeMaxSector();
+
+ int mbSize = value();
+ if ( mbSize == maximum() )
+ {
+ // If we are at the maximum value, select the last sector to avoid
+ // potential rounding errors which could leave a few sectors at the end
+ // unused
+ return SectorRange( minSector, maxSector );
+ }
+
+ qint64 lastSector = minSector + qint64( mbSize ) * 1024 * 1024 / m_device->logicalSectorSize();
+ Q_ASSERT( lastSector <= maxSector );
+ if ( lastSector > maxSector )
+ {
+ cLog() << "lastSector (" << lastSector << ") > maxSector (" << maxSector << "). This should not happen!";
+ lastSector = maxSector;
+ }
+ return SectorRange( minSector, lastSector );
+}
+
+bool
+PartitionSizeWidget::isDirty() const
+{
+ return m_initialValue != value();
+}
+
+qint64
+PartitionSizeWidget::mbSizeForSectorRange( qint64 first, qint64 last ) const
+{
+ return ( last - first + 1 ) * m_device->logicalSectorSize() / 1024 / 1024;
+}
+
+qint64
+PartitionSizeWidget::computeMaxSector() const
+{
+ Q_ASSERT( m_device );
+ Q_ASSERT( m_partition );
+ return m_partition->lastSector() + m_device->partitionTable()->freeSectorsAfter( *m_partition );
+}
+
+qint64
+PartitionSizeWidget::computeMinSector() const
+{
+ Q_ASSERT( m_device );
+ Q_ASSERT( m_partition );
+ return m_partition->firstSector() - m_device->partitionTable()->freeSectorsBefore( *m_partition );
+}
diff --git a/src/modules/partition/PartitionSizeWidget.h b/src/modules/partition/PartitionSizeWidget.h
new file mode 100644
index 000000000..028de980d
--- /dev/null
+++ b/src/modules/partition/PartitionSizeWidget.h
@@ -0,0 +1,50 @@
+/* === 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 PARTITIONSIZEWIDGET_H
+#define PARTITIONSIZEWIDGET_H
+
+#include
+
+class Device;
+class Partition;
+
+class PartitionSizeWidget : public QSpinBox
+{
+public:
+ typedef QPair< qint64, qint64 > SectorRange;
+
+ explicit PartitionSizeWidget( QWidget* parent = nullptr );
+ void init( Device* device, Partition* partition );
+
+ SectorRange sectorRange() const;
+
+ bool isDirty() const;
+
+private:
+ Device* m_device = nullptr;
+ Partition* m_partition = nullptr;
+ int m_initialValue;
+
+ qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const;
+
+ qint64 computeMinSector() const;
+ qint64 computeMaxSector() const;
+};
+
+#endif /* PARTITIONSIZEWIDGET_H */