#pragma once #include #include #include #include // 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; };