diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp index 4cf9a06a0..998d9f38b 100644 --- a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp @@ -94,7 +94,12 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent ) bottomLayout->addWidget( m_label ); QToolBar* toolBar = new QToolBar; - auto toggleLogAction = toolBar->addAction( QIcon::fromTheme( "utilities-terminal" ), "Toggle log" ); + const auto logButtonIcon = QIcon::fromTheme( "utilities-terminal" ); + auto toggleLogAction = toolBar->addAction( + Branding::instance()->image( + { "utilities-log-viewer", "utilities-terminal", "text-x-log", "text-x-changelog", "preferences-log" }, + QSize( 32, 32 ) ), + "Toggle log" ); auto toggleLogButton = dynamic_cast< QToolButton* >( toolBar->widgetForAction( toggleLogAction ) ); connect( toggleLogButton, &QToolButton::clicked, this, &ExecutionViewStep::toggleLog ); @@ -228,12 +233,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..fb5772023 100644 --- a/src/libcalamaresui/widgets/LogWidget.cpp +++ b/src/libcalamaresui/widgets/LogWidget.cpp @@ -1,6 +1,18 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2022 Bob van der Linden + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + #include "LogWidget.h" + #include "utils/Logger.h" + #include +#include #include #include #include @@ -61,6 +73,7 @@ LogWidget::LogWidget( QWidget* parent ) setLayout( layout ); m_text->setReadOnly( true ); + m_text->setVerticalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOn ); QFont monospaceFont( "monospace" ); monospaceFont.setStyleHint( QFont::Monospace ); @@ -70,6 +83,7 @@ LogWidget::LogWidget( QWidget* parent ) connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk ); + m_log_thread.setPriority( QThread::LowestPriority ); m_log_thread.start(); } @@ -77,8 +91,23 @@ void LogWidget::handleLogChunk( const QString& logChunk ) { m_text->appendPlainText( logChunk ); - m_text->moveCursor( QTextCursor::End ); - 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..5b3ef17a9 100644 --- a/src/libcalamaresui/widgets/LogWidget.h +++ b/src/libcalamaresui/widgets/LogWidget.h @@ -1,3 +1,12 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2022 Bob van der Linden + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + #ifndef LIBCALAMARESUI_LOGWIDGET_H #define LIBCALAMARESUI_LOGWIDGET_H @@ -18,7 +27,7 @@ public: explicit LogThread( QObject* parent = nullptr ); ~LogThread() override; -signals: +Q_SIGNALS: void onLogChunk( const QString& logChunk ); }; @@ -32,7 +41,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