[packagechooser] Switch to a list form

- Using id's as keys in a map orders them indeterminately -- in
   practice, alphabetically by key. Switch to a list form so that
   the products stick to the order they have in the config file
   (which means distro's can list "preferred" versions at top).
main
Adriaan de Groot 6 years ago
parent 9a52430e74
commit b16354133d

@ -178,12 +178,9 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap
}
bool first_time = !m_model;
ok = false;
QVariantMap items = CalamaresUtils::getSubMap( configurationMap, "items", ok );
if ( ok )
if ( configurationMap.contains( "items" ) )
{
fillModel( items );
fillModel( configurationMap.value( "items" ).toList() );
}
// TODO: replace this hard-coded model
@ -210,31 +207,42 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap
}
void
PackageChooserViewStep::fillModel( const QVariantMap& items )
PackageChooserViewStep::fillModel( const QVariantList& items )
{
if ( !m_model )
{
m_model = new PackageListModel( nullptr );
}
cDebug() << "Loading PackageChooser model items from config";
for ( auto item_it = items.constKeyValueBegin(); item_it != items.constKeyValueEnd(); ++item_it )
if ( items.isEmpty() )
{
QString id = ( *item_it ).first;
cWarning() << "No *items* for PackageChooser module.";
return;
}
QVariantMap item_map = ( *item_it ).second.toMap();
cDebug() << "Loading PackageChooser model items from config";
int item_index = 0;
for ( const auto& item_it : items )
{
++item_index;
QVariantMap item_map = item_it.toMap();
if ( item_map.isEmpty() )
{
cWarning() << "PackageChooser item" << id << "is not valid.";
cWarning() << "PackageChooser entry" << item_index << "is not valid.";
continue;
}
QString id = CalamaresUtils::getString( item_map, "id" );
QString package = CalamaresUtils::getString( item_map, "package" );
QString name = CalamaresUtils::getString( item_map, "name" );
QString description = CalamaresUtils::getString( item_map, "description" );
QString screenshot = CalamaresUtils::getString( item_map, "screenshot" );
if ( name.isEmpty() )
if ( name.isEmpty() && id.isEmpty() )
{
name = tr( "No product" );
}
else if ( name.isEmpty() )
{
cWarning() << "PackageChooser item" << id << "has an empty name.";
continue;

@ -56,7 +56,7 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
private:
void fillModel( const QVariantMap& items );
void fillModel( const QVariantList& items );
void hookupModel();
PackageChooserPage* m_widget;

@ -21,12 +21,16 @@
mode: required
# Items to display in the chooser. In general, this should be a
# pretty short list to avoid overwhelming the UI.
# pretty short list to avoid overwhelming the UI. This is a list
# of objects, and the items are displayed in list order.
#
# Each item has a key, which is used as its ID (used in setting
# the value of *packagechooser_<module-id>*). The following fields
# Each item has an id, which is used in setting # the value of
# *packagechooser_<module-id>*). The following fields
# are mandatory:
#
# - *id* ID for the product. The ID "" is special, and is used for
# "no package selected". Only include this if the mode allows
# selecting none.
# - *package* Package name for the product. While mandatory, this is
# not actually used anywhere.
# - *name* Human-readable, but untranslated, name of the product.
@ -37,20 +41,20 @@ mode: required
# Use the empty string "" as ID / key for the "no selection" item if
# you want to customize the display of that item as well.
items:
"":
package: ""
name: "No Desktop"
description: "Please pick a desktop environment from the list. If you don't want to install a desktop, that's fine, your system will start up in text-only mode and you can install a desktop environment later."
screenshot: ":/images/no-selection.png"
kde:
package: kde
name: Plasma Desktop
description: "KDE Plasma Desktop, simple by default, a clean work area for real-world usage which intends to stay out of your way. Plasma is powerful when needed, enabling the user to create the workflow that makes them more effective to complete their tasks."
screenshot: ":/images/kde.png"
gnome:
package: gnome
name: GNOME
description: GNU Networked Object Modeling Environment Desktop
screenshot: ":/images/gnome.png"
- id: ""
package: ""
name: "No Desktop"
description: "Please pick a desktop environment from the list. If you don't want to install a desktop, that's fine, your system will start up in text-only mode and you can install a desktop environment later."
screenshot: ":/images/no-selection.png"
- id: kde
package: kde
name: Plasma Desktop
description: "KDE Plasma Desktop, DERP"
screenshot: ":/images/kde.png"
- id: gnome
package: gnome
name: GNOME
description: GNU Networked Object Modeling Environment Desktop
screenshot: ":/images/gnome.png"

Loading…
Cancel
Save