diff --git a/pages/logs-page.cpp b/pages/logs-page.cpp index e7ce482..11c305d 100644 --- a/pages/logs-page.cpp +++ b/pages/logs-page.cpp @@ -1,5 +1,6 @@ #include "logs-page.h" +#include #include #include #include @@ -7,6 +8,7 @@ #include #include +#include "log-manager.h" #include "ui-kit.h" 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(); 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->setPlaceholderText("Filtrer les logs (paquet, action, date)..."); m_filter->setMinimumHeight(36); @@ -45,6 +55,17 @@ LogsPage::LogsPage(AppCore* core, QWidget* parent) : Page(core, parent) { 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() { @@ -53,11 +74,19 @@ void LogsPage::refresh() { void LogsPage::load() { QString error; - m_raw = core()->readPackageLog(&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(); } diff --git a/pages/logs-page.h b/pages/logs-page.h index 1f725bc..43911ce 100644 --- a/pages/logs-page.h +++ b/pages/logs-page.h @@ -4,20 +4,23 @@ #include "page.h" +class QComboBox; class QLineEdit; class QTextEdit; -// Logs pacman: the raw /var/log/pacman.log, filtered in memory so typing stays -// instant even with a multi-megabyte file (the core reads it, the page keeps a -// copy). +// Journal viewer. Two sources share the screen: the application's own journal — +// every operation and event, including the raw output of the commands that ran, +// 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 { Q_OBJECT public: 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 { - return QStringLiteral("Journal brut du gestionnaire de paquets"); + return QStringLiteral("Journal de l'application et journal pacman"); } void refresh() override; @@ -25,7 +28,10 @@ public: private: void load(); void applyFilter(); + // True when the selector points at the application's own journal. + bool viewingAppLog() const; + QComboBox* m_source = nullptr; QLineEdit* m_filter = nullptr; QTextEdit* m_text = nullptr; QString m_raw; diff --git a/src/main-window.cpp b/src/main-window.cpp index 15e4e70..e5139b3 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -28,6 +28,7 @@ #include #include "app-logging.h" +#include "log-manager.h" #include "browse-page.h" #include "cleanup-page.h" #include "dashboard-page.h" @@ -660,9 +661,13 @@ void MainWindow::setupMenuBar() { QMenu* fileMenu = menuBar->addMenu("Fichier"); fileMenu->addAction("Exporter la liste affichée...", this, [this] { + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("export de la liste affichée")); m_browse->exportCsv(); }); fileMenu->addAction("Exporter l'historique...", this, [this] { + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("export de l'historique")); m_history->exportCsv(); }); fileMenu->addSeparator(); @@ -770,7 +775,11 @@ void MainWindow::setupShortcuts() { bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() { 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(); }); } @@ -781,6 +790,23 @@ void MainWindow::setupShortcuts() { void MainWindow::onNavChanged(int 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) { case NavDashboard: m_pages->setCurrentWidget(m_dashboard); @@ -832,6 +858,9 @@ void MainWindow::onOpenPage(const QString& pageId) { void MainWindow::onOpenPackage(const QString& name) { if (name.isEmpty()) return; + LogManager::instance().logEvent( + QStringLiteral("ui"), + QStringLiteral("ouverture des détails de %1").arg(name)); m_browse->selectOnNextLoad(name); if (QAbstractButton* button = m_navGroup->button(NavInstalled)) button->click(); 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() { + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("clic rafraîchir les sources")); handleStartResult(m_core->refresh(), "Rafraîchissement des sources"); } void MainWindow::onUpdateAll() { + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("clic tout mettre à jour")); handleStartResult(m_core->updateAll(), "Mise à jour globale"); } @@ -868,6 +901,11 @@ void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) { // --------------------------------------------------------------------------- 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); // Per-session credentials: prompt once now so operations don't re-ask. The // core reports the mode change in the status bar itself. @@ -879,21 +917,34 @@ void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) { bool MainWindow::promptForSudoPassword() { if (m_core->hasSudoPassword()) return true; + LogManager::instance().logEvent( + QStringLiteral("ui"), + QStringLiteral("demande du mot de passe administrateur")); + bool ok = false; const QString password = QInputDialog::getText( this, "Authentification", "Mot de passe administrateur (sudo) :", QLineEdit::Password, QString(), &ok); if (!ok) { + LogManager::instance().logEvent( + QStringLiteral("ui"), + QStringLiteral("mot de passe refusé par l'utilisateur")); statusBar()->showMessage("Opération annulée : identifiants requis."); return false; } + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("mot de passe fourni")); m_core->setSudoPassword(password); return true; } 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 // gets its own dialog instead of a message the user has to act on by hand. if (locked) { @@ -930,6 +981,10 @@ void MainWindow::handleStartResult(const AppCore::StartResult& result, } 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 // unwinding: retry straight away rather than announcing a lock that is gone. if (!m_core->databaseLocked()) { @@ -1095,6 +1150,8 @@ void MainWindow::onCoreHistoryChanged() { } void MainWindow::onCheckForUpdates() { + LogManager::instance().logEvent(QStringLiteral("ui"), + QStringLiteral("clic vérifier les mises à jour")); m_core->checkForAppUpdate(); }