From 791f9cbccbef3fcbf5433329a313e7b4c28bbaab Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 4 Aug 2019 16:00:55 +0200 Subject: [PATCH] [packagechooser] Read packages model from config - add key *items* which will be used to fill up the model for software products. TODO: needs translation support --- .../packagechooser/PackageChooserViewStep.cpp | 55 ++++++++++++++++++- .../packagechooser/PackageChooserViewStep.h | 1 + .../packagechooser/packagechooser.conf | 35 ++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index 8515d03a9..4d9ab4f5f 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -177,6 +177,15 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap m_id = moduleInstanceKey().split( '@' ).last(); } + bool first_time = !m_model; + + ok = false; + QVariantMap items = CalamaresUtils::getSubMap( configurationMap, "items", ok ); + if ( ok ) + { + fillModel( items ); + } + // TODO: replace this hard-coded model if ( !m_model ) { @@ -192,12 +201,54 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap m_model->addPackage( PackageItem { "kde", "kde", "Plasma", "Plasma Desktop", ":/images/kde.png" } ); m_model->addPackage( PackageItem { "gnome", "gnome", "GNOME", "GNU Networked Object Modeling Environment Desktop", ":/images/gnome.png" } ); + } + + if ( first_time && m_widget && m_model ) + { + hookupModel(); + } +} + +void +PackageChooserViewStep::fillModel( const QVariantMap& 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 ) + { + QString id = ( *item_it ).first; - if ( m_widget ) + QVariantMap item_map = ( *item_it ).second.toMap(); + if ( item_map.isEmpty() ) { - hookupModel(); + cWarning() << "PackageChooser item" << id << "is not valid."; + continue; } + + 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() ) + { + cWarning() << "PackageChooser item" << id << "has an empty name."; + continue; + } + if ( description.isEmpty() ) + { + description = tr( "No description provided." ); + } + if ( screenshot.isEmpty() ) + { + screenshot = QStringLiteral( ":/images/no-selection.png" ); + } + + m_model->addPackage( PackageItem { id, package, name, description, screenshot } ); } } diff --git a/src/modules/packagechooser/PackageChooserViewStep.h b/src/modules/packagechooser/PackageChooserViewStep.h index 55ed2d4d5..4d5cc346f 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.h +++ b/src/modules/packagechooser/PackageChooserViewStep.h @@ -56,6 +56,7 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; private: + void fillModel( const QVariantMap& items ); void hookupModel(); PackageChooserPage* m_widget; diff --git a/src/modules/packagechooser/packagechooser.conf b/src/modules/packagechooser/packagechooser.conf index b4e48c995..f4bab476c 100644 --- a/src/modules/packagechooser/packagechooser.conf +++ b/src/modules/packagechooser/packagechooser.conf @@ -19,3 +19,38 @@ # or "optionalmultiple", "requiredmultiple" (for zero-or-more # or one-or-more). mode: required + +# Items to display in the chooser. In general, this should be a +# pretty short list to avoid overwhelming the UI. +# +# Each item has a key, which is used as its ID (used in setting +# the value of *packagechooser_*). The following fields +# are mandatory: +# +# - *package* Package name for the product. While mandatory, this is +# not actually used anywhere. +# - *name* Human-readable, but untranslated, name of the product. +# - *description* Human-readable, but untranslated, description. +# - *screenshot* Path to a single screenshot of the product. May be +# a filesystem path or a QRC path (e.g. ":/images/no-selection.png"). +# +# 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" + +