From a381d6794f0e013ff9ef99d8b3352674fb456920 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 May 2020 13:07:12 +0200 Subject: [PATCH] [partition] Migrate required-storage setting to Config object - Create and use the config object in the view step - Add setConfigurationMap() to Config --- src/modules/partition/core/Config.cpp | 28 +++++++++++++++++++ src/modules/partition/core/Config.h | 8 +++--- .../partition/gui/PartitionViewStep.cpp | 16 ++++------- src/modules/partition/gui/PartitionViewStep.h | 5 ++-- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/modules/partition/core/Config.cpp b/src/modules/partition/core/Config.cpp index 50dd052d0..5026169fb 100644 --- a/src/modules/partition/core/Config.cpp +++ b/src/modules/partition/core/Config.cpp @@ -17,3 +17,31 @@ */ #include "Config.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/Variant.h" + +Config::Config( QObject* parent ) + : QObject( parent ) +{ +} + +void +Config::setConfigurationMap( const QVariantMap& configurationMap ) +{ + // Settings that overlap with the Welcome module + m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 ); +} + +void +Config::updateGlobalStorage() const +{ + // If there's no setting (e.g. from the welcome page) for required storage + // then use ours, if it was set. + auto* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + if ( m_requiredStorageGiB >= 0.0 && gs && !gs->contains( "requiredStorageGiB" ) ) + { + gs->insert( "requiredStorageGiB", m_requiredStorageGiB ); + } +} diff --git a/src/modules/partition/core/Config.h b/src/modules/partition/core/Config.h index c9b2bd289..2543700be 100644 --- a/src/modules/partition/core/Config.h +++ b/src/modules/partition/core/Config.h @@ -29,14 +29,14 @@ class Config : public QObject Q_OBJECT public: - Config() = default; + Config( QObject* parent ); virtual ~Config() = default; - using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice >; + void setConfigurationMap( const QVariantMap& ); + + void updateGlobalStorage() const; private: - SwapChoiceSet m_swapChoices; - qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module }; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index a583a4b96..02666097b 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -22,6 +22,7 @@ #include "gui/PartitionViewStep.h" +#include "core/Config.h" #include "core/DeviceModel.h" #include "core/KPMHelpers.h" #include "core/OsproberEntry.h" @@ -64,11 +65,11 @@ PartitionViewStep::PartitionViewStep( QObject* parent ) : Calamares::ViewStep( parent ) + , m_config( new Config( this ) ) , m_core( nullptr ) , m_widget( new QStackedWidget() ) , m_choicePage( nullptr ) , m_manualPartitionPage( nullptr ) - , m_requiredStorageGiB( 0.0 ) { m_widget->setContentsMargins( 0, 0, 0, 0 ); @@ -385,13 +386,7 @@ PartitionViewStep::isAtEnd() const void PartitionViewStep::onActivate() { - // If there's no setting (e.g. from the welcome page) for required storage - // then use ours, if it was set. - auto* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; - if ( m_requiredStorageGiB >= 0.0 && gs && !gs->contains( "requiredStorageGiB" ) ) - { - gs->insert( "requiredStorageGiB", m_requiredStorageGiB ); - } + m_config->updateGlobalStorage(); // if we're coming back to PVS from the next VS if ( m_widget->currentWidget() == m_choicePage && m_choicePage->currentChoice() == ChoicePage::Alongside ) @@ -525,6 +520,8 @@ PartitionViewStep::onLeave() void PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { + m_config->setConfigurationMap( configurationMap ); + // Copy the efiSystemPartition setting to the global storage. It is needed not only in // the EraseDiskPage, but also in the bootloader configuration modules (grub, bootloader). Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); @@ -635,9 +632,6 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_swapChoices = choices; - // Settings that overlap with the Welcome module - m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 ); - // These gs settings seem to be unused (in upstream Calamares) outside of // the partition module itself. gs->insert( "ensureSuspendToDisk", ensureSuspendToDisk ); diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 63d11c816..efe2cb343 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -32,6 +32,7 @@ #include class ChoicePage; +class Config; class PartitionPage; class PartitionCoreModule; class QStackedWidget; @@ -78,6 +79,8 @@ private: void initPartitionCoreModule(); void continueLoading(); + Config* m_config; + PartitionCoreModule* m_core; QStackedWidget* m_widget; ChoicePage* m_choicePage; @@ -87,8 +90,6 @@ private: QFutureWatcher* m_future; QSet< PartitionActions::Choices::SwapChoice > m_swapChoices; - - qreal m_requiredStorageGiB; // May duplicate setting in the welcome module }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PartitionViewStepFactory )