2016-06-28 00:00:47 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Luca Giambonini <almack@chakraos.org>
|
|
|
|
* Copyright 2016, Lisa Vitolo <shainer@chakraos.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/>.
|
|
|
|
*/
|
|
|
|
|
2016-06-26 00:26:08 +02:00
|
|
|
#include "NetInstallPage.h"
|
|
|
|
|
2016-06-28 00:00:47 +02:00
|
|
|
#include "widgets/groupselectionwidget.h"
|
2016-06-26 00:26:08 +02:00
|
|
|
#include "ui_page_netinst.h"
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
|
|
|
#include "utils/Logger.h"
|
2016-06-28 00:23:10 +02:00
|
|
|
#include "utils/YamlUtils.h"
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
#include <KIO/Job>
|
|
|
|
#include <KIO/StoredTransferJob>
|
|
|
|
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QWidget>
|
2016-06-30 23:59:29 +02:00
|
|
|
#include <QSignalMapper>
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
2016-06-28 00:23:10 +02:00
|
|
|
using CalamaresUtils::yamlToVariant;
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
NetInstallPage::NetInstallPage( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, ui( new Ui::Page_NetInst )
|
|
|
|
{
|
|
|
|
ui->setupUi( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
NetInstallPage::isReady()
|
|
|
|
{
|
|
|
|
// nothing to wait for, the data are immediately ready
|
|
|
|
// if the user does not select any group nothing is installed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-28 00:23:10 +02:00
|
|
|
void NetInstallPage::readGroups( const QByteArray& yamlData )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
|
|
|
YAML::Node groups = YAML::Load( yamlData.constData() );
|
|
|
|
Q_ASSERT( groups.IsSequence() );
|
|
|
|
|
|
|
|
for ( YAML::const_iterator it = groups.begin(); it != groups.end(); ++it )
|
|
|
|
{
|
|
|
|
YAML::Node groupDefinition = it->as<YAML::Node>();
|
|
|
|
|
2016-06-28 00:23:10 +02:00
|
|
|
QString name( tr( yamlToVariant(groupDefinition["name"]).toByteArray() ) );
|
|
|
|
QString description( tr( yamlToVariant(groupDefinition["description"]).toByteArray() ) );
|
2016-06-26 00:26:08 +02:00
|
|
|
QStringList packages;
|
|
|
|
|
|
|
|
for ( YAML::const_iterator it = groupDefinition["packages"].begin();
|
|
|
|
it != groupDefinition["packages"].end(); ++it )
|
2016-06-28 00:23:10 +02:00
|
|
|
packages.append( yamlToVariant(*it).toString() );
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
m_groups[name].name = name;
|
|
|
|
m_groups[name].description = description;
|
|
|
|
m_groups[name].packages = packages;
|
|
|
|
|
|
|
|
if ( groupDefinition["selected"] )
|
2016-06-28 00:23:10 +02:00
|
|
|
m_groups[name].selected = yamlToVariant( groupDefinition["selected"] ).toBool();
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
if ( groupDefinition["hidden"] )
|
2016-06-28 00:23:10 +02:00
|
|
|
m_groups[name].hidden = yamlToVariant( groupDefinition["hidden"] ).toBool();
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
m_groupOrder.append( name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NetInstallPage::dataIsHere( KJob* job )
|
|
|
|
{
|
|
|
|
if ( job->error() )
|
|
|
|
{
|
|
|
|
qDebug() << job->errorString();
|
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto transferJob = dynamic_cast<KIO::StoredTransferJob*>( job );
|
|
|
|
Q_ASSERT( transferJob != nullptr );
|
2016-06-28 00:23:10 +02:00
|
|
|
readGroups( transferJob->data() );
|
2016-06-26 00:26:08 +02:00
|
|
|
|
|
|
|
QSignalMapper* mapper = new QSignalMapper( this );
|
|
|
|
foreach ( const QString& groupKey, m_groupOrder )
|
|
|
|
{
|
|
|
|
Group group = m_groups[groupKey];
|
|
|
|
if ( group.hidden )
|
|
|
|
{
|
|
|
|
// Do not present on view.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GroupSelectionWidget* groupWidget = new GroupSelectionWidget( group.name, group.description, group.packages, this );
|
|
|
|
m_groupWidgets.insert( groupKey, groupWidget );
|
|
|
|
ui->groupswidget->layout()->addWidget( groupWidget );
|
|
|
|
|
|
|
|
mapper->setMapping( groupWidget, groupKey );
|
2016-06-30 23:59:29 +02:00
|
|
|
connect( groupWidget, &GroupSelectionWidget::toggled, mapper,
|
|
|
|
static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map) );
|
|
|
|
//connect( groupWidget, SIGNAL( toggled( bool ) ), mapper, SLOT( map() ) );
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
emit checkReady( isReady() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList NetInstallPage::selectedPackages() const
|
|
|
|
{
|
|
|
|
QStringList selectedPackages;
|
|
|
|
|
|
|
|
// Add all the packages for groups that are toggled in the view.
|
|
|
|
for ( auto it = m_groupWidgets.constBegin(); it != m_groupWidgets.constEnd(); it++ )
|
|
|
|
{
|
|
|
|
if ( it.value()->isToggled() )
|
|
|
|
selectedPackages += m_groups[it.key()].packages;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all the packages for groups that are hidden but selected.
|
|
|
|
for ( const Group& group : m_groups.values() )
|
|
|
|
{
|
|
|
|
if ( group.hidden && group.selected )
|
|
|
|
selectedPackages += group.packages;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedPackages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetInstallPage::loadGroupList()
|
|
|
|
{
|
|
|
|
QString confUrl(
|
|
|
|
Calamares::JobQueue::instance()->globalStorage()->value(
|
|
|
|
"groupsUrl" ).toString() );
|
|
|
|
|
|
|
|
KIO::Job* getJob = KIO::storedGet( confUrl, KIO::Reload, KIO::Overwrite | KIO::HideProgressInfo );
|
2016-06-30 23:27:37 +02:00
|
|
|
connect ( getJob, &KIO::Job::result, this, &NetInstallPage::dataIsHere );
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetInstallPage::onActivate()
|
|
|
|
{
|
|
|
|
ui->groupswidget->setFocus();
|
|
|
|
}
|