From 513602141660deab76b228e7d6a741461e9d920f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Sep 2018 06:23:33 -0400 Subject: [PATCH] [partition] Move SwapChoice to another namespace - The choice of swap needs to be handled in more places, so make the enum available in the partition module core instead of just inside the choice page. --- src/modules/partition/core/PartitionActions.h | 19 ++++++++++++++- src/modules/partition/gui/ChoicePage.cpp | 24 +++++++++---------- src/modules/partition/gui/ChoicePage.h | 9 ------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index bb624552f..8312d582b 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -50,6 +50,23 @@ void doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition, const QString& luksPassphrase = QString() ); -} + +/** @brief Namespace for enums + * + * This namespace houses non-class enums..... + */ +namespace Choices +{ + /** @brief Ccchoice of swap (size and type) */ + enum SwapChoice + { + NoSwap, // don't create any swap, don't use any + ReuseSwap, // don't create, but do use existing + SmallSwap, // up to 8GiB of swap + FullSwap, // ensureSuspendToDisk -- at least RAM size + SwapFile // use a file (if supported) + }; +} // namespace Choices +} // namespace PartitionActions #endif // PARTITIONACTIONS_H diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 4c5f7ff65..82302ac4c 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -59,7 +59,7 @@ #include #include - +using PartitionActions::Choices::SwapChoice; /** * @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of @@ -182,10 +182,10 @@ ChoicePage::init( PartitionCoreModule* core ) * No texts are set -- that happens later by the translator functions. */ static inline QComboBox* -createCombo( std::initializer_list< ChoicePage::SwapChoice > l ) +createCombo( std::initializer_list< SwapChoice > l ) { QComboBox* box = new QComboBox; - for ( ChoicePage::SwapChoice c : l ) + for ( SwapChoice c : l ) box->addItem( QString(), c ); return box; } @@ -245,13 +245,13 @@ ChoicePage::setupChoices() // Fill up swap options // .. TODO: only if enabled in the config - m_eraseSwapChoices = createCombo( { NoSwap, SmallSwap, FullSwap } ); + m_eraseSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice:: FullSwap } ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoices ); - m_replaceSwapChoices = createCombo( { NoSwap, ReuseSwap, SmallSwap, FullSwap } ); + m_replaceSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::ReuseSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } ); m_replaceButton->addOptionsComboBox( m_replaceSwapChoices ); - m_alongsideSwapChoices = createCombo( { NoSwap, ReuseSwap, SmallSwap, FullSwap } ); + m_alongsideSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::ReuseSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } ); m_alongsideButton->addOptionsComboBox( m_alongsideSwapChoices ); m_itemsLayout->addWidget( m_alongsideButton ); @@ -1431,7 +1431,7 @@ ChoicePage::updateSwapChoicesTr(QComboBox* box) if ( !box ) return; - static_assert(NoSwap == 0, "Enum values out-of-sync"); + static_assert(SwapChoice::NoSwap == 0, "Enum values out-of-sync"); for ( int index = 0; index < box->count(); ++index ) { bool ok = false; @@ -1440,23 +1440,23 @@ ChoicePage::updateSwapChoicesTr(QComboBox* box) switch ( value = box->itemData( index ).toInt( &ok ) ) { // case 0: - case NoSwap: + case SwapChoice::NoSwap: // toInt() returns 0 on failure, so check for ok if ( ok ) // It was explicitly set to 0 box->setItemText( index, tr( "No Swap" ) ); else cWarning() << "Box item" << index << box->itemText( index ) << "has non-integer role."; break; - case ReuseSwap: + case SwapChoice::ReuseSwap: box->setItemText( index, tr( "Reuse Swap" ) ); break; - case SmallSwap: + case SwapChoice::SmallSwap: box->setItemText( index, tr( "Swap (no Hibernate)" ) ); break; - case FullSwap: + case SwapChoice::FullSwap: box->setItemText( index, tr( "Swap (with Hibernate)" ) ); break; - case SwapFile: + case SwapChoice::SwapFile: box->setItemText( index, tr( "Swap to file" ) ); break; default: diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index a8ff3a330..07d052c2d 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -62,15 +62,6 @@ public: Manual }; - enum SwapChoice - { - NoSwap, // don't create any swap, don't use any - ReuseSwap, // don't create, but do use existing - SmallSwap, // up to 8GiB of swap - FullSwap, // ensureSuspendToDisk -- at least RAM size - SwapFile // use a file (if supported) - }; - explicit ChoicePage( QWidget* parent = nullptr ); virtual ~ChoicePage();