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

+12
View File
@@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#include "app-settings.h"
#include "history-manager.h"
#include "package-manager.h"
#include "pacman-manager.h"
@@ -64,6 +65,11 @@ public:
HistoryManager* history() const { return m_history; }
UpdateManager* updateManager() const { return m_update; }
PluginShop* shop() const { return m_shop; }
// User preferences (journal, drag & drop, language, update policy). The
// core reads them to decide whether a version check may run; the Settings
// screen writes them. Shared process-wide, hence the accessor rather than
// an owned member.
AppSettings* settings() const { return &AppSettings::instance(); }
std::vector<IPackageManager*> availableProviders() const;
QStringList availableProviderNames() const;
bool hasAvailableProvider() const;
@@ -156,8 +162,14 @@ public:
void removeShopPlugin(const QString& id);
// ---- Application self-update ----
// Whether a version check may run right now: the daily check is not asked
// for, the automatic check is off, or the user put the app's own updates on
// hold (see AppSettings).
bool shouldCheckForAppUpdate() const;
void checkForAppUpdate();
// Why checkForAppUpdate() would refuse, for the status bar and the Settings
// screen. Empty when a check may run.
QString appUpdateCheckRefusal() const;
bool canSelfUpdate() const;
UpdateManager::UpdateMethod updateMethod() const;
QString updateMethodDescription() const;
+111
View File
@@ -0,0 +1,111 @@
#pragma once
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QStringList>
// Every preference the Settings screen owns, gathered in one place and kept out
// of the widgets: where the journal is written and how big it may grow, the
// drag & drop switch, the language, and the application-update policy (automatic
// check, and the block the user can put on it).
//
// The credential mode deliberately stays in AppCore: it belongs to the
// privileged-operation state, not to this list.
//
// It is a singleton (like LogManager) because three unrelated moments need to
// read it — LogManager when it opens the journal, main() before any window
// exists (to install the translator), and the Settings screen — and a single
// object means a value changed in the screen is immediately what the rest of the
// app reads, with no second copy to keep in sync.
//
// Values live in QSettings (organisation "Freebuff", application "PacManager"),
// under the "settings/" prefix. Every setter signals, so LogManager, MainWindow
// and LanguageManager react instead of the app having to be restarted.
class AppSettings : public QObject {
Q_OBJECT
public:
// Process-wide settings, created on first use (thread-safe).
static AppSettings& instance();
explicit AppSettings(QObject* parent = nullptr);
// ---- Journal: where and how big ----
// Directory holding operations.log. Never empty: an unusable value falls
// back to defaultLogDirectory() rather than leaving the app without a
// journal.
QString logDirectory() const;
void setLogDirectory(const QString& directory);
// Where the journal lived before any preference was set: the user's own
// config tree, so it survives a sandbox rebuild (and a Flatpak build, where
// it resolves inside the sandbox home).
static QString defaultLogDirectory();
// Expands "~", cleans the path and rejects what is left empty, so a
// half-typed directory never breaks logging.
static QString sanitizeLogDirectory(const QString& directory);
// Size cap of the journal, 0 meaning unlimited. Writing past the cap rotates
// the file (LogManager keeps one previous journal).
qint64 logMaxBytes() const;
void setLogMaxBytes(qint64 bytes);
// A cap that would rotate on every line is a cap nobody wants, so anything
// positive below the floor is raised to it; a negative value means no cap.
static qint64 sanitizeLogMaxBytes(qint64 bytes);
// ---- Drag & drop of Flatpak files ----
bool dragDropEnabled() const;
void setDragDropEnabled(bool enabled);
// ---- Language ----
// "system" to follow the desktop, or one of knownLanguages(). Unknown codes
// fall back to "fr", the language the interface is written in.
QString language() const;
void setLanguage(const QString& code);
static QStringList knownLanguages();
static QString sanitizeLanguage(const QString& code);
// ---- Application updates (PacManager itself, not the system packages) ----
// Whether the version is checked on its own at launch, once a day.
bool autoUpdateCheckEnabled() const;
void setAutoUpdateCheckEnabled(bool enabled);
// Blocks every version check for `hours`; 0 blocks until the user unlocks
// it. Only the app's own update is affected: installing system package
// updates is never blocked.
void blockUpdatesFor(int hours);
void unblockUpdates();
bool updatesBlocked() const {
return isBlocked(QDateTime::currentDateTime(), m_blockIndefinite, m_blockUntil);
}
bool updatesBlockedIndefinitely() const { return m_blockIndefinite; }
// Invalid when the block has no scheduled end (not blocked, or blocked
// indefinitely).
QDateTime updateBlockedUntil() const { return m_blockUntil; }
// The two decisions above, as pure functions so the policy can be tested
// without a clock, a settings file or a running app.
static QDateTime blockTarget(const QDateTime& now, int hours);
static bool isBlocked(const QDateTime& now, bool indefinite, const QDateTime& until);
// What the block currently means, for the screen and the status bar. Empty
// when no block is in force.
static QString blockDescription(bool indefinite, const QDateTime& until,
const QDateTime& now);
signals:
void logDirectoryChanged(const QString& directory);
void logMaxBytesChanged(qint64 bytes);
void dragDropEnabledChanged(bool enabled);
void languageChanged(const QString& code);
void autoUpdateCheckEnabledChanged(bool enabled);
void updateBlockChanged();
private:
// Reads the three block values back in one go, so the in-memory state can
// never disagree with what was persisted.
void loadUpdateBlock();
void saveUpdateBlock();
bool m_blockIndefinite = false;
QDateTime m_blockUntil;
};
+45
View File
@@ -0,0 +1,45 @@
#pragma once
#include <QString>
#include <QStringList>
class QTranslator;
// Installs the translation matching the language preference, and swaps it when
// the user picks another one on the Settings screen.
//
// The translation files are ordinary Qt .qm catalogues, looked up as
// "translations/pacmanager_<code>.qm" in, in order:
//
// 1. <AppSettings log directory>/translations (user's own, survives an update);
// 2. <AppDataLocation>/translations (next to the config);
// 3. <directory of the executable>/translations (running from a build tree).
//
// A code with no .qm on any of those paths simply stays untranslated: the
// interface is written in French, which is what apply() falls back to. That is
// deliberate — the setting is the plumbing, and shipping catalogues is a
// translation pass of its own.
class LanguageManager {
public:
// Resolves "system" to the desktop's language and falls back to the
// interface's own language when the desktop asks for something no catalogue
// covers.
static QString resolve(const QString& code);
// True when a catalogue is actually installed for `code`, so the Settings
// screen can say so instead of pretending a choice will change something.
static bool isTranslationAvailable(const QString& code);
// Where a catalogue is looked up, for the screen to display.
static QString searchPathHint();
// Installs the catalogue for `code` (see resolve) and asks every widget to
// retranslate itself. Returns true when a catalogue was installed.
static bool apply(const QString& code);
// Catalogue currently installed, empty when the interface is untranslated.
static QString activeCode();
// Directories actually searched, in order, existing ones only.
static QStringList searchPaths();
};
+18 -2
View File
@@ -34,8 +34,11 @@
// across the code base feed it without extra plumbing.
//
// The file lives in the user's own data tree (XDG_CONFIG_HOME / home) so it is
// never lost when a sandbox is rebuilt. All methods are safe to call from any
// thread.
// never lost when a sandbox is rebuilt, and both that directory and a size cap
// are the user's to choose on the Settings screen: changing either takes effect
// immediately, the existing journal being moved along (see AppSettings).
//
// All methods are safe to call from any thread.
class LogManager : public QObject {
Q_OBJECT
public:
@@ -70,6 +73,14 @@ public:
// Path of the journal as written on disk (useful for debugging).
QString filePath() const;
// Size the journal currently takes on disk, 0 when there is none yet. The
// Settings screen shows it next to the cap the user picked.
qint64 currentSizeBytes() const;
// Path of the rotated journal, kept so the user can still read what came
// before the last rotation.
static QString backupFilePath();
// Routes every Qt log message into the journal. Call once, after the
// QApplication exists. Safe to call more than once.
static void installQtMessageHandler();
@@ -83,6 +94,11 @@ private:
// lock; this method takes it.
void write(const QString& text);
// Applies the current AppSettings: moves the journal to the configured
// directory and adopts the size cap. Called once from the constructor and
// again whenever a setting changes.
void applySettings();
QString m_filePath;
FILE* m_file = nullptr;
mutable QMutex m_mutex;
+24
View File
@@ -33,6 +33,7 @@ class HistoryPage;
class LogsPage;
class Page;
class PluginsPage;
class SettingsPage;
// The window is only a frame: it owns the sidebar, the header, the status bar,
// the menu, the tray and every dialog, and it stacks one screen per file from
@@ -61,6 +62,8 @@ protected:
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dropEvent(QDropEvent* event) override;
// Language switch: Qt asks every widget to retranslate itself.
void changeEvent(QEvent* event) override;
private slots:
void onNavChanged(int id);
@@ -105,6 +108,7 @@ private:
NavHistory,
NavLogs,
NavPlugins,
NavSettings,
};
void setupUI();
@@ -124,6 +128,9 @@ private:
// 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);
// Last count given to the badge, kept so a language switch can rebuild the
// entry's label without having to re-query the core.
int m_updatesBadgeCount = 0;
void notifyUpdatesAvailable(int count);
// Runs a request and, when the core refused it, walks the user through what
// it needs before replaying it.
@@ -138,6 +145,18 @@ private:
// dialog, anything else is shown as-is.
void showActionError(const QString& title, const QString& error, bool locked);
void applyCredentialMode(AppCore::CredentialMode mode);
// Applies the mode and re-checks the matching menu entry, so the menu bar
// and the Settings screen can never disagree about the current mode.
void onCredentialModeRequested(bool atLaunch);
// Re-applies the language and puts the text back in the widgets, so
// switching language on the Settings screen takes effect at once.
void onLanguageChanged(const QString& code);
// Keeps the window's drop target in step with the preference.
void onDragDropEnabledChanged(bool enabled);
// Puts every string the frame owns back into its widget. Called on the
// LanguageChange event, so it is what makes the language setting visible
// without restarting.
void retranslateUI();
// Records that the running operation just said something: the step is kept
// for the heartbeat and the "nothing printed" clock restarts.
void noteOperationOutput(const QString& step);
@@ -176,6 +195,11 @@ private:
HistoryPage* m_history = nullptr;
LogsPage* m_logs = nullptr;
PluginsPage* m_plugins = nullptr;
SettingsPage* m_settings = nullptr;
// Sidebar entries, by nav id, so the language can be re-applied to them
// (and the updates badge found) without rebuilding the sidebar.
QHash<int, QPushButton*> m_navButtons;
// Progress of the running operation, anchored in the status bar: the bar
// itself (indeterminate until a provider reports a real percentage) and the