From a174d4a2aa3d07c6a3c4bedfdf77471f71ec1dba Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 2 Sep 2019 09:22:45 -0400 Subject: moved plugins to settings --- src/settings.h | 123 +++++++++++++++++++++------------------------------------ 1 file changed, 44 insertions(+), 79 deletions(-) (limited to 'src/settings.h') diff --git a/src/settings.h b/src/settings.h index 698cfe21..fc33e0de 100644 --- a/src/settings.h +++ b/src/settings.h @@ -128,6 +128,46 @@ private: }; +class PluginSettings +{ +public: + PluginSettings(QSettings& settings); + + void clearPlugins(); + void registerPlugin(MOBase::IPlugin *plugin); + void addPluginSettings(const std::vector &plugins); + + QVariant pluginSetting(const QString &pluginName, const QString &key) const; + void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value); + QVariant pluginPersistent(const QString &pluginName, const QString &key, const QVariant &def) const; + void setPluginPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync); + void addBlacklistPlugin(const QString &fileName); + bool pluginBlacklisted(const QString &fileName) const; + void setPluginBlacklist(const QStringList& pluginNames); + std::vector plugins() const { return m_Plugins; } + + QVariantMap pluginSettings(const QString &pluginName) const; + void setPluginSettings(const QString &pluginName, const QVariantMap& map); + + QVariantMap pluginDescriptions(const QString &pluginName) const; + void pluginDescriptions(const QString &pluginName, const QVariantMap& map); + + const QSet& pluginBlacklist() const; + + void save(); + +private: + QSettings& m_Settings; + std::vector m_Plugins; + QMap m_PluginSettings; + QMap m_PluginDescriptions; + QSet m_PluginBlacklist; + + void readPluginBlacklist(); + void writePluginBlacklist(); +}; + + enum class EndorsementState { Accepted = 1, @@ -158,23 +198,6 @@ public: QString getFilename() const; - /** - * unregister all plugins from settings - */ - 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 - */ - void registerPlugin(MOBase::IPlugin *plugin); - - /** - * set up the settings for the specified plugins - **/ - void addPluginSettings(const std::vector &plugins); - /** * @return true if the user wants unchecked plugins (esp, esm) should be hidden from * the virtual dat adirectory @@ -284,6 +307,9 @@ public: ColorSettings& colors(); const ColorSettings& colors() const; + PluginSettings& plugins(); + const PluginSettings& plugins() const; + /** * @return true if the user has set up automatic login to nexus @@ -422,42 +448,6 @@ public: QSettings &directInterface() { return m_Settings; } const QSettings &directInterface() const { return m_Settings; } - /** - * @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; - - /** - * @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); - - /** - * @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; - - /** - * @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) */ @@ -469,24 +459,6 @@ public: ServerList getServersFromOldMap() const; void updateServers(ServerList servers); - /** - * @brief add a plugin that is to be blacklisted - * @param fileName name of the plugin to blacklist - */ - void addBlacklistPlugin(const QString &fileName); - - /** - * @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; - - /** - * @return all loaded MO plugins - */ - std::vector plugins() const { return m_Plugins; } - bool usePrereleases() const; void setUsePrereleases(bool b); @@ -513,12 +485,6 @@ public: void dump() const; - // temp - QMap m_PluginSettings; - QMap m_PluginDescriptions; - QSet m_PluginBlacklist; - void writePluginBlacklist(); - public slots: void managedGameChanged(MOBase::IPluginGame const *gamePlugin); @@ -532,13 +498,12 @@ private: mutable QSettings m_Settings; GeometrySettings m_Geometry; ColorSettings m_Colors; + PluginSettings m_Plugins; LoadMechanism m_LoadMechanism; - std::vector m_Plugins; static bool obfuscate(const QString key, const QString data); static QString deObfuscate(const QString key); - void readPluginBlacklist(); QString getConfigurablePath(const QString &key, const QString &def, bool resolve) const; void setConfigurablePath(const QString &key, const QString& path); }; -- cgit v1.3.1