feat(ui): show the application journal in the Logs screen
The Logs screen only offered /var/log/pacman.log, which is unreadable without root and says nothing about what the app itself did. Let the user switch between that file and the new application journal, refresh it live while an operation runs, and record navigation and dialog events so the screen tells the whole story. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
3 files changed
+99
-7
No files matched your search
+30
-1
@@ -1,5 +1,6 @@
|
||||
#include "logs-page.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
@@ -7,6 +8,7 @@
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "log-manager.h"
|
||||
#include "ui-kit.h"
|
||||
|
||||
LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
@@ -17,6 +19,14 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
QHBoxLayout* filterRow = new QHBoxLayout();
|
||||
filterRow->setSpacing(10);
|
||||
|
||||
m_source = new QComboBox();
|
||||
m_source->addItem(QStringLiteral("Journal de l'application"));
|
||||
m_source->addItem(QStringLiteral("Journal pacman (/var/log/pacman.log)"));
|
||||
m_source->setMinimumHeight(36);
|
||||
m_source->setToolTip("Choisir la source du journal affiché");
|
||||
connect(m_source, &QComboBox::currentIndexChanged, this, [this](int) { load(); });
|
||||
filterRow->addWidget(m_source);
|
||||
|
||||
m_filter = new QLineEdit();
|
||||
m_filter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
||||
m_filter->setMinimumHeight(36);
|
||||
@@ -45,6 +55,17 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
buttonBar->addWidget(refreshButton);
|
||||
|
||||
layout->addLayout(buttonBar);
|
||||
|
||||
// The journal grows while the app runs: reload it whenever a new entry lands,
|
||||
// but only while this page is actually showing it (so an install does not
|
||||
// reload the text on a screen the user is not looking at).
|
||||
connect(&LogManager::instance(), &LogManager::fileUpdated, this, [this] {
|
||||
if (viewingAppLog() && isVisible()) load();
|
||||
});
|
||||
}
|
||||
|
||||
bool LogsPage::viewingAppLog() const {
|
||||
return m_source->currentIndex() == 0;
|
||||
}
|
||||
|
||||
void LogsPage::refresh() {
|
||||
@@ -53,11 +74,19 @@ void LogsPage::refresh() {
|
||||
|
||||
void LogsPage::load() {
|
||||
QString error;
|
||||
m_raw = core()->readPackageLog(&error);
|
||||
m_raw = viewingAppLog() ? LogManager::instance().readFile(&error)
|
||||
: core()->readPackageLog(&error);
|
||||
|
||||
if (!error.isEmpty()) {
|
||||
m_text->setPlainText(error);
|
||||
return;
|
||||
}
|
||||
if (m_raw.isEmpty()) {
|
||||
m_text->setPlainText(viewingAppLog()
|
||||
? QStringLiteral("Journal vide : rien n'a encore été enregistré.")
|
||||
: QStringLiteral("Journal pacman vide ou illisible."));
|
||||
return;
|
||||
}
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user