[libcalamares] Add a base class for Config-objects

This is an optional (until 3.3) base class, which can handle
Presets consistently for configurations.
This commit is contained in:
Adriaan de Groot 2021-03-12 13:49:37 +01:00
parent 381a4f9b53
commit 0be5e04c2e
3 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,64 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "Config.h"
#include "Preset.h"
#include "utils/Variant.h"
namespace Calamares
{
namespace ModuleSystem
{
class Config::Private
{
public:
std::unique_ptr< Presets > m_presets;
};
Config::Config( QObject* parent )
: QObject( parent )
, d( std::make_unique< Private >() )
{
}
Config::~Config() {}
void
Config::loadPresets( const QVariantMap& configurationMap )
{
const QString key( "presets" );
if ( !configurationMap.contains( key ) )
{
d->m_presets.reset();
return;
}
bool bogus = true;
d->m_presets = std::make_unique< Presets >( CalamaresUtils::getSubMap( configurationMap, key, bogus ) );
}
void
Config::loadPresets( const QVariantMap& configurationMap, const QStringList& recognizedKeys )
{
const QString key( "presets" );
if ( !configurationMap.contains( key ) )
{
d->m_presets.reset();
return;
}
bool bogus = true;
d->m_presets
= std::make_unique< Presets >( CalamaresUtils::getSubMap( configurationMap, key, bogus ), recognizedKeys );
}
} // namespace ModuleSystem
} // namespace Calamares