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:
27 files changed
+1906
-27
No files matched your search
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user