[libcalamares] Start making InstanceDescription a stronger type

- Replace a map-of-strings with a class type.
- For now, doesn't compile.
- Intention is to construct from a YAML / QVariant from the
  *instances* list in `settings.conf`.
This commit is contained in:
Adriaan de Groot 2020-03-13 02:41:42 +01:00
parent 3897bd54df
commit 0e68013bb3
2 changed files with 18 additions and 19 deletions

View File

@ -71,6 +71,10 @@ requireBool( const YAML::Node& config, const char* key, bool d )
namespace Calamares namespace Calamares
{ {
InstanceDescription::InstanceDescription( const QVariantMap& m )
{
}
Settings* Settings::s_instance = nullptr; Settings* Settings::s_instance = nullptr;
Settings* Settings*
@ -134,17 +138,7 @@ interpretInstances( const YAML::Node& node, Settings::InstanceDescriptionList& c
{ {
continue; continue;
} }
QVariantMap instancesVListItemMap = instancesVListItem.toMap(); customInstances.append( InstanceDescription( instancesVListItem.toMap() ) );
Settings::InstanceDescription instanceMap;
for ( auto it = instancesVListItemMap.constBegin(); it != instancesVListItemMap.constEnd(); ++it )
{
if ( it.value().type() != QVariant::String )
{
continue;
}
instanceMap.insert( it.key(), it.value().toString() );
}
customInstances.append( instanceMap );
} }
} }
} }
@ -302,7 +296,7 @@ Settings::init( bool debugMode )
cWarning() << "Calamares::Settings already created"; cWarning() << "Calamares::Settings already created";
return s_instance; return s_instance;
} }
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( debugMode ); QStringList settingsFileCandidatesByPriority = settingsFileCandidates( debugMode );
QFileInfo settingsFile; QFileInfo settingsFile;
@ -340,7 +334,7 @@ Settings::init( bool debugMode )
cError() << "FATAL: no sequence set."; cError() << "FATAL: no sequence set.";
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
return settings; return settings;
} }

View File

@ -32,6 +32,12 @@
namespace Calamares namespace Calamares
{ {
class DLLEXPORT InstanceDescription
{
public:
InstanceDescription( const QVariantMap& );
};
class DLLEXPORT Settings : public QObject class DLLEXPORT Settings : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -42,10 +48,9 @@ public:
static Settings* init( bool debugMode ); static Settings* init( bool debugMode );
/// @brief Explicif filename, debug is always true (for testing) /// @brief Explicif filename, debug is always true (for testing)
static Settings* init( const QString& filename ); static Settings* init( const QString& filename );
QStringList modulesSearchPaths() const; QStringList modulesSearchPaths() const;
using InstanceDescription = QMap< QString, QString >;
using InstanceDescriptionList = QList< InstanceDescription >; using InstanceDescriptionList = QList< InstanceDescription >;
InstanceDescriptionList customModuleInstances() const; InstanceDescriptionList customModuleInstances() const;
@ -55,7 +60,7 @@ public:
QString brandingComponentName() const; QString brandingComponentName() const;
/** @brief Is this a debugging run? /** @brief Is this a debugging run?
* *
* Returns true if Calamares is in debug mode. In debug mode, * Returns true if Calamares is in debug mode. In debug mode,
* modules and settings are loaded from more locations, to help * modules and settings are loaded from more locations, to help
* development and debugging. * development and debugging.
@ -63,7 +68,7 @@ public:
bool debugMode() const { return m_debug; } bool debugMode() const { return m_debug; }
/** @brief Distinguish "install" from "OEM" modes. /** @brief Distinguish "install" from "OEM" modes.
* *
* Returns true in "install" mode, which is where actions happen * Returns true in "install" mode, which is where actions happen
* in a chroot -- the target system, which exists separately from * in a chroot -- the target system, which exists separately from
* the source system. In "OEM" mode, returns false and most actions * the source system. In "OEM" mode, returns false and most actions
@ -72,13 +77,13 @@ public:
bool doChroot() const { return m_doChroot; } bool doChroot() const { return m_doChroot; }
/** @brief Global setting of prompt-before-install. /** @brief Global setting of prompt-before-install.
* *
* Returns true when the configuration is such that the user * Returns true when the configuration is such that the user
* should be prompted one-last-time before any action is taken * should be prompted one-last-time before any action is taken
* that really affects the machine. * that really affects the machine.
*/ */
bool showPromptBeforeExecution() const { return m_promptInstall; } bool showPromptBeforeExecution() const { return m_promptInstall; }
/** @brief Distinguish between "install" and "setup" modes. /** @brief Distinguish between "install" and "setup" modes.
* *
* This influences user-visible strings, for instance using the * This influences user-visible strings, for instance using the