Add support for per-job progress
This commit is contained in:
parent
e9da5cb6cb
commit
89fd6a950b
@ -64,8 +64,7 @@ public:
|
|||||||
virtual QString prettyName() const = 0;
|
virtual QString prettyName() const = 0;
|
||||||
virtual JobResult exec() = 0;
|
virtual JobResult exec() = 0;
|
||||||
signals:
|
signals:
|
||||||
void running( const Calamares::job_ptr& );
|
void progress( qreal percent );
|
||||||
void finished( const Calamares::job_ptr& );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "CalamaresConfig.h"
|
#include "CalamaresConfig.h"
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
@ -50,12 +51,11 @@ public:
|
|||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
qreal total = m_jobs.size();
|
m_jobIndex = 0;
|
||||||
int current = 0;
|
|
||||||
for( auto job : m_jobs )
|
for( auto job : m_jobs )
|
||||||
{
|
{
|
||||||
qreal percent = current / total;
|
emitProgress();
|
||||||
emitProgress( percent, job->prettyName() );
|
connect( job.data(), &Job::progress, this, &JobThread::emitProgress );
|
||||||
JobResult result = job->exec();
|
JobResult result = job->exec();
|
||||||
if ( !result )
|
if ( !result )
|
||||||
{
|
{
|
||||||
@ -63,21 +63,34 @@ public:
|
|||||||
emitFinished();
|
emitFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++current;
|
++m_jobIndex;
|
||||||
}
|
}
|
||||||
emitProgress( 1, QString() );
|
emitProgress();
|
||||||
emitFinished();
|
emitFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList< Calamares::job_ptr > m_jobs;
|
QList< Calamares::job_ptr > m_jobs;
|
||||||
JobQueue* m_queue;
|
JobQueue* m_queue;
|
||||||
|
int m_jobIndex;
|
||||||
|
|
||||||
void emitProgress( qreal percent, const QString& prettyName )
|
void emitProgress( qreal jobPercent = 0 )
|
||||||
{
|
{
|
||||||
|
// Make sure jobPercent is reasonable, in case a job messed up its
|
||||||
|
// percentage computations.
|
||||||
|
jobPercent = qBound( qreal( 0 ), jobPercent, qreal( 1 ) );
|
||||||
|
|
||||||
|
int jobCount = m_jobs.size();
|
||||||
|
QString message = m_jobIndex < jobCount
|
||||||
|
? m_jobs.at( m_jobIndex )->prettyName()
|
||||||
|
: tr( "Done" );
|
||||||
|
|
||||||
|
qreal percent = ( m_jobIndex + jobPercent ) / qreal( jobCount );
|
||||||
|
cLog() << Q_FUNC_INFO << "percent=" << percent * 100 << message;
|
||||||
|
|
||||||
QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection,
|
QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection,
|
||||||
Q_ARG( qreal, percent ),
|
Q_ARG( qreal, percent ),
|
||||||
Q_ARG( QString, prettyName )
|
Q_ARG( QString, message )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +53,13 @@ CreatePartitionJob::prettyName() const
|
|||||||
Calamares::JobResult
|
Calamares::JobResult
|
||||||
CreatePartitionJob::exec()
|
CreatePartitionJob::exec()
|
||||||
{
|
{
|
||||||
|
int step = 0;
|
||||||
|
const qreal stepCount = 4;
|
||||||
|
|
||||||
Report report( 0 );
|
Report report( 0 );
|
||||||
QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() );
|
QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() );
|
||||||
|
|
||||||
|
progress( step++ / stepCount );
|
||||||
CoreBackend* backend = CoreBackendManager::self()->backend();
|
CoreBackend* backend = CoreBackendManager::self()->backend();
|
||||||
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
|
QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
|
||||||
if ( !backendDevice.data() )
|
if ( !backendDevice.data() )
|
||||||
@ -66,6 +70,7 @@ CreatePartitionJob::exec()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress( step++ / stepCount );
|
||||||
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
|
QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
|
||||||
if ( !backendPartitionTable.data() )
|
if ( !backendPartitionTable.data() )
|
||||||
{
|
{
|
||||||
@ -75,6 +80,7 @@ CreatePartitionJob::exec()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progress( step++ / stepCount );
|
||||||
QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
|
QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
|
||||||
if ( partitionPath.isEmpty() )
|
if ( partitionPath.isEmpty() )
|
||||||
{
|
{
|
||||||
@ -85,6 +91,7 @@ CreatePartitionJob::exec()
|
|||||||
}
|
}
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
|
progress( step++ / stepCount );
|
||||||
FileSystem& fs = m_partition->fileSystem();
|
FileSystem& fs = m_partition->fileSystem();
|
||||||
if ( fs.type() == FileSystem::Unformatted || fs.type() == FileSystem::Extended )
|
if ( fs.type() == FileSystem::Unformatted || fs.type() == FileSystem::Extended )
|
||||||
return Calamares::JobResult::ok();
|
return Calamares::JobResult::ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user