[netinstall] Use the network-manager
- use asynchronousGet and keep the reply - drop unused includes - apply current coding style
This commit is contained in:
parent
badbdf59ee
commit
9850e4b35b
@ -22,26 +22,24 @@
|
|||||||
#include "NetInstallPage.h"
|
#include "NetInstallPage.h"
|
||||||
|
|
||||||
#include "PackageModel.h"
|
#include "PackageModel.h"
|
||||||
|
|
||||||
#include "ui_page_netinst.h"
|
#include "ui_page_netinst.h"
|
||||||
|
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#include "network/Manager.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
#include "utils/Yaml.h"
|
#include "utils/Yaml.h"
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
|
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
using CalamaresUtils::yamlToVariant;
|
using CalamaresUtils::yamlToVariant;
|
||||||
|
|
||||||
NetInstallPage::NetInstallPage( QWidget* parent )
|
NetInstallPage::NetInstallPage( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::Page_NetInst )
|
, ui( new Ui::Page_NetInst )
|
||||||
, m_networkManager( this )
|
, m_reply( nullptr )
|
||||||
, m_groups( nullptr )
|
, m_groups( nullptr )
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
@ -55,14 +53,14 @@ NetInstallPage::readGroups( const QByteArray& yamlData )
|
|||||||
YAML::Node groups = YAML::Load( yamlData.constData() );
|
YAML::Node groups = YAML::Load( yamlData.constData() );
|
||||||
|
|
||||||
if ( !groups.IsSequence() )
|
if ( !groups.IsSequence() )
|
||||||
|
{
|
||||||
cWarning() << "netinstall groups data does not form a sequence.";
|
cWarning() << "netinstall groups data does not form a sequence.";
|
||||||
|
}
|
||||||
Q_ASSERT( groups.IsSequence() );
|
Q_ASSERT( groups.IsSequence() );
|
||||||
m_groups = new PackageModel( groups );
|
m_groups = new PackageModel( groups );
|
||||||
CALAMARES_RETRANSLATE(
|
CALAMARES_RETRANSLATE( m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
|
||||||
m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) );
|
|
||||||
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) ); )
|
m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) ); )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( YAML::Exception& e )
|
catch ( YAML::Exception& e )
|
||||||
{
|
{
|
||||||
@ -71,29 +69,53 @@ NetInstallPage::readGroups( const QByteArray& yamlData )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/// @brief Convenience to zero out and deleteLater on the reply, used in dataIsHere
|
||||||
NetInstallPage::dataIsHere( QNetworkReply* reply )
|
struct ReplyDeleter
|
||||||
{
|
{
|
||||||
cDebug() << "NetInstall group data received" << reply->url();
|
QNetworkReply*& p;
|
||||||
reply->deleteLater();
|
|
||||||
|
~ReplyDeleter()
|
||||||
|
{
|
||||||
|
if ( p )
|
||||||
|
{
|
||||||
|
p->deleteLater();
|
||||||
|
}
|
||||||
|
p = nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
NetInstallPage::dataIsHere()
|
||||||
|
{
|
||||||
|
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 };
|
||||||
|
|
||||||
// If m_required is *false* then we still say we're ready
|
// If m_required is *false* then we still say we're ready
|
||||||
// even if the reply is corrupt or missing.
|
// even if the reply is corrupt or missing.
|
||||||
if ( reply->error() != QNetworkReply::NoError )
|
if ( m_reply->error() != QNetworkReply::NoError )
|
||||||
{
|
{
|
||||||
cWarning() << "unable to fetch netinstall package lists.";
|
cWarning() << "unable to fetch netinstall package lists.";
|
||||||
cDebug() << Logger::SubEntry << "Netinstall reply error: " << reply->error();
|
cDebug() << Logger::SubEntry << "Netinstall reply error: " << m_reply->error();
|
||||||
cDebug() << Logger::SubEntry << "Request for url: " << reply->url().toString() << " failed with: " << reply->errorString();
|
cDebug() << Logger::SubEntry << "Request for url: " << m_reply->url().toString()
|
||||||
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
|
<< " failed with: " << m_reply->errorString();
|
||||||
|
ui->netinst_status->setText(
|
||||||
|
tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) );
|
||||||
emit checkReady( !m_required );
|
emit checkReady( !m_required );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !readGroups( reply->readAll() ) )
|
if ( !readGroups( m_reply->readAll() ) )
|
||||||
{
|
{
|
||||||
cWarning() << "netinstall groups data was received, but invalid.";
|
cWarning() << "netinstall groups data was received, but invalid.";
|
||||||
cDebug() << Logger::SubEntry << "Url: " << reply->url().toString();
|
cDebug() << Logger::SubEntry << "Url: " << m_reply->url().toString();
|
||||||
cDebug() << Logger::SubEntry << "Headers: " << reply->rawHeaderList();
|
cDebug() << Logger::SubEntry << "Headers: " << m_reply->rawHeaderList();
|
||||||
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Received invalid groups data)" ) );
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Received invalid groups data)" ) );
|
||||||
emit checkReady( !m_required );
|
emit checkReady( !m_required );
|
||||||
return;
|
return;
|
||||||
@ -110,7 +132,9 @@ PackageModel::PackageItemDataList
|
|||||||
NetInstallPage::selectedPackages() const
|
NetInstallPage::selectedPackages() const
|
||||||
{
|
{
|
||||||
if ( m_groups )
|
if ( m_groups )
|
||||||
|
{
|
||||||
return m_groups->getPackages();
|
return m_groups->getPackages();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "no netinstall groups are available.";
|
cWarning() << "no netinstall groups are available.";
|
||||||
@ -121,24 +145,23 @@ NetInstallPage::selectedPackages() const
|
|||||||
void
|
void
|
||||||
NetInstallPage::loadGroupList( const QString& confUrl )
|
NetInstallPage::loadGroupList( const QString& confUrl )
|
||||||
{
|
{
|
||||||
cDebug() << "NetInstall loading groups from" << confUrl;
|
using namespace CalamaresUtils::Network;
|
||||||
QNetworkRequest request;
|
|
||||||
request.setUrl( QUrl( confUrl ) );
|
|
||||||
// Follows all redirects except unsafe ones (https to http).
|
|
||||||
request.setAttribute( QNetworkRequest::FollowRedirectsAttribute, true );
|
|
||||||
// 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)" );
|
|
||||||
|
|
||||||
connect( &m_networkManager, &QNetworkAccessManager::finished,
|
cDebug() << "NetInstall loading groups from" << confUrl;
|
||||||
this, &NetInstallPage::dataIsHere );
|
QNetworkReply* reply = Manager::instance().asynchronouseGet(
|
||||||
auto* rq = m_networkManager.get( request );
|
QUrl( confUrl ),
|
||||||
if ( rq->error() )
|
RequestOptions( RequestOptions::FakeUserAgent | RequestOptions::FollowRedirect, std::chrono::seconds( 30 ) ) );
|
||||||
|
|
||||||
|
if ( !reply )
|
||||||
{
|
{
|
||||||
cDebug() << Logger::Continuation << "request failed immediately," << rq->errorString();
|
cDebug() << Logger::Continuation << "request failed immediately.";
|
||||||
rq->deleteLater();
|
|
||||||
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Incorrect configuration)" ) );
|
ui->netinst_status->setText( tr( "Network Installation. (Disabled: Incorrect configuration)" ) );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_reply = reply;
|
||||||
|
connect( reply, &QNetworkReply::finished, this, &NetInstallPage::dataIsHere );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -24,14 +24,10 @@
|
|||||||
#include "PackageModel.h"
|
#include "PackageModel.h"
|
||||||
#include "PackageTreeItem.h"
|
#include "PackageTreeItem.h"
|
||||||
|
|
||||||
#include <QAbstractButton>
|
#include <QString>
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
// required forward declarations
|
|
||||||
class QByteArray;
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class QString;
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -57,10 +53,7 @@ public:
|
|||||||
// corrupt or unavailable data causes checkReady() to be emitted
|
// corrupt or unavailable data causes checkReady() to be emitted
|
||||||
// true (not-required) or false.
|
// true (not-required) or false.
|
||||||
void setRequired( bool );
|
void setRequired( bool );
|
||||||
bool getRequired() const
|
bool getRequired() const { return m_required; }
|
||||||
{
|
|
||||||
return m_required;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the list of packages belonging to groups that are
|
// Returns the list of packages belonging to groups that are
|
||||||
// selected in the view in this given moment. No data is cached here, so
|
// selected in the view in this given moment. No data is cached here, so
|
||||||
@ -68,7 +61,7 @@ public:
|
|||||||
PackageModel::PackageItemDataList selectedPackages() const;
|
PackageModel::PackageItemDataList selectedPackages() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void dataIsHere( QNetworkReply* );
|
void dataIsHere();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkReady( bool );
|
void checkReady( bool );
|
||||||
@ -81,9 +74,7 @@ private:
|
|||||||
|
|
||||||
Ui::Page_NetInst* ui;
|
Ui::Page_NetInst* ui;
|
||||||
|
|
||||||
// Handles connection with the remote URL storing the configuration.
|
QNetworkReply* m_reply;
|
||||||
QNetworkAccessManager m_networkManager;
|
|
||||||
|
|
||||||
PackageModel* m_groups;
|
PackageModel* m_groups;
|
||||||
bool m_required;
|
bool m_required;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user