[libcalamares] Refactor job-weight computations

- only check index-vs-length once
main
Adriaan de Groot 6 years ago
parent 07da6e3905
commit afc0c78b4c

@ -73,7 +73,8 @@ public:
} }
emitProgress(); emitProgress();
cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName() << " (there are" << m_jobs.count() << " left)"; cDebug() << "Starting" << ( anyFailed ? "EMERGENCY JOB" : "job" ) << job->prettyName() << " (there are"
<< m_jobs.count() << " left)";
connect( job.data(), &Job::progress, this, &JobThread::emitProgress ); connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
JobResult result = job->exec(); JobResult result = job->exec();
if ( !anyFailed && !result ) if ( !anyFailed && !result )
@ -113,20 +114,20 @@ private:
int jobCount = m_jobs.size(); int jobCount = m_jobs.size();
QString message = m_jobIndex < jobCount ? m_jobs.at( m_jobIndex )->prettyStatusMessage() : tr( "Done" ); QString message = m_jobIndex < jobCount ? m_jobs.at( m_jobIndex )->prettyStatusMessage() : tr( "Done" );
qreal percent = 1.0; // Pretend we're done, since the if will reset it
if ( m_jobIndex < jobCount )
{
qreal cumulativeProgress = 0.0; qreal cumulativeProgress = 0.0;
for ( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) ) for ( auto jobWeight : m_jobWeights.mid( 0, m_jobIndex ) )
{ {
cumulativeProgress += jobWeight; cumulativeProgress += jobWeight;
} }
qreal percent percent = cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent );
= m_jobIndex < jobCount ? cumulativeProgress + ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) : 1.0;
if ( m_jobIndex < jobCount ) Logger::CDebug( Logger::LOGVERBOSE )
{ << "[JOBQUEUE]: Progress for Job[" << m_jobIndex << "]: " << ( jobPercent * 100 ) << "% completed";
Logger::CDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress for Job[" << m_jobIndex Logger::CDebug( Logger::LOGVERBOSE )
<< "]: " << ( jobPercent * 100 ) << "% completed"; << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 ) << "% (accumulated) + "
Logger::CDebug( Logger::LOGVERBOSE ) << "[JOBQUEUE]: Progress Overall: " << ( cumulativeProgress * 100 )
<< "% (accumulated) + "
<< ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 ) << ( ( ( m_jobWeights.at( m_jobIndex ) ) * jobPercent ) * 100 )
<< "% (this job) = " << ( percent * 100 ) << "% (total)"; << "% (this job) = " << ( percent * 100 ) << "% (total)";
} }

Loading…
Cancel
Save