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.
152 lines
5.5 KiB
C++
152 lines
5.5 KiB
C++
#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));
|
|
}
|