[libcalamaresui] Allow starting and stopping the log-follower.

This commit is contained in:
Adriaan de Groot 2022-03-14 16:28:44 +01:00
parent 87c8c3e6ee
commit d5e0fca490
3 changed files with 37 additions and 2 deletions

View File

@ -228,12 +228,22 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
void void
ExecutionViewStep::toggleLog() ExecutionViewStep::toggleLog()
{ {
m_tab_widget->setCurrentIndex( ( m_tab_widget->currentIndex() + 1 ) % m_tab_widget->count() ); const bool logBecomesVisible = m_tab_widget->currentIndex() == 0; // ie. is not visible right now
if ( logBecomesVisible )
{
m_log_widget->start();
}
else
{
m_log_widget->stop();
}
m_tab_widget->setCurrentIndex( logBecomesVisible ? 1 : 0 );
} }
void void
ExecutionViewStep::onLeave() ExecutionViewStep::onLeave()
{ {
m_log_widget->stop();
m_slideshow->changeSlideShowState( Slideshow::Stop ); m_slideshow->changeSlideShowState( Slideshow::Stop );
} }

View File

@ -70,6 +70,7 @@ LogWidget::LogWidget( QWidget* parent )
connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk ); connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk );
m_log_thread.setPriority( QThread::LowestPriority );
m_log_thread.start(); m_log_thread.start();
} }
@ -81,4 +82,21 @@ LogWidget::handleLogChunk( const QString& logChunk )
m_text->ensureCursorVisible(); m_text->ensureCursorVisible();
} }
void
LogWidget::start()
{
if ( !m_log_thread.isRunning() )
{
m_text->clear();
m_log_thread.start();
}
}
void
LogWidget::stop()
{
m_log_thread.requestInterruption();
}
} // namespace Calamares } // namespace Calamares

View File

@ -18,7 +18,7 @@ public:
explicit LogThread( QObject* parent = nullptr ); explicit LogThread( QObject* parent = nullptr );
~LogThread() override; ~LogThread() override;
signals: Q_SIGNALS:
void onLogChunk( const QString& logChunk ); void onLogChunk( const QString& logChunk );
}; };
@ -32,7 +32,14 @@ class LogWidget : public QWidget
public: public:
explicit LogWidget( QWidget* parent = nullptr ); explicit LogWidget( QWidget* parent = nullptr );
public Q_SLOTS:
/// @brief Called by the thread when there is new data
void handleLogChunk( const QString& logChunk ); void handleLogChunk( const QString& logChunk );
/// @brief Stop watching for log data
void stop();
/// @brief Start watching for new log data
void start();
}; };
} // namespace Calamares } // namespace Calamares