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,677 @@
|
||||
#include "browse-page.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QSplitter>
|
||||
#include <QStackedWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ui-kit.h"
|
||||
|
||||
BrowsePage::BrowsePage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(24, 20, 24, 20);
|
||||
layout->setSpacing(12);
|
||||
|
||||
// Search row (search mode only)
|
||||
m_searchRow = new QWidget();
|
||||
QHBoxLayout* searchRow = new QHBoxLayout(m_searchRow);
|
||||
searchRow->setContentsMargins(0, 0, 0, 0);
|
||||
searchRow->setSpacing(10);
|
||||
|
||||
m_searchBar = new QLineEdit();
|
||||
// Drops belong to the window: a .flatpakref let go over the search field
|
||||
// must install, not paste its path (see MainWindow::dragEnterEvent).
|
||||
m_searchBar->setAcceptDrops(false);
|
||||
m_searchBar->setPlaceholderText(tr("Rechercher un paquet (ex : firefox)..."));
|
||||
m_searchBar->setMinimumHeight(40);
|
||||
m_searchBar->addAction(ui::icon("search"), QLineEdit::LeadingPosition);
|
||||
connect(m_searchBar, &QLineEdit::returnPressed, this, &BrowsePage::onSearch);
|
||||
searchRow->addWidget(m_searchBar, 1);
|
||||
|
||||
m_searchButton = new QPushButton(tr("Rechercher"));
|
||||
m_searchButton->setProperty("variant", "primary");
|
||||
m_searchButton->setMinimumHeight(40);
|
||||
m_searchButton->setMinimumWidth(130);
|
||||
connect(m_searchButton, &QPushButton::clicked, this, &BrowsePage::onSearch);
|
||||
searchRow->addWidget(m_searchButton);
|
||||
|
||||
layout->addWidget(m_searchRow);
|
||||
|
||||
// Filter row (installed mode only)
|
||||
m_filterRow = new QWidget();
|
||||
QHBoxLayout* filterRow = new QHBoxLayout(m_filterRow);
|
||||
filterRow->setContentsMargins(0, 0, 0, 0);
|
||||
filterRow->setSpacing(10);
|
||||
|
||||
m_filterBar = new QLineEdit();
|
||||
m_filterBar->setAcceptDrops(false); // drops go to the window (see above)
|
||||
m_filterBar->setPlaceholderText(tr("Filtrer par nom..."));
|
||||
m_filterBar->setMinimumHeight(36);
|
||||
m_filterBar->addAction(ui::icon("filter"), QLineEdit::LeadingPosition);
|
||||
m_filterBar->setClearButtonEnabled(true);
|
||||
connect(m_filterBar, &QLineEdit::textChanged, this, &BrowsePage::onFilterChanged);
|
||||
filterRow->addWidget(m_filterBar, 1);
|
||||
|
||||
QLabel* filterHint = new QLabel(tr("Filtre local, instantané"));
|
||||
filterHint->setStyleSheet("font-size: 12px; color: #64748b;");
|
||||
filterRow->addWidget(filterHint);
|
||||
|
||||
m_filterRow->setVisible(false);
|
||||
layout->addWidget(m_filterRow);
|
||||
|
||||
// Thin progress bar, shown while the core works on a listing.
|
||||
m_progressBar = new QProgressBar();
|
||||
m_progressBar->setVisible(false);
|
||||
m_progressBar->setFixedHeight(6);
|
||||
m_progressBar->setTextVisible(false);
|
||||
layout->addWidget(m_progressBar);
|
||||
|
||||
// Action toolbar
|
||||
QHBoxLayout* actionBar = new QHBoxLayout();
|
||||
actionBar->setSpacing(8);
|
||||
|
||||
m_installButton = new QPushButton(tr("Installer"));
|
||||
m_installButton->setProperty("variant", "success");
|
||||
m_installButton->setIcon(ui::icon("package"));
|
||||
m_installButton->setEnabled(false);
|
||||
connect(m_installButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (m_selected.name.empty()) return;
|
||||
m_pendingSelect = QString::fromStdString(m_selected.name);
|
||||
start(core->install(m_selected), tr("Installation"));
|
||||
});
|
||||
actionBar->addWidget(m_installButton);
|
||||
|
||||
m_removeButton = new QPushButton(tr("Supprimer"));
|
||||
m_removeButton->setProperty("variant", "danger");
|
||||
m_removeButton->setIcon(ui::icon("trash"));
|
||||
m_removeButton->setEnabled(false);
|
||||
connect(m_removeButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (m_selected.name.empty()) return;
|
||||
m_pendingSelect = QString::fromStdString(m_selected.name);
|
||||
|
||||
// One row stands for one installation, or for a provider that only ever
|
||||
// has one: there is nothing to choose, so the row is what gets removed.
|
||||
if (m_selected.instances.size() < 2) {
|
||||
start(core->remove(m_selected), tr("Suppression"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Several copies of the same application: the user says which ones go.
|
||||
// A cancelled chooser aborts, an empty choice says so in the status bar.
|
||||
const auto targets = chooseInstancesToRemove();
|
||||
if (!targets.has_value()) return;
|
||||
if (targets->empty()) {
|
||||
emit message(tr("Aucune installation sélectionnée : cochez les copies "
|
||||
"à supprimer, ou annulez."));
|
||||
return;
|
||||
}
|
||||
start(core->removeInstances(m_selected, *targets), tr("Suppression"));
|
||||
});
|
||||
actionBar->addWidget(m_removeButton);
|
||||
|
||||
m_updateButton = new QPushButton(tr("Mettre à jour"));
|
||||
m_updateButton->setProperty("variant", "warning");
|
||||
m_updateButton->setIcon(ui::icon("refresh"));
|
||||
m_updateButton->setEnabled(false);
|
||||
connect(m_updateButton, &QPushButton::clicked, this, [this, core] {
|
||||
if (m_selected.name.empty()) return;
|
||||
m_pendingSelect = QString::fromStdString(m_selected.name);
|
||||
start(core->update(m_selected), tr("Mise à jour"));
|
||||
});
|
||||
actionBar->addWidget(m_updateButton);
|
||||
|
||||
m_updateAllButton = new QPushButton(tr("Tout mettre à jour"));
|
||||
m_updateAllButton->setProperty("variant", "info");
|
||||
m_updateAllButton->setIcon(ui::icon("arrow-up"));
|
||||
m_updateAllButton->setEnabled(false);
|
||||
connect(m_updateAllButton, &QPushButton::clicked, this, [this, core] {
|
||||
start(core->updateAll(), tr("Mise à jour globale"));
|
||||
});
|
||||
actionBar->addWidget(m_updateAllButton);
|
||||
|
||||
QPushButton* exportButton = new QPushButton(tr("Exporter"));
|
||||
exportButton->setToolTip(tr("Exporter la liste affichée en CSV"));
|
||||
connect(exportButton, &QPushButton::clicked, this, &BrowsePage::exportCsv);
|
||||
actionBar->addWidget(exportButton);
|
||||
|
||||
actionBar->addStretch();
|
||||
|
||||
m_resultCount = ui::countLabel();
|
||||
actionBar->addWidget(m_resultCount);
|
||||
|
||||
layout->addLayout(actionBar);
|
||||
|
||||
// Splitter: package table | details
|
||||
QSplitter* splitter = new QSplitter(Qt::Horizontal);
|
||||
splitter->setHandleWidth(10);
|
||||
|
||||
QFrame* listCard = ui::card();
|
||||
QVBoxLayout* listLayout = new QVBoxLayout(listCard);
|
||||
listLayout->setContentsMargins(8, 8, 8, 8);
|
||||
listLayout->setSpacing(6);
|
||||
|
||||
QLabel* listHeader = new QLabel("PAQUETS");
|
||||
listHeader->setObjectName("cardTitle");
|
||||
listLayout->addWidget(listHeader);
|
||||
|
||||
m_table = ui::table({tr("Nom"), tr("Version"), tr("Dépôt"), tr("Fournisseur"), tr("Statut")});
|
||||
connect(m_table, &QTableWidget::currentCellChanged, this,
|
||||
[this](int currentRow, int, int, int) { onPackageSelected(currentRow); });
|
||||
|
||||
m_tableStack = ui::withEmptyState(
|
||||
m_table,
|
||||
tr("Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
||||
"paquets installés."));
|
||||
// The "Tout mettre à jour" button only makes sense on the updates tab, but
|
||||
// there it must be usable without selecting a row first; the per-package
|
||||
// buttons stay gated on the selection.
|
||||
m_updateAllButton->setToolTip(tr("Mettre à jour tous les paquets listés"));
|
||||
listLayout->addWidget(m_tableStack);
|
||||
splitter->addWidget(listCard);
|
||||
|
||||
QFrame* detailsCard = ui::card();
|
||||
QVBoxLayout* detailsLayout = new QVBoxLayout(detailsCard);
|
||||
detailsLayout->setContentsMargins(20, 18, 20, 18);
|
||||
detailsLayout->setSpacing(10);
|
||||
|
||||
m_pkgName = new QLabel(tr("Sélectionnez un paquet"));
|
||||
m_pkgName->setWordWrap(true);
|
||||
// Serif like the site's package headings.
|
||||
m_pkgName->setStyleSheet(
|
||||
"font-family: serif; font-size: 22px; font-weight: 700; color: #e2e8f0;"
|
||||
"background: transparent;");
|
||||
detailsLayout->addWidget(m_pkgName);
|
||||
|
||||
m_pkgVersion = new QLabel("");
|
||||
m_pkgVersion->setStyleSheet(
|
||||
"font-size: 13px; color: #94a3b8; background: transparent;");
|
||||
detailsLayout->addWidget(m_pkgVersion);
|
||||
|
||||
QHBoxLayout* metaRow = new QHBoxLayout();
|
||||
metaRow->setSpacing(8);
|
||||
|
||||
auto makeMetaBadge = [](QLabel** out) {
|
||||
QLabel* label = new QLabel("—");
|
||||
label->setStyleSheet(
|
||||
"background: #273449; color: #94a3b8; border: 1px solid #303b4e;"
|
||||
"border-radius: 999px; padding: 3px 12px; font-size: 12px;");
|
||||
*out = label;
|
||||
return label;
|
||||
};
|
||||
metaRow->addWidget(makeMetaBadge(&m_pkgRepo));
|
||||
metaRow->addWidget(makeMetaBadge(&m_pkgSize));
|
||||
metaRow->addWidget(makeMetaBadge(&m_pkgProvider));
|
||||
metaRow->addStretch();
|
||||
detailsLayout->addLayout(metaRow);
|
||||
|
||||
// Only shown for a package the provider holds several times over.
|
||||
m_pkgInstances = new QLabel();
|
||||
m_pkgInstances->setWordWrap(true);
|
||||
m_pkgInstances->setStyleSheet(
|
||||
"font-size: 13px; color: #7dd3fc; background: transparent;");
|
||||
m_pkgInstances->setVisible(false);
|
||||
detailsLayout->addWidget(m_pkgInstances);
|
||||
|
||||
QFrame* separator = new QFrame();
|
||||
separator->setFrameShape(QFrame::HLine);
|
||||
separator->setStyleSheet(
|
||||
"color: #303b4e; background: #303b4e; max-height: 1px; border: none;");
|
||||
detailsLayout->addWidget(separator);
|
||||
|
||||
m_pkgDescription = new QLabel("");
|
||||
m_pkgDescription->setWordWrap(true);
|
||||
m_pkgDescription->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
m_pkgDescription->setStyleSheet(
|
||||
"font-size: 14px; color: #94a3b8; background: transparent;");
|
||||
detailsLayout->addWidget(m_pkgDescription, 1);
|
||||
|
||||
detailsLayout->addStretch();
|
||||
splitter->addWidget(detailsCard);
|
||||
|
||||
splitter->setSizes({560, 420});
|
||||
layout->addWidget(splitter, 1);
|
||||
|
||||
// ---- Core wiring ----
|
||||
connect(core, &AppCore::searchChunk, this,
|
||||
[this](std::vector<PackageInfo> results) { appendRows(results); });
|
||||
connect(core, &AppCore::searchFinished, this,
|
||||
[this](std::vector<PackageInfo> results) { populateTable(results); });
|
||||
connect(core, &AppCore::listFinished, this,
|
||||
[this](AppCore::ListMode mode, std::vector<PackageInfo> results) {
|
||||
if (mode == AppCore::ListMode::Installed) {
|
||||
m_installed = results;
|
||||
if (m_mode == Mode::Installed) onFilterChanged(m_filterBar->text());
|
||||
} else if (mode == AppCore::ListMode::Updates) {
|
||||
// The "searching" hint is replaced by the outcome: an empty
|
||||
// result means the system is up to date, not that the check
|
||||
// is still running.
|
||||
if (results.empty()) {
|
||||
ui::setEmptyStateText(
|
||||
m_tableStack,
|
||||
tr("Aucune mise à jour disponible.\nVotre système est à "
|
||||
"jour."));
|
||||
}
|
||||
if (m_mode == Mode::Updates) populateTable(results);
|
||||
}
|
||||
});
|
||||
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
||||
// A listing started from elsewhere (dashboard) while the user was
|
||||
// already on the updates tab would leave it without data: reload now
|
||||
// that the core is free again.
|
||||
if (!busy && m_mode == Mode::Updates && isVisible()) reloadCurrentView();
|
||||
});
|
||||
connect(core, &AppCore::busyChanged, this, [this](bool busy) {
|
||||
m_progressBar->setVisible(busy);
|
||||
if (!busy) {
|
||||
// A band stopped just before the end reads as a cancellation: when
|
||||
// real progress was shown, it is completed first.
|
||||
if (m_progressBar->maximum() > 0) m_progressBar->setValue(100);
|
||||
return;
|
||||
}
|
||||
m_progressValue = 0;
|
||||
// Start indeterminate; the first real percentage reported by the tool
|
||||
// turns the band into a determinate fill.
|
||||
m_progressBar->setRange(0, 0);
|
||||
m_progressBar->setValue(0);
|
||||
});
|
||||
connect(core, &AppCore::actionProgress, this,
|
||||
[this](const QString&, int percent) {
|
||||
if (percent < 0) return;
|
||||
// Providers (and the commands inside one operation) each count
|
||||
// from 0 again, so the band only ever moves forward.
|
||||
if (percent > m_progressValue) m_progressValue = percent;
|
||||
m_progressBar->setRange(0, 100);
|
||||
m_progressBar->setValue(m_progressValue);
|
||||
});
|
||||
connect(core, &AppCore::actionFinished, this,
|
||||
[this](const QString& action, const QString&, bool success, const QString&,
|
||||
bool) {
|
||||
// The installed state changed: show the fresh state of what the
|
||||
// user is looking at, but only when they are looking at it.
|
||||
if (!success || !isVisible()) return;
|
||||
if (action == QLatin1String("install") || action == QLatin1String("remove")
|
||||
|| action == QLatin1String("update")
|
||||
|| action == QLatin1String("update-all")
|
||||
|| action == QLatin1String("refresh")) {
|
||||
reloadCurrentView();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QString BrowsePage::navTitle() const {
|
||||
if (m_mode == Mode::Installed) return tr("Paquets installés");
|
||||
if (m_mode == Mode::Updates) return tr("Mises à jour disponibles");
|
||||
return QStringLiteral("Recherche");
|
||||
}
|
||||
|
||||
QString BrowsePage::navSubtitle() const {
|
||||
if (m_mode == Mode::Installed) return tr("Parcourez les paquets de votre système");
|
||||
if (m_mode == Mode::Updates) return tr("Maintenez votre système à jour");
|
||||
return tr("Trouvez et installez des paquets");
|
||||
}
|
||||
|
||||
void BrowsePage::refresh() {
|
||||
reloadCurrentView();
|
||||
}
|
||||
|
||||
void BrowsePage::showSearch() {
|
||||
setMode(Mode::Search);
|
||||
m_searchBar->setFocus();
|
||||
}
|
||||
|
||||
void BrowsePage::focusSearch() {
|
||||
setMode(Mode::Search);
|
||||
m_searchBar->setFocus();
|
||||
m_searchBar->selectAll();
|
||||
}
|
||||
|
||||
void BrowsePage::showInstalled(const QString& select) {
|
||||
setMode(Mode::Installed);
|
||||
if (!select.isEmpty()) m_pendingSelect = select;
|
||||
start(core()->loadInstalled(), tr("Paquets installés"));
|
||||
}
|
||||
|
||||
void BrowsePage::showUpdates() {
|
||||
setMode(Mode::Updates);
|
||||
// The update check is what the user came for: run it on every arrival on
|
||||
// the tab (pacman caches its queries for a few seconds, so a click right
|
||||
// after the dashboard loaded reuses that answer instead of respawning it).
|
||||
// The "searching" hint replaces the empty-state text for the duration, so
|
||||
// the tab never looks stuck on an empty table.
|
||||
ui::setEmptyStateText(m_tableStack,
|
||||
tr("Recherche des mises à jour en cours...\nLes résultats "
|
||||
"s'afficheront automatiquement."));
|
||||
if (core()->busy()) {
|
||||
// Something else is loading (e.g. the dashboard asked for the counts):
|
||||
// the busyChanged handler below reloads when the core frees up.
|
||||
return;
|
||||
}
|
||||
start(core()->loadUpdates(), tr("Mises à jour"));
|
||||
}
|
||||
|
||||
void BrowsePage::setMode(Mode mode) {
|
||||
m_mode = mode;
|
||||
m_searchRow->setVisible(mode == Mode::Search);
|
||||
m_filterRow->setVisible(mode == Mode::Installed);
|
||||
m_installButton->setVisible(mode == Mode::Search);
|
||||
|
||||
// "Tout mettre à jour" acts on the whole list, so it is only offered on the
|
||||
// tab that displays pending updates; there it needs no row selection.
|
||||
if (m_updateAllButton) {
|
||||
m_updateAllButton->setVisible(mode == Mode::Updates);
|
||||
m_updateAllButton->setEnabled(mode == Mode::Updates
|
||||
&& core()->hasAvailableProvider());
|
||||
}
|
||||
|
||||
// The updates tab rewrote the empty-state hint for its own states; restore
|
||||
// the generic one so the other tabs never show a stale updates message.
|
||||
if (mode != Mode::Updates) {
|
||||
ui::setEmptyStateText(
|
||||
m_tableStack,
|
||||
tr("Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des "
|
||||
"paquets installés."));
|
||||
}
|
||||
|
||||
// Clear any stale selection and reset the details panel
|
||||
m_table->clearSelection();
|
||||
resetDetails();
|
||||
}
|
||||
|
||||
void BrowsePage::reloadCurrentView() {
|
||||
if (m_mode == Mode::Installed) {
|
||||
start(core()->loadInstalled(), tr("Paquets installés"));
|
||||
} else if (m_mode == Mode::Updates) {
|
||||
start(core()->loadUpdates(), tr("Mises à jour"));
|
||||
} else if (!m_searchBar->text().trimmed().isEmpty()) {
|
||||
onSearch();
|
||||
}
|
||||
}
|
||||
|
||||
void BrowsePage::onSearch() {
|
||||
if (m_searchBar->text().trimmed().isEmpty()) {
|
||||
// Refocus the field instead of interrupting with a dialog.
|
||||
m_searchBar->setFocus();
|
||||
emit message(tr("Entrez un terme de recherche."));
|
||||
return;
|
||||
}
|
||||
|
||||
m_table->setRowCount(0);
|
||||
m_results.clear();
|
||||
start(core()->search(m_searchBar->text()), tr("Recherche"));
|
||||
}
|
||||
|
||||
void BrowsePage::onFilterChanged(const QString& text) {
|
||||
if (m_mode != Mode::Installed) return;
|
||||
|
||||
std::vector<PackageInfo> filtered;
|
||||
if (text.isEmpty()) {
|
||||
filtered = m_installed;
|
||||
} else {
|
||||
const QString needle = text.toLower();
|
||||
for (const auto& pkg : m_installed) {
|
||||
if (QString::fromStdString(pkg.name).toLower().contains(needle)) {
|
||||
filtered.push_back(pkg);
|
||||
}
|
||||
}
|
||||
}
|
||||
populateTable(filtered);
|
||||
}
|
||||
|
||||
void BrowsePage::populateTable(const std::vector<PackageInfo>& packages) {
|
||||
m_results = packages;
|
||||
ui::showEmptyState(m_tableStack, packages.empty());
|
||||
{
|
||||
ui::TableFillBatch batch(m_table);
|
||||
m_table->setRowCount(0);
|
||||
m_table->setRowCount(static_cast<int>(packages.size()));
|
||||
for (int i = 0; i < static_cast<int>(packages.size()); ++i) {
|
||||
addRow(i, packages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
m_resultCount->setText(QString(tr("%1 paquet(s)")).arg(packages.size()));
|
||||
|
||||
if (packages.empty()) {
|
||||
resetDetails();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we came here for a specific package (dashboard history, or the one an
|
||||
// operation just touched), select it.
|
||||
if (!m_pendingSelect.isEmpty()) {
|
||||
const QString target = m_pendingSelect;
|
||||
m_pendingSelect.clear();
|
||||
for (int i = 0; i < static_cast<int>(m_results.size()); ++i) {
|
||||
if (QString::fromStdString(m_results[i].name) == target) {
|
||||
m_table->selectRow(i);
|
||||
onPackageSelected(i); // update the details panel immediately
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_table->selectRow(0);
|
||||
}
|
||||
|
||||
// Appends an incoming search chunk to the rows already displayed, so the first
|
||||
// matches appear while the remaining providers are still searching.
|
||||
void BrowsePage::appendRows(const std::vector<PackageInfo>& packages) {
|
||||
const int startRow = static_cast<int>(m_results.size());
|
||||
m_results.insert(m_results.end(), packages.begin(), packages.end());
|
||||
|
||||
ui::TableFillBatch batch(m_table);
|
||||
m_table->setRowCount(static_cast<int>(m_results.size()));
|
||||
for (int i = 0; i < static_cast<int>(packages.size()); ++i) {
|
||||
addRow(startRow + i, packages[i]);
|
||||
}
|
||||
ui::showEmptyState(m_tableStack, m_results.empty());
|
||||
m_resultCount->setText(QString(tr("%1 paquet(s)")).arg(m_results.size()));
|
||||
}
|
||||
|
||||
void BrowsePage::addRow(int row, const PackageInfo& pkg) {
|
||||
QFont nameFont;
|
||||
nameFont.setWeight(QFont::DemiBold);
|
||||
|
||||
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
|
||||
nameItem->setFont(nameFont);
|
||||
m_table->setItem(row, 0, nameItem);
|
||||
|
||||
m_table->setItem(row, 1, new QTableWidgetItem(QString::fromStdString(pkg.version)));
|
||||
m_table->setItem(row, 2,
|
||||
new QTableWidgetItem(pkg.repository.empty()
|
||||
? QStringLiteral("—")
|
||||
: QString::fromStdString(pkg.repository)));
|
||||
|
||||
QTableWidgetItem* providerItem =
|
||||
new QTableWidgetItem(ui::providersLabel(core()->plugins(), pkg));
|
||||
providerItem->setForeground(QColor("#94a3b8"));
|
||||
m_table->setItem(row, 3, providerItem);
|
||||
|
||||
QTableWidgetItem* statusItem = new QTableWidgetItem(ui::packageStatusText(pkg));
|
||||
if (pkg.installed && pkg.updateAvailable) {
|
||||
statusItem->setForeground(QColor("#fbbf24"));
|
||||
statusItem->setIcon(ui::icon("arrow-up"));
|
||||
} else if (pkg.installed) {
|
||||
statusItem->setForeground(QColor("#34d399"));
|
||||
statusItem->setIcon(ui::icon("check"));
|
||||
} else {
|
||||
statusItem->setIcon(ui::icon("package"));
|
||||
}
|
||||
m_table->setItem(row, 4, statusItem);
|
||||
}
|
||||
|
||||
void BrowsePage::onPackageSelected(int row) {
|
||||
if (row < 0 || row >= static_cast<int>(m_results.size())) {
|
||||
resetDetails();
|
||||
return;
|
||||
}
|
||||
|
||||
m_selected = m_results[row];
|
||||
updateDetails(m_selected);
|
||||
|
||||
IPackageManager* provider =
|
||||
core()->providerFor(QString::fromStdString(m_selected.provider));
|
||||
m_installButton->setEnabled(provider && provider->canInstall()
|
||||
&& !m_selected.installed);
|
||||
m_removeButton->setEnabled(provider && provider->canRemove() && m_selected.installed);
|
||||
m_updateButton->setEnabled(provider && provider->canUpdate()
|
||||
&& m_selected.updateAvailable);
|
||||
}
|
||||
|
||||
void BrowsePage::updateDetails(const PackageInfo& pkg) {
|
||||
m_pkgName->setText(QString::fromStdString(pkg.name));
|
||||
|
||||
QString versionText = QString(tr("Version : %1")).arg(QString::fromStdString(pkg.version));
|
||||
if (pkg.updateAvailable) versionText += tr(" (mise à jour disponible)");
|
||||
m_pkgVersion->setText(versionText);
|
||||
|
||||
m_pkgRepo->setText(pkg.repository.empty()
|
||||
? tr("Dépôt : —")
|
||||
: QString(tr("Dépôt : %1")).arg(QString::fromStdString(pkg.repository)));
|
||||
m_pkgSize->setText(pkg.size.empty()
|
||||
? tr("Taille : —")
|
||||
: QString(tr("Taille : %1")).arg(QString::fromStdString(pkg.size)));
|
||||
m_pkgProvider->setText(
|
||||
QString(tr("Fournisseur : %1")).arg(ui::providersLabel(core()->plugins(), pkg)));
|
||||
|
||||
// A provider can hold several copies of the same application (flatpak: one
|
||||
// per installation, per remote or per branch). The row stands for the
|
||||
// application, so the copies it is made of are listed here — and the remove
|
||||
// button asks which of them to act on.
|
||||
if (pkg.instances.size() > 1) {
|
||||
QStringList copies;
|
||||
for (const PackageInstance& instance : pkg.instances) {
|
||||
copies << QString::fromStdString(instance.label);
|
||||
}
|
||||
m_pkgInstances->setText(
|
||||
QString(tr("%1 installation(s) :\n• %2"))
|
||||
.arg(copies.size())
|
||||
.arg(copies.join(QStringLiteral("\n• "))));
|
||||
m_pkgInstances->setVisible(true);
|
||||
} else {
|
||||
m_pkgInstances->setVisible(false);
|
||||
}
|
||||
|
||||
// Rich details (dependencies, required-by, install date, update size): the
|
||||
// core queries pacman on demand and caches the answer, so selecting a row
|
||||
// stays instant even when pacman is slow.
|
||||
QString details = QString::fromStdString(pkg.description);
|
||||
const QString rich = core()->packageDetails(pkg);
|
||||
if (!rich.isEmpty()) {
|
||||
if (!details.isEmpty()) details += "\n\n";
|
||||
details += rich;
|
||||
}
|
||||
m_pkgDescription->setText(details);
|
||||
}
|
||||
|
||||
// Asks which copies of the selected application to remove, when the provider
|
||||
// holds it more than once (flatpak: a user and a system-wide installation, or
|
||||
// two remotes or branches of the same id). One line per copy, each with the
|
||||
// provider's own target kept aside, so the core is handed exactly what it must
|
||||
// act on. Returns nothing when the user cancels, and an empty list when they
|
||||
// ticked nothing — which is why the caller only asks when there are at least
|
||||
// two copies: with one, the row is the thing to remove.
|
||||
std::optional<std::vector<std::string>> BrowsePage::chooseInstancesToRemove() {
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(tr("Supprimer %1").arg(QString::fromStdString(m_selected.name)));
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(&dialog);
|
||||
layout->setSpacing(10);
|
||||
QLabel* prompt = new QLabel(
|
||||
tr("%1 est installé plusieurs fois. Choisissez les installations à "
|
||||
"supprimer.")
|
||||
.arg(QString::fromStdString(m_selected.name)),
|
||||
&dialog);
|
||||
prompt->setWordWrap(true);
|
||||
layout->addWidget(prompt);
|
||||
|
||||
QListWidget* copies = new QListWidget(&dialog);
|
||||
for (const PackageInstance& instance : m_selected.instances) {
|
||||
QListWidgetItem* item =
|
||||
new QListWidgetItem(QString::fromStdString(instance.label), copies);
|
||||
// The target never reaches the screen: it is the provider's own syntax,
|
||||
// kept beside the label and handed straight back.
|
||||
item->setData(Qt::UserRole, QString::fromStdString(instance.target));
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
layout->addWidget(copies);
|
||||
|
||||
QDialogButtonBox* buttons =
|
||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
||||
buttons->button(QDialogButtonBox::Ok)->setText(tr("Supprimer"));
|
||||
buttons->button(QDialogButtonBox::Cancel)->setText(tr("Annuler"));
|
||||
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
||||
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
||||
layout->addWidget(buttons);
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) return std::nullopt;
|
||||
|
||||
std::vector<std::string> targets;
|
||||
for (int row = 0; row < copies->count(); ++row) {
|
||||
if (copies->item(row)->checkState() != Qt::Checked) continue;
|
||||
targets.push_back(copies->item(row)->data(Qt::UserRole).toString().toStdString());
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
void BrowsePage::resetDetails() {
|
||||
m_selected = PackageInfo{};
|
||||
m_pkgName->setText(tr("Sélectionnez un paquet"));
|
||||
m_pkgVersion->setText("");
|
||||
m_pkgRepo->setText("—");
|
||||
m_pkgSize->setText("—");
|
||||
m_pkgProvider->setText("—");
|
||||
m_pkgInstances->setVisible(false);
|
||||
m_pkgDescription->setText("");
|
||||
m_installButton->setEnabled(false);
|
||||
m_removeButton->setEnabled(false);
|
||||
m_updateButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void BrowsePage::exportCsv() {
|
||||
if (m_results.empty()) {
|
||||
emit message(tr("Aucune liste à exporter."));
|
||||
return;
|
||||
}
|
||||
|
||||
const QString path = QFileDialog::getSaveFileName(
|
||||
this, tr("Exporter la liste des paquets"),
|
||||
QDir::homePath() + "/pacmanager-paquets.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 << "Nom;Version;Depot;Fournisseur;Statut\n";
|
||||
for (const auto& pkg : m_results) {
|
||||
out << ui::csvField(QString::fromStdString(pkg.name)) << ';'
|
||||
<< ui::csvField(QString::fromStdString(pkg.version)) << ';'
|
||||
<< ui::csvField(QString::fromStdString(pkg.repository)) << ';'
|
||||
<< ui::csvField(ui::providersLabel(core()->plugins(), pkg)) << ';'
|
||||
<< ui::csvField(ui::packageStatusText(pkg)) << '\n';
|
||||
}
|
||||
emit message(QString(tr("%1 paquet(s) exporté(s) vers %2"))
|
||||
.arg(m_results.size())
|
||||
.arg(path));
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QProgressBar;
|
||||
class QPushButton;
|
||||
class QStackedWidget;
|
||||
class QTableWidget;
|
||||
|
||||
// The browsing screen. Search, installed and updates share this page because
|
||||
// they are the same table with a different query behind it; the sidebar exposes
|
||||
// three entries, all landing here with a different mode.
|
||||
class BrowsePage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Mode { Search, Installed, Updates };
|
||||
|
||||
explicit BrowsePage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override;
|
||||
QString navSubtitle() const override;
|
||||
void refresh() override;
|
||||
|
||||
// Entry points used by the sidebar, the dashboard shortcuts and the menu.
|
||||
void showSearch();
|
||||
void showInstalled(const QString& select = QString());
|
||||
void showUpdates();
|
||||
// Package to select once the next listing arrives: lets the frame open a
|
||||
// package from the dashboard without loading the list twice.
|
||||
void selectOnNextLoad(const QString& name) { m_pendingSelect = name; }
|
||||
// Puts the caret in the search field (Ctrl+F), selecting the current term.
|
||||
void focusSearch();
|
||||
|
||||
int resultCount() const { return static_cast<int>(m_results.size()); }
|
||||
// Exports the displayed list to a CSV file (the file dialog is the frame's
|
||||
// business, the content is this page's).
|
||||
void exportCsv();
|
||||
|
||||
private:
|
||||
void setMode(Mode mode);
|
||||
void reloadCurrentView();
|
||||
void onSearch();
|
||||
void onPackageSelected(int row);
|
||||
void onFilterChanged(const QString& text);
|
||||
void populateTable(const std::vector<PackageInfo>& packages);
|
||||
void appendRows(const std::vector<PackageInfo>& packages);
|
||||
void addRow(int row, const PackageInfo& pkg);
|
||||
// Which installations of the selected package to remove, asked only when
|
||||
// the provider holds it more than once. Nothing (std::nullopt) when the
|
||||
// user cancels, an empty list when they tick nothing.
|
||||
std::optional<std::vector<std::string>> chooseInstancesToRemove();
|
||||
void updateDetails(const PackageInfo& pkg);
|
||||
void resetDetails();
|
||||
|
||||
Mode m_mode = Mode::Search;
|
||||
|
||||
// Everything the current query returned, and the last installed listing
|
||||
// kept aside for the instant local filter.
|
||||
std::vector<PackageInfo> m_results;
|
||||
std::vector<PackageInfo> m_installed;
|
||||
PackageInfo m_selected;
|
||||
// Package to select once the next listing arrives (after a click on the
|
||||
// dashboard history, or after an operation).
|
||||
QString m_pendingSelect;
|
||||
|
||||
QWidget* m_searchRow = nullptr;
|
||||
QLineEdit* m_searchBar = nullptr;
|
||||
QPushButton* m_searchButton = nullptr;
|
||||
QWidget* m_filterRow = nullptr;
|
||||
QLineEdit* m_filterBar = nullptr;
|
||||
QLabel* m_resultCount = nullptr;
|
||||
QPushButton* m_installButton = nullptr;
|
||||
QPushButton* m_removeButton = nullptr;
|
||||
QPushButton* m_updateButton = nullptr;
|
||||
QPushButton* m_updateAllButton = nullptr;
|
||||
QProgressBar* m_progressBar = nullptr;
|
||||
// Highest percentage reported by the running operation, so the bar never
|
||||
// moves backwards when a provider restarts its own count.
|
||||
int m_progressValue = 0;
|
||||
QTableWidget* m_table = nullptr;
|
||||
QStackedWidget* m_tableStack = nullptr;
|
||||
QLabel* m_pkgName = nullptr;
|
||||
QLabel* m_pkgVersion = nullptr;
|
||||
QLabel* m_pkgRepo = nullptr;
|
||||
QLabel* m_pkgSize = nullptr;
|
||||
QLabel* m_pkgProvider = nullptr;
|
||||
// The copies a multi-installed package is made of, shown only when there is
|
||||
// more than one.
|
||||
QLabel* m_pkgInstances = nullptr;
|
||||
QLabel* m_pkgDescription = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,234 @@
|
||||
#include "cleanup-page.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ui-kit.h"
|
||||
|
||||
CleanupPage::CleanupPage(AppCore* core, QWidget* parent) : Page(core, parent) {
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(24, 20, 24, 20);
|
||||
layout->setSpacing(12);
|
||||
|
||||
QFrame* hintCard = ui::card();
|
||||
QVBoxLayout* hintLayout = new QVBoxLayout(hintCard);
|
||||
hintLayout->setContentsMargins(18, 16, 18, 16);
|
||||
hintLayout->setSpacing(4);
|
||||
|
||||
QLabel* hintTitle = new QLabel(tr("PAQUETS INUTILISÉS ET LEGACY"));
|
||||
hintTitle->setObjectName("cardTitle");
|
||||
hintLayout->addWidget(hintTitle);
|
||||
|
||||
QLabel* hint = new QLabel(
|
||||
tr("Les <b>orphelins</b> ont été installés comme dépendances et ne sont "
|
||||
"plus requis par aucun paquet : ils peuvent être supprimés sans risque. "
|
||||
"Les paquets <b>étrangers</b> viennent de l'AUR ou d'une compilation "
|
||||
"manuelle : vérifiez-les un par un avant de les supprimer."));
|
||||
hint->setTextFormat(Qt::RichText);
|
||||
hint->setWordWrap(true);
|
||||
hint->setStyleSheet("font-size: 12px; color: #94a3b8;");
|
||||
hintLayout->addWidget(hint);
|
||||
|
||||
layout->addWidget(hintCard);
|
||||
|
||||
m_table = ui::table({tr("Paquet"), tr("Version"), tr("Type"), tr("Fournisseur")});
|
||||
connect(m_table, &QTableWidget::currentCellChanged, this,
|
||||
[this](int currentRow, int, int, int) { onSelectionChanged(currentRow); });
|
||||
m_tableStack = ui::withEmptyState(
|
||||
m_table,
|
||||
tr("Rien à nettoyer pour le moment.\nLancez une analyse pour vérifier."));
|
||||
layout->addWidget(m_tableStack, 1);
|
||||
|
||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
||||
buttonBar->setSpacing(8);
|
||||
|
||||
QPushButton* scanButton = new QPushButton(tr("Analyser"));
|
||||
scanButton->setProperty("variant", "primary");
|
||||
scanButton->setIcon(ui::icon("search"));
|
||||
scanButton->setToolTip(tr("Rechercher les paquets inutilisés et legacy"));
|
||||
connect(scanButton, &QPushButton::clicked, this, &CleanupPage::scan);
|
||||
buttonBar->addWidget(scanButton);
|
||||
|
||||
m_removeOrphansButton = new QPushButton(tr("Supprimer les orphelins"));
|
||||
m_removeOrphansButton->setProperty("variant", "danger");
|
||||
m_removeOrphansButton->setIcon(ui::icon("trash"));
|
||||
m_removeOrphansButton->setEnabled(false);
|
||||
m_removeOrphansButton->setToolTip(
|
||||
tr("Supprimer tous les paquets que plus rien ne requiert"));
|
||||
connect(m_removeOrphansButton, &QPushButton::clicked, this,
|
||||
&CleanupPage::removeOrphans);
|
||||
buttonBar->addWidget(m_removeOrphansButton);
|
||||
|
||||
m_removeSelectionButton = new QPushButton(tr("Supprimer la sélection"));
|
||||
m_removeSelectionButton->setIcon(ui::icon("trash"));
|
||||
m_removeSelectionButton->setEnabled(false);
|
||||
connect(m_removeSelectionButton, &QPushButton::clicked, this,
|
||||
&CleanupPage::removeSelection);
|
||||
buttonBar->addWidget(m_removeSelectionButton);
|
||||
|
||||
m_cacheButton = new QPushButton(tr("Vider les caches"));
|
||||
m_cacheButton->setProperty("variant", "warning");
|
||||
m_cacheButton->setIcon(ui::icon("broom"));
|
||||
m_cacheButton->setToolTip(
|
||||
tr("Purger le cache de paquets (paccache / pacman -Sc) et les runtimes "
|
||||
"Flatpak inutilisés"));
|
||||
connect(m_cacheButton, &QPushButton::clicked, this, &CleanupPage::cleanCaches);
|
||||
buttonBar->addWidget(m_cacheButton);
|
||||
|
||||
buttonBar->addStretch();
|
||||
|
||||
m_count = ui::countLabel();
|
||||
buttonBar->addWidget(m_count);
|
||||
|
||||
layout->addLayout(buttonBar);
|
||||
|
||||
// The candidate list arrives through listFinished, which every page shares.
|
||||
connect(core, &AppCore::listFinished, this,
|
||||
[this](AppCore::ListMode mode, std::vector<PackageInfo> results) {
|
||||
if (mode == AppCore::ListMode::Cleanup) populate(results);
|
||||
});
|
||||
}
|
||||
|
||||
void CleanupPage::refresh() {
|
||||
scan();
|
||||
}
|
||||
|
||||
void CleanupPage::scan() {
|
||||
m_table->setRowCount(0);
|
||||
m_candidates.clear();
|
||||
m_removeOrphansButton->setEnabled(false);
|
||||
m_removeSelectionButton->setEnabled(false);
|
||||
|
||||
start(core()->loadCleanup(), tr("Nettoyage"));
|
||||
}
|
||||
|
||||
void CleanupPage::populate(const std::vector<PackageInfo>& candidates) {
|
||||
m_candidates = candidates;
|
||||
ui::showEmptyState(m_tableStack, candidates.empty());
|
||||
|
||||
QFont nameFont;
|
||||
nameFont.setWeight(QFont::DemiBold);
|
||||
|
||||
ui::TableFillBatch batch(m_table);
|
||||
m_table->setRowCount(0);
|
||||
m_table->setRowCount(static_cast<int>(candidates.size()));
|
||||
|
||||
int orphans = 0;
|
||||
for (int i = 0; i < static_cast<int>(candidates.size()); ++i) {
|
||||
const PackageInfo& pkg = candidates[i];
|
||||
if (pkg.orphan) ++orphans;
|
||||
|
||||
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
|
||||
nameItem->setFont(nameFont);
|
||||
m_table->setItem(i, 0, nameItem);
|
||||
|
||||
m_table->setItem(i, 1, new QTableWidgetItem(QString::fromStdString(pkg.version)));
|
||||
|
||||
QTableWidgetItem* typeItem =
|
||||
new QTableWidgetItem(QString::fromStdString(pkg.cleanupReason));
|
||||
typeItem->setForeground(QColor(pkg.orphan ? "#fbbf24" : "#94a3b8"));
|
||||
typeItem->setIcon(ui::icon(pkg.orphan ? "alert" : "package"));
|
||||
m_table->setItem(i, 2, typeItem);
|
||||
|
||||
m_table->setItem(i, 3, new QTableWidgetItem(ui::providersLabel(core()->plugins(), pkg)));
|
||||
}
|
||||
batch.release();
|
||||
|
||||
m_count->setText(QString(tr("%1 orphelin(s) · %2 legacy"))
|
||||
.arg(orphans)
|
||||
.arg(static_cast<int>(candidates.size()) - orphans));
|
||||
m_removeOrphansButton->setEnabled(orphans > 0);
|
||||
m_removeOrphansButton->setText(orphans > 0
|
||||
? QString(tr("Supprimer les orphelins (%1)")).arg(orphans)
|
||||
: QString(tr("Supprimer les orphelins")));
|
||||
|
||||
if (!candidates.empty()) m_table->selectRow(0);
|
||||
onSelectionChanged(m_table->currentRow());
|
||||
}
|
||||
|
||||
void CleanupPage::onSelectionChanged(int row) {
|
||||
if (row < 0 || row >= static_cast<int>(m_candidates.size())) {
|
||||
m_removeSelectionButton->setEnabled(false);
|
||||
m_removeSelectionButton->setToolTip(QString());
|
||||
return;
|
||||
}
|
||||
|
||||
const PackageInfo& pkg = m_candidates[row];
|
||||
const QString name = QString::fromStdString(pkg.name);
|
||||
m_removeSelectionButton->setEnabled(true);
|
||||
// A legacy package is only ever removed one by one and with an explicit
|
||||
// warning: nothing on the system proves it is unused.
|
||||
m_removeSelectionButton->setToolTip(
|
||||
pkg.orphan
|
||||
? QString(tr("Supprimer « %1 » (orphelin)")).arg(name)
|
||||
: QString(tr("Supprimer « %1 » (%2) — à vérifier : rien ne prouve "
|
||||
"qu'il est inutilisé"))
|
||||
.arg(name, QString::fromStdString(pkg.cleanupReason)));
|
||||
}
|
||||
|
||||
void CleanupPage::removeOrphans() {
|
||||
std::vector<PackageInfo> orphans;
|
||||
for (const auto& pkg : m_candidates) {
|
||||
if (pkg.orphan) orphans.push_back(pkg);
|
||||
}
|
||||
if (orphans.empty()) {
|
||||
emit message(tr("Aucun orphelin à supprimer."));
|
||||
return;
|
||||
}
|
||||
removePackages(orphans, QString(tr("%1 orphelin(s)")).arg(orphans.size()));
|
||||
}
|
||||
|
||||
void CleanupPage::removeSelection() {
|
||||
const int row = m_table->currentRow();
|
||||
if (row < 0 || row >= static_cast<int>(m_candidates.size())) return;
|
||||
|
||||
// Copied: the candidate list is rebuilt once the removal completes.
|
||||
const PackageInfo pkg = m_candidates[row];
|
||||
removePackages({pkg}, QString(tr("« %1 »")).arg(QString::fromStdString(pkg.name)));
|
||||
}
|
||||
|
||||
void CleanupPage::removePackages(const std::vector<PackageInfo>& packages,
|
||||
const QString& description) {
|
||||
if (packages.empty()) {
|
||||
emit message(tr("Aucun paquet sélectionné n'est supprimable."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (QMessageBox::question(this, tr("Nettoyage"),
|
||||
QString(tr("Supprimer %1 ?\n\nCette action est irréversible.")).arg(description))
|
||||
!= QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
start(core()->removePackages(packages, description), tr("Nettoyage"));
|
||||
}
|
||||
|
||||
void CleanupPage::cleanCaches() {
|
||||
// The core owns which providers have a cache; the page only names them in
|
||||
// the confirmation it shows before the purge.
|
||||
QStringList names;
|
||||
for (IPackageManager* pm : core()->availableProviders()) {
|
||||
if (pm->canCleanCache()) names << QString::fromStdString(pm->getName());
|
||||
}
|
||||
if (names.isEmpty()) {
|
||||
emit message(tr("Aucun cache à nettoyer sur ce système."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (QMessageBox::question(this, tr("Nettoyage"),
|
||||
QString(tr("Vider les caches de %1 ?\n\npacman ne conserve que la "
|
||||
"dernière version de chaque paquet téléchargé et Flatpak "
|
||||
"supprime les runtimes qu'aucune application n'utilise "
|
||||
"plus.")).arg(names.join(", "))) != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
start(core()->cleanCaches(), tr("Nettoyage des caches"));
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QStackedWidget;
|
||||
class QTableWidget;
|
||||
|
||||
// Nettoyage: lists what a cleanup can reclaim (orphans and legacy packages
|
||||
// reported by every provider) and frees the disk space the providers hold in
|
||||
// their caches. Nothing runs until the user asks for it: the candidate list is
|
||||
// only built on demand, since both queries cost a pacman call.
|
||||
class CleanupPage : public Page {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CleanupPage(AppCore* core, QWidget* parent = nullptr);
|
||||
|
||||
QString navTitle() const override { return QStringLiteral("Nettoyage"); }
|
||||
QString navSubtitle() const override {
|
||||
return QStringLiteral(
|
||||
"Purger les paquets inutilisés ou legacy et libérer de l'espace");
|
||||
}
|
||||
|
||||
void refresh() override;
|
||||
|
||||
private:
|
||||
void scan();
|
||||
void populate(const std::vector<PackageInfo>& candidates);
|
||||
void onSelectionChanged(int row);
|
||||
void removeOrphans();
|
||||
void removeSelection();
|
||||
void cleanCaches();
|
||||
// Confirms the removal, then hands the selection to the core (grouping the
|
||||
// packages per provider and running the groups in sequence are core rules).
|
||||
void removePackages(const std::vector<PackageInfo>& packages,
|
||||
const QString& description);
|
||||
|
||||
QTableWidget* m_table = nullptr;
|
||||
QStackedWidget* m_tableStack = nullptr;
|
||||
QLabel* m_count = nullptr;
|
||||
QPushButton* m_removeOrphansButton = nullptr;
|
||||
QPushButton* m_removeSelectionButton = nullptr;
|
||||
QPushButton* m_cacheButton = nullptr;
|
||||
// Last listing shown, kept so a row can be mapped back to its package when
|
||||
// the user asks to remove it.
|
||||
std::vector<PackageInfo> m_candidates;
|
||||
};
|
||||
Reference in new issue
Block a user