All the business logic now lives in AppCore (providers, workers, history, plugins, sudo and pacman-lock handling), freed from any widget so it runs headless and is testable on its own. The Qt window becomes a thin frame around one file per screen under pages/, wired through a common Page contract and a shared ui-kit. CMake gains the app-core-test target, which links Qt Core only to enforce the headless guarantee. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
#include "logs-page.h"
|
|
|
|
#include <QHBoxLayout>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QTextCursor>
|
|
#include <QTextEdit>
|
|
#include <QVBoxLayout>
|
|
|
|
#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_filter = new QLineEdit();
|
|
m_filter->setPlaceholderText("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("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);
|
|
}
|
|
|
|
void LogsPage::refresh() {
|
|
load();
|
|
}
|
|
|
|
void LogsPage::load() {
|
|
QString error;
|
|
m_raw = core()->readPackageLog(&error);
|
|
if (!error.isEmpty()) {
|
|
m_text->setPlainText(error);
|
|
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);
|
|
}
|