refactor(pages): group the screens by what the user is doing
pages/ was a flat row of eight screens, so a change to one meant scanning the whole folder to see what else was in it. The screens now sit in packages/ (browse, cleanup), overview/ (dashboard, history), system/ (logs, settings) and extensions/ (plugins), with the scaffolding they all build on — the Page base and the shared widgets — in base/.
This commit is contained in:
19 files changed
+19
-19
No files matched your search
@@ -0,0 +1,207 @@
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QLabel;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
|
||||
// Tableau de bord: the four figures of the system, the shortcuts to the pages
|
||||
// used most often, and the last recorded actions.
|
||||
class DashboardPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DashboardPage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override { return QStringLiteral("Tableau de bord"); }
|
||||
QString navSubtitle() const override {
|
||||
return QStringLiteral("Vue d'ensemble de votre système");
|
||||
}
|
||||
|
||||
void refresh() override;
|
||||
|
||||
signals:
|
||||
// A click on a recent action opens that package on the Installed screen.
|
||||
void openPackage(const QString& name);
|
||||
|
||||
private:
|
||||
void refreshRecentActivity();
|
||||
void onActivityClicked(QListWidgetItem* item);
|
||||
|
||||
QLabel* m_statInstalled = nullptr;
|
||||
QLabel* m_statUpdates = nullptr;
|
||||
QLabel* m_statHistory = nullptr;
|
||||
QLabel* m_statManager = nullptr;
|
||||
QListWidget* m_recentList = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,151 @@
|
||||
#include "history-page.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QTableWidget>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ui-kit.h"
|
||||
|
||||
HistoryPage::HistoryPage(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);
|
||||
|
||||
QLabel* filterLabel = new QLabel(tr("Filtrer :"));
|
||||
filterLabel->setStyleSheet("font-size: 13px; color: #94a3b8;");
|
||||
filterRow->addWidget(filterLabel);
|
||||
|
||||
m_filter = new QComboBox();
|
||||
m_filter->addItems({tr("Toutes les actions"), tr("Installations"), tr("Suppressions"),
|
||||
tr("Mises à jour"), tr("Nettoyages")});
|
||||
connect(m_filter, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
[this](int) { refreshTable(); });
|
||||
filterRow->addWidget(m_filter);
|
||||
|
||||
filterRow->addStretch();
|
||||
|
||||
m_count = ui::countLabel();
|
||||
filterRow->addWidget(m_count);
|
||||
|
||||
layout->addLayout(filterRow);
|
||||
|
||||
m_table = ui::table({"Date", tr("Action"), tr("Paquet"), tr("Gestionnaire"), tr("Statut")},
|
||||
/*allStretch=*/true);
|
||||
layout->addWidget(m_table, 1);
|
||||
|
||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
||||
buttonBar->addStretch();
|
||||
|
||||
QPushButton* exportButton = new QPushButton(tr("Exporter (CSV)"));
|
||||
exportButton->setToolTip(tr("Enregistrer l'historique affiché dans un fichier CSV"));
|
||||
connect(exportButton, &QPushButton::clicked, this, &HistoryPage::exportCsv);
|
||||
buttonBar->addWidget(exportButton);
|
||||
|
||||
QPushButton* clearButton = new QPushButton(tr("Effacer l'historique"));
|
||||
clearButton->setProperty("variant", "danger");
|
||||
clearButton->setIcon(ui::icon("trash"));
|
||||
connect(clearButton, &QPushButton::clicked, this, [this, core] {
|
||||
// The core clears the file and announces it; this page follows through
|
||||
// historyChanged (connected below).
|
||||
core->clearHistory();
|
||||
});
|
||||
buttonBar->addWidget(clearButton);
|
||||
|
||||
layout->addLayout(buttonBar);
|
||||
|
||||
connect(core, &AppCore::historyChanged, this, &HistoryPage::refresh);
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
void HistoryPage::refresh() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
void HistoryPage::refreshTable() {
|
||||
const auto& all = core()->history()->getHistory();
|
||||
|
||||
std::vector<HistoryEntry> entries;
|
||||
const int filter = m_filter->currentIndex();
|
||||
for (const auto& entry : all) {
|
||||
const bool match = filter == 0
|
||||
|| (filter == 1 && entry.action == "install")
|
||||
|| (filter == 2 && entry.action == "remove")
|
||||
|| (filter == 3 && entry.action == "update")
|
||||
|| (filter == 4 && entry.action == "cleanup");
|
||||
if (match) entries.push_back(entry);
|
||||
}
|
||||
|
||||
m_count->setText(QString(tr("%1 action(s)")).arg(entries.size()));
|
||||
|
||||
ui::TableFillBatch batch(m_table);
|
||||
m_table->setRowCount(static_cast<int>(entries.size()));
|
||||
|
||||
for (int i = 0; i < static_cast<int>(entries.size()); ++i) {
|
||||
const auto& entry = entries[i];
|
||||
|
||||
// The site's status colours, one per action kind.
|
||||
QString actionText, actionColor;
|
||||
if (entry.action == "install") {
|
||||
actionText = tr("Installation"); actionColor = "#34d399";
|
||||
} else if (entry.action == "remove") {
|
||||
actionText = tr("Suppression"); actionColor = "#f87171";
|
||||
} else if (entry.action == "cleanup") {
|
||||
actionText = tr("Nettoyage"); actionColor = "#7dd3fc";
|
||||
} else {
|
||||
actionText = tr("Mise à jour"); actionColor = "#fbbf24";
|
||||
}
|
||||
|
||||
m_table->setItem(i, 0,
|
||||
new QTableWidgetItem(QString::fromStdString(entry.timestamp)));
|
||||
m_table->setItem(i, 1, new QTableWidgetItem(actionText));
|
||||
m_table->item(i, 1)->setForeground(QColor(actionColor));
|
||||
m_table->setItem(i, 2, new QTableWidgetItem(QString::fromStdString(entry.package)));
|
||||
m_table->setItem(i, 3, new QTableWidgetItem(QString::fromStdString(entry.plugin)));
|
||||
QTableWidgetItem* statusItem =
|
||||
new QTableWidgetItem(entry.success ? tr("Succès") : tr("Échec"));
|
||||
statusItem->setIcon(ui::icon(entry.success ? "check" : "close"));
|
||||
m_table->setItem(i, 4, statusItem);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryPage::exportCsv() {
|
||||
const auto& history = core()->history()->getHistory();
|
||||
if (history.empty()) {
|
||||
emit message(tr("Historique vide."));
|
||||
return;
|
||||
}
|
||||
|
||||
const QString path = QFileDialog::getSaveFileName(
|
||||
this, tr("Exporter l'historique"),
|
||||
QDir::homePath() + "/pacmanager-historique.csv", "CSV (*.csv)");
|
||||
if (path.isEmpty()) return;
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(this, tr("Export"),
|
||||
QString(tr("Impossible d'écrire dans %1")).arg(path));
|
||||
return;
|
||||
}
|
||||
QTextStream out(&file);
|
||||
out << "Date;Action;Paquet;Gestionnaire;Statut\n";
|
||||
for (const auto& entry : history) {
|
||||
out << ui::csvField(QString::fromStdString(entry.timestamp)) << ';'
|
||||
<< ui::csvField(QString::fromStdString(entry.action)) << ';'
|
||||
<< ui::csvField(QString::fromStdString(entry.package)) << ';'
|
||||
<< ui::csvField(QString::fromStdString(entry.plugin)) << ';'
|
||||
<< (entry.success ? "Succes" : "Echec") << '\n';
|
||||
}
|
||||
emit message(QString(tr("Historique exporté vers %1")).arg(path));
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QTableWidget;
|
||||
|
||||
// Historique: every action the application recorded (installations, removals,
|
||||
// updates, cleanups), filterable and exportable.
|
||||
class HistoryPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HistoryPage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override { return QStringLiteral("Historique"); }
|
||||
QString navSubtitle() const override {
|
||||
return QStringLiteral("Journal de toutes vos actions");
|
||||
}
|
||||
|
||||
void refresh() override;
|
||||
void exportCsv();
|
||||
|
||||
private:
|
||||
void refreshTable();
|
||||
|
||||
QComboBox* m_filter = nullptr;
|
||||
QLabel* m_count = nullptr;
|
||||
QTableWidget* m_table = nullptr;
|
||||
};
|
||||
Reference in new issue
Block a user