[packagechooser] Delay initialization of default Id

When the module is loaded and the viewstep created, it doesn't have a
module Id **yet**. That is set after reading more of the configuration
file. It **is** set by the time setConfigurationMap() is called,
so pass it on to the Config object then. This means that packagechooser
modules can skip the *id* config key and use the module Id.
This commit is contained in:
Adriaan de Groot 2021-04-23 22:04:15 +02:00
parent 6ce1a49f1c
commit aa3633e43a
3 changed files with 31 additions and 13 deletions

View File

@ -51,11 +51,10 @@ PackageChooserMethodNames()
return names;
}
Config::Config( const Calamares::ModuleSystem::InstanceKey& defaultId, QObject* parent )
Config::Config( QObject* parent )
: Calamares::ModuleSystem::Config( parent )
, m_model( new PackageListModel( this ) )
, m_mode( PackageChooserMode::Required )
, m_defaultId( defaultId )
{
}
@ -91,7 +90,7 @@ Config::introductionPackage() const
void
Config::updateGlobalStorage( const QStringList& selected ) const
{
QString key = QStringLiteral( "packagechooser_%1" ).arg( m_id );
const QString& key = m_id;
cDebug() << "Writing to GS" << key;
if ( m_method == PackageChooserMethod::Legacy )
@ -177,24 +176,34 @@ fillModel( PackageListModel* model, const QVariantList& items )
void
Config::setConfigurationMap( const QVariantMap& configurationMap )
{
m_mode = packageChooserModeNames().find( CalamaresUtils::getString( configurationMap, "mode" ), PackageChooserMode::Required );
m_method = PackageChooserMethodNames().find( CalamaresUtils::getString( configurationMap, "method" ), PackageChooserMethod::Legacy );
m_mode = packageChooserModeNames().find( CalamaresUtils::getString( configurationMap, "mode" ),
PackageChooserMode::Required );
m_method = PackageChooserMethodNames().find( CalamaresUtils::getString( configurationMap, "method" ),
PackageChooserMethod::Legacy );
m_id = CalamaresUtils::getString( configurationMap, "id" );
if ( m_id.isEmpty() )
{
m_id = m_defaultId.id();
cDebug() << "Using default ID" << m_id << "from" << m_defaultId.toString();
const QString configId = CalamaresUtils::getString( configurationMap, "id" );
if ( configId.isEmpty() )
{
m_id = m_defaultId.toString();
if ( m_id.isEmpty() )
{
m_id = QString( "packagechooser" );
}
cDebug() << "Using default ID" << m_id << "from" << m_defaultId.toString();
}
else
{
m_id = QStringLiteral( "packagechooser_" ) + configId;
}
}
m_defaultModelIndex = QModelIndex();
if ( configurationMap.contains( "items" ) )
{
fillModel( m_model, configurationMap.value( "items" ).toList() );
}
QString default_item_id = CalamaresUtils::getString( configurationMap, "default" );
// find default item
if ( !default_item_id.isEmpty() )
{
for ( int item_n = 0; item_n < m_model->packageCount(); ++item_n )

View File

@ -40,9 +40,17 @@ class Config : public Calamares::ModuleSystem::Config
Q_OBJECT
public:
Config( const Calamares::ModuleSystem::InstanceKey& defaultId, QObject* parent = nullptr );
Config( QObject* parent = nullptr );
~Config() override;
/** @brief Sets the default Id for this Config
*
* The default Id is the (owning) module identifier for the config,
* and it is used when the Id read from the config file is empty.
* The **usual** configuration when using method *packages* is
* to rely on the default Id.
*/
void setDefaultId( const Calamares::ModuleSystem::InstanceKey& defaultId ) { m_defaultId = defaultId; }
void setConfigurationMap( const QVariantMap& ) override;
PackageChooserMode mode() const { return m_mode; }

View File

@ -37,7 +37,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( PackageChooserViewStepFactory, registerPlug
PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_config( new Config( moduleInstanceKey(), this ) )
, m_config( new Config( this ) )
, m_widget( nullptr )
, m_stepName( nullptr )
{
@ -146,6 +146,7 @@ PackageChooserViewStep::jobs() const
void
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
m_config->setDefaultId( moduleInstanceKey() );
m_config->setConfigurationMap( configurationMap );
bool labels_ok = false;