summaryrefslogtreecommitdiff
path: root/src/settings.h
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2020-01-06 05:17:01 -0700
committerGitHub <noreply@github.com>2020-01-06 05:17:01 -0700
commitdfa600996c49c1b23dca884c963dc917bd9cfc0a (patch)
treec6def4277cc962822d0dcde71fa9148e050f693f /src/settings.h
parente69078e2399a88bda7bb9ffae7a3d57db9a4e9cf (diff)
parentd1a788dfad341b32235abc25c2ba1645f8be1ace (diff)
Merge pull request #954 from ModOrganizer2/Develop
Stage for release 2.2.2
Diffstat (limited to 'src/settings.h')
-rw-r--r--src/settings.h1094
1 files changed, 667 insertions, 427 deletions
diff --git a/src/settings.h b/src/settings.h
index bccd1e81..0e5238b1 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -21,555 +21,795 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define SETTINGS_H
#include "loadmechanism.h"
+#include <lootcli/lootcli.h>
+#include <questionboxmemory.h>
+#include <log.h>
+#include <usvfsparameters.h>
-#include <QList>
-#include <QMap>
-#include <QObject>
-#include <QPushButton>
-#include <QSet>
-#include <QSettings>
-#include <QString>
-#include <QVariant>
-#include <QColor>
-#include <QMetaType>
-
-#include <QtGlobal> //for uint
-
-#include <map>
-#include <vector>
-
-class QCheckBox;
-class QComboBox;
-class QLineEdit;
-class QSpinBox;
-class QListWidget;
-class QWidget;
-class QLabel;
-class QPushButton;
-
-struct ServerInfo;
+#ifdef interface
+ #undef interface
+#endif
namespace MOBase {
class IPlugin;
class IPluginGame;
+ class ExpanderWidget;
}
-class SettingsDialog;
-class PluginContainer;
+class QSplitter;
-/**
- * manages the settings for Mod Organizer. The settings are not cached
- * inside the class but read/written directly from/to disc
- **/
-class Settings : public QObject
+class ServerList;
+class Settings;
+
+
+
+// setting for the currently managed game
+//
+class GameSettings
+{
+public:
+ GameSettings(QSettings& setting);
+
+ // game plugin
+ //
+ const MOBase::IPluginGame* plugin();
+ void setPlugin(const MOBase::IPluginGame* gamePlugin);
+
+ // whether files of the core game are forced-enabled so the user can't
+ // accidentally disable them
+ //
+ bool forceEnableCoreFiles() const;
+ void setForceEnableCoreFiles(bool b);
+
+ // the directory where the managed game is stored
+ //
+ std::optional<QString> directory() const;
+ void setDirectory(const QString& path);
+
+ // the name of the managed game
+ //
+ std::optional<QString> name() const;
+ void setName(const QString& name);
+
+ // the edition of the managed game
+ //
+ std::optional<QString> edition() const;
+ void setEdition(const QString& name);
+
+ // the current profile name
+ //
+ std::optional<QString> selectedProfileName() const;
+ void setSelectedProfileName(const QString& name);
+
+ // load mechanism type
+ //
+ LoadMechanism::EMechanism loadMechanismType() const;
+ void setLoadMechanism(LoadMechanism::EMechanism m);
+
+ // load mechanism object
+ //
+ const LoadMechanism& loadMechanism() const;
+ LoadMechanism& loadMechanism();
+
+ // whether the user wants unchecked plugins (esp, esm) to be hidden from
+ // the virtual data directory
+ //
+ bool hideUncheckedPlugins() const;
+ void setHideUncheckedPlugins(bool b);
+
+private:
+ QSettings& m_Settings;
+ const MOBase::IPluginGame* m_GamePlugin;
+ LoadMechanism m_LoadMechanism;
+};
+
+
+// geometry settings for various widgets; this should contain any setting that
+// can get invalid through UI changes or when users change display settings
+// (resolution, monitors, etc.); see WidgetSettings for the counterpart
+//
+// all these settings are stored under [Geometry] and get wiped when the
+// "reset geometry settings" button is clicked in the settings
+//
+// saveGeometry(), restoreGeometry(), saveState() and restoreState() call the
+// same functions on the given widget
+//
+class GeometrySettings
{
+public:
+ GeometrySettings(QSettings& s);
+
+ // asks the settings to get reset
+ //
+ // this gets called from the settings dialog and gets picked up in
+ // resetIfNeeded(), called from runApplication() just before exiting
+ //
+ void requestReset();
+ void resetIfNeeded();
+
+
+ void saveGeometry(const QMainWindow* w);
+ bool restoreGeometry(QMainWindow* w) const;
+
+ void saveGeometry(const QDialog* d);
+ bool restoreGeometry(QDialog* d) const;
+
+ void saveState(const QMainWindow* window);
+ bool restoreState(QMainWindow* window) const;
+
+ void saveState(const QHeaderView* header);
+ bool restoreState(QHeaderView* header) const;
+
+ void saveState(const QSplitter* splitter);
+ bool restoreState(QSplitter* splitter) const;
+
+ void saveState(const MOBase::ExpanderWidget* expander);
+ bool restoreState(MOBase::ExpanderWidget* expander) const;
+
+ void saveVisibility(const QWidget* w);
+ bool restoreVisibility(QWidget* w, std::optional<bool> def={}) const;
+
+ void saveToolbars(const QMainWindow* w);
+ void restoreToolbars(QMainWindow* w) const;
- Q_OBJECT
+ void saveDocks(const QMainWindow* w);
+ void restoreDocks(QMainWindow* w) const;
+ // this should be a generic "tab order" setting, but it only happens for the
+ // mod info dialog right now
+ //
+ QStringList modInfoTabOrder() const;
+ void setModInfoTabOrder(const QString& names);
+
+ // whether dialogs should be centered on their parent
+ //
+ bool centerDialogs() const;
+ void setCenterDialogs(bool b);
+
+ // assumes the given widget is a top-level
+ //
+ void centerOnMainWindowMonitor(QWidget* w);
+
+ // saves the monitor number of the given window
+ //
+ void saveMainWindowMonitor(const QMainWindow* w);
+
+private:
+ QSettings& m_Settings;
+ bool m_Reset;
+
+ void saveWindowGeometry(const QWidget* w);
+ bool restoreWindowGeometry(QWidget* w) const;
+
+ void ensureWindowOnScreen(QWidget* w) const;
+ static void centerOnMonitor(QWidget* w, int monitor);
+ static void centerOnParent(QWidget* w, QWidget* parent=nullptr);
+};
+
+
+// widget settings that should stay valid regardless of UI changes or when users
+// change display settings (resolution, monitors, etc.); see GeometrySettings
+// for the counterpart
+//
+class WidgetSettings
+{
public:
+ WidgetSettings(QSettings& s);
- /**
- * @brief constructor
- **/
- Settings(const QSettings &settingsSource);
+ // selected index for a combobox
+ //
+ std::optional<int> index(const QComboBox* cb) const;
+ void saveIndex(const QComboBox* cb);
+ void restoreIndex(QComboBox* cb, std::optional<int> def={}) const;
- virtual ~Settings();
+ // selected tab index for a tab widget
+ //
+ std::optional<int> index(const QTabWidget* w) const;
+ void saveIndex(const QTabWidget* w);
+ void restoreIndex(QTabWidget* w, std::optional<int> def={}) const;
- static Settings &instance();
+ // check state for a checkable button
+ //
+ std::optional<bool> checked(const QAbstractButton* w) const;
+ void saveChecked(const QAbstractButton* w);
+ void restoreChecked(QAbstractButton* w, std::optional<bool> def={}) const;
- /**
- * unregister all plugins from settings
- */
+ // returns the remembered button for a question dialog, or NoButton if the
+ // user hasn't saved the choice
+ //
+ MOBase::QuestionBoxMemory::Button questionButton(
+ const QString& windowName, const QString& filename) const;
+
+ // sets the button to be remembered for the given window
+ //
+ void setQuestionWindowButton(
+ const QString& windowName, MOBase::QuestionBoxMemory::Button button);
+
+ // sets the button to be remembered for the given file
+ //
+ void setQuestionFileButton(
+ const QString& windowName, const QString& filename,
+ MOBase::QuestionBoxMemory::Button choice);
+
+ // wipes all the remembered buttons
+ //
+ void resetQuestionButtons();
+
+private:
+ QSettings& m_Settings;
+};
+
+
+// various color settings
+//
+class ColorSettings
+{
+public:
+ ColorSettings(QSettings& s);
+
+ QColor modlistOverwrittenLoose() const;
+ void setModlistOverwrittenLoose(const QColor& c);
+
+ QColor modlistOverwritingLoose() const;
+ void setModlistOverwritingLoose(const QColor& c);
+
+ QColor modlistOverwrittenArchive() const;
+ void setModlistOverwrittenArchive(const QColor& c);
+
+ QColor modlistOverwritingArchive() const;
+ void setModlistOverwritingArchive(const QColor& c);
+
+ QColor modlistContainsPlugin() const;
+ void setModlistContainsPlugin(const QColor& c);
+
+ QColor pluginListContained() const;
+ void setPluginListContained(const QColor& c) ;
+
+ std::optional<QColor> previousSeparatorColor() const;
+ void setPreviousSeparatorColor(const QColor& c) const;
+ void removePreviousSeparatorColor();
+
+ // whether the scrollbar of the mod list should have colors for custom
+ // separator colors
+ //
+ bool colorSeparatorScrollbar() const;
+ void setColorSeparatorScrollbar(bool b);
+
+ // returns a color with a good contrast for the given background
+ //
+ static QColor idealTextColor(const QColor& rBackgroundColor);
+
+private:
+ QSettings& m_Settings;
+};
+
+
+// settings about plugins
+//
+class PluginSettings
+{
+public:
+ PluginSettings(QSettings& settings);
+
+
+ // forgets all the plugins
+ //
void clearPlugins();
- /**
- * @brief register plugin to be configurable
- * @param plugin the plugin to register
- * @return true if the plugin may be registered, false if it is blacklisted
- */
+ // adds the given plugin to the list and loads all of its settings
+ //
void registerPlugin(MOBase::IPlugin *plugin);
- /**
- * displays a SettingsDialog that allows the user to change settings. If the
- * user accepts the changes, the settings are immediately written
- **/
- void query(PluginContainer *pluginContainer, QWidget *parent);
+ // returns all the registered plugins
+ //
+ std::vector<MOBase::IPlugin*> plugins() const;
- /**
- * set up the settings for the specified plugins
- **/
- void addPluginSettings(const std::vector<MOBase::IPlugin*> &plugins);
- /**
- * @return true if the user wants unchecked plugins (esp, esm) should be hidden from
- * the virtual dat adirectory
- **/
- bool hideUncheckedPlugins() const;
+ // returns the plugin setting for the given key
+ //
+ QVariant setting(const QString &pluginName, const QString &key) const;
- /**
- * @return true if files of the core game are forced-enabled so the user can't accidentally disable them
- */
- bool forceEnableCoreFiles() const;
+ // sets the plugin setting for the given key
+ //
+ void setSetting(const QString &pluginName, const QString &key, const QVariant &value);
- /**
- * @return true if the GUI should be locked when running executables
- */
- bool lockGUI() const;
+ // returns all settings
+ //
+ QVariantMap settings(const QString &pluginName) const;
- /**
- * @brief register download speed
- * @param url complete download url
- * @param bytesPerSecond download size in bytes per second
- */
- void setDownloadSpeed(const QString &serverName, int bytesPerSecond);
+ // overwrites all settings
+ //
+ void setSettings(const QString &pluginName, const QVariantMap& map);
+
+ // returns all descriptions
+ //
+ QVariantMap descriptions(const QString &pluginName) const;
+
+ // overwrites all descriptions
+ //
+ void setDescriptions(const QString &pluginName, const QVariantMap& map);
+
+
+ // ?
+ QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def) const;
+ void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync);
- /**
- * the steam appid is assigned by the steam platform to each product sold there.
- * The appid may differ between different versions of a game so it may be impossible
- * for Mod Organizer to automatically recognize it, though usually it does
- * @return the steam appid for the game
- **/
- QString getSteamAppID() const;
- /**
- * retrieves the base directory under which the other directories usually
- * reside
- */
- QString getBaseDirectory() const;
+ // adds the given plugin to the blacklist
+ //
+ void addBlacklist(const QString &fileName);
- /**
- * retrieve the directory where downloads are stored (with native separators)
- **/
- QString getDownloadDirectory(bool resolve = true) const;
+ // returns whether the given plugin is blacklisted
+ //
+ bool blacklisted(const QString &fileName) const;
- /**
- * retrieve a sorted list of preferred servers
- */
- std::map<QString, int> getPreferredServers();
+ // overwrites the whole blacklist
+ //
+ void setBlacklist(const QStringList& pluginNames);
- /**
- * retrieve the directory where mods are stored (with native separators)
- **/
- QString getModDirectory(bool resolve = true) const;
+ // returns the blacklist
+ //
+ const QSet<QString>& blacklist() const;
- /**
- * retrieve the directory where the web cache is stored (with native separators)
- **/
- QString getCacheDirectory(bool resolve = true) const;
- /**
- * retrieve the directory where the managed game is stored (with native separators)
- **/
- QString getManagedGameDirectory() const;
+ // commits all the settings to the ini
+ //
+ void save();
- /**
- * retrieve the directory where profiles stored (with native separators)
- **/
- QString getProfileDirectory(bool resolve = true) const;
+private:
+ QSettings& m_Settings;
+ std::vector<MOBase::IPlugin*> m_Plugins;
+ QMap<QString, QVariantMap> m_PluginSettings;
+ QMap<QString, QVariantMap> m_PluginDescriptions;
+ QSet<QString> m_PluginBlacklist;
+
+ // commits the blacklist to the ini
+ //
+ void writeBlacklist();
+
+ // reads the blacklist from the ini
+ //
+ QSet<QString> readBlacklist() const;
+};
+
+
+// paths for the game and various components
+//
+// if the 'resolve' parameter is true, %BASE_DIR% is expanded; it's set to
+// false mostly in the settings dialog
+//
+class PathSettings
+{
+public:
+ PathSettings(QSettings& settings);
- /**
- * retrieve the directory were new files are stored that can't be assigned
- * to a mod (with native separators)
- */
- QString getOverwriteDirectory(bool resolve = true) const;
+ QString base() const;
+ void setBase(const QString& path);
- /**
- * @return true if the user has set up automatic login to nexus
- **/
- bool automaticLoginEnabled() const;
+ QString downloads(bool resolve = true) const;
+ void setDownloads(const QString& path);
- /**
- * @brief retrieve the login information for nexus
- *
- * @param username (out) receives the user name for nexus
- * @param password (out) received the password for nexus
- * @return true if automatic login is active, false otherwise
- **/
- bool getNexusApiKey(QString &apiKey) const;
+ QString mods(bool resolve = true) const;
+ void setMods(const QString& path);
- /**
- * @brief set the nexus login information
- *
- * @param username username
- * @param password password
- */
- bool setNexusApiKey(const QString& apiKey);
+ QString cache(bool resolve = true) const;
+ void setCache(const QString& path);
- /**
- * @brief clears the nexus login information
- */
- bool clearNexusApiKey();
+ QString profiles(bool resolve = true) const;
+ void setProfiles(const QString& path);
- /**
- * @brief returns whether an API key is currently stored
- */
- bool hasNexusApiKey() const;
+ QString overwrite(bool resolve = true) const;
+ void setOverwrite(const QString& path);
- /**
- * @brief retrieve the login information for steam
- *
- * @param username (out) receives the user name for nexus
- * @param password (out) received the password for nexus
- * @return true if a username has been specified, false otherwise
- **/
- bool getSteamLogin(QString &username, QString &password) const;
- /**
- * @return true if the user disabled internet features
- */
+ // map of names to directories, used to remember the last directory used in
+ // various file pickers
+ //
+ std::map<QString, QString> recent() const;
+ void setRecent(const std::map<QString, QString>& map);
+
+private:
+ QSettings& m_Settings;
+
+ QString getConfigurablePath(const QString &key, const QString &def, bool resolve) const;
+ void setConfigurablePath(const QString &key, const QString& path);
+};
+
+
+class NetworkSettings
+{
+public:
+ NetworkSettings(QSettings& settings);
+
+ // whether the user has disabled online features
+ //
bool offlineMode() const;
+ void setOfflineMode(bool b);
- /**
- * @return true if the user chose compact downloads
- */
- bool compactDownloads() const;
+ // whether the user wants to use the system proxy
+ //
+ bool useProxy() const;
+ void setUseProxy(bool b);
- /**
- * @return true if the user chose meta downloads
- */
- bool metaDownloads() const;
+ // add a new download speed to the list for the given server; each server
+ // remembers the last couple of download speeds and displays the average in
+ // the network settings
+ //
+ void setDownloadSpeed(const QString &serverName, int bytesPerSecond);
- /**
- * @return the configured log level
- */
- int logLevel() const;
+ // known servers
+ //
+ ServerList servers() const;
- /**
- * @return the configured crash dumps type
- */
- int crashDumpsType() const;
+ // sets the servers
+ //
+ void updateServers(ServerList servers);
- /**
- * @return the configured crash dumps max
- */
- int crashDumpsMax() const;
+ // for 2.2.1 and before, rewrites the old byte array map to the new format
+ //
+ void updateFromOldMap();
+
+ void dump() const;
- QColor modlistOverwrittenLooseColor() const;
+private:
+ QSettings& m_Settings;
- QColor modlistOverwritingLooseColor() const;
+ // for pre 2.2.1 ini files
+ //
+ ServerList serversFromOldMap() const;
+};
- QColor modlistOverwrittenArchiveColor() const;
- QColor modlistOverwritingArchiveColor() const;
+enum class EndorsementState
+{
+ Accepted = 1,
+ Refused,
+ NoDecision
+};
- QColor modlistContainsPluginColor() const;
+EndorsementState endorsementStateFromString(const QString& s);
+QString toString(EndorsementState s);
- QColor pluginListContainedColor() const;
- QString executablesBlacklist() const;
+class NexusSettings
+{
+public:
+ NexusSettings(Settings& parent, QSettings& settings);
- /**
- * @brief set the steam login information
- *
- * @param username username
- * @param password password
- */
- void setSteamLogin(QString username, QString password);
+ // if the key exists from the credentials store, puts it in `apiKey` and
+ // returns true; otherwise, returns false and leaves `apiKey` untouched
+ //
+ bool apiKey(QString& apiKey) const;
- /**
- * @return the load mechanism to be used
- **/
- LoadMechanism::EMechanism getLoadMechanism() const;
+ // sets the api key in the credentials store, removes it if empty; returns
+ // false on errors
+ //
+ bool setApiKey(const QString& apiKey);
- /**
- * @brief activate the load mechanism selected by the user
- **/
- void setupLoadMechanism();
+ // removes the api key from the credentials store; returns false on errors
+ //
+ bool clearApiKey();
- /**
- * @return true if the user configured the use of a network proxy
- */
- bool useProxy() const;
+ // returns whether an API key is currently stored
+ //
+ bool hasApiKey() const;
- /**
- * @return true if endorsement integration is enabled
- */
+ // returns whether endorsement integration is enabled
+ //
bool endorsementIntegration() const;
+ void setEndorsementIntegration(bool b) const;
- /**
- * @return true if the API counter should be hidden
- */
- bool hideAPICounter() const;
+ // returns the endorsement state of MO itself
+ //
+ EndorsementState endorsementState() const;
+ void setEndorsementState(EndorsementState s);
- /**
- * @return true if the user wants to see non-official plugins installed outside MO in his mod list
- */
- bool displayForeign() const;
+ // registers MO as the handler for nxm links
+ //
+ // if 'force' is true, the registration dialog will be shown even if the user
+ // said earlier not to
+ //
+ void registerAsNXMHandler(bool force);
- /**
- * @brief sets the new motd hash
- **/
- void setMotDHash(uint hash);
+private:
+ Settings& m_Parent;
+ QSettings& m_Settings;
+};
- /**
- * @return true if the user wants to have archives being parsed to show conflicts and contents
- */
- bool archiveParsing() const;
- /**
- * @return hash of the last displayed message of the day
- **/
- uint getMotDHash() const;
+class SteamSettings
+{
+public:
+ SteamSettings(Settings& parent, QSettings& settings);
- /**
- * @brief allows direct access to the wrapped QSettings object
- * @return the wrapped QSettings object
- */
- QSettings &directInterface() { return m_Settings; }
- const QSettings &directInterface() const { return m_Settings; }
+ // the steam appid is assigned by the steam platform to each product sold
+ // there.
+ //
+ // the appid may differ between different versions of a game so it may be
+ // impossible for MO to automatically recognize it, though usually it does
+ //
+ QString appID() const;
+ void setAppID(const QString& id);
- /**
- * @brief retrieve a setting for one of the installed plugins
- * @param pluginName name of the plugin
- * @param key name of the setting to retrieve
- * @return the requested value as a QVariant
- * @note an invalid QVariant is returned if the the plugin/setting is not declared
- */
- QVariant pluginSetting(const QString &pluginName, const QString &key) const;
+ // the steam username is stored in the ini, but the password is in the
+ // windows credentials store; both values are independent and either can be
+ // empty
+ //
+ // if the username exists in the ini, it is assigned to `username`; if not
+ // `username` is set to an empty string
+ //
+ // if the password exists in the credentials store, it is assigned to
+ // `password`; if not, `password` is set to an empty string
+ //
+ // returns whether _both_ the username and password have a value
+ //
+ bool login(QString &username, QString &password) const;
- /**
- * @brief set a setting for one of the installed mods
- * @param pluginName name of the plugin
- * @param key name of the setting to change
- * @param value the new value to set
- * @throw an exception is thrown if pluginName is invalid
- */
- void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value);
+ // sets the steam login; the username is saved in the ini file and the
+ // password in the credentials store
+ //
+ // if a value is empty, it is removed from its backing store
+ //
+ void setLogin(QString username, QString password);
- /**
- * @brief retrieve a persistent value for a plugin
- * @param pluginName name of the plugin to store data for
- * @param key id of the value to retrieve
- * @param def default value to return if the value is not set
- * @return the requested value
- */
- QVariant pluginPersistent(const QString &pluginName, const QString &key, const QVariant &def) const;
+private:
+ Settings& m_Parent;
+ QSettings& m_Settings;
+};
- /**
- * @brief set a persistent value for a plugin
- * @param pluginName name of the plugin to store data for
- * @param key id of the value to retrieve
- * @param value value to set
- * @throw an exception is thrown if pluginName is invalid
- */
- void setPluginPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync);
- /**
- * @return short code of the configured language (corresponding to the translation files)
- */
- QString language();
+class InterfaceSettings
+{
+public:
+ InterfaceSettings(QSettings& settings);
- /**
- * @brief updates the list of known servers
- * @param list of servers from a recent query
- */
- void updateServers(const QList<ServerInfo> &servers);
+ // whether the GUI should be locked when running executables
+ //
+ bool lockGUI() const;
+ void setLockGUI(bool b);
- /**
- * @brief add a plugin that is to be blacklisted
- * @param fileName name of the plugin to blacklist
- */
- void addBlacklistPlugin(const QString &fileName);
+ // filename of the theme
+ //
+ std::optional<QString> styleName() const;
+ void setStyleName(const QString& name);
- /**
- * @brief test if a plugin is blacklisted and shouldn't be loaded
- * @param fileName name of the plugin
- * @return true if the file is blacklisted
- */
- bool pluginBlacklisted(const QString &fileName) const;
+ // whether to show compact downloads
+ //
+ bool compactDownloads() const;
+ void setCompactDownloads(bool b);
- /**
- * @return all loaded MO plugins
- */
- std::vector<MOBase::IPlugin*> plugins() const { return m_Plugins; }
+ // whether to show meta information for downloads
+ //
+ bool metaDownloads() const;
+ void setMetaDownloads(bool b);
- bool usePrereleases() const;
+ // whether the API counter should be hidden
+ //
+ bool hideAPICounter() const;
+ void setHideAPICounter(bool b);
- /**
- * @brief register MO as the handler for nxm links
- * @param force set to true to enforce the registration dialog to show up,
- * even if the user said earlier not to
- */
- void registerAsNXMHandler(bool force);
+ // whether the user wants to see non-official plugins installed outside MO in
+ // the mod list
+ //
+ bool displayForeign() const;
+ void setDisplayForeign(bool b);
- /**
- * @brief color the scrollbar of the mod list for custom separator colors?
- * @return the state of the setting
- */
- bool colorSeparatorScrollbar() const;
+ // short code of the configured language (corresponding to the translation
+ // files)
+ //
+ QString language();
+ void setLanguage(const QString& name);
-public slots:
+ // whether the given tutorial has been completed
+ //
+ bool isTutorialCompleted(const QString& windowName) const;
+ void setTutorialCompleted(const QString& windowName, bool b=true);
- void managedGameChanged(MOBase::IPluginGame const *gamePlugin);
+ // whether to show the confirmation when switching instances
+ //
+ bool showChangeGameConfirmation() const;
+ void setShowChangeGameConfirmation(bool b);
+
+ // whether double-clicks on files should try to open previews first
+ //
+ bool doubleClicksOpenPreviews() const;
+ void setDoubleClicksOpenPreviews(bool b);
+
+private:
+ QSettings& m_Settings;
+};
+
+
+class DiagnosticsSettings
+{
public:
- static QColor getIdealTextColor(const QColor& rBackgroundColor);
+ DiagnosticsSettings(QSettings& settings);
+
+ // log level for both MO and usvfs
+ //
+ MOBase::log::Levels logLevel() const;
+ void setLogLevel(MOBase::log::Levels level);
+
+ // log level for loot
+ lootcli::LogLevels lootLogLevel() const;
+ void setLootLogLevel(lootcli::LogLevels level);
+
+ // crash dump type for both MO and usvfs
+ //
+ CrashDumpsType crashDumpsType() const;
+ void setCrashDumpsType(CrashDumpsType type);
+
+ // maximum number of dump files keps, for both MO and usvfs
+ //
+ int crashDumpsMax() const;
+ void setCrashDumpsMax(int n);
+
+ std::chrono::seconds spawnDelay() const;
+ void setSpawnDelay(std::chrono::seconds t);
+
private:
+ QSettings& m_Settings;
+};
- static bool obfuscate(const QString key, const QString data);
- static QString deObfuscate(const QString key);
- void addLanguages(QComboBox *languageBox);
- void addStyles(QComboBox *styleBox);
- void readPluginBlacklist();
- void writePluginBlacklist();
- QString getConfigurablePath(const QString &key, const QString &def, bool resolve) const;
+// manages the settings for MO; the settings are accessed directly through a
+// QSettings and so are not cached here
+//
+class Settings : public QObject
+{
+ Q_OBJECT;
- class SettingsTab
- {
- public:
- SettingsTab(Settings *m_parent, SettingsDialog &m_dialog);
- virtual ~SettingsTab();
+public:
+ Settings(const QString& path);
+ ~Settings();
- virtual void update() = 0;
+ static Settings &instance();
- protected:
- Settings *m_parent;
- QSettings &m_Settings;
- SettingsDialog &m_dialog;
+ // name of the ini file
+ //
+ QString filename() const;
- };
+ // version of MO stored in the ini; this may be different from the current
+ // version if the user just updated
+ //
+ std::optional<QVersionNumber> version() const;
- /** Display/store the configuration in the 'general' tab of the settings dialogue */
- class GeneralTab : public SettingsTab
- {
- public:
- GeneralTab(Settings *m_parent, SettingsDialog &m_dialog);
+ // updates the settings to bring them up to date
+ //
+ void processUpdates(const QVersionNumber& current, const QVersionNumber& last);
- void update();
+ // whether MO has been started for the first time
+ //
+ bool firstStart() const;
+ void setFirstStart(bool b);
- private:
- QComboBox *m_languageBox;
- QComboBox *m_styleBox;
- QCheckBox *m_compactBox;
- QCheckBox *m_showMetaBox;
- QCheckBox *m_usePrereleaseBox;
- QPushButton *m_overwritingBtn;
- QPushButton *m_overwrittenBtn;
- QPushButton *m_overwritingArchiveBtn;
- QPushButton *m_overwrittenArchiveBtn;
- QPushButton *m_containsBtn;
- QPushButton *m_containedBtn;
- QCheckBox *m_colorSeparatorsBox;
- };
+ // configured executables
+ //
+ std::vector<std::map<QString, QVariant>> executables() const;
+ void setExecutables(const std::vector<std::map<QString, QVariant>>& v);
- class PathsTab : public SettingsTab
- {
- public:
- PathsTab(Settings *parent, SettingsDialog &dialog);
+ // whether to backup existing mods on install
+ //
+ bool keepBackupOnInstall() const;
+ void setKeepBackupOnInstall(bool b);
- void update();
+ // blacklisted executables do not get hooked by usvfs; this list is managed
+ // by MO but given to usvfs when starting an executable
+ //
+ QString executablesBlacklist() const;
+ bool isExecutableBlacklisted(const QString& s) const;
+ void setExecutablesBlacklist(const QString& s);
- private:
- QLineEdit *m_baseDirEdit;
- QLineEdit *m_downloadDirEdit;
- QLineEdit *m_modDirEdit;
- QLineEdit *m_cacheDirEdit;
- QLineEdit *m_profilesDirEdit;
- QLineEdit *m_overwriteDirEdit;
- QLineEdit *m_managedGameDirEdit;
- };
+ // ? looks obsolete, only used by dead code
+ //
+ unsigned int motdHash() const;
+ void setMotdHash(unsigned int hash);
- class DiagnosticsTab : public SettingsTab
- {
- public:
- DiagnosticsTab(Settings *parent, SettingsDialog &dialog);
+ // whether archives should be parsed to show conflicts and contents
+ //
+ bool archiveParsing() const;
+ void setArchiveParsing(bool b);
- void update();
+ // whether the user wants to check for updates
+ //
+ bool checkForUpdates() const;
+ void setCheckForUpdates(bool b);
- private:
- QComboBox *m_logLevelBox;
- QComboBox *m_dumpsTypeBox;
- QSpinBox *m_dumpsMaxEdit;
- QLabel *m_diagnosticsExplainedLabel;
- };
+ // whether the user wants to upgrade to pre-releases
+ //
+ bool usePrereleases() const;
+ void setUsePrereleases(bool b);
- /** Display/store the configuration in the 'nexus' tab of the settings dialogue */
- class NexusTab : public SettingsTab
- {
- public:
- NexusTab(Settings *m_parent, SettingsDialog &m_dialog);
- void update();
- private:
- QCheckBox *m_offlineBox;
- QCheckBox *m_proxyBox;
- QListWidget *m_knownServersList;
- QListWidget *m_preferredServersList;
- QCheckBox *m_endorsementBox;
- QCheckBox *m_hideAPICounterBox;
- };
+ GameSettings& game();
+ const GameSettings& game() const;
- /** Display/store the configuration in the 'steam' tab of the settings dialogue */
- class SteamTab : public SettingsTab
- {
- public:
- SteamTab(Settings *m_parent, SettingsDialog &m_dialog);
+ GeometrySettings& geometry();
+ const GeometrySettings& geometry() const;
- void update();
+ WidgetSettings& widgets();
+ const WidgetSettings& widgets() const;
- private:
- QLineEdit *m_steamUserEdit;
- QLineEdit *m_steamPassEdit;
- };
+ ColorSettings& colors();
+ const ColorSettings& colors() const;
- /** Display/store the configuration in the 'plugins' tab of the settings dialogue */
- class PluginsTab : public SettingsTab
- {
- public:
- PluginsTab(Settings *m_parent, SettingsDialog &m_dialog);
+ PluginSettings& plugins();
+ const PluginSettings& plugins() const;
- void update();
+ PathSettings& paths();
+ const PathSettings& paths() const;
- private:
- QListWidget *m_pluginsList;
- QListWidget *m_pluginBlacklistList;
- };
+ NetworkSettings& network();
+ const NetworkSettings& network() const;
- /** Display/store the configuration in the 'workarounds' tab of the settings dialogue */
- class WorkaroundsTab : public SettingsTab
- {
- public:
- WorkaroundsTab(Settings *m_parent, SettingsDialog &m_dialog);
+ NexusSettings& nexus();
+ const NexusSettings& nexus() const;
- void update();
+ SteamSettings& steam();
+ const SteamSettings& steam() const;
- private:
- QLineEdit *m_appIDEdit;
- QComboBox *m_mechanismBox;
- QCheckBox *m_hideUncheckedBox;
- QCheckBox *m_forceEnableBox;
- QCheckBox *m_displayForeignBox;
- QCheckBox *m_lockGUIBox;
- QCheckBox *m_enableArchiveParsingBox;
- QPushButton *m_resetGeometriesBtn;
- };
+ InterfaceSettings& interface();
+ const InterfaceSettings& interface() const;
-private slots:
+ DiagnosticsSettings& diagnostics();
+ const DiagnosticsSettings& diagnostics() const;
- void resetDialogs();
+ // makes sure the ini file is written to disk
+ //
+ QSettings::Status sync() const;
-signals:
+ void dump() const;
+public slots:
+ // this slot is connected to by various parts of MO
+ //
+ void managedGameChanged(MOBase::IPluginGame const *gamePlugin);
+
+signals:
+ // these are fired from outside the settings, mostly by the settings dialog
+ //
void languageChanged(const QString &newLanguage);
void styleChanged(const QString &newStyle);
private:
-
static Settings *s_Instance;
+ mutable QSettings m_Settings;
- MOBase::IPluginGame const *m_GamePlugin;
-
- QSettings m_Settings;
-
- LoadMechanism m_LoadMechanism;
+ GameSettings m_Game;
+ GeometrySettings m_Geometry;
+ WidgetSettings m_Widgets;
+ ColorSettings m_Colors;
+ PluginSettings m_Plugins;
+ PathSettings m_Paths;
+ NetworkSettings m_Network;
+ NexusSettings m_Nexus;
+ SteamSettings m_Steam;
+ InterfaceSettings m_Interface;
+ DiagnosticsSettings m_Diagnostics;
+};
- std::vector<MOBase::IPlugin*> m_Plugins;
- QMap<QString, QVariantMap> m_PluginSettings;
- QMap<QString, QVariantMap> m_PluginDescriptions;
+// helper class that calls restoreGeometry() in the constructor and
+// saveGeometry() in the destructor
+//
+template <class W>
+class GeometrySaver
+{
+public:
+ GeometrySaver(Settings& s, W* w)
+ : m_settings(s), m_widget(w)
+ {
+ m_settings.geometry().restoreGeometry(m_widget);
+ }
- QSet<QString> m_PluginBlacklist;
+ ~GeometrySaver()
+ {
+ m_settings.geometry().saveGeometry(m_widget);
+ }
+private:
+ Settings& m_settings;
+ W* m_widget;
};
#endif // SETTINGS_H