[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; bool first_time = !m_model;
if ( configurationMap.contains( "items" ) )
ok = false;
QVariantMap items = CalamaresUtils::getSubMap( configurationMap, "items", ok );
if ( ok )
{ {
fillModel( items ); fillModel( configurationMap.value( "items" ).toList() );
} }
// TODO: replace this hard-coded model // TODO: replace this hard-coded model
@ -210,31 +207,42 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap
} }
void void
PackageChooserViewStep::fillModel( const QVariantMap& items ) PackageChooserViewStep::fillModel( const QVariantList& items )
{ {
if ( !m_model ) if ( !m_model )
{ {
m_model = new PackageListModel( nullptr ); m_model = new PackageListModel( nullptr );
} }
cDebug() << "Loading PackageChooser model items from config"; if ( items.isEmpty() )
for ( auto item_it = items.constKeyValueBegin(); item_it != items.constKeyValueEnd(); ++item_it )
{ {
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() ) if ( item_map.isEmpty() )
{ {
cWarning() << "PackageChooser item" << id << "is not valid."; cWarning() << "PackageChooser entry" << item_index << "is not valid.";
continue; continue;
} }
QString id = CalamaresUtils::getString( item_map, "id" );
QString package = CalamaresUtils::getString( item_map, "package" ); QString package = CalamaresUtils::getString( item_map, "package" );
QString name = CalamaresUtils::getString( item_map, "name" ); QString name = CalamaresUtils::getString( item_map, "name" );
QString description = CalamaresUtils::getString( item_map, "description" ); QString description = CalamaresUtils::getString( item_map, "description" );
QString screenshot = CalamaresUtils::getString( item_map, "screenshot" ); 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."; cWarning() << "PackageChooser item" << id << "has an empty name.";
continue; continue;

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

@ -21,12 +21,16 @@
mode: required mode: required
# Items to display in the chooser. In general, this should be a # 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 # Each item has an id, which is used in setting # the value of
# the value of *packagechooser_<module-id>*). The following fields # *packagechooser_<module-id>*). The following fields
# are mandatory: # 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 # - *package* Package name for the product. While mandatory, this is
# not actually used anywhere. # not actually used anywhere.
# - *name* Human-readable, but untranslated, name of the product. # - *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 # Use the empty string "" as ID / key for the "no selection" item if
# you want to customize the display of that item as well. # you want to customize the display of that item as well.
items: items:
"": - id: ""
package: "" package: ""
name: "No Desktop" 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." 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" screenshot: ":/images/no-selection.png"
kde: - id: kde
package: kde package: kde
name: Plasma Desktop 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." description: "KDE Plasma Desktop, DERP"
screenshot: ":/images/kde.png" screenshot: ":/images/kde.png"
gnome: - id: gnome
package: gnome package: gnome
name: GNOME name: GNOME
description: GNU Networked Object Modeling Environment Desktop description: GNU Networked Object Modeling Environment Desktop
screenshot: ":/images/gnome.png" screenshot: ":/images/gnome.png"

Loading…
Cancel
Save