2019-08-02 10:57:12 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PackageChooserViewStep.h"
|
|
|
|
|
|
|
|
#include "PackageChooserPage.h"
|
2019-08-02 13:05:46 +02:00
|
|
|
#include "PackageModel.h"
|
2019-08-02 10:57:12 +02:00
|
|
|
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
|
|
|
|
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( PackageChooserViewStepFactory, registerPlugin< PackageChooserViewStep >(); )
|
|
|
|
|
|
|
|
PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
|
|
|
|
: Calamares::ViewStep( parent )
|
|
|
|
, m_widget( nullptr )
|
2019-08-02 13:05:46 +02:00
|
|
|
, m_model( nullptr )
|
2019-08-03 23:28:55 +02:00
|
|
|
, m_mode( PackageChooserMode::Required )
|
2019-08-02 10:57:12 +02:00
|
|
|
{
|
|
|
|
emit nextStatusChanged( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PackageChooserViewStep::~PackageChooserViewStep()
|
|
|
|
{
|
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
{
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
2019-08-02 13:05:46 +02:00
|
|
|
delete m_model;
|
2019-08-02 10:57:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
PackageChooserViewStep::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Packages" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
|
|
|
PackageChooserViewStep::widget()
|
|
|
|
{
|
|
|
|
if ( !m_widget )
|
|
|
|
{
|
2019-08-02 16:25:26 +02:00
|
|
|
m_widget = new PackageChooserPage( m_mode, nullptr );
|
2019-08-02 17:06:03 +02:00
|
|
|
connect( m_widget, &PackageChooserPage::selectionChanged, [=]() {
|
|
|
|
emit nextStatusChanged( this->isNextEnabled() );
|
|
|
|
} );
|
|
|
|
|
2019-08-02 13:05:46 +02:00
|
|
|
if ( m_model )
|
|
|
|
{
|
|
|
|
hookupModel();
|
|
|
|
}
|
2019-08-02 16:26:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cWarning() << "PackageChooser Widget created before model.";
|
|
|
|
}
|
2019-08-02 10:57:12 +02:00
|
|
|
}
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PackageChooserViewStep::isNextEnabled() const
|
|
|
|
{
|
2019-08-02 16:25:26 +02:00
|
|
|
if ( !m_model )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m_widget )
|
|
|
|
{
|
|
|
|
// No way to have changed anything
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-02 16:43:10 +02:00
|
|
|
switch ( m_mode )
|
2019-08-02 16:25:26 +02:00
|
|
|
{
|
2019-08-02 16:43:10 +02:00
|
|
|
case PackageChooserMode::Optional:
|
2019-08-03 23:28:55 +02:00
|
|
|
case PackageChooserMode::OptionalMultiple:
|
2019-08-02 17:06:03 +02:00
|
|
|
// zero or one OR zero or more
|
2019-08-02 16:43:10 +02:00
|
|
|
return true;
|
2019-08-03 23:28:55 +02:00
|
|
|
case PackageChooserMode::Required:
|
2019-08-02 16:43:10 +02:00
|
|
|
case PackageChooserMode::RequiredMultiple:
|
2019-08-02 17:06:03 +02:00
|
|
|
// exactly one OR one or more
|
|
|
|
return m_widget->hasSelection();
|
2019-08-02 16:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED return true;
|
2019-08-02 10:57:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PackageChooserViewStep::isBackEnabled() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PackageChooserViewStep::isAtBeginning() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PackageChooserViewStep::isAtEnd() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PackageChooserViewStep::onLeave()
|
|
|
|
{
|
2019-08-03 23:51:00 +02:00
|
|
|
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 );
|
2019-08-04 00:08:41 +02:00
|
|
|
|
2019-08-03 23:51:00 +02:00
|
|
|
cDebug() << "PackageChooser" << key << "selected" << value;
|
2019-08-02 10:57:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobList
|
|
|
|
PackageChooserViewStep::jobs() const
|
|
|
|
{
|
|
|
|
Calamares::JobList l;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
2019-08-03 15:45:00 +02:00
|
|
|
QString mode = CalamaresUtils::getString( configurationMap, "mode" );
|
|
|
|
bool ok = false;
|
|
|
|
if ( !mode.isEmpty() )
|
|
|
|
{
|
|
|
|
m_mode = roleNames().find( mode, ok );
|
|
|
|
}
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
m_mode = PackageChooserMode::Required;
|
|
|
|
}
|
2019-08-03 23:28:55 +02:00
|
|
|
|
2019-08-03 23:24:30 +02:00
|
|
|
m_id = CalamaresUtils::getString( configurationMap, "id" );
|
2019-08-03 23:33:34 +02:00
|
|
|
if ( m_id.isEmpty() )
|
|
|
|
{
|
|
|
|
// Not set, so use the instance id
|
|
|
|
// TODO: use a stronger type than QString for structured IDs
|
|
|
|
m_id = moduleInstanceKey().split( '@' ).last();
|
|
|
|
}
|
2019-08-03 23:28:55 +02:00
|
|
|
|
2019-08-04 16:00:55 +02:00
|
|
|
bool first_time = !m_model;
|
2019-08-04 20:19:56 +02:00
|
|
|
if ( configurationMap.contains( "items" ) )
|
2019-08-04 16:00:55 +02:00
|
|
|
{
|
2019-08-04 20:19:56 +02:00
|
|
|
fillModel( configurationMap.value( "items" ).toList() );
|
2019-08-04 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( first_time && m_widget && m_model )
|
|
|
|
{
|
|
|
|
hookupModel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-08-04 20:19:56 +02:00
|
|
|
PackageChooserViewStep::fillModel( const QVariantList& items )
|
2019-08-04 16:00:55 +02:00
|
|
|
{
|
|
|
|
if ( !m_model )
|
|
|
|
{
|
|
|
|
m_model = new PackageListModel( nullptr );
|
|
|
|
}
|
2019-08-02 13:05:46 +02:00
|
|
|
|
2019-08-04 20:19:56 +02:00
|
|
|
if ( items.isEmpty() )
|
2019-08-04 16:00:55 +02:00
|
|
|
{
|
2019-08-04 20:19:56 +02:00
|
|
|
cWarning() << "No *items* for PackageChooser module.";
|
|
|
|
return;
|
|
|
|
}
|
2019-08-02 13:05:46 +02:00
|
|
|
|
2019-08-04 20:19:56 +02:00
|
|
|
cDebug() << "Loading PackageChooser model items from config";
|
|
|
|
int item_index = 0;
|
|
|
|
for ( const auto& item_it : items )
|
|
|
|
{
|
|
|
|
++item_index;
|
|
|
|
QVariantMap item_map = item_it.toMap();
|
2019-08-04 16:00:55 +02:00
|
|
|
if ( item_map.isEmpty() )
|
2019-08-02 13:05:46 +02:00
|
|
|
{
|
2019-08-04 20:19:56 +02:00
|
|
|
cWarning() << "PackageChooser entry" << item_index << "is not valid.";
|
2019-08-04 16:00:55 +02:00
|
|
|
continue;
|
2019-08-02 13:05:46 +02:00
|
|
|
}
|
2019-08-04 16:00:55 +02:00
|
|
|
|
2019-08-06 15:55:27 +02:00
|
|
|
if ( item_map.contains( "appdata" ) )
|
|
|
|
{
|
2019-08-06 22:36:35 +02:00
|
|
|
m_model->addPackage( PackageItem::fromAppData( item_map ) );
|
2019-08-06 15:55:27 +02:00
|
|
|
}
|
2019-08-19 13:10:38 +02:00
|
|
|
else if ( item_map.contains( "appstream" ) )
|
|
|
|
{
|
|
|
|
m_model->addPackage( PackageItem::fromAppStream( item_map ) );
|
|
|
|
}
|
2019-08-06 15:55:27 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_model->addPackage( PackageItem( item_map ) );
|
|
|
|
}
|
2019-08-02 13:05:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PackageChooserViewStep::hookupModel()
|
|
|
|
{
|
|
|
|
if ( !m_model || !m_widget )
|
|
|
|
{
|
|
|
|
cError() << "Can't hook up model until widget and model both exist.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_widget->setModel( m_model );
|
2019-08-02 10:57:12 +02:00
|
|
|
}
|