[packagechooser,netinstall] Add support for packagechooser to drive netinstall

This commit is contained in:
dalto 2022-01-15 09:41:23 -06:00
parent 4e61f24960
commit 2eda55d3af
7 changed files with 110 additions and 1 deletions

View File

@ -15,6 +15,7 @@
#include "PackageModel.h" #include "PackageModel.h"
#include "ui_page_netinst.h" #include "ui_page_netinst.h"
#include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "network/Manager.h" #include "network/Manager.h"
@ -62,4 +63,19 @@ void
NetInstallPage::onActivate() NetInstallPage::onActivate()
{ {
ui->groupswidget->setFocus(); ui->groupswidget->setFocus();
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( gs->contains( "NetinstallSelect" ) && gs->value( "NetinstallSelect" ).canConvert( QVariant::StringList ) )
{
const QStringList selectNames = gs->value( "NetinstallSelect" ).toStringList();
static_cast< PackageModel* >( ui->groupswidget->model() )->setSelections( selectNames );
}
if ( gs->contains( "NetinstallAdd" ) && gs->value( "NetinstallAdd" ).canConvert( QVariant::List ) )
{
const QVariantList groups = gs->value( "NetinstallAdd" ).toList();
static_cast< PackageModel* >( ui->groupswidget->model() )->appendModelData( groups );
}
} }

View File

@ -170,6 +170,29 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
return QVariant(); return QVariant();
} }
void
PackageModel::setSelections( QStringList selectNames )
{
if ( m_rootItem )
{
setSelections( selectNames, m_rootItem );
}
}
void
PackageModel::setSelections( QStringList selectNames, PackageTreeItem* item )
{
for ( int i = 0; i < item->childCount(); i++ )
{
auto* child = item->child( i );
setSelections( selectNames, child );
}
if ( item->isGroup() && selectNames.contains( item->name() ) )
{
item->setSelected( Qt::CheckState::Checked );
}
}
PackageTreeItem::List PackageTreeItem::List
PackageModel::getPackages() const PackageModel::getPackages() const
{ {
@ -309,3 +332,15 @@ PackageModel::setupModelData( const QVariantList& l )
setupModelData( l, m_rootItem ); setupModelData( l, m_rootItem );
emit endResetModel(); emit endResetModel();
} }
void
PackageModel::appendModelData( const QVariantList& groupList )
{
if ( m_rootItem )
{
emit beginResetModel();
setupModelData( groupList, m_rootItem );
emit endResetModel();
}
}

View File

@ -54,9 +54,14 @@ public:
int rowCount( const QModelIndex& parent = QModelIndex() ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
int columnCount( const QModelIndex& parent = QModelIndex() ) const override; int columnCount( const QModelIndex& parent = QModelIndex() ) const override;
void setSelections( QStringList selectNames );
void setSelections(QStringList selectNames, PackageTreeItem *item );
PackageTreeItem::List getPackages() const; PackageTreeItem::List getPackages() const;
PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const; PackageTreeItem::List getItemPackages( PackageTreeItem* item ) const;
void appendModelData( const QVariantList& groupList );
private: private:
friend class ItemTests; friend class ItemTests;

View File

@ -55,6 +55,8 @@ PackageChooserMethodNames()
{ "custom", PackageChooserMethod::Legacy }, { "custom", PackageChooserMethod::Legacy },
{ "contextualprocess", PackageChooserMethod::Legacy }, { "contextualprocess", PackageChooserMethod::Legacy },
{ "packages", PackageChooserMethod::Packages }, { "packages", PackageChooserMethod::Packages },
{ "netinstall-add", PackageChooserMethod::NetAdd },
{ "netinstall-select", PackageChooserMethod::NetSelect },
}; };
return names; return names;
} }
@ -121,6 +123,23 @@ Config::updateGlobalStorage( const QStringList& selected ) const
CalamaresUtils::Packages::setGSPackageAdditions( CalamaresUtils::Packages::setGSPackageAdditions(
Calamares::JobQueue::instance()->globalStorage(), m_defaultId, packageNames ); Calamares::JobQueue::instance()->globalStorage(), m_defaultId, packageNames );
} }
else if ( m_method == PackageChooserMethod::NetAdd )
{
QVariantList netinstallDataList = m_model->getNetinstallDataForNames( selected );
if ( netinstallDataList.isEmpty() )
{
cWarning() << "No netinstall information found for " << selected;
}
else
{
Calamares::JobQueue::instance()->globalStorage()->insert( "NetinstallAdd", netinstallDataList );
}
}
else if ( m_method == PackageChooserMethod::NetSelect )
{
cDebug() << m_defaultId << "groups to select in netinstall" << selected;
Calamares::JobQueue::instance()->globalStorage()->insert( "NetinstallSelect", selected );
}
else else
{ {
cWarning() << "Unknown packagechooser method" << smash( m_method ); cWarning() << "Unknown packagechooser method" << smash( m_method );

View File

@ -33,6 +33,8 @@ enum class PackageChooserMethod
{ {
Legacy, // use contextualprocess or other custom Legacy, // use contextualprocess or other custom
Packages, // use the packages module Packages, // use the packages module
NetAdd, // adds packages to the netinstall module
NetSelect, // makes selections in the netinstall module
}; };
const NamedEnumTable< PackageChooserMethod >& PackageChooserMethodNames(); const NamedEnumTable< PackageChooserMethod >& PackageChooserMethodNames();

View File

@ -15,6 +15,14 @@
#include <QFileInfo> #include <QFileInfo>
static QVariantMap
getSubMap( const QVariantMap& map, const QString& key )
{
bool success;
return CalamaresUtils::getSubMap( map, key, success );
}
static QPixmap static QPixmap
loadScreenshot( const QString& path ) loadScreenshot( const QString& path )
{ {
@ -51,12 +59,13 @@ PackageItem::PackageItem( const QString& a_id,
{ {
} }
PackageItem::PackageItem::PackageItem( const QVariantMap& item_map ) PackageItem::PackageItem( const QVariantMap& item_map )
: id( CalamaresUtils::getString( item_map, "id" ) ) : id( CalamaresUtils::getString( item_map, "id" ) )
, name( CalamaresUtils::Locale::TranslatedString( item_map, "name" ) ) , name( CalamaresUtils::Locale::TranslatedString( item_map, "name" ) )
, description( CalamaresUtils::Locale::TranslatedString( item_map, "description" ) ) , description( CalamaresUtils::Locale::TranslatedString( item_map, "description" ) )
, screenshot( loadScreenshot( CalamaresUtils::getString( item_map, "screenshot" ) ) ) , screenshot( loadScreenshot( CalamaresUtils::getString( item_map, "screenshot" ) ) )
, packageNames( CalamaresUtils::getStringList( item_map, "packages" ) ) , packageNames( CalamaresUtils::getStringList( item_map, "packages" ) )
, netinstallData( getSubMap( item_map, "netinstall" ) )
{ {
if ( name.isEmpty() && id.isEmpty() ) if ( name.isEmpty() && id.isEmpty() )
{ {
@ -125,6 +134,20 @@ PackageListModel::getInstallPackagesForNames( const QStringList& ids ) const
return l; return l;
} }
QVariantList
PackageListModel::getNetinstallDataForNames( const QStringList& ids ) const
{
QVariantList l;
for ( const auto& p : qAsConst( m_packages ) )
{
if ( ids.contains( p.id ) )
{
l.append( p.netinstallData );
}
}
return l;
}
int int
PackageListModel::rowCount( const QModelIndex& index ) const PackageListModel::rowCount( const QModelIndex& index ) const
{ {

View File

@ -26,6 +26,7 @@ struct PackageItem
CalamaresUtils::Locale::TranslatedString description; CalamaresUtils::Locale::TranslatedString description;
QPixmap screenshot; QPixmap screenshot;
QStringList packageNames; QStringList packageNames;
QVariantMap netinstallData;
/// @brief Create blank PackageItem /// @brief Create blank PackageItem
PackageItem(); PackageItem();
@ -111,6 +112,14 @@ public:
*/ */
QStringList getInstallPackagesForNames( const QStringList& ids ) const; QStringList getInstallPackagesForNames( const QStringList& ids ) const;
/** @brief Does a name lookup (based on id) and returns the netinstall data
*
* If there is a package with an id in @p ids, returns their netinstall data
*
* returns a list of netinstall data or an emply list if none is found
*/
QVariantList getNetinstallDataForNames( const QStringList& ids ) const;
enum Roles : int enum Roles : int
{ {
NameRole = Qt::DisplayRole, NameRole = Qt::DisplayRole,