2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "settings/lib/ISettingCallback.h"
12 #include "threads/CriticalSection.h"
19 class CSettingSection
;
20 class CSettingsManager
;
26 \brief Basic wrapper around CSettingsManager providing the framework for
27 properly setting up the settings manager and registering all the callbacks,
28 handlers and custom setting types.
34 virtual ~CSettingsBase();
36 CSettingsManager
* GetSettingsManager() const { return m_settingsManager
; }
39 \brief Initializes the setting system with the generic
40 settings definition and platform specific setting definitions.
42 \return True if the initialization was successful, false otherwise
44 virtual bool Initialize();
46 \brief Returns whether the settings system has been initialized or not.
48 virtual bool IsInitialized() const;
50 \brief Loads the setting values.
52 \return True if the setting values are successfully loaded, false otherwise
54 virtual bool Load() = 0;
56 \brief Tells the settings system that all setting values
59 This manual trigger is necessary to enable the ISettingCallback methods
62 virtual void SetLoaded();
64 \brief Returns whether the settings system has been loaded or not.
66 virtual bool IsLoaded() const;
68 \brief Saves the setting values.
70 \return True if the setting values were successfully saved, false otherwise
72 virtual bool Save() = 0;
74 \brief Unloads the previously loaded setting values.
76 The values of all the settings are reset to their default values.
78 virtual void Unload();
80 \brief Uninitializes the settings system.
82 Unregisters all previously registered callbacks and destroys all setting
85 virtual void Uninitialize();
88 \brief Registers the given ISettingCallback implementation for the given
91 \param callback ISettingCallback implementation
92 \param settingList List of setting identifiers for which the given callback shall be triggered
94 void RegisterCallback(ISettingCallback
* callback
, const std::set
<std::string
>& settingList
);
96 \brief Unregisters the given ISettingCallback implementation.
98 \param callback ISettingCallback implementation
100 void UnregisterCallback(ISettingCallback
* callback
);
103 \brief Gets the setting with the given identifier.
105 \param id Setting identifier
106 \return Setting object with the given identifier or NULL if the identifier is unknown
108 std::shared_ptr
<CSetting
> GetSetting(const std::string
& id
) const;
110 \brief Gets the full list of setting sections.
112 \return List of setting sections
114 std::vector
<std::shared_ptr
<CSettingSection
>> GetSections() const;
116 \brief Gets the setting section with the given identifier.
118 \param section Setting section identifier
119 \return Setting section with the given identifier or NULL if the identifier is unknown
121 std::shared_ptr
<CSettingSection
> GetSection(const std::string
& section
) const;
124 \brief Gets the boolean value of the setting with the given identifier.
126 \param id Setting identifier
127 \return Boolean value of the setting with the given identifier
129 bool GetBool(const std::string
& id
) const;
131 \brief Gets the integer value of the setting with the given identifier.
133 \param id Setting identifier
134 \return Integer value of the setting with the given identifier
136 int GetInt(const std::string
& id
) const;
138 \brief Gets the real number value of the setting with the given identifier.
140 \param id Setting identifier
141 \return Real number value of the setting with the given identifier
143 double GetNumber(const std::string
& id
) const;
145 \brief Gets the string value of the setting with the given identifier.
147 \param id Setting identifier
148 \return String value of the setting with the given identifier
150 std::string
GetString(const std::string
& id
) const;
152 \brief Gets the values of the list setting with the given identifier.
154 \param id Setting identifier
155 \return List of values of the setting with the given identifier
157 std::vector
<CVariant
> GetList(const std::string
& id
) const;
160 \brief Sets the boolean value of the setting with the given identifier.
162 \param id Setting identifier
163 \param value Boolean value to set
164 \return True if setting the value was successful, false otherwise
166 bool SetBool(const std::string
& id
, bool value
);
168 \brief Toggles the boolean value of the setting with the given identifier.
170 \param id Setting identifier
171 \return True if toggling the boolean value was successful, false otherwise
173 bool ToggleBool(const std::string
& id
);
175 \brief Sets the integer value of the setting with the given identifier.
177 \param id Setting identifier
178 \param value Integer value to set
179 \return True if setting the value was successful, false otherwise
181 bool SetInt(const std::string
& id
, int value
);
183 \brief Sets the real number value of the setting with the given identifier.
185 \param id Setting identifier
186 \param value Real number value to set
187 \return True if setting the value was successful, false otherwise
189 bool SetNumber(const std::string
& id
, double value
);
191 \brief Sets the string value of the setting with the given identifier.
193 \param id Setting identifier
194 \param value String value to set
195 \return True if setting the value was successful, false otherwise
197 bool SetString(const std::string
& id
, const std::string
& value
);
199 \brief Sets the values of the list setting with the given identifier.
201 \param id Setting identifier
202 \param value Values to set
203 \return True if setting the values was successful, false otherwise
205 bool SetList(const std::string
& id
, const std::vector
<CVariant
>& value
);
208 \brief Sets the value of the setting with the given identifier to its default.
210 \param id Setting identifier
211 \return True if setting the value to its default was successful, false otherwise
213 bool SetDefault(const std::string
&id
);
215 \brief Sets the value of all settings to their default.
222 virtual void InitializeSettingTypes() { }
223 virtual void InitializeControls() { }
224 virtual void InitializeOptionFillers() { }
225 virtual void UninitializeOptionFillers() { }
226 virtual void InitializeConditions() { }
227 virtual void UninitializeConditions() { }
228 virtual bool InitializeDefinitions() = 0;
229 virtual void InitializeVisibility() { }
230 virtual void InitializeDefaults() { }
231 virtual void InitializeISettingsHandlers() { }
232 virtual void UninitializeISettingsHandlers() { }
233 virtual void InitializeISubSettings() { }
234 virtual void UninitializeISubSettings() { }
235 virtual void InitializeISettingCallbacks() { }
236 virtual void UninitializeISettingCallbacks() { }
238 bool InitializeDefinitionsFromXml(const CXBMCTinyXML
& xml
);
241 \brief Loads setting values from the given document in XML format
243 \param xml Document in XML format from which the settings are loaded
244 \param updated Output parameter indicating whether setting values had to be updated
245 \return True if the setting values were successfully loaded, false otherwise
247 bool LoadValuesFromXml(const CXBMCTinyXML
& xml
, bool& updated
);
249 \brief Saves the setting values in XML format to the given document.
251 \param xml Document to save the setting values in XML format into
252 \return True if the setting values were successfully saved, false otherwise
254 bool SaveValuesToXml(CXBMCTinyXML
& xml
) const;
257 \brief Loads setting values from the given XML element.
259 \param root XML element containing setting values
260 \param updated Output parameter indicating whether setting values had to be updated
261 \return True if the setting values were successfully loaded, false otherwise
263 bool LoadValuesFromXml(const TiXmlElement
* root
, bool& updated
);
266 \brief Loads hidden setting values from the given XML element.
268 \param root XML element containing setting values
269 \return True if the setting values were successfully loaded, false otherwise
271 bool LoadHiddenValuesFromXml(const TiXmlElement
* root
);
273 bool m_initialized
= false;
274 CSettingsManager
* m_settingsManager
;
275 mutable CCriticalSection m_critical
;
277 CSettingsBase(const CSettingsBase
&) = delete;
278 CSettingsBase
& operator=(const CSettingsBase
&) = delete;