/* * Copyright (C) 2017-2018 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later * See LICENSES/README.md for more information. */ #pragma once #include "addons/IAddon.h" #include "settings/SettingControl.h" #include "settings/SettingCreator.h" #include "settings/SettingsBase.h" #include "settings/lib/ISettingCallback.h" #include #include #include #include #include enum class SettingDependencyOperator; class CSettingCategory; class CSettingGroup; class CSettingDependency; class CXBMCTinyXML; struct StringSettingOption; namespace ADDON { class IAddon; class IAddonInstanceHandler; class CAddonSettings : public CSettingControlCreator, public CSettingCreator, public CSettingsBase, public ISettingCallback { public: CAddonSettings(const std::shared_ptr& addon, AddonInstanceId instanceId); ~CAddonSettings() override = default; // specialization of CSettingsBase bool Initialize() override { return false; } // implementations of CSettingsBase bool Load() override { return false; } bool Save() override { return false; } // specialization of CSettingCreator std::shared_ptr CreateSetting( const std::string& settingType, const std::string& settingId, CSettingsManager* settingsManager = nullptr) const override; // implementation of ISettingCallback void OnSettingAction(const std::shared_ptr& setting) override; const std::string& GetAddonId() const { return m_addonId; } bool Initialize(const CXBMCTinyXML& doc, bool allowEmpty = false); bool Load(const CXBMCTinyXML& doc); bool Save(CXBMCTinyXML& doc) const; bool HasSettings() const; std::string GetSettingLabel(int label) const; std::shared_ptr AddSetting(const std::string& settingId, bool value); std::shared_ptr AddSetting(const std::string& settingId, int value); std::shared_ptr AddSetting(const std::string& settingId, double value); std::shared_ptr AddSetting(const std::string& settingId, const std::string& value); protected: // specializations of CSettingsBase void InitializeSettingTypes() override; void InitializeControls() override; void InitializeConditions() override; // implementation of CSettingsBase bool InitializeDefinitions() override { return false; } private: bool AddInstanceSettings(); bool InitializeDefinitions(const CXBMCTinyXML& doc); bool ParseSettingVersion(const CXBMCTinyXML& doc, uint32_t& version) const; std::shared_ptr ParseOldSettingElement( const TiXmlElement* categoryElement, const std::shared_ptr& category, std::set& settingIds); std::shared_ptr ParseOldCategoryElement(uint32_t& categoryId, const TiXmlElement* categoryElement, std::set& settingIds); bool InitializeFromOldSettingDefinitions(const CXBMCTinyXML& doc); std::shared_ptr InitializeFromOldSettingAction(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue); std::shared_ptr InitializeFromOldSettingLabel(); std::shared_ptr InitializeFromOldSettingBool(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue); std::shared_ptr InitializeFromOldSettingTextIpAddress( const std::string& settingId, const std::string& settingType, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingNumber(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingPath(const std::string& settingId, const std::string& settingType, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingDate(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingTime(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingSelect( const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel, const std::string& settingValues, const std::vector& settingLValues); std::shared_ptr InitializeFromOldSettingAddon(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const int settingLabel); std::shared_ptr InitializeFromOldSettingEnums( const std::string& settingId, const std::string& settingType, const TiXmlElement* settingElement, const std::string& defaultValue, const std::string& settingValues, const std::vector& settingLValues); std::shared_ptr InitializeFromOldSettingFileEnum(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, const std::string& settingValues); std::shared_ptr InitializeFromOldSettingRangeOfNum(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue); std::shared_ptr InitializeFromOldSettingSlider(const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue); std::shared_ptr InitializeFromOldSettingFileWithSource( const std::string& settingId, const TiXmlElement* settingElement, const std::string& defaultValue, std::string source); bool LoadOldSettingValues(const CXBMCTinyXML& doc, std::map& settings) const; struct ConditionExpression { SettingDependencyOperator m_operator; bool m_negated; int32_t m_relativeSettingIndex; std::string m_value; }; bool ParseOldLabel(const TiXmlElement* element, const std::string& settingId, int& labelId); bool ParseOldCondition(const std::shared_ptr& setting, const std::vector>& settings, const std::string& condition, CSettingDependency& dependeny) const; static bool ParseOldConditionExpression(std::string str, ConditionExpression& expression); static void FileEnumSettingOptionsFiller(const std::shared_ptr& setting, std::vector& list, std::string& current, void* data); // store these values so that we don't always have to access the weak pointer const std::string m_addonId; const std::string m_addonPath; const std::string m_addonProfile; const AddonInstanceId m_instanceId{ADDON_SETTINGS_ID}; uint32_t m_unidentifiedSettingId; int m_unknownSettingLabelId; std::map m_unknownSettingLabels; Logger m_logger; }; } // namespace ADDON