From d5e0fca4909b44042ae01bd1983efd9169752cf0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 14 Mar 2022 16:28:44 +0100 Subject: [PATCH 1/5] [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 From 1a3f41ff333adee40bda793fe55049724fbbe9d1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 15 Mar 2022 11:56:39 +0100 Subject: [PATCH 2/5] [libcalamaresui] Allow more options for icon --- src/libcalamaresui/viewpages/ExecutionViewStep.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp index b227971fb..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 ); From d998c9e24ba2a25be14fdd4845cbe0308d1ee49f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 15 Mar 2022 14:02:24 +0100 Subject: [PATCH 3/5] [libcalamaresui] Try to improve 'tailing' experience --- src/libcalamaresui/widgets/LogWidget.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/widgets/LogWidget.cpp b/src/libcalamaresui/widgets/LogWidget.cpp index 8e559be7d..7d81e0ca0 100644 --- a/src/libcalamaresui/widgets/LogWidget.cpp +++ b/src/libcalamaresui/widgets/LogWidget.cpp @@ -77,8 +77,14 @@ LogWidget::LogWidget( QWidget* parent ) void LogWidget::handleLogChunk( const QString& logChunk ) { + // Scroll to the end of the new chunk, only if we were at the end (tailing + // the log); scrolling up will break the tail-to-end behavior. + const bool isAtEnd = m_text->textCursor().atEnd(); m_text->appendPlainText( logChunk ); - m_text->moveCursor( QTextCursor::End ); + if ( isAtEnd ) + { + m_text->moveCursor( QTextCursor::End ); + } m_text->ensureCursorVisible(); } From 28bf8478c4542c14196e1784189d35731a8b85a3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 15 Mar 2022 14:39:59 +0100 Subject: [PATCH 4/5] [libcalamaresui] Simplify log-window Scrolling explicitly to the bottom isn't needed; leaving it up to appendPlainText() has the following behavior: - if the text is scrolled all the way down, follows the text and scrolls further down (tailing) - if it is not scrolled all the way down, keeps current position. --- src/libcalamaresui/widgets/LogWidget.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libcalamaresui/widgets/LogWidget.cpp b/src/libcalamaresui/widgets/LogWidget.cpp index 7d81e0ca0..d4d9a8e20 100644 --- a/src/libcalamaresui/widgets/LogWidget.cpp +++ b/src/libcalamaresui/widgets/LogWidget.cpp @@ -1,6 +1,8 @@ #include "LogWidget.h" #include "utils/Logger.h" + #include +#include #include #include #include @@ -61,6 +63,7 @@ LogWidget::LogWidget( QWidget* parent ) setLayout( layout ); m_text->setReadOnly( true ); + m_text->setVerticalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOn ); QFont monospaceFont( "monospace" ); monospaceFont.setStyleHint( QFont::Monospace ); @@ -77,15 +80,7 @@ LogWidget::LogWidget( QWidget* parent ) void LogWidget::handleLogChunk( const QString& logChunk ) { - // Scroll to the end of the new chunk, only if we were at the end (tailing - // the log); scrolling up will break the tail-to-end behavior. - const bool isAtEnd = m_text->textCursor().atEnd(); m_text->appendPlainText( logChunk ); - if ( isAtEnd ) - { - m_text->moveCursor( QTextCursor::End ); - } - m_text->ensureCursorVisible(); } void From f0d4788e6d04ab3225e0b281e680fabae7cdef5f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 15 Mar 2022 14:42:27 +0100 Subject: [PATCH 5/5] [libcalamaresui] SPDX-tagging for Bob --- src/libcalamaresui/widgets/LogWidget.cpp | 10 ++++++++++ src/libcalamaresui/widgets/LogWidget.h | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/libcalamaresui/widgets/LogWidget.cpp b/src/libcalamaresui/widgets/LogWidget.cpp index d4d9a8e20..fb5772023 100644 --- a/src/libcalamaresui/widgets/LogWidget.cpp +++ b/src/libcalamaresui/widgets/LogWidget.cpp @@ -1,4 +1,14 @@ +/* === 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 diff --git a/src/libcalamaresui/widgets/LogWidget.h b/src/libcalamaresui/widgets/LogWidget.h index 2abb07596..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