[packagechooser,netinstall] Add support for packagechooser to drive netinstall
This commit is contained in:
parent
4e61f24960
commit
2eda55d3af
@ -15,6 +15,7 @@
|
||||
#include "PackageModel.h"
|
||||
#include "ui_page_netinst.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
|
||||
#include "network/Manager.h"
|
||||
@ -62,4 +63,19 @@ void
|
||||
NetInstallPage::onActivate()
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,29 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c
|
||||
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
|
||||
PackageModel::getPackages() const
|
||||
{
|
||||
@ -309,3 +332,15 @@ PackageModel::setupModelData( const QVariantList& l )
|
||||
setupModelData( l, m_rootItem );
|
||||
emit endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageModel::appendModelData( const QVariantList& groupList )
|
||||
{
|
||||
if ( m_rootItem )
|
||||
{
|
||||
emit beginResetModel();
|
||||
setupModelData( groupList, m_rootItem );
|
||||
emit endResetModel();
|
||||
}
|
||||
}
|
||||
|
@ -54,9 +54,14 @@ public:
|
||||
int rowCount( 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 getItemPackages( PackageTreeItem* item ) const;
|
||||
|
||||
void appendModelData( const QVariantList& groupList );
|
||||
|
||||
private:
|
||||
friend class ItemTests;
|
||||
|
||||
|
@ -55,6 +55,8 @@ PackageChooserMethodNames()
|
||||
{ "custom", PackageChooserMethod::Legacy },
|
||||
{ "contextualprocess", PackageChooserMethod::Legacy },
|
||||
{ "packages", PackageChooserMethod::Packages },
|
||||
{ "netinstall-add", PackageChooserMethod::NetAdd },
|
||||
{ "netinstall-select", PackageChooserMethod::NetSelect },
|
||||
};
|
||||
return names;
|
||||
}
|
||||
@ -121,6 +123,23 @@ Config::updateGlobalStorage( const QStringList& selected ) const
|
||||
CalamaresUtils::Packages::setGSPackageAdditions(
|
||||
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
|
||||
{
|
||||
cWarning() << "Unknown packagechooser method" << smash( m_method );
|
||||
|
@ -33,6 +33,8 @@ enum class PackageChooserMethod
|
||||
{
|
||||
Legacy, // use contextualprocess or other custom
|
||||
Packages, // use the packages module
|
||||
NetAdd, // adds packages to the netinstall module
|
||||
NetSelect, // makes selections in the netinstall module
|
||||
};
|
||||
|
||||
const NamedEnumTable< PackageChooserMethod >& PackageChooserMethodNames();
|
||||
|
@ -15,6 +15,14 @@
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
static QVariantMap
|
||||
getSubMap( const QVariantMap& map, const QString& key )
|
||||
{
|
||||
bool success;
|
||||
|
||||
return CalamaresUtils::getSubMap( map, key, success );
|
||||
}
|
||||
|
||||
static QPixmap
|
||||
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" ) )
|
||||
, name( CalamaresUtils::Locale::TranslatedString( item_map, "name" ) )
|
||||
, description( CalamaresUtils::Locale::TranslatedString( item_map, "description" ) )
|
||||
, screenshot( loadScreenshot( CalamaresUtils::getString( item_map, "screenshot" ) ) )
|
||||
, packageNames( CalamaresUtils::getStringList( item_map, "packages" ) )
|
||||
, netinstallData( getSubMap( item_map, "netinstall" ) )
|
||||
{
|
||||
if ( name.isEmpty() && id.isEmpty() )
|
||||
{
|
||||
@ -125,6 +134,20 @@ PackageListModel::getInstallPackagesForNames( const QStringList& ids ) const
|
||||
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
|
||||
PackageListModel::rowCount( const QModelIndex& index ) const
|
||||
{
|
||||
|
@ -26,6 +26,7 @@ struct PackageItem
|
||||
CalamaresUtils::Locale::TranslatedString description;
|
||||
QPixmap screenshot;
|
||||
QStringList packageNames;
|
||||
QVariantMap netinstallData;
|
||||
|
||||
/// @brief Create blank PackageItem
|
||||
PackageItem();
|
||||
@ -111,6 +112,14 @@ public:
|
||||
*/
|
||||
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
|
||||
{
|
||||
NameRole = Qt::DisplayRole,
|
||||
|
Loading…
Reference in New Issue
Block a user