From 0231619c7ccb109dddea17015a1921acb3a33170 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 10:22:08 +0100 Subject: [PATCH 01/16] [partition] Refactor slot for change in action - Let's not go overboard on lambdas, - Needed for others that also want to update the partitioning preview --- src/modules/partition/gui/ChoicePage.cpp | 20 ++++++++++++-------- src/modules/partition/gui/ChoicePage.h | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index ba49bd95d..27364e9bb 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -305,14 +305,7 @@ ChoicePage::setupChoices() m_rightLayout->setStretchFactor( m_previewAfterFrame, 0 ); connect( this, &ChoicePage::actionChosen, - this, [=] - { - Device* currd = selectedDevice(); - if ( currd ) - { - applyActionChoice( currentChoice() ); - } - } ); + this, &ChoicePage::onActionChanged ); CALAMARES_RETRANSLATE( updateSwapChoicesTr( m_eraseSwapChoices ); @@ -412,6 +405,17 @@ ChoicePage::continueApplyDeviceChoice() } +void +ChoicePage::onActionChanged() +{ + Device* currd = selectedDevice(); + if ( currd ) + { + applyActionChoice( currentChoice() ); + } +} + + void ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) { diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 07d052c2d..5a5c5ac34 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -109,6 +109,9 @@ private slots: void onEncryptWidgetStateChanged(); void onHomeCheckBoxStateChanged(); + /** @brief Calls applyActionChoice() as needed. */ + void onActionChanged(); + private: void updateNextEnabled(); void setupChoices(); From 988a0a53882e233397cc2451ba8de3e840a3e9ac Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 10:34:02 +0100 Subject: [PATCH 02/16] [partition] Changing swap choice also changes preview - When selecting *erase*, you may be able to change the swap settings. If so, changing swap settings should change the preview. --- src/modules/partition/gui/ChoicePage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 27364e9bb..17bd06048 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -306,6 +306,8 @@ ChoicePage::setupChoices() connect( this, &ChoicePage::actionChosen, this, &ChoicePage::onActionChanged ); + connect( m_eraseSwapChoices, QOverload::of(&QComboBox::currentIndexChanged), + this, &ChoicePage::onActionChanged ); CALAMARES_RETRANSLATE( updateSwapChoicesTr( m_eraseSwapChoices ); From edc6c6465786e22712d1fde153ff2acfd922d017 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 11:01:16 +0100 Subject: [PATCH 03/16] [partition] Create swap-combo from a set - Alternate way to create swap-combobox, using configuration values rather than an initializer list. --- src/modules/partition/gui/ChoicePage.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 17bd06048..2c68b0180 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -194,6 +194,16 @@ createCombo( std::initializer_list< SwapChoice > l ) return box; } +static inline QComboBox* +createCombo( const QSet< SwapChoice >& s ) +{ + QComboBox* box = new QComboBox; + for ( SwapChoice c : { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap, SwapChoice::ReuseSwap, SwapChoice::SwapFile } ) + if ( s.contains( c ) ) + box->addItem( QString(), c ); + return box; +} + /** * @brief ChoicePage::setupChoices creates PrettyRadioButton objects for the action * choices. From 5945e9584dfdadbe9c9a2777a35fee4ea1cc257a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 11:15:38 +0100 Subject: [PATCH 04/16] [partition] Refactor name-to-enum and back for swap choices --- .../partition/core/PartitionActions.cpp | 43 +++++++++++++++++++ src/modules/partition/core/PartitionActions.h | 3 ++ .../partition/gui/PartitionViewStep.cpp | 27 +----------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index a4f2baa17..8b0303277 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -303,4 +303,47 @@ doReplacePartition( PartitionCoreModule* core, core->dumpQueue(); } +namespace Choices +{ + +SwapChoice +nameToChoice( QString name, bool& ok ) +{ + ok = false; + name = name.toLower(); + + // Each return here first sets ok to true, returns enum value + if ( name == QStringLiteral( "none" ) ) + return( ok=true, SwapChoice::NoSwap ); + else if ( name == QStringLiteral( "small" ) ) + return( ok=true, SwapChoice::SmallSwap); + else if ( name == QStringLiteral( "suspend" ) ) + return( ok=true, SwapChoice::FullSwap ); + else if ( name == QStringLiteral( "reuse" ) ) + return( ok=true, SwapChoice::ReuseSwap ); + else if ( name == QStringLiteral( "file" ) ) + return( ok=true, SwapChoice::SwapFile ); + + ok = false; + return SwapChoice::NoSwap; } + +QString +choiceToName( SwapChoice c ) +{ + switch ( c ) + { + case SwapChoice::NoSwap: return QStringLiteral( "none" ); + case SwapChoice::SmallSwap: return QStringLiteral( "small" ); + case SwapChoice::FullSwap: return QStringLiteral( "suspend" ); + case SwapChoice::ReuseSwap: return QStringLiteral( "reuse" ); + case SwapChoice::SwapFile: return QStringLiteral( "file" ); + } + + cWarning() << "Unknown SwapChoice" << c << "treated as none"; + return QStringLiteral( "none" ); +} + +} // namespace Choices + +} // namespace PartitionActions diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index 5acf444fa..d17852b63 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -43,6 +43,9 @@ namespace Choices SwapFile // use a file (if supported) }; + SwapChoice nameToChoice( QString name, bool& ok ); + QString choiceToName( SwapChoice ); + struct ReplacePartitionOptions { QString defaultFsType; // e.g. "ext4" or "btrfs" diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 0152f8bec..3ec5dcddc 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -471,31 +471,6 @@ PartitionViewStep::onLeave() } -static PartitionActions::Choices::SwapChoice -nameToChoice( QString name, bool& ok ) -{ - ok = false; - name = name.toLower(); - - using namespace PartitionActions::Choices; - - // Each return here first sets ok to true, returns enum value - if ( name == QStringLiteral( "none" ) ) - return( ok=true, SwapChoice::NoSwap ); - else if ( name == QStringLiteral( "small" ) ) - return( ok=true, SwapChoice::SmallSwap); - else if ( name == QStringLiteral( "suspend" ) ) - return( ok=true, SwapChoice::FullSwap ); - else if ( name == QStringLiteral( "reuse" ) ) - return( ok=true, SwapChoice::ReuseSwap ); - else if ( name == QStringLiteral( "file" ) ) - return( ok=true, SwapChoice::SwapFile ); - - ok = false; - return SwapChoice::NoSwap; -} - - void PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -533,7 +508,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) for ( const auto& item : l ) { bool ok = false; - auto v = nameToChoice( item, ok ); + auto v = PartitionActions::Choices::nameToChoice( item, ok ); if ( ok ) choices.insert( v ); } From 2998c2754581f6d9d933757fbaa5c1cfcc9f4d22 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 11:35:35 +0100 Subject: [PATCH 05/16] [partition] Use configured swap choices in choice page --- src/modules/partition/gui/ChoicePage.cpp | 5 +++-- src/modules/partition/gui/ChoicePage.h | 5 ++++- src/modules/partition/gui/PartitionViewStep.cpp | 3 ++- src/modules/partition/gui/PartitionViewStep.h | 5 +++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 2c68b0180..7e2fd0b30 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -72,7 +72,7 @@ using PartitionActions::Choices::SwapChoice; * will show up as a list view. * @param parent the QWidget parent. */ -ChoicePage::ChoicePage( QWidget* parent ) +ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) : QWidget( parent ) , m_nextEnabled( false ) , m_core( nullptr ) @@ -92,6 +92,7 @@ ChoicePage::ChoicePage( QWidget* parent ) , m_bootloaderComboBox( nullptr ) , m_lastSelectedDeviceIndex( -1 ) , m_enableEncryptionWidget( true ) + , m_swapChoices( swapChoices ) { setupUi( this ); @@ -259,7 +260,7 @@ ChoicePage::setupChoices() // Fill up swap options // .. TODO: only if enabled in the config - m_eraseSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } ); + m_eraseSwapChoices = createCombo( m_swapChoices ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); #if 0 diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 5a5c5ac34..a7447c694 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -25,6 +25,7 @@ #include #include "core/OsproberEntry.h" +#include "core/PartitionActions.h" #include #include @@ -43,6 +44,7 @@ class DeviceInfoWidget; class Device; +using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice>; /** * @brief The ChoicePage class is the first page of the partitioning interface. @@ -62,7 +64,7 @@ public: Manual }; - explicit ChoicePage( QWidget* parent = nullptr ); + explicit ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent = nullptr ); virtual ~ChoicePage(); /** @@ -167,6 +169,7 @@ private: QString m_defaultFsType; bool m_enableEncryptionWidget; + SwapChoiceSet m_swapChoices; QMutex m_coreMutex; }; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 3ec5dcddc..d6ca9838b 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -91,7 +91,7 @@ PartitionViewStep::continueLoading() Q_ASSERT( !m_manualPartitionPage ); m_manualPartitionPage = new PartitionPage( m_core ); - m_choicePage = new ChoicePage(); + m_choicePage = new ChoicePage( m_swapChoices ); m_choicePage->init( m_core ); @@ -534,6 +534,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) else choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap ); } + m_swapChoices = choices; // These gs settings seem to be unused (in upstream Calamares) outside of // the partition module itself. diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index dfd0310b3..f23108316 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -26,7 +26,10 @@ #include +#include "core/PartitionActions.h" + #include +#include class ChoicePage; class PartitionPage; @@ -76,6 +79,8 @@ private: PartitionPage* m_manualPartitionPage; QWidget* m_waitingWidget; + + QSet< PartitionActions::Choices::SwapChoice > m_swapChoices; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PartitionViewStepFactory ) From a66ea106d6400ea3a6dc1ccdf3c4dc0872e27678 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 11:40:27 +0100 Subject: [PATCH 06/16] [partition] Missing implicit include --- src/modules/partition/gui/ChoicePage.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index a7447c694..954bc5df1 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -29,6 +29,7 @@ #include #include +#include class QBoxLayout; class QComboBox; From a4566879243164ab43669646bb1a7f304d9a7313 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 12:11:35 +0100 Subject: [PATCH 07/16] [partition] Include all possible SwapChoices in example --- src/modules/partition/partition.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 229ffc32c..f0c2c9149 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -26,10 +26,10 @@ efiSystemPartition: "/boot/efi" # 8.8GiB on disk in the end). userSwapChoices: - none # Create no swap, use no swap - # - reuse # Re-use existing swap, but don't create any + - reuse # Re-use existing swap, but don't create any - small # Up to 4GB - suspend # At least main memory size - # - file # To swap file instead of partition (unsupported right now) + - file # To swap file instead of partition (unsupported right now) # LEGACY SETTINGS (these will generate a warning) # ensureSuspendToDisk: true From 00df8a9fb1dc087a9d4533b82e8261d098399462 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 4 Dec 2018 12:21:02 +0100 Subject: [PATCH 08/16] [partition] Remove unused code - Swap choice for replace and alongside will happen much, much later. --- src/modules/partition/gui/ChoicePage.cpp | 12 ------------ src/modules/partition/gui/ChoicePage.h | 2 -- 2 files changed, 14 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 7e2fd0b30..8c22dac29 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -84,8 +84,6 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) , m_replaceButton( nullptr ) , m_somethingElseButton( nullptr ) , m_eraseSwapChoices( nullptr ) - , m_replaceSwapChoices( nullptr ) - , m_alongsideSwapChoices( nullptr ) , m_deviceInfoWidget( nullptr ) , m_beforePartitionBarsView( nullptr ) , m_beforePartitionLabelsView( nullptr ) @@ -263,14 +261,6 @@ ChoicePage::setupChoices() m_eraseSwapChoices = createCombo( m_swapChoices ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); -#if 0 - m_replaceSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::ReuseSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } ); - m_replaceButton->addOptionsComboBox( m_replaceSwapChoices ); - - m_alongsideSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::ReuseSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } ); - m_alongsideButton->addOptionsComboBox( m_alongsideSwapChoices ); -#endif - m_itemsLayout->addWidget( m_alongsideButton ); m_itemsLayout->addWidget( m_replaceButton ); m_itemsLayout->addWidget( m_eraseButton ); @@ -322,8 +312,6 @@ ChoicePage::setupChoices() CALAMARES_RETRANSLATE( updateSwapChoicesTr( m_eraseSwapChoices ); - updateSwapChoicesTr( m_alongsideSwapChoices ); - updateSwapChoicesTr( m_replaceSwapChoices ); ) } diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 954bc5df1..f4cb5fce5 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -152,8 +152,6 @@ private: PrettyRadioButton* m_replaceButton; PrettyRadioButton* m_somethingElseButton; QComboBox* m_eraseSwapChoices; - QComboBox* m_replaceSwapChoices; - QComboBox* m_alongsideSwapChoices; DeviceInfoWidget* m_deviceInfoWidget; From 4973d00aceea35cc6a676386298fc94278e54e86 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Dec 2018 13:52:23 +0100 Subject: [PATCH 09/16] [partition] Only create drop-down if there is something to select - Swap choices may be 0 (then choose none), 1 (choose that one) or more (currently undecided) --- src/modules/partition/gui/ChoicePage.cpp | 18 +++++++++++++++--- src/modules/partition/gui/ChoicePage.h | 7 ++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 8c22dac29..1321e0d5c 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -65,6 +65,14 @@ using PartitionActions::Choices::SwapChoice; +SwapChoice pickOne( const SwapChoiceSet& s ) +{ + if ( s.count() == 1 ) + for ( auto i = s.begin(); i != s.end(); ++i ) + return *i; // That's the only element + return SwapChoice::NoSwap; +} + /** * @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of * the module loading code path. @@ -90,7 +98,8 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) , m_bootloaderComboBox( nullptr ) , m_lastSelectedDeviceIndex( -1 ) , m_enableEncryptionWidget( true ) - , m_swapChoices( swapChoices ) + , m_availableSwapChoices( swapChoices ) + , m_eraseSwapChoice( pickOne( swapChoices ) ) { setupUi( this ); @@ -258,8 +267,11 @@ ChoicePage::setupChoices() // Fill up swap options // .. TODO: only if enabled in the config - m_eraseSwapChoices = createCombo( m_swapChoices ); - m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); + if ( m_availableSwapChoices.count() > 1 ) + { + m_eraseSwapChoices = createCombo( m_availableSwapChoices ); + m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); + } m_itemsLayout->addWidget( m_alongsideButton ); m_itemsLayout->addWidget( m_replaceButton ); diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index f4cb5fce5..762903987 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -45,7 +45,7 @@ class DeviceInfoWidget; class Device; -using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice>; +using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice >; /** * @brief The ChoicePage class is the first page of the partitioning interface. @@ -151,7 +151,7 @@ private: PrettyRadioButton* m_eraseButton; PrettyRadioButton* m_replaceButton; PrettyRadioButton* m_somethingElseButton; - QComboBox* m_eraseSwapChoices; + QComboBox* m_eraseSwapChoices; // UI, see also m_swapChoices DeviceInfoWidget* m_deviceInfoWidget; @@ -168,7 +168,8 @@ private: QString m_defaultFsType; bool m_enableEncryptionWidget; - SwapChoiceSet m_swapChoices; + SwapChoiceSet m_availableSwapChoices; // What is available + PartitionActions::Choices::SwapChoice m_eraseSwapChoice; // what is selected QMutex m_coreMutex; }; From fee17949245184d8284aeb2c89b549822146f5b8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 18 Jan 2019 15:56:51 +0100 Subject: [PATCH 10/16] [partition] Use NamedEnumTable support code - reduce amount of custom code by using the (new) generic implementation --- .../partition/core/PartitionActions.cpp | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 8b0303277..ae0e42838 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -26,6 +26,8 @@ #include "utils/CalamaresUtilsSystem.h" #include "utils/Units.h" +#include "utils/NamedEnum.h" + #include "JobQueue.h" #include "utils/Logger.h" @@ -305,43 +307,31 @@ doReplacePartition( PartitionCoreModule* core, namespace Choices { +static const NamedEnumTable& +nameTable() +{ + static const NamedEnumTable names{ + { QStringLiteral( "none" ), SwapChoice::NoSwap }, + { QStringLiteral( "small" ), SwapChoice::SmallSwap }, + { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, + { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, + { QStringLiteral( "file" ), SwapChoice::SwapFile } + }; + + return names; +} SwapChoice nameToChoice( QString name, bool& ok ) { - ok = false; - name = name.toLower(); - - // Each return here first sets ok to true, returns enum value - if ( name == QStringLiteral( "none" ) ) - return( ok=true, SwapChoice::NoSwap ); - else if ( name == QStringLiteral( "small" ) ) - return( ok=true, SwapChoice::SmallSwap); - else if ( name == QStringLiteral( "suspend" ) ) - return( ok=true, SwapChoice::FullSwap ); - else if ( name == QStringLiteral( "reuse" ) ) - return( ok=true, SwapChoice::ReuseSwap ); - else if ( name == QStringLiteral( "file" ) ) - return( ok=true, SwapChoice::SwapFile ); - - ok = false; - return SwapChoice::NoSwap; + return nameTable().find( name, ok ); } QString choiceToName( SwapChoice c ) { - switch ( c ) - { - case SwapChoice::NoSwap: return QStringLiteral( "none" ); - case SwapChoice::SmallSwap: return QStringLiteral( "small" ); - case SwapChoice::FullSwap: return QStringLiteral( "suspend" ); - case SwapChoice::ReuseSwap: return QStringLiteral( "reuse" ); - case SwapChoice::SwapFile: return QStringLiteral( "file" ); - } - - cWarning() << "Unknown SwapChoice" << c << "treated as none"; - return QStringLiteral( "none" ); + bool ok = false; + return nameTable().find( c, ok ); } } // namespace Choices From e85fedfd41a590d86a8f97f4e0cdd3a2bf89d567 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 18 Jan 2019 15:57:21 +0100 Subject: [PATCH 11/16] [partition] Drop comment that doesn't apply anymore --- src/modules/partition/gui/ChoicePage.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index ee5ce0c48..56010d988 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -77,8 +77,6 @@ SwapChoice pickOne( const SwapChoiceSet& s ) /** * @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of * the module loading code path. - * @param compactMode if true, the drive selector will be a combo box on top, otherwise it - * will show up as a list view. * @param parent the QWidget parent. */ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) From 8ecae75dc8f51c3ac116c902515a914379d7ebc8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Jan 2019 07:36:50 -0500 Subject: [PATCH 12/16] [partition] Simplify code a little - Document and make pickOne() more correct - Reduce calls to globalStorage(), it doesn't change --- src/modules/partition/gui/ChoicePage.cpp | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 56010d988..8ff028ac4 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -66,12 +66,22 @@ using PartitionActions::Choices::SwapChoice; +/** @brief Given a set of swap choices, return a sensible value from it. + * + * "Sensible" here means: if there is one value, use it; otherwise, use + * NoSwap if there are no choices, or if NoSwap is one of the choices, in the set. + * If that's not possible, any value from the set. + */ SwapChoice pickOne( const SwapChoiceSet& s ) { + if ( s.count() == 0 ) + return SwapChoice::NoSwap; if ( s.count() == 1 ) - for ( auto i = s.begin(); i != s.end(); ++i ) - return *i; // That's the only element - return SwapChoice::NoSwap; + return *( s.begin() ); + if ( s.contains( SwapChoice::NoSwap ) ) + return SwapChoice::NoSwap; + // Here, count > 1 but NoSwap is not a member. + return *( s.begin() ); } /** @@ -102,12 +112,10 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) { setupUi( this ); - m_defaultFsType = Calamares::JobQueue::instance()-> - globalStorage()-> - value( "defaultFileSystemType" ).toString(); - m_enableEncryptionWidget = Calamares::JobQueue::instance()-> - globalStorage()-> - value( "enableLuksAutomatedPartitioning" ).toBool(); + auto gs = Calamares::JobQueue::instance()->globalStorage(); + + m_defaultFsType = gs->value( "defaultFileSystemType" ).toString(); + m_enableEncryptionWidget = gs->value( "enableLuksAutomatedPartitioning" ).toBool(); if ( FileSystem::typeForName( m_defaultFsType ) == FileSystem::Unknown ) m_defaultFsType = "ext4"; @@ -149,7 +157,7 @@ ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent ) m_previewAfterFrame->hide(); m_encryptWidget->hide(); m_reuseHomeCheckBox->hide(); - Calamares::JobQueue::instance()->globalStorage()->insert( "reuseHome", false ); + gs->insert( "reuseHome", false ); } From fbef117fc8f738f0b9a7ab57db5cf3138743f7d5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Jan 2019 07:52:23 -0500 Subject: [PATCH 13/16] [partition] Remove unused code --- src/modules/partition/gui/ChoicePage.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 8ff028ac4..3c9895642 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -200,15 +200,6 @@ ChoicePage::init( PartitionCoreModule* core ) * * No texts are set -- that happens later by the translator functions. */ -static inline QComboBox* -createCombo( std::initializer_list< SwapChoice > l ) -{ - QComboBox* box = new QComboBox; - for ( SwapChoice c : l ) - box->addItem( QString(), c ); - return box; -} - static inline QComboBox* createCombo( const QSet< SwapChoice >& s ) { From 24422b19bdd5e01e7e4e13f37f43f0cf525e01c2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Jan 2019 08:20:01 -0500 Subject: [PATCH 14/16] [partition] Idiomatic connect() usage --- src/modules/partition/gui/ChoicePage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 3c9895642..693f801ce 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -289,7 +289,7 @@ ChoicePage::setupChoices() m_itemsLayout->addStretch(); - connect( m_grp, static_cast< void( QButtonGroup::* )( int, bool ) >( &QButtonGroup::buttonToggled ), + connect( m_grp, QOverload::of( &QButtonGroup::buttonToggled ), this, [ this ]( int id, bool checked ) { if ( checked ) // An action was picked. @@ -1206,7 +1206,7 @@ ChoicePage::createBootloaderComboBox( QWidget* parent ) bcb->setModel( m_core->bootLoaderModel() ); // When the chosen bootloader device changes, we update the choice in the PCM - connect( bcb, static_cast< void (QComboBox::*)(int) >( &QComboBox::currentIndexChanged ), + connect( bcb, QOverload::of( &QComboBox::currentIndexChanged ), this, [this]( int newIndex ) { QComboBox* bcb = qobject_cast< QComboBox* >( sender() ); From aef61a42bc8fa8ac8833d413df6c33565b4a0e77 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Jan 2019 08:22:17 -0500 Subject: [PATCH 15/16] [partition] Tidy up code - avoid possible nullptr dereference on connect() if no swap choices - group retranslations together --- src/modules/partition/gui/ChoicePage.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 693f801ce..800418ade 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -276,10 +276,6 @@ ChoicePage::setupChoices() m_itemsLayout->addWidget( m_eraseButton ); m_somethingElseButton = new PrettyRadioButton; - CALAMARES_RETRANSLATE( - m_somethingElseButton->setText( tr( "Manual partitioning
" - "You can create or resize partitions yourself." ) ); - ) m_somethingElseButton->setIconSize( iconSize ); m_somethingElseButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionManual, CalamaresUtils::Original, @@ -317,10 +313,13 @@ ChoicePage::setupChoices() connect( this, &ChoicePage::actionChosen, this, &ChoicePage::onActionChanged ); - connect( m_eraseSwapChoices, QOverload::of(&QComboBox::currentIndexChanged), - this, &ChoicePage::onActionChanged ); + if ( m_eraseSwapChoices ) + connect( m_eraseSwapChoices, QOverload::of(&QComboBox::currentIndexChanged), + this, &ChoicePage::onActionChanged ); CALAMARES_RETRANSLATE( + m_somethingElseButton->setText( tr( "Manual partitioning
" + "You can create or resize partitions yourself." ) ); updateSwapChoicesTr( m_eraseSwapChoices ); ) } From b913753831357897b6241690a50a76b08ab7647f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Jan 2019 08:54:09 -0500 Subject: [PATCH 16/16] [partition] No need to re-query the current choice --- src/modules/partition/gui/ChoicePage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 800418ade..814f0636d 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -514,7 +514,7 @@ ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice ) case Manual: break; } - updateActionChoicePreview( currentChoice() ); + updateActionChoicePreview( choice ); }