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.
208 lines
8.3 KiB
C++
208 lines
8.3 KiB
C++
#include "dashboard-page.h"
|
|
|
|
#include <QAbstractItemView>
|
|
#include <QFrame>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QListWidget>
|
|
#include <QListWidgetItem>
|
|
#include <QPushButton>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "ui-kit.h"
|
|
|
|
DashboardPage::DashboardPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
|
setObjectName("dashboardPage");
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(16);
|
|
|
|
// Stat cards
|
|
QHBoxLayout* statsRow = new QHBoxLayout();
|
|
statsRow->setSpacing(12);
|
|
statsRow->addWidget(
|
|
ui::statCard("package", tr("Paquets installés"), "blue", &m_statInstalled));
|
|
statsRow->addWidget(
|
|
ui::statCard("arrow-up", tr("Mises à jour dispo"), "amber", &m_statUpdates));
|
|
statsRow->addWidget(
|
|
ui::statCard("history", tr("Actions enregistrées"), "cyan", &m_statHistory));
|
|
statsRow->addWidget(
|
|
ui::statCard("tools", tr("Gestionnaire"), "green", &m_statManager));
|
|
layout->addLayout(statsRow);
|
|
|
|
// Quick actions
|
|
QFrame* actionsCard = ui::card();
|
|
QVBoxLayout* actionsLayout = new QVBoxLayout(actionsCard);
|
|
actionsLayout->setContentsMargins(18, 16, 18, 16);
|
|
actionsLayout->setSpacing(10);
|
|
|
|
QLabel* actionsTitle = new QLabel(tr("ACTIONS RAPIDES"));
|
|
actionsTitle->setObjectName("cardTitle");
|
|
actionsLayout->addWidget(actionsTitle);
|
|
|
|
QHBoxLayout* actionsRow = new QHBoxLayout();
|
|
actionsRow->setSpacing(10);
|
|
|
|
QPushButton* btnSearch = new QPushButton(tr("Rechercher un paquet"));
|
|
btnSearch->setProperty("variant", "primary");
|
|
btnSearch->setIcon(ui::icon("search"));
|
|
connect(btnSearch, &QPushButton::clicked, this,
|
|
[this] { emit goToPage("search"); });
|
|
actionsRow->addWidget(btnSearch);
|
|
|
|
QPushButton* btnInstalled = new QPushButton(tr("Paquets installés"));
|
|
btnInstalled->setIcon(ui::icon("package"));
|
|
connect(btnInstalled, &QPushButton::clicked, this,
|
|
[this] { emit goToPage("installed"); });
|
|
actionsRow->addWidget(btnInstalled);
|
|
|
|
QPushButton* btnUpdateAll = new QPushButton(tr("Tout mettre à jour"));
|
|
btnUpdateAll->setProperty("variant", "warning");
|
|
btnUpdateAll->setIcon(ui::icon("arrow-up"));
|
|
connect(btnUpdateAll, &QPushButton::clicked, this,
|
|
[this, core] { start(core->updateAll(), tr("Mise à jour globale")); });
|
|
actionsRow->addWidget(btnUpdateAll);
|
|
|
|
QPushButton* btnCleanup = new QPushButton(tr("Nettoyer le système"));
|
|
btnCleanup->setIcon(ui::icon("broom"));
|
|
btnCleanup->setToolTip(tr("Purger les paquets inutilisés et vider les caches"));
|
|
connect(btnCleanup, &QPushButton::clicked, this,
|
|
[this] { emit goToPage("cleanup"); });
|
|
actionsRow->addWidget(btnCleanup);
|
|
|
|
QPushButton* btnRefresh = new QPushButton(tr("Rafraîchir les sources"));
|
|
btnRefresh->setProperty("variant", "info");
|
|
btnRefresh->setIcon(ui::icon("refresh"));
|
|
connect(btnRefresh, &QPushButton::clicked, this,
|
|
[this, core] { start(core->refresh(), tr("Rafraîchissement des sources")); });
|
|
actionsRow->addWidget(btnRefresh);
|
|
|
|
QPushButton* btnLogs = new QPushButton(tr("Logs pacman"));
|
|
btnLogs->setIcon(ui::icon("logs"));
|
|
connect(btnLogs, &QPushButton::clicked, this, [this] { emit goToPage("logs"); });
|
|
actionsRow->addWidget(btnLogs);
|
|
|
|
actionsRow->addStretch();
|
|
actionsLayout->addLayout(actionsRow);
|
|
layout->addWidget(actionsCard);
|
|
|
|
// Recent activity
|
|
QFrame* recentCard = ui::card();
|
|
QVBoxLayout* recentLayout = new QVBoxLayout(recentCard);
|
|
recentLayout->setContentsMargins(18, 16, 18, 12);
|
|
recentLayout->setSpacing(8);
|
|
|
|
QLabel* recentTitle = new QLabel(tr("ACTIVITÉ RÉCENTE"));
|
|
recentTitle->setObjectName("cardTitle");
|
|
recentLayout->addWidget(recentTitle);
|
|
|
|
m_recentList = new QListWidget();
|
|
m_recentList->setObjectName("recentList");
|
|
m_recentList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
m_recentList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
m_recentList->setFocusPolicy(Qt::NoFocus);
|
|
connect(m_recentList, &QListWidget::itemClicked, this,
|
|
&DashboardPage::onActivityClicked);
|
|
recentLayout->addWidget(m_recentList, 1);
|
|
|
|
layout->addWidget(recentCard, 1);
|
|
|
|
// The figures and the activity list both come from the core.
|
|
connect(core, &AppCore::listFinished, this,
|
|
[this](AppCore::ListMode mode, std::vector<PackageInfo> results) {
|
|
if (mode == AppCore::ListMode::Installed) {
|
|
m_statInstalled->setText(QString::number(results.size()));
|
|
} else if (mode == AppCore::ListMode::Updates) {
|
|
m_statUpdates->setText(QString::number(results.size()));
|
|
m_statUpdates->setStyleSheet(results.empty()
|
|
? QString()
|
|
: QString("color: #fbbf24;"));
|
|
}
|
|
});
|
|
connect(core, &AppCore::historyChanged, this, &DashboardPage::refresh);
|
|
}
|
|
|
|
void DashboardPage::refresh() {
|
|
m_statHistory->setText(QString::number(core()->historyCount()));
|
|
m_statManager->setText(core()->hasAvailableProvider()
|
|
? core()->availableProviderNames().join(", ")
|
|
: QStringLiteral("indisponible"));
|
|
refreshRecentActivity();
|
|
|
|
// The listing itself arrives through listFinished: the search/installed
|
|
// pages share it, so nothing is queried twice.
|
|
if (core()->hasAvailableProvider()) {
|
|
start(core()->loadCounts(), tr("Tableau de bord"));
|
|
}
|
|
}
|
|
|
|
void DashboardPage::refreshRecentActivity() {
|
|
m_recentList->clear();
|
|
|
|
const auto& history = core()->history()->getHistory();
|
|
if (history.empty()) {
|
|
QListWidgetItem* empty =
|
|
new QListWidgetItem(tr("Aucune action enregistrée pour le moment"));
|
|
empty->setFlags(Qt::NoItemFlags);
|
|
empty->setTextAlignment(Qt::AlignCenter);
|
|
m_recentList->addItem(empty);
|
|
return;
|
|
}
|
|
|
|
int start = std::max(0, static_cast<int>(history.size()) - 8);
|
|
for (int i = static_cast<int>(history.size()) - 1; i >= start; --i) {
|
|
const HistoryEntry& entry = history[i];
|
|
|
|
QListWidgetItem* item = new QListWidgetItem();
|
|
item->setSizeHint(QSize(0, 42));
|
|
// Keep the package name so a click can open its details.
|
|
item->setData(Qt::UserRole, QString::fromStdString(entry.package));
|
|
|
|
QWidget* row = new QWidget();
|
|
QHBoxLayout* rowLayout = new QHBoxLayout(row);
|
|
rowLayout->setContentsMargins(10, 4, 10, 4);
|
|
rowLayout->setSpacing(10);
|
|
|
|
QLabel* timestamp = new QLabel(QString::fromStdString(entry.timestamp));
|
|
timestamp->setStyleSheet(
|
|
"background: transparent; color: #64748b;"
|
|
"font-family: monospace; font-size: 12px;");
|
|
rowLayout->addWidget(timestamp);
|
|
|
|
// Badge colours are the site's status colours, each one tinted onto the
|
|
// card background the badge sits on.
|
|
QString actionText, actionBg, actionFg;
|
|
if (entry.action == "install") {
|
|
actionText = tr("Installation"); actionBg = "#213d46"; actionFg = "#34d399";
|
|
} else if (entry.action == "remove") {
|
|
actionText = tr("Suppression"); actionBg = "#383241"; actionFg = "#f87171";
|
|
} else if (entry.action == "cleanup") {
|
|
actionText = tr("Nettoyage"); actionBg = "#213b52"; actionFg = "#7dd3fc";
|
|
} else {
|
|
actionText = tr("Mise à jour"); actionBg = "#393b38"; actionFg = "#fbbf24";
|
|
}
|
|
rowLayout->addWidget(ui::badge(actionText, actionBg, actionFg));
|
|
|
|
QLabel* package = new QLabel(QString::fromStdString(entry.package));
|
|
package->setStyleSheet("background: transparent; font-weight: 600; color: #e2e8f0;");
|
|
rowLayout->addWidget(package);
|
|
|
|
rowLayout->addStretch();
|
|
|
|
QLabel* status = new QLabel();
|
|
status->setPixmap(ui::iconPixmap(entry.success ? "check" : "close", 16));
|
|
status->setStyleSheet("background: transparent;");
|
|
rowLayout->addWidget(status);
|
|
|
|
m_recentList->addItem(item);
|
|
m_recentList->setItemWidget(item, row);
|
|
}
|
|
}
|
|
|
|
void DashboardPage::onActivityClicked(QListWidgetItem* item) {
|
|
if (!item) return;
|
|
const QString name = item->data(Qt::UserRole).toString();
|
|
if (name.isEmpty()) return;
|
|
emit openPackage(name);
|
|
}
|