[libcalamares] Add a base class for Config-objects

This is an optional (until 3.3) base class, which can handle
Presets consistently for configurations.
main
Adriaan de Groot 4 years ago
parent 381a4f9b53
commit 0be5e04c2e

@ -48,6 +48,7 @@ set( libSources
locale/TranslatableString.cpp
# Modules
modulesystem/Config.cpp
modulesystem/Descriptor.cpp
modulesystem/InstanceKey.cpp
modulesystem/Module.cpp

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

@ -0,0 +1,60 @@
/* === 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.
*
*/
#ifndef CALAMARES_MODULESYSTEM_CONFIG_H
#define CALAMARES_MODULESYSTEM_CONFIG_H
#include "DllMacro.h"
#include <QObject>
#include <QStringList>
#include <QVariantMap>
#include <memory>
namespace Calamares
{
namespace ModuleSystem
{
/** @brief Base class for Config-objects
*
* This centralizes the things every Config-object should
* do and provides one source of preset-data. A Config-object
* for a module can **optionally** inherit from this class
* to get presets-support.
*
* TODO:3.3 This is not optional
* TODO:3.3 Put consistent i18n for Configurations in here too
*/
class DLLEXPORT Config : public QObject
{
public:
Config( QObject* parent = nullptr );
~Config() override;
/** @brief Set the configuration from the config file
*
* Subclasses must implement this to load configuration data;
* that subclass **should** also call loadPresets() with the
* same map, to pick up the "presets" key consistently.
*/
virtual void setConfigurationMap( const QVariantMap& ) = 0;
protected:
void loadPresets( const QVariantMap& configurationMap );
void loadPresets( const QVariantMap& configurationMap, const QStringList& recognizedKeys );
private:
class Private;
std::unique_ptr< Private > d;
};
} // namespace ModuleSystem
} // namespace Calamares
#endif
Loading…
Cancel
Save