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,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));
|
||||
}
|
||||
Reference in new issue
Block a user