From e9da5cb6cbe6a48f476b041acf0944939f7527b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Wed, 23 Jul 2014 10:58:08 +0200 Subject: [PATCH] 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. --- src/libcalamares/JobQueue.cpp | 19 +++++++++++++------ src/libcalamares/JobQueue.h | 3 ++- src/libcalamaresui/InstallationViewStep.cpp | 6 +++--- src/libcalamaresui/InstallationViewStep.h | 2 +- src/modules/partition/tests/JobTests.cpp | 18 +++++++----------- src/modules/partition/tests/JobTests.h | 4 ++-- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index e40fe5466..f6c7d17ed 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -50,31 +50,33 @@ public: void run() override { - int total = m_jobs.size(); + qreal total = m_jobs.size(); int current = 0; for( auto job : m_jobs ) { - emitProgress( current, total, job->prettyName() ); + qreal percent = current / total; + emitProgress( percent, job->prettyName() ); JobResult result = job->exec(); if ( !result ) { emitFailed( result.message(), result.details() ); + emitFinished(); return; } ++current; } - emitProgress( total, total, QString() ); + emitProgress( 1, QString() ); + emitFinished(); } private: QList< Calamares::job_ptr > m_jobs; 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, - Q_ARG( int, current ), - Q_ARG( int, total ), + Q_ARG( qreal, percent ), Q_ARG( QString, prettyName ) ); } @@ -86,6 +88,11 @@ private: Q_ARG( QString, details ) ); } + + void emitFinished() + { + QMetaObject::invokeMethod( m_queue, "finished", Qt::QueuedConnection ); + } }; diff --git a/src/libcalamares/JobQueue.h b/src/libcalamares/JobQueue.h index 505fa91e6..d39929ebb 100644 --- a/src/libcalamares/JobQueue.h +++ b/src/libcalamares/JobQueue.h @@ -46,7 +46,8 @@ public: void start(); 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 ); private: diff --git a/src/libcalamaresui/InstallationViewStep.cpp b/src/libcalamaresui/InstallationViewStep.cpp index 4b3035061..f1eecd483 100644 --- a/src/libcalamaresui/InstallationViewStep.cpp +++ b/src/libcalamaresui/InstallationViewStep.cpp @@ -32,6 +32,7 @@ InstallationViewStep::InstallationViewStep( QObject* parent ) , m_widget( new QWidget ) { m_progressBar = new QProgressBar; + m_progressBar->setMaximum( 10000 ); m_label = new QLabel; QVBoxLayout* layout = new QVBoxLayout( m_widget ); layout->addWidget(m_progressBar); @@ -88,10 +89,9 @@ InstallationViewStep::jobs() const } void -InstallationViewStep::updateFromJobQueue( int current, int total, const QString& message ) +InstallationViewStep::updateFromJobQueue( qreal percent, const QString& message ) { - m_progressBar->setMaximum( total ); - m_progressBar->setValue( current ); + m_progressBar->setValue( percent * m_progressBar->maximum() ); m_label->setText( message ); } diff --git a/src/libcalamaresui/InstallationViewStep.h b/src/libcalamaresui/InstallationViewStep.h index 6cfe52dec..122f6cfd7 100644 --- a/src/libcalamaresui/InstallationViewStep.h +++ b/src/libcalamaresui/InstallationViewStep.h @@ -51,7 +51,7 @@ private: QProgressBar* m_progressBar; QLabel* m_label; - void updateFromJobQueue( int current, int total, const QString& message ); + void updateFromJobQueue( qreal percent, const QString& message ); }; } diff --git a/src/modules/partition/tests/JobTests.cpp b/src/modules/partition/tests/JobTests.cpp index 4dee8566e..b4239001b 100644 --- a/src/modules/partition/tests/JobTests.cpp +++ b/src/modules/partition/tests/JobTests.cpp @@ -32,36 +32,32 @@ Partition* firstFreePartition( PartitionNode* parent ) QueueRunner::QueueRunner( JobQueue* 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 ); } bool QueueRunner::run() { - m_done = false; - m_success = false; + m_finished = false; + m_success = true; m_queue->start(); QEventLoop loop; - while ( !m_done ) + while ( !m_finished ) loop.processEvents(); return m_success; } void -QueueRunner::onProgress( int current, int total, const QString& prettyName ) +QueueRunner::onFinished() { - QVERIFY( current <= total ); - if ( current < total ) - return; - m_success = true; - m_done = true; + m_finished = true; } void QueueRunner::onFailed( const QString& message, const QString& details ) { - m_done = true; + m_success = false; QString msg = message + "\ndetails: " + details; QFAIL( qPrintable( msg ) ); } diff --git a/src/modules/partition/tests/JobTests.h b/src/modules/partition/tests/JobTests.h index 21ae63741..e4a35cb3f 100644 --- a/src/modules/partition/tests/JobTests.h +++ b/src/modules/partition/tests/JobTests.h @@ -25,10 +25,10 @@ public: bool run(); private: - void onProgress( int current, int total, const QString& prettyName ); void onFailed( const QString& message, const QString& details ); + void onFinished(); Calamares::JobQueue* m_queue; - bool m_done; + bool m_finished; bool m_success; };