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 "logs-page.h"
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -7,6 +8,7 @@
|
|||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include "log-manager.h"
|
||||||
#include "ui-kit.h"
|
#include "ui-kit.h"
|
||||||
|
|
||||||
LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
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();
|
QHBoxLayout* filterRow = new QHBoxLayout();
|
||||||
filterRow->setSpacing(10);
|
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 = new QLineEdit();
|
||||||
m_filter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
m_filter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
||||||
m_filter->setMinimumHeight(36);
|
m_filter->setMinimumHeight(36);
|
||||||
@@ -45,6 +55,17 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
|||||||
buttonBar->addWidget(refreshButton);
|
buttonBar->addWidget(refreshButton);
|
||||||
|
|
||||||
layout->addLayout(buttonBar);
|
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() {
|
void LogsPage::refresh() {
|
||||||
@@ -53,11 +74,19 @@ void LogsPage::refresh() {
|
|||||||
|
|
||||||
void LogsPage::load() {
|
void LogsPage::load() {
|
||||||
QString error;
|
QString error;
|
||||||
m_raw = core()->readPackageLog(&error);
|
m_raw = viewingAppLog() ? LogManager::instance().readFile(&error)
|
||||||
|
: core()->readPackageLog(&error);
|
||||||
|
|
||||||
if (!error.isEmpty()) {
|
if (!error.isEmpty()) {
|
||||||
m_text->setPlainText(error);
|
m_text->setPlainText(error);
|
||||||
return;
|
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();
|
applyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -4,20 +4,23 @@
|
|||||||
|
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
|
|
||||||
|
class QComboBox;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
|
|
||||||
// Logs pacman: the raw /var/log/pacman.log, filtered in memory so typing stays
|
// Journal viewer. Two sources share the screen: the application's own journal —
|
||||||
// instant even with a multi-megabyte file (the core reads it, the page keeps a
|
// every operation and event, including the raw output of the commands that ran,
|
||||||
// copy).
|
// 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 {
|
class LogsPage : public Page {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LogsPage(AppCore* core, QWidget* parent = nullptr);
|
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 {
|
QString navSubtitle() const override {
|
||||||
return QStringLiteral("Journal brut du gestionnaire de paquets");
|
return QStringLiteral("Journal de l'application et journal pacman");
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh() override;
|
void refresh() override;
|
||||||
@@ -25,7 +28,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
void load();
|
void load();
|
||||||
void applyFilter();
|
void applyFilter();
|
||||||
|
// True when the selector points at the application's own journal.
|
||||||
|
bool viewingAppLog() const;
|
||||||
|
|
||||||
|
QComboBox* m_source = nullptr;
|
||||||
QLineEdit* m_filter = nullptr;
|
QLineEdit* m_filter = nullptr;
|
||||||
QTextEdit* m_text = nullptr;
|
QTextEdit* m_text = nullptr;
|
||||||
QString m_raw;
|
QString m_raw;
|
||||||
|
|||||||
+58
-1
@@ -28,6 +28,7 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "app-logging.h"
|
#include "app-logging.h"
|
||||||
|
#include "log-manager.h"
|
||||||
#include "browse-page.h"
|
#include "browse-page.h"
|
||||||
#include "cleanup-page.h"
|
#include "cleanup-page.h"
|
||||||
#include "dashboard-page.h"
|
#include "dashboard-page.h"
|
||||||
@@ -660,9 +661,13 @@ void MainWindow::setupMenuBar() {
|
|||||||
|
|
||||||
QMenu* fileMenu = menuBar->addMenu("Fichier");
|
QMenu* fileMenu = menuBar->addMenu("Fichier");
|
||||||
fileMenu->addAction("Exporter la liste affichée...", this, [this] {
|
fileMenu->addAction("Exporter la liste affichée...", this, [this] {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("export de la liste affichée"));
|
||||||
m_browse->exportCsv();
|
m_browse->exportCsv();
|
||||||
});
|
});
|
||||||
fileMenu->addAction("Exporter l'historique...", this, [this] {
|
fileMenu->addAction("Exporter l'historique...", this, [this] {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("export de l'historique"));
|
||||||
m_history->exportCsv();
|
m_history->exportCsv();
|
||||||
});
|
});
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
@@ -770,7 +775,11 @@ void MainWindow::setupShortcuts() {
|
|||||||
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
||||||
m_navGroup->button(NavUpdates)->click();
|
m_navGroup->button(NavUpdates)->click();
|
||||||
});
|
});
|
||||||
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() { m_browse->exportCsv(); });
|
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("export de la liste affichée"));
|
||||||
|
m_browse->exportCsv();
|
||||||
|
});
|
||||||
bind(QKeySequence::Quit, [this]() { close(); });
|
bind(QKeySequence::Quit, [this]() { close(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,6 +790,23 @@ void MainWindow::setupShortcuts() {
|
|||||||
void MainWindow::onNavChanged(int id) {
|
void MainWindow::onNavChanged(int id) {
|
||||||
qCDebug(pacmgrUi) << "navigate to page" << id;
|
qCDebug(pacmgrUi) << "navigate to page" << id;
|
||||||
|
|
||||||
|
QString pageName;
|
||||||
|
switch (id) {
|
||||||
|
case NavDashboard: pageName = QStringLiteral("tableau de bord"); break;
|
||||||
|
case NavSearch: pageName = QStringLiteral("recherche"); break;
|
||||||
|
case NavInstalled: pageName = QStringLiteral("installés"); break;
|
||||||
|
case NavUpdates: pageName = QStringLiteral("mises à jour"); break;
|
||||||
|
case NavCleanup: pageName = QStringLiteral("nettoyage"); break;
|
||||||
|
case NavHistory: pageName = QStringLiteral("historique"); break;
|
||||||
|
case NavLogs: pageName = QStringLiteral("logs"); break;
|
||||||
|
case NavPlugins: pageName = QStringLiteral("plugins"); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("ui"),
|
||||||
|
pageName.isEmpty() ? QStringLiteral("navigation → page %1").arg(id)
|
||||||
|
: QStringLiteral("navigation → %1").arg(pageName));
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case NavDashboard:
|
case NavDashboard:
|
||||||
m_pages->setCurrentWidget(m_dashboard);
|
m_pages->setCurrentWidget(m_dashboard);
|
||||||
@@ -832,6 +858,9 @@ void MainWindow::onOpenPage(const QString& pageId) {
|
|||||||
void MainWindow::onOpenPackage(const QString& name) {
|
void MainWindow::onOpenPackage(const QString& name) {
|
||||||
if (name.isEmpty()) return;
|
if (name.isEmpty()) return;
|
||||||
|
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("ui"),
|
||||||
|
QStringLiteral("ouverture des détails de %1").arg(name));
|
||||||
m_browse->selectOnNextLoad(name);
|
m_browse->selectOnNextLoad(name);
|
||||||
if (QAbstractButton* button = m_navGroup->button(NavInstalled)) button->click();
|
if (QAbstractButton* button = m_navGroup->button(NavInstalled)) button->click();
|
||||||
statusBar()->showMessage(QString("Ouverture des détails de %1...").arg(name));
|
statusBar()->showMessage(QString("Ouverture des détails de %1...").arg(name));
|
||||||
@@ -846,10 +875,14 @@ void MainWindow::onStartRequested(const AppCore::StartResult& result, const QStr
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onRefresh() {
|
void MainWindow::onRefresh() {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("clic rafraîchir les sources"));
|
||||||
handleStartResult(m_core->refresh(), "Rafraîchissement des sources");
|
handleStartResult(m_core->refresh(), "Rafraîchissement des sources");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onUpdateAll() {
|
void MainWindow::onUpdateAll() {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("clic tout mettre à jour"));
|
||||||
handleStartResult(m_core->updateAll(), "Mise à jour globale");
|
handleStartResult(m_core->updateAll(), "Mise à jour globale");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,6 +901,11 @@ void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("ui"),
|
||||||
|
QStringLiteral("mode d'identifiants → %1")
|
||||||
|
.arg(mode == AppCore::CredentialMode::AtLaunch ? QStringLiteral("au lancement")
|
||||||
|
: QStringLiteral("à chaque fois")));
|
||||||
m_core->setCredentialMode(mode);
|
m_core->setCredentialMode(mode);
|
||||||
// Per-session credentials: prompt once now so operations don't re-ask. The
|
// Per-session credentials: prompt once now so operations don't re-ask. The
|
||||||
// core reports the mode change in the status bar itself.
|
// core reports the mode change in the status bar itself.
|
||||||
@@ -879,21 +917,34 @@ void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
|
|||||||
bool MainWindow::promptForSudoPassword() {
|
bool MainWindow::promptForSudoPassword() {
|
||||||
if (m_core->hasSudoPassword()) return true;
|
if (m_core->hasSudoPassword()) return true;
|
||||||
|
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("ui"),
|
||||||
|
QStringLiteral("demande du mot de passe administrateur"));
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const QString password = QInputDialog::getText(
|
const QString password = QInputDialog::getText(
|
||||||
this, "Authentification",
|
this, "Authentification",
|
||||||
"Mot de passe administrateur (sudo) :",
|
"Mot de passe administrateur (sudo) :",
|
||||||
QLineEdit::Password, QString(), &ok);
|
QLineEdit::Password, QString(), &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("ui"),
|
||||||
|
QStringLiteral("mot de passe refusé par l'utilisateur"));
|
||||||
statusBar()->showMessage("Opération annulée : identifiants requis.");
|
statusBar()->showMessage("Opération annulée : identifiants requis.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("mot de passe fourni"));
|
||||||
m_core->setSudoPassword(password);
|
m_core->setSudoPassword(password);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showActionError(const QString& title, const QString& error, bool locked) {
|
void MainWindow::showActionError(const QString& title, const QString& error, bool locked) {
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("erreur"),
|
||||||
|
QStringLiteral("%1 : %2").arg(title, error.isEmpty() ? QStringLiteral("sans détail") : error));
|
||||||
|
|
||||||
// A locked database is the one failure the app can resolve on its own, so it
|
// A locked database is the one failure the app can resolve on its own, so it
|
||||||
// gets its own dialog instead of a message the user has to act on by hand.
|
// gets its own dialog instead of a message the user has to act on by hand.
|
||||||
if (locked) {
|
if (locked) {
|
||||||
@@ -930,6 +981,10 @@ void MainWindow::handleStartResult(const AppCore::StartResult& result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::handleDatabaseLock(const QString& title) {
|
void MainWindow::handleDatabaseLock(const QString& title) {
|
||||||
|
LogManager::instance().logEvent(
|
||||||
|
QStringLiteral("verrou"),
|
||||||
|
QStringLiteral("%1 : %2").arg(title, m_core->databaseLockDescription()));
|
||||||
|
|
||||||
// The other manager frequently finishes while the failed operation was
|
// The other manager frequently finishes while the failed operation was
|
||||||
// unwinding: retry straight away rather than announcing a lock that is gone.
|
// unwinding: retry straight away rather than announcing a lock that is gone.
|
||||||
if (!m_core->databaseLocked()) {
|
if (!m_core->databaseLocked()) {
|
||||||
@@ -1095,6 +1150,8 @@ void MainWindow::onCoreHistoryChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCheckForUpdates() {
|
void MainWindow::onCheckForUpdates() {
|
||||||
|
LogManager::instance().logEvent(QStringLiteral("ui"),
|
||||||
|
QStringLiteral("clic vérifier les mises à jour"));
|
||||||
m_core->checkForAppUpdate();
|
m_core->checkForAppUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user