diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/settings/lib/SettingConditions.h | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/settings/lib/SettingConditions.h')
-rw-r--r-- | xbmc/settings/lib/SettingConditions.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/xbmc/settings/lib/SettingConditions.h b/xbmc/settings/lib/SettingConditions.h new file mode 100644 index 0000000..aee2c06 --- /dev/null +++ b/xbmc/settings/lib/SettingConditions.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2013-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 "SettingDefinitions.h" +#include "utils/BooleanLogic.h" + +#include <map> +#include <set> +#include <string> +#include <utility> + +class CSettingsManager; +class CSetting; + +using SettingConditionCheck = bool (*)(const std::string& condition, + const std::string& value, + const std::shared_ptr<const CSetting>& setting, + void* data); + +class ISettingCondition +{ +public: + explicit ISettingCondition(CSettingsManager *settingsManager) + : m_settingsManager(settingsManager) + { } + virtual ~ISettingCondition() = default; + + virtual bool Check() const = 0; + +protected: + CSettingsManager *m_settingsManager; +}; + +class CSettingConditionItem : public CBooleanLogicValue, public ISettingCondition +{ +public: + explicit CSettingConditionItem(CSettingsManager *settingsManager = nullptr) + : ISettingCondition(settingsManager) + { } + ~CSettingConditionItem() override = default; + + bool Deserialize(const TiXmlNode *node) override; + const char* GetTag() const override { return SETTING_XML_ELM_CONDITION; } + bool Check() const override; + +protected: + std::string m_name; + std::string m_setting; +}; + +class CSettingConditionCombination : public CBooleanLogicOperation, public ISettingCondition +{ +public: + explicit CSettingConditionCombination(CSettingsManager *settingsManager = nullptr) + : ISettingCondition(settingsManager) + { } + ~CSettingConditionCombination() override = default; + + bool Check() const override; + +private: + CBooleanLogicOperation* newOperation() override { return new CSettingConditionCombination(m_settingsManager); } + CBooleanLogicValue* newValue() override { return new CSettingConditionItem(m_settingsManager); } +}; + +class CSettingCondition : public CBooleanLogic, public ISettingCondition +{ +public: + explicit CSettingCondition(CSettingsManager *settingsManager = nullptr); + ~CSettingCondition() override = default; + + bool Check() const override; +}; + +class CSettingConditionsManager +{ +public: + CSettingConditionsManager() = default; + CSettingConditionsManager(const CSettingConditionsManager&) = delete; + CSettingConditionsManager const& operator=(CSettingConditionsManager const&) = delete; + virtual ~CSettingConditionsManager() = default; + + void AddCondition(std::string condition); + void AddDynamicCondition(std::string identifier, SettingConditionCheck condition, void *data = nullptr); + void RemoveDynamicCondition(std::string identifier); + + bool Check( + std::string condition, + const std::string& value = "", + const std::shared_ptr<const CSetting>& setting = std::shared_ptr<const CSetting>()) const; + +private: + using SettingConditionPair = std::pair<std::string, std::pair<SettingConditionCheck, void*>>; + using SettingConditionMap = std::map<std::string, std::pair<SettingConditionCheck, void*>>; + + SettingConditionMap m_conditions; + std::set<std::string> m_defines; +}; |