diff --git a/src/modules/packagechooser/PackageChooserPage.cpp b/src/modules/packagechooser/PackageChooserPage.cpp index f0a6579b4..1986cf464 100644 --- a/src/modules/packagechooser/PackageChooserPage.cpp +++ b/src/modules/packagechooser/PackageChooserPage.cpp @@ -53,10 +53,10 @@ PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent } /** @brief size the given @p pixmap to @p size - * + * * This is "smart" in the sense that it tries to keep the image un-scaled * (if it's just a little too big) and otherwise scales as needed. - * + * * Returns a copy if any modifications are done. */ static QPixmap @@ -129,26 +129,7 @@ void PackageChooserPage::setModel( QAbstractItemModel* model ) { ui->products->setModel( model ); - - // Check if any of the items in the model is the "none" option. - // If so, copy its values into the introduction / none item. - for ( int r = 0; r < model->rowCount(); ++r ) - { - auto index = model->index( r, 0 ); - if ( index.isValid() ) - { - QVariant v = model->data( index, PackageListModel::IdRole ); - if ( v.isValid() && v.toString().isEmpty() ) - { - m_introduction.name = model->data( index, PackageListModel::NameRole ).toString(); - m_introduction.description = model->data( index, PackageListModel::DescriptionRole ).toString(); - m_introduction.screenshot = model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >(); - currentChanged( QModelIndex() ); - break; - } - } - } - + currentChanged( QModelIndex() ); connect( ui->products->selectionModel(), &QItemSelectionModel::selectionChanged, this, @@ -181,3 +162,11 @@ PackageChooserPage::selectedPackageIds() const } return ids; } + +void +PackageChooserPage::setIntroduction( const CalamaresUtils::Locale::TranslatedString& name, + const CalamaresUtils::Locale::TranslatedString& description ) +{ + m_introduction.name = name; + m_introduction.description = description; +} diff --git a/src/modules/packagechooser/PackageChooserPage.h b/src/modules/packagechooser/PackageChooserPage.h index 401de903b..4a1ac207b 100644 --- a/src/modules/packagechooser/PackageChooserPage.h +++ b/src/modules/packagechooser/PackageChooserPage.h @@ -21,6 +21,8 @@ #include "PackageModel.h" +#include "locale/TranslatableConfiguration.h" + #include #include @@ -37,6 +39,9 @@ public: void setModel( QAbstractItemModel* model ); + /// @brief Sets the introductory (no-package-selected) texts + void setIntroduction( const CalamaresUtils::Locale::TranslatedString& name, + const CalamaresUtils::Locale::TranslatedString& description ); /// @brief Is anything selected? bool hasSelection() const; /** @brief Get the list of selected ids diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index 6b014fda2..ff506117d 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -283,4 +283,13 @@ PackageChooserViewStep::hookupModel() } m_widget->setModel( m_model ); + for ( int i = 0; i < m_model->packageCount(); ++i ) + { + const auto& package = m_model->packageData( i ); + if ( package.id.isEmpty() ) + { + m_widget->setIntroduction( package.name, package.description ); + break; + } + } } diff --git a/src/modules/packagechooser/PackageChooserViewStep.h b/src/modules/packagechooser/PackageChooserViewStep.h index da0775758..499571c12 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.h +++ b/src/modules/packagechooser/PackageChooserViewStep.h @@ -66,7 +66,7 @@ private: // Configuration PackageChooserMode m_mode; QString m_id; - CalamaresUtils::Locale::TranslatedString *m_stepName; // As it appears in the sidebar + CalamaresUtils::Locale::TranslatedString* m_stepName; // As it appears in the sidebar }; CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory ) diff --git a/src/modules/packagechooser/PackageModel.h b/src/modules/packagechooser/PackageModel.h index 8362bee33..ee3b30185 100644 --- a/src/modules/packagechooser/PackageModel.h +++ b/src/modules/packagechooser/PackageModel.h @@ -80,6 +80,14 @@ struct PackageItem * A valid item has an untranslated name available. */ bool isValid() const { return !name.isEmpty(); } + + /** @brief Is this a (the) No-Package package? + * + * There should be at most one No-Package item in a collection + * of PackageItems. That one will be used to describe a + * "no package" situation. + */ + bool isNonePackage() const { return id.isEmpty(); } }; using PackageList = QVector< PackageItem >; @@ -100,6 +108,11 @@ public: int rowCount( const QModelIndex& index ) const override; QVariant data( const QModelIndex& index, int role ) const override; + /// @brief Direct (non-abstract) access to package data + const PackageItem& packageData( int r ) const { return m_packages[ r ]; } + /// @brief Direct (non-abstract) count of package data + int packageCount() const { return m_packages.count(); } + enum Roles : int { NameRole = Qt::DisplayRole,