[tracking] Refactor creation of jobs
- Let the jobs handle their own styling and handling, simplify the ViewStep code.
This commit is contained in:
parent
309b2f872d
commit
49e66b11a2
@ -18,6 +18,8 @@
|
||||
|
||||
#include "TrackingJobs.h"
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "network/Manager.h"
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
#include "utils/Logger.h"
|
||||
@ -72,6 +74,44 @@ TrackingInstallJob::exec()
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
||||
|
||||
void
|
||||
TrackingInstallJob::addJob( Calamares::JobList& list, InstallTrackingConfig* config )
|
||||
{
|
||||
if ( config->isEnabled() )
|
||||
{
|
||||
QString installUrl = config->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;
|
||||
|
||||
list.append( Calamares::job_ptr( new TrackingInstallJob( installUrl ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TrackingMachineJob::addJob( Calamares::JobList& list, MachineTrackingConfig* config )
|
||||
{
|
||||
if ( config->isEnabled() )
|
||||
{
|
||||
const auto style = config->machineTrackingStyle();
|
||||
if ( style == "neon" )
|
||||
{
|
||||
list.append( Calamares::job_ptr( new TrackingMachineNeonJob() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
cWarning() << "Unsupported machine tracking style" << style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
TrackingMachineNeonJob::prettyName() const
|
||||
{
|
||||
|
@ -16,13 +16,35 @@
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRACKINGJOBS
|
||||
#define TRACKINGJOBS
|
||||
#ifndef TRACKING_TRACKINGJOBS_H
|
||||
#define TRACKING_TRACKINGJOBS_H
|
||||
|
||||
#include "Job.h"
|
||||
|
||||
class InstallTrackingConfig;
|
||||
class MachineTrackingConfig;
|
||||
|
||||
class QSemaphore;
|
||||
|
||||
/** @section Tracking Jobs
|
||||
*
|
||||
* The tracking jobs do the actual work of configuring tracking on the
|
||||
* target machine. Tracking jobs may have *styles*, variations depending
|
||||
* on the distro or environment of the target system. At the root of
|
||||
* each family of tracking jobs (installation, machine, user) there is
|
||||
* a class with static method `addJob()` that takes the configuration
|
||||
* information from the relevant Config sub-object and optionally
|
||||
* adds the right job (subclass!) to the list of jobs.
|
||||
*/
|
||||
|
||||
/** @brief Install-tracking job (gets a URL)
|
||||
*
|
||||
* The install-tracking job (there is only one kind) does a GET
|
||||
* on a configured URL with some additional information about
|
||||
* the machine (if configured into the URL).
|
||||
*
|
||||
* No persistent tracking is done.
|
||||
*/
|
||||
class TrackingInstallJob : public Calamares::Job
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -35,11 +57,25 @@ public:
|
||||
QString prettyStatusMessage() const override;
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
static void addJob( Calamares::JobList& list, InstallTrackingConfig* config );
|
||||
|
||||
private:
|
||||
const QString m_url;
|
||||
};
|
||||
|
||||
class TrackingMachineNeonJob : public Calamares::Job
|
||||
/** @brief Base class for machine-tracking jobs
|
||||
*
|
||||
* Machine-tracking configuraiton depends on the distro / style of machine
|
||||
* being tracked, so it has subclasses to switch on the relevant kind
|
||||
* of tracking. A machine is tracked persistently.
|
||||
*/
|
||||
class TrackingMachineJob : public Calamares::Job
|
||||
{
|
||||
public:
|
||||
static void addJob( Calamares::JobList& list, MachineTrackingConfig* config );
|
||||
};
|
||||
|
||||
class TrackingMachineNeonJob : public TrackingMachineJob
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -165,7 +165,7 @@ TrackingPage::setTrackingPolicy( TrackingType t, QString url )
|
||||
}
|
||||
else
|
||||
{
|
||||
connect( button, &QToolButton::clicked, [url] { QDesktopServices::openUrl( url ); } );
|
||||
connect( button, &QToolButton::clicked, [ url ] { QDesktopServices::openUrl( url ); } );
|
||||
cDebug() << "Tracking policy" << int( t ) << "set to" << url;
|
||||
}
|
||||
else
|
||||
@ -186,7 +186,7 @@ TrackingPage::setGeneralPolicy( QString url )
|
||||
ui->generalPolicyLabel->show();
|
||||
ui->generalPolicyLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
|
||||
ui->generalPolicyLabel->show();
|
||||
connect( ui->generalPolicyLabel, &QLabel::linkActivated, [url] { QDesktopServices::openUrl( url ); } );
|
||||
connect( ui->generalPolicyLabel, &QLabel::linkActivated, [ url ] { QDesktopServices::openUrl( url ); } );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,45 +106,19 @@ void
|
||||
TrackingViewStep::onLeave()
|
||||
{
|
||||
cDebug() << "Install tracking:" << m_config->installTracking()->isEnabled();
|
||||
cDebug() << "Machine tracking:" << m_config->machineTracking()->isEnabled();
|
||||
cDebug() << " User tracking:" << m_config->userTracking()->isEnabled();
|
||||
cDebug() << Logger::SubEntry << "Machine tracking:" << m_config->machineTracking()->isEnabled();
|
||||
cDebug() << Logger::SubEntry << " 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;
|
||||
}
|
||||
}
|
||||
Calamares::JobList l;
|
||||
TrackingInstallJob::addJob( l, m_config->installTracking() );
|
||||
TrackingMachineJob::addJob( l, m_config->machineTracking() );
|
||||
return l;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user