[packagechooser] Massage API

- use updateGlobalStorage() for both single-selection and
  model-based approaches, although the model-based one
  needs extra parameters.
- complain about inconsistent settings and API calls (e.g.
  setting a model and single-selection at the same time)
This commit is contained in:
Adriaan de Groot 2021-09-03 22:41:13 +02:00
parent 8a49fde016
commit 33e7e8da58
3 changed files with 46 additions and 4 deletions

View File

@ -98,10 +98,13 @@ Config::introductionPackage() const
void void
Config::updateGlobalStorage( const QStringList& selected ) const Config::updateGlobalStorage( const QStringList& selected ) const
{ {
if ( m_packageChoice.has_value() )
{
cWarning() << "Inconsistent package choices -- both model and single-selection QML";
}
if ( m_method == PackageChooserMethod::Legacy ) if ( m_method == PackageChooserMethod::Legacy )
{ {
QString value = selected.join( ',' ); QString value = selected.join( ',' );
// QString value = ( m_pkgc );
Calamares::JobQueue::instance()->globalStorage()->insert( m_id, value ); Calamares::JobQueue::instance()->globalStorage()->insert( m_id, value );
cDebug() << m_id << "selected" << value; cDebug() << m_id << "selected" << value;
} }
@ -118,6 +121,36 @@ Config::updateGlobalStorage( const QStringList& selected ) const
} }
} }
void
Config::updateGlobalStorage() const
{
if ( m_model->packageCount() > 0 )
{
cWarning() << "Inconsistent package choices -- both model and single-selection QML";
}
if ( m_method == PackageChooserMethod::Legacy )
{
auto* gs = Calamares::JobQueue::instance()->globalStorage();
if ( m_packageChoice.has_value() )
{
gs->insert( m_id, m_packageChoice.value() );
}
else
{
gs->remove( m_id );
}
}
else if ( m_method == PackageChooserMethod::Packages )
{
cWarning() << "Unsupported single-selection packagechooser method 'Packages'";
}
else
{
cWarning() << "Unknown packagechooser method" << smash( m_method );
}
}
void void
Config::setPackageChoice( const QString& packageChoice ) Config::setPackageChoice( const QString& packageChoice )
{ {
@ -252,5 +285,9 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
else else
{ {
setPackageChoice( CalamaresUtils::getString( configurationMap, "packageChoice" ) ); setPackageChoice( CalamaresUtils::getString( configurationMap, "packageChoice" ) );
if ( m_method != PackageChooserMethod::Legacy )
{
cWarning() << "Single-selection QML module must use 'Legacy' method.";
}
} }
} }

View File

@ -85,8 +85,13 @@ public:
* (and only) the packages in @p selected as selected. * (and only) the packages in @p selected as selected.
*/ */
void updateGlobalStorage( const QStringList& selected ) const; void updateGlobalStorage( const QStringList& selected ) const;
/// As updateGlobalStorage() with an empty selection list /** @brief Write selection to global storage
void fillGSSecondaryConfiguration() const { updateGlobalStorage( QStringList() ); } *
* Updates the GS keys for this packagechooser, marking **only**
* the package choice as selected. This assumes that the single-
* selection QML code is in use.
*/
void updateGlobalStorage() const;
QString packageChoice() const { return m_packageChoice.value_or( QString() ); } QString packageChoice() const { return m_packageChoice.value_or( QString() ); }
void setPackageChoice( const QString& packageChoice ); void setPackageChoice( const QString& packageChoice );

View File

@ -74,7 +74,7 @@ PackageChooserQmlViewStep::jobs() const
void void
PackageChooserQmlViewStep::onLeave() PackageChooserQmlViewStep::onLeave()
{ {
m_config->fillGSSecondaryConfiguration(); m_config->updateGlobalStorage();
} }
void void