[libcalamaresui] Report progress also while waiting

- Ping the progress every 1.2 seconds, so the user sees more than
   just the throbber.
This commit is contained in:
Adriaan de Groot 2019-02-25 06:33:46 -05:00
parent 452b51304d
commit 5ddf7b980b
2 changed files with 29 additions and 1 deletions

View File

@ -65,6 +65,7 @@ check( Module * const &m, RequirementsChecker *c )
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
: QObject( parent )
, m_modules( std::move( modules ) )
, m_progressTimer( nullptr )
{
m_watchers.reserve( m_modules.count() );
m_collectedRequirements.reserve( m_modules.count() );
@ -79,6 +80,10 @@ RequirementsChecker::~RequirementsChecker()
void
RequirementsChecker::run()
{
m_progressTimer = new QTimer( this );
connect( m_progressTimer, &QTimer::timeout, this, &RequirementsChecker::reportProgress );
m_progressTimer->start( 1200 ); // msec
for (const auto& module : m_modules )
{
Watcher *watcher = new Watcher( this );
@ -95,6 +100,9 @@ RequirementsChecker::finished()
{
cDebug() << "All requirements have been checked.";
if ( m_progressTimer )
m_progressTimer->stop();
bool acceptable = true;
int count = 0;
for ( const auto& r : m_collectedRequirements )
@ -124,4 +132,14 @@ RequirementsChecker::addCheckedRequirements( RequirementsList l )
emit requirementsResult( l );
}
void
RequirementsChecker::reportProgress()
{
auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher *w ) { return w && !w->isFinished(); } );
if ( remaining > 0 )
emit requirementsProgress( tr( "Waiting for %n module(s).", "", remaining ) );
else
emit requirementsProgress( tr( "System-requirements checking is complete." ) );
}
}

View File

@ -18,11 +18,13 @@
#ifndef CALAMARES_REQUIREMENTSCHECKER_H
#define CALAMARES_REQUIREMENTSCHECKER_H
#include "Requirement.h"
#include <QFutureWatcher>
#include <QObject>
#include <QTimer>
#include <QVector>
#include "Requirement.h"
namespace Calamares
{
@ -43,12 +45,18 @@ public:
virtual ~RequirementsChecker() override;
public slots:
/// @brief Start checking all the requirements
void run();
/// @brief Called when requirements are reported by a module
void addCheckedRequirements( RequirementsList );
/// @brief Called when all requirements have been checked
void finished();
/// @brief Called periodically while requirements are being checked
void reportProgress();
signals:
/// @brief Human-readable progress message
void requirementsProgress( const QString& );
@ -69,6 +77,8 @@ private:
QVector< Watcher* > m_watchers;
RequirementsList m_collectedRequirements;
QTimer *m_progressTimer;
} ;
}