mirror of https://github.com/cutefishos/calamares
Merge branch 'issue-1297' into calamares
This does **not** result issue-1297, but brings in some prep-work and pleasant clean-ups.main
commit
b1b81f27cc
@ -0,0 +1,141 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
Config::Config( QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
}
|
||||
|
||||
static PartitionActions::Choices::SwapChoiceSet
|
||||
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 );
|
||||
|
||||
PartitionActions::Choices::SwapChoiceSet choices; // Available swap choices
|
||||
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;
|
||||
auto v = PartitionActions::Choices::swapChoiceNames().find( item, ok );
|
||||
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 ) ) \
|
||||
{ \
|
||||
bool bogus = false; \
|
||||
cWarning() << unsupportedSetting << PartitionActions::Choices::swapChoiceNames().find( x, bogus ); \
|
||||
choices.remove( x ); \
|
||||
}
|
||||
|
||||
COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::SwapFile )
|
||||
COMPLAIN_UNSUPPORTED( PartitionActions::Choices::SwapChoice::ReuseSwap )
|
||||
#undef COMPLAIN_UNSUPPORTED
|
||||
|
||||
return choices;
|
||||
}
|
||||
|
||||
void
|
||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
// Settings that overlap with the Welcome module
|
||||
m_requiredStorageGiB = CalamaresUtils::getDouble( configurationMap, "requiredStorage", -1.0 );
|
||||
m_swapChoices = getSwapChoices( configurationMap );
|
||||
|
||||
bool nameFound = false; // In the name table (ignored, falls back to first entry in table)
|
||||
m_initialInstallChoice = PartitionActions::Choices::installChoiceNames().find( CalamaresUtils::getString( configurationMap, "initialPartitioningChoice" ), nameFound );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PARTITION_CONFIG_H
|
||||
#define PARTITION_CONFIG_H
|
||||
|
||||
#include "core/PartitionActions.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
|
||||
class Config : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Config( QObject* parent );
|
||||
virtual ~Config() = default;
|
||||
|
||||
void setConfigurationMap( const QVariantMap& );
|
||||
void updateGlobalStorage() const;
|
||||
|
||||
PartitionActions::Choices::SwapChoiceSet swapChoices() const { return m_swapChoices; }
|
||||
|
||||
/**
|
||||
* @brief What kind of installation (partitioning) is requested **initially**?
|
||||
*
|
||||
* @return the partitioning choice (may by @c NoChoice)
|
||||
*/
|
||||
PartitionActions::Choices::InstallChoice initialInstallChoice() const { return m_initialInstallChoice; }
|
||||
|
||||
private:
|
||||
PartitionActions::Choices::SwapChoiceSet m_swapChoices;
|
||||
PartitionActions::Choices::InstallChoice m_initialInstallChoice = PartitionActions::Choices::NoChoice;
|
||||
qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue