11 #include "ISettingCallback.h" 12 #include "ISettingControlCreator.h" 13 #include "ISettingCreator.h" 14 #include "ISettingsHandler.h" 15 #include "ISettingsValueSerializer.h" 17 #include "SettingConditions.h" 18 #include "SettingDefinitions.h" 19 #include "SettingDependency.h" 20 #include "threads/SharedSection.h" 21 #include "utils/logtypes.h" 25 #include <unordered_set> 53 static const uint32_t Version;
54 static const uint32_t MinimumSupportedVersion;
57 std::shared_ptr<CSetting>
CreateSetting(
const std::string &settingType,
const std::string &settingId,
CSettingsManager *settingsManager =
nullptr)
const override;
60 std::shared_ptr<ISettingControl>
CreateControl(
const std::string &controlType)
const override;
62 uint32_t GetVersion()
const {
return Version; }
63 uint32_t GetMinimumSupportedVersion()
const {
return MinimumSupportedVersion; }
90 bool Load(
const TiXmlElement *root,
bool &updated,
bool triggerEvents =
true, std::map<std::string, std::shared_ptr<CSetting>> *loadedSettings =
nullptr);
121 bool LoadSetting(
const TiXmlNode *node,
const std::string &settingId);
132 bool LoadSetting(
const TiXmlNode *node,
const std::string &settingId,
bool &updated);
164 void AddSection(
const std::shared_ptr<CSettingSection>& section);
184 bool AddSetting(
const std::shared_ptr<CSetting>& setting,
185 const std::shared_ptr<CSettingSection>& section,
186 const std::shared_ptr<CSettingCategory>& category,
187 const std::shared_ptr<CSettingGroup>&
group);
285 std::shared_ptr<CSetting>
GetSetting(
const std::string &
id)
const;
291 std::vector<std::shared_ptr<CSettingSection>>
GetSections()
const;
298 std::shared_ptr<CSettingSection>
GetSection(std::string section)
const;
323 SettingDependencyMap
GetDependencies(
const std::shared_ptr<const CSetting>& setting)
const;
331 bool GetBool(
const std::string &
id)
const;
338 int GetInt(
const std::string &
id)
const;
345 double GetNumber(
const std::string &
id)
const;
352 std::string
GetString(
const std::string &
id)
const;
359 std::vector< std::shared_ptr<CSetting> >
GetList(
const std::string &
id)
const;
368 bool SetBool(
const std::string &
id,
bool value);
383 bool SetInt(
const std::string &
id,
int value);
391 bool SetNumber(
const std::string &
id,
double value);
399 bool SetString(
const std::string &
id,
const std::string &value);
407 bool SetList(
const std::string &
id,
const std::vector< std::shared_ptr<CSetting> > &value);
446 void AddDynamicCondition(
const std::string &identifier, SettingConditionCheck condition,
void *data =
nullptr);
457 bool OnSettingChanging(
const std::shared_ptr<const CSetting>& setting)
override;
458 void OnSettingChanged(
const std::shared_ptr<const CSetting>& setting)
override;
459 void OnSettingAction(
const std::shared_ptr<const CSetting>& setting)
override;
460 bool OnSettingUpdate(
const std::shared_ptr<CSetting>& setting,
461 const char* oldSettingId,
462 const TiXmlNode* oldSettingNode)
override;
463 void OnSettingPropertyChanged(
const std::shared_ptr<const CSetting>& setting,
464 const char* propertyName)
override;
467 bool OnSettingsLoading()
override;
468 void OnSettingsLoaded()
override;
469 void OnSettingsUnloaded()
override;
470 bool OnSettingsSaving()
const override;
471 void OnSettingsSaved()
const override;
472 void OnSettingsCleared()
override;
474 bool Serialize(TiXmlNode *parent)
const;
475 bool Deserialize(
const TiXmlNode *node,
bool &updated, std::map<std::string, std::shared_ptr<CSetting>> *loadedSettings =
nullptr);
477 bool LoadSetting(
const TiXmlNode* node,
const std::shared_ptr<CSetting>& setting,
bool& updated);
478 bool UpdateSetting(
const TiXmlNode* node,
479 const std::shared_ptr<CSetting>& setting,
481 void UpdateSettingByDependency(
const std::string &settingId,
const CSettingDependency &dependency);
482 void UpdateSettingByDependency(
const std::string &settingId, SettingDependencyType dependencyType);
484 void AddSetting(
const std::shared_ptr<CSetting>& setting);
486 void ResolveReferenceSettings(
const std::shared_ptr<CSettingSection>& section);
487 void CleanupIncompleteSettings();
489 enum class SettingOptionsFillerType {
497 using CallbackSet = std::set<ISettingCallback *>;
499 std::shared_ptr<CSetting> setting;
500 SettingDependencyMap dependencies;
501 std::set<std::string> children;
502 CallbackSet callbacks;
503 std::unordered_set<std::string> references;
506 using SettingMap = std::map<std::string, Setting>;
516 void RefreshVisibilityAndEnableStatus(
const std::shared_ptr<const CSetting>& setting);
518 void ResolveSettingDependencies(
const std::shared_ptr<CSetting>& setting);
519 void ResolveSettingDependencies(
const Setting& setting);
521 SettingMap::const_iterator FindSetting(std::string settingId)
const;
522 SettingMap::iterator FindSetting(std::string settingId);
523 std::pair<SettingMap::iterator, bool> InsertSetting(std::string settingId,
const Setting& setting);
525 bool m_initialized =
false;
526 bool m_loaded =
false;
528 SettingMap m_settings;
529 using SettingSectionMap = std::map<std::string, std::shared_ptr<CSettingSection>>;
530 SettingSectionMap m_sections;
532 using SettingCreatorMap = std::map<std::string, ISettingCreator*>;
533 SettingCreatorMap m_settingCreators;
535 using SettingControlCreatorMap = std::map<std::string, ISettingControlCreator*>;
536 SettingControlCreatorMap m_settingControlCreators;
538 using SettingsHandlers = std::vector<ISettingsHandler*>;
539 SettingsHandlers m_settingsHandlers;
543 struct SettingOptionsFiller {
545 SettingOptionsFillerType type;
547 using SettingOptionsFillerMap = std::map<std::string, SettingOptionsFiller>;
548 SettingOptionsFillerMap m_optionsFillers;
void UnregisterSettingOptionsFiller(const std::string &identifier)
Unregisters the setting options filler registered under the given identifier.
Definition: SettingsManager.cpp:460
Category of groups of settings being part of a section.
Definition: SettingSection.h:93
std::shared_ptr< CSettingSection > GetSection(std::string section) const
Gets the setting section with the given identifier.
Definition: SettingsManager.cpp:549
std::shared_ptr< ISettingControl > CreateControl(const std::string &controlType) const override
Creates a new setting control of the given custom setting control type.
Definition: SettingsManager.cpp:986
bool IsLoaded() const
Returns whether the settings system has been loaded or not.
Definition: SettingsManager.h:156
void RegisterCallback(ISettingCallback *callback, const std::set< std::string > &settingList)
Registers the given ISettingCallback implementation to be triggered for the given list of settings...
Definition: SettingsManager.cpp:366
bool SetBool(const std::string &id, bool value)
Sets the boolean value of the setting with the given identifier.
Definition: SettingsManager.cpp:593
const CSettingConditionsManager & GetConditions() const
Gets the setting conditions manager used by the settings manager.
Definition: SettingsManager.h:426
CSettingsManager()
Creates a new (uninitialized) settings manager.
Definition: SettingsManager.cpp:56
bool GetBool(const std::string &id) const
Gets the boolean value of the setting with the given identifier.
Definition: SettingsManager.cpp:583
bool HasSettings() const
Checks whether any settings have been initialized.
Definition: SettingsManager.cpp:516
Definition: ISettingCallback.h:16
void RemoveDynamicCondition(const std::string &identifier)
Removes the given dynamic condition.
Definition: SettingsManager.cpp:729
bool AddSetting(const std::shared_ptr< CSetting > &setting, const std::shared_ptr< CSettingSection > §ion, const std::shared_ptr< CSettingCategory > &category, const std::shared_ptr< CSettingGroup > &group)
Adds the given setting to the given group in the given category in the given section;.
Definition: SettingsManager.cpp:310
bool Initialize(const TiXmlElement *root)
Initializes the settings manager using the setting definitions represented by the given XML element...
Definition: SettingsManager.cpp:81
Interface for creating a new setting control of a custom setting control type.
Definition: ISettingControlCreator.h:20
bool SetInt(const std::string &id, int value)
Sets the integer value of the setting with the given identifier.
Definition: SettingsManager.cpp:623
Section of setting categories.
Definition: SettingSection.h:152
Definition: SettingConditions.h:82
Interface for creating a new setting of a custom setting type.
Definition: ISettingCreator.h:21
void Unload()
Unloads the previously loaded setting values.
Definition: SettingsManager.cpp:199
std::string GetString(const std::string &id) const
Gets the string value of the setting with the given identifier.
Definition: SettingsManager.cpp:653
void SetDefaults()
Sets the value of all settings to their default.
Definition: SettingsManager.cpp:704
void UnregisterSettingsHandler(ISettingsHandler *settingsHandler)
Unregisters the given ISettingsHandler implementation.
Definition: SettingsManager.cpp:433
void Clear()
Clears the complete settings manager.
Definition: SettingsManager.cpp:215
void RegisterSettingOptionsFiller(const std::string &identifier, IntegerSettingOptionsFiller optionsFiller)
Registers the given integer setting options filler under the given identifier.
Definition: SettingsManager.cpp:444
bool Save(const ISettingsValueSerializer *serializer, std::string &serializedValues) const
Saves the setting values using the given serializer.
Definition: SettingsManager.cpp:178
void UnregisterCallback(ISettingCallback *callback)
Unregisters the given ISettingCallback implementation.
Definition: SettingsManager.cpp:389
void * GetSettingOptionsFiller(const std::shared_ptr< const CSetting > &setting)
Gets the implementation of the setting options filler used by the given setting.
Definition: SettingsManager.cpp:466
bool SetString(const std::string &id, const std::string &value)
Sets the string value of the setting with the given identifier.
Definition: SettingsManager.cpp:663
void RegisterSettingsHandler(ISettingsHandler *settingsHandler, bool bFront=false)
Registers the given ISettingsHandler implementation.
Definition: SettingsManager.cpp:418
double GetNumber(const std::string &id) const
Gets the real number value of the setting with the given identifier.
Definition: SettingsManager.cpp:633
Definition: SettingUpdate.h:23
Definition: ISettingsValueSerializer.h:15
Definition: SmartPlayList.cpp:137
Interface defining methods being called by the settings system if an action is performed on multiple/...
Definition: ISettingsHandler.h:16
bool SetDefault(const std::string &id)
Sets the value of the setting to its default.
Definition: SettingsManager.cpp:693
void AddCondition(const std::string &condition)
Adds the given static condition.
Definition: SettingsManager.cpp:711
void AddDynamicCondition(const std::string &identifier, SettingConditionCheck condition, void *data=nullptr)
Adds the given dynamic condition.
Definition: SettingsManager.cpp:720
int GetInt(const std::string &id) const
Gets the integer value of the setting with the given identifier.
Definition: SettingsManager.cpp:613
A CSharedSection is a mutex that satisfies the Shared Lockable concept (see Lockables.h).
Definition: SharedSection.h:19
Settings manager responsible for initializing, loading and handling all settings. ...
Definition: SettingsManager.h:41
void RegisterSettingControl(const std::string &controlType, ISettingControlCreator *settingControlCreator)
Registers a custom setting control type and its ISettingControlCreator implementation.
Definition: SettingsManager.cpp:407
bool SetNumber(const std::string &id, double value)
Sets the real number value of the setting with the given identifier.
Definition: SettingsManager.cpp:643
Group of settings being part of a category.
Definition: SettingSection.h:28
std::shared_ptr< CSetting > GetSetting(const std::string &id) const
Gets the setting with the given identifier.
Definition: SettingsManager.cpp:521
bool IsInitialized() const
Returns whether the settings system has been initialized or not.
Definition: SettingsManager.h:144
std::shared_ptr< CSetting > CreateSetting(const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager=nullptr) const override
Creates a new setting of the given custom setting type.
Definition: SettingsManager.cpp:956
bool ToggleBool(const std::string &id)
Toggles the boolean value of the setting with the given identifier.
Definition: SettingsManager.cpp:603
Definition: SettingDependency.h:111
void SetInitialized()
Tells the settings system that the initialization is complete.
Definition: SettingsManager.cpp:248
uint32_t ParseVersion(const TiXmlElement *root) const
Try to get the version of the setting definitions/values represented by the given XML element...
Definition: SettingsManager.cpp:72
bool LoadSetting(const TiXmlNode *node, const std::string &settingId)
Loads the setting being represented by the given XML node with the given identifier.
Definition: SettingsManager.cpp:228
SettingDependencyMap GetDependencies(const std::string &id) const
Gets a map of settings (and their dependencies) which depend on the setting with the given identifier...
Definition: SettingsManager.cpp:565
std::vector< std::shared_ptr< CSettingSection > > GetSections() const
Gets the full list of setting sections.
Definition: SettingsManager.cpp:539
std::vector< std::shared_ptr< CSetting > > GetList(const std::string &id) const
Gets the values of the list setting with the given identifier.
Definition: SettingsManager.cpp:673
void SetLoaded()
Tells the settings system that all setting values have been loaded.
Definition: SettingsManager.h:152
bool SetList(const std::string &id, const std::vector< std::shared_ptr< CSetting > > &value)
Sets the values of the list setting with the given identifier.
Definition: SettingsManager.cpp:683
void RegisterSettingType(const std::string &settingType, ISettingCreator *settingCreator)
Registers a custom setting type and its ISettingCreator implementation.
Definition: SettingsManager.cpp:396
void AddSection(const std::shared_ptr< CSettingSection > §ion)
Adds the given section, its categories, groups and settings.
Definition: SettingsManager.cpp:268
bool Load(const TiXmlElement *root, bool &updated, bool triggerEvents=true, std::map< std::string, std::shared_ptr< CSetting >> *loadedSettings=nullptr)
Loads setting values from the given XML element.
Definition: SettingsManager.cpp:141