[packagechooser] Remove 'id' configuration setting

- Setting 'id' (which changes the Global Storage key that
  gets used) is a kludge when the existing module-instance
  name can be used instead -- and **was** already used, as
  a fallback when 'id' is not set. There's no point in having
  two places to set a particular name.
- Rip out the docs for 'id' as well.
- Add documentation on the difference between single-selection
  (the QML implementation) and model-selection (what the Widgets
  version does).
This commit is contained in:
Adriaan de Groot 2021-09-03 23:59:11 +02:00
parent 6def41fab4
commit e311d7a893
4 changed files with 29 additions and 51 deletions

View File

@ -95,6 +95,12 @@ Config::introductionPackage() const
return *defaultIntroduction; return *defaultIntroduction;
} }
static inline QString
make_gs_key( const Calamares::ModuleSystem::InstanceKey& key )
{
return QStringLiteral( "packagechooser_" ) + key.id();
}
void void
Config::updateGlobalStorage( const QStringList& selected ) const Config::updateGlobalStorage( const QStringList& selected ) const
{ {
@ -105,8 +111,8 @@ Config::updateGlobalStorage( const QStringList& selected ) const
if ( m_method == PackageChooserMethod::Legacy ) if ( m_method == PackageChooserMethod::Legacy )
{ {
QString value = selected.join( ',' ); QString value = selected.join( ',' );
Calamares::JobQueue::instance()->globalStorage()->insert( m_id, value ); Calamares::JobQueue::instance()->globalStorage()->insert( make_gs_key( m_defaultId ), value );
cDebug() << m_id << "selected" << value; cDebug() << m_defaultId << "selected" << value;
} }
else if ( m_method == PackageChooserMethod::Packages ) else if ( m_method == PackageChooserMethod::Packages )
{ {
@ -133,11 +139,11 @@ Config::updateGlobalStorage() const
auto* gs = Calamares::JobQueue::instance()->globalStorage(); auto* gs = Calamares::JobQueue::instance()->globalStorage();
if ( m_packageChoice.has_value() ) if ( m_packageChoice.has_value() )
{ {
gs->insert( m_id, m_packageChoice.value() ); gs->insert( make_gs_key( m_defaultId ), m_packageChoice.value() );
} }
else else
{ {
gs->remove( m_id ); gs->remove( make_gs_key( m_defaultId ) );
} }
} }
else if ( m_method == PackageChooserMethod::Packages ) else if ( m_method == PackageChooserMethod::Packages )
@ -240,26 +246,7 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
if ( m_method == PackageChooserMethod::Legacy ) if ( m_method == PackageChooserMethod::Legacy )
{ {
const QString configId = CalamaresUtils::getString( configurationMap, "id" ); cDebug() << "Using module ID" << m_defaultId;
const QString base = QStringLiteral( "packagechooser_" );
if ( configId.isEmpty() )
{
if ( m_defaultId.id().isEmpty() )
{
// We got nothing to work with
m_id = base;
}
else
{
m_id = base + m_defaultId.id();
}
cDebug() << "Using default ID" << m_id << "from" << m_defaultId.toString();
}
else
{
m_id = base + configId;
cDebug() << "Using configured ID" << m_id;
}
} }
if ( configurationMap.contains( "items" ) ) if ( configurationMap.contains( "items" ) )

View File

@ -110,8 +110,6 @@ private:
PackageChooserMode m_mode = PackageChooserMode::Optional; PackageChooserMode m_mode = PackageChooserMode::Optional;
/// How this module stores to GS /// How this module stores to GS
PackageChooserMethod m_method = PackageChooserMethod::Legacy; PackageChooserMethod m_method = PackageChooserMethod::Legacy;
/// Id (used to identify settings from this module in GS)
QString m_id;
/// Value to use for id if none is set in the config file /// Value to use for id if none is set in the config file
Calamares::ModuleSystem::InstanceKey m_defaultId; Calamares::ModuleSystem::InstanceKey m_defaultId;
/** @brief QML selection (for single-selection approaches) /** @brief QML selection (for single-selection approaches)

View File

@ -15,11 +15,10 @@ mode: required
# #
# - "legacy" or "custom" or "contextualprocess" # - "legacy" or "custom" or "contextualprocess"
# When set to "legacy", writes a GlobalStorage value for the choice that # When set to "legacy", writes a GlobalStorage value for the choice that
# has been made. The key is *packagechooser_<id>*. Normally, the module's # has been made. The key is *packagechooser_<id>*. The module's
# instance name is used; see the *instances* section of `settings.conf`. # instance name is used; see the *instances* section of `settings.conf`.
# If there is just one packagechooser module, and no special instance is set, # If there is just one packagechooser module, and no special instance is set,
# resulting GS key is probably *packagechooser@packagechooser*. # resulting GS key is probably *packagechooser_packagechooser*.
# You can set *id* to change that, but it is not recommended.
# #
# The GS value is a comma-separated list of the IDs of the selected # The GS value is a comma-separated list of the IDs of the selected
# packages, or an empty string if none is selected. # packages, or an empty string if none is selected.
@ -33,15 +32,12 @@ mode: required
# consumption by the *packages* module (which should appear later # consumption by the *packages* module (which should appear later
# in the `exec` section. These package settings will then be handed # in the `exec` section. These package settings will then be handed
# off to whatever package manager is configured there. # off to whatever package manager is configured there.
# The *id* key is not used.
# #
# There is no need to put this module in the `exec` section. There # There is no need to put this module in the `exec` section. There
# are no jobs that this module provides. You should put **other** # are no jobs that this module provides. You should put **other**
# modules, either *contextualprocess* or *packages* or some custom # modules, either *contextualprocess* or *packages* or some custom
# module, in the `exec` section to do the actual work. # module, in the `exec` section to do the actual work.
method: legacy method: legacy
# The *id* key is used only in "legacy" mode
# id: ""
# Human-visible strings in this module. These are all optional. # Human-visible strings in this module. These are all optional.
@ -51,13 +47,13 @@ method: legacy
# Each key can have a [locale] added to it, which is used as # Each key can have a [locale] added to it, which is used as
# the translated string for that locale. For the strings # the translated string for that locale. For the strings
# associated with the "no-selection" item, see *items*, below # associated with the "no-selection" item, see *items*, below
# with the explicit id "". # with the explicit item-*id* "".
# #
labels: labels:
step: "Packages" step: "Packages"
step[nl]: "Pakketten" step[nl]: "Pakketten"
# (Optional) 'id' of pre-selected list-view item. # (Optional) item-*id* of pre-selected list-view item.
# Pre-selects one of the items below. # Pre-selects one of the items below.
# default: kde # default: kde

View File

@ -1,23 +1,26 @@
# SPDX-FileCopyrightText: no # SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
# #
# Configuration for the low-density software chooser # Configuration for the low-density software chooser, QML implementation
--- #
# Software selection mode, to set whether the software packages # The example QML implementation uses single-selection, rather than
# can be chosen singly, or multiply. # a model for the available packages. That makes it simpler: the
# QML itself codes the available options, descriptions and images
# -- after all, this is **low density** selection, so a custom UI
# can make sense for the few choices that need to be made.
#
# #
# The example QML module does not use a model, and ignores this value.
mode: required
---
# Software installation method: # Software installation method:
# #
# - "legacy" or "custom" or "contextualprocess" # - "legacy" or "custom" or "contextualprocess"
# When set to "legacy", writes a GlobalStorage value for the choice that # When set to "legacy", writes a GlobalStorage value for the choice that
# has been made. The key is *packagechooser_<id>*. Normally, the module's # has been made. The key is *packagechooser_<id>*. The module's
# instance name is used; see the *instances* section of `settings.conf`. # instance name is used; see the *instances* section of `settings.conf`.
# If there is just one packagechooser module, and no special instance is set, # If there is just one packagechooserq module, and no special instance is set,
# resulting GS key is probably *packagechooser@packagechooser*. # resulting GS key is probably *packagechooser_packagechooserq*.
# You can set *id* to change that, but it is not recommended. # (Do note that the prefix of the GS key remains "packagechooser_")
# #
# The GS value is a comma-separated list of the IDs of the selected # The GS value is a comma-separated list of the IDs of the selected
# packages, or an empty string if none is selected. # packages, or an empty string if none is selected.
@ -31,19 +34,13 @@ mode: required
# consumption by the *packages* module (which should appear later # consumption by the *packages* module (which should appear later
# in the `exec` section. These package settings will then be handed # in the `exec` section. These package settings will then be handed
# off to whatever package manager is configured there. # off to whatever package manager is configured there.
# The *id* key is not used.
# #
# There is no need to put this module in the `exec` section. There # There is no need to put this module in the `exec` section. There
# are no jobs that this module provides. You should put **other** # are no jobs that this module provides. You should put **other**
# modules, either *contextualprocess* or *packages* or some custom # modules, either *contextualprocess* or *packages* or some custom
# module, in the `exec` section to do the actual work. # module, in the `exec` section to do the actual work.
method: legacy
# The *id* key is used only in "legacy" mode and changes the GlobalStorage
# key used to store the package choices. It is not recommended to use
# this, since the module instance key does the same job.
# #
# id: "" method: legacy
# The *packageChoice* value is used for setting the default selection # The *packageChoice* value is used for setting the default selection
# in the QML view; this should match one of the keys used in the QML # in the QML view; this should match one of the keys used in the QML