kodi
SettingsBase.h
1 /*
2  * Copyright (C) 2016-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 "settings/lib/ISettingCallback.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 class CSetting;
19 class CSettingSection;
20 class CSettingsManager;
21 class CVariant;
22 class CXBMCTinyXML;
23 class TiXmlElement;
24 
32 {
33 public:
34  virtual ~CSettingsBase();
35 
36  CSettingsManager* GetSettingsManager() const { return m_settingsManager; }
37 
44  virtual bool Initialize();
48  virtual bool IsInitialized() const;
54  virtual bool Load() = 0;
62  virtual void SetLoaded();
66  virtual bool IsLoaded() const;
72  virtual bool Save() = 0;
78  virtual void Unload();
85  virtual void Uninitialize();
86 
94  void RegisterCallback(ISettingCallback* callback, const std::set<std::string>& settingList);
100  void UnregisterCallback(ISettingCallback* callback);
101 
108  std::shared_ptr<CSetting> GetSetting(const std::string& id) const;
114  std::vector<std::shared_ptr<CSettingSection>> GetSections() const;
121  std::shared_ptr<CSettingSection> GetSection(const std::string& section) const;
122 
129  bool GetBool(const std::string& id) const;
136  int GetInt(const std::string& id) const;
143  double GetNumber(const std::string& id) const;
150  std::string GetString(const std::string& id) const;
157  std::vector<CVariant> GetList(const std::string& id) const;
158 
166  bool SetBool(const std::string& id, bool value);
173  bool ToggleBool(const std::string& id);
181  bool SetInt(const std::string& id, int value);
189  bool SetNumber(const std::string& id, double value);
197  bool SetString(const std::string& id, const std::string& value);
205  bool SetList(const std::string& id, const std::vector<CVariant>& value);
206 
213  bool SetDefault(const std::string &id);
217  void SetDefaults();
218 
219 protected:
220  CSettingsBase();
221 
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() { }
237 
238  bool InitializeDefinitionsFromXml(const CXBMCTinyXML& xml);
239 
247  bool LoadValuesFromXml(const CXBMCTinyXML& xml, bool& updated);
254  bool SaveValuesToXml(CXBMCTinyXML& xml) const;
255 
263  bool LoadValuesFromXml(const TiXmlElement* root, bool& updated);
264 
271  bool LoadHiddenValuesFromXml(const TiXmlElement* root);
272 
273  bool m_initialized = false;
274  CSettingsManager* m_settingsManager;
275  mutable CCriticalSection m_critical;
276 private:
277  CSettingsBase(const CSettingsBase&) = delete;
278  CSettingsBase& operator=(const CSettingsBase&) = delete;
279 };
virtual bool Load()=0
Loads the setting values.
virtual bool IsLoaded() const
Returns whether the settings system has been loaded or not.
Definition: SettingsBase.cpp:113
bool SetNumber(const std::string &id, double value)
Sets the real number value of the setting with the given identifier.
Definition: SettingsBase.cpp:223
virtual void Unload()
Unloads the previously loaded setting values.
Definition: SettingsBase.cpp:131
int GetInt(const std::string &id) const
Gets the integer value of the setting with the given identifier.
Definition: SettingsBase.cpp:208
std::shared_ptr< CSetting > GetSetting(const std::string &id) const
Gets the setting with the given identifier.
Definition: SettingsBase.cpp:172
Definition: XBMCTinyXML.h:33
virtual bool IsInitialized() const
Returns whether the settings system has been initialized or not.
Definition: SettingsBase.cpp:67
void UnregisterCallback(ISettingCallback *callback)
Unregisters the given ISettingCallback implementation.
Definition: SettingsBase.cpp:167
Definition: ISettingCallback.h:16
std::vector< std::shared_ptr< CSettingSection > > GetSections() const
Gets the full list of setting sections.
Definition: SettingsBase.cpp:180
bool SaveValuesToXml(CXBMCTinyXML &xml) const
Saves the setting values in XML format to the given document.
Definition: SettingsBase.cpp:118
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
virtual void SetLoaded()
Tells the settings system that all setting values have been loaded.
Definition: SettingsBase.cpp:108
bool SetDefault(const std::string &id)
Sets the value of the setting with the given identifier to its default.
Definition: SettingsBase.cpp:256
bool SetList(const std::string &id, const std::vector< CVariant > &value)
Sets the values of the list setting with the given identifier.
Definition: SettingsBase.cpp:247
std::vector< CVariant > GetList(const std::string &id) const
Gets the values of the list setting with the given identifier.
Definition: SettingsBase.cpp:238
Definition: Variant.h:31
double GetNumber(const std::string &id) const
Gets the real number value of the setting with the given identifier.
Definition: SettingsBase.cpp:218
std::string GetString(const std::string &id) const
Gets the string value of the setting with the given identifier.
Definition: SettingsBase.cpp:228
bool SetInt(const std::string &id, int value)
Sets the integer value of the setting with the given identifier.
Definition: SettingsBase.cpp:213
Section of setting categories.
Definition: SettingSection.h:152
virtual void Uninitialize()
Uninitializes the settings system.
Definition: SettingsBase.cpp:136
bool LoadHiddenValuesFromXml(const TiXmlElement *root)
Loads hidden setting values from the given XML element.
Definition: SettingsBase.cpp:89
bool GetBool(const std::string &id) const
Gets the boolean value of the setting with the given identifier.
Definition: SettingsBase.cpp:193
void RegisterCallback(ISettingCallback *callback, const std::set< std::string > &settingList)
Registers the given ISettingCallback implementation for the given set of settings.
Definition: SettingsBase.cpp:162
void SetDefaults()
Sets the value of all settings to their default.
Definition: SettingsBase.cpp:261
bool SetBool(const std::string &id, bool value)
Sets the boolean value of the setting with the given identifier.
Definition: SettingsBase.cpp:198
Basic wrapper around CSettingsManager providing the framework for properly setting up the settings ma...
Definition: SettingsBase.h:31
Settings manager responsible for initializing, loading and handling all settings. ...
Definition: SettingsManager.h:41
bool SetString(const std::string &id, const std::string &value)
Sets the string value of the setting with the given identifier.
Definition: SettingsBase.cpp:233
bool ToggleBool(const std::string &id)
Toggles the boolean value of the setting with the given identifier.
Definition: SettingsBase.cpp:203
bool LoadValuesFromXml(const CXBMCTinyXML &xml, bool &updated)
Loads setting values from the given document in XML format.
Definition: SettingsBase.cpp:72
virtual bool Initialize()
Initializes the setting system with the generic settings definition and platform specific setting def...
Definition: SettingsBase.cpp:33
virtual bool Save()=0
Saves the setting values.
std::shared_ptr< CSettingSection > GetSection(const std::string &section) const
Gets the setting section with the given identifier.
Definition: SettingsBase.cpp:185