From 06e30b829099e9576217cf540b7aa13d95bce51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 7 Aug 2014 13:05:16 +0200 Subject: [PATCH] Remove PartitionSizeWidget --- src/modules/partition/CMakeLists.txt | 1 - src/modules/partition/PartitionSizeWidget.cpp | 100 ------------------ src/modules/partition/PartitionSizeWidget.h | 50 --------- 3 files changed, 151 deletions(-) delete mode 100644 src/modules/partition/PartitionSizeWidget.cpp delete mode 100644 src/modules/partition/PartitionSizeWidget.h diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 0b99a9dff..7910f39a4 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -41,7 +41,6 @@ calamares_add_plugin( partition PartitionPage.cpp PartitionPreview.cpp PartitionSizeController.cpp - PartitionSizeWidget.cpp PartitionViewStep.cpp PMUtils.cpp ResizePartitionJob.cpp diff --git a/src/modules/partition/PartitionSizeWidget.cpp b/src/modules/partition/PartitionSizeWidget.cpp deleted file mode 100644 index 485770138..000000000 --- a/src/modules/partition/PartitionSizeWidget.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* === 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 deleted file mode 100644 index 028de980d..000000000 --- a/src/modules/partition/PartitionSizeWidget.h +++ /dev/null @@ -1,50 +0,0 @@ -/* === 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 */