diff --git a/include/uibase/extensionsetting.h b/include/uibase/extensionsetting.h new file mode 100644 index 00000000..cd1ee7f6 --- /dev/null +++ b/include/uibase/extensionsetting.h @@ -0,0 +1,89 @@ +#pragma once + +#include +#include + +namespace MOBase +{ + +// class representing a group of settings +// +class SettingGroup +{ +public: + SettingGroup(QString const& name, QString const& title, QString const& description) + : m_Name{name}, m_Title{title}, m_Description{description} + {} + + // return the (internal) name of this group, localization independent + // + const auto& name() const { return m_Name; } + + // retrieve the title of this group, can be localized + // + const auto& title() const { return m_Title; } + + // retrieve the description of this group, can be localized + // + const auto& description() const { return m_Description; } + +private: + QString m_Name, m_Title, m_Description; +}; + +// class that represents an extension or a plugin setting +// +class Setting +{ +public: + // deprecated constructor that was previously available as PluginSettin + // + [[deprecated]] Setting(const QString& name, const QString& description, + const QVariant& defaultValue) + : m_Name{name}, m_Title{name}, m_Description{description}, m_Group{}, + m_DefaultValue{defaultValue} + {} + + Setting(const QString& name, const QString& title, const QString& description, + const QVariant& defaultValue) + : m_Name{name}, m_Title{title}, m_Description{description}, m_Group{}, + m_DefaultValue{defaultValue} + {} + + Setting(const QString& name, const QString& title, const QString& description, + const QString& group, const QVariant& defaultValue) + : m_Name{name}, m_Title{title}, m_Description{description}, m_Group{group}, + m_DefaultValue{defaultValue} + {} + +public: + // return the (internal) name of this setting, localization independent + // + const auto& name() const { return m_Name; } + + // retrieve the title of this setting, can be localized + // + const auto& title() const { return m_Title; } + + // retrieve the description of this setting, can be localized + // + const auto& description() const { return m_Description; } + + // retrieve the name of the group this settings belongs to or an empty string if there + // is none + // + const auto& group() const { return m_Group; } + + // retrieve the default value of this setting + // + const auto& defaultValue() const { return m_DefaultValue; } + +private: + QString m_Name; + QString m_Title; + QString m_Description; + QString m_Group; + QVariant m_DefaultValue; +}; + +} // namespace MOBase diff --git a/include/uibase/imodinterface.h b/include/uibase/imodinterface.h index ca8c6ff6..b093aea5 100644 --- a/include/uibase/imodinterface.h +++ b/include/uibase/imodinterface.h @@ -269,17 +269,17 @@ class IModInterface virtual void setUrl(const QString& url) = 0; public: // Plugin operations: - /** - * @brief Retrieve the specified setting in this mod for a plugin. - * - * @param pluginName Name of the plugin for which to retrieve a setting. This should - * always be IPlugin::name() unless you have a really good reason to access - * settings of another plugin. - * @param key Identifier of the setting. - * @param defaultValue The default value to return if the setting does not exist. - * - * @return the setting, if found, or the default value. - */ + /** + * @brief Retrieve the specified setting in this mod for a plugin. + * + * @param pluginName Name of the plugin for which to retrieve a setting. This should + * always be IPlugin::name() unless you have a really good reason to access + * settings of another plugin. + * @param key Identifier of the setting. + * @param defaultValue The default value to return if the setting does not exist. + * + * @return the setting, if found, or the default value. + */ virtual QVariant pluginSetting(const QString& pluginName, const QString& key, const QVariant& defaultValue = QVariant()) const = 0; diff --git a/include/uibase/iplugin.h b/include/uibase/iplugin.h index c86d774b..7df54d6e 100644 --- a/include/uibase/iplugin.h +++ b/include/uibase/iplugin.h @@ -21,9 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef IPLUGIN_H #define IPLUGIN_H +#include "extensionsetting.h" #include "imoinfo.h" #include "pluginrequirements.h" -#include "pluginsetting.h" #include "versioninfo.h" #include #include @@ -88,7 +88,12 @@ class IPlugin * @note Plugin can store "hidden" (from the user) settings using * IOrganizer::persistent / IOrganizer::setPersistent. */ - virtual QList settings() const = 0; + virtual QList settings() const = 0; + + /** + * @return the list of groups for settings. + */ + virtual QList settingGroups() const { return {}; } /** * @return whether the plugin should be enabled by default diff --git a/include/uibase/pluginsetting.h b/include/uibase/pluginsetting.h index 6844f4d0..0b00013f 100644 --- a/include/uibase/pluginsetting.h +++ b/include/uibase/pluginsetting.h @@ -21,29 +21,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef PLUGINSETTING_H #define PLUGINSETTING_H -#include -#include -#include +#include "extensionsetting.h" namespace MOBase { -/** - * @brief struct to hold the user-configurable parameters a plugin accepts. The purpose - * of this struct is only to inform the application what settings to offer to the user, - * it does not hold the actual value - */ -struct PluginSetting -{ - PluginSetting(const QString& key, const QString& description, - const QVariant& defaultValue) - : key(key), description(description), defaultValue(defaultValue) - {} - - QString key; - QString description; - QVariant defaultValue; -}; +// deprecated alias +using PluginSetting [[ deprecated ]] = Setting; } // namespace MOBase diff --git a/src/extension.cpp b/src/extension.cpp index bc50efdc..898beabb 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -96,10 +96,10 @@ ExtensionMetaData::ExtensionMetaData(std::filesystem::path const& path, Version::ParseMode::SemVer); } catch (InvalidVersionException const& ex) { throw InvalidExtensionMetaDataException( - std::format("invalid or missing version '{}'", jsonData["version"].toString())); + std::format("invalid or missing version '{}': {}", + jsonData["version"].toString(), ex.what())); } - // TODO: name of the key // translation context m_TranslationContext = jsonData["translation-context"].toString(""); @@ -337,7 +337,7 @@ TranslationExtension::parseTranslation(std::filesystem::path const& extensionFol QLocale locale(identifier); name = QString("%1 (%2)") .arg(locale.nativeLanguageName()) - .arg(locale.nativeCountryName()); + .arg(locale.nativeTerritoryName()); } return std::make_shared(identifier.toStdString(), name.toStdString(),