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>
|
2018-06-15 11:59:11 +02:00
|
|
|
* Copyright 2017-2018, 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"
|
2019-09-02 14:10:36 +02:00
|
|
|
|
2016-06-26 00:26:08 +02:00
|
|
|
#include "JobQueue.h"
|
2018-05-21 16:58:57 +02:00
|
|
|
|
2019-09-02 14:10:36 +02:00
|
|
|
#include "network/Manager.h"
|
2016-06-26 00:26:08 +02:00
|
|
|
#include "utils/Logger.h"
|
2017-01-25 09:34:18 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2019-04-29 12:04:55 +02:00
|
|
|
#include "utils/Yaml.h"
|
2016-06-26 00:26:08 +02:00
|
|
|
|
2017-01-23 13:42:40 +01:00
|
|
|
#include <QHeaderView>
|
2019-09-02 14:10:36 +02:00
|
|
|
#include <QNetworkReply>
|
2016-06-26 00:26:08 +02:00
|
|
|
|
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 )
|
2019-09-02 14:10:36 +02:00
|
|
|
, m_reply( nullptr )
|
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() )
|
2019-09-02 14:10:36 +02:00
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "netinstall groups data does not form a sequence.";
|
2019-09-02 14:10:36 +02:00
|
|
|
}
|
2017-09-06 11:47:11 +02:00
|
|
|
Q_ASSERT( groups.IsSequence() );
|
|
|
|
m_groups = new PackageModel( groups );
|
2019-09-02 14:10:36 +02:00
|
|
|
CALAMARES_RETRANSLATE( m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-09-02 14:10:36 +02:00
|
|
|
/// @brief Convenience to zero out and deleteLater on the reply, used in dataIsHere
|
|
|
|
struct ReplyDeleter
|
|
|
|
{
|
|
|
|
QNetworkReply*& p;
|
|
|
|
|
|
|
|
~ReplyDeleter()
|
|
|
|
{
|
|
|
|
if ( p )
|
|
|
|
{
|
|
|
|
p->deleteLater();
|
|
|
|
}
|
|
|
|
p = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-26 00:26:08 +02:00
|
|
|
void
|
2019-09-02 14:10:36 +02:00
|
|
|
NetInstallPage::dataIsHere()
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2019-09-02 14:10:36 +02:00
|
|
|
if ( !m_reply || !m_reply->isFinished() )
|
|
|
|
{
|
|
|
|
cWarning() << "NetInstall data called too early.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cDebug() << "NetInstall group data received" << m_reply->url();
|
|
|
|
|
|
|
|
ReplyDeleter d { m_reply };
|
2019-08-01 14:31:25 +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.
|
2019-09-02 14:10:36 +02:00
|
|
|
if ( m_reply->error() != QNetworkReply::NoError )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "unable to fetch netinstall package lists.";
|
2019-09-02 14:10:36 +02:00
|
|
|
cDebug() << Logger::SubEntry << "Netinstall reply error: " << m_reply->error();
|
|
|
|
cDebug() << Logger::SubEntry << "Request for url: " << m_reply->url().toString()
|
|
|
|
<< " failed with: " << m_reply->errorString();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-02 14:10:36 +02:00
|
|
|
if ( !readGroups( m_reply->readAll() ) )
|
2017-09-06 11:47:11 +02:00
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "netinstall groups data was received, but invalid.";
|
2019-09-02 14:10:36 +02:00
|
|
|
cDebug() << Logger::SubEntry << "Url: " << m_reply->url().toString();
|
|
|
|
cDebug() << Logger::SubEntry << "Headers: " << m_reply->rawHeaderList();
|
2017-10-23 17:44:39 +02:00
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Received invalid groups data)" ) );
|
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
|
|
|
|
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 )
|
2019-09-02 14:10:36 +02:00
|
|
|
{
|
2017-11-06 11:25:14 +01:00
|
|
|
return m_groups->getPackages();
|
2019-09-02 14:10:36 +02:00
|
|
|
}
|
2017-11-06 11:25:14 +01:00
|
|
|
else
|
|
|
|
{
|
2018-02-13 11:07:12 +01:00
|
|
|
cWarning() << "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
|
2018-05-21 16:58:57 +02:00
|
|
|
NetInstallPage::loadGroupList( const QString& confUrl )
|
2016-06-26 00:26:08 +02:00
|
|
|
{
|
2019-09-02 14:10:36 +02:00
|
|
|
using namespace CalamaresUtils::Network;
|
|
|
|
|
2019-08-01 14:31:25 +02:00
|
|
|
cDebug() << "NetInstall loading groups from" << confUrl;
|
2019-09-02 14:10:36 +02:00
|
|
|
QNetworkReply* reply = Manager::instance().asynchronouseGet(
|
|
|
|
QUrl( confUrl ),
|
|
|
|
RequestOptions( RequestOptions::FakeUserAgent | RequestOptions::FollowRedirect, std::chrono::seconds( 30 ) ) );
|
|
|
|
|
|
|
|
if ( !reply )
|
2019-08-01 14:39:09 +02:00
|
|
|
{
|
2019-09-02 14:10:36 +02:00
|
|
|
cDebug() << Logger::Continuation << "request failed immediately.";
|
2019-08-01 14:39:09 +02:00
|
|
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Incorrect configuration)" ) );
|
|
|
|
}
|
2019-09-02 14:10:36 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_reply = reply;
|
|
|
|
connect( reply, &QNetworkReply::finished, this, &NetInstallPage::dataIsHere );
|
|
|
|
}
|
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();
|
|
|
|
}
|