feat(cleanup): add a maintenance page for unused and legacy packages

Leftovers pile up on a machine: dependencies that no installed package
requires any more, and installs coming from the AUR or manual builds that the
sync databases know nothing about. The new Nettoyage page lists both (orphans
first, since they are the ones that can be removed in bulk), shows which
provider reported each row, and frees the space held by the caches: paccache
(or pacman -Sc) and flatpak's unused runtimes.

Cleanup is an optional capability of IPackageManager, so providers that only
install packages keep working unchanged.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-09-12 22:17:08 +02:00
1 parent b8f8dc569f
commit 632cdf1dea
10 files changed
+750 -6

No files matched your search

+35 -2
View File
@@ -14,6 +14,7 @@
#include <QHash>
#include <string>
#include <utility>
#include <vector>
#include "package-manager.h"
@@ -54,7 +55,7 @@ private:
class ListWorker : public QThread {
Q_OBJECT
public:
enum Mode { Installed, Updates };
enum Mode { Installed, Updates, Cleanup };
ListWorker(const std::vector<IPackageManager*>& providers, Mode mode);
void run() override;
signals:
@@ -70,8 +71,11 @@ private:
class InstallWorker : public QThread {
Q_OBJECT
public:
enum class Op { Install, Remove, Update, UpdateAll, Refresh };
enum class Op { Install, Remove, Update, UpdateAll, Refresh, RemovePackages, CleanCache };
InstallWorker(IPackageManager* pm, Op op, const std::string& package);
// Bulk variant: removes several packages in one provider call (cleanup
// page) instead of one call per package.
InstallWorker(IPackageManager* pm, Op op, const std::vector<std::string>& packages);
InstallWorker(const std::vector<IPackageManager*>& providers, Op op);
void run() override;
signals:
@@ -84,6 +88,7 @@ private:
std::vector<IPackageManager*> m_providers;
Op m_op;
std::string m_package;
std::vector<std::string> m_packages;
};
class MainWindow : public QMainWindow {
@@ -123,6 +128,12 @@ private slots:
void onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
const QString& errorMessage);
void onSelfUpdateFinished(bool success, const QString& message);
void onCleanupScan();
void onCleanupListFinished(std::vector<PackageInfo> results);
void onCleanupSelectionChanged(int row);
void onRemoveCleanupOrphans();
void onRemoveCleanupSelection();
void onCleanCaches();
private:
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
@@ -135,6 +146,7 @@ private:
NavSearch,
NavInstalled,
NavUpdates,
NavCleanup,
NavHistory,
NavLogs,
NavPlugins,
@@ -148,6 +160,7 @@ private:
PageHistory,
PageLogs,
PagePlugins,
PageCleanup,
};
// When the sudo password is requested: once per session (at launch) or
@@ -183,6 +196,7 @@ private:
void setupHistoryPage();
void setupLogsPage();
void setupPluginsPage();
void setupCleanupPage();
void setupMenuBar();
void updatePageTitle();
void updateStatusBar();
@@ -206,6 +220,13 @@ private:
void loadInstalled();
void loadUpdates();
void refreshHistoryTable();
void loadCleanup();
void populateCleanupTable(const std::vector<PackageInfo>& candidates);
// Runs a bulk removal of the given candidates, one provider at a time, and
// refreshes the cleanup list when the last group is done.
void removeCleanupPackages(const std::vector<PackageInfo>& packages,
const QString& description);
void startNextCleanupRemoval();
void loadLogs();
void applyLogsFilter();
void setupTray();
@@ -276,6 +297,18 @@ private:
// dashboard refreshes do not spam the user.
int m_lastNotifiedUpdates = -1;
// Cleanup page
QTableWidget* m_cleanupTable = nullptr;
QLabel* m_cleanupCount = nullptr;
QPushButton* m_cleanupRemoveOrphansButton = nullptr;
QPushButton* m_cleanupRemoveSelectionButton = nullptr;
QPushButton* m_cleanupCacheButton = nullptr;
std::vector<PackageInfo> m_cleanupCandidates;
// Providers left to process for the bulk removal in progress, with the
// packages each of them owns. They run one after another because pacman
// locks its database.
std::vector<std::pair<IPackageManager*, std::vector<std::string>>> m_pendingRemovals;
// Plugins page
QTableWidget* m_pluginTable = nullptr;
QPushButton* m_pluginToggleButton = nullptr;