/* === This file is part of Calamares - === * * Copyright 2017, Adriaan de Groot * * 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 . */ #include "TrackingViewStep.h" #include "Config.h" #include "TrackingJobs.h" #include "TrackingPage.h" #include "GlobalStorage.h" #include "JobQueue.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" #include "utils/Variant.h" #include #include CALAMARES_PLUGIN_FACTORY_DEFINITION( TrackingViewStepFactory, registerPlugin< TrackingViewStep >(); ) /** @brief Is @p s a valid machine-tracking style. */ static bool isValidStyle( const QString& s ) { static QStringList knownStyles { "neon" }; return knownStyles.contains( s ); } TrackingViewStep::TrackingViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_config( new Config( this ) ) , m_widget( new TrackingPage( m_config ) ) { emit nextStatusChanged( false ); } TrackingViewStep::~TrackingViewStep() { if ( m_widget && m_widget->parent() == nullptr ) { m_widget->deleteLater(); } } QString TrackingViewStep::prettyName() const { return tr( "Feedback" ); } QWidget* TrackingViewStep::widget() { return m_widget; } bool TrackingViewStep::isNextEnabled() const { return true; } bool TrackingViewStep::isBackEnabled() const { return true; } bool TrackingViewStep::isAtBeginning() const { return true; } bool TrackingViewStep::isAtEnd() const { return true; } void TrackingViewStep::onLeave() { cDebug() << "Install tracking:" << m_config->installTracking()->isEnabled(); cDebug() << "Machine tracking:" << m_config->machineTracking()->isEnabled(); cDebug() << " User tracking:" << m_config->userTracking()->isEnabled(); } Calamares::JobList TrackingViewStep::jobs() const { Calamares::JobList l; cDebug() << "Creating tracking jobs .."; if ( m_config->installTracking()->isEnabled() ) { QString installUrl = m_config->installTracking()->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() << Logger::SubEntry << "install-tracking URL" << installUrl; l.append( Calamares::job_ptr( new TrackingInstallJob( installUrl ) ) ); } if ( m_config->machineTracking()->isEnabled() ) { const auto style = m_config->machineTracking()->machineTrackingStyle(); if ( style == "neon" ) { l.append( Calamares::job_ptr( new TrackingMachineNeonJob() ) ); } else { cWarning() << "Unsupported machine tracking style" << style; } } return l; } void TrackingViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { m_config->setConfigurationMap( configurationMap ); bool ok; m_widget->setTrackingLevel( trackingNames().find( CalamaresUtils::getString( configurationMap, "default" ), ok ) ); if ( !ok ) { cWarning() << "Default tracking level unknown:" << CalamaresUtils::getString( configurationMap, "default" ); } } const NamedEnumTable< TrackingType >& trackingNames() { // *INDENT-OFF* // clang-format off static const NamedEnumTable< TrackingType > names { { QStringLiteral( "none" ), TrackingType::NoTracking }, { QStringLiteral( "install" ), TrackingType::InstallTracking }, { QStringLiteral( "machine" ), TrackingType::MachineTracking }, { QStringLiteral( "user" ), TrackingType::UserTracking } }; // clang-format on // *INDENT-ON* return names; }