[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.
This commit is contained in:
Adriaan de Groot 2018-09-13 06:23:33 -04:00
parent 846e496d76
commit 5136021416
3 changed files with 30 additions and 22 deletions

View File

@ -50,6 +50,23 @@ void doReplacePartition( PartitionCoreModule* core,
Device* dev, Device* dev,
Partition* partition, Partition* partition,
const QString& luksPassphrase = QString() ); 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 #endif // PARTITIONACTIONS_H

View File

@ -59,7 +59,7 @@
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
using PartitionActions::Choices::SwapChoice;
/** /**
* @brief ChoicePage::ChoicePage is the default constructor. Called on startup as part of * @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. * No texts are set -- that happens later by the translator functions.
*/ */
static inline QComboBox* static inline QComboBox*
createCombo( std::initializer_list< ChoicePage::SwapChoice > l ) createCombo( std::initializer_list< SwapChoice > l )
{ {
QComboBox* box = new QComboBox; QComboBox* box = new QComboBox;
for ( ChoicePage::SwapChoice c : l ) for ( SwapChoice c : l )
box->addItem( QString(), c ); box->addItem( QString(), c );
return box; return box;
} }
@ -245,13 +245,13 @@ ChoicePage::setupChoices()
// Fill up swap options // Fill up swap options
// .. TODO: only if enabled in the config // .. 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_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_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_alongsideButton->addOptionsComboBox( m_alongsideSwapChoices );
m_itemsLayout->addWidget( m_alongsideButton ); m_itemsLayout->addWidget( m_alongsideButton );
@ -1431,7 +1431,7 @@ ChoicePage::updateSwapChoicesTr(QComboBox* box)
if ( !box ) if ( !box )
return; 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 ) for ( int index = 0; index < box->count(); ++index )
{ {
bool ok = false; bool ok = false;
@ -1440,23 +1440,23 @@ ChoicePage::updateSwapChoicesTr(QComboBox* box)
switch ( value = box->itemData( index ).toInt( &ok ) ) switch ( value = box->itemData( index ).toInt( &ok ) )
{ {
// case 0: // case 0:
case NoSwap: case SwapChoice::NoSwap:
// toInt() returns 0 on failure, so check for ok // toInt() returns 0 on failure, so check for ok
if ( ok ) // It was explicitly set to 0 if ( ok ) // It was explicitly set to 0
box->setItemText( index, tr( "No Swap" ) ); box->setItemText( index, tr( "No Swap" ) );
else else
cWarning() << "Box item" << index << box->itemText( index ) << "has non-integer role."; cWarning() << "Box item" << index << box->itemText( index ) << "has non-integer role.";
break; break;
case ReuseSwap: case SwapChoice::ReuseSwap:
box->setItemText( index, tr( "Reuse Swap" ) ); box->setItemText( index, tr( "Reuse Swap" ) );
break; break;
case SmallSwap: case SwapChoice::SmallSwap:
box->setItemText( index, tr( "Swap (no Hibernate)" ) ); box->setItemText( index, tr( "Swap (no Hibernate)" ) );
break; break;
case FullSwap: case SwapChoice::FullSwap:
box->setItemText( index, tr( "Swap (with Hibernate)" ) ); box->setItemText( index, tr( "Swap (with Hibernate)" ) );
break; break;
case SwapFile: case SwapChoice::SwapFile:
box->setItemText( index, tr( "Swap to file" ) ); box->setItemText( index, tr( "Swap to file" ) );
break; break;
default: default:

View File

@ -62,15 +62,6 @@ public:
Manual 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 ); explicit ChoicePage( QWidget* parent = nullptr );
virtual ~ChoicePage(); virtual ~ChoicePage();