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>
|
2017-10-28 02:18:36 +02:00
|
|
|
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.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 );
|
|
|
|
}
|
|
|
|
|
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" ) );
|
2017-10-28 02:18:36 +02:00
|
|
|
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) ); )
|
2017-09-06 11:47:11 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch ( YAML::Exception& e )
|
|
|
|
{
|
2017-09-06 13:51:22 +02:00
|
|
|
CalamaresUtils::explainYamlException( e, yamlData, "netinstall groups data" );
|
2017-09-06 11:47:11 +02:00
|
|
|
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
|
|
|
{
|
2017-11-06 11:14:42 +01:00
|
|
|
// If m_required is *false* then we still say we're ready
|
|
|
|
// even if the reply is corrupt or missing.
|
2016-07-15 14:27:10 +02:00
|
|
|
if ( reply->error() != QNetworkReply::NoError )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2017-11-06 19:46:26 +01:00
|
|
|
cDebug() << "WARNING: unable to fetch netinstall package lists.";
|
|
|
|
cDebug() << " ..Netinstall reply error: " << reply->error();
|
|
|
|
cDebug() << " ..Request for url: " << reply->url().toString() << " failed with: " << 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)" ) );
|
2017-11-06 11:14:42 +01:00
|
|
|
emit checkReady( !m_required );
|
2016-06-26 00:26:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-06 11:47:11 +02:00
|
|
|
if ( !readGroups( reply->readAll() ) )
|
|
|
|
{
|
2017-11-06 19:46:26 +01:00
|
|
|
cDebug() << "WARNING: netinstall groups data was received, but invalid.";
|
|
|
|
cDebug() << " ..Url: " << reply->url().toString();
|
|
|
|
cDebug() << " ..Headers: " << reply->rawHeaderList();
|
2017-10-23 17:44:39 +02:00
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Received invalid groups data)" ) );
|
2017-09-06 11:47:11 +02:00
|
|
|
reply->deleteLater();
|
2017-11-06 11:14:42 +01:00
|
|
|
emit checkReady( !m_required );
|
2017-09-06 11:47:11 +02:00
|
|
|
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();
|
2017-11-06 11:14:42 +01:00
|
|
|
emit checkReady( true );
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 11:42:13 +01:00
|
|
|
PackageModel::PackageItemDataList
|
2017-11-06 11:34:57 +01:00
|
|
|
NetInstallPage::selectedPackages() const
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2017-11-06 11:25:14 +01:00
|
|
|
if ( m_groups )
|
|
|
|
return m_groups->getPackages();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cDebug() << "WARNING: no netinstall groups are available.";
|
2017-11-06 11:42:13 +01:00
|
|
|
return PackageModel::PackageItemDataList();
|
2017-11-06 11:25:14 +01:00
|
|
|
}
|
2016-06-26 00:26:08 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 11:34:57 +01:00
|
|
|
void
|
|
|
|
NetInstallPage::loadGroupList()
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-11-06 11:34:57 +01:00
|
|
|
void
|
|
|
|
NetInstallPage::setRequired( bool b )
|
2017-11-06 11:14:42 +01:00
|
|
|
{
|
|
|
|
m_required = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-06 11:34:57 +01:00
|
|
|
void
|
|
|
|
NetInstallPage::onActivate()
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
|
|
|
ui->groupswidget->setFocus();
|
|
|
|
}
|