2020-03-24 12:02:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Luca Giambonini <almack@chakraos.org>
|
|
|
|
* Copyright 2016, Lisa Vitolo <shainer@chakraos.org>
|
|
|
|
* Copyright 2017, Kyle Robbertze <krobbertze@gmail.com>
|
|
|
|
* Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
|
|
|
|
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.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 "Config.h"
|
|
|
|
|
2020-03-24 13:13:18 +01:00
|
|
|
#include "network/Manager.h"
|
|
|
|
#include "utils/Logger.h"
|
2020-03-28 11:45:44 +01:00
|
|
|
#include "utils/RAII.h"
|
2020-03-24 13:13:18 +01:00
|
|
|
#include "utils/Yaml.h"
|
|
|
|
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
2020-03-24 12:02:16 +01:00
|
|
|
Config::Config( QObject* parent )
|
2020-03-24 13:13:18 +01:00
|
|
|
: QObject( parent )
|
|
|
|
, m_model( new PackageModel( this ) )
|
2020-03-24 12:02:16 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-24 13:13:18 +01:00
|
|
|
Config::~Config() {}
|
|
|
|
|
2020-03-27 14:54:06 +01:00
|
|
|
QString
|
|
|
|
Config::status() const
|
|
|
|
{
|
|
|
|
switch ( m_status )
|
|
|
|
{
|
|
|
|
case Status::Ok:
|
|
|
|
return QString();
|
|
|
|
case Status::FailedBadConfiguration:
|
|
|
|
return tr( "Network Installation. (Disabled: Incorrect configuration)" );
|
|
|
|
case Status::FailedBadData:
|
|
|
|
return tr( "Network Installation. (Disabled: Received invalid groups data)" );
|
|
|
|
case Status::FailedInternalError:
|
|
|
|
return tr( "Network Installation. (Disabled: internal error)" );
|
|
|
|
case Status::FailedNetworkError:
|
|
|
|
return tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" );
|
|
|
|
}
|
|
|
|
NOTREACHED return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-24 12:02:16 +01:00
|
|
|
void
|
2020-03-27 14:54:06 +01:00
|
|
|
Config::setStatus( Status s )
|
2020-03-24 12:02:16 +01:00
|
|
|
{
|
|
|
|
m_status = s;
|
2020-03-27 14:54:06 +01:00
|
|
|
emit statusChanged( status() );
|
2020-03-24 12:02:16 +01:00
|
|
|
}
|
2020-03-24 13:13:18 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
Config::loadGroupList( const QVariantList& groupData )
|
|
|
|
{
|
|
|
|
m_model->setupModelData( groupData );
|
2020-03-27 16:12:48 +01:00
|
|
|
emit statusReady();
|
2020-03-24 13:13:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::loadGroupList( const QUrl& url )
|
|
|
|
{
|
|
|
|
if ( !url.isValid() )
|
|
|
|
{
|
2020-03-27 14:54:06 +01:00
|
|
|
setStatus( Status::FailedBadConfiguration );
|
2020-03-24 13:13:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
using namespace CalamaresUtils::Network;
|
|
|
|
|
|
|
|
cDebug() << "NetInstall loading groups from" << url;
|
2020-03-27 21:14:47 +01:00
|
|
|
QNetworkReply* reply = Manager::instance().asynchronousGet(
|
2020-03-24 13:13:18 +01:00
|
|
|
url,
|
|
|
|
RequestOptions( RequestOptions::FakeUserAgent | RequestOptions::FollowRedirect, std::chrono::seconds( 30 ) ) );
|
|
|
|
|
|
|
|
if ( !reply )
|
|
|
|
{
|
|
|
|
cDebug() << Logger::Continuation << "request failed immediately.";
|
2020-03-27 14:54:06 +01:00
|
|
|
setStatus( Status::FailedBadConfiguration );
|
2020-03-24 13:13:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_reply = reply;
|
|
|
|
connect( reply, &QNetworkReply::finished, this, &Config::receivedGroupData );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::receivedGroupData()
|
|
|
|
{
|
|
|
|
if ( !m_reply || !m_reply->isFinished() )
|
|
|
|
{
|
|
|
|
cWarning() << "NetInstall data called too early.";
|
2020-03-27 14:54:06 +01:00
|
|
|
setStatus( Status::FailedInternalError );
|
2020-03-24 13:13:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cDebug() << "NetInstall group data received" << m_reply->size() << "bytes from" << m_reply->url();
|
|
|
|
|
2020-04-16 23:20:22 +02:00
|
|
|
cqDeleter< QNetworkReply > d { m_reply };
|
2020-03-24 13:13:18 +01:00
|
|
|
|
|
|
|
// If m_required is *false* then we still say we're ready
|
|
|
|
// even if the reply is corrupt or missing.
|
|
|
|
if ( m_reply->error() != QNetworkReply::NoError )
|
|
|
|
{
|
|
|
|
cWarning() << "unable to fetch netinstall package lists.";
|
|
|
|
cDebug() << Logger::SubEntry << "Netinstall reply error: " << m_reply->error();
|
|
|
|
cDebug() << Logger::SubEntry << "Request for url: " << m_reply->url().toString()
|
|
|
|
<< " failed with: " << m_reply->errorString();
|
2020-03-27 14:54:06 +01:00
|
|
|
setStatus( Status::FailedNetworkError );
|
2020-03-24 13:13:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray yamlData = m_reply->readAll();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
YAML::Node groups = YAML::Load( yamlData.constData() );
|
|
|
|
|
2020-04-16 23:20:22 +02:00
|
|
|
if ( groups.IsSequence() )
|
|
|
|
{
|
|
|
|
loadGroupList( CalamaresUtils::yamlSequenceToVariant( groups ) );
|
|
|
|
}
|
|
|
|
else if ( groups.IsMap() )
|
|
|
|
{
|
|
|
|
auto map = CalamaresUtils::yamlMapToVariant( groups );
|
|
|
|
loadGroupList( map.value( "groups" ).toList() );
|
|
|
|
}
|
|
|
|
else
|
2020-03-24 13:13:18 +01:00
|
|
|
{
|
|
|
|
cWarning() << "NetInstall groups data does not form a sequence.";
|
|
|
|
}
|
2020-04-16 23:20:22 +02:00
|
|
|
if ( m_model->rowCount() < 1 )
|
|
|
|
{
|
|
|
|
cWarning() << "NetInstall groups data was empty.";
|
|
|
|
}
|
2020-03-24 13:13:18 +01:00
|
|
|
}
|
|
|
|
catch ( YAML::Exception& e )
|
|
|
|
{
|
|
|
|
CalamaresUtils::explainYamlException( e, yamlData, "netinstall groups data" );
|
2020-03-27 14:54:06 +01:00
|
|
|
setStatus( Status::FailedBadData );
|
2020-03-24 13:13:18 +01:00
|
|
|
}
|
|
|
|
}
|