Change signature of JobQueue::progress, add finished() signal
Now uses a qreal for progress instead of current and total Also added a finished() signal because determining whether the queue is finished should not be done by comparing a qreal with 1.0 as this is not precise.
This commit is contained in:
parent
2636a1273f
commit
e9da5cb6cb
@ -50,31 +50,33 @@ public:
|
|||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
int total = m_jobs.size();
|
qreal total = m_jobs.size();
|
||||||
int current = 0;
|
int current = 0;
|
||||||
for( auto job : m_jobs )
|
for( auto job : m_jobs )
|
||||||
{
|
{
|
||||||
emitProgress( current, total, job->prettyName() );
|
qreal percent = current / total;
|
||||||
|
emitProgress( percent, job->prettyName() );
|
||||||
JobResult result = job->exec();
|
JobResult result = job->exec();
|
||||||
if ( !result )
|
if ( !result )
|
||||||
{
|
{
|
||||||
emitFailed( result.message(), result.details() );
|
emitFailed( result.message(), result.details() );
|
||||||
|
emitFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++current;
|
++current;
|
||||||
}
|
}
|
||||||
emitProgress( total, total, QString() );
|
emitProgress( 1, QString() );
|
||||||
|
emitFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList< Calamares::job_ptr > m_jobs;
|
QList< Calamares::job_ptr > m_jobs;
|
||||||
JobQueue* m_queue;
|
JobQueue* m_queue;
|
||||||
|
|
||||||
void emitProgress( int current, int total, const QString& prettyName )
|
void emitProgress( qreal percent, const QString& prettyName )
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection,
|
QMetaObject::invokeMethod( m_queue, "progress", Qt::QueuedConnection,
|
||||||
Q_ARG( int, current ),
|
Q_ARG( qreal, percent ),
|
||||||
Q_ARG( int, total ),
|
|
||||||
Q_ARG( QString, prettyName )
|
Q_ARG( QString, prettyName )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -86,6 +88,11 @@ private:
|
|||||||
Q_ARG( QString, details )
|
Q_ARG( QString, details )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void emitFinished()
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod( m_queue, "finished", Qt::QueuedConnection );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ public:
|
|||||||
void start();
|
void start();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progress( int current, int total, const QString& prettyName );
|
void progress( qreal percent, const QString& prettyName );
|
||||||
|
void finished();
|
||||||
void failed( const QString& message, const QString& details );
|
void failed( const QString& message, const QString& details );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -32,6 +32,7 @@ InstallationViewStep::InstallationViewStep( QObject* parent )
|
|||||||
, m_widget( new QWidget )
|
, m_widget( new QWidget )
|
||||||
{
|
{
|
||||||
m_progressBar = new QProgressBar;
|
m_progressBar = new QProgressBar;
|
||||||
|
m_progressBar->setMaximum( 10000 );
|
||||||
m_label = new QLabel;
|
m_label = new QLabel;
|
||||||
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
||||||
layout->addWidget(m_progressBar);
|
layout->addWidget(m_progressBar);
|
||||||
@ -88,10 +89,9 @@ InstallationViewStep::jobs() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InstallationViewStep::updateFromJobQueue( int current, int total, const QString& message )
|
InstallationViewStep::updateFromJobQueue( qreal percent, const QString& message )
|
||||||
{
|
{
|
||||||
m_progressBar->setMaximum( total );
|
m_progressBar->setValue( percent * m_progressBar->maximum() );
|
||||||
m_progressBar->setValue( current );
|
|
||||||
m_label->setText( message );
|
m_label->setText( message );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ private:
|
|||||||
QProgressBar* m_progressBar;
|
QProgressBar* m_progressBar;
|
||||||
QLabel* m_label;
|
QLabel* m_label;
|
||||||
|
|
||||||
void updateFromJobQueue( int current, int total, const QString& message );
|
void updateFromJobQueue( qreal percent, const QString& message );
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,36 +32,32 @@ Partition* firstFreePartition( PartitionNode* parent )
|
|||||||
QueueRunner::QueueRunner( JobQueue* queue )
|
QueueRunner::QueueRunner( JobQueue* queue )
|
||||||
: m_queue( queue )
|
: m_queue( queue )
|
||||||
{
|
{
|
||||||
connect( m_queue, &JobQueue::progress, this, &QueueRunner::onProgress );
|
connect( m_queue, &JobQueue::finished, this, &QueueRunner::onFinished );
|
||||||
connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed );
|
connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
QueueRunner::run()
|
QueueRunner::run()
|
||||||
{
|
{
|
||||||
m_done = false;
|
m_finished = false;
|
||||||
m_success = false;
|
m_success = true;
|
||||||
m_queue->start();
|
m_queue->start();
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
while ( !m_done )
|
while ( !m_finished )
|
||||||
loop.processEvents();
|
loop.processEvents();
|
||||||
return m_success;
|
return m_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QueueRunner::onProgress( int current, int total, const QString& prettyName )
|
QueueRunner::onFinished()
|
||||||
{
|
{
|
||||||
QVERIFY( current <= total );
|
m_finished = true;
|
||||||
if ( current < total )
|
|
||||||
return;
|
|
||||||
m_success = true;
|
|
||||||
m_done = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
QueueRunner::onFailed( const QString& message, const QString& details )
|
QueueRunner::onFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
m_done = true;
|
m_success = false;
|
||||||
QString msg = message + "\ndetails: " + details;
|
QString msg = message + "\ndetails: " + details;
|
||||||
QFAIL( qPrintable( msg ) );
|
QFAIL( qPrintable( msg ) );
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ public:
|
|||||||
bool run();
|
bool run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onProgress( int current, int total, const QString& prettyName );
|
|
||||||
void onFailed( const QString& message, const QString& details );
|
void onFailed( const QString& message, const QString& details );
|
||||||
|
void onFinished();
|
||||||
Calamares::JobQueue* m_queue;
|
Calamares::JobQueue* m_queue;
|
||||||
bool m_done;
|
bool m_finished;
|
||||||
bool m_success;
|
bool m_success;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user