mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 17:35:37 -04:00
[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:
parent
6ce1a49f1c
commit
aa3633e43a
3 changed files with 31 additions and 13 deletions
|
@ -51,11 +51,10 @@ PackageChooserMethodNames()
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::Config( const Calamares::ModuleSystem::InstanceKey& defaultId, QObject* parent )
|
Config::Config( QObject* parent )
|
||||||
: Calamares::ModuleSystem::Config( parent )
|
: Calamares::ModuleSystem::Config( parent )
|
||||||
, m_model( new PackageListModel( this ) )
|
, m_model( new PackageListModel( this ) )
|
||||||
, m_mode( PackageChooserMode::Required )
|
, m_mode( PackageChooserMode::Required )
|
||||||
, m_defaultId( defaultId )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ Config::introductionPackage() const
|
||||||
void
|
void
|
||||||
Config::updateGlobalStorage( const QStringList& selected ) const
|
Config::updateGlobalStorage( const QStringList& selected ) const
|
||||||
{
|
{
|
||||||
QString key = QStringLiteral( "packagechooser_%1" ).arg( m_id );
|
const QString& key = m_id;
|
||||||
cDebug() << "Writing to GS" << key;
|
cDebug() << "Writing to GS" << key;
|
||||||
|
|
||||||
if ( m_method == PackageChooserMethod::Legacy )
|
if ( m_method == PackageChooserMethod::Legacy )
|
||||||
|
@ -177,24 +176,34 @@ fillModel( PackageListModel* model, const QVariantList& items )
|
||||||
void
|
void
|
||||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
m_mode = packageChooserModeNames().find( CalamaresUtils::getString( configurationMap, "mode" ), PackageChooserMode::Required );
|
m_mode = packageChooserModeNames().find( CalamaresUtils::getString( configurationMap, "mode" ),
|
||||||
m_method = PackageChooserMethodNames().find( CalamaresUtils::getString( configurationMap, "method" ), PackageChooserMethod::Legacy );
|
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();
|
const QString configId = CalamaresUtils::getString( configurationMap, "id" );
|
||||||
cDebug() << "Using default ID" << m_id << "from" << m_defaultId.toString();
|
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" ) )
|
if ( configurationMap.contains( "items" ) )
|
||||||
{
|
{
|
||||||
fillModel( m_model, configurationMap.value( "items" ).toList() );
|
fillModel( m_model, configurationMap.value( "items" ).toList() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString default_item_id = CalamaresUtils::getString( configurationMap, "default" );
|
QString default_item_id = CalamaresUtils::getString( configurationMap, "default" );
|
||||||
// find default item
|
|
||||||
if ( !default_item_id.isEmpty() )
|
if ( !default_item_id.isEmpty() )
|
||||||
{
|
{
|
||||||
for ( int item_n = 0; item_n < m_model->packageCount(); ++item_n )
|
for ( int item_n = 0; item_n < m_model->packageCount(); ++item_n )
|
||||||
|
|
|
@ -40,9 +40,17 @@ class Config : public Calamares::ModuleSystem::Config
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config( const Calamares::ModuleSystem::InstanceKey& defaultId, QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
~Config() override;
|
~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;
|
void setConfigurationMap( const QVariantMap& ) override;
|
||||||
|
|
||||||
PackageChooserMode mode() const { return m_mode; }
|
PackageChooserMode mode() const { return m_mode; }
|
||||||
|
|
|
@ -37,7 +37,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( PackageChooserViewStepFactory, registerPlug
|
||||||
|
|
||||||
PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
|
PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_config( new Config( moduleInstanceKey(), this ) )
|
, m_config( new Config( this ) )
|
||||||
, m_widget( nullptr )
|
, m_widget( nullptr )
|
||||||
, m_stepName( nullptr )
|
, m_stepName( nullptr )
|
||||||
{
|
{
|
||||||
|
@ -146,6 +146,7 @@ PackageChooserViewStep::jobs() const
|
||||||
void
|
void
|
||||||
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
|
m_config->setDefaultId( moduleInstanceKey() );
|
||||||
m_config->setConfigurationMap( configurationMap );
|
m_config->setConfigurationMap( configurationMap );
|
||||||
|
|
||||||
bool labels_ok = false;
|
bool labels_ok = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue