1 /* 2 * Copyright (C) 2013-2018 Team Kodi 3 * This file is part of Kodi - https://kodi.tv 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * See LICENSES/README.md for more information. 7 */ 8 9 #pragma once 10 11 #include "SettingRequirement.h" 12 13 #include <string> 14 15 class CSettingsManager; 16 class TiXmlNode; 17 18 /*! 19 \ingroup settings 20 \brief Interface defining the base of all setting objects 21 */ 22 class ISetting 23 { 24 public: 25 /*! 26 \brief Creates a new setting object with the given identifier. 27 28 \param id Identifier of the setting object 29 \param settingsManager Reference to the settings manager 30 */ 31 ISetting(const std::string &id, CSettingsManager *settingsManager = nullptr); 32 virtual ~ISetting() = default; 33 34 /*! 35 \brief Deserializes the given XML node into the properties of the setting 36 object. 37 38 If the update parameter is true, the checks for mandatory properties are 39 skipped and values are only updated. 40 41 \param node XML node containing the properties of the setting object 42 \param update Whether to perform checks for mandatory properties or not 43 \return True if deserialization was successful, false otherwise 44 */ 45 virtual bool Deserialize(const TiXmlNode *node, bool update = false); 46 47 /*! 48 \brief Gets the identifier of the setting object. 49 50 \return Identifier of the setting object 51 */ GetId()52 const std::string& GetId() const { return m_id; } 53 /*! 54 \brief Whether the setting object is visible or hidden. 55 56 \return True if the setting object is visible, false otherwise 57 */ IsVisible()58 virtual bool IsVisible() const { return m_visible; } 59 /*! 60 \brief Sets the visibility state of the setting object. 61 62 \param visible Whether the setting object shall be visible or not 63 */ SetVisible(bool visible)64 virtual void SetVisible(bool visible) { m_visible = visible; } 65 /*! 66 \brief Gets the localizeable label ID of the setting group. 67 68 \return Localizeable label ID of the setting group 69 */ GetLabel()70 int GetLabel() const { return m_label; } 71 /*! 72 \brief Sets the localizeable label ID of the setting group. 73 74 \param label Localizeable label ID of the setting group 75 */ SetLabel(int label)76 void SetLabel(int label) { m_label = label; } 77 /*! 78 \brief Gets the localizeable help ID of the setting group. 79 80 \return Localizeable help ID of the setting group 81 */ GetHelp()82 int GetHelp() const { return m_help; } 83 /*! 84 \brief Sets the localizeable help ID of the setting group. 85 86 \param label Localizeable help ID of the setting group 87 */ SetHelp(int help)88 void SetHelp(int help) { m_help = help; } 89 /*! 90 \brief Whether the setting object meets all necessary requirements. 91 92 \return True if the setting object meets all necessary requirements, false otherwise 93 */ MeetsRequirements()94 virtual bool MeetsRequirements() const { return m_meetsRequirements; } 95 /*! 96 \brief Checks if the setting object meets all necessary requirements. 97 */ 98 virtual void CheckRequirements(); 99 /*! 100 \brief Sets whether the setting object meets all necessary requirements. 101 102 \param visible Whether the setting object meets all necessary requirements or not 103 */ SetRequirementsMet(bool requirementsMet)104 virtual void SetRequirementsMet(bool requirementsMet) { m_meetsRequirements = requirementsMet; } 105 106 /*! 107 \brief Deserializes the given XML node to retrieve a setting object's 108 identifier. 109 110 \param node XML node containing a setting object's identifier 111 \param identification Will contain the deserialized setting object's identifier 112 \return True if a setting object's identifier was deserialized, false otherwise 113 */ 114 static bool DeserializeIdentification(const TiXmlNode *node, std::string &identification); 115 116 protected: 117 std::string m_id; 118 CSettingsManager *m_settingsManager; 119 120 private: 121 bool m_visible = true; 122 int m_label = -1; 123 int m_help = -1; 124 bool m_meetsRequirements = true; 125 CSettingRequirement m_requirementCondition; 126 }; 127