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:
Aurélien Gâteau 2014-07-23 10:58:08 +02:00
parent 2636a1273f
commit e9da5cb6cb
6 changed files with 28 additions and 24 deletions

View File

@ -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 );
}
};

View File

@ -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:

View File

@ -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 );
}

View File

@ -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 );
};
}

View File

@ -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 ) );
}

View File

@ -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;
};