2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-04-17 00:24:32 +02:00
|
|
|
*
|
2020-07-30 10:26:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2020-04-17 00:24:32 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2020-04-17 00:24:32 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Config.h"
|
2020-05-18 13:07:12 +02:00
|
|
|
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2020-05-18 14:03:31 +02:00
|
|
|
#include "utils/Logger.h"
|
2020-05-18 13:07:12 +02:00
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
|
|
|
Config::Config( QObject* parent )
|
|
|
|
: QObject( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-18 14:12:50 +02:00
|
|
|
static PartitionActions::Choices::SwapChoiceSet
|
2020-05-18 14:03:31 +02:00
|
|
|
getSwapChoices( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
// SWAP SETTINGS
|
|
|
|
//
|
|
|
|
// This is a bit convoluted because there's legacy settings to handle as well
|
|
|
|
// as the new-style list of choices, with mapping back-and-forth.
|
|
|
|
if ( configurationMap.contains( "userSwapChoices" )
|
|
|
|
&& ( configurationMap.contains( "ensureSuspendToDisk" ) || configurationMap.contains( "neverCreateSwap" ) ) )
|
|
|
|
{
|
|
|
|
cError() << "Partition-module configuration mixes old- and new-style swap settings.";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( configurationMap.contains( "ensureSuspendToDisk" ) )
|
|
|
|
{
|
|
|
|
cWarning() << "Partition-module setting *ensureSuspendToDisk* is deprecated.";
|
|
|
|
}
|
|
|
|
bool ensureSuspendToDisk = CalamaresUtils::getBool( configurationMap, "ensureSuspendToDisk", true );
|
|
|
|
|
|
|
|
if ( configurationMap.contains( "neverCreateSwap" ) )
|
|
|
|
{
|
|
|
|
cWarning() << "Partition-module setting *neverCreateSwap* is deprecated.";
|
|
|
|
}
|
|
|
|
bool neverCreateSwap = CalamaresUtils::getBool( configurationMap, "neverCreateSwap", false );
|
|
|
|
|
2020-05-18 14:12:50 +02:00
|
|
|
PartitionActions::Choices::SwapChoiceSet choices; // Available swap choices
|
2020-05-18 14:03:31 +02:00
|
|
|
if ( configurationMap.contains( "userSwapChoices" ) )
|
|
|
|
{
|
|
|
|
// We've already warned about overlapping settings with the
|
|
|
|
// legacy *ensureSuspendToDisk* and *neverCreateSwap*.
|
|
|
|
QStringList l = configurationMap[ "userSwapChoices" ].toStringList();
|
|
|
|
|
|
|
|
for ( const auto& item : l )
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2020-07-30 10:51:48 +02:00
|
|
|
auto v = PartitionActions::Choices::swapChoiceNames().find( item, ok );
|
2020-05-18 14:03:31 +02:00
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
choices.insert( v );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( choices.isEmpty() )
|
|
|
|
{
|
|
|
|
cWarning() << "Partition-module configuration for *userSwapChoices* is empty:" << l;
|
|
|
|
choices.insert( PartitionActions::Choices::SwapChoice::FullSwap );
|
|
|
|
}
|
|
|
|
|
|
|
|
// suspend if it's one of the possible choices; suppress swap only if it's
|
|
|
|
// the **only** choice available.
|
|
|
|
ensureSuspendToDisk = choices.contains( PartitionActions::Choices::SwapChoice::FullSwap );
|
|
|
|
neverCreateSwap = ( choices.count() == 1 ) && choices.contains( PartitionActions::Choices::SwapChoice::NoSwap );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Convert the legacy settings into a single setting for now.
|
|
|
|
if ( neverCreateSwap )
|
|
|
|
{
|
|
|
|
choices.insert( PartitionActions::Choices::SwapChoice::NoSwap );
|
|
|
|
}
|
|
|
|
else if ( ensureSuspendToDisk )
|
|
|
|
{
|
|
|
|
choices.insert( PartitionActions::Choices::SwapChoice::FullSwap );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
choices.insert( PartitionActions::Choices::SwapChoice::SmallSwap );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not all are supported right now // FIXME
|
|
|
|
static const char unsupportedSetting[] = "Partition-module does not support *userSwapChoices* setting";
|
|
|
|
|
|
|
|
#define COMPLAIN_UNSUPPORTED( x ) \
|
|
|
|
if ( choices.contains( x ) ) \
|
|
|
|
{ \
|
2020-07-30 10:51:48 +02:00
|
|
|
bool bogus = false; \
|
|
|
|
cWarning() << unsupportedSetting << PartitionActions::Choices::swapChoiceNames().find( x, bogus ); \
|
2020-05-18 14:03:31 +02:00
|
|
|
choices.remove( x ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap )
|
|
|
|
#undef COMPLAIN_UNSUPPORTED
|
|
|
|
|
|
|
|
return choices;
|
|
|
|
}
|
|
|
|
|
2020-09-29 14:00:49 +02:00
|
|
|
void
|
|
|
|
Config::setInstallChoice( int c )
|
|
|
|
{
|
|
|
|
if ( ( c < PartitionActions::Choices::InstallChoice::NoChoice )
|
|
|
|
|| ( c > PartitionActions::Choices::InstallChoice::Manual ) )
|
|
|
|
{
|
|
|
|
cWarning() << "Invalid install choice (int)" << c;
|
|
|
|
c = PartitionActions::Choices::InstallChoice::NoChoice;
|
|
|
|
}
|
|
|
|
setInstallChoice( static_cast< PartitionActions::Choices::InstallChoice >( c ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::setInstallChoice( PartitionActions::Choices::InstallChoice c )
|
|
|
|
{
|
|
|
|
if ( c != m_installChoice )
|
|
|
|
{
|
|
|
|
m_installChoice = c;
|
|
|
|
emit installChoiceChanged( c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-18 13:07:12 +02:00
|
|
|
void
|
|
|
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
// Settings that overlap with the Welcome module
|
|
|
|
m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 );
|
2020-05-18 14:03:31 +02:00
|
|
|
m_swapChoices = getSwapChoices( configurationMap );
|
2020-07-30 11:36:59 +02:00
|
|
|
|
|
|
|
bool nameFound = false; // In the name table (ignored, falls back to first entry in table)
|
2020-08-22 01:19:58 +02:00
|
|
|
m_initialInstallChoice = PartitionActions::Choices::installChoiceNames().find(
|
|
|
|
CalamaresUtils::getString( configurationMap, "initialPartitioningChoice" ), nameFound );
|
2020-09-29 14:00:49 +02:00
|
|
|
setInstallChoice( m_initialInstallChoice );
|
|
|
|
|
2020-09-28 15:32:47 +02:00
|
|
|
m_initialSwapChoice = PartitionActions::Choices::swapChoiceNames().find(
|
|
|
|
CalamaresUtils::getString( configurationMap, "initialSwapChoice" ), nameFound );
|
|
|
|
if ( !m_swapChoices.contains( m_initialSwapChoice ) )
|
|
|
|
{
|
|
|
|
cWarning() << "Configuration for *initialSwapChoice* is not one of the *userSwapChoices*";
|
|
|
|
m_initialSwapChoice = PartitionActions::Choices::pickOne( m_swapChoices );
|
|
|
|
}
|
2020-05-18 13:07:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|