diff --git a/include/main-window.h b/include/main-window.h index 1754de1..93ac1f0 100644 --- a/include/main-window.h +++ b/include/main-window.h @@ -202,6 +202,9 @@ private: void updateStatusBar(); void refreshDashboard(); void refreshRecentActivity(); + // Mirrors the pending update count on the sidebar entry, so the page that + // needs attention is visible from wherever the user is. + void setUpdatesBadge(int count); void refreshPluginsTable(); void updatePackageInfo(const PackageInfo& pkg); std::string richDetails(const PackageInfo& pkg); @@ -233,12 +236,15 @@ private: void setupShortcuts(); void notifyUpdatesAvailable(int count); QFrame* makeCard(); - QFrame* makeStatCard(const QString& iconName, const QString& title, QLabel** valueOut); + QFrame* makeStatCard(const QString& iconName, const QString& title, + const QString& accent, QLabel** valueOut); // Sidebar QFrame* m_sidebar = nullptr; QButtonGroup* m_navGroup = nullptr; QPushButton* m_refreshButton = nullptr; + QPushButton* m_navUpdatesButton = nullptr; + QLabel* m_versionLabel = nullptr; // Header QWidget* m_headerWidget = nullptr; @@ -271,6 +277,8 @@ private: // of the window while any install/search runs. QProgressBar* m_installProgressBar = nullptr; QTableWidget* m_packageTable = nullptr; + // Listing + empty-state hint, swapped depending on the row count. + QStackedWidget* m_packageTableStack = nullptr; QLabel* m_packageName = nullptr; QLabel* m_packageVersion = nullptr; QLabel* m_packageRepo = nullptr; @@ -299,6 +307,7 @@ private: // Cleanup page QTableWidget* m_cleanupTable = nullptr; + QStackedWidget* m_cleanupTableStack = nullptr; QLabel* m_cleanupCount = nullptr; QPushButton* m_cleanupRemoveOrphansButton = nullptr; QPushButton* m_cleanupRemoveSelectionButton = nullptr; diff --git a/src/main-window.cpp b/src/main-window.cpp index 45dc511..905bd85 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "app-logging.h" @@ -239,6 +240,32 @@ private: std::unique_ptr m_blocker; }; +// Wraps a listing in a stack that swaps in a centered hint while the listing is +// empty, so a page with no result explains itself instead of showing a bare +// table header. +static QStackedWidget* withEmptyState(QTableWidget* table, const QString& hint) { + QStackedWidget* stack = new QStackedWidget(); + stack->addWidget(table); + + QWidget* placeholder = new QWidget(); + QVBoxLayout* layout = new QVBoxLayout(placeholder); + layout->addStretch(); + QLabel* label = new QLabel(hint); + label->setAlignment(Qt::AlignCenter); + label->setWordWrap(true); + label->setStyleSheet( + "background: transparent; color: #565f73; font-size: 13px;"); + layout->addWidget(label); + layout->addStretch(); + stack->addWidget(placeholder); + return stack; +} + +// Swaps between the listing and its empty-state hint. +static void showEmptyState(QStackedWidget* stack, bool empty) { + if (stack) stack->setCurrentIndex(empty ? 1 : 0); +} + // 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) { @@ -408,12 +435,33 @@ void MainWindow::setupUI() { "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; }" + // Cards read as raised surfaces: a slightly lighter background, a hair + // line border and a rounded corner separate them from the page without + // adding shadows Qt cannot render consistently across platforms. + "QFrame#card {" + " background: #121722;" + " border: 1px solid #1d2432;" + " border-radius: 12px;" + "}" + // Stat cards carry a coloured left edge so the four metrics are told + // apart at a glance. + "QFrame#card[accent=\"blue\"] { border-left: 3px solid #7aa2f7; }" + "QFrame#card[accent=\"amber\"] { border-left: 3px solid #e0af68; }" + "QFrame#card[accent=\"cyan\"] { border-left: 3px solid #56b6c2; }" + "QFrame#card[accent=\"green\"] { border-left: 3px solid #3fb950; }" "QLabel#cardTitle { font-size: 11px; font-weight: 700; color: #7a8299; letter-spacing: 1px; }" - "QLabel#statValue { font-size: 30px; font-weight: 800; color: #ffffff; }" + "QLabel#statValue { font-size: 32px; font-weight: 800; color: #ffffff; }" "QLabel#statTitle { font-size: 12px; color: #7a8299; font-weight: 600; }" + // ---- Sidebar extras ---- + "QLabel#sectionTitle {" + " font-size: 10px;" + " font-weight: 800;" + " color: #4d5566;" + " letter-spacing: 1.2px;" + " padding: 14px 10px 2px 10px;" + "}" + "QLabel#versionLabel { font-size: 11px; color: #565f73; padding: 8px 10px; }" + "QPushButton[nav=\"true\"][highlighted=\"true\"] { color: #e0af68; }" // ---- Buttons ---- "QPushButton {" " background: #232b3a;" @@ -580,6 +628,12 @@ void MainWindow::setupSidebar() { m_navGroup = new QButtonGroup(this); m_navGroup->setExclusive(true); + auto addSection = [&](const QString& title) { + QLabel* label = new QLabel(title); + label->setObjectName("sectionTitle"); + layout->addWidget(label); + }; + auto addNavButton = [&](int id, const QString& iconName, const QString& text, const QString& tip) { QPushButton* btn = new QPushButton(text); @@ -594,13 +648,16 @@ void MainWindow::setupSidebar() { return btn; }; + addSection("GESTION"); 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"); + m_navUpdatesButton = addNavButton(NavUpdates, "arrow-up", "Mises à jour", + "Voir les mises à jour disponibles"); + + addSection("SYSTÈME"); 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"); @@ -617,6 +674,13 @@ void MainWindow::setupSidebar() { m_refreshButton->setToolTip("Rafraîchir les bases de données (pacman -Sy)"); connect(m_refreshButton, &QPushButton::clicked, this, &MainWindow::onRefresh); layout->addWidget(m_refreshButton); + + // The version actually installed, right where the user looks for it. + m_versionLabel = new QLabel(QString("v%1").arg(UpdateManager::currentVersion())); + m_versionLabel->setObjectName("versionLabel"); + m_versionLabel->setAlignment(Qt::AlignCenter); + m_versionLabel->setToolTip("Version installée de PacManager"); + layout->addWidget(m_versionLabel); } void MainWindow::setupHeader() { @@ -641,6 +705,21 @@ void MainWindow::setupHeader() { layout->addLayout(textLayout); layout->addStretch(); + + // The two actions used most often stay reachable from every page instead of + // only from the dashboard. + QPushButton* refreshBtn = new QPushButton("Rafraîchir"); + refreshBtn->setIcon(loadIcon("refresh")); + refreshBtn->setToolTip("Rafraîchir les bases de données (Ctrl+R)"); + connect(refreshBtn, &QPushButton::clicked, this, &MainWindow::onRefresh); + layout->addWidget(refreshBtn); + + QPushButton* updateAllBtn = new QPushButton("Tout mettre à jour"); + updateAllBtn->setProperty("variant", "warning"); + updateAllBtn->setIcon(loadIcon("arrow-up")); + updateAllBtn->setToolTip("Mettre à jour tous les paquets (Ctrl+U affiche la liste)"); + connect(updateAllBtn, &QPushButton::clicked, this, &MainWindow::onUpdateAll); + layout->addWidget(updateAllBtn); } void MainWindow::setupDashboardPage() { @@ -653,10 +732,14 @@ void MainWindow::setupDashboardPage() { // 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)); + statsRow->addWidget( + makeStatCard("package", "Paquets installés", "blue", &m_statInstalled)); + statsRow->addWidget( + makeStatCard("arrow-up", "Mises à jour dispo", "amber", &m_statUpdates)); + statsRow->addWidget( + makeStatCard("history", "Actions enregistrées", "cyan", &m_statHistory)); + statsRow->addWidget( + makeStatCard("tools", "Gestionnaire", "green", &m_statManager)); layout->addLayout(statsRow); // Quick actions @@ -878,7 +961,11 @@ void MainWindow::setupBrowsePage() { connect(m_packageTable, &QTableWidget::currentCellChanged, this, [this](int currentRow, int, int, int) { onPackageSelected(currentRow); }); - listLayout->addWidget(m_packageTable); + m_packageTableStack = withEmptyState( + m_packageTable, + "Aucun paquet à afficher.\nLancez une recherche ou ouvrez la liste des " + "paquets installés."); + listLayout->addWidget(m_packageTableStack); splitter->addWidget(listCard); // Right card: package details @@ -1176,7 +1263,10 @@ void MainWindow::setupCleanupPage() { 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); + m_cleanupTableStack = withEmptyState( + m_cleanupTable, + "Rien à nettoyer pour le moment.\nLancez une analyse pour vérifier."); + layout->addWidget(m_cleanupTableStack, 1); QHBoxLayout* buttonBar = new QHBoxLayout(); buttonBar->setSpacing(8); @@ -1440,8 +1530,10 @@ QFrame* MainWindow::makeCard() { } QFrame* MainWindow::makeStatCard(const QString& iconName, const QString& title, - QLabel** valueOut) { + const QString& accent, QLabel** valueOut) { QFrame* card = makeCard(); + // Read by the stylesheet rule that draws the coloured left edge. + card->setProperty("accent", accent); QVBoxLayout* layout = new QVBoxLayout(card); layout->setContentsMargins(18, 16, 18, 16); layout->setSpacing(6); @@ -1682,6 +1774,7 @@ void MainWindow::onRecentActivityClicked(QListWidgetItem* item) { void MainWindow::populatePackageTable(const std::vector& results) { m_currentResults = results; + showEmptyState(m_packageTableStack, results.empty()); { TableFillBatch batch(m_packageTable); m_packageTable->setRowCount(0); @@ -2079,6 +2172,7 @@ void MainWindow::onCleanupListFinished(std::vector results) { void MainWindow::populateCleanupTable(const std::vector& candidates) { m_cleanupCandidates = candidates; + showEmptyState(m_cleanupTableStack, candidates.empty()); QFont nameFont; nameFont.setWeight(QFont::DemiBold); @@ -2594,11 +2688,28 @@ void MainWindow::refreshDashboard() { m_lastNotifiedUpdates = static_cast(r.size()); notifyUpdatesAvailable(static_cast(r.size())); } + setUpdatesBadge(static_cast(r.size())); }); connect(upd, &ListWorker::finished, this, [upd] { upd->wait(); upd->deleteLater(); }); upd->start(); } +void MainWindow::setUpdatesBadge(int count) { + if (!m_navUpdatesButton) return; + + m_navUpdatesButton->setText(count > 0 + ? QString("Mises à jour · %1").arg(count) + : QString("Mises à jour")); + + // A dynamic property only takes effect once the style is re-applied, so it + // is only touched when it actually changes. + const bool highlighted = count > 0; + if (m_navUpdatesButton->property("highlighted").toBool() == highlighted) return; + m_navUpdatesButton->setProperty("highlighted", highlighted); + m_navUpdatesButton->style()->unpolish(m_navUpdatesButton); + m_navUpdatesButton->style()->polish(m_navUpdatesButton); +} + void MainWindow::refreshRecentActivity() { m_recentList->clear();