Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5df9f2c22a | ||
|
|
ca49ad5e63 | ||
|
|
f525d52ab2 |
No files matched your search
@@ -17,6 +17,7 @@ set(SOURCES
|
||||
src/pacman-manager.cpp
|
||||
src/history-manager.cpp
|
||||
src/package-model.cpp
|
||||
resources/resources.qrc
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
|
||||
@@ -21,6 +21,7 @@ class QStackedWidget;
|
||||
class QTableWidget;
|
||||
class QTextEdit;
|
||||
class QListWidget;
|
||||
class QListWidgetItem;
|
||||
class QButtonGroup;
|
||||
class QFrame;
|
||||
|
||||
@@ -88,6 +89,7 @@ private slots:
|
||||
void onRefreshLogs();
|
||||
void onHistoryFilterChanged();
|
||||
void onInstalledFilterChanged(const QString& text);
|
||||
void onRecentActivityClicked(QListWidgetItem* item);
|
||||
|
||||
private:
|
||||
enum BrowseMode { ModeSearch, ModeInstalled, ModeUpdates };
|
||||
@@ -117,7 +119,7 @@ private:
|
||||
void refreshHistoryTable();
|
||||
void loadLogs();
|
||||
QFrame* makeCard();
|
||||
QFrame* makeStatCard(const QString& icon, const QString& title, QLabel** valueOut);
|
||||
QFrame* makeStatCard(const QString& iconName, const QString& title, QLabel** valueOut);
|
||||
|
||||
// Sidebar
|
||||
QFrame* m_sidebar = nullptr;
|
||||
@@ -156,7 +158,7 @@ private:
|
||||
QLabel* m_packageVersion = nullptr;
|
||||
QLabel* m_packageRepo = nullptr;
|
||||
QLabel* m_packageSize = nullptr;
|
||||
QLabel* m_packageUpdateBadge = nullptr;
|
||||
QWidget* m_packageUpdateBadge = nullptr;
|
||||
QLabel* m_packageDescription = nullptr;
|
||||
|
||||
// History page
|
||||
@@ -175,4 +177,5 @@ private:
|
||||
std::vector<PackageInfo> m_currentResults;
|
||||
std::vector<PackageInfo> m_installedPackages;
|
||||
PackageInfo m_selectedPackage;
|
||||
std::string m_pendingSelect; // package to auto-select after the installed list loads
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "package-manager.h"
|
||||
#include <map>
|
||||
|
||||
// Native Arch Linux package manager, integrated directly into the application
|
||||
class PacmanManager : public IPackageManager {
|
||||
@@ -25,6 +26,14 @@ public:
|
||||
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||
static std::vector<PackageInfo> parseInstalledOutput(const std::string& output);
|
||||
|
||||
// Parse `pacman -Qi` output (one block per package) into a name -> installed size map.
|
||||
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||
static std::map<std::string, std::string> parseInstalledSizes(const std::string& output);
|
||||
|
||||
// Parse `pacman -Sl` output ("repo name version" per line) into a name -> repository map.
|
||||
// Exposed as static so the parsing can be unit-tested without invoking pacman.
|
||||
static std::map<std::string, std::string> parseSyncRepos(const std::string& output);
|
||||
|
||||
std::vector<PackageInfo> search(const std::string& query) override;
|
||||
bool install(const std::string& packageName,
|
||||
std::function<void(const std::string&)> progressCallback) override;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#e0af68" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
|
||||
<line x1="12" y1="9" x2="12" y2="13"/>
|
||||
<line x1="12" y1="17" x2="12.01" y2="17"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 372 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<line x1="12" y1="19" x2="12" y2="5"/>
|
||||
<polyline points="5 12 12 5 19 12"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 263 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#3fb950" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<polyline points="20 6 9 17 4 12"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 223 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#f7768e" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<line x1="18" y1="6" x2="6" y2="18"/>
|
||||
<line x1="6" y1="6" x2="18" y2="18"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 265 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M22 3H2l8 9.5V19l4 2v-8.5L22 3z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 229 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<circle cx="12" cy="12" r="9"/>
|
||||
<path d="M12 7v5l3 3"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 243 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M3 11l9-8 9 8"/>
|
||||
<path d="M5 10v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V10"/>
|
||||
<path d="M9 21v-7h6v7"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 295 B |
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
|
||||
<path d="M14 2v6h6"/>
|
||||
<path d="M8 13h8"/>
|
||||
<path d="M8 17h5"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 324 B |
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M21 8l-9-5-9 5v8l9 5 9-5V8z"/>
|
||||
<path d="M3 8l9 5 9-5"/>
|
||||
<path d="M12 13v8"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 275 B |
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M23 4v6h-6"/>
|
||||
<path d="M1 20v-6h6"/>
|
||||
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10"/>
|
||||
<path d="M20.49 15a9 9 0 0 1-14.85 3.36L1 14"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 332 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<circle cx="11" cy="11" r="7"/>
|
||||
<line x1="21" y1="21" x2="16.5" y2="16.5"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 263 B |
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 350 B |
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#c8d3f5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="24" height="24">
|
||||
<path d="M3 6h18"/>
|
||||
<path d="M8 6V4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v2"/>
|
||||
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
|
||||
<line x1="10" y1="11" x2="10" y2="17"/>
|
||||
<line x1="14" y1="11" x2="14" y2="17"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 402 B |
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource prefix="/icons">
|
||||
<file alias="home.svg">icons/home.svg</file>
|
||||
<file alias="search.svg">icons/search.svg</file>
|
||||
<file alias="package.svg">icons/package.svg</file>
|
||||
<file alias="trash.svg">icons/trash.svg</file>
|
||||
<file alias="arrow-up.svg">icons/arrow-up.svg</file>
|
||||
<file alias="history.svg">icons/history.svg</file>
|
||||
<file alias="logs.svg">icons/logs.svg</file>
|
||||
<file alias="refresh.svg">icons/refresh.svg</file>
|
||||
<file alias="tools.svg">icons/tools.svg</file>
|
||||
<file alias="check.svg">icons/check.svg</file>
|
||||
<file alias="close.svg">icons/close.svg</file>
|
||||
<file alias="filter.svg">icons/filter.svg</file>
|
||||
<file alias="alert.svg">icons/alert.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <QMenuBar>
|
||||
#include <QMenu>
|
||||
#include <QStatusBar>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -72,6 +74,17 @@ static QLabel* makeBadge(const QString& text, const QString& bg, const QString&
|
||||
return badge;
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
// MainWindow implementation
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
// Workers emit std::vector<PackageInfo> from another thread (QThread::run);
|
||||
@@ -85,7 +98,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
|
||||
setupMenuBar();
|
||||
|
||||
if (!m_pacman->isAvailable()) {
|
||||
statusBar()->showMessage("⚠️ pacman n'est pas disponible sur ce système.");
|
||||
statusBar()->showMessage("pacman n'est pas disponible sur ce système.");
|
||||
m_searchBar->setEnabled(false);
|
||||
m_searchButton->setEnabled(false);
|
||||
m_refreshButton->setEnabled(false);
|
||||
@@ -139,7 +152,8 @@ void MainWindow::setupUI() {
|
||||
"QMainWindow, QWidget { background: #0d1017; color: #dbe2f0; }"
|
||||
// ---- Sidebar ----
|
||||
"QFrame#sidebar { background: #11151d; border-right: 1px solid #1d2432; }"
|
||||
"QLabel#logo { font-size: 16px; font-weight: 800; color: #ffffff; padding: 2px 8px; }"
|
||||
"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;"
|
||||
@@ -303,9 +317,21 @@ void MainWindow::setupSidebar() {
|
||||
layout->setContentsMargins(12, 16, 12, 12);
|
||||
layout->setSpacing(4);
|
||||
|
||||
QLabel* appTitle = new QLabel("📦 PacManager");
|
||||
appTitle->setObjectName("logo");
|
||||
layout->addWidget(appTitle);
|
||||
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");
|
||||
@@ -317,32 +343,37 @@ void MainWindow::setupSidebar() {
|
||||
m_navGroup = new QButtonGroup(this);
|
||||
m_navGroup->setExclusive(true);
|
||||
|
||||
auto addNavButton = [&](int id, const QString& text, const QString& tip) {
|
||||
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(0, "🏠 Tableau de bord", "Vue d'ensemble du système");
|
||||
addNavButton(1, "🔍 Recherche", "Rechercher des paquets");
|
||||
addNavButton(2, "📦 Installés", "Voir les paquets installés");
|
||||
addNavButton(3, "⬆️ Mises à jour", "Voir les mises à jour disponibles");
|
||||
addNavButton(0, "home", "Tableau de bord", "Vue d'ensemble du système");
|
||||
addNavButton(1, "search", "Recherche", "Rechercher des paquets");
|
||||
addNavButton(2, "package", "Installés", "Voir les paquets installés");
|
||||
addNavButton(3, "arrow-up", "Mises à jour", "Voir les mises à jour disponibles");
|
||||
layout->addSpacing(8);
|
||||
addNavButton(4, "📋 Historique", "Historique des actions");
|
||||
addNavButton(5, "📜 Logs", "Logs pacman");
|
||||
addNavButton(4, "history", "Historique", "Historique des actions");
|
||||
addNavButton(5, "logs", "Logs", "Logs pacman");
|
||||
|
||||
connect(m_navGroup, &QButtonGroup::idClicked, this, &MainWindow::onNavChanged);
|
||||
m_navGroup->button(0)->setChecked(true);
|
||||
|
||||
layout->addStretch();
|
||||
|
||||
m_refreshButton = new QPushButton("🔄 Rafraîchir les sources");
|
||||
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);
|
||||
@@ -382,10 +413,10 @@ void MainWindow::setupDashboardPage() {
|
||||
// Stat cards
|
||||
QHBoxLayout* statsRow = new QHBoxLayout();
|
||||
statsRow->setSpacing(12);
|
||||
statsRow->addWidget(makeStatCard("📦", "Paquets installés", &m_statInstalled));
|
||||
statsRow->addWidget(makeStatCard("⬆️", "Mises à jour dispo", &m_statUpdates));
|
||||
statsRow->addWidget(makeStatCard("📋", "Actions enregistrées", &m_statHistory));
|
||||
statsRow->addWidget(makeStatCard("🛠️", "Gestionnaire", &m_statManager));
|
||||
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
|
||||
@@ -401,31 +432,36 @@ void MainWindow::setupDashboardPage() {
|
||||
QHBoxLayout* actionsRow = new QHBoxLayout();
|
||||
actionsRow->setSpacing(10);
|
||||
|
||||
QPushButton* btnSearch = new QPushButton("🔍 Rechercher un paquet");
|
||||
QPushButton* btnSearch = new QPushButton("Rechercher un paquet");
|
||||
btnSearch->setProperty("variant", "primary");
|
||||
btnSearch->setIcon(loadIcon("search"));
|
||||
connect(btnSearch, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(1)->click();
|
||||
m_searchBar->setFocus();
|
||||
});
|
||||
actionsRow->addWidget(btnSearch);
|
||||
|
||||
QPushButton* btnInstalled = new QPushButton("📦 Paquets installés");
|
||||
QPushButton* btnInstalled = new QPushButton("Paquets installés");
|
||||
btnInstalled->setIcon(loadIcon("package"));
|
||||
connect(btnInstalled, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(2)->click();
|
||||
});
|
||||
actionsRow->addWidget(btnInstalled);
|
||||
|
||||
QPushButton* btnUpdateAll = new QPushButton("⬆️ Tout mettre à jour");
|
||||
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* btnRefresh = new QPushButton("🔄 Rafraîchir les sources");
|
||||
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");
|
||||
QPushButton* btnLogs = new QPushButton("Logs pacman");
|
||||
btnLogs->setIcon(loadIcon("logs"));
|
||||
connect(btnLogs, &QPushButton::clicked, this, [this]() {
|
||||
m_navGroup->button(5)->click();
|
||||
});
|
||||
@@ -450,6 +486,9 @@ void MainWindow::setupDashboardPage() {
|
||||
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);
|
||||
@@ -470,8 +509,9 @@ void MainWindow::setupBrowsePage() {
|
||||
searchRow->setSpacing(10);
|
||||
|
||||
m_searchBar = new QLineEdit();
|
||||
m_searchBar->setPlaceholderText("🔍 Rechercher un paquet (ex : firefox)...");
|
||||
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);
|
||||
|
||||
@@ -491,8 +531,9 @@ void MainWindow::setupBrowsePage() {
|
||||
filterRow->setSpacing(10);
|
||||
|
||||
m_filterBar = new QLineEdit();
|
||||
m_filterBar->setPlaceholderText("🔎 Filtrer par nom...");
|
||||
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);
|
||||
@@ -515,26 +556,30 @@ void MainWindow::setupBrowsePage() {
|
||||
QHBoxLayout* actionBar = new QHBoxLayout();
|
||||
actionBar->setSpacing(8);
|
||||
|
||||
m_installButton = new QPushButton("📦 Installer");
|
||||
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 = 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 = 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 = 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);
|
||||
@@ -611,7 +656,18 @@ void MainWindow::setupBrowsePage() {
|
||||
"padding: 3px 12px; font-size: 12px;");
|
||||
metaRow->addWidget(m_packageSize);
|
||||
|
||||
m_packageUpdateBadge = makeBadge("⬆️ Mise à jour disponible", "#3d2f0f", "#e0af68");
|
||||
// "Update available" badge with an SVG arrow + text.
|
||||
m_packageUpdateBadge = new QWidget();
|
||||
m_packageUpdateBadge->setStyleSheet("background: #3d2f0f; border-radius: 9px;");
|
||||
QHBoxLayout* updLayout = new QHBoxLayout(m_packageUpdateBadge);
|
||||
updLayout->setContentsMargins(9, 2, 9, 2);
|
||||
updLayout->setSpacing(5);
|
||||
QLabel* updIcon = new QLabel();
|
||||
updIcon->setPixmap(iconPixmap("arrow-up", 12));
|
||||
updLayout->addWidget(updIcon);
|
||||
QLabel* updText = new QLabel("Mise à jour disponible");
|
||||
updText->setStyleSheet("font-size: 11px; font-weight: 600; color: #e0af68; background: transparent;");
|
||||
updLayout->addWidget(updText);
|
||||
m_packageUpdateBadge->setVisible(false);
|
||||
metaRow->addWidget(m_packageUpdateBadge);
|
||||
|
||||
@@ -681,8 +737,9 @@ void MainWindow::setupHistoryPage() {
|
||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
||||
buttonBar->addStretch();
|
||||
|
||||
QPushButton* clearBtn = new QPushButton("🗑️ Effacer l'historique");
|
||||
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);
|
||||
|
||||
@@ -704,7 +761,8 @@ void MainWindow::setupLogsPage() {
|
||||
QHBoxLayout* buttonBar = new QHBoxLayout();
|
||||
buttonBar->addStretch();
|
||||
|
||||
QPushButton* refreshBtn = new QPushButton("🔄 Recharger");
|
||||
QPushButton* refreshBtn = new QPushButton("Recharger");
|
||||
refreshBtn->setIcon(loadIcon("refresh"));
|
||||
connect(refreshBtn, &QPushButton::clicked, this, &MainWindow::onRefreshLogs);
|
||||
buttonBar->addWidget(refreshBtn);
|
||||
|
||||
@@ -762,14 +820,16 @@ QFrame* MainWindow::makeCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
QFrame* MainWindow::makeStatCard(const QString& icon, const QString& title, QLabel** valueOut) {
|
||||
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(icon);
|
||||
iconLabel->setStyleSheet("font-size: 22px; background: transparent;");
|
||||
QLabel* iconLabel = new QLabel();
|
||||
iconLabel->setPixmap(iconPixmap(iconName, 24));
|
||||
iconLabel->setStyleSheet("background: transparent;");
|
||||
layout->addWidget(iconLabel);
|
||||
|
||||
QLabel* value = new QLabel("…");
|
||||
@@ -886,7 +946,7 @@ void MainWindow::onSearch() {
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
statusBar()->showMessage("🔍 Recherche en cours...");
|
||||
statusBar()->showMessage("Recherche en cours...");
|
||||
m_packageTable->setRowCount(0);
|
||||
|
||||
SearchWorker* worker = new SearchWorker(m_pacman, query);
|
||||
@@ -897,7 +957,7 @@ void MainWindow::onSearch() {
|
||||
|
||||
void MainWindow::loadInstalled() {
|
||||
setBusy(true);
|
||||
statusBar()->showMessage("📦 Chargement des paquets installés...");
|
||||
statusBar()->showMessage("Chargement des paquets installés...");
|
||||
m_packageTable->setRowCount(0);
|
||||
|
||||
ListWorker* worker = new ListWorker(m_pacman, ListWorker::Installed);
|
||||
@@ -908,7 +968,7 @@ void MainWindow::loadInstalled() {
|
||||
|
||||
void MainWindow::loadUpdates() {
|
||||
setBusy(true);
|
||||
statusBar()->showMessage("⬆️ Recherche des mises à jour...");
|
||||
statusBar()->showMessage("Recherche des mises à jour...");
|
||||
m_packageTable->setRowCount(0);
|
||||
|
||||
ListWorker* worker = new ListWorker(m_pacman, ListWorker::Updates);
|
||||
@@ -920,7 +980,7 @@ void MainWindow::loadUpdates() {
|
||||
void MainWindow::onSearchFinished(std::vector<PackageInfo> results) {
|
||||
setBusy(false);
|
||||
populatePackageTable(results);
|
||||
statusBar()->showMessage(QString("🔍 %1 paquet(s) trouvé(s)").arg(results.size()));
|
||||
statusBar()->showMessage(QString("%1 paquet(s) trouvé(s)").arg(results.size()));
|
||||
}
|
||||
|
||||
void MainWindow::onListFinished(std::vector<PackageInfo> results) {
|
||||
@@ -930,11 +990,11 @@ void MainWindow::onListFinished(std::vector<PackageInfo> results) {
|
||||
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()));
|
||||
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()));
|
||||
QString("%1 mise(s) à jour disponible(s)").arg(results.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -955,6 +1015,20 @@ void MainWindow::onInstalledFilterChanged(const QString& text) {
|
||||
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(2)->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);
|
||||
@@ -977,33 +1051,53 @@ void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
|
||||
pkg.repository.empty() ? "—" : QString::fromStdString(pkg.repository)));
|
||||
|
||||
QString statusText;
|
||||
QString statusIcon;
|
||||
QColor statusColor;
|
||||
if (pkg.installed && pkg.updateAvailable) {
|
||||
statusText = "⬆️ MAJ dispo";
|
||||
statusText = "MAJ dispo";
|
||||
statusIcon = "arrow-up";
|
||||
statusColor = QColor("#e0af68");
|
||||
} else if (pkg.installed) {
|
||||
statusText = "✅ Installé";
|
||||
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, 3, statusItem);
|
||||
}
|
||||
|
||||
m_resultCount->setText(QString("%1 paquet(s)").arg(results.size()));
|
||||
|
||||
if (!results.empty()) {
|
||||
m_packageTable->selectRow(0);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindow::onPackageSelected(int row) {
|
||||
@@ -1059,7 +1153,7 @@ void MainWindow::onUpdate() {
|
||||
|
||||
setBusy(true);
|
||||
statusBar()->showMessage(
|
||||
QString("🔄 Mise à jour de %1...").arg(QString::fromStdString(m_selectedPackage.name)));
|
||||
QString("Mise à jour de %1...").arg(QString::fromStdString(m_selectedPackage.name)));
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::Update, m_selectedPackage.name);
|
||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
||||
@@ -1068,9 +1162,9 @@ void MainWindow::onUpdate() {
|
||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
||||
setBusy(false);
|
||||
if (success) {
|
||||
statusBar()->showMessage("✅ Mise à jour terminée");
|
||||
statusBar()->showMessage("Mise à jour terminée");
|
||||
} else {
|
||||
statusBar()->showMessage("❌ Échec de la mise à jour");
|
||||
statusBar()->showMessage("Échec de la mise à jour");
|
||||
}
|
||||
m_historyManager->record({"", "update", m_selectedPackage.name,
|
||||
m_pacman->getName(), success});
|
||||
@@ -1087,7 +1181,7 @@ void MainWindow::onUpdateAll() {
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
statusBar()->showMessage("🔄 Mise à jour de tous les paquets...");
|
||||
statusBar()->showMessage("Mise à jour de tous les paquets...");
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::UpdateAll, "");
|
||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
||||
@@ -1096,9 +1190,9 @@ void MainWindow::onUpdateAll() {
|
||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
||||
setBusy(false);
|
||||
if (success) {
|
||||
statusBar()->showMessage("✅ Tous les paquets sont à jour");
|
||||
statusBar()->showMessage("Tous les paquets sont à jour");
|
||||
} else {
|
||||
statusBar()->showMessage("❌ Erreur lors de la mise à jour globale");
|
||||
statusBar()->showMessage("Erreur lors de la mise à jour globale");
|
||||
}
|
||||
reloadCurrentView();
|
||||
refreshDashboard();
|
||||
@@ -1114,7 +1208,7 @@ void MainWindow::onRefresh() {
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
statusBar()->showMessage("🔄 Rafraîchissement des sources...");
|
||||
statusBar()->showMessage("Rafraîchissement des sources...");
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::Refresh, "");
|
||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
||||
@@ -1123,9 +1217,9 @@ void MainWindow::onRefresh() {
|
||||
connect(worker, &InstallWorker::finished, [this](bool success) {
|
||||
setBusy(false);
|
||||
if (success) {
|
||||
statusBar()->showMessage("✅ Sources rafraîchies");
|
||||
statusBar()->showMessage("Sources rafraîchies");
|
||||
} else {
|
||||
statusBar()->showMessage("❌ Erreur lors du rafraîchissement");
|
||||
statusBar()->showMessage("Erreur lors du rafraîchissement");
|
||||
}
|
||||
refreshDashboard();
|
||||
});
|
||||
@@ -1136,7 +1230,7 @@ void MainWindow::onRefresh() {
|
||||
void MainWindow::performInstall(const std::string& package) {
|
||||
setBusy(true);
|
||||
statusBar()->showMessage(
|
||||
QString("📦 Installation de %1...").arg(QString::fromStdString(package)));
|
||||
QString("Installation de %1...").arg(QString::fromStdString(package)));
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::Install, package);
|
||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
||||
@@ -1146,11 +1240,11 @@ void MainWindow::performInstall(const std::string& package) {
|
||||
setBusy(false);
|
||||
if (success) {
|
||||
statusBar()->showMessage(
|
||||
QString("✅ %1 installé avec succès").arg(
|
||||
QString("%1 installé avec succès").arg(
|
||||
QString::fromStdString(m_selectedPackage.name)));
|
||||
} else {
|
||||
statusBar()->showMessage(
|
||||
QString("❌ Échec de l'installation de %1").arg(
|
||||
QString("Échec de l'installation de %1").arg(
|
||||
QString::fromStdString(m_selectedPackage.name)));
|
||||
}
|
||||
m_historyManager->record({"", "install", m_selectedPackage.name,
|
||||
@@ -1173,7 +1267,7 @@ void MainWindow::performRemove(const std::string& package) {
|
||||
|
||||
setBusy(true);
|
||||
statusBar()->showMessage(
|
||||
QString("🗑️ Suppression de %1...").arg(QString::fromStdString(package)));
|
||||
QString("Suppression de %1...").arg(QString::fromStdString(package)));
|
||||
|
||||
auto* worker = new InstallWorker(m_pacman, InstallWorker::Op::Remove, package);
|
||||
connect(worker, &InstallWorker::progress, [this](const QString& msg) {
|
||||
@@ -1183,11 +1277,11 @@ void MainWindow::performRemove(const std::string& package) {
|
||||
setBusy(false);
|
||||
if (success) {
|
||||
statusBar()->showMessage(
|
||||
QString("✅ %1 supprimé avec succès").arg(
|
||||
QString("%1 supprimé avec succès").arg(
|
||||
QString::fromStdString(m_selectedPackage.name)));
|
||||
} else {
|
||||
statusBar()->showMessage(
|
||||
QString("❌ Échec de la suppression de %1").arg(
|
||||
QString("Échec de la suppression de %1").arg(
|
||||
QString::fromStdString(m_selectedPackage.name)));
|
||||
}
|
||||
m_historyManager->record({"", "remove", m_selectedPackage.name,
|
||||
@@ -1255,8 +1349,10 @@ void MainWindow::refreshHistoryTable() {
|
||||
new QTableWidgetItem(QString::fromStdString(entry.package)));
|
||||
m_historyTable->setItem(i, 3,
|
||||
new QTableWidgetItem(QString::fromStdString(entry.plugin)));
|
||||
m_historyTable->setItem(i, 4,
|
||||
new QTableWidgetItem(entry.success ? "✅ Succès" : "❌ Échec"));
|
||||
QTableWidgetItem* statusItem =
|
||||
new QTableWidgetItem(entry.success ? "Succès" : "Échec");
|
||||
statusItem->setIcon(loadIcon(entry.success ? "check" : "close"));
|
||||
m_historyTable->setItem(i, 4, statusItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1268,7 +1364,7 @@ void MainWindow::onClearHistory() {
|
||||
m_historyManager->clear();
|
||||
refreshHistoryTable();
|
||||
refreshDashboard();
|
||||
statusBar()->showMessage("🗑️ Historique effacé");
|
||||
statusBar()->showMessage("Historique effacé");
|
||||
}
|
||||
|
||||
void MainWindow::loadLogs() {
|
||||
@@ -1289,7 +1385,7 @@ void MainWindow::loadLogs() {
|
||||
|
||||
void MainWindow::onRefreshLogs() {
|
||||
loadLogs();
|
||||
statusBar()->showMessage("📜 Logs rechargés");
|
||||
statusBar()->showMessage("Logs rechargés");
|
||||
}
|
||||
|
||||
void MainWindow::refreshDashboard() {
|
||||
@@ -1344,6 +1440,8 @@ void MainWindow::refreshRecentActivity() {
|
||||
|
||||
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);
|
||||
@@ -1373,10 +1471,9 @@ void MainWindow::refreshRecentActivity() {
|
||||
|
||||
rowLayout->addStretch();
|
||||
|
||||
QLabel* status = new QLabel(entry.success ? "✓" : "✗");
|
||||
status->setStyleSheet(QString(
|
||||
"background: transparent; font-size: 14px; font-weight: 700; color: %1;")
|
||||
.arg(entry.success ? "#3fb950" : "#f7768e"));
|
||||
QLabel* status = new QLabel();
|
||||
status->setPixmap(iconPixmap(entry.success ? "check" : "close", 16));
|
||||
status->setStyleSheet("background: transparent;");
|
||||
rowLayout->addWidget(status);
|
||||
|
||||
m_recentList->addItem(item);
|
||||
|
||||
@@ -117,7 +117,31 @@ bool PacmanManager::update(const std::string& packageName,
|
||||
}
|
||||
|
||||
std::vector<PackageInfo> PacmanManager::listInstalled() {
|
||||
return parseInstalledOutput(exec("pacman -Q 2>&1"));
|
||||
auto packages = parseInstalledOutput(exec("pacman -Q 2>&1"));
|
||||
|
||||
// Enrich each installed package with its installed size (shown as "Taille")
|
||||
// and the repository/origin it was installed from. Both come from a single
|
||||
// subprocess each, which is fast enough to run on page load.
|
||||
auto sizes = parseInstalledSizes(exec("pacman -Qi 2>&1"));
|
||||
auto repos = parseSyncRepos(exec("pacman -Sl 2>&1"));
|
||||
|
||||
for (auto& pkg : packages) {
|
||||
auto sizeIt = sizes.find(pkg.name);
|
||||
if (sizeIt != sizes.end()) {
|
||||
pkg.size = sizeIt->second;
|
||||
pkg.installedSize = sizeIt->second;
|
||||
}
|
||||
|
||||
auto repoIt = repos.find(pkg.name);
|
||||
if (repoIt != repos.end()) {
|
||||
pkg.repository = repoIt->second;
|
||||
} else {
|
||||
// Not present in any sync repository: foreign package (AUR / manual build).
|
||||
pkg.repository = "AUR";
|
||||
}
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
// Parse `pacman -Qu` output (one "name version" line per outdated package).
|
||||
@@ -194,3 +218,70 @@ bool PacmanManager::isPackageInstalled(const std::string& name) {
|
||||
std::string cmd = "pacman -Qi " + name + " > /dev/null 2>&1";
|
||||
return system(cmd.c_str()) == 0;
|
||||
}
|
||||
|
||||
// Parse `pacman -Qi` output (one blank-line-separated block per package) into a
|
||||
// map of package name -> installed size (e.g. "263.47 MiB").
|
||||
std::map<std::string, std::string> PacmanManager::parseInstalledSizes(
|
||||
const std::string& output) {
|
||||
std::map<std::string, std::string> sizes;
|
||||
std::istringstream iss(output);
|
||||
std::string line;
|
||||
|
||||
std::string currentName;
|
||||
while (std::getline(iss, line)) {
|
||||
// A blank line ends the current package block.
|
||||
if (line.empty()) {
|
||||
currentName.clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t colon = line.find(':');
|
||||
if (colon == std::string::npos) continue;
|
||||
|
||||
std::string field = line.substr(0, colon);
|
||||
// Trim trailing whitespace from the label (labels are padded to align).
|
||||
while (!field.empty() && field.back() == ' ') field.pop_back();
|
||||
|
||||
std::string value = line.substr(colon + 1);
|
||||
// Trim leading whitespace from the value.
|
||||
size_t start = value.find_first_not_of(" \t");
|
||||
if (start != std::string::npos) {
|
||||
value = value.substr(start);
|
||||
}
|
||||
|
||||
if (field == "Name") {
|
||||
currentName = value;
|
||||
} else if (field == "Installed Size" && !currentName.empty()) {
|
||||
sizes[currentName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
// Parse `pacman -Sl` output ("repo name version" per sync-DB package) into a map of
|
||||
// package name -> repository, so the origin of each installed package can be shown.
|
||||
std::map<std::string, std::string> PacmanManager::parseSyncRepos(
|
||||
const std::string& output) {
|
||||
std::map<std::string, std::string> repos;
|
||||
std::istringstream iss(output);
|
||||
std::string line;
|
||||
|
||||
bool firstLine = true;
|
||||
while (std::getline(iss, line)) {
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
continue; // Skip the "Repository Name Version" header.
|
||||
}
|
||||
if (line.empty()) continue;
|
||||
|
||||
std::istringstream ls(line);
|
||||
std::string repo;
|
||||
std::string name;
|
||||
if (!(ls >> repo >> name)) continue;
|
||||
|
||||
repos[name] = repo;
|
||||
}
|
||||
|
||||
return repos;
|
||||
}
|
||||
@@ -36,12 +36,57 @@ static void testParseInstalledOutput_emptyInput() {
|
||||
assert(pkgs.empty());
|
||||
}
|
||||
|
||||
static void testParseInstalledSizes_parsesBlocks() {
|
||||
std::string output =
|
||||
"Name : firefox\n"
|
||||
"Version : 128.0-1\n"
|
||||
"Installed Size : 263.47 MiB\n"
|
||||
"Install Date : 2026-01-01\n"
|
||||
"\n"
|
||||
"Name : vim\n"
|
||||
"Installed Size : 12.3 MiB\n";
|
||||
|
||||
auto sizes = PacmanManager::parseInstalledSizes(output);
|
||||
|
||||
assert(sizes.size() == 2);
|
||||
assert(sizes["firefox"] == "263.47 MiB");
|
||||
assert(sizes["vim"] == "12.3 MiB");
|
||||
}
|
||||
|
||||
static void testParseInstalledSizes_emptyInput() {
|
||||
assert(PacmanManager::parseInstalledSizes("").empty());
|
||||
}
|
||||
|
||||
static void testParseSyncRepos_skipsHeader() {
|
||||
std::string output =
|
||||
"Repository Name Version\n"
|
||||
"core linux 6.6-1\n"
|
||||
"extra firefox 128.0-1\n"
|
||||
"multilib gcc-libs 13.2-1\n";
|
||||
|
||||
auto repos = PacmanManager::parseSyncRepos(output);
|
||||
|
||||
assert(repos.size() == 3);
|
||||
assert(repos["linux"] == "core");
|
||||
assert(repos["firefox"] == "extra");
|
||||
assert(repos["gcc-libs"] == "multilib");
|
||||
}
|
||||
|
||||
static void testParseSyncRepos_emptyInput() {
|
||||
assert(PacmanManager::parseSyncRepos("").empty());
|
||||
}
|
||||
|
||||
int main() {
|
||||
testParseInstalledOutput_parsesSimpleLines();
|
||||
testParseInstalledOutput_keepsHyphensInNames();
|
||||
testParseInstalledOutput_skipsEmptyLines();
|
||||
testParseInstalledOutput_emptyInput();
|
||||
|
||||
testParseInstalledSizes_parsesBlocks();
|
||||
testParseInstalledSizes_emptyInput();
|
||||
testParseSyncRepos_skipsHeader();
|
||||
testParseSyncRepos_emptyInput();
|
||||
|
||||
std::cout << "All pacman-manager tests passed." << std::endl;
|
||||
return 0;
|
||||
}
|
||||