2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2017-08-29 14:00:37 +02:00
|
|
|
*
|
|
|
|
* 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 "JobQueue.h"
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "utils/Logger.h"
|
2017-11-06 16:12:41 +01:00
|
|
|
#include "utils/CalamaresUtils.h"
|
2017-11-08 15:35:49 +01:00
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
2017-08-29 14:00:37 +02:00
|
|
|
|
2017-11-09 11:19:24 +01:00
|
|
|
#include "TrackingJobs.h"
|
2017-08-29 14:00:37 +02:00
|
|
|
#include "TrackingPage.h"
|
2017-11-09 11:19:24 +01:00
|
|
|
#include "TrackingViewStep.h"
|
2017-08-29 14:00:37 +02:00
|
|
|
|
2017-11-08 13:46:33 +01:00
|
|
|
#include <QDesktopServices>
|
2017-08-29 14:00:37 +02:00
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( TrackingViewStepFactory, registerPlugin<TrackingViewStep>(); )
|
|
|
|
|
2017-11-22 13:39:52 +01:00
|
|
|
/** @brief Is @p s a valid machine-tracking style. */
|
|
|
|
static bool isValidStyle( const QString& s )
|
|
|
|
{
|
|
|
|
static QStringList knownStyles { "neon" };
|
|
|
|
return knownStyles.contains( s );
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:00:37 +02:00
|
|
|
TrackingViewStep::TrackingViewStep( QObject* parent )
|
|
|
|
: Calamares::ViewStep( parent )
|
|
|
|
, m_widget( new TrackingPage )
|
|
|
|
{
|
|
|
|
emit nextStatusChanged( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TrackingViewStep::~TrackingViewStep()
|
|
|
|
{
|
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
TrackingViewStep::prettyName() const
|
|
|
|
{
|
2017-11-22 13:21:58 +01:00
|
|
|
return tr( "Feedback" );
|
2017-08-29 14:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
|
|
|
TrackingViewStep::widget()
|
|
|
|
{
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingViewStep::next()
|
|
|
|
{
|
|
|
|
emit done();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingViewStep::back()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TrackingViewStep::isNextEnabled() const
|
|
|
|
{
|
2017-11-06 16:12:41 +01:00
|
|
|
return true;
|
2017-08-29 14:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TrackingViewStep::isBackEnabled() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TrackingViewStep::isAtBeginning() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TrackingViewStep::isAtEnd() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-08 10:25:36 +01:00
|
|
|
void TrackingViewStep::onLeave()
|
|
|
|
{
|
2017-11-21 13:51:30 +01:00
|
|
|
m_installTracking.userEnabled = m_widget->getTrackingOption( TrackingType::InstallTracking );
|
|
|
|
m_machineTracking.userEnabled = m_widget->getTrackingOption( TrackingType::MachineTracking );
|
|
|
|
m_userTracking.userEnabled = m_widget->getTrackingOption( TrackingType::UserTracking );
|
|
|
|
cDebug() << "Install tracking:" << m_installTracking.enabled();
|
|
|
|
cDebug() << "Machine tracking:" << m_machineTracking.enabled();
|
|
|
|
cDebug() << " User tracking:" << m_userTracking.enabled();
|
2017-11-08 10:25:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-08 15:59:40 +01:00
|
|
|
Calamares::JobList
|
2017-08-29 14:00:37 +02:00
|
|
|
TrackingViewStep::jobs() const
|
|
|
|
{
|
2017-11-08 15:59:40 +01:00
|
|
|
Calamares::JobList l;
|
|
|
|
|
|
|
|
cDebug() << "Creating tracking jobs ..";
|
2017-11-22 13:39:52 +01:00
|
|
|
if ( m_installTracking.enabled() && !m_installTrackingUrl.isEmpty() )
|
2017-11-08 15:35:49 +01:00
|
|
|
{
|
|
|
|
QString installUrl = m_installTrackingUrl;
|
|
|
|
const auto s = CalamaresUtils::System::instance();
|
|
|
|
|
|
|
|
QString memory, disk;
|
|
|
|
memory.setNum( s->getTotalMemoryB().first );
|
|
|
|
disk.setNum( s->getTotalDiskB() );
|
|
|
|
|
|
|
|
installUrl
|
|
|
|
.replace( "$CPU", s->getCpuDescription() )
|
|
|
|
.replace( "$MEMORY", memory )
|
|
|
|
.replace( "$DISK", disk );
|
|
|
|
|
|
|
|
cDebug() << " .. install-tracking URL" << installUrl;
|
2017-11-09 11:45:25 +01:00
|
|
|
|
|
|
|
l.append( Calamares::job_ptr( new TrackingInstallJob( installUrl ) ) );
|
2017-11-08 15:35:49 +01:00
|
|
|
}
|
2017-11-22 13:39:52 +01:00
|
|
|
|
|
|
|
if ( m_machineTracking.enabled() && !m_machineTrackingStyle.isEmpty() )
|
|
|
|
{
|
|
|
|
Q_ASSERT( isValidStyle( m_machineTrackingStyle ) );
|
|
|
|
if ( m_machineTrackingStyle == "neon" )
|
|
|
|
l.append( Calamares::job_ptr( new TrackingMachineNeonJob() ) );
|
|
|
|
}
|
2017-11-08 15:59:40 +01:00
|
|
|
return l;
|
2017-08-29 14:00:37 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 16:12:41 +01:00
|
|
|
|
2017-11-08 13:46:33 +01:00
|
|
|
QVariantMap TrackingViewStep::setTrackingOption(const QVariantMap& configurationMap, const QString& key, TrackingType t)
|
2017-11-06 16:12:41 +01:00
|
|
|
{
|
2017-11-08 10:25:36 +01:00
|
|
|
bool settingEnabled = false;
|
2017-11-06 16:12:41 +01:00
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
auto config = CalamaresUtils::getSubMap( configurationMap, key, success );
|
|
|
|
|
|
|
|
if ( success )
|
|
|
|
{
|
2017-11-08 10:25:36 +01:00
|
|
|
settingEnabled = CalamaresUtils::getBool( config, "enabled", false );
|
2017-11-06 16:12:41 +01:00
|
|
|
}
|
2017-11-08 10:25:36 +01:00
|
|
|
|
2017-11-08 15:49:32 +01:00
|
|
|
TrackingEnabled& trackingConfiguration = tracking( t );
|
2017-11-08 10:25:36 +01:00
|
|
|
trackingConfiguration.settingEnabled = settingEnabled;
|
2017-11-21 13:51:30 +01:00
|
|
|
trackingConfiguration.userEnabled = false;
|
2017-11-06 16:12:41 +01:00
|
|
|
|
2017-11-21 13:51:30 +01:00
|
|
|
m_widget->enableTrackingOption(t, settingEnabled);
|
2017-11-08 13:46:33 +01:00
|
|
|
m_widget->setTrackingPolicy(t, CalamaresUtils::getString( config, "policy" ) );
|
|
|
|
|
|
|
|
return config;
|
2017-11-06 16:12:41 +01:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:00:37 +02:00
|
|
|
void
|
|
|
|
TrackingViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
2017-11-08 15:35:49 +01:00
|
|
|
QVariantMap config;
|
|
|
|
|
|
|
|
config = setTrackingOption( configurationMap, "install", TrackingType::InstallTracking );
|
|
|
|
m_installTrackingUrl = CalamaresUtils::getString( config, "url" );
|
|
|
|
|
2017-11-22 13:39:52 +01:00
|
|
|
config = setTrackingOption( configurationMap, "machine", TrackingType::MachineTracking );
|
|
|
|
auto s = CalamaresUtils::getString( config, "style" );
|
|
|
|
if ( isValidStyle( s ) )
|
|
|
|
m_machineTrackingStyle = s;
|
|
|
|
|
2017-11-08 10:25:36 +01:00
|
|
|
setTrackingOption( configurationMap, "user", TrackingType::UserTracking );
|
2017-11-21 13:51:30 +01:00
|
|
|
|
|
|
|
m_widget->setGeneralPolicy( CalamaresUtils::getString( configurationMap, "policy" ) );
|
|
|
|
m_widget->setTrackingLevel( CalamaresUtils::getString( configurationMap, "default" ) );
|
2017-08-29 14:00:37 +02:00
|
|
|
}
|