[calamares] Make module-tester configurable in slideshow mode

- Uses global storage to steer the jobs that are created, in case
  the slideshow needs to be tweaked by percentages or whatever.
- While here, add some code docs and apply coding style.
This commit is contained in:
Adriaan de Groot 2020-05-20 12:12:11 +02:00
parent d51a545fcf
commit 738a6a9019

View File

@ -144,8 +144,9 @@ handle_args( QCoreApplication& a )
class ExecViewJob : public Calamares::CppJob class ExecViewJob : public Calamares::CppJob
{ {
public: public:
explicit ExecViewJob( const QString& name ) explicit ExecViewJob( const QString& name, unsigned long t = 3 )
: m_name( name ) : m_name( name )
, m_delay( t )
{ {
} }
virtual ~ExecViewJob() override; virtual ~ExecViewJob() override;
@ -154,7 +155,7 @@ public:
Calamares::JobResult exec() override Calamares::JobResult exec() override
{ {
QThread::sleep( 3 ); QThread::sleep( m_delay );
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
} }
@ -162,6 +163,7 @@ public:
private: private:
QString m_name; QString m_name;
unsigned long m_delay;
}; };
ExecViewJob::~ExecViewJob() {} ExecViewJob::~ExecViewJob() {}
@ -194,9 +196,12 @@ protected:
ExecViewModule::ExecViewModule() ExecViewModule::ExecViewModule()
: Calamares::Module() : Calamares::Module()
{ {
// Normally the module-loader gives the module an instance key
// (out of the settings file, or the descriptor of the module).
// We don't have one, so build one -- this gives us "x@x".
QVariantMap m; QVariantMap m;
m.insert( "name", "x" ); m.insert( "name", "x" );
Calamares::Module::initFrom(m, "x" ); Calamares::Module::initFrom( m, "x" );
} }
ExecViewModule::~ExecViewModule() {} ExecViewModule::~ExecViewModule() {}
@ -212,7 +217,7 @@ ExecViewModule::loadSelf()
auto* viewStep = new Calamares::ExecutionViewStep(); auto* viewStep = new Calamares::ExecutionViewStep();
viewStep->setModuleInstanceKey( instanceKey() ); viewStep->setModuleInstanceKey( instanceKey() );
viewStep->setConfigurationMap( m_configurationMap ); viewStep->setConfigurationMap( m_configurationMap );
viewStep->appendJobModuleInstanceKey( "x@x" ); viewStep->appendJobModuleInstanceKey( instanceKey().toString() );
Calamares::ViewManager::instance()->addViewStep( viewStep ); Calamares::ViewManager::instance()->addViewStep( viewStep );
m_loaded = true; m_loaded = true;
} }
@ -234,9 +239,34 @@ Calamares::JobList
ExecViewModule::jobs() const ExecViewModule::jobs() const
{ {
Calamares::JobList l; Calamares::JobList l;
const auto* gs = Calamares::JobQueue::instance()->globalStorage();
if ( gs && gs->contains( "jobs" ) )
{
QVariantList joblist = gs->value( "jobs" ).toList();
for ( const auto& jd : joblist )
{
QVariantMap jobdescription = jd.toMap();
if ( jobdescription.contains( "name" ) && jobdescription.contains( "delay" ) )
{
l.append( Calamares::job_ptr( new ExecViewJob( jobdescription.value( "name" ).toString(),
jobdescription.value( "delay" ).toULongLong() ) ) );
}
}
}
if ( l.count() > 0 )
{
return l;
}
l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "step 1" ) ) ) ); l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "step 1" ) ) ) );
l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "step two" ) ) ) ); l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "step two" ) ) ) );
l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "step III" ) ) ) ); l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "locking mutexes" ), 20 ) ) );
l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "unlocking mutexes" ), 1 ) ) );
for ( const QString& s : QStringList { "Harder", "Better", "Faster", "Stronger" } )
{
l.append( Calamares::job_ptr( new ExecViewJob( s, 0 ) ) );
}
l.append( Calamares::job_ptr( new ExecViewJob( QStringLiteral( "cleaning up" ), 20 ) ) );
return l; return l;
} }