Every label, tooltip, empty state and status message was a bare QStringLiteral, so nothing could be translated. They now go through tr() (QCoreApplication::translate from a free helper, QT_TRANSLATE_NOOP where the code already had it), which is what the catalogues are keyed on. The journal follows the same rule as the interface: an event, an error and the two outcomes of a command read in the chosen language. What the tools print themselves is left alone — that is their output, not our wording — and so are the qC* developer traces, which keep their technical English.
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(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);
|
|
}
|