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

+27
View File
@@ -1,5 +1,6 @@
#include "app-core.h"
#include <QDateTime>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
@@ -1194,10 +1195,36 @@ QString AppCore::packageDetails(const PackageInfo& pkg) {
// ---------------------------------------------------------------------------
bool AppCore::shouldCheckForAppUpdate() const {
if (!appUpdateCheckRefusal().isEmpty()) return false;
return m_update->shouldCheck();
}
QString AppCore::appUpdateCheckRefusal() const {
AppSettings& preferences = AppSettings::instance();
// The user parked the app's own updates: no automatic check, and the manual
// one says why instead of quietly doing nothing.
if (preferences.updatesBlocked()) {
return AppSettings::blockDescription(
preferences.updatesBlockedIndefinitely(), preferences.updateBlockedUntil(),
QDateTime::currentDateTime());
}
if (!preferences.autoUpdateCheckEnabled()) {
return QStringLiteral(
"La vérification automatique des mises à jour est désactivée dans "
"les paramètres.");
}
return QString();
}
void AppCore::checkForAppUpdate() {
const QString refusal = appUpdateCheckRefusal();
if (!refusal.isEmpty()) {
LogManager::instance().logEvent(QStringLiteral("maj-app"), refusal);
emit statusMessage(refusal);
return;
}
LogManager::instance().logEvent(QStringLiteral("maj-app"),
QStringLiteral("vérification de version"));
emit statusMessage(QStringLiteral("Vérification des mises à jour..."));
+242
View File
@@ -0,0 +1,242 @@
#include "app-settings.h"
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QSettings>
#include <QStandardPaths>
namespace {
// Below this a cap would rotate the journal on practically every line, which
// makes the "previous journal" LogManager keeps useless.
constexpr qint64 kMinLogMaxBytes = 64 * 1024;
QString key(const char* name) {
return QStringLiteral("settings/") + QString::fromLatin1(name);
}
} // namespace
AppSettings& AppSettings::instance() {
// Function-local static: created once, thread-safe since C++11.
static AppSettings settings;
return settings;
}
AppSettings::AppSettings(QObject* parent) : QObject(parent) {
loadUpdateBlock();
}
// ---------------------------------------------------------------------------
// Journal
// ---------------------------------------------------------------------------
QString AppSettings::defaultLogDirectory() {
const QString dir = QStandardPaths::writableLocation(
QStandardPaths::AppConfigLocation);
if (!dir.isEmpty()) {
QDir(dir).mkpath(".");
return dir;
}
return QDir::homePath() + QStringLiteral("/.config/PacManager");
}
QString AppSettings::sanitizeLogDirectory(const QString& directory) {
QString path = directory.trimmed();
if (path.isEmpty()) return defaultLogDirectory();
// The dialog hands back a native path, but a hand-edited setting may still
// start with "~" — which no other API in the app would expand.
if (path == QLatin1String("~")) {
path = QDir::homePath();
} else if (path.startsWith(QLatin1String("~/"))) {
path = QDir::homePath() + path.mid(1);
}
const QString clean = QDir::cleanPath(QFileInfo(path).absoluteFilePath());
return clean.isEmpty() ? defaultLogDirectory() : clean;
}
QString AppSettings::logDirectory() const {
QSettings settings;
return sanitizeLogDirectory(settings.value(key("logDirectory")).toString());
}
void AppSettings::setLogDirectory(const QString& directory) {
const QString wanted = sanitizeLogDirectory(directory);
// Compared with what is in force *before* writing: comparing with the
// stored value afterwards would always match, and every setter would
// announce a change that did not happen.
if (wanted == logDirectory()) return;
QSettings settings;
// Back to the default: remove the key rather than pinning the current
// default path, which would survive a change of XDG_CONFIG_HOME.
if (wanted == defaultLogDirectory()) {
settings.remove(key("logDirectory"));
} else {
settings.setValue(key("logDirectory"), wanted);
}
emit logDirectoryChanged(wanted);
}
qint64 AppSettings::sanitizeLogMaxBytes(qint64 bytes) {
if (bytes <= 0) return 0;
if (bytes < kMinLogMaxBytes) return kMinLogMaxBytes;
return bytes;
}
qint64 AppSettings::logMaxBytes() const {
QSettings settings;
return sanitizeLogMaxBytes(settings.value(key("logMaxBytes"), 0).toLongLong());
}
void AppSettings::setLogMaxBytes(qint64 bytes) {
const qint64 wanted = sanitizeLogMaxBytes(bytes);
if (wanted == logMaxBytes()) return;
QSettings settings;
if (wanted == 0) settings.remove(key("logMaxBytes"));
else settings.setValue(key("logMaxBytes"), wanted);
emit logMaxBytesChanged(wanted);
}
// ---------------------------------------------------------------------------
// Drag & drop
// ---------------------------------------------------------------------------
bool AppSettings::dragDropEnabled() const {
QSettings settings;
// On by default: dropping a .flatpakref on the window is the quickest way
// to install it, so turning it off has to be a deliberate act.
return settings.value(key("dragDrop"), true).toBool();
}
void AppSettings::setDragDropEnabled(bool enabled) {
if (enabled == dragDropEnabled()) return;
QSettings settings;
settings.setValue(key("dragDrop"), enabled);
emit dragDropEnabledChanged(enabled);
}
// ---------------------------------------------------------------------------
// Language
// ---------------------------------------------------------------------------
QStringList AppSettings::knownLanguages() {
return {QStringLiteral("fr"), QStringLiteral("en")};
}
QString AppSettings::sanitizeLanguage(const QString& code) {
const QString wanted = code.trimmed().toLower();
// Nothing stored means "follow the desktop", which is what a fresh install
// gets; an unknown code is not the desktop, it is a mistake.
if (wanted.isEmpty() || wanted == QLatin1String("system")) {
return QStringLiteral("system");
}
return knownLanguages().contains(wanted) ? wanted : QStringLiteral("fr");
}
QString AppSettings::language() const {
QSettings settings;
return sanitizeLanguage(settings.value(key("language")).toString());
}
void AppSettings::setLanguage(const QString& code) {
const QString wanted = sanitizeLanguage(code);
if (wanted == language()) return;
QSettings settings;
settings.setValue(key("language"), wanted);
emit languageChanged(wanted);
}
// ---------------------------------------------------------------------------
// Application updates
// ---------------------------------------------------------------------------
bool AppSettings::autoUpdateCheckEnabled() const {
QSettings settings;
return settings.value(key("autoUpdateCheck"), true).toBool();
}
void AppSettings::setAutoUpdateCheckEnabled(bool enabled) {
if (enabled == autoUpdateCheckEnabled()) return;
QSettings settings;
settings.setValue(key("autoUpdateCheck"), enabled);
emit autoUpdateCheckEnabledChanged(enabled);
}
QDateTime AppSettings::blockTarget(const QDateTime& now, int hours) {
if (hours <= 0) return QDateTime();
// Second precision, which is all a snooze needs and is exactly what
// survives the round trip through the settings file: a deadline rebuilt
// from it therefore compares equal to the one that was written.
const QDateTime end = now.addSecs(static_cast<qint64>(hours) * 3600);
return QDateTime::fromSecsSinceEpoch(end.toSecsSinceEpoch());
}
bool AppSettings::isBlocked(const QDateTime& now, bool indefinite, const QDateTime& until) {
if (indefinite) return true;
return until.isValid() && now < until;
}
void AppSettings::loadUpdateBlock() {
QSettings settings;
m_blockIndefinite = settings.value(key("updateBlockIndefinite"), false).toBool();
m_blockUntil = QDateTime::fromString(
settings.value(key("updateBlockUntil")).toString(), Qt::ISODate);
// A stored date that no longer parses is dropped rather than believed: an
// unreadable "until" must never keep the user from checking again.
if (m_blockUntil.isNull()) m_blockUntil = QDateTime();
}
void AppSettings::saveUpdateBlock() {
QSettings settings;
settings.setValue(key("updateBlockIndefinite"), m_blockIndefinite);
if (m_blockUntil.isValid()) {
settings.setValue(key("updateBlockUntil"), m_blockUntil.toString(Qt::ISODate));
} else {
settings.remove(key("updateBlockUntil"));
}
}
void AppSettings::blockUpdatesFor(int hours) {
m_blockIndefinite = hours <= 0;
m_blockUntil = blockTarget(QDateTime::currentDateTime(), hours);
saveUpdateBlock();
emit updateBlockChanged();
}
void AppSettings::unblockUpdates() {
m_blockIndefinite = false;
m_blockUntil = QDateTime();
saveUpdateBlock();
emit updateBlockChanged();
}
QString AppSettings::blockDescription(bool indefinite, const QDateTime& until,
const QDateTime& now) {
if (indefinite) {
return QCoreApplication::translate(
"AppSettings", "Mises à jour bloquées jusqu'à annulation.");
}
if (!until.isValid() || now >= until) return QString();
const qint64 seconds = until.secsTo(now);
const qint64 hours = seconds / 3600;
if (hours >= 24) {
const qint64 days = hours / 24;
return QCoreApplication::translate("AppSettings", "Mises à jour bloisées encore %1 jour(s).")
.arg(days);
}
if (hours >= 1) {
return QCoreApplication::translate("AppSettings", "Mises à jour bloisées encore %1 heure(s).")
.arg(hours);
}
return QCoreApplication::translate("AppSettings", "Mises à jour bloisées encore %1 minute(s).")
.arg(qMax<qint64>(1, seconds / 60));
}
+111
View File
@@ -0,0 +1,111 @@
#include "language-manager.h"
#include "app-settings.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDir>
#include <QEvent>
#include <QFile>
#include <QLocale>
#include <QStandardPaths>
#include <QTranslator>
#include <QWidget>
namespace {
// Kept alive for the whole process: a QTranslator that is destroyed takes the
// installed translation with it.
QTranslator* g_translator = nullptr;
QString catalogueFileName(const QString& code) {
return QStringLiteral("translations/pacmanager_%1.qm").arg(code);
}
} // namespace
QStringList LanguageManager::searchPaths() {
QStringList paths;
// Next to the settings the user just chose: where a catalogue installed by
// hand (or by a future in-app translation pack) belongs.
paths << AppSettings::instance().logDirectory() + QStringLiteral("/translations");
const QString data = QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation);
if (!data.isEmpty()) paths << data + QStringLiteral("/translations");
// Running from a build tree, the catalogues sit beside the binary.
paths << QCoreApplication::applicationDirPath() + QStringLiteral("/translations");
QStringList existing;
for (const QString& path : paths) {
if (QDir(path).exists()) existing << path;
}
return existing;
}
QString LanguageManager::resolve(const QString& code) {
const QString wanted = AppSettings::sanitizeLanguage(code);
if (wanted != QLatin1String("system")) return wanted;
// "system" follows the desktop, but only into a language the app knows: a
// desktop set to Esperanto should leave the interface in its own language
// rather than install nothing at all.
const QString locale = QLocale::system().name().left(2);
if (AppSettings::knownLanguages().contains(locale)) return locale;
return QStringLiteral("fr");
}
bool LanguageManager::isTranslationAvailable(const QString& code) {
const QString resolved = resolve(code);
const QString fileName = catalogueFileName(resolved);
for (const QString& path : searchPaths()) {
if (QFile::exists(path + QLatin1Char('/') + fileName)) return true;
}
return false;
}
QString LanguageManager::searchPathHint() {
return searchPaths().isEmpty() ? QString() : searchPaths().first();
}
QString LanguageManager::activeCode() {
return g_translator ? g_translator->language() : QString();
}
bool LanguageManager::apply(const QString& code) {
const QString resolved = resolve(code);
const QString fileName = catalogueFileName(resolved);
// The previous catalogue goes first, so a language the user just left does
// not keep translating part of the interface.
if (g_translator) {
QCoreApplication::removeTranslator(g_translator);
delete g_translator;
g_translator = nullptr;
}
bool installed = false;
for (const QString& path : searchPaths()) {
if (!g_translator) g_translator = new QTranslator();
if (g_translator->load(fileName, path)) {
QCoreApplication::installTranslator(g_translator);
installed = true;
break;
}
delete g_translator;
g_translator = nullptr;
}
// No catalogue (the common case today): the widgets still get the event, so
// switching back to an untranslated language restores the original wording
// instead of leaving the previous translation in place.
const QWidgetList widgets = QApplication::allWidgets();
for (QWidget* widget : widgets) {
QEvent event(QEvent::LanguageChange);
QCoreApplication::sendEvent(widget, &event);
}
return installed;
}
+77 -14
View File
@@ -1,8 +1,11 @@
#include "log-manager.h"
#include "app-settings.h"
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QLoggingCategory>
#include <QStandardPaths>
#include <QStringBuilder>
@@ -14,24 +17,24 @@
namespace {
// Where the plain text history of what the app did lives on any desktop
// session, inside the user's own data tree (so a Flatpak-sandboxed build still
// finds it in ~/.local/share).
QString logDirectory() {
const QString dir = QStandardPaths::writableLocation(
QStandardPaths::AppConfigLocation);
if (!dir.isEmpty()) {
QDir(dir).mkpath(".");
return dir;
}
return QDir::homePath() + QStringLiteral("/.config/PacManager");
}
// The journal's file name, and the one its rotated copy gets.
constexpr auto kLogFileName = "operations.log";
constexpr auto kBackupFileName = "operations.log.1";
QString currentTimestamp() {
return QDateTime::currentDateTime().toString(
QStringLiteral("yyyy-MM-dd hh:mm:ss"));
}
// Renames `path` onto `target`, replacing whatever was there. Journal rotation
// and the move to a new directory both want that, and Qt refuses to overwrite
// otherwise.
bool replaceFile(const QString& path, const QString& target) {
if (!QFile::exists(path)) return true;
if (QFile::exists(target) && !QFile::remove(target)) return false;
return QFile::rename(path, target);
}
} // namespace
LogManager& LogManager::instance() {
@@ -41,16 +44,77 @@ LogManager& LogManager::instance() {
}
LogManager::LogManager(QObject* parent) : QObject(parent) {
m_filePath = logDirectory() + QStringLiteral("/") + QStringLiteral("operations.log");
// Subscribing before the first write means the journal is opened where the
// user asked, not where it was asked to open.
AppSettings& settings = AppSettings::instance();
connect(&settings, &AppSettings::logDirectoryChanged, this,
[this](const QString&) { applySettings(); });
applySettings();
}
QString LogManager::filePath() const {
QMutexLocker lock(&m_mutex);
return m_filePath;
}
QString LogManager::backupFilePath() {
return AppSettings::instance().logDirectory() + QLatin1Char('/') +
QLatin1String(kBackupFileName);
}
qint64 LogManager::currentSizeBytes() const {
QMutexLocker lock(&m_mutex);
return QFileInfo(m_filePath).size();
}
// Puts the journal where AppSettings says, carrying the existing file along so
// switching directory does not silently start an empty log.
void LogManager::applySettings() {
const QString directory = AppSettings::instance().logDirectory();
const QString wanted = directory + QLatin1Char('/') + QLatin1String(kLogFileName);
// A directory that cannot be created is reported by the absence of the
// journal on the Settings screen, not by throwing here.
if (!QDir().mkpath(directory)) return;
QString previous;
{
QMutexLocker lock(&m_mutex);
if (wanted == m_filePath) return;
previous = m_filePath;
if (m_file) {
std::fclose(m_file);
m_file = nullptr;
}
m_filePath = wanted;
}
// Carried over only when the target has no journal of its own: a directory
// that already has one is not overwritten. Done without the lock, which
// write() takes for itself.
if (!previous.isEmpty()) {
replaceFile(previous, wanted);
}
write(QStringLiteral("[%1] [config] journal → %2\n")
.arg(currentTimestamp(), wanted));
}
void LogManager::write(const QString& text) {
QMutexLocker lock(&m_mutex);
const QByteArray bytes = text.toUtf8();
// Rotation before the write, so the cap really is a ceiling. One previous
// journal is kept; the one before it is dropped.
const qint64 cap = AppSettings::instance().logMaxBytes();
if (cap > 0 && QFileInfo(m_filePath).size() + bytes.size() > cap) {
if (m_file) {
std::fclose(m_file);
m_file = nullptr;
}
replaceFile(m_filePath, m_filePath + QLatin1String(".1"));
}
// Append mode, opened lazily and kept open: a long session keeps growing and
// the file is never truncated while the app runs.
if (!m_file) {
@@ -58,7 +122,6 @@ void LogManager::write(const QString& text) {
if (!m_file) return;
}
const QByteArray bytes = text.toUtf8();
std::fputs(bytes.constData(), m_file);
// Flushed line by line so the journal survives a crash: the last thing the
// app did is exactly what the user wants to read after one.
+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() {
+8
View File
@@ -3,6 +3,8 @@
#include <QStringList>
#include <QTimer>
#include "app-settings.h"
#include "language-manager.h"
#include "log-manager.h"
#include "main-window.h"
#include "update-manager.h"
@@ -17,11 +19,17 @@ int main(int argc, char* argv[]) {
// into the journal, so the Logs screen shows the same detail as a debug run
// without the user having to set QT_LOGGING_RULES.
QLoggingCategory::setFilterRules(QStringLiteral("pacmgr.*=true"));
// The journal opens where the user asked it to, not where the previous
// release wrote it: AppSettings is read before the first line is written.
LogManager::installQtMessageHandler();
LogManager::instance().logEvent(
QStringLiteral("app"),
QStringLiteral("session démarrée (v%1)").arg(UpdateManager::currentVersion()));
// The chosen catalogue is installed before any widget exists, so the whole
// interface is built in the right language from the start.
LanguageManager::apply(AppSettings::instance().language());
MainWindow window;
window.setWindowTitle("PacManager - Gestionnaire de Paquets");
window.resize(1200, 760);