Merge branch 'improve-swap-ui' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2019-01-18 18:11:25 +01:00
commit 067ca16112
7 changed files with 96 additions and 33 deletions

View File

@ -26,6 +26,8 @@
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Units.h"
#include "utils/NamedEnum.h"
#include "JobQueue.h"
#include "utils/Logger.h"
@ -303,4 +305,35 @@ doReplacePartition( PartitionCoreModule* core,
core->dumpQueue();
}
namespace Choices
{
static const NamedEnumTable<SwapChoice>&
nameTable()
{
static const NamedEnumTable<SwapChoice> 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 )
{
return nameTable().find( name, ok );
}
QString
choiceToName( SwapChoice c )
{
bool ok = false;
return nameTable().find( c, ok );
}
} // namespace Choices
} // namespace PartitionActions

View File

@ -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"

View File

@ -66,14 +66,20 @@
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.
* @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( QWidget* parent )
ChoicePage::ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent )
: QWidget( parent )
, m_nextEnabled( false )
, m_core( nullptr )
@ -85,14 +91,14 @@ ChoicePage::ChoicePage( 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 )
, m_bootloaderComboBox( nullptr )
, m_lastSelectedDeviceIndex( -1 )
, m_enableEncryptionWidget( true )
, m_availableSwapChoices( swapChoices )
, m_eraseSwapChoice( pickOne( swapChoices ) )
{
setupUi( this );
@ -195,6 +201,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.
@ -250,16 +266,11 @@ ChoicePage::setupChoices()
// Fill up swap options
// .. TODO: only if enabled in the config
m_eraseSwapChoices = createCombo( { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap } );
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
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 );
@ -306,19 +317,12 @@ ChoicePage::setupChoices()
m_rightLayout->setStretchFactor( m_previewAfterFrame, 0 );
connect( this, &ChoicePage::actionChosen,
this, [=]
{
Device* currd = selectedDevice();
if ( currd )
{
applyActionChoice( currentChoice() );
}
} );
this, &ChoicePage::onActionChanged );
connect( m_eraseSwapChoices, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &ChoicePage::onActionChanged );
CALAMARES_RETRANSLATE(
updateSwapChoicesTr( m_eraseSwapChoices );
updateSwapChoicesTr( m_alongsideSwapChoices );
updateSwapChoicesTr( m_replaceSwapChoices );
)
}
@ -413,6 +417,17 @@ ChoicePage::continueApplyDeviceChoice()
}
void
ChoicePage::onActionChanged()
{
Device* currd = selectedDevice();
if ( currd )
{
applyActionChoice( currentChoice() );
}
}
void
ChoicePage::applyActionChoice( ChoicePage::InstallChoice choice )
{

View File

@ -26,9 +26,11 @@
#include <QWidget>
#include "core/OsproberEntry.h"
#include "core/PartitionActions.h"
#include <QMutex>
#include <QPointer>
#include <QSet>
class QBoxLayout;
class QComboBox;
@ -44,6 +46,7 @@ class DeviceInfoWidget;
class Device;
using SwapChoiceSet = QSet< PartitionActions::Choices::SwapChoice >;
/**
* @brief The ChoicePage class is the first page of the partitioning interface.
@ -63,7 +66,7 @@ public:
Manual
};
explicit ChoicePage( QWidget* parent = nullptr );
explicit ChoicePage( const SwapChoiceSet& swapChoices, QWidget* parent = nullptr );
virtual ~ChoicePage();
/**
@ -113,6 +116,9 @@ private slots:
void onEncryptWidgetStateChanged();
void onHomeCheckBoxStateChanged();
/** @brief Calls applyActionChoice() as needed. */
void onActionChanged();
private:
void updateNextEnabled();
void setupChoices();
@ -149,9 +155,7 @@ private:
PrettyRadioButton* m_eraseButton;
PrettyRadioButton* m_replaceButton;
PrettyRadioButton* m_somethingElseButton;
QComboBox* m_eraseSwapChoices;
QComboBox* m_replaceSwapChoices;
QComboBox* m_alongsideSwapChoices;
QComboBox* m_eraseSwapChoices; // UI, see also m_swapChoices
DeviceInfoWidget* m_deviceInfoWidget;
@ -168,6 +172,8 @@ private:
QString m_defaultFsType;
bool m_enableEncryptionWidget;
SwapChoiceSet m_availableSwapChoices; // What is available
PartitionActions::Choices::SwapChoice m_eraseSwapChoice; // what is selected
QMutex m_coreMutex;
};

View File

@ -93,7 +93,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 );
@ -586,7 +586,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 );
}
@ -612,6 +612,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.

View File

@ -26,7 +26,10 @@
#include <PluginDllMacro.h>
#include "core/PartitionActions.h"
#include <QObject>
#include <QSet>
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 )

View File

@ -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