From d5e0fca4909b44042ae01bd1983efd9169752cf0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 14 Mar 2022 16:28:44 +0100 Subject: [PATCH] [libcalamaresui] Allow starting and stopping the log-follower. --- .../viewpages/ExecutionViewStep.cpp | 12 +++++++++++- src/libcalamaresui/widgets/LogWidget.cpp | 18 ++++++++++++++++++ src/libcalamaresui/widgets/LogWidget.h | 9 ++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp index 4cf9a06a0..b227971fb 100644 --- a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp @@ -228,12 +228,22 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message ) void 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 ExecutionViewStep::onLeave() { + m_log_widget->stop(); m_slideshow->changeSlideShowState( Slideshow::Stop ); } diff --git a/src/libcalamaresui/widgets/LogWidget.cpp b/src/libcalamaresui/widgets/LogWidget.cpp index 7a253b78c..8e559be7d 100644 --- a/src/libcalamaresui/widgets/LogWidget.cpp +++ b/src/libcalamaresui/widgets/LogWidget.cpp @@ -70,6 +70,7 @@ LogWidget::LogWidget( QWidget* parent ) connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk ); + m_log_thread.setPriority( QThread::LowestPriority ); m_log_thread.start(); } @@ -81,4 +82,21 @@ LogWidget::handleLogChunk( const QString& logChunk ) 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 diff --git a/src/libcalamaresui/widgets/LogWidget.h b/src/libcalamaresui/widgets/LogWidget.h index 2d0ef9ab5..2abb07596 100644 --- a/src/libcalamaresui/widgets/LogWidget.h +++ b/src/libcalamaresui/widgets/LogWidget.h @@ -18,7 +18,7 @@ public: explicit LogThread( QObject* parent = nullptr ); ~LogThread() override; -signals: +Q_SIGNALS: void onLogChunk( const QString& logChunk ); }; @@ -32,7 +32,14 @@ class LogWidget : public QWidget public: explicit LogWidget( QWidget* parent = nullptr ); +public Q_SLOTS: + /// @brief Called by the thread when there is new data void handleLogChunk( const QString& logChunk ); + + /// @brief Stop watching for log data + void stop(); + /// @brief Start watching for new log data + void start(); }; } // namespace Calamares