[packagechooser] Set GlobalStorage packagechooser_<id>

This commit is contained in:
Adriaan de Groot 2019-08-03 23:51:00 +02:00
parent c59ffc7765
commit 140c0db7a4
6 changed files with 45 additions and 1 deletions

View File

@ -98,3 +98,24 @@ PackageChooserPage::hasSelection() const
{ {
return ui && ui->products && ui->products->selectionModel() && ui->products->selectionModel()->hasSelection(); return ui && ui->products && ui->products->selectionModel() && ui->products->selectionModel()->hasSelection();
} }
QStringList
PackageChooserPage::selectedPackageIds() const
{
if ( !( ui && ui->products && ui->products->selectionModel() ) )
{
return QStringList();
}
const auto* model = ui->products->model();
QStringList ids;
for ( const auto& index : ui->products->selectionModel()->selectedIndexes() )
{
QString pid = model->data( index, PackageListModel::IdRole ).toString();
if ( !pid.isEmpty() )
{
ids.append( pid );
}
}
return ids;
}

View File

@ -37,7 +37,13 @@ public:
void setModel( QAbstractItemModel* model ); void setModel( QAbstractItemModel* model );
/// @brief Is anything selected?
bool hasSelection() const; bool hasSelection() const;
/** @brief Get the list of selected ids
*
* This list may be empty (if none is selected).
*/
QStringList selectedPackageIds() const;
public slots: public slots:
void currentChanged( const QModelIndex& index ); void currentChanged( const QModelIndex& index );

View File

@ -137,6 +137,15 @@ PackageChooserViewStep::isAtEnd() const
void void
PackageChooserViewStep::onLeave() PackageChooserViewStep::onLeave()
{ {
QString key = QStringLiteral( "packagechooser_%1" ).arg( m_id );
QString value;
if ( m_widget->hasSelection() )
{
value = m_widget->selectedPackageIds().join( ',' );
}
Calamares::JobQueue::instance()->globalStorage()->insert( key, value );
cDebug() << "PackageChooser" << key << "selected" << value;
} }
Calamares::JobList Calamares::JobList

View File

@ -128,6 +128,10 @@ PackageListModel::data( const QModelIndex& index, int role ) const
{ {
return m_packages[ row ].screenshot; return m_packages[ row ].screenshot;
} }
else if ( role == IdRole )
{
return m_packages[ row ].id;
}
return QVariant(); return QVariant();
} }

View File

@ -84,7 +84,8 @@ public:
{ {
NameRole = Qt::DisplayRole, NameRole = Qt::DisplayRole,
DescriptionRole = Qt::UserRole, DescriptionRole = Qt::UserRole,
ScreenshotRole ScreenshotRole,
IdRole
}; };
private: private:

View File

@ -7,6 +7,9 @@
# If there is just one packagechooser module, and no *id* is set, # If there is just one packagechooser module, and no *id* is set,
# resulting GS key is probably *packagechooser_packagechooser*. # resulting GS key is probably *packagechooser_packagechooser*.
# #
# The GS value is a comma-separated list of the IDs of the selected
# packages, or an empty string if none is selected.
#
# id: "" # id: ""
# Software selection mode, to set whether the software packages # Software selection mode, to set whether the software packages