refactor(arch): split the app into a logic core and per-screen pages
All the business logic now lives in AppCore (providers, workers, history, plugins, sudo and pacman-lock handling), freed from any widget so it runs headless and is testable on its own. The Qt window becomes a thin frame around one file per screen under pages/, wired through a common Page contract and a shared ui-kit. CMake gains the app-core-test target, which links Qt Core only to enforce the headless guarantee. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
576daf2fae
commit
897c174925
24 files changed
+4322
-3056
No files matched your search
@@ -0,0 +1,150 @@
|
||||
#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("Filtrer :");
|
||||
filterLabel->setStyleSheet("font-size: 13px; color: #7a8299;");
|
||||
filterRow->addWidget(filterLabel);
|
||||
|
||||
m_filter = new QComboBox();
|
||||
m_filter->addItems({"Toutes les actions", "Installations", "Suppressions",
|
||||
"Mises à jour", "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", "Action", "Paquet", "Gestionnaire", "Statut"},
|
||||
/*allStretch=*/true);
|
||||
layout->addWidget(m_table, 1);
|
||||
|
||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
||||
buttonBar->addStretch();
|
||||
|
||||
QPushButton* exportButton = new QPushButton("Exporter (CSV)");
|
||||
exportButton->setToolTip("Enregistrer l'historique affiché dans un fichier CSV");
|
||||
connect(exportButton, &QPushButton::clicked, this, &HistoryPage::exportCsv);
|
||||
buttonBar->addWidget(exportButton);
|
||||
|
||||
QPushButton* clearButton = new QPushButton("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("%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];
|
||||
|
||||
QString actionText, actionColor;
|
||||
if (entry.action == "install") {
|
||||
actionText = "Installation"; actionColor = "#3fb950";
|
||||
} else if (entry.action == "remove") {
|
||||
actionText = "Suppression"; actionColor = "#f7768e";
|
||||
} else if (entry.action == "cleanup") {
|
||||
actionText = "Nettoyage"; actionColor = "#56b6c2";
|
||||
} else {
|
||||
actionText = "Mise à jour"; actionColor = "#e0af68";
|
||||
}
|
||||
|
||||
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 ? "Succès" : "É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, "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, "Export",
|
||||
QString("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("Historique exporté vers %1").arg(path));
|
||||
}
|
||||
Reference in new issue
Block a user