[libcalamares] Better type for the list of InstanceKeys

- *sequence* lists module instance keys; make the stored type of
  those keys InstanceKey instead of QString
This commit is contained in:
Adriaan de Groot 2020-08-11 15:27:30 +02:00
parent b23dbd47c7
commit 253e5610af
3 changed files with 18 additions and 10 deletions

View File

@ -210,7 +210,13 @@ interpretSequence( const YAML::Node& node, Settings::ModuleSequence& moduleSeque
} }
QStringList thisActionRoster = sequenceVListItem.toMap().value( thisActionS ).toStringList(); QStringList thisActionRoster = sequenceVListItem.toMap().value( thisActionS ).toStringList();
moduleSequence.append( qMakePair( thisAction, thisActionRoster ) ); Calamares::ModuleSystem::InstanceKeyList roster;
roster.reserve( thisActionRoster.count() );
std::transform( thisActionRoster.constBegin(),
thisActionRoster.constEnd(),
std::back_inserter( roster ),
[]( const QString& s ) { return Calamares::ModuleSystem::InstanceKey::fromString( s ); } );
moduleSequence.append( qMakePair( thisAction, roster ) );
} }
} }
else else
@ -262,24 +268,23 @@ Settings::validateSequence()
// Check the sequence against the existing instances (which so far are only custom) // Check the sequence against the existing instances (which so far are only custom)
for ( const auto& step : m_modulesSequence ) for ( const auto& step : m_modulesSequence )
{ {
for ( const auto& instance : step.second ) for ( const auto& instanceKey : step.second )
{ {
Calamares::ModuleSystem::InstanceKey k = Calamares::ModuleSystem::InstanceKey::fromString( instance ); if ( !instanceKey.isValid() )
if ( !k.isValid() )
{ {
cWarning() << "Invalid instance key in *sequence*," << instance; cWarning() << "Invalid instance key in *sequence*," << instanceKey;
continue; continue;
} }
targetKey = k; targetKey = instanceKey;
const auto it = std::find_if( m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder ); const auto it = std::find_if( m_moduleInstances.constBegin(), m_moduleInstances.constEnd(), moduleFinder );
if ( it == m_moduleInstances.constEnd() ) if ( it == m_moduleInstances.constEnd() )
{ {
if ( k.isCustom() ) if ( instanceKey.isCustom() )
{ {
cWarning() << "Custom instance key" << instance << "is not listed in the *instances*"; cWarning() << "Custom instance key" << instanceKey << "is not listed in the *instances*";
} }
m_moduleInstances.append( InstanceDescription( k ) ); m_moduleInstances.append( InstanceDescription( instanceKey ) );
} }
} }
} }

View File

@ -110,7 +110,7 @@ public:
*/ */
InstanceDescriptionList moduleInstances() const; InstanceDescriptionList moduleInstances() const;
using ModuleSequence = QList< QPair< ModuleSystem::Action, QStringList > >; using ModuleSequence = QList< QPair< ModuleSystem::Action, Calamares::ModuleSystem::InstanceKeyList > >;
/** @brief Representation of *sequence* of execution /** @brief Representation of *sequence* of execution
* *
* Each "section" of the *sequence* key in `settings.conf` gets an * Each "section" of the *sequence* key in `settings.conf` gets an

View File

@ -22,6 +22,7 @@
#define MODULESYSTEM_INSTANCEKEY_H #define MODULESYSTEM_INSTANCEKEY_H
#include <QDebug> #include <QDebug>
#include <QList>
#include <QPair> #include <QPair>
#include <QString> #include <QString>
@ -96,6 +97,8 @@ private:
} }
}; };
using InstanceKeyList = QList< InstanceKey >;
QDebug& operator<<( QDebug& s, const Calamares::ModuleSystem::InstanceKey& i ); QDebug& operator<<( QDebug& s, const Calamares::ModuleSystem::InstanceKey& i );
} // namespace ModuleSystem } // namespace ModuleSystem