feat(settings): add a dedicated screen for every user preference

The preferences used to be spread across a menu entry and hardcoded paths,
so the user could not see them, let alone change them: where the journal
goes, whether a dropped Flatpak file is accepted, and when the app checks
its own version were all decided in code.

They now live in AppSettings, one model the rest of the app already reads,
and the new Settings screen only writes to it. Nothing keeps a second copy
of a value, so a change is visible everywhere at once — switching directory
moves the journal, unchecking drag & drop makes the window refuse the drop,
blocking the update has the manual check say why instead of silently doing
nothing.

The update block is deliberately limited to PacManager itself: blocking a
system package update is a decision the app has no business making.

The language setting installs a Qt catalogue and asks every widget to
retranslate. The interface is still written in French with QStringLiteral,
so no catalogue ships yet; a language with none is shown in the list but
disabled rather than silently doing nothing, and Qt Linguist stays optional
so the build does not depend on it.
This commit is contained in:
BlackAngelTV committed 2026-09-28 20:44:21 +02:00
1 parent ed8185d5fe
commit aff959bc4b
27 files changed
+1906 -27

No files matched your search

+140 -4
View File
@@ -37,9 +37,11 @@
#include "cleanup-page.h"
#include "dashboard-page.h"
#include "history-page.h"
#include "language-manager.h"
#include "logs-page.h"
#include "page.h"
#include "plugins-page.h"
#include "settings-page.h"
// How long a wait reads best in the status bar: "45 s", "2 min 05", "1 h 03".
static QString formatElapsed(qint64 ms) {
@@ -236,6 +238,23 @@ static QString appStyleSheet() {
" color: #e2e8f0;"
"}"
"QComboBox:hover { border-color: #7dd3fc; }"
// ---- Settings screen ----
// The cards scroll as a whole: the area itself must not paint, or the
// page gradient would be cut off at its edges.
"QScrollArea { background: transparent; border: none; }"
"QScrollArea > QWidget > QWidget { background: transparent; }"
// Explanatory text under each control, in the site's secondary colour.
"QLabel#settingHint { font-size: 12px; color: #94a3b8; }"
"QCheckBox { font-size: 13px; color: #e2e8f0; spacing: 8px; }"
"QCheckBox::indicator {"
" width: 18px; height: 18px;"
" border: 1px solid #475569; border-radius: 5px; background: #1e293b;"
"}"
"QCheckBox::indicator:hover { border-color: #7dd3fc; }"
"QCheckBox::indicator:checked {"
" background: #38bdf8; border-color: #38bdf8;"
" image: url(:/icons/check-dark.svg);"
"}"
"QComboBox::drop-down { border: none; width: 26px; }"
"QComboBox QAbstractItemView {"
" background: #273449;"
@@ -353,6 +372,15 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) {
connect(m_core, &AppCore::selfUpdateFinished, this,
&MainWindow::onCoreSelfUpdateFinished);
// The preferences the window reacts to rather than merely reads: dropping a
// file and switching language are both things the user does on the Settings
// screen and expects to see take effect at once.
AppSettings& preferences = AppSettings::instance();
connect(&preferences, &AppSettings::dragDropEnabledChanged, this,
&MainWindow::onDragDropEnabledChanged);
connect(&preferences, &AppSettings::languageChanged, this,
&MainWindow::onLanguageChanged);
setupUI();
setupMenuBar();
setupTray();
@@ -435,8 +463,9 @@ void MainWindow::setupUI() {
statusBar()->showMessage("Prêt");
// Flatpak files can be dropped anywhere on the window (see dragEnterEvent).
setAcceptDrops(true);
// Flatpak files can be dropped anywhere on the window (see dragEnterEvent),
// unless the user turned that off on the Settings screen.
setAcceptDrops(AppSettings::instance().dragDropEnabled());
// Progress of the running operation, anchored at the bottom of the window
// so it takes no space on the screens. It appears while install/update/
@@ -515,6 +544,7 @@ void MainWindow::setupSidebar() {
btn->setIcon(loadIcon(iconName));
btn->setIconSize(QSize(17, 17));
m_navGroup->addButton(btn, id);
m_navButtons.insert(id, btn);
layout->addWidget(btn);
return btn;
};
@@ -532,6 +562,8 @@ void MainWindow::setupSidebar() {
addNavButton(NavHistory, "history", "Historique", "Historique des actions");
addNavButton(NavLogs, "logs", "Logs", "Logs pacman");
addNavButton(NavPlugins, "plugin", "Plugins", "Gestionnaires de paquets et extensions");
addNavButton(NavSettings, "settings", "Paramètres",
"Journal, glisser-déposer, langue et mises à jour");
connect(m_navGroup, &QButtonGroup::idClicked, this, &MainWindow::onNavChanged);
m_navGroup->button(NavDashboard)->setChecked(true);
@@ -621,6 +653,11 @@ void MainWindow::setupPages() {
m_plugins = new PluginsPage(m_core);
registerPage("plugins", NavPlugins, m_plugins);
m_settings = new SettingsPage(m_core);
registerPage("settings", NavSettings, m_settings);
connect(m_settings, &Page::credentialModeRequested, this,
&MainWindow::onCredentialModeRequested);
}
void MainWindow::registerPage(const QString& id, int navId, Page* page) {
@@ -660,6 +697,7 @@ void MainWindow::updateStatusBar() {
void MainWindow::setUpdatesBadge(int count) {
if (!m_navUpdatesButton) return;
m_updatesBadgeCount = count;
m_navUpdatesButton->setText(count > 0
? QString("Mises à jour · %1").arg(count)
@@ -716,6 +754,7 @@ void MainWindow::setupMenuBar() {
toolsMenu->addAction("Historique", this, [this, goTo] { goTo(NavHistory); });
toolsMenu->addAction("Logs pacman", this, [this, goTo] { goTo(NavLogs); });
toolsMenu->addAction("Plugins", this, [this, goTo] { goTo(NavPlugins); });
toolsMenu->addAction("Paramètres", this, [this, goTo] { goTo(NavSettings); });
toolsMenu->addSeparator();
toolsMenu->addAction("Prévisualiser les mises à jour", this, [this, goTo] {
goTo(NavUpdates);
@@ -725,6 +764,12 @@ void MainWindow::setupMenuBar() {
QMenu* settingsMenu = menuBar->addMenu("Paramètres");
// The dedicated screen holds every preference; the two entries below are
// shortcuts to the one that would otherwise be a menu of its own.
settingsMenu->addAction("Ouvrir les paramètres", this,
[this, goTo] { goTo(NavSettings); });
settingsMenu->addSeparator();
QActionGroup* credGroup = new QActionGroup(this);
credGroup->setExclusive(true);
@@ -746,9 +791,9 @@ void MainWindow::setupMenuBar() {
(atLaunch ? m_credLaunchAction : m_credEachTimeAction)->setChecked(true);
connect(m_credEachTimeAction, &QAction::triggered, this,
[this]() { applyCredentialMode(AppCore::CredentialMode::EachTime); });
[this]() { onCredentialModeRequested(false); });
connect(m_credLaunchAction, &QAction::triggered, this,
[this]() { applyCredentialMode(AppCore::CredentialMode::AtLaunch); });
[this]() { onCredentialModeRequested(true); });
QMenu* helpMenu = menuBar->addMenu("Aide");
helpMenu->addAction("Vérifier les mises à jour", this, &MainWindow::onCheckForUpdates);
@@ -806,6 +851,10 @@ void MainWindow::setupShortcuts() {
bind(QKeySequence(QStringLiteral("Ctrl+U")), [this]() {
m_navGroup->button(NavUpdates)->click();
});
// The convention every other application uses for its own settings.
bind(QKeySequence(QStringLiteral("Ctrl+,")), [this]() {
m_navGroup->button(NavSettings)->click();
});
bind(QKeySequence(QStringLiteral("Ctrl+E")), [this]() {
LogManager::instance().logEvent(QStringLiteral("ui"),
QStringLiteral("export de la liste affichée"));
@@ -831,6 +880,7 @@ void MainWindow::onNavChanged(int id) {
case NavHistory: pageName = QStringLiteral("historique"); break;
case NavLogs: pageName = QStringLiteral("logs"); break;
case NavPlugins: pageName = QStringLiteral("plugins"); break;
case NavSettings: pageName = QStringLiteral("paramètres"); break;
default: break;
}
LogManager::instance().logEvent(
@@ -871,6 +921,10 @@ void MainWindow::onNavChanged(int id) {
m_pages->setCurrentWidget(m_plugins);
m_plugins->refresh();
break;
case NavSettings:
m_pages->setCurrentWidget(m_settings);
m_settings->refresh();
break;
default:
break;
}
@@ -907,6 +961,7 @@ void MainWindow::onPageMessage(const QString& text) {
QStringList MainWindow::installableDroppedFiles(const QMimeData* mimeData) const {
QStringList files;
if (!AppSettings::instance().dragDropEnabled()) return files;
if (!mimeData || !mimeData->hasUrls()) return files;
for (const QUrl& url : mimeData->urls()) {
@@ -1063,6 +1118,87 @@ void MainWindow::applyCredentialMode(AppCore::CredentialMode mode) {
if (mode == AppCore::CredentialMode::AtLaunch) promptForSudoPassword();
}
// One place answers a change of mode, whichever of the two entry points (the
// menu bar, the Settings screen) asked for it, so both end up in step.
void MainWindow::onCredentialModeRequested(bool atLaunch) {
applyCredentialMode(atLaunch ? AppCore::CredentialMode::AtLaunch
: AppCore::CredentialMode::EachTime);
(atLaunch ? m_credLaunchAction : m_credEachTimeAction)->setChecked(true);
}
void MainWindow::onLanguageChanged(const QString& code) {
LogManager::instance().logEvent(QStringLiteral("config"),
QStringLiteral("langue → %1").arg(code));
// Qt asks every widget to retranslate itself through the LanguageChange
// event, which this window answers in changeEvent().
LanguageManager::apply(code);
}
void MainWindow::onDragDropEnabledChanged(bool enabled) {
// The preference governs the window's own drop target only: files handed
// over by the desktop ("Ouvrir avec PacManager") keep working either way.
setAcceptDrops(enabled);
LogManager::instance().logEvent(
QStringLiteral("config"),
QStringLiteral("glisser-déposer → %1")
.arg(enabled ? QStringLiteral("activé") : QStringLiteral("désactivé")));
}
void MainWindow::retranslateUI() {
// The screens provide their own title, so the header follows them.
updatePageTitle();
if (m_versionLabel) {
m_versionLabel->setText(QStringLiteral("v%1").arg(UpdateManager::currentVersion()));
}
struct NavLabel { int id; const char* text; const char* tip; };
// Kept next to the sidebar: those strings are the frame's, and the screens
// below retranslate themselves.
static const NavLabel kNavLabels[] = {
{NavDashboard, QT_TRANSLATE_NOOP("MainWindow", "Tableau de bord"),
QT_TRANSLATE_NOOP("MainWindow", "Vue d'ensemble du système")},
{NavSearch, QT_TRANSLATE_NOOP("MainWindow", "Recherche"),
QT_TRANSLATE_NOOP("MainWindow", "Rechercher des paquets")},
{NavInstalled, QT_TRANSLATE_NOOP("MainWindow", "Installés"),
QT_TRANSLATE_NOOP("MainWindow", "Voir les paquets installés")},
{NavUpdates, QT_TRANSLATE_NOOP("MainWindow", "Mises à jour"),
QT_TRANSLATE_NOOP("MainWindow", "Voir les mises à jour disponibles")},
{NavCleanup, QT_TRANSLATE_NOOP("MainWindow", "Nettoyage"),
QT_TRANSLATE_NOOP("MainWindow", "Purger les paquets inutilisés ou legacy et vider les caches")},
{NavHistory, QT_TRANSLATE_NOOP("MainWindow", "Historique"),
QT_TRANSLATE_NOOP("MainWindow", "Historique des actions")},
{NavLogs, QT_TRANSLATE_NOOP("MainWindow", "Logs"),
QT_TRANSLATE_NOOP("MainWindow", "Logs pacman")},
{NavPlugins, QT_TRANSLATE_NOOP("MainWindow", "Plugins"),
QT_TRANSLATE_NOOP("MainWindow", "Gestionnaires de paquets et extensions")},
{NavSettings, QT_TRANSLATE_NOOP("MainWindow", "Paramètres"),
QT_TRANSLATE_NOOP("MainWindow", "Journal, glisser-déposer, langue et mises à jour")},
};
for (const NavLabel& label : kNavLabels) {
auto it = m_navButtons.find(label.id);
if (it == m_navButtons.end()) continue;
// The updates entry carries its pending count in its label, which
// setUpdatesBadge() is the one to rebuild.
if (label.id != NavUpdates) it.value()->setText(tr(label.text));
it.value()->setToolTip(tr(label.tip));
}
setUpdatesBadge(m_updatesBadgeCount);
if (m_refreshButton) m_refreshButton->setText(tr("Rafraîchir les sources"));
if (m_headerUpdateAllButton) {
m_headerUpdateAllButton->setText(tr("Tout mettre à jour"));
}
}
void MainWindow::changeEvent(QEvent* event) {
if (event->type() == QEvent::LanguageChange) {
retranslateUI();
}
QMainWindow::changeEvent(event);
}
// The core knows *when* a password is needed (it owns the credential state and
// the sudo pipeline); the frame only owns the dialog.
bool MainWindow::promptForSudoPassword() {