2016-06-28 00:00:47 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Luca Giambonini <almack@chakraos.org>
|
|
|
|
* Copyright 2016, Lisa Vitolo <shainer@chakraos.org>
|
2017-01-25 09:34:18 +01:00
|
|
|
* Copyright 2017, Kyle Robbertze <krobbertze@gmail.com>
|
2017-06-21 14:27:10 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2016-06-28 00:00:47 +02:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2017-01-23 13:42:40 +01:00
|
|
|
#include "PackageModel.h"
|
|
|
|
|
2016-06-26 00:26:08 +02:00
|
|
|
#include "ui_page_netinst.h"
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
|
|
|
#include "utils/Logger.h"
|
2017-01-25 09:34:18 +01:00
|
|
|
#include "utils/Retranslator.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>
|
|
|
|
|
2016-07-15 14:27:10 +02:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QNetworkReply>
|
2016-06-26 00:26:08 +02:00
|
|
|
|
2017-01-23 13:42:40 +01:00
|
|
|
#include <QHeaderView>
|
2016-06-26 00:26:08 +02:00
|
|
|
#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 )
|
2016-07-15 14:27:10 +02:00
|
|
|
, m_networkManager( this )
|
2017-06-17 21:14:02 +02:00
|
|
|
, m_groups( nullptr )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-09-06 11:47:11 +02:00
|
|
|
bool
|
|
|
|
NetInstallPage::readGroups( const QByteArray& yamlData )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2017-09-06 11:47:11 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
YAML::Node groups = YAML::Load( yamlData.constData() );
|
|
|
|
|
|
|
|
if ( !groups.IsSequence() )
|
|
|
|
cDebug() << "WARNING: netinstall groups data does not form a sequence.";
|
|
|
|
Q_ASSERT( groups.IsSequence() );
|
|
|
|
m_groups = new PackageModel( groups );
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
|
|
|
|
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Description" ) ); )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch ( YAML::Exception& e )
|
|
|
|
{
|
|
|
|
cDebug() << "WARNING: YAML error " << e.what() << "in netinstall groups data.";
|
|
|
|
if ( ( e.mark.line >= 0 ) && ( e.mark.column >= 0 ) )
|
|
|
|
{
|
|
|
|
// Try to show the line where it happened.
|
|
|
|
int linestart = 0;
|
|
|
|
for ( int linecount = 0; linecount < e.mark.line; ++linecount )
|
|
|
|
{
|
|
|
|
linestart = yamlData.indexOf( '\n', linestart );
|
|
|
|
// No more \ns found, weird
|
|
|
|
if ( linestart < 0 )
|
|
|
|
break;
|
|
|
|
linestart += 1; // Skip that \n
|
|
|
|
}
|
|
|
|
int lineend = linestart;
|
|
|
|
if ( linestart >= 0 )
|
|
|
|
{
|
|
|
|
lineend = yamlData.indexOf( '\n', linestart );
|
|
|
|
if ( lineend < 0 )
|
|
|
|
lineend = yamlData.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
int rangestart = linestart;
|
|
|
|
int rangeend = lineend;
|
|
|
|
// Adjust range (linestart..lineend) so it's not too long
|
|
|
|
if ( ( linestart >= 0 ) && ( e.mark.column > 30 ) )
|
|
|
|
rangestart += ( e.mark.column - 30 );
|
|
|
|
if ( ( linestart >= 0 ) && ( rangeend - rangestart > 40 ) )
|
|
|
|
rangeend = rangestart + 40;
|
|
|
|
|
|
|
|
if ( linestart >= 0 )
|
|
|
|
cDebug() << "WARNING: offending YAML data:" << yamlData.mid( rangestart, rangeend-rangestart ).constData();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-15 14:27:10 +02:00
|
|
|
NetInstallPage::dataIsHere( QNetworkReply* reply )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2016-07-15 14:27:10 +02:00
|
|
|
if ( reply->error() != QNetworkReply::NoError )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2016-07-15 14:27:10 +02:00
|
|
|
cDebug() << reply->errorString();
|
2016-06-26 00:26:08 +02:00
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-06 11:47:11 +02:00
|
|
|
if ( !readGroups( reply->readAll() ) )
|
|
|
|
{
|
|
|
|
cDebug() << "Netinstall groups data was received, but invalid.";
|
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
|
|
|
|
reply->deleteLater();
|
|
|
|
return;
|
|
|
|
}
|
2016-06-26 00:26:08 +02:00
|
|
|
|
2017-01-23 13:42:40 +01:00
|
|
|
ui->groupswidget->setModel( m_groups );
|
|
|
|
ui->groupswidget->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents );
|
|
|
|
ui->groupswidget->header()->setSectionResizeMode( 1, QHeaderView::Stretch );
|
2016-06-26 00:26:08 +02:00
|
|
|
|
2016-07-15 14:27:10 +02:00
|
|
|
reply->deleteLater();
|
2016-06-26 00:26:08 +02:00
|
|
|
emit checkReady( isReady() );
|
|
|
|
}
|
|
|
|
|
2017-01-25 09:34:18 +01:00
|
|
|
QList<PackageTreeItem::ItemData> NetInstallPage::selectedPackages() const
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2017-01-25 09:34:18 +01:00
|
|
|
return m_groups->getPackages();
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetInstallPage::loadGroupList()
|
|
|
|
{
|
|
|
|
QString confUrl(
|
|
|
|
Calamares::JobQueue::instance()->globalStorage()->value(
|
|
|
|
"groupsUrl" ).toString() );
|
|
|
|
|
2016-07-15 14:27:10 +02:00
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl( QUrl( confUrl ) );
|
|
|
|
// Follows all redirects except unsafe ones (https to http).
|
2017-01-23 14:04:07 +01:00
|
|
|
request.setAttribute( QNetworkRequest::FollowRedirectsAttribute, true );
|
2016-07-15 15:02:14 +02:00
|
|
|
// Not everybody likes the default User Agent used by this class (looking at you,
|
|
|
|
// sourceforge.net), so let's set a more descriptive one.
|
|
|
|
request.setRawHeader( "User-Agent", "Mozilla/5.0 (compatible; Calamares)" );
|
2016-07-15 14:27:10 +02:00
|
|
|
|
2017-01-23 14:04:07 +01:00
|
|
|
connect( &m_networkManager, &QNetworkAccessManager::finished,
|
|
|
|
this, &NetInstallPage::dataIsHere );
|
|
|
|
m_networkManager.get( request );
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetInstallPage::onActivate()
|
|
|
|
{
|
|
|
|
ui->groupswidget->setFocus();
|
|
|
|
}
|