2017-11-09 11:19:24 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde..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 "TrackingJobs.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2017-11-13 11:13:19 +01:00
|
|
|
#include <QEventLoop>
|
2017-11-09 11:19:24 +01:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QSemaphore>
|
2017-11-13 11:13:19 +01:00
|
|
|
#include <QTimer>
|
2017-11-09 11:19:24 +01:00
|
|
|
|
|
|
|
TrackingInstallJob::TrackingInstallJob( const QString& url )
|
|
|
|
: m_url( url )
|
2017-11-09 11:45:25 +01:00
|
|
|
, m_networkManager( nullptr )
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-09 11:45:25 +01:00
|
|
|
TrackingInstallJob::~TrackingInstallJob()
|
|
|
|
{
|
|
|
|
delete m_networkManager;
|
|
|
|
}
|
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
QString TrackingInstallJob::prettyName() const
|
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return tr( "Installation feedback" );
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TrackingInstallJob::prettyDescription() const
|
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return prettyName();
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TrackingInstallJob::prettyStatusMessage() const
|
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
return tr( "Sending installation feedback." );
|
2017-11-09 11:19:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobResult TrackingInstallJob::exec()
|
|
|
|
{
|
2017-11-09 11:45:25 +01:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl( QUrl( m_url ) );
|
|
|
|
// 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)" );
|
|
|
|
|
2017-11-13 11:13:19 +01:00
|
|
|
QTimer timeout;
|
|
|
|
timeout.setSingleShot(true);
|
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
connect( m_networkManager, &QNetworkAccessManager::finished,
|
|
|
|
this, &TrackingInstallJob::dataIsHere );
|
2017-11-13 11:13:19 +01:00
|
|
|
connect( m_networkManager, &QNetworkAccessManager::finished,
|
|
|
|
&loop, &QEventLoop::quit );
|
|
|
|
connect( &timeout, &QTimer::timeout,
|
|
|
|
&loop, &QEventLoop::quit );
|
2017-11-09 11:19:24 +01:00
|
|
|
|
|
|
|
m_networkManager->get( request ); // The semaphore is released when data is received
|
2017-11-13 11:13:19 +01:00
|
|
|
timeout.start( 5000 /* ms */ );
|
|
|
|
|
|
|
|
loop.exec();
|
|
|
|
|
|
|
|
if ( !timeout.isActive() )
|
2017-11-09 11:19:24 +01:00
|
|
|
{
|
|
|
|
cDebug() << "WARNING: install-tracking request timed out.";
|
|
|
|
return Calamares::JobResult::error( tr( "Internal error in install-tracking." ),
|
|
|
|
tr( "HTTP request timed out." ) );
|
|
|
|
}
|
2017-11-13 11:13:19 +01:00
|
|
|
timeout.stop();
|
2017-11-09 11:19:24 +01:00
|
|
|
|
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackingInstallJob::dataIsHere( QNetworkReply* reply )
|
|
|
|
{
|
2017-11-22 13:49:06 +01:00
|
|
|
cDebug() << "Installation feedback request OK";
|
2017-11-09 11:19:24 +01:00
|
|
|
reply->deleteLater();
|
|
|
|
}
|
2017-11-22 13:39:52 +01:00
|
|
|
|
|
|
|
QString TrackingMachineNeonJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Machine feedback" );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TrackingMachineNeonJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
return prettyName();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TrackingMachineNeonJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Configuring machine feedback." );
|
|
|
|
}
|
|
|
|
|
|
|
|
Calamares::JobResult TrackingMachineNeonJob::exec()
|
|
|
|
{
|
|
|
|
return Calamares::JobResult::error( tr( "Error in machine feedback configuration." ),
|
|
|
|
tr( "Could not configure machine feedback correctly." ) );
|
|
|
|
}
|