[libcalamaresui] Tell the manager explicitly when loading is done

- Add some extra checks for validity of m_currentStep (an index)
- Start off with explicitly invalid index, and keep it so until
  loading is complete; this prevents the situation where quit-at-end
  gets triggered after loading the very first module.
main
Adriaan de Groot 5 years ago
parent c2fac3a717
commit 7393198f7b

@ -339,14 +339,8 @@ CalamaresApplication::initViewSteps()
} }
cDebug() << "STARTUP: Window now visible and ProgressTreeView populated"; cDebug() << "STARTUP: Window now visible and ProgressTreeView populated";
cDebug() << Logger::SubEntry << Calamares::ViewManager::instance()->viewSteps().count() << "view steps loaded.";
const auto& steps = Calamares::ViewManager::instance()->viewSteps(); Calamares::ViewManager::instance()->onInitComplete();
cDebug() << Logger::SubEntry << steps.count() << "view steps loaded.";
// Tell the first view that it's been shown.
if ( steps.count() > 0 )
{
steps.first()->onActivate();
}
} }
void void

@ -65,7 +65,7 @@ ViewManager::instance( QObject* parent )
ViewManager::ViewManager( QObject* parent ) ViewManager::ViewManager( QObject* parent )
: QAbstractListModel( parent ) : QAbstractListModel( parent )
, m_currentStep( 0 ) , m_currentStep( -1 )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
{ {
Q_ASSERT( !s_instance ); Q_ASSERT( !s_instance );
@ -122,7 +122,7 @@ ViewManager::insertViewStep( int before, ViewStep* step )
// TODO: this can be a regular slot // TODO: this can be a regular slot
connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) { connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) {
ViewStep* vs = qobject_cast< ViewStep* >( sender() ); ViewStep* vs = qobject_cast< ViewStep* >( sender() );
if ( vs ) if ( vs && currentStepValid() )
{ {
if ( vs == m_steps.at( m_currentStep ) ) if ( vs == m_steps.at( m_currentStep ) )
{ {
@ -238,6 +238,18 @@ ViewManager::onInitFailed( const QStringList& modules )
insertViewStep( 0, new BlankViewStep( title, description.arg( *Calamares::Branding::ProductName ), detailString ) ); insertViewStep( 0, new BlankViewStep( title, description.arg( *Calamares::Branding::ProductName ), detailString ) );
} }
void
ViewManager::onInitComplete()
{
m_currentStep = 0;
// Tell the first view that it's been shown.
if ( m_steps.count() > 0 )
{
m_steps.first()->onActivate();
}
}
ViewStepList ViewStepList
ViewManager::viewSteps() const ViewManager::viewSteps() const
{ {
@ -248,7 +260,7 @@ ViewManager::viewSteps() const
ViewStep* ViewStep*
ViewManager::currentStep() const ViewManager::currentStep() const
{ {
return m_steps.value( m_currentStep ); return currentStepValid() ? m_steps.value( m_currentStep ) : nullptr;
} }
@ -279,12 +291,22 @@ isAtVeryEnd( const ViewStepList& steps, int index )
{ {
return false; return false;
} }
// .. and if the index is invalid, ignore it too
if ( !( ( 0 <= index ) && ( index < steps.count() ) ) )
{
return false;
}
return ( index >= steps.count() ) || ( index == steps.count() - 1 && steps.last()->isAtEnd() ); return ( index >= steps.count() ) || ( index == steps.count() - 1 && steps.last()->isAtEnd() );
} }
void void
ViewManager::next() ViewManager::next()
{ {
if ( !currentStepValid() )
{
return;
}
ViewStep* step = m_steps.at( m_currentStep ); ViewStep* step = m_steps.at( m_currentStep );
bool executing = false; bool executing = false;
if ( step->isAtEnd() ) if ( step->isAtEnd() )
@ -416,6 +438,11 @@ ViewManager::updateButtonLabels()
void void
ViewManager::back() ViewManager::back()
{ {
if ( !currentStepValid() )
{
return;
}
ViewStep* step = m_steps.at( m_currentStep ); ViewStep* step = m_steps.at( m_currentStep );
if ( step->isAtBeginning() && m_currentStep > 0 ) if ( step->isAtBeginning() && m_currentStep > 0 )
{ {

@ -184,6 +184,12 @@ public Q_SLOTS:
*/ */
void onInitFailed( const QStringList& modules ); void onInitFailed( const QStringList& modules );
/** @brief Tell the manager that initialization / loading is complete.
*
* Call this at least once, to tell the manager to activate the first page.
*/
void onInitComplete();
signals: signals:
void currentStepChanged(); void currentStepChanged();
void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() void enlarge( QSize enlarge ) const; // See ViewStep::enlarge()
@ -211,6 +217,8 @@ private:
void updateButtonLabels(); void updateButtonLabels();
void updateCancelEnabled( bool enabled ); void updateCancelEnabled( bool enabled );
inline bool currentStepValid() const { return ( 0 <= m_currentStep ) && ( m_currentStep < m_steps.length() ); }
static ViewManager* s_instance; static ViewManager* s_instance;
ViewStepList m_steps; ViewStepList m_steps;

Loading…
Cancel
Save