The checkout path installed with the build's configured prefix instead of installing into the directory holding the running copy, so the binary in use and its version marker both stayed at the old release: the app kept reporting that version and offered the same update again at every launch. Every method now stages and installs into the running binary's directory, the install step writes the release it just installed next to the binary, and currentVersion() reads the version compiled into the running build first, falling back to the marker file. The repo-root `version` file stays the single source of truth: CMake compiles it in. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
3075 lines
121 KiB
C++
3075 lines
121 KiB
C++
#include "main-window.h"
|
|
|
|
#include <QButtonGroup>
|
|
#include <QStackedWidget>
|
|
#include <QTableWidget>
|
|
#include <QHeaderView>
|
|
#include <QTextEdit>
|
|
#include <QDesktopServices>
|
|
#include <QUrl>
|
|
#include <QMessageBox>
|
|
#include <QSplitter>
|
|
#include <QFrame>
|
|
#include <QFile>
|
|
#include <QFileInfo>
|
|
#include <QTextCursor>
|
|
#include <QListWidget>
|
|
#include <QListWidgetItem>
|
|
#include <QColor>
|
|
#include <QAbstractItemView>
|
|
#include <QMetaType>
|
|
#include <QMenuBar>
|
|
#include <QMenu>
|
|
#include <QStatusBar>
|
|
#include <QIcon>
|
|
#include <QPixmap>
|
|
#include <QActionGroup>
|
|
#include <QInputDialog>
|
|
#include <QTimer>
|
|
#include <QSystemTrayIcon>
|
|
#include <QShortcut>
|
|
#include <QKeySequence>
|
|
#include <QFileDialog>
|
|
#include <QTextStream>
|
|
#include <QDir>
|
|
#include <QCoreApplication>
|
|
#include <QProcess>
|
|
|
|
#include "app-logging.h"
|
|
|
|
#include <algorithm>
|
|
#include <functional>
|
|
|
|
// Worker threads
|
|
SearchWorker::SearchWorker(const std::vector<IPackageManager*>& providers,
|
|
const std::string& query)
|
|
: m_providers(providers), m_query(query) {}
|
|
|
|
void SearchWorker::run() {
|
|
std::vector<PackageInfo> results;
|
|
for (IPackageManager* pm : m_providers) {
|
|
if (!pm->canSearch()) continue;
|
|
|
|
// Publish the freshly found packages right away, grouped in small
|
|
// batches so the table starts filling while the next provider is still
|
|
// running its (potentially slow) search in the background.
|
|
std::vector<PackageInfo> providerResults;
|
|
for (auto& pkg : pm->search(m_query)) {
|
|
pkg.provider = pm->getName();
|
|
providerResults.push_back(pkg);
|
|
}
|
|
constexpr int kBatchSize = 10;
|
|
for (size_t i = 0; i < providerResults.size(); i += kBatchSize) {
|
|
std::vector<PackageInfo> batch(
|
|
providerResults.begin() + i,
|
|
providerResults.begin() + std::min(i + kBatchSize, providerResults.size()));
|
|
emit chunk(std::move(batch));
|
|
}
|
|
|
|
results.insert(results.end(), providerResults.begin(), providerResults.end());
|
|
}
|
|
|
|
// One row per package name, whatever the number of providers offering it.
|
|
mergeProviderDuplicates(results);
|
|
|
|
// Group by provider (query order), then sort alphabetically within each.
|
|
std::vector<std::string> providerOrder;
|
|
for (IPackageManager* pm : m_providers) providerOrder.push_back(pm->getName());
|
|
sortByProviderThenName(results, providerOrder);
|
|
|
|
emit finished(results);
|
|
}
|
|
|
|
ListWorker::ListWorker(const std::vector<IPackageManager*>& providers, Mode mode)
|
|
: m_providers(providers), m_mode(mode) {}
|
|
|
|
void ListWorker::run() {
|
|
std::vector<PackageInfo> results;
|
|
for (IPackageManager* pm : m_providers) {
|
|
if (m_mode == Installed) {
|
|
if (!pm->canListInstalled()) continue;
|
|
for (auto& pkg : pm->listInstalled()) {
|
|
pkg.provider = pm->getName();
|
|
results.push_back(pkg);
|
|
}
|
|
} else if (m_mode == Updates) {
|
|
if (!pm->canUpdate()) continue;
|
|
for (auto& pkg : pm->listUpdates()) {
|
|
pkg.provider = pm->getName();
|
|
results.push_back(pkg);
|
|
}
|
|
} else {
|
|
if (!pm->canListCleanup()) continue;
|
|
for (auto& pkg : pm->listCleanupCandidates()) {
|
|
pkg.provider = pm->getName();
|
|
results.push_back(pkg);
|
|
}
|
|
}
|
|
}
|
|
// One row per package name, whatever the number of providers offering it.
|
|
// Cleanup candidates stay as reported: each row is tied to the provider
|
|
// that must remove it, and merging would hide which one reported it.
|
|
if (m_mode != Cleanup) mergeProviderDuplicates(results);
|
|
emit finished(results);
|
|
}
|
|
|
|
InstallWorker::InstallWorker(IPackageManager* pm, Op op, const std::string& package)
|
|
: m_providers{pm}, m_op(op), m_package(package) {}
|
|
|
|
InstallWorker::InstallWorker(IPackageManager* pm, Op op,
|
|
const std::vector<std::string>& packages)
|
|
: m_providers{pm}, m_op(op), m_packages(packages) {}
|
|
|
|
InstallWorker::InstallWorker(const std::vector<IPackageManager*>& providers, Op op)
|
|
: m_providers(providers), m_op(op) {}
|
|
|
|
void InstallWorker::run() {
|
|
bool success = true;
|
|
for (IPackageManager* pm : m_providers) {
|
|
// Prefix progress lines with the provider when several run at once.
|
|
// A real percentage (>= 0) also drives the determinate status bar bar.
|
|
auto cb = [this, pm](const std::string& msg, int percent) {
|
|
if (m_providers.size() > 1) {
|
|
emit progress(QString("[%1] %2")
|
|
.arg(QString::fromStdString(pm->getName()),
|
|
QString::fromStdString(msg)));
|
|
} else {
|
|
emit progress(QString::fromStdString(msg));
|
|
}
|
|
if (percent >= 0) emit progressValue(percent);
|
|
};
|
|
|
|
// Keep running the remaining providers even if one fails.
|
|
switch (m_op) {
|
|
case Op::Install: success = pm->install(m_package, cb) && success; break;
|
|
case Op::Remove: success = pm->remove(m_package, cb) && success; break;
|
|
case Op::Update: success = pm->update(m_package, cb) && success; break;
|
|
case Op::UpdateAll: success = pm->update("", cb) && success; break;
|
|
case Op::Refresh: success = pm->refresh(cb) && success; break;
|
|
case Op::RemovePackages:
|
|
success = pm->removePackages(m_packages, cb) && success;
|
|
break;
|
|
case Op::CleanCache: success = pm->cleanCache(cb) && success; break;
|
|
}
|
|
}
|
|
emit finished(success);
|
|
}
|
|
|
|
// Small rounded "badge" label used for status pills across the UI.
|
|
static QLabel* makeBadge(const QString& text, const QString& bg, const QString& fg) {
|
|
QLabel* badge = new QLabel(text);
|
|
badge->setStyleSheet(QString(
|
|
"background: %1; color: %2; border-radius: 9px;"
|
|
"padding: 2px 9px; font-size: 11px; font-weight: 600;")
|
|
.arg(bg, fg));
|
|
return badge;
|
|
}
|
|
|
|
// Closes a popen() stream. A named deleter avoids the GCC warning about the
|
|
// function-pointer attributes carried by decltype(&pclose) being dropped.
|
|
struct PipeCloser {
|
|
void operator()(FILE* file) const {
|
|
if (file) pclose(file);
|
|
}
|
|
};
|
|
|
|
// Load one of the embedded SVG icons (see resources/resources.qrc).
|
|
static QIcon loadIcon(const QString& name) {
|
|
return QIcon(QString(":/icons/%1.svg").arg(name));
|
|
}
|
|
|
|
// Render an SVG icon as a pixmap for use in QLabel (e.g. stat card icons or
|
|
// inline status indicators), sizing it to the requested resolution.
|
|
static QPixmap iconPixmap(const QString& name, int size) {
|
|
return loadIcon(name).pixmap(QSize(size, size));
|
|
}
|
|
|
|
// Display name of a provider id (e.g. "pacman" -> "Pacman"), falling back to
|
|
// the raw id for providers that are no longer registered.
|
|
static QString providerLabel(const PluginManager* pm, const std::string& id) {
|
|
for (const auto& entry : pm->plugins()) {
|
|
if (entry.info.id == id) return QString::fromStdString(entry.info.name);
|
|
}
|
|
return QString::fromStdString(id);
|
|
}
|
|
|
|
// Comma-separated display names of every provider offering a package (used by
|
|
// the Fournisseur column and the details badge).
|
|
static QString providersLabel(const PluginManager* pm, const PackageInfo& pkg) {
|
|
QStringList names;
|
|
for (const auto& id : pkg.providers) {
|
|
names << providerLabel(pm, id);
|
|
}
|
|
if (names.isEmpty() && !pkg.provider.empty()) {
|
|
names << providerLabel(pm, pkg.provider);
|
|
}
|
|
return names.join(", ");
|
|
}
|
|
|
|
// Quote a CSV field when it contains the separator, a quote or a newline, so
|
|
// exported lists stay importable in a spreadsheet.
|
|
static QString csvField(const QString& value) {
|
|
if (!value.contains(';') && !value.contains('"') && !value.contains('\n')) {
|
|
return value;
|
|
}
|
|
QString escaped = value;
|
|
escaped.replace(QLatin1String("\""), QLatin1String("\"\""));
|
|
return QLatin1Char('"') + escaped + QLatin1Char('"');
|
|
}
|
|
|
|
// Human-readable status of a package row, shared by the table and the export.
|
|
static QString packageStatusText(const PackageInfo& pkg) {
|
|
if (pkg.installed && pkg.updateAvailable) return QStringLiteral("MAJ dispo");
|
|
if (pkg.installed) return QStringLiteral("Installé");
|
|
if (!pkg.repository.empty()) return QStringLiteral("Disponible");
|
|
return QStringLiteral("—");
|
|
}
|
|
|
|
// MainWindow implementation
|
|
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
|
// Workers emit std::vector<PackageInfo> from another thread (QThread::run);
|
|
// without this registration the queued connection is dropped silently.
|
|
qRegisterMetaType<std::vector<PackageInfo>>("std::vector<PackageInfo>");
|
|
|
|
// Plugin registry: pacman is compiled in; every other plugin (Flatpak,
|
|
// ...) ships as an external shared library loaded at runtime from the
|
|
// plugins/ directories (see the Plugins page for details).
|
|
m_pluginManager = new PluginManager();
|
|
m_pluginManager->registerBuiltin(
|
|
{"pacman", "Pacman", "1.0.0",
|
|
"Gestionnaire de paquets natif d'Arch Linux", "FWS"},
|
|
new PacmanManager());
|
|
m_pluginManager->discoverExternal();
|
|
|
|
// Non-owning handle kept for sudo credential handling and pacman logs.
|
|
m_pacman = dynamic_cast<PacmanManager*>(m_pluginManager->managerFor("pacman"));
|
|
|
|
m_historyManager = new HistoryManager();
|
|
m_updateManager = new UpdateManager(this);
|
|
|
|
setupUI();
|
|
setupMenuBar();
|
|
setupTray();
|
|
setupShortcuts();
|
|
|
|
// Addon plugins get the main window so they can attach their own UI
|
|
// (status-bar widgets, toolbar buttons, ...). Only enabled+available
|
|
// addons receive it.
|
|
for (IPlugin* addon : m_pluginManager->availableAddons()) {
|
|
addon->onUiReady(this);
|
|
}
|
|
|
|
if (m_pluginManager->availableManagers().empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible sur ce système.");
|
|
m_searchBar->setEnabled(false);
|
|
m_searchButton->setEnabled(false);
|
|
m_refreshButton->setEnabled(false);
|
|
m_updateAllButton->setEnabled(false);
|
|
refreshDashboard();
|
|
return;
|
|
}
|
|
|
|
// With per-session credentials, ask for the sudo password once, right
|
|
// after the window is shown (so the dialog has a visible parent).
|
|
if (m_pacman && m_pacman->isAvailable()) {
|
|
QTimer::singleShot(0, this, [this]() {
|
|
if (m_credentialMode == CredentialMode::AtLaunch) {
|
|
ensureCredentials(m_pluginManager->availableManagers());
|
|
}
|
|
});
|
|
}
|
|
|
|
refreshDashboard();
|
|
updateStatusBar();
|
|
|
|
// Check for app updates once per day (or on first launch). The delay lets
|
|
// the window appear first so the status bar message is visible.
|
|
if (m_updateManager->shouldCheck()) {
|
|
QTimer::singleShot(1500, this, &MainWindow::onCheckForUpdates);
|
|
}
|
|
}
|
|
|
|
MainWindow::~MainWindow() {
|
|
delete m_pluginManager; // owns every provider, built-in and external
|
|
delete m_historyManager;
|
|
delete m_updateManager;
|
|
}
|
|
|
|
void MainWindow::setupUI() {
|
|
QWidget* centralWidget = new QWidget(this);
|
|
QHBoxLayout* rootLayout = new QHBoxLayout(centralWidget);
|
|
rootLayout->setContentsMargins(0, 0, 0, 0);
|
|
rootLayout->setSpacing(0);
|
|
|
|
setupSidebar();
|
|
rootLayout->addWidget(m_sidebar);
|
|
|
|
// Right column: header + stacked pages
|
|
QWidget* content = new QWidget();
|
|
content->setObjectName("content");
|
|
QVBoxLayout* contentLayout = new QVBoxLayout(content);
|
|
contentLayout->setContentsMargins(0, 0, 0, 0);
|
|
contentLayout->setSpacing(0);
|
|
|
|
setupHeader();
|
|
contentLayout->addWidget(m_headerWidget);
|
|
|
|
m_pages = new QStackedWidget();
|
|
setupDashboardPage();
|
|
setupBrowsePage();
|
|
setupHistoryPage();
|
|
setupLogsPage();
|
|
setupPluginsPage();
|
|
setupCleanupPage();
|
|
contentLayout->addWidget(m_pages, 1);
|
|
|
|
rootLayout->addWidget(content, 1);
|
|
setCentralWidget(centralWidget);
|
|
|
|
statusBar()->showMessage("Prêt");
|
|
|
|
// Tiny indeterminate bar anchored at the bottom of the window: it appears
|
|
// while install/update/remove/search operations run, without taking space
|
|
// on the content pages.
|
|
m_installProgressBar = new QProgressBar();
|
|
m_installProgressBar->setRange(0, 0);
|
|
m_installProgressBar->setTextVisible(false);
|
|
m_installProgressBar->setFixedHeight(4);
|
|
m_installProgressBar->setFixedWidth(120);
|
|
m_installProgressBar->setVisible(false);
|
|
statusBar()->addPermanentWidget(m_installProgressBar);
|
|
|
|
setStyleSheet(
|
|
// ---- Base ----
|
|
"QMainWindow, QWidget { background: #0d1017; color: #dbe2f0; }"
|
|
// ---- Sidebar ----
|
|
"QFrame#sidebar { background: #11151d; border-right: 1px solid #1d2432; }"
|
|
"QWidget#logo { padding: 4px 0; }"
|
|
"QLabel#logoText { font-size: 16px; font-weight: 800; color: #ffffff; }"
|
|
"QLabel#tagline { font-size: 11px; color: #6b7285; padding: 0 8px 8px 8px; }"
|
|
"QPushButton[nav=\"true\"] {"
|
|
" text-align: left;"
|
|
" background: transparent;"
|
|
" border: none;"
|
|
" border-left: 3px solid transparent;"
|
|
" border-radius: 8px;"
|
|
" padding: 9px 10px 9px 13px;"
|
|
" font-size: 13px;"
|
|
" font-weight: 600;"
|
|
" color: #98a0b3;"
|
|
"}"
|
|
"QPushButton[nav=\"true\"]:hover { background: #1a2130; color: #e8edf9; }"
|
|
"QPushButton[nav=\"true\"]:checked { background: #1c2434; border-left: 3px solid #7aa2f7; color: #ffffff; }"
|
|
"QPushButton[nav=\"true\"]:disabled { color: #565f73; }"
|
|
// ---- Header ----
|
|
"QWidget#header { background: #0f1219; border-bottom: 1px solid #1d2432; }"
|
|
"QLabel#headerTitle { font-size: 19px; font-weight: 800; color: #e8edf9; }"
|
|
"QLabel#headerSubtitle { font-size: 12px; color: #7a8299; }"
|
|
// ---- Cards ----
|
|
// Cards are intentionally frameless: the dashboard and detail panels
|
|
// use a flat look where content sits directly on the page background.
|
|
"QFrame#card { background: transparent; border: none; }"
|
|
"QLabel#cardTitle { font-size: 11px; font-weight: 700; color: #7a8299; letter-spacing: 1px; }"
|
|
"QLabel#statValue { font-size: 30px; font-weight: 800; color: #ffffff; }"
|
|
"QLabel#statTitle { font-size: 12px; color: #7a8299; font-weight: 600; }"
|
|
// ---- Buttons ----
|
|
"QPushButton {"
|
|
" background: #232b3a;"
|
|
" color: #dbe2f0;"
|
|
" border: none;"
|
|
" border-radius: 8px;"
|
|
" padding: 8px 16px;"
|
|
" font-size: 13px;"
|
|
" font-weight: 600;"
|
|
"}"
|
|
"QPushButton:hover { background: #2c3648; }"
|
|
"QPushButton:pressed { background: #1e2634; }"
|
|
"QPushButton:disabled { background: #181d28; color: #565f73; }"
|
|
"QPushButton[variant=\"primary\"] { background: #7aa2f7; color: #0d1017; }"
|
|
"QPushButton[variant=\"primary\"]:hover { background: #8ab0ff; }"
|
|
"QPushButton[variant=\"primary\"]:pressed { background: #5f86d9; }"
|
|
"QPushButton[variant=\"primary\"]:disabled { background: #2a3350; color: #7a8299; }"
|
|
"QPushButton[variant=\"success\"] { background: #3fb950; color: #0d1017; }"
|
|
"QPushButton[variant=\"success\"]:hover { background: #4ecb5f; }"
|
|
"QPushButton[variant=\"success\"]:pressed { background: #35a344; }"
|
|
"QPushButton[variant=\"success\"]:disabled { background: #1d2b21; color: #5f7a66; }"
|
|
"QPushButton[variant=\"danger\"] { background: #f7768e; color: #0d1017; }"
|
|
"QPushButton[variant=\"danger\"]:hover { background: #ff8ba4; }"
|
|
"QPushButton[variant=\"danger\"]:pressed { background: #e05e78; }"
|
|
"QPushButton[variant=\"danger\"]:disabled { background: #2c1c21; color: #7a5f66; }"
|
|
"QPushButton[variant=\"warning\"] { background: #e0af68; color: #0d1017; }"
|
|
"QPushButton[variant=\"warning\"]:hover { background: #ecc27e; }"
|
|
"QPushButton[variant=\"warning\"]:pressed { background: #d09a50; }"
|
|
"QPushButton[variant=\"warning\"]:disabled { background: #2b241c; color: #7a6d5c; }"
|
|
"QPushButton[variant=\"info\"] { background: #56b6c2; color: #0d1017; }"
|
|
"QPushButton[variant=\"info\"]:hover { background: #6cc7d2; }"
|
|
"QPushButton[variant=\"info\"]:pressed { background: #45a3ae; }"
|
|
"QPushButton[variant=\"info\"]:disabled { background: #1c2a2d; color: #5f7a7d; }"
|
|
// ---- Inputs ----
|
|
"QLineEdit {"
|
|
" background: #141927;"
|
|
" border: 1px solid #2a3448;"
|
|
" border-radius: 10px;"
|
|
" padding: 9px 14px;"
|
|
" font-size: 13px;"
|
|
" color: #dbe2f0;"
|
|
" selection-background-color: #7aa2f7;"
|
|
"}"
|
|
"QLineEdit:focus { border: 1px solid #7aa2f7; }"
|
|
"QLineEdit:disabled { color: #565f73; }"
|
|
"QComboBox {"
|
|
" background: #141927;"
|
|
" border: 1px solid #2a3448;"
|
|
" border-radius: 10px;"
|
|
" padding: 7px 12px;"
|
|
" font-size: 13px;"
|
|
" color: #dbe2f0;"
|
|
"}"
|
|
"QComboBox::drop-down { border: none; width: 26px; }"
|
|
"QComboBox QAbstractItemView {"
|
|
" background: #141927;"
|
|
" border: 1px solid #2a3448;"
|
|
" selection-background-color: #232c44;"
|
|
" color: #dbe2f0;"
|
|
"}"
|
|
// ---- Progress bar ----
|
|
"QProgressBar { background: #1c2330; border: none; border-radius: 3px; }"
|
|
"QProgressBar::chunk { background: #7aa2f7; border-radius: 3px; }"
|
|
// ---- Package table ----
|
|
// No outer frame: the table blends with the page background, keeping
|
|
// only the column header and alternating rows as visual separators.
|
|
"QTableWidget {"
|
|
" background: transparent;"
|
|
" alternate-background-color: #141a25;"
|
|
" border: none;"
|
|
" gridline-color: transparent;"
|
|
" outline: 0;"
|
|
"}"
|
|
"QTableWidget::item { border: none; padding: 4px 8px; }"
|
|
"QTableWidget::item:selected { background: #232c44; color: #ffffff; }"
|
|
"QTableWidget::item:hover { background: #1a2130; }"
|
|
"QHeaderView::section {"
|
|
" background: #1a2130;"
|
|
" color: #7a8299;"
|
|
" border: none;"
|
|
" border-bottom: 1px solid #232b3a;"
|
|
" padding: 8px;"
|
|
" font-size: 11px;"
|
|
" font-weight: 700;"
|
|
" letter-spacing: 1px;"
|
|
"}"
|
|
// ---- Recent activity list ----
|
|
"QListWidget#recentList { background: transparent; border: none; outline: 0; }"
|
|
"QListWidget#recentList::item { border-radius: 8px; margin: 1px 2px; }"
|
|
"QListWidget#recentList::item:hover { background: #1a2130; }"
|
|
// ---- Logs editor ----
|
|
"QTextEdit {"
|
|
" background: #12161f;"
|
|
" color: #c8d3f5;"
|
|
" border: 1px solid #232b3a;"
|
|
" border-radius: 10px;"
|
|
" padding: 10px;"
|
|
" font-family: monospace;"
|
|
" font-size: 13px;"
|
|
"}"
|
|
// ---- Scrollbars ----
|
|
"QScrollBar:vertical { background: transparent; width: 10px; margin: 2px; }"
|
|
"QScrollBar::handle:vertical { background: #2a3448; border-radius: 5px; min-height: 30px; }"
|
|
"QScrollBar::handle:vertical:hover { background: #3a455c; }"
|
|
"QScrollBar:horizontal { background: transparent; height: 10px; margin: 2px; }"
|
|
"QScrollBar::handle:horizontal { background: #2a3448; border-radius: 5px; min-width: 30px; }"
|
|
"QScrollBar::handle:horizontal:hover { background: #3a455c; }"
|
|
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical,"
|
|
"QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { height: 0; width: 0; }"
|
|
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical,"
|
|
"QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background: transparent; }"
|
|
// ---- Status bar ----
|
|
"QStatusBar {"
|
|
" background: #0f1219;"
|
|
" color: #7a8299;"
|
|
" border-top: 1px solid #1d2432;"
|
|
" font-size: 12px;"
|
|
"}"
|
|
// ---- Splitter ----
|
|
"QSplitter::handle { background: transparent; }"
|
|
// ---- Tooltips ----
|
|
"QToolTip {"
|
|
" background: #1c2434;"
|
|
" color: #e8edf9;"
|
|
" border: 1px solid #2a3448;"
|
|
" border-radius: 6px;"
|
|
" padding: 4px 8px;"
|
|
"}"
|
|
);
|
|
}
|
|
|
|
void MainWindow::setupSidebar() {
|
|
m_sidebar = new QFrame();
|
|
m_sidebar->setObjectName("sidebar");
|
|
m_sidebar->setFixedWidth(210);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(m_sidebar);
|
|
layout->setContentsMargins(12, 16, 12, 12);
|
|
layout->setSpacing(4);
|
|
|
|
QWidget* logoRow = new QWidget();
|
|
logoRow->setObjectName("logo");
|
|
QHBoxLayout* logoLayout = new QHBoxLayout(logoRow);
|
|
logoLayout->setContentsMargins(8, 2, 8, 2);
|
|
logoLayout->setSpacing(8);
|
|
|
|
QLabel* logoIcon = new QLabel();
|
|
logoIcon->setPixmap(iconPixmap("package", 20));
|
|
logoLayout->addWidget(logoIcon);
|
|
|
|
QLabel* appTitle = new QLabel("PacManager");
|
|
appTitle->setObjectName("logoText");
|
|
logoLayout->addWidget(appTitle);
|
|
logoLayout->addStretch();
|
|
layout->addWidget(logoRow);
|
|
|
|
QLabel* appSubtitle = new QLabel("Gestionnaire de paquets Arch Linux");
|
|
appSubtitle->setObjectName("tagline");
|
|
appSubtitle->setWordWrap(true);
|
|
layout->addWidget(appSubtitle);
|
|
|
|
layout->addSpacing(14);
|
|
|
|
m_navGroup = new QButtonGroup(this);
|
|
m_navGroup->setExclusive(true);
|
|
|
|
auto addNavButton = [&](int id, const QString& iconName,
|
|
const QString& text, const QString& tip) {
|
|
QPushButton* btn = new QPushButton(text);
|
|
btn->setProperty("nav", true);
|
|
btn->setCheckable(true);
|
|
btn->setToolTip(tip);
|
|
btn->setCursor(Qt::PointingHandCursor);
|
|
btn->setIcon(loadIcon(iconName));
|
|
btn->setIconSize(QSize(17, 17));
|
|
m_navGroup->addButton(btn, id);
|
|
layout->addWidget(btn);
|
|
return btn;
|
|
};
|
|
|
|
addNavButton(NavDashboard, "home", "Tableau de bord", "Vue d'ensemble du système");
|
|
addNavButton(NavSearch, "search", "Recherche", "Rechercher des paquets");
|
|
addNavButton(NavInstalled, "package", "Installés", "Voir les paquets installés");
|
|
addNavButton(NavUpdates, "arrow-up", "Mises à jour", "Voir les mises à jour disponibles");
|
|
addNavButton(NavCleanup, "broom", "Nettoyage",
|
|
"Purger les paquets inutilisés ou legacy et vider les caches");
|
|
layout->addSpacing(8);
|
|
addNavButton(NavHistory, "history", "Historique", "Historique des actions");
|
|
addNavButton(NavLogs, "logs", "Logs", "Logs pacman");
|
|
addNavButton(NavPlugins, "plugin", "Plugins", "Gestionnaires de paquets et extensions");
|
|
|
|
connect(m_navGroup, &QButtonGroup::idClicked, this, &MainWindow::onNavChanged);
|
|
m_navGroup->button(NavDashboard)->setChecked(true);
|
|
|
|
layout->addStretch();
|
|
|
|
m_refreshButton = new QPushButton("Rafraîchir les sources");
|
|
m_refreshButton->setProperty("nav", true);
|
|
m_refreshButton->setIcon(loadIcon("refresh"));
|
|
m_refreshButton->setIconSize(QSize(17, 17));
|
|
m_refreshButton->setToolTip("Rafraîchir les bases de données (pacman -Sy)");
|
|
connect(m_refreshButton, &QPushButton::clicked, this, &MainWindow::onRefresh);
|
|
layout->addWidget(m_refreshButton);
|
|
}
|
|
|
|
void MainWindow::setupHeader() {
|
|
m_headerWidget = new QWidget();
|
|
m_headerWidget->setObjectName("header");
|
|
m_headerWidget->setFixedHeight(74);
|
|
|
|
QHBoxLayout* layout = new QHBoxLayout(m_headerWidget);
|
|
layout->setContentsMargins(24, 0, 24, 0);
|
|
layout->setSpacing(6);
|
|
|
|
QVBoxLayout* textLayout = new QVBoxLayout();
|
|
textLayout->setSpacing(2);
|
|
|
|
m_headerTitle = new QLabel("Tableau de bord");
|
|
m_headerTitle->setObjectName("headerTitle");
|
|
textLayout->addWidget(m_headerTitle);
|
|
|
|
m_headerSubtitle = new QLabel("Vue d'ensemble de votre système");
|
|
m_headerSubtitle->setObjectName("headerSubtitle");
|
|
textLayout->addWidget(m_headerSubtitle);
|
|
|
|
layout->addLayout(textLayout);
|
|
layout->addStretch();
|
|
}
|
|
|
|
void MainWindow::setupDashboardPage() {
|
|
QWidget* page = new QWidget();
|
|
page->setObjectName("dashboardPage");
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(16);
|
|
|
|
// Stat cards
|
|
QHBoxLayout* statsRow = new QHBoxLayout();
|
|
statsRow->setSpacing(12);
|
|
statsRow->addWidget(makeStatCard("package", "Paquets installés", &m_statInstalled));
|
|
statsRow->addWidget(makeStatCard("arrow-up", "Mises à jour dispo", &m_statUpdates));
|
|
statsRow->addWidget(makeStatCard("history", "Actions enregistrées", &m_statHistory));
|
|
statsRow->addWidget(makeStatCard("tools", "Gestionnaire", &m_statManager));
|
|
layout->addLayout(statsRow);
|
|
|
|
// Quick actions
|
|
QFrame* actionsCard = makeCard();
|
|
QVBoxLayout* actionsLayout = new QVBoxLayout(actionsCard);
|
|
actionsLayout->setContentsMargins(18, 16, 18, 16);
|
|
actionsLayout->setSpacing(10);
|
|
|
|
QLabel* actionsTitle = new QLabel("ACTIONS RAPIDES");
|
|
actionsTitle->setObjectName("cardTitle");
|
|
actionsLayout->addWidget(actionsTitle);
|
|
|
|
QHBoxLayout* actionsRow = new QHBoxLayout();
|
|
actionsRow->setSpacing(10);
|
|
|
|
QPushButton* btnSearch = new QPushButton("Rechercher un paquet");
|
|
btnSearch->setProperty("variant", "primary");
|
|
btnSearch->setIcon(loadIcon("search"));
|
|
connect(btnSearch, &QPushButton::clicked, this, [this]() {
|
|
m_navGroup->button(NavSearch)->click();
|
|
m_searchBar->setFocus();
|
|
});
|
|
actionsRow->addWidget(btnSearch);
|
|
|
|
QPushButton* btnInstalled = new QPushButton("Paquets installés");
|
|
btnInstalled->setIcon(loadIcon("package"));
|
|
connect(btnInstalled, &QPushButton::clicked, this, [this]() {
|
|
m_navGroup->button(NavInstalled)->click();
|
|
});
|
|
actionsRow->addWidget(btnInstalled);
|
|
|
|
QPushButton* btnUpdateAll = new QPushButton("Tout mettre à jour");
|
|
btnUpdateAll->setProperty("variant", "warning");
|
|
btnUpdateAll->setIcon(loadIcon("arrow-up"));
|
|
connect(btnUpdateAll, &QPushButton::clicked, this, &MainWindow::onUpdateAll);
|
|
actionsRow->addWidget(btnUpdateAll);
|
|
|
|
QPushButton* btnCleanup = new QPushButton("Nettoyer le système");
|
|
btnCleanup->setIcon(loadIcon("broom"));
|
|
btnCleanup->setToolTip("Purger les paquets inutilisés et vider les caches");
|
|
connect(btnCleanup, &QPushButton::clicked, this, [this]() {
|
|
m_navGroup->button(NavCleanup)->click();
|
|
});
|
|
actionsRow->addWidget(btnCleanup);
|
|
|
|
QPushButton* btnRefresh = new QPushButton("Rafraîchir les sources");
|
|
btnRefresh->setProperty("variant", "info");
|
|
btnRefresh->setIcon(loadIcon("refresh"));
|
|
connect(btnRefresh, &QPushButton::clicked, this, &MainWindow::onRefresh);
|
|
actionsRow->addWidget(btnRefresh);
|
|
|
|
QPushButton* btnLogs = new QPushButton("Logs pacman");
|
|
btnLogs->setIcon(loadIcon("logs"));
|
|
connect(btnLogs, &QPushButton::clicked, this, [this]() {
|
|
m_navGroup->button(NavLogs)->click();
|
|
});
|
|
actionsRow->addWidget(btnLogs);
|
|
|
|
actionsRow->addStretch();
|
|
actionsLayout->addLayout(actionsRow);
|
|
layout->addWidget(actionsCard);
|
|
|
|
// Recent activity
|
|
QFrame* recentCard = makeCard();
|
|
QVBoxLayout* recentLayout = new QVBoxLayout(recentCard);
|
|
recentLayout->setContentsMargins(18, 16, 18, 12);
|
|
recentLayout->setSpacing(8);
|
|
|
|
QLabel* recentTitle = new QLabel("ACTIVITÉ RÉCENTE");
|
|
recentTitle->setObjectName("cardTitle");
|
|
recentLayout->addWidget(recentTitle);
|
|
|
|
m_recentList = new QListWidget();
|
|
m_recentList->setObjectName("recentList");
|
|
m_recentList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
m_recentList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
m_recentList->setFocusPolicy(Qt::NoFocus);
|
|
// Clicking an entry opens that package's install/remove/update details from the installed list.
|
|
connect(m_recentList, &QListWidget::itemClicked,
|
|
this, &MainWindow::onRecentActivityClicked);
|
|
recentLayout->addWidget(m_recentList, 1);
|
|
|
|
layout->addWidget(recentCard, 1);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
void MainWindow::setupBrowsePage() {
|
|
QWidget* page = new QWidget();
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
// Search row (visible in search mode only)
|
|
m_searchRowWidget = new QWidget();
|
|
QHBoxLayout* searchRow = new QHBoxLayout(m_searchRowWidget);
|
|
searchRow->setContentsMargins(0, 0, 0, 0);
|
|
searchRow->setSpacing(10);
|
|
|
|
m_searchBar = new QLineEdit();
|
|
m_searchBar->setPlaceholderText("Rechercher un paquet (ex : firefox)...");
|
|
m_searchBar->setMinimumHeight(40);
|
|
m_searchBar->addAction(loadIcon("search"), QLineEdit::LeadingPosition);
|
|
connect(m_searchBar, &QLineEdit::returnPressed, this, &MainWindow::onSearch);
|
|
searchRow->addWidget(m_searchBar, 1);
|
|
|
|
m_searchButton = new QPushButton("Rechercher");
|
|
m_searchButton->setProperty("variant", "primary");
|
|
m_searchButton->setMinimumHeight(40);
|
|
m_searchButton->setMinimumWidth(130);
|
|
connect(m_searchButton, &QPushButton::clicked, this, &MainWindow::onSearch);
|
|
searchRow->addWidget(m_searchButton);
|
|
|
|
layout->addWidget(m_searchRowWidget);
|
|
|
|
// Filter row (visible in installed mode only)
|
|
m_filterRowWidget = new QWidget();
|
|
QHBoxLayout* filterRow = new QHBoxLayout(m_filterRowWidget);
|
|
filterRow->setContentsMargins(0, 0, 0, 0);
|
|
filterRow->setSpacing(10);
|
|
|
|
m_filterBar = new QLineEdit();
|
|
m_filterBar->setPlaceholderText("Filtrer par nom...");
|
|
m_filterBar->setMinimumHeight(36);
|
|
m_filterBar->addAction(loadIcon("filter"), QLineEdit::LeadingPosition);
|
|
m_filterBar->setClearButtonEnabled(true);
|
|
connect(m_filterBar, &QLineEdit::textChanged, this, &MainWindow::onInstalledFilterChanged);
|
|
filterRow->addWidget(m_filterBar, 1);
|
|
|
|
QLabel* filterHint = new QLabel("Filtre local, instantané");
|
|
filterHint->setStyleSheet("font-size: 12px; color: #7a8299;");
|
|
filterRow->addWidget(filterHint);
|
|
|
|
m_filterRowWidget->setVisible(false);
|
|
layout->addWidget(m_filterRowWidget);
|
|
|
|
// Thin progress bar
|
|
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("Installer");
|
|
m_installButton->setProperty("variant", "success");
|
|
m_installButton->setIcon(loadIcon("package"));
|
|
m_installButton->setEnabled(false);
|
|
connect(m_installButton, &QPushButton::clicked, this, &MainWindow::onInstall);
|
|
actionBar->addWidget(m_installButton);
|
|
|
|
m_removeButton = new QPushButton("Supprimer");
|
|
m_removeButton->setProperty("variant", "danger");
|
|
m_removeButton->setIcon(loadIcon("trash"));
|
|
m_removeButton->setEnabled(false);
|
|
connect(m_removeButton, &QPushButton::clicked, this, &MainWindow::onRemove);
|
|
actionBar->addWidget(m_removeButton);
|
|
|
|
m_updateButton = new QPushButton("Mettre à jour");
|
|
m_updateButton->setProperty("variant", "warning");
|
|
m_updateButton->setIcon(loadIcon("refresh"));
|
|
m_updateButton->setEnabled(false);
|
|
connect(m_updateButton, &QPushButton::clicked, this, &MainWindow::onUpdate);
|
|
actionBar->addWidget(m_updateButton);
|
|
|
|
m_updateAllButton = new QPushButton("Tout mettre à jour");
|
|
m_updateAllButton->setProperty("variant", "info");
|
|
m_updateAllButton->setIcon(loadIcon("arrow-up"));
|
|
m_updateAllButton->setEnabled(false);
|
|
connect(m_updateAllButton, &QPushButton::clicked, this, &MainWindow::onUpdateAll);
|
|
actionBar->addWidget(m_updateAllButton);
|
|
|
|
QPushButton* exportBtn = new QPushButton("Exporter");
|
|
exportBtn->setToolTip("Exporter la liste affichée en CSV");
|
|
connect(exportBtn, &QPushButton::clicked, this, &MainWindow::onExportPackageList);
|
|
actionBar->addWidget(exportBtn);
|
|
|
|
actionBar->addStretch();
|
|
|
|
m_resultCount = new QLabel("");
|
|
m_resultCount->setStyleSheet("font-size: 12px; color: #7a8299; font-weight: 600;");
|
|
actionBar->addWidget(m_resultCount);
|
|
|
|
layout->addLayout(actionBar);
|
|
|
|
// Splitter: package table | details
|
|
QSplitter* splitter = new QSplitter(Qt::Horizontal);
|
|
splitter->setHandleWidth(10);
|
|
|
|
// Left card: package table
|
|
QFrame* listCard = makeCard();
|
|
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_packageTable = new QTableWidget(0, 5);
|
|
m_packageTable->setHorizontalHeaderLabels(
|
|
{"Nom", "Version", "Dépôt", "Fournisseur", "Statut"});
|
|
m_packageTable->verticalHeader()->setVisible(false);
|
|
m_packageTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
m_packageTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
m_packageTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
m_packageTable->setShowGrid(false);
|
|
m_packageTable->setAlternatingRowColors(true);
|
|
m_packageTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
m_packageTable->verticalHeader()->setDefaultSectionSize(36);
|
|
m_packageTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
m_packageTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
m_packageTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
m_packageTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
m_packageTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
|
connect(m_packageTable, &QTableWidget::currentCellChanged, this,
|
|
[this](int currentRow, int, int, int) { onPackageSelected(currentRow); });
|
|
|
|
listLayout->addWidget(m_packageTable);
|
|
splitter->addWidget(listCard);
|
|
|
|
// Right card: package details
|
|
QFrame* detailsCard = makeCard();
|
|
QVBoxLayout* detailsLayout = new QVBoxLayout(detailsCard);
|
|
detailsLayout->setContentsMargins(20, 18, 20, 18);
|
|
detailsLayout->setSpacing(10);
|
|
|
|
m_packageName = new QLabel("Sélectionnez un paquet");
|
|
m_packageName->setWordWrap(true);
|
|
m_packageName->setStyleSheet("font-size: 22px; font-weight: 700; color: #e8edf9; background: transparent;");
|
|
detailsLayout->addWidget(m_packageName);
|
|
|
|
m_packageVersion = new QLabel("");
|
|
m_packageVersion->setStyleSheet("font-size: 13px; color: #7a8299; background: transparent;");
|
|
detailsLayout->addWidget(m_packageVersion);
|
|
|
|
QHBoxLayout* metaRow = new QHBoxLayout();
|
|
metaRow->setSpacing(8);
|
|
|
|
m_packageRepo = new QLabel("—");
|
|
m_packageRepo->setStyleSheet(
|
|
"background: #1c2434; color: #7a8299; border-radius: 10px;"
|
|
"padding: 3px 12px; font-size: 12px;");
|
|
metaRow->addWidget(m_packageRepo);
|
|
|
|
m_packageSize = new QLabel("—");
|
|
m_packageSize->setStyleSheet(
|
|
"background: #1c2434; color: #7a8299; border-radius: 10px;"
|
|
"padding: 3px 12px; font-size: 12px;");
|
|
metaRow->addWidget(m_packageSize);
|
|
|
|
m_packageProvider = new QLabel("—");
|
|
m_packageProvider->setStyleSheet(
|
|
"background: #1c2434; color: #7a8299; border-radius: 10px;"
|
|
"padding: 3px 12px; font-size: 12px;");
|
|
metaRow->addWidget(m_packageProvider);
|
|
|
|
metaRow->addStretch();
|
|
detailsLayout->addLayout(metaRow);
|
|
|
|
QFrame* separator = new QFrame();
|
|
separator->setFrameShape(QFrame::HLine);
|
|
separator->setStyleSheet("color: #232b3a; background: #232b3a; max-height: 1px; border: none;");
|
|
detailsLayout->addWidget(separator);
|
|
|
|
m_packageDescription = new QLabel("");
|
|
m_packageDescription->setWordWrap(true);
|
|
m_packageDescription->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
m_packageDescription->setStyleSheet(
|
|
"font-size: 14px; color: #c8d3f5; background: transparent;");
|
|
detailsLayout->addWidget(m_packageDescription, 1);
|
|
|
|
detailsLayout->addStretch();
|
|
splitter->addWidget(detailsCard);
|
|
|
|
splitter->setSizes({560, 420});
|
|
layout->addWidget(splitter, 1);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
void MainWindow::setupHistoryPage() {
|
|
QWidget* page = new QWidget();
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
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_historyFilter = new QComboBox();
|
|
m_historyFilter->addItems({"Toutes les actions", "Installations", "Suppressions",
|
|
"Mises à jour", "Nettoyages"});
|
|
connect(m_historyFilter, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
this, &MainWindow::onHistoryFilterChanged);
|
|
filterRow->addWidget(m_historyFilter);
|
|
|
|
filterRow->addStretch();
|
|
|
|
m_historyCount = new QLabel("");
|
|
m_historyCount->setStyleSheet("font-size: 12px; color: #7a8299; font-weight: 600;");
|
|
filterRow->addWidget(m_historyCount);
|
|
|
|
layout->addLayout(filterRow);
|
|
|
|
m_historyTable = new QTableWidget(0, 5);
|
|
m_historyTable->setHorizontalHeaderLabels(
|
|
{"Date", "Action", "Paquet", "Gestionnaire", "Statut"});
|
|
m_historyTable->verticalHeader()->setVisible(false);
|
|
m_historyTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
m_historyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
m_historyTable->setShowGrid(false);
|
|
m_historyTable->setAlternatingRowColors(true);
|
|
m_historyTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
m_historyTable->verticalHeader()->setDefaultSectionSize(34);
|
|
layout->addWidget(m_historyTable, 1);
|
|
|
|
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
buttonBar->addStretch();
|
|
|
|
QPushButton* exportBtn = new QPushButton("Exporter (CSV)");
|
|
exportBtn->setToolTip("Enregistrer l'historique affiché dans un fichier CSV");
|
|
connect(exportBtn, &QPushButton::clicked, this, &MainWindow::onExportHistory);
|
|
buttonBar->addWidget(exportBtn);
|
|
|
|
QPushButton* clearBtn = new QPushButton("Effacer l'historique");
|
|
clearBtn->setProperty("variant", "danger");
|
|
clearBtn->setIcon(loadIcon("trash"));
|
|
connect(clearBtn, &QPushButton::clicked, this, &MainWindow::onClearHistory);
|
|
buttonBar->addWidget(clearBtn);
|
|
|
|
layout->addLayout(buttonBar);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
void MainWindow::setupLogsPage() {
|
|
QWidget* page = new QWidget();
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
// Filter row: /var/log/pacman.log can be huge, so the content is read once
|
|
// into m_logsRaw and filtered in memory (no re-read per keystroke).
|
|
QHBoxLayout* filterRow = new QHBoxLayout();
|
|
filterRow->setSpacing(10);
|
|
|
|
m_logsFilter = new QLineEdit();
|
|
m_logsFilter->setPlaceholderText("Filtrer les logs (paquet, action, date)...");
|
|
m_logsFilter->setMinimumHeight(36);
|
|
m_logsFilter->setClearButtonEnabled(true);
|
|
m_logsFilter->addAction(loadIcon("filter"), QLineEdit::LeadingPosition);
|
|
connect(m_logsFilter, &QLineEdit::textChanged,
|
|
this, &MainWindow::onLogsFilterChanged);
|
|
filterRow->addWidget(m_logsFilter, 1);
|
|
|
|
layout->addLayout(filterRow);
|
|
|
|
m_logsText = new QTextEdit();
|
|
m_logsText->setReadOnly(true);
|
|
layout->addWidget(m_logsText, 1);
|
|
|
|
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
buttonBar->addStretch();
|
|
|
|
QPushButton* refreshBtn = new QPushButton("Recharger");
|
|
refreshBtn->setIcon(loadIcon("refresh"));
|
|
connect(refreshBtn, &QPushButton::clicked, this, &MainWindow::onRefreshLogs);
|
|
buttonBar->addWidget(refreshBtn);
|
|
|
|
layout->addLayout(buttonBar);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
// The Plugins page acts as the add-on store: it lists every plugin known to
|
|
// the application (built-in and external — package-manager providers and
|
|
// generic addons), lets the user enable/disable them, and rescans the plugin
|
|
// directories for new ones.
|
|
void MainWindow::setupPluginsPage() {
|
|
QWidget* page = new QWidget();
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
QFrame* hintCard = makeCard();
|
|
QVBoxLayout* hintLayout = new QVBoxLayout(hintCard);
|
|
hintLayout->setContentsMargins(18, 16, 18, 16);
|
|
hintLayout->setSpacing(4);
|
|
|
|
QLabel* hintTitle = new QLabel("AJOUTER UN PLUGIN");
|
|
hintTitle->setObjectName("cardTitle");
|
|
hintLayout->addWidget(hintTitle);
|
|
|
|
QLabel* hint = new QLabel(
|
|
"Pacman est intégré et le plugin Flatpak est livré par défaut. Si un "
|
|
"fournisseur est « Indisponible », sélectionnez-le puis cliquez sur "
|
|
"« Installer l'outil » pour l'installer via pacman. Un plugin peut être "
|
|
"un gestionnaire de paquets (apt, dnf, ...) ou n'importe quelle extension "
|
|
"(addon graphique, helper, ...) tant qu'il est écrit en C++ : compilez une "
|
|
"bibliothèque partagée (voir plugins/example-provider et "
|
|
"plugins/example-addon) et déposez-la dans "
|
|
"~/.local/share/PacManager/plugins/ ou dans le dossier plugins/ à côté de "
|
|
"l'exécutable, puis cliquez sur « Recharger ».");
|
|
hint->setWordWrap(true);
|
|
hint->setStyleSheet("font-size: 12px; color: #7a8299;");
|
|
hintLayout->addWidget(hint);
|
|
|
|
layout->addWidget(hintCard);
|
|
|
|
m_pluginTable = new QTableWidget(0, 5);
|
|
m_pluginTable->setHorizontalHeaderLabels(
|
|
{"Plugin", "Type", "Version", "Auteur", "Statut"});
|
|
m_pluginTable->verticalHeader()->setVisible(false);
|
|
m_pluginTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
m_pluginTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
m_pluginTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
m_pluginTable->setShowGrid(false);
|
|
m_pluginTable->setAlternatingRowColors(true);
|
|
m_pluginTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
m_pluginTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
m_pluginTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
m_pluginTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
m_pluginTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
|
m_pluginTable->verticalHeader()->setDefaultSectionSize(36);
|
|
connect(m_pluginTable, &QTableWidget::currentCellChanged, this,
|
|
[this](int currentRow, int, int, int) { onPluginTableSelected(currentRow); });
|
|
layout->addWidget(m_pluginTable, 1);
|
|
|
|
m_pluginDescription = new QLabel("");
|
|
m_pluginDescription->setWordWrap(true);
|
|
m_pluginDescription->setStyleSheet(
|
|
"font-size: 13px; color: #c8d3f5; background: transparent; padding: 2px 4px;");
|
|
layout->addWidget(m_pluginDescription);
|
|
|
|
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
buttonBar->addStretch();
|
|
|
|
// Installs the OS package backing a provider whose tool is missing
|
|
// (e.g. pacman -S flatpak), then rescans so it becomes available.
|
|
m_pluginInstallButton = new QPushButton("Installer l'outil");
|
|
m_pluginInstallButton->setProperty("variant", "primary");
|
|
m_pluginInstallButton->setEnabled(false);
|
|
m_pluginInstallButton->setVisible(false);
|
|
connect(m_pluginInstallButton, &QPushButton::clicked,
|
|
this, &MainWindow::onInstallPluginTool);
|
|
buttonBar->addWidget(m_pluginInstallButton);
|
|
|
|
m_pluginToggleButton = new QPushButton("Activer");
|
|
m_pluginToggleButton->setEnabled(false);
|
|
connect(m_pluginToggleButton, &QPushButton::clicked, this, &MainWindow::onTogglePlugin);
|
|
buttonBar->addWidget(m_pluginToggleButton);
|
|
|
|
QPushButton* rescanButton = new QPushButton("Recharger");
|
|
rescanButton->setIcon(loadIcon("refresh"));
|
|
rescanButton->setToolTip("Rescanner les dossiers de plugins");
|
|
connect(rescanButton, &QPushButton::clicked, this, &MainWindow::onRescanPlugins);
|
|
buttonBar->addWidget(rescanButton);
|
|
|
|
layout->addLayout(buttonBar);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
// Maintenance page: 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.
|
|
void MainWindow::setupCleanupPage() {
|
|
QWidget* page = new QWidget();
|
|
QVBoxLayout* layout = new QVBoxLayout(page);
|
|
layout->setContentsMargins(24, 20, 24, 20);
|
|
layout->setSpacing(12);
|
|
|
|
QFrame* hintCard = makeCard();
|
|
QVBoxLayout* hintLayout = new QVBoxLayout(hintCard);
|
|
hintLayout->setContentsMargins(18, 16, 18, 16);
|
|
hintLayout->setSpacing(4);
|
|
|
|
QLabel* hintTitle = new QLabel("PAQUETS INUTILISÉS ET LEGACY");
|
|
hintTitle->setObjectName("cardTitle");
|
|
hintLayout->addWidget(hintTitle);
|
|
|
|
QLabel* hint = new QLabel(
|
|
"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: #7a8299;");
|
|
hintLayout->addWidget(hint);
|
|
|
|
layout->addWidget(hintCard);
|
|
|
|
m_cleanupTable = new QTableWidget(0, 4);
|
|
m_cleanupTable->setHorizontalHeaderLabels(
|
|
{"Paquet", "Version", "Type", "Fournisseur"});
|
|
m_cleanupTable->verticalHeader()->setVisible(false);
|
|
m_cleanupTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
m_cleanupTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
m_cleanupTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
m_cleanupTable->setShowGrid(false);
|
|
m_cleanupTable->setAlternatingRowColors(true);
|
|
m_cleanupTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
m_cleanupTable->verticalHeader()->setDefaultSectionSize(36);
|
|
m_cleanupTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
m_cleanupTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
m_cleanupTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
|
m_cleanupTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
|
connect(m_cleanupTable, &QTableWidget::currentCellChanged, this,
|
|
[this](int currentRow, int, int, int) { onCleanupSelectionChanged(currentRow); });
|
|
layout->addWidget(m_cleanupTable, 1);
|
|
|
|
QHBoxLayout* buttonBar = new QHBoxLayout();
|
|
buttonBar->setSpacing(8);
|
|
|
|
QPushButton* scanButton = new QPushButton("Analyser");
|
|
scanButton->setProperty("variant", "primary");
|
|
scanButton->setIcon(loadIcon("search"));
|
|
scanButton->setToolTip("Rechercher les paquets inutilisés et legacy");
|
|
connect(scanButton, &QPushButton::clicked, this, &MainWindow::onCleanupScan);
|
|
buttonBar->addWidget(scanButton);
|
|
|
|
m_cleanupRemoveOrphansButton = new QPushButton("Supprimer les orphelins");
|
|
m_cleanupRemoveOrphansButton->setProperty("variant", "danger");
|
|
m_cleanupRemoveOrphansButton->setIcon(loadIcon("trash"));
|
|
m_cleanupRemoveOrphansButton->setEnabled(false);
|
|
m_cleanupRemoveOrphansButton->setToolTip(
|
|
"Supprimer tous les paquets que plus rien ne requiert");
|
|
connect(m_cleanupRemoveOrphansButton, &QPushButton::clicked,
|
|
this, &MainWindow::onRemoveCleanupOrphans);
|
|
buttonBar->addWidget(m_cleanupRemoveOrphansButton);
|
|
|
|
m_cleanupRemoveSelectionButton = new QPushButton("Supprimer la sélection");
|
|
m_cleanupRemoveSelectionButton->setIcon(loadIcon("trash"));
|
|
m_cleanupRemoveSelectionButton->setEnabled(false);
|
|
connect(m_cleanupRemoveSelectionButton, &QPushButton::clicked,
|
|
this, &MainWindow::onRemoveCleanupSelection);
|
|
buttonBar->addWidget(m_cleanupRemoveSelectionButton);
|
|
|
|
m_cleanupCacheButton = new QPushButton("Vider les caches");
|
|
m_cleanupCacheButton->setProperty("variant", "warning");
|
|
m_cleanupCacheButton->setIcon(loadIcon("broom"));
|
|
m_cleanupCacheButton->setToolTip(
|
|
"Purger le cache de paquets (paccache / pacman -Sc) et les runtimes "
|
|
"Flatpak inutilisés");
|
|
connect(m_cleanupCacheButton, &QPushButton::clicked, this, &MainWindow::onCleanCaches);
|
|
buttonBar->addWidget(m_cleanupCacheButton);
|
|
|
|
buttonBar->addStretch();
|
|
|
|
m_cleanupCount = new QLabel("");
|
|
m_cleanupCount->setStyleSheet("font-size: 12px; color: #7a8299; font-weight: 600;");
|
|
buttonBar->addWidget(m_cleanupCount);
|
|
|
|
layout->addLayout(buttonBar);
|
|
|
|
m_pages->addWidget(page);
|
|
}
|
|
|
|
void MainWindow::setupMenuBar() {
|
|
QMenuBar* menuBar = this->menuBar();
|
|
menuBar->setStyleSheet(
|
|
"QMenuBar { background: #0d1017; color: #c8d3f5; padding: 2px 8px; }"
|
|
"QMenuBar::item { padding: 6px 10px; border-radius: 6px; background: transparent; }"
|
|
"QMenuBar::item:selected { background: #232b3a; }"
|
|
"QMenu {"
|
|
" background: #141927;"
|
|
" color: #dbe2f0;"
|
|
" border: 1px solid #2a3448;"
|
|
" border-radius: 8px;"
|
|
" padding: 6px;"
|
|
"}"
|
|
"QMenu::item { padding: 7px 24px 7px 14px; border-radius: 6px; }"
|
|
"QMenu::item:selected { background: #7aa2f7; color: #0d1017; }"
|
|
"QMenu::separator { height: 1px; background: #2a3448; margin: 6px 8px; }"
|
|
);
|
|
|
|
QMenu* fileMenu = menuBar->addMenu("Fichier");
|
|
fileMenu->addAction("Exporter la liste affichée...", this,
|
|
&MainWindow::onExportPackageList);
|
|
fileMenu->addAction("Exporter l'historique...", this, &MainWindow::onExportHistory);
|
|
fileMenu->addSeparator();
|
|
fileMenu->addAction("Quitter", this, &QWidget::close);
|
|
|
|
QMenu* toolsMenu = menuBar->addMenu("Outils");
|
|
toolsMenu->addAction("Tableau de bord", this,
|
|
[this]() { m_navGroup->button(NavDashboard)->click(); });
|
|
toolsMenu->addAction("Rechercher", this, [this]() {
|
|
m_navGroup->button(NavSearch)->click();
|
|
m_searchBar->setFocus();
|
|
});
|
|
toolsMenu->addAction("Paquets installés", this,
|
|
[this]() { m_navGroup->button(NavInstalled)->click(); });
|
|
toolsMenu->addAction("Mises à jour", this,
|
|
[this]() { m_navGroup->button(NavUpdates)->click(); });
|
|
toolsMenu->addAction("Nettoyage", this,
|
|
[this]() { m_navGroup->button(NavCleanup)->click(); });
|
|
toolsMenu->addAction("Historique", this,
|
|
[this]() { m_navGroup->button(NavHistory)->click(); });
|
|
toolsMenu->addAction("Logs pacman", this,
|
|
[this]() { m_navGroup->button(NavLogs)->click(); });
|
|
toolsMenu->addAction("Plugins", this,
|
|
[this]() { m_navGroup->button(NavPlugins)->click(); });
|
|
toolsMenu->addSeparator();
|
|
toolsMenu->addAction("Prévisualiser les mises à jour", this, &MainWindow::onPreviewUpdates);
|
|
toolsMenu->addAction("Rafraîchir les sources", this, &MainWindow::onRefresh);
|
|
|
|
QMenu* settingsMenu = menuBar->addMenu("Paramètres");
|
|
|
|
QActionGroup* credGroup = new QActionGroup(this);
|
|
credGroup->setExclusive(true);
|
|
|
|
QAction* credTitle = settingsMenu->addAction("Identifiants sudo");
|
|
credTitle->setEnabled(false);
|
|
|
|
m_credEachTimeAction = settingsMenu->addAction("Demander à chaque fois");
|
|
m_credEachTimeAction->setCheckable(true);
|
|
m_credEachTimeAction->setToolTip("Demande le mot de passe avant chaque opération");
|
|
credGroup->addAction(m_credEachTimeAction);
|
|
|
|
m_credLaunchAction = settingsMenu->addAction("Demander au lancement");
|
|
m_credLaunchAction->setCheckable(true);
|
|
m_credLaunchAction->setToolTip("Demande le mot de passe une seule fois, au lancement");
|
|
credGroup->addAction(m_credLaunchAction);
|
|
|
|
m_credentialMode = (m_settings.value("credentials/mode", "each").toString() == "launch")
|
|
? CredentialMode::AtLaunch
|
|
: CredentialMode::EachTime;
|
|
(m_credentialMode == CredentialMode::AtLaunch ? m_credLaunchAction
|
|
: m_credEachTimeAction)->setChecked(true);
|
|
|
|
connect(m_credEachTimeAction, &QAction::triggered, this,
|
|
[this]() { applyCredentialMode(CredentialMode::EachTime); });
|
|
connect(m_credLaunchAction, &QAction::triggered, this,
|
|
[this]() { applyCredentialMode(CredentialMode::AtLaunch); });
|
|
|
|
QMenu* helpMenu = menuBar->addMenu("Aide");
|
|
helpMenu->addAction("Vérifier les mises à jour", this, &MainWindow::onCheckForUpdates);
|
|
helpMenu->addSeparator();
|
|
helpMenu->addAction("À propos", [this]() {
|
|
QMessageBox::about(this, "PacManager",
|
|
QString("<h2>PacManager v%1</h2>"
|
|
"<p>Gestionnaire de paquets pour Arch Linux (pacman).</p>")
|
|
.arg(UpdateManager::currentVersion()));
|
|
});
|
|
}
|
|
|
|
void MainWindow::applyCredentialMode(CredentialMode mode) {
|
|
m_credentialMode = mode;
|
|
m_settings.setValue("credentials/mode",
|
|
mode == CredentialMode::AtLaunch ? "launch" : "each");
|
|
|
|
if (mode == CredentialMode::EachTime) {
|
|
// Each operation must re-authenticate: never keep the password around.
|
|
if (m_pacman) m_pacman->clearPassword();
|
|
statusBar()->showMessage("Identifiants demandés à chaque opération.");
|
|
} else {
|
|
// Per-session credentials: prompt once now so operations don't re-ask.
|
|
ensureCredentials(m_pluginManager->availableManagers());
|
|
statusBar()->showMessage("Identifiants enregistrés pour la session.");
|
|
}
|
|
}
|
|
|
|
// Makes sure a sudo password is available before a privileged operation,
|
|
// prompting the user on the UI thread when needed. Only providers that run
|
|
// through sudo (pacman) trigger the prompt. Returns false if the user
|
|
// cancelled, in which case the operation must not start.
|
|
bool MainWindow::ensureCredentials(const std::vector<IPackageManager*>& providers) {
|
|
bool needsPassword = false;
|
|
for (IPackageManager* pm : providers) {
|
|
if (pm && pm->requiresPassword()) {
|
|
needsPassword = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!needsPassword) return true;
|
|
if (!m_pacman || !m_pacman->isAvailable()) return false;
|
|
if (system("which sudo > /dev/null 2>&1") != 0) {
|
|
statusBar()->showMessage("sudo n'est pas installé sur ce système.");
|
|
return false;
|
|
}
|
|
|
|
// Per-session mode: reuse the password captured at launch.
|
|
if (m_credentialMode == CredentialMode::AtLaunch && m_pacman->hasPassword()) {
|
|
return true;
|
|
}
|
|
|
|
bool ok = false;
|
|
QString password = QInputDialog::getText(
|
|
this, "Authentification",
|
|
"Mot de passe administrateur (sudo) :",
|
|
QLineEdit::Password, QString(), &ok);
|
|
if (!ok) {
|
|
statusBar()->showMessage("Opération annulée : identifiants requis.");
|
|
return false;
|
|
}
|
|
|
|
m_pacman->setPassword(password.toStdString());
|
|
return true;
|
|
}
|
|
|
|
// Manager owning a package: the one tagged in the package, or the first
|
|
// available provider when the tag is missing or unknown.
|
|
IPackageManager* MainWindow::providerFor(const std::string& id) const {
|
|
if (const auto* entry = m_pluginManager->findAvailable(id)) {
|
|
return entry->manager;
|
|
}
|
|
auto available = m_pluginManager->availableManagers();
|
|
return available.empty() ? nullptr : available.front();
|
|
}
|
|
|
|
bool MainWindow::showProviderError(const QString& title, IPackageManager* provider) {
|
|
if (!provider) return false;
|
|
std::string err = provider->lastError();
|
|
if (err.empty()) return false;
|
|
const bool dbLock = err.find("verrouillée") != std::string::npos
|
|
|| err.find("db.lck") != std::string::npos;
|
|
if (!dbLock) {
|
|
QMessageBox::warning(this, title, QString::fromStdString(err));
|
|
return false;
|
|
}
|
|
// Locked DB: explain + offer a retry, since the other manager (or stale
|
|
// lock) is often gone by the time the user clicks again.
|
|
QMessageBox box(this);
|
|
box.setWindowTitle(title);
|
|
box.setIcon(QMessageBox::Warning);
|
|
box.setText(QString::fromStdString(err));
|
|
box.setInformativeText("Fermez l'autre gestionnaire (ou supprimez le "
|
|
"fichier résiduel indiqué), puis réessayez.");
|
|
QPushButton* retryBtn = box.addButton("Réessayer", QMessageBox::AcceptRole);
|
|
box.addButton("Fermer", QMessageBox::RejectRole);
|
|
box.exec();
|
|
if (box.clickedButton() == retryBtn && !m_pendingRetryAction.isEmpty()) {
|
|
const QString action = m_pendingRetryAction;
|
|
m_pendingRetryAction.clear();
|
|
// Defer so the dialog closes before the worker touches the UI.
|
|
QTimer::singleShot(0, this, [this, action] { retryPrivilegedAction(action); });
|
|
} else {
|
|
m_pendingRetryAction.clear();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::retryPrivilegedAction(const QString& action) {
|
|
if (action == "install" && !m_selectedPackage.name.empty()) {
|
|
m_pendingSelect = m_selectedPackage.name;
|
|
performInstall(m_selectedPackage.name);
|
|
} else if (action == "remove" && !m_selectedPackage.name.empty()) {
|
|
m_pendingSelect = m_selectedPackage.name;
|
|
performRemove(m_selectedPackage.name);
|
|
} else if (action == "update-all") {
|
|
onUpdateAll();
|
|
} else if (action == "refresh") {
|
|
onRefresh();
|
|
} else if (action == "update" && !m_selectedPackage.name.empty()) {
|
|
onUpdate();
|
|
}
|
|
}
|
|
|
|
void MainWindow::clearCredentialsAfterUse() {
|
|
// In per-operation mode the password is single-use: drop it once the
|
|
// command ran so the next operation prompts again.
|
|
if (m_credentialMode == CredentialMode::EachTime && m_pacman) {
|
|
m_pacman->clearPassword();
|
|
}
|
|
}
|
|
|
|
QFrame* MainWindow::makeCard() {
|
|
QFrame* card = new QFrame();
|
|
card->setObjectName("card");
|
|
return card;
|
|
}
|
|
|
|
QFrame* MainWindow::makeStatCard(const QString& iconName, const QString& title,
|
|
QLabel** valueOut) {
|
|
QFrame* card = makeCard();
|
|
QVBoxLayout* layout = new QVBoxLayout(card);
|
|
layout->setContentsMargins(18, 16, 18, 16);
|
|
layout->setSpacing(6);
|
|
|
|
QLabel* iconLabel = new QLabel();
|
|
iconLabel->setPixmap(iconPixmap(iconName, 24));
|
|
iconLabel->setStyleSheet("background: transparent;");
|
|
layout->addWidget(iconLabel);
|
|
|
|
QLabel* value = new QLabel("…");
|
|
value->setObjectName("statValue");
|
|
layout->addWidget(value);
|
|
|
|
QLabel* titleLabel = new QLabel(title);
|
|
titleLabel->setObjectName("statTitle");
|
|
layout->addWidget(titleLabel);
|
|
|
|
*valueOut = value;
|
|
return card;
|
|
}
|
|
|
|
void MainWindow::updatePageTitle() {
|
|
switch (m_navGroup->checkedId()) {
|
|
case NavDashboard:
|
|
m_headerTitle->setText("Tableau de bord");
|
|
m_headerSubtitle->setText("Vue d'ensemble de votre système");
|
|
break;
|
|
case NavSearch:
|
|
m_headerTitle->setText("Recherche");
|
|
m_headerSubtitle->setText("Trouvez et installez des paquets");
|
|
break;
|
|
case NavInstalled:
|
|
m_headerTitle->setText("Paquets installés");
|
|
m_headerSubtitle->setText("Parcourez les paquets de votre système");
|
|
break;
|
|
case NavUpdates:
|
|
m_headerTitle->setText("Mises à jour disponibles");
|
|
m_headerSubtitle->setText("Maintenez votre système à jour");
|
|
break;
|
|
case NavCleanup:
|
|
m_headerTitle->setText("Nettoyage");
|
|
m_headerSubtitle->setText(
|
|
"Purger les paquets inutilisés ou legacy et libérer de l'espace");
|
|
break;
|
|
case NavHistory:
|
|
m_headerTitle->setText("Historique");
|
|
m_headerSubtitle->setText("Journal de toutes vos actions");
|
|
break;
|
|
case NavLogs:
|
|
m_headerTitle->setText("Logs pacman");
|
|
m_headerSubtitle->setText("Journal brut du gestionnaire de paquets");
|
|
break;
|
|
case NavPlugins:
|
|
m_headerTitle->setText("Plugins");
|
|
m_headerSubtitle->setText("Gestionnaires de paquets et extensions");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MainWindow::onNavChanged(int id) {
|
|
qCDebug(pacmgrUi) << "navigate to page" << id;
|
|
updatePageTitle();
|
|
|
|
switch (id) {
|
|
case NavDashboard:
|
|
m_pages->setCurrentIndex(PageDashboard);
|
|
refreshDashboard();
|
|
break;
|
|
case NavSearch:
|
|
setBrowseMode(ModeSearch);
|
|
m_searchBar->setFocus();
|
|
break;
|
|
case NavInstalled:
|
|
setBrowseMode(ModeInstalled);
|
|
loadInstalled();
|
|
break;
|
|
case NavUpdates:
|
|
setBrowseMode(ModeUpdates);
|
|
loadUpdates();
|
|
break;
|
|
case NavCleanup:
|
|
m_pages->setCurrentIndex(PageCleanup);
|
|
loadCleanup();
|
|
break;
|
|
case NavHistory:
|
|
m_pages->setCurrentIndex(PageHistory);
|
|
refreshHistoryTable();
|
|
break;
|
|
case NavLogs:
|
|
m_pages->setCurrentIndex(PageLogs);
|
|
loadLogs();
|
|
break;
|
|
case NavPlugins:
|
|
m_pages->setCurrentIndex(PagePlugins);
|
|
refreshPluginsTable();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void MainWindow::setBrowseMode(BrowseMode mode) {
|
|
m_browseMode = mode;
|
|
m_pages->setCurrentIndex(PageBrowse);
|
|
|
|
m_searchRowWidget->setVisible(mode == ModeSearch);
|
|
m_filterRowWidget->setVisible(mode == ModeInstalled);
|
|
m_installButton->setVisible(mode == ModeSearch);
|
|
|
|
// Clear any stale selection and reset the details panel
|
|
m_packageTable->clearSelection();
|
|
resetDetailsPanel();
|
|
}
|
|
|
|
void MainWindow::resetDetailsPanel() {
|
|
m_packageName->setText("Sélectionnez un paquet");
|
|
m_packageVersion->setText("");
|
|
m_packageRepo->setText("—");
|
|
m_packageSize->setText("—");
|
|
m_packageProvider->setText("—");
|
|
m_packageDescription->setText("");
|
|
m_installButton->setEnabled(false);
|
|
m_removeButton->setEnabled(false);
|
|
m_updateButton->setEnabled(false);
|
|
}
|
|
|
|
void MainWindow::onSearch() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible.");
|
|
return;
|
|
}
|
|
|
|
std::string query = m_searchBar->text().toStdString();
|
|
if (query.empty()) {
|
|
// Refocus the search field instead of interrupting with a dialog.
|
|
m_searchBar->setFocus();
|
|
statusBar()->showMessage("Entrez un terme de recherche.");
|
|
return;
|
|
}
|
|
|
|
setBusy(true);
|
|
statusBar()->showMessage("Recherche en cours...");
|
|
m_packageTable->setRowCount(0);
|
|
|
|
SearchWorker* worker = new SearchWorker(providers, query);
|
|
connect(worker, &SearchWorker::chunk, this, &MainWindow::onSearchChunk);
|
|
connect(worker, &SearchWorker::finished, this, &MainWindow::onSearchFinished);
|
|
connect(worker, &SearchWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
// Called as results stream in: append the incoming row instead of rebuilding
|
|
// the whole table, so the first matches appear while the search continues.
|
|
void MainWindow::onSearchChunk(std::vector<PackageInfo> results) {
|
|
appendPackageRows(results);
|
|
}
|
|
|
|
void MainWindow::loadInstalled() {
|
|
setBusy(true);
|
|
statusBar()->showMessage("Chargement des paquets installés...");
|
|
m_packageTable->setRowCount(0);
|
|
|
|
ListWorker* worker = new ListWorker(m_pluginManager->availableManagers(),
|
|
ListWorker::Installed);
|
|
connect(worker, &ListWorker::finished, this, &MainWindow::onListFinished);
|
|
connect(worker, &ListWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::loadUpdates() {
|
|
setBusy(true);
|
|
statusBar()->showMessage("Recherche des mises à jour...");
|
|
m_packageTable->setRowCount(0);
|
|
|
|
ListWorker* worker = new ListWorker(m_pluginManager->availableManagers(),
|
|
ListWorker::Updates);
|
|
connect(worker, &ListWorker::finished, this, &MainWindow::onListFinished);
|
|
connect(worker, &ListWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onSearchFinished(std::vector<PackageInfo> results) {
|
|
setBusy(false);
|
|
// The table is already filled incrementally via onSearchChunk; rebuild it
|
|
// once at the end to guarantee a consistent final list.
|
|
populatePackageTable(results);
|
|
statusBar()->showMessage(QString("%1 paquet(s) trouvé(s)").arg(results.size()));
|
|
}
|
|
|
|
void MainWindow::onListFinished(std::vector<PackageInfo> results) {
|
|
setBusy(false);
|
|
|
|
if (m_browseMode == ModeInstalled) {
|
|
m_installedPackages = results;
|
|
// Re-apply the current filter text on the freshly loaded list
|
|
onInstalledFilterChanged(m_filterBar->text());
|
|
statusBar()->showMessage(QString("%1 paquet(s) installé(s)").arg(results.size()));
|
|
} else if (m_browseMode == ModeUpdates) {
|
|
populatePackageTable(results);
|
|
statusBar()->showMessage(
|
|
QString("%1 mise(s) à jour disponible(s)").arg(results.size()));
|
|
}
|
|
}
|
|
|
|
void MainWindow::onInstalledFilterChanged(const QString& text) {
|
|
if (m_browseMode != ModeInstalled) return;
|
|
|
|
std::vector<PackageInfo> filtered;
|
|
if (text.isEmpty()) {
|
|
filtered = m_installedPackages;
|
|
} else {
|
|
QString needle = text.toLower();
|
|
for (const auto& pkg : m_installedPackages) {
|
|
if (QString::fromStdString(pkg.name).toLower().contains(needle)) {
|
|
filtered.push_back(pkg);
|
|
}
|
|
}
|
|
}
|
|
populatePackageTable(filtered);
|
|
}
|
|
|
|
// Navigates to the Installed page and opens the clicked package's details
|
|
// (with remove / update actions available) by selecting it in the list.
|
|
void MainWindow::onRecentActivityClicked(QListWidgetItem* item) {
|
|
if (!item) return;
|
|
|
|
QString name = item->data(Qt::UserRole).toString();
|
|
if (name.isEmpty()) return;
|
|
|
|
m_pendingSelect = name.toStdString();
|
|
m_navGroup->button(NavInstalled)->click(); // Installed page -> loadInstalled() runs
|
|
statusBar()->showMessage(
|
|
QString("Ouverture des détails de %1...").arg(name));
|
|
}
|
|
|
|
void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
|
|
m_currentResults = results;
|
|
m_packageTable->setRowCount(0);
|
|
m_packageTable->setRowCount(static_cast<int>(results.size()));
|
|
|
|
for (int i = 0; i < static_cast<int>(results.size()); ++i) {
|
|
addPackageRow(i, results[i]);
|
|
}
|
|
|
|
m_resultCount->setText(QString("%1 paquet(s)").arg(results.size()));
|
|
|
|
if (results.empty()) {
|
|
resetDetailsPanel();
|
|
return;
|
|
}
|
|
|
|
// If we navigated here from the dashboard for a specific package, select it.
|
|
if (!m_pendingSelect.empty()) {
|
|
std::string target = m_pendingSelect;
|
|
m_pendingSelect.clear();
|
|
for (int i = 0; i < static_cast<int>(m_currentResults.size()); ++i) {
|
|
if (m_currentResults[i].name == target) {
|
|
m_packageTable->selectRow(i);
|
|
onPackageSelected(i); // ensure the detail panel updates immediately
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
m_packageTable->selectRow(0);
|
|
}
|
|
|
|
// Appends an incoming search chunk to the already-displayed rows, updating the
|
|
// stored result set so selection and the details panel stay consistent.
|
|
void MainWindow::appendPackageRows(const std::vector<PackageInfo>& results) {
|
|
const int startRow = static_cast<int>(m_currentResults.size());
|
|
m_currentResults.insert(m_currentResults.end(), results.begin(), results.end());
|
|
m_packageTable->setRowCount(static_cast<int>(m_currentResults.size()));
|
|
|
|
for (size_t i = 0; i < results.size(); ++i) {
|
|
addPackageRow(startRow + static_cast<int>(i), results[i]);
|
|
}
|
|
m_resultCount->setText(QString("%1 paquet(s)").arg(m_currentResults.size()));
|
|
}
|
|
|
|
void MainWindow::addPackageRow(int i, const PackageInfo& pkg) {
|
|
QFont nameFont;
|
|
nameFont.setWeight(QFont::DemiBold);
|
|
|
|
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(pkg.name));
|
|
nameItem->setFont(nameFont);
|
|
m_packageTable->setItem(i, 0, nameItem);
|
|
|
|
m_packageTable->setItem(i, 1,
|
|
new QTableWidgetItem(QString::fromStdString(pkg.version)));
|
|
|
|
m_packageTable->setItem(i, 2, new QTableWidgetItem(
|
|
pkg.repository.empty() ? "—" : QString::fromStdString(pkg.repository)));
|
|
|
|
QTableWidgetItem* providerItem = new QTableWidgetItem(
|
|
providersLabel(m_pluginManager, pkg));
|
|
providerItem->setForeground(QColor("#98a0b3"));
|
|
providerItem->setIcon(loadIcon("package"));
|
|
m_packageTable->setItem(i, 3, providerItem);
|
|
|
|
QString statusText;
|
|
QString statusIcon;
|
|
QColor statusColor;
|
|
if (pkg.installed && pkg.updateAvailable) {
|
|
statusText = "MAJ dispo";
|
|
statusIcon = "arrow-up";
|
|
statusColor = QColor("#e0af68");
|
|
} else if (pkg.installed) {
|
|
statusText = "Installé";
|
|
statusIcon = "check";
|
|
statusColor = QColor("#3fb950");
|
|
} else if (!pkg.repository.empty()) {
|
|
statusText = "Disponible";
|
|
statusIcon = "package";
|
|
statusColor = QColor("#98a0b3");
|
|
} else {
|
|
statusText = "—";
|
|
statusIcon.clear();
|
|
statusColor = QColor("#565f73");
|
|
}
|
|
|
|
QTableWidgetItem* statusItem = new QTableWidgetItem(statusText);
|
|
statusItem->setForeground(statusColor);
|
|
if (!statusIcon.isEmpty()) statusItem->setIcon(loadIcon(statusIcon));
|
|
m_packageTable->setItem(i, 4, statusItem);
|
|
}
|
|
|
|
void MainWindow::onPackageSelected(int row) {
|
|
if (row < 0 || row >= static_cast<int>(m_currentResults.size())) {
|
|
resetDetailsPanel();
|
|
return;
|
|
}
|
|
|
|
m_selectedPackage = m_currentResults[row];
|
|
updatePackageInfo(m_selectedPackage);
|
|
|
|
IPackageManager* provider = providerFor(m_selectedPackage.provider);
|
|
|
|
m_installButton->setEnabled(
|
|
m_browseMode == ModeSearch
|
|
&& provider && provider->canInstall()
|
|
&& !m_selectedPackage.installed);
|
|
m_removeButton->setEnabled(
|
|
provider && provider->canRemove()
|
|
&& m_selectedPackage.installed);
|
|
m_updateButton->setEnabled(
|
|
provider && provider->canUpdate()
|
|
&& m_selectedPackage.updateAvailable);
|
|
}
|
|
|
|
void MainWindow::updatePackageInfo(const PackageInfo& pkg) {
|
|
m_packageName->setText(QString::fromStdString(pkg.name));
|
|
|
|
QString versionText = QString("Version : %1").arg(QString::fromStdString(pkg.version));
|
|
if (pkg.updateAvailable) {
|
|
versionText += " (mise à jour disponible)";
|
|
}
|
|
m_packageVersion->setText(versionText);
|
|
|
|
m_packageRepo->setText(pkg.repository.empty()
|
|
? "Dépôt : —"
|
|
: QString("Dépôt : %1").arg(QString::fromStdString(pkg.repository)));
|
|
m_packageSize->setText(pkg.size.empty()
|
|
? "Taille : —"
|
|
: QString("Taille : %1").arg(QString::fromStdString(pkg.size)));
|
|
m_packageProvider->setText(
|
|
QString("Fournisseur : %1").arg(providersLabel(m_pluginManager, pkg)));
|
|
|
|
// Rich details: dependencies, required-by, install date (pacman), update
|
|
// size estimate for pending updates. Loaded on demand so selecting a row
|
|
// stays instant even when pacman is slow.
|
|
QString details = QString::fromStdString(pkg.description);
|
|
const std::string rich = m_pacman ? richDetails(pkg) : std::string();
|
|
if (!rich.empty()) {
|
|
if (!details.isEmpty()) details += "\n\n";
|
|
details += QString::fromStdString(rich);
|
|
}
|
|
m_packageDescription->setText(details);
|
|
}
|
|
|
|
// Runs the read-only pacman queries backing the details panel. Kept
|
|
// synchronous: -Qi/-Si answer in milliseconds and the panel already updated
|
|
// the basics above, so no worker thread is worth the complexity.
|
|
std::string MainWindow::richDetails(const PackageInfo& pkg) {
|
|
if (!m_pacman || !m_pacman->isAvailable()) return {};
|
|
|
|
// Cache per name+provider+version+installed: selecting a row repeatedly (or
|
|
// arrowing through the table) must not re-spawn pacman every time.
|
|
const QString key = QStringLiteral("%1|%2|%3|%4")
|
|
.arg(QString::fromStdString(pkg.name),
|
|
QString::fromStdString(pkg.provider),
|
|
QString::fromStdString(pkg.version))
|
|
.arg(pkg.installed ? 1 : 0);
|
|
const auto cached = m_detailsCache.constFind(key);
|
|
if (cached != m_detailsCache.constEnd()) return cached.value();
|
|
|
|
auto run = [](const std::string& cmd) {
|
|
std::array<char, 4096> buf{};
|
|
std::string out;
|
|
std::unique_ptr<FILE, PipeCloser> pipe(popen(cmd.c_str(), "r"));
|
|
if (!pipe) return out;
|
|
while (fgets(buf.data(), buf.size(), pipe.get())) out += buf.data();
|
|
return out;
|
|
};
|
|
auto field = [&](const std::string& out, const std::string& name) {
|
|
std::istringstream iss(out);
|
|
std::string line;
|
|
while (std::getline(iss, line)) {
|
|
size_t colon = line.find(':');
|
|
if (colon == std::string::npos) continue;
|
|
std::string key = line.substr(0, colon);
|
|
while (!key.empty() && key.back() == ' ') key.pop_back();
|
|
if (key != name) continue;
|
|
std::string val = line.substr(colon + 1);
|
|
size_t start = val.find_first_not_of(" \t");
|
|
if (start != std::string::npos) val = val.substr(start);
|
|
while (!val.empty() && (val.back() == '\n' || val.back() == '\r' || val.back() == ' '))
|
|
val.pop_back();
|
|
return val;
|
|
}
|
|
return std::string();
|
|
};
|
|
|
|
const bool isPacmanPkg = pkg.provider == "pacman" || pkg.provider.empty();
|
|
const std::string q = pkg.provider == "aur" ? "yay -Qi " : "pacman -Qi ";
|
|
const std::string s = pkg.provider == "aur" ? "yay -Si " : "pacman -Si ";
|
|
std::string installed = run(q + pkg.name + " 2>/dev/null");
|
|
if (installed.empty() && isPacmanPkg) installed = run("pacman -Qi " + pkg.name + " 2>/dev/null");
|
|
|
|
std::string out;
|
|
auto addRow = [&](const char* label, const std::string& val) {
|
|
if (val.empty() || val == "None" || val == "--") return;
|
|
if (!out.empty()) out += "\n";
|
|
out += std::string(label) + " : " + val;
|
|
};
|
|
if (!installed.empty()) {
|
|
addRow("Taille installée", field(installed, "Installed Size"));
|
|
addRow("Date d'installation", field(installed, "Install Date"));
|
|
addRow("Dépend de", field(installed, "Depends On"));
|
|
addRow("Requis par", field(installed, "Required By"));
|
|
} else {
|
|
// Only query the sync database when the package is not installed here,
|
|
// halving the subprocess count on the Installed/Updates pages.
|
|
const std::string sync = run(s + pkg.name + " 2>/dev/null");
|
|
if (!sync.empty()) {
|
|
addRow("Taille du téléchargement", field(sync, "Download Size"));
|
|
addRow("Taille installée", field(sync, "Installed Size"));
|
|
addRow("Dépend de", field(sync, "Depends On"));
|
|
}
|
|
}
|
|
|
|
// Bound the cache so a long browsing session cannot grow it forever.
|
|
if (m_detailsCache.size() > 512) m_detailsCache.clear();
|
|
m_detailsCache.insert(key, out);
|
|
return out;
|
|
}
|
|
|
|
void MainWindow::onInstall() {
|
|
if (m_selectedPackage.name.empty()) return;
|
|
performInstall(m_selectedPackage.name);
|
|
}
|
|
|
|
void MainWindow::onRemove() {
|
|
if (m_selectedPackage.name.empty()) return;
|
|
performRemove(m_selectedPackage.name);
|
|
}
|
|
|
|
void MainWindow::onUpdate() {
|
|
if (m_selectedPackage.name.empty()) return;
|
|
|
|
IPackageManager* provider = providerFor(m_selectedPackage.provider);
|
|
if (!provider || !provider->canUpdate()) return;
|
|
if (!tryAcquireOp()) return;
|
|
m_pendingRetryAction = "update";
|
|
if (!ensureCredentials({provider})) {
|
|
setBusy(false);
|
|
m_pendingRetryAction.clear();
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage(
|
|
QString("Mise à jour de %1...").arg(QString::fromStdString(m_selectedPackage.name)));
|
|
|
|
auto* worker = new InstallWorker(provider, InstallWorker::Op::Update, m_selectedPackage.name);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage("Mise à jour terminée");
|
|
} else {
|
|
statusBar()->showMessage("Échec de la mise à jour");
|
|
showProviderError("Échec de la mise à jour", provider);
|
|
}
|
|
m_historyManager->record({"", "update", m_selectedPackage.name,
|
|
provider->getName(), success});
|
|
clearCredentialsAfterUse();
|
|
reloadCurrentView();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onUpdateAll() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible.");
|
|
return;
|
|
}
|
|
if (!tryAcquireOp()) return;
|
|
m_pendingRetryAction = "update-all";
|
|
if (!ensureCredentials(providers)) {
|
|
setBusy(false);
|
|
m_pendingRetryAction.clear();
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage("Mise à jour de tous les paquets...");
|
|
|
|
auto* worker = new InstallWorker(providers, InstallWorker::Op::UpdateAll);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, providers](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage("Tous les paquets sont à jour");
|
|
} else {
|
|
statusBar()->showMessage("Erreur lors de la mise à jour globale");
|
|
for (IPackageManager* pm : providers) {
|
|
if (!pm->lastError().empty()) {
|
|
// showProviderError offers a retry for db-lock errors.
|
|
showProviderError("Erreur lors de la mise à jour globale", pm);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
clearCredentialsAfterUse();
|
|
reloadCurrentView();
|
|
refreshDashboard();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onRefresh() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible.");
|
|
return;
|
|
}
|
|
if (!tryAcquireOp()) return;
|
|
m_pendingRetryAction = "refresh";
|
|
if (!ensureCredentials(providers)) {
|
|
setBusy(false);
|
|
m_pendingRetryAction.clear();
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage("Rafraîchissement des sources...");
|
|
|
|
auto* worker = new InstallWorker(providers, InstallWorker::Op::Refresh);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, providers](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage("Sources rafraîchies");
|
|
} else {
|
|
statusBar()->showMessage("Erreur lors du rafraîchissement");
|
|
for (IPackageManager* pm : providers) {
|
|
if (!pm->lastError().empty()) {
|
|
showProviderError("Erreur lors du rafraîchissement", pm);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
clearCredentialsAfterUse();
|
|
refreshDashboard();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onCleanupScan() {
|
|
loadCleanup();
|
|
}
|
|
|
|
void MainWindow::loadCleanup() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible.");
|
|
return;
|
|
}
|
|
|
|
setBusy(true);
|
|
statusBar()->showMessage("Analyse des paquets inutilisés et legacy...");
|
|
m_cleanupTable->setRowCount(0);
|
|
m_cleanupCandidates.clear();
|
|
m_cleanupRemoveOrphansButton->setEnabled(false);
|
|
m_cleanupRemoveSelectionButton->setEnabled(false);
|
|
|
|
auto* worker = new ListWorker(providers, ListWorker::Cleanup);
|
|
connect(worker, &ListWorker::finished, this, &MainWindow::onCleanupListFinished);
|
|
connect(worker, &ListWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onCleanupListFinished(std::vector<PackageInfo> results) {
|
|
setBusy(false);
|
|
populateCleanupTable(results);
|
|
|
|
int orphans = 0;
|
|
for (const auto& pkg : results) {
|
|
if (pkg.orphan) ++orphans;
|
|
}
|
|
statusBar()->showMessage(
|
|
QString("%1 orphelin(s) et %2 paquet(s) legacy détecté(s)")
|
|
.arg(orphans).arg(static_cast<int>(results.size()) - orphans));
|
|
}
|
|
|
|
void MainWindow::populateCleanupTable(const std::vector<PackageInfo>& candidates) {
|
|
m_cleanupCandidates = candidates;
|
|
m_cleanupTable->setRowCount(0);
|
|
m_cleanupTable->setRowCount(static_cast<int>(candidates.size()));
|
|
|
|
QFont nameFont;
|
|
nameFont.setWeight(QFont::DemiBold);
|
|
|
|
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_cleanupTable->setItem(i, 0, nameItem);
|
|
|
|
m_cleanupTable->setItem(i, 1,
|
|
new QTableWidgetItem(QString::fromStdString(pkg.version)));
|
|
|
|
QTableWidgetItem* typeItem =
|
|
new QTableWidgetItem(QString::fromStdString(pkg.cleanupReason));
|
|
typeItem->setForeground(QColor(pkg.orphan ? "#e0af68" : "#7a8299"));
|
|
typeItem->setIcon(loadIcon(pkg.orphan ? "alert" : "package"));
|
|
m_cleanupTable->setItem(i, 2, typeItem);
|
|
|
|
m_cleanupTable->setItem(i, 3,
|
|
new QTableWidgetItem(providersLabel(m_pluginManager, pkg)));
|
|
}
|
|
|
|
m_cleanupCount->setText(QString("%1 orphelin(s) · %2 legacy")
|
|
.arg(orphans).arg(static_cast<int>(candidates.size()) - orphans));
|
|
m_cleanupRemoveOrphansButton->setEnabled(orphans > 0);
|
|
m_cleanupRemoveOrphansButton->setText(orphans > 0
|
|
? QString("Supprimer les orphelins (%1)").arg(orphans)
|
|
: QString("Supprimer les orphelins"));
|
|
|
|
if (!candidates.empty()) m_cleanupTable->selectRow(0);
|
|
onCleanupSelectionChanged(m_cleanupTable->currentRow());
|
|
}
|
|
|
|
void MainWindow::onCleanupSelectionChanged(int row) {
|
|
if (row < 0 || row >= static_cast<int>(m_cleanupCandidates.size())) {
|
|
m_cleanupRemoveSelectionButton->setEnabled(false);
|
|
m_cleanupRemoveSelectionButton->setToolTip(QString());
|
|
return;
|
|
}
|
|
|
|
const PackageInfo& pkg = m_cleanupCandidates[row];
|
|
const QString name = QString::fromStdString(pkg.name);
|
|
m_cleanupRemoveSelectionButton->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_cleanupRemoveSelectionButton->setToolTip(
|
|
pkg.orphan
|
|
? QString("Supprimer « %1 » (orphelin)").arg(name)
|
|
: QString("Supprimer « %1 » (%2) — à vérifier : rien ne prouve "
|
|
"qu'il est inutilisé")
|
|
.arg(name, QString::fromStdString(pkg.cleanupReason)));
|
|
}
|
|
|
|
void MainWindow::onRemoveCleanupOrphans() {
|
|
std::vector<PackageInfo> orphans;
|
|
for (const auto& pkg : m_cleanupCandidates) {
|
|
if (pkg.orphan) orphans.push_back(pkg);
|
|
}
|
|
if (orphans.empty()) {
|
|
statusBar()->showMessage("Aucun orphelin à supprimer.");
|
|
return;
|
|
}
|
|
removeCleanupPackages(orphans, QString("%1 orphelin(s)").arg(orphans.size()));
|
|
}
|
|
|
|
void MainWindow::onRemoveCleanupSelection() {
|
|
const int row = m_cleanupTable->currentRow();
|
|
if (row < 0 || row >= static_cast<int>(m_cleanupCandidates.size())) return;
|
|
|
|
// Copied: the candidate list is rebuilt once the removal completes.
|
|
const PackageInfo pkg = m_cleanupCandidates[row];
|
|
removeCleanupPackages({pkg},
|
|
QString("« %1 »").arg(QString::fromStdString(pkg.name)));
|
|
}
|
|
|
|
// Groups the candidates per provider (each provider then gets a single removal
|
|
// command), confirms once, and hands over to the sequential runner below.
|
|
void MainWindow::removeCleanupPackages(const std::vector<PackageInfo>& packages,
|
|
const QString& description) {
|
|
m_pendingRemovals.clear();
|
|
for (const auto& pkg : packages) {
|
|
IPackageManager* provider = providerFor(pkg.provider);
|
|
if (!provider || !provider->canRemove()) continue;
|
|
|
|
auto group = std::find_if(
|
|
m_pendingRemovals.begin(), m_pendingRemovals.end(),
|
|
[provider](const auto& entry) { return entry.first == provider; });
|
|
if (group == m_pendingRemovals.end()) {
|
|
m_pendingRemovals.push_back({provider, {pkg.name}});
|
|
} else {
|
|
group->second.push_back(pkg.name);
|
|
}
|
|
}
|
|
|
|
if (m_pendingRemovals.empty()) {
|
|
statusBar()->showMessage("Aucun paquet sélectionné n'est supprimable.");
|
|
return;
|
|
}
|
|
|
|
if (QMessageBox::question(this, "Nettoyage",
|
|
QString("Supprimer %1 ?\n\nCette action est irréversible.")
|
|
.arg(description)) != QMessageBox::Yes) {
|
|
m_pendingRemovals.clear();
|
|
return;
|
|
}
|
|
|
|
std::vector<IPackageManager*> providers;
|
|
for (const auto& entry : m_pendingRemovals) providers.push_back(entry.first);
|
|
|
|
if (!tryAcquireOp()) {
|
|
m_pendingRemovals.clear();
|
|
return;
|
|
}
|
|
if (!ensureCredentials(providers)) {
|
|
setBusy(false);
|
|
m_pendingRemovals.clear();
|
|
return;
|
|
}
|
|
|
|
startNextCleanupRemoval();
|
|
}
|
|
|
|
// Removes the next provider's group of packages, then chains into the
|
|
// following one. Two removals never run at once: pacman locks its database for
|
|
// the whole operation.
|
|
void MainWindow::startNextCleanupRemoval() {
|
|
if (m_pendingRemovals.empty()) {
|
|
setBusy(false);
|
|
clearCredentialsAfterUse();
|
|
m_detailsCache.clear();
|
|
loadCleanup();
|
|
refreshDashboard();
|
|
return;
|
|
}
|
|
|
|
const auto job = m_pendingRemovals.front();
|
|
m_pendingRemovals.erase(m_pendingRemovals.begin());
|
|
IPackageManager* provider = job.first;
|
|
const std::vector<std::string> packages = job.second;
|
|
|
|
statusBar()->showMessage(
|
|
QString("Suppression de %1 paquet(s)...").arg(packages.size()));
|
|
|
|
auto* worker = new InstallWorker(provider, InstallWorker::Op::RemovePackages, packages);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this,
|
|
[this, provider, packages](bool success) {
|
|
if (success) {
|
|
statusBar()->showMessage(
|
|
QString("%1 paquet(s) supprimé(s)").arg(packages.size()));
|
|
} else {
|
|
statusBar()->showMessage("Échec du nettoyage");
|
|
showProviderError("Échec du nettoyage", provider);
|
|
}
|
|
// One history row per removed package keeps the install/remove filters
|
|
// of the History page meaningful.
|
|
for (const auto& name : packages) {
|
|
m_historyManager->record({"", "remove", name, provider->getName(), success});
|
|
}
|
|
startNextCleanupRemoval();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onCleanCaches() {
|
|
std::vector<IPackageManager*> providers;
|
|
QStringList names;
|
|
for (IPackageManager* pm : m_pluginManager->availableManagers()) {
|
|
if (!pm->canCleanCache()) continue;
|
|
providers.push_back(pm);
|
|
names << QString::fromStdString(pm->getName());
|
|
}
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun cache à nettoyer sur ce système.");
|
|
return;
|
|
}
|
|
|
|
if (QMessageBox::question(this, "Nettoyage",
|
|
QString("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;
|
|
}
|
|
|
|
if (!tryAcquireOp()) return;
|
|
if (!ensureCredentials(providers)) {
|
|
setBusy(false);
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage("Nettoyage des caches...");
|
|
|
|
auto* worker = new InstallWorker(providers, InstallWorker::Op::CleanCache);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, providers](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage("Caches nettoyés");
|
|
} else {
|
|
statusBar()->showMessage("Échec du nettoyage des caches");
|
|
for (IPackageManager* pm : providers) {
|
|
if (!pm->lastError().empty()) {
|
|
showProviderError("Échec du nettoyage des caches", pm);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
for (IPackageManager* pm : providers) {
|
|
m_historyManager->record({"", "cleanup", "caches", pm->getName(), success});
|
|
}
|
|
clearCredentialsAfterUse();
|
|
refreshDashboard();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::performInstall(const std::string& package) {
|
|
IPackageManager* provider = providerFor(m_selectedPackage.provider);
|
|
if (!provider || !provider->canInstall()) return;
|
|
qCInfo(pacmgrOp) << "install" << QString::fromStdString(package)
|
|
<< "via" << QString::fromStdString(provider->getName());
|
|
if (!tryAcquireOp()) return;
|
|
m_pendingRetryAction = "install";
|
|
if (!ensureCredentials({provider})) {
|
|
setBusy(false);
|
|
m_pendingRetryAction.clear();
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage(
|
|
QString("Installation de %1...").arg(QString::fromStdString(package)));
|
|
|
|
auto* worker = new InstallWorker(provider, InstallWorker::Op::Install, package);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage(
|
|
QString("%1 installé avec succès").arg(
|
|
QString::fromStdString(m_selectedPackage.name)));
|
|
} else {
|
|
statusBar()->showMessage(
|
|
QString("Échec de l'installation de %1").arg(
|
|
QString::fromStdString(m_selectedPackage.name)));
|
|
showProviderError("Échec de l'installation", provider);
|
|
}
|
|
m_historyManager->record({"", "install", m_selectedPackage.name,
|
|
provider->getName(), success});
|
|
clearCredentialsAfterUse();
|
|
reloadCurrentView();
|
|
refreshDashboard();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::performRemove(const std::string& package) {
|
|
IPackageManager* provider = providerFor(m_selectedPackage.provider);
|
|
if (!provider || !provider->canRemove()) return;
|
|
qCInfo(pacmgrOp) << "remove" << QString::fromStdString(package)
|
|
<< "via" << QString::fromStdString(provider->getName());
|
|
if (!tryAcquireOp()) return;
|
|
m_pendingRetryAction = "remove";
|
|
if (!ensureCredentials({provider})) {
|
|
setBusy(false);
|
|
m_pendingRetryAction.clear();
|
|
return;
|
|
}
|
|
|
|
statusBar()->showMessage(
|
|
QString("Suppression de %1...").arg(QString::fromStdString(package)));
|
|
|
|
auto* worker = new InstallWorker(provider, InstallWorker::Op::Remove, package);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, provider](bool success) {
|
|
setBusy(false);
|
|
if (success) {
|
|
statusBar()->showMessage(
|
|
QString("%1 supprimé avec succès").arg(
|
|
QString::fromStdString(m_selectedPackage.name)));
|
|
} else {
|
|
statusBar()->showMessage(
|
|
QString("Échec de la suppression de %1").arg(
|
|
QString::fromStdString(m_selectedPackage.name)));
|
|
showProviderError("Échec de la suppression", provider);
|
|
}
|
|
m_historyManager->record({"", "remove", m_selectedPackage.name,
|
|
provider->getName(), success});
|
|
clearCredentialsAfterUse();
|
|
reloadCurrentView();
|
|
refreshDashboard();
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::reloadCurrentView() {
|
|
// Installed state changed: drop the cached pacman details so the panel
|
|
// shows the fresh size/date after an install/remove/update.
|
|
m_detailsCache.clear();
|
|
if (m_browseMode == ModeInstalled) {
|
|
loadInstalled();
|
|
} else if (m_browseMode == ModeUpdates) {
|
|
loadUpdates();
|
|
} else if (!m_searchBar->text().isEmpty()) {
|
|
onSearch();
|
|
}
|
|
}
|
|
|
|
void MainWindow::setBusy(bool busy) {
|
|
m_busy = busy;
|
|
m_progressBar->setVisible(busy);
|
|
m_installProgressBar->setVisible(busy);
|
|
if (busy) {
|
|
// Start indeterminate; a real percentage (onInstallProgress) switches
|
|
// the bottom bar to a determinate fill once the tool reports progress.
|
|
m_progressBar->setRange(0, 0);
|
|
m_progressBar->setValue(0);
|
|
m_installProgressBar->setRange(0, 0);
|
|
m_installProgressBar->setValue(0);
|
|
}
|
|
}
|
|
|
|
// Single privileged pacman operation at a time: pacman locks its DB
|
|
// (/var/lib/pacman/db.lck), so a second concurrent op would fail with
|
|
// "verrouillage de la base de données impossible".
|
|
bool MainWindow::tryAcquireOp() {
|
|
if (m_busy) {
|
|
statusBar()->showMessage("Une opération est déjà en cours, patientez...");
|
|
return false;
|
|
}
|
|
setBusy(true);
|
|
return true;
|
|
}
|
|
|
|
// A real download percentage reported by the provider fills the bottom bar as
|
|
// a determinate progress. -1 (unknown) leaves the bar in its previous state.
|
|
void MainWindow::onInstallProgress(int percent) {
|
|
if (percent < 0) return;
|
|
m_installProgressBar->setVisible(true);
|
|
m_installProgressBar->setRange(0, 100);
|
|
m_installProgressBar->setValue(percent);
|
|
}
|
|
|
|
void MainWindow::refreshHistoryTable() {
|
|
const auto& all = m_historyManager->getHistory();
|
|
|
|
std::vector<HistoryEntry> entries;
|
|
int filter = m_historyFilter->currentIndex();
|
|
for (const auto& entry : all) {
|
|
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_historyCount->setText(QString("%1 action(s)").arg(entries.size()));
|
|
m_historyTable->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_historyTable->setItem(i, 0,
|
|
new QTableWidgetItem(QString::fromStdString(entry.timestamp)));
|
|
m_historyTable->setItem(i, 1, new QTableWidgetItem(actionText));
|
|
m_historyTable->item(i, 1)->setForeground(QColor(actionColor));
|
|
m_historyTable->setItem(i, 2,
|
|
new QTableWidgetItem(QString::fromStdString(entry.package)));
|
|
m_historyTable->setItem(i, 3,
|
|
new QTableWidgetItem(QString::fromStdString(entry.plugin)));
|
|
QTableWidgetItem* statusItem =
|
|
new QTableWidgetItem(entry.success ? "Succès" : "Échec");
|
|
statusItem->setIcon(loadIcon(entry.success ? "check" : "close"));
|
|
m_historyTable->setItem(i, 4, statusItem);
|
|
}
|
|
}
|
|
|
|
void MainWindow::onHistoryFilterChanged() {
|
|
refreshHistoryTable();
|
|
}
|
|
|
|
void MainWindow::onClearHistory() {
|
|
m_historyManager->clear();
|
|
refreshHistoryTable();
|
|
refreshDashboard();
|
|
statusBar()->showMessage("Historique effacé");
|
|
}
|
|
|
|
void MainWindow::loadLogs() {
|
|
const QString logPath = "/var/log/pacman.log";
|
|
|
|
QFile logFile(logPath);
|
|
if (!logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
m_logsRaw.clear();
|
|
m_logsText->setPlainText(
|
|
QString("Impossible d'ouvrir %1.\n"
|
|
"Vérifiez que le fichier existe et que vous avez les droits de lecture.")
|
|
.arg(logPath));
|
|
return;
|
|
}
|
|
|
|
m_logsRaw = QString::fromUtf8(logFile.readAll());
|
|
applyLogsFilter();
|
|
}
|
|
|
|
void MainWindow::onLogsFilterChanged() {
|
|
applyLogsFilter();
|
|
}
|
|
|
|
// Renders m_logsRaw, keeping only the lines matching the filter box. Filtering
|
|
// in memory keeps typing instant even with a multi-megabyte pacman.log.
|
|
void MainWindow::applyLogsFilter() {
|
|
if (!m_logsText) return;
|
|
const QString needle = m_logsFilter ? m_logsFilter->text().trimmed() : QString();
|
|
if (needle.isEmpty()) {
|
|
m_logsText->setPlainText(m_logsRaw);
|
|
} else {
|
|
QString filtered;
|
|
const QStringList lines = m_logsRaw.split(QLatin1Char('\n'));
|
|
for (const QString& line : lines) {
|
|
if (line.contains(needle, Qt::CaseInsensitive)) {
|
|
filtered += line;
|
|
filtered += QLatin1Char('\n');
|
|
}
|
|
}
|
|
m_logsText->setPlainText(filtered);
|
|
}
|
|
m_logsText->moveCursor(QTextCursor::End);
|
|
}
|
|
|
|
void MainWindow::onRefreshLogs() {
|
|
loadLogs();
|
|
statusBar()->showMessage("Logs rechargés");
|
|
}
|
|
|
|
void MainWindow::refreshDashboard() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
m_statInstalled->setText("—");
|
|
m_statUpdates->setText("—");
|
|
m_statManager->setText("indisponible");
|
|
refreshRecentActivity();
|
|
return;
|
|
}
|
|
|
|
m_statHistory->setText(QString::number(m_historyManager->getHistory().size()));
|
|
|
|
QStringList names;
|
|
for (IPackageManager* pm : providers) {
|
|
names << QString::fromStdString(pm->getName());
|
|
}
|
|
m_statManager->setText(names.join(", "));
|
|
refreshRecentActivity();
|
|
|
|
auto* inst = new ListWorker(providers, ListWorker::Installed);
|
|
connect(inst, &ListWorker::finished, this, [this](std::vector<PackageInfo> r) {
|
|
m_statInstalled->setText(QString::number(r.size()));
|
|
});
|
|
connect(inst, &ListWorker::finished, this, [inst] { inst->wait(); inst->deleteLater(); });
|
|
inst->start();
|
|
|
|
auto* upd = new ListWorker(providers, ListWorker::Updates);
|
|
connect(upd, &ListWorker::finished, this, [this](std::vector<PackageInfo> r) {
|
|
m_statUpdates->setText(QString::number(r.size()));
|
|
m_statUpdates->setStyleSheet(r.empty()
|
|
? QString()
|
|
: QString("color: #e0af68;"));
|
|
// Notify once per distinct count, so the periodic dashboard refresh
|
|
// does not re-pop the tray message.
|
|
if (static_cast<int>(r.size()) != m_lastNotifiedUpdates) {
|
|
m_lastNotifiedUpdates = static_cast<int>(r.size());
|
|
notifyUpdatesAvailable(static_cast<int>(r.size()));
|
|
}
|
|
});
|
|
connect(upd, &ListWorker::finished, this, [upd] { upd->wait(); upd->deleteLater(); });
|
|
upd->start();
|
|
}
|
|
|
|
void MainWindow::refreshRecentActivity() {
|
|
m_recentList->clear();
|
|
|
|
const auto& history = m_historyManager->getHistory();
|
|
if (history.empty()) {
|
|
QListWidgetItem* empty = new QListWidgetItem(
|
|
"Aucune action enregistrée pour le moment");
|
|
empty->setFlags(Qt::NoItemFlags);
|
|
empty->setTextAlignment(Qt::AlignCenter);
|
|
m_recentList->addItem(empty);
|
|
return;
|
|
}
|
|
|
|
int start = std::max(0, static_cast<int>(history.size()) - 8);
|
|
for (int i = static_cast<int>(history.size()) - 1; i >= start; --i) {
|
|
const HistoryEntry& entry = history[i];
|
|
|
|
QListWidgetItem* item = new QListWidgetItem();
|
|
item->setSizeHint(QSize(0, 42));
|
|
// Keep the package name so a click can navigate to its details.
|
|
item->setData(Qt::UserRole, QString::fromStdString(entry.package));
|
|
|
|
QWidget* row = new QWidget();
|
|
QHBoxLayout* rowLayout = new QHBoxLayout(row);
|
|
rowLayout->setContentsMargins(10, 4, 10, 4);
|
|
rowLayout->setSpacing(10);
|
|
|
|
QLabel* ts = new QLabel(QString::fromStdString(entry.timestamp));
|
|
ts->setStyleSheet(
|
|
"background: transparent; color: #5f6785;"
|
|
"font-family: monospace; font-size: 12px;");
|
|
rowLayout->addWidget(ts);
|
|
|
|
QString actionText, actionBg, actionFg;
|
|
if (entry.action == "install") {
|
|
actionText = "Installation"; actionBg = "#12301f"; actionFg = "#3fb950";
|
|
} else if (entry.action == "remove") {
|
|
actionText = "Suppression"; actionBg = "#3a1a1a"; actionFg = "#f7768e";
|
|
} else if (entry.action == "cleanup") {
|
|
actionText = "Nettoyage"; actionBg = "#12333a"; actionFg = "#56b6c2";
|
|
} else {
|
|
actionText = "Mise à jour"; actionBg = "#3d2f0f"; actionFg = "#e0af68";
|
|
}
|
|
rowLayout->addWidget(makeBadge(actionText, actionBg, actionFg));
|
|
|
|
QLabel* pkg = new QLabel(QString::fromStdString(entry.package));
|
|
pkg->setStyleSheet(
|
|
"background: transparent; font-weight: 600; color: #c8d3f5;");
|
|
rowLayout->addWidget(pkg);
|
|
|
|
rowLayout->addStretch();
|
|
|
|
QLabel* status = new QLabel();
|
|
status->setPixmap(iconPixmap(entry.success ? "check" : "close", 16));
|
|
status->setStyleSheet("background: transparent;");
|
|
rowLayout->addWidget(status);
|
|
|
|
m_recentList->addItem(item);
|
|
m_recentList->setItemWidget(item, row);
|
|
}
|
|
}
|
|
|
|
void MainWindow::updateStatusBar() {
|
|
std::vector<IPackageManager*> providers = m_pluginManager->availableManagers();
|
|
if (providers.empty()) {
|
|
statusBar()->showMessage("Aucun gestionnaire de paquets disponible.");
|
|
return;
|
|
}
|
|
QString info = QString("%1 gestionnaire(s) actif(s) | Paquets affichés : %2 | Actions enregistrées : %3")
|
|
.arg(providers.size())
|
|
.arg(m_currentResults.size())
|
|
.arg(m_historyManager->getHistory().size());
|
|
statusBar()->showMessage(info);
|
|
}
|
|
|
|
void MainWindow::onPluginTableSelected(int row) {
|
|
if (row < 0 || row >= static_cast<int>(m_pluginManager->plugins().size())) {
|
|
m_pluginToggleButton->setEnabled(false);
|
|
m_pluginInstallButton->setVisible(false);
|
|
m_pluginDescription->clear();
|
|
return;
|
|
}
|
|
|
|
const auto& entry = m_pluginManager->plugins()[row];
|
|
m_selectedPluginId = entry.info.id;
|
|
m_pluginDescription->setText(QString::fromStdString(entry.info.description));
|
|
|
|
bool toggleable = entry.info.available;
|
|
m_pluginToggleButton->setEnabled(toggleable);
|
|
m_pluginToggleButton->setToolTip(
|
|
toggleable ? QString()
|
|
: QString("Outil « %1 » non détecté sur ce système.")
|
|
.arg(QString::fromStdString(entry.info.name)));
|
|
m_pluginToggleButton->setText(
|
|
m_pluginManager->isEnabled(entry.info.id) ? "Désactiver" : "Activer");
|
|
|
|
// Offer to install the backing tool (e.g. flatpak via pacman) when it is
|
|
// missing and we know which OS package provides it.
|
|
bool installable = !entry.info.available && !entry.info.installHint.empty()
|
|
&& m_pacman && m_pacman->isAvailable();
|
|
m_pluginInstallButton->setVisible(!entry.info.available);
|
|
m_pluginInstallButton->setEnabled(installable);
|
|
m_pluginInstallButton->setToolTip(
|
|
installable
|
|
? QString("sudo pacman -S %1").arg(QString::fromStdString(entry.info.installHint))
|
|
: QString());
|
|
}
|
|
|
|
// Installs the OS package backing the selected provider through pacman, then
|
|
// re-checks availability so the provider can be used right away.
|
|
void MainWindow::onInstallPluginTool() {
|
|
if (m_selectedPluginId.empty()) return;
|
|
if (!m_pacman || !m_pacman->isAvailable()) {
|
|
statusBar()->showMessage("pacman est requis pour installer l'outil.");
|
|
return;
|
|
}
|
|
|
|
const std::string id = m_selectedPluginId;
|
|
std::string installHint;
|
|
for (const auto& entry : m_pluginManager->plugins()) {
|
|
if (entry.info.id == id) {
|
|
installHint = entry.info.installHint;
|
|
break;
|
|
}
|
|
}
|
|
if (installHint.empty()) return;
|
|
if (!ensureCredentials({m_pacman})) return;
|
|
|
|
setBusy(true);
|
|
statusBar()->showMessage(
|
|
QString("Installation de l'outil %1...").arg(QString::fromStdString(installHint)));
|
|
|
|
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::Install, installHint);
|
|
connect(worker, &InstallWorker::progress, this, [this](const QString& msg) {
|
|
statusBar()->showMessage(msg);
|
|
});
|
|
connect(worker, &InstallWorker::progressValue, this, &MainWindow::onInstallProgress);
|
|
connect(worker, &InstallWorker::finished, this, [this, id](bool success) {
|
|
setBusy(false);
|
|
clearCredentialsAfterUse();
|
|
if (!success) {
|
|
statusBar()->showMessage("Échec de l'installation de l'outil.");
|
|
return;
|
|
}
|
|
|
|
m_pluginManager->refreshAvailability();
|
|
refreshPluginsTable();
|
|
refreshDashboard();
|
|
statusBar()->showMessage("Outil installé, plugin disponible.");
|
|
});
|
|
connect(worker, &InstallWorker::finished, this, [worker] { worker->wait(); worker->deleteLater(); });
|
|
worker->start();
|
|
}
|
|
|
|
void MainWindow::onTogglePlugin() {
|
|
if (m_selectedPluginId.empty()) return;
|
|
|
|
const std::string id = m_selectedPluginId;
|
|
bool enabled = !m_pluginManager->isEnabled(id);
|
|
m_pluginManager->setEnabled(id, enabled);
|
|
|
|
// A freshly enabled addon gets the main window so it can attach its UI
|
|
// (it may have been disabled when onUiReady ran at launch).
|
|
if (enabled) {
|
|
for (const auto& entry : m_pluginManager->plugins()) {
|
|
if (entry.info.id == id && entry.plugin) {
|
|
entry.plugin->onUiReady(this);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
refreshPluginsTable();
|
|
refreshDashboard();
|
|
reloadCurrentView();
|
|
}
|
|
|
|
void MainWindow::onRescanPlugins() {
|
|
m_pluginManager->reload();
|
|
|
|
// Newly discovered addons need the main window to attach their UI.
|
|
for (IPlugin* addon : m_pluginManager->availableAddons()) {
|
|
addon->onUiReady(this);
|
|
}
|
|
|
|
refreshPluginsTable();
|
|
refreshDashboard();
|
|
reloadCurrentView();
|
|
statusBar()->showMessage("Plugins rechargés.");
|
|
}
|
|
|
|
void MainWindow::refreshPluginsTable() {
|
|
const auto& plugins = m_pluginManager->plugins();
|
|
m_pluginTable->setRowCount(0);
|
|
m_pluginTable->setRowCount(static_cast<int>(plugins.size()));
|
|
|
|
QFont nameFont;
|
|
nameFont.setWeight(QFont::DemiBold);
|
|
|
|
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
|
const auto& entry = plugins[i];
|
|
|
|
QTableWidgetItem* nameItem =
|
|
new QTableWidgetItem(QString::fromStdString(entry.info.name));
|
|
nameItem->setFont(nameFont);
|
|
nameItem->setData(Qt::UserRole, QString::fromStdString(entry.info.id));
|
|
m_pluginTable->setItem(i, 0, nameItem);
|
|
|
|
// Type column distinguishes package-manager providers from generic
|
|
// addons; the build origin is appended for external plugins.
|
|
QString kindText = entry.info.kind == PluginKind::Addon ? "Extension"
|
|
: "Fournisseur";
|
|
QString typeText = entry.info.builtin ? kindText : kindText + " (externe)";
|
|
QTableWidgetItem* typeItem = new QTableWidgetItem(typeText);
|
|
typeItem->setForeground(QColor("#7a8299"));
|
|
m_pluginTable->setItem(i, 1, typeItem);
|
|
|
|
m_pluginTable->setItem(i, 2,
|
|
new QTableWidgetItem(QString::fromStdString(entry.info.version)));
|
|
m_pluginTable->setItem(i, 3,
|
|
new QTableWidgetItem(QString::fromStdString(entry.info.author)));
|
|
|
|
QString statusText;
|
|
QColor statusColor;
|
|
if (!entry.info.available) {
|
|
statusText = "Indisponible";
|
|
statusColor = QColor("#565f73");
|
|
} else if (m_pluginManager->isEnabled(entry.info.id)) {
|
|
statusText = "Actif";
|
|
statusColor = QColor("#3fb950");
|
|
} else {
|
|
statusText = "Désactivé";
|
|
statusColor = QColor("#e0af68");
|
|
}
|
|
|
|
QTableWidgetItem* statusItem = new QTableWidgetItem(statusText);
|
|
statusItem->setForeground(statusColor);
|
|
statusItem->setIcon(loadIcon(
|
|
entry.info.available ? (m_pluginManager->isEnabled(entry.info.id) ? "check" : "close")
|
|
: "alert"));
|
|
m_pluginTable->setItem(i, 4, statusItem);
|
|
}
|
|
|
|
if (!plugins.empty()) {
|
|
// Keep the previously selected plugin selected when possible.
|
|
int row = 0;
|
|
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
|
if (plugins[i].info.id == m_selectedPluginId) {
|
|
row = i;
|
|
break;
|
|
}
|
|
}
|
|
m_pluginTable->selectRow(row);
|
|
onPluginTableSelected(row);
|
|
} else {
|
|
m_pluginToggleButton->setEnabled(false);
|
|
m_pluginInstallButton->setVisible(false);
|
|
m_pluginDescription->clear();
|
|
}
|
|
}
|
|
|
|
// Starts an update check against the Gitea releases API. Used both at launch
|
|
// (once per day) and from the Aide menu.
|
|
// ---------------------------------------------------------------------------
|
|
// System tray: optional, only created when the desktop actually provides one.
|
|
// Offers quick access to the pending updates from outside the window.
|
|
// ---------------------------------------------------------------------------
|
|
void MainWindow::setupTray() {
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) return;
|
|
|
|
m_tray = new QSystemTrayIcon(loadIcon("package"), this);
|
|
m_tray->setToolTip("PacManager");
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
menu->addAction("Afficher PacManager", this, [this]() {
|
|
showNormal();
|
|
raise();
|
|
activateWindow();
|
|
});
|
|
menu->addSeparator();
|
|
menu->addAction("Vérifier les mises à jour", this, &MainWindow::onCheckForUpdates);
|
|
menu->addAction("Prévisualiser les mises à jour", this, &MainWindow::onPreviewUpdates);
|
|
menu->addAction("Tout mettre à jour", this, &MainWindow::onUpdateAll);
|
|
menu->addSeparator();
|
|
menu->addAction("Quitter", this, &QWidget::close);
|
|
m_tray->setContextMenu(menu);
|
|
|
|
connect(m_tray, &QSystemTrayIcon::activated, this, &MainWindow::onTrayActivated);
|
|
m_tray->show();
|
|
}
|
|
|
|
void MainWindow::onTrayActivated(QSystemTrayIcon::ActivationReason reason) {
|
|
// A click on the icon brings the window back from the background.
|
|
if (reason != QSystemTrayIcon::Trigger && reason != QSystemTrayIcon::DoubleClick) {
|
|
return;
|
|
}
|
|
showNormal();
|
|
raise();
|
|
activateWindow();
|
|
}
|
|
|
|
void MainWindow::notifyUpdatesAvailable(int count) {
|
|
if (!m_tray || count <= 0) return;
|
|
m_tray->showMessage("PacManager",
|
|
QString("%1 mise(s) à jour disponible(s)").arg(count),
|
|
QSystemTrayIcon::Information, 5000);
|
|
}
|
|
|
|
// Keyboard shortcuts for the actions used most often.
|
|
void MainWindow::setupShortcuts() {
|
|
auto bind = [this](const QKeySequence& key, const std::function<void()>& action) {
|
|
QShortcut* shortcut = new QShortcut(key, this);
|
|
shortcut->setContext(Qt::WindowShortcut);
|
|
connect(shortcut, &QShortcut::activated, this, action);
|
|
};
|
|
|
|
bind(QKeySequence::Find, [this]() {
|
|
m_navGroup->button(NavSearch)->click();
|
|
m_searchBar->setFocus();
|
|
m_searchBar->selectAll();
|
|
});
|
|
bind(QKeySequence::Refresh, [this]() { onRefresh(); });
|
|
bind(QKeySequence(Qt::Key_F5), [this]() { onRefresh(); });
|
|
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
|
|
m_navGroup->button(NavUpdates)->click();
|
|
});
|
|
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() { onExportPackageList(); });
|
|
bind(QKeySequence::Quit, [this]() { close(); });
|
|
}
|
|
|
|
// Shows the pending updates without applying anything: jumps to the updates
|
|
// page, which lists every outdated package across the active providers.
|
|
void MainWindow::onPreviewUpdates() {
|
|
m_navGroup->button(NavUpdates)->click();
|
|
statusBar()->showMessage("Prévisualisation des mises à jour disponibles");
|
|
}
|
|
|
|
// Exports the currently displayed package list (search / installed / updates)
|
|
// to a semicolon-separated CSV usable in a spreadsheet.
|
|
void MainWindow::onExportPackageList() {
|
|
if (m_currentResults.empty()) {
|
|
statusBar()->showMessage("Aucune liste à exporter.");
|
|
return;
|
|
}
|
|
const QString path = QFileDialog::getSaveFileName(
|
|
this, "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, "Export",
|
|
QString("Impossible d'écrire dans %1").arg(path));
|
|
return;
|
|
}
|
|
QTextStream out(&file);
|
|
out << "Nom;Version;Depot;Fournisseur;Statut\n";
|
|
for (const auto& pkg : m_currentResults) {
|
|
out << csvField(QString::fromStdString(pkg.name)) << ';'
|
|
<< csvField(QString::fromStdString(pkg.version)) << ';'
|
|
<< csvField(QString::fromStdString(pkg.repository)) << ';'
|
|
<< csvField(providersLabel(m_pluginManager, pkg)) << ';'
|
|
<< csvField(packageStatusText(pkg)) << '\n';
|
|
}
|
|
statusBar()->showMessage(
|
|
QString("%1 paquet(s) exporté(s) vers %2")
|
|
.arg(static_cast<int>(m_currentResults.size())).arg(path));
|
|
}
|
|
|
|
// Exports the recorded action history to CSV.
|
|
void MainWindow::onExportHistory() {
|
|
const auto& history = m_historyManager->getHistory();
|
|
if (history.empty()) {
|
|
statusBar()->showMessage("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 << csvField(QString::fromStdString(entry.timestamp)) << ';'
|
|
<< csvField(QString::fromStdString(entry.action)) << ';'
|
|
<< csvField(QString::fromStdString(entry.package)) << ';'
|
|
<< csvField(QString::fromStdString(entry.plugin)) << ';'
|
|
<< (entry.success ? "Succes" : "Echec") << '\n';
|
|
}
|
|
statusBar()->showMessage(
|
|
QString("Historique exporté vers %1").arg(path));
|
|
}
|
|
|
|
void MainWindow::onCheckForUpdates() {
|
|
statusBar()->showMessage("Vérification des mises à jour...");
|
|
connect(m_updateManager, &UpdateManager::checkFinished,
|
|
this, &MainWindow::onUpdateCheckFinished);
|
|
m_updateManager->checkForUpdates();
|
|
}
|
|
|
|
// Handles the result of a release check: offers to self-update when a newer
|
|
// version exists, otherwise a status bar confirmation. Errors are reported
|
|
// silently in the status bar so a network failure never blocks the app.
|
|
void MainWindow::onUpdateCheckFinished(bool hasUpdate, const QString& latestVersion,
|
|
const QString& errorMessage) {
|
|
disconnect(m_updateManager, &UpdateManager::checkFinished,
|
|
this, &MainWindow::onUpdateCheckFinished);
|
|
|
|
if (!errorMessage.isEmpty()) {
|
|
statusBar()->showMessage(errorMessage);
|
|
return;
|
|
}
|
|
|
|
if (!hasUpdate) {
|
|
statusBar()->showMessage(
|
|
QString("PacManager est à jour (v%1)").arg(UpdateManager::currentVersion()));
|
|
return;
|
|
}
|
|
|
|
// Ask the user whether to update now or skip. The update runs in the
|
|
// background (git pull from a checkout, clone + rebuild, prebuilt unpack,
|
|
// or tarball rebuild); the running binary stays untouched and the app
|
|
// hands over to the new build once the update succeeds.
|
|
const UpdateManager::UpdateMethod method = m_updateManager->updateMethod();
|
|
const QString targetDir = m_updateManager->binDir();
|
|
|
|
QMessageBox box(this);
|
|
box.setWindowTitle("Mise à jour disponible");
|
|
box.setIcon(QMessageBox::Information);
|
|
box.setTextFormat(Qt::RichText);
|
|
box.setText(QString("<h3>PacManager v%1 est disponible</h3>"
|
|
"<p>Vous utilisez actuellement la version %2.</p>")
|
|
.arg(latestVersion, UpdateManager::currentVersion()));
|
|
|
|
QPushButton* updateBtn = box.addButton("Mettre à jour", QMessageBox::AcceptRole);
|
|
box.addButton("Plus tard", QMessageBox::RejectRole);
|
|
if (method == UpdateManager::UpdateMethod::None) {
|
|
// No local way to update: offer the releases page instead of a button
|
|
// that would immediately fail.
|
|
updateBtn->setText("Ouvrir la page des releases");
|
|
}
|
|
box.setInformativeText(UpdateManager::methodDescription(method, targetDir));
|
|
box.exec();
|
|
|
|
if (box.clickedButton() != updateBtn) {
|
|
// "Plus tard" (or closing the dialog) simply skips the update.
|
|
return;
|
|
}
|
|
|
|
if (method == UpdateManager::UpdateMethod::None) {
|
|
QDesktopServices::openUrl(QUrl(m_updateManager->releasePageUrl()));
|
|
return;
|
|
}
|
|
|
|
// Prompt for the sudo password only when the update must write into a
|
|
// root-owned directory (e.g. /usr/bin). Every method installs into the
|
|
// running binary's directory, and only that final copy is privileged:
|
|
// everything else builds in a temp directory owned by the user.
|
|
QString sudoPassword;
|
|
if (!QFileInfo(targetDir).isWritable()
|
|
&& m_pacman && m_pacman->isAvailable()) {
|
|
bool ok = false;
|
|
sudoPassword = QInputDialog::getText(
|
|
this, "Mise à jour",
|
|
QString("Mot de passe sudo pour installer dans %1 :").arg(targetDir),
|
|
QLineEdit::Password, QString(), &ok);
|
|
if (!ok) {
|
|
statusBar()->showMessage("Mise à jour annulée.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
qCInfo(pacmgrUpdate) << "applying update, method" << static_cast<int>(method)
|
|
<< "target" << targetDir;
|
|
statusBar()->showMessage("Mise à jour en cours en arrière-plan...");
|
|
connect(m_updateManager, &UpdateManager::selfUpdateFinished,
|
|
this, &MainWindow::onSelfUpdateFinished);
|
|
m_updateManager->performSelfUpdate(sudoPassword);
|
|
}
|
|
|
|
// Called when the background git pull + build finishes. A success hands over to
|
|
// the freshly installed binary right away; a failure is reported in a dialog.
|
|
void MainWindow::onSelfUpdateFinished(bool success, const QString& message) {
|
|
disconnect(m_updateManager, &UpdateManager::selfUpdateFinished,
|
|
this, &MainWindow::onSelfUpdateFinished);
|
|
|
|
if (!success) {
|
|
QMessageBox::warning(this, "Échec de la mise à jour",
|
|
QString("<p>La mise à jour a échoué :</p><pre>%1</pre>")
|
|
.arg(message.toHtmlEscaped()));
|
|
return;
|
|
}
|
|
|
|
// The build log is no longer shown to the user, so keep it in the app log
|
|
// for troubleshooting.
|
|
qCInfo(pacmgrUpdate) << "self-update output:" << message;
|
|
|
|
// Restarting is the only way to run the new build: this process still maps
|
|
// the inode that was replaced on disk. Ask for a manual restart only when
|
|
// no runnable binary is there to hand over to.
|
|
const QString program = UpdateManager::restartProgram(m_updateManager->binDir());
|
|
if (!program.isEmpty()
|
|
&& QProcess::startDetached(program, QCoreApplication::arguments().mid(1))) {
|
|
qCInfo(pacmgrUpdate) << "update installed, relaunching" << program;
|
|
statusBar()->showMessage("Mise à jour terminée, redémarrage de PacManager...");
|
|
// Quit on the next event-loop pass so the message paints first. The new
|
|
// process is detached and outlives this one.
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
return;
|
|
}
|
|
|
|
qCWarning(pacmgrUpdate) << "could not relaunch" << program;
|
|
QMessageBox::information(this, "Mise à jour terminée",
|
|
QString("<h3>PacManager a été mis à jour</h3>"
|
|
"<p>La nouvelle version sera active au prochain démarrage.</p>"
|
|
"<pre>%1</pre>")
|
|
.arg(message.toHtmlEscaped()));
|
|
}
|