The window accepts a drop and the desktop entry's %U hands over the file the user picked, so both gestures end up as the same request. The frame asks the core which files it can install and never names a format itself; dropped files queue up because the core runs one operation at a time, and the search and log fields stop swallowing drops so a file dropped on them reaches the window. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
114 lines
3.6 KiB
C++
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(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();
|
|
// 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("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);
|
|
|
|
// 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()
|
|
? QStringLiteral("Journal vide : rien n'a encore été enregistré.")
|
|
: QStringLiteral("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);
|
|
}
|