From b16354133da0f5873f7eee25d1e1aeec297d2483 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 4 Aug 2019 20:19:56 +0200 Subject: [PATCH] [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). --- .../packagechooser/PackageChooserViewStep.cpp | 32 +++++++++------ .../packagechooser/PackageChooserViewStep.h | 2 +- .../packagechooser/packagechooser.conf | 40 ++++++++++--------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index 4d9ab4f5f..4476eb9e6 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -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; diff --git a/src/modules/packagechooser/PackageChooserViewStep.h b/src/modules/packagechooser/PackageChooserViewStep.h index 4d5cc346f..e3ffc1d5b 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.h +++ b/src/modules/packagechooser/PackageChooserViewStep.h @@ -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; diff --git a/src/modules/packagechooser/packagechooser.conf b/src/modules/packagechooser/packagechooser.conf index f4bab476c..391e1f325 100644 --- a/src/modules/packagechooser/packagechooser.conf +++ b/src/modules/packagechooser/packagechooser.conf @@ -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_*). The following fields +# Each item has an id, which is used in setting # the value of +# *packagechooser_*). 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"