Files
FWS-PacManage/pages/system/logs-page.cpp
BlackAngelTV 3e85db87b2 refactor(pages): group the screens by what the user is doing
pages/ was a flat row of eight screens, so a change to one meant scanning
the whole folder to see what else was in it. The screens now sit in
packages/ (browse, cleanup), overview/ (dashboard, history), system/
(logs, settings) and extensions/ (plugins), with the scaffolding they
all build on — the Page base and the shared widgets — in base/.
2026-09-29 21:26:51 +02:00

114 lines
3.6 KiB
C++

#include "logs-page.h"
#include <QComboBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QTextCursor>
#include <QTextEdit>
#include <QVBoxLayout>
#include "log-manager.h"
#include "ui-kit.h"
LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(24, 20, 24, 20);
layout->setSpacing(12);
QHBoxLayout* filterRow = new QHBoxLayout();
filterRow->setSpacing(10);
m_source = new QComboBox();
m_source->addItem(tr("Journal de l'application"));
m_source->addItem(tr("Journal pacman (/var/log/pacman.log)"));
m_source->setMinimumHeight(36);
m_source->setToolTip(tr("Choisir la source du journal affiché"));
connect(m_source, &QComboBox::currentIndexChanged, this, [this](int) { load(); });
filterRow->addWidget(m_source);
m_filter = new QLineEdit();
// Drops go to the window, which installs Flatpak files (see
// MainWindow::dragEnterEvent) rather than pasting a path here.
m_filter->setAcceptDrops(false);
m_filter->setPlaceholderText(tr("Filtrer les logs (paquet, action, date)..."));
m_filter->setMinimumHeight(36);
m_filter->setClearButtonEnabled(true);
m_filter->addAction(ui::icon("filter"), QLineEdit::LeadingPosition);
connect(m_filter, &QLineEdit::textChanged, this, [this](const QString&) {
applyFilter();
});
filterRow->addWidget(m_filter, 1);
layout->addLayout(filterRow);
m_text = new QTextEdit();
m_text->setReadOnly(true);
layout->addWidget(m_text, 1);
QHBoxLayout* buttonBar = new QHBoxLayout();
buttonBar->addStretch();
QPushButton* refreshButton = new QPushButton(tr("Recharger"));
refreshButton->setIcon(ui::icon("refresh"));
connect(refreshButton, &QPushButton::clicked, this, [this] {
load();
emit message(tr("Logs rechargés"));
});
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() {
load();
}
void LogsPage::load() {
QString 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()
? tr("Journal vide : rien n'a encore été enregistré.")
: tr("Journal pacman vide ou illisible."));
return;
}
applyFilter();
}
// Renders the raw log, keeping only the lines matching the filter box.
void LogsPage::applyFilter() {
const QString needle = m_filter->text().trimmed();
if (needle.isEmpty()) {
m_text->setPlainText(m_raw);
} else {
QString filtered;
const QStringList lines = m_raw.split(QLatin1Char('\n'));
for (const QString& line : lines) {
if (line.contains(needle, Qt::CaseInsensitive)) {
filtered += line;
filtered += QLatin1Char('\n');
}
}
m_text->setPlainText(filtered);
}
m_text->moveCursor(QTextCursor::End);
}