From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/settings/lib/SettingConditions.h | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 xbmc/settings/lib/SettingConditions.h (limited to 'xbmc/settings/lib/SettingConditions.h') 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 +#include +#include +#include + +class CSettingsManager; +class CSetting; + +using SettingConditionCheck = bool (*)(const std::string& condition, + const std::string& value, + const std::shared_ptr& 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& setting = std::shared_ptr()) const; + +private: + using SettingConditionPair = std::pair>; + using SettingConditionMap = std::map>; + + SettingConditionMap m_conditions; + std::set m_defines; +}; -- cgit v1.2.3