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();
|
||||
}
|
||||
|
||||
|
||||
+11
-5
@@ -4,20 +4,23 @@
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QTextEdit;
|
||||
|
||||
// Logs pacman: the raw /var/log/pacman.log, filtered in memory so typing stays
|
||||
// instant even with a multi-megabyte file (the core reads it, the page keeps a
|
||||
// copy).
|
||||
// Journal viewer. Two sources share the screen: the application's own journal —
|
||||
// every operation and event, including the raw output of the commands that ran,
|
||||
// so it reads like a hand-run terminal session — and the raw /var/log/pacman.log.
|
||||
// Both are filtered in memory so typing stays instant even with a multi-megabyte
|
||||
// file (the core/journal reads it, the page keeps a copy).
|
||||
class LogsPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogsPage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override { return QStringLiteral("Logs pacman"); }
|
||||
QString navTitle() const override { return QStringLiteral("Logs"); }
|
||||
QString navSubtitle() const override {
|
||||
return QStringLiteral("Journal brut du gestionnaire de paquets");
|
||||
return QStringLiteral("Journal de l'application et journal pacman");
|
||||
}
|
||||
|
||||
void refresh() override;
|
||||
@@ -25,7 +28,10 @@ public:
|
||||
private:
|
||||
void load();
|
||||
void applyFilter();
|
||||
// True when the selector points at the application's own journal.
|
||||
bool viewingAppLog() const;
|
||||
|
||||
QComboBox* m_source = nullptr;
|
||||
QLineEdit* m_filter = nullptr;
|
||||
QTextEdit* m_text = nullptr;
|
||||
QString m_raw;
|
||||
|
||||
Reference in new issue
Block a user