Kodi Documentation 18.0
Kodi is an open source media player and entertainment hub.
CSettingsManager Class Reference

Settings manager responsible for initializing, loading and handling all settings. More...

#include <SettingsManager.h>

Inheritance diagram for CSettingsManager:
ISettingCreator ISettingControlCreator ISettingCallback ISettingsHandler ISubSettings

Public Member Functions

 CSettingsManager ()=default
 Creates a new (uninitialized) settings manager. More...
 
 ~CSettingsManager () override
 
std::shared_ptr< CSettingCreateSetting (const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager=nullptr) const override
 Creates a new setting of the given custom setting type. More...
 
std::shared_ptr< ISettingControlCreateControl (const std::string &controlType) const override
 Creates a new setting control of the given custom setting control type. More...
 
uint32_t ParseVersion (const TiXmlElement *root) const
 Try to get the version of the setting definitions/values represented by the given XML element. More...
 
bool Initialize (const TiXmlElement *root)
 Initializes the settings manager using the setting definitions represented by the given XML element. More...
 
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. More...
 
bool Save (TiXmlNode *root) const override
 Saves the setting values to the given XML node. More...
 
void Unload ()
 Unloads the previously loaded setting values. More...
 
void Clear () override
 Clears the complete settings manager. More...
 
bool LoadSetting (const TiXmlNode *node, const std::string &settingId)
 Loads the setting being represented by the given XML node with the given identifier. More...
 
bool LoadSetting (const TiXmlNode *node, const std::string &settingId, bool &updated)
 Loads the setting being represented by the given XML node with the given identifier. More...
 
void SetInitialized ()
 Tells the settings system that the initialization is complete. More...
 
bool IsInitialized () const
 Returns whether the settings system has been initialized or not. More...
 
void SetLoaded ()
 Tells the settings system that all setting values have been loaded. More...
 
bool IsLoaded () const
 Returns whether the settings system has been loaded or not. More...
 
void AddSection (std::shared_ptr< CSettingSection > section)
 Adds the given section, its categories, groups and settings. More...
 
bool AddSetting (std::shared_ptr< CSetting > setting, std::shared_ptr< CSettingSection > section, std::shared_ptr< CSettingCategory > category, std::shared_ptr< CSettingGroup > group)
 Adds the given setting to the given group in the given category in the given section;. More...
 
void RegisterCallback (ISettingCallback *callback, const std::set< std::string > &settingList)
 Registers the given ISettingCallback implementation to be triggered for the given list of settings. More...
 
void UnregisterCallback (ISettingCallback *callback)
 Unregisters the given ISettingCallback implementation. More...
 
void RegisterSettingType (const std::string &settingType, ISettingCreator *settingCreator)
 Registers a custom setting type and its ISettingCreator implementation. More...
 
void RegisterSettingControl (const std::string &controlType, ISettingControlCreator *settingControlCreator)
 Registers a custom setting control type and its ISettingControlCreator implementation. More...
 
void RegisterSettingsHandler (ISettingsHandler *settingsHandler, bool bFront=false)
 Registers the given ISettingsHandler implementation. More...
 
void UnregisterSettingsHandler (ISettingsHandler *settingsHandler)
 Unregisters the given ISettingsHandler implementation. More...
 
void RegisterSubSettings (ISubSettings *subSettings)
 Registers the given ISubSettings implementation. More...
 
void UnregisterSubSettings (ISubSettings *subSettings)
 Unregisters the given ISubSettings implementation. More...
 
void RegisterSettingOptionsFiller (const std::string &identifier, IntegerSettingOptionsFiller optionsFiller)
 Registers the given integer setting options filler under the given identifier. More...
 
void RegisterSettingOptionsFiller (const std::string &identifier, StringSettingOptionsFiller optionsFiller)
 Registers the given string setting options filler under the given identifier. More...
 
void UnregisterSettingOptionsFiller (const std::string &identifier)
 Unregisters the setting options filler registered under the given identifier. More...
 
voidGetSettingOptionsFiller (std::shared_ptr< const CSetting > setting)
 Gets the implementation of the setting options filler used by the given setting. More...
 
std::shared_ptr< CSettingGetSetting (const std::string &id) const
 Gets the setting with the given identifier. More...
 
std::vector< std::shared_ptr< CSettingSection > > GetSections () const
 Gets the full list of setting sections. More...
 
std::shared_ptr< CSettingSectionGetSection (std::string section) const
 Gets the setting section with the given identifier. More...
 
SettingDependencyMap GetDependencies (const std::string &id) const
 Gets a map of settings (and their dependencies) which depend on the setting with the given identifier. More...
 
SettingDependencyMap GetDependencies (std::shared_ptr< const CSetting > setting) const
 Gets a map of settings (and their dependencies) which depend on the given setting. More...
 
bool GetBool (const std::string &id) const
 Gets the boolean value of the setting with the given identifier. More...
 
int GetInt (const std::string &id) const
 Gets the integer value of the setting with the given identifier. More...
 
double GetNumber (const std::string &id) const
 Gets the real number value of the setting with the given identifier. More...
 
std::string GetString (const std::string &id) const
 Gets the string value of the setting with the given identifier. More...
 
std::vector< std::shared_ptr< CSetting > > GetList (const std::string &id) const
 Gets the values of the list setting with the given identifier. More...
 
bool SetBool (const std::string &id, bool value)
 Sets the boolean value of the setting with the given identifier. More...
 
bool ToggleBool (const std::string &id)
 Toggles the boolean value of the setting with the given identifier. More...
 
bool SetInt (const std::string &id, int value)
 Sets the integer value of the setting with the given identifier. More...
 
bool SetNumber (const std::string &id, double value)
 Sets the real number value of the setting with the given identifier. More...
 
bool SetString (const std::string &id, const std::string &value)
 Sets the string value of the setting with the given identifier. More...
 
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. More...
 
bool FindIntInList (const std::string &id, int value) const
 Search in a list of Ints for a given value. More...
 
bool SetDefault (const std::string &id)
 Sets the value of the setting to its default. More...
 
void SetDefaults ()
 Sets the value of all settings to their default. More...
 
const CSettingConditionsManagerGetConditions () const
 Gets the setting conditions manager used by the settings manager. More...
 
void AddCondition (const std::string &condition)
 Adds the given static condition. More...
 
void AddDynamicCondition (const std::string &identifier, SettingConditionCheck condition, void *data=nullptr)
 Adds the given dynamic condition. More...
 
void RemoveDynamicCondition (const std::string &identifier)
 Removes the given dynamic condition. More...
 
- Public Member Functions inherited from ISettingCreator
virtual ~ISettingCreator ()=default
 
- Public Member Functions inherited from ISettingControlCreator
virtual ~ISettingControlCreator ()=default
 

Static Public Attributes

static const uint32_t Version = 2
 
static const uint32_t MinimumSupportedVersion = 0
 

Detailed Description

Settings manager responsible for initializing, loading and handling all settings.

Constructor & Destructor Documentation

◆ CSettingsManager()

CSettingsManager::CSettingsManager ( )
default

Creates a new (uninitialized) settings manager.

◆ ~CSettingsManager()

CSettingsManager::~CSettingsManager ( )
override

Member Function Documentation

◆ AddCondition()

void CSettingsManager::AddCondition ( const std::string &  condition)

Adds the given static condition.

A static condition is just a string. If a static condition is evaluated, the result depends on whether the condition's value is defined or not.

Parameters
conditionStatic condition string/value

◆ AddDynamicCondition()

void CSettingsManager::AddDynamicCondition ( const std::string &  identifier,
SettingConditionCheck  condition,
void data = nullptr 
)

Adds the given dynamic condition.

A dynamic condition has an identifier and an implementation which is triggered when the condition is evaluated.

Parameters
identifierIdentifier of the dynamic condition
conditionImplementation of the dynamic condition
dataOpaque data pointer, will be passed back to SettingConditionCheck function

◆ AddSection()

void CSettingsManager::AddSection ( std::shared_ptr< CSettingSection section)

Adds the given section, its categories, groups and settings.

This is possible before and after the setting definitions have been initialized.

◆ AddSetting()

bool CSettingsManager::AddSetting ( std::shared_ptr< CSetting setting,
std::shared_ptr< CSettingSection section,
std::shared_ptr< CSettingCategory category,
std::shared_ptr< CSettingGroup group 
)

Adds the given setting to the given group in the given category in the given section;.

If the given section has not been added yet, it is added. If the given category has not been added to the given section yet, it is added. If the given group has not been added to the given category yet, it is added. If the given setting has not been added to the given group yet, it is added.

This is possible before and after the setting definitions have been initialized.

Parameters
settingNew setting to be added
sectionSection the new setting should be added to
categoryCategory the new setting should be added to
groupGroup the new setting should be added to
Returns
True if the setting has been added, false otherwise

◆ Clear()

void CSettingsManager::Clear ( )
overridevirtual

Clears the complete settings manager.

This removes all initialized settings, groups, categories and sections and returns to the uninitialized state. Any registered callbacks or implementations stay registered.

Reimplemented from ISubSettings.

◆ CreateControl()

std::shared_ptr< ISettingControl > CSettingsManager::CreateControl ( const std::string &  controlType) const
overridevirtual

Creates a new setting control of the given custom setting control type.

Parameters
controlTypestring representation of the setting control type
Returns
A new setting control object of the given (custom) setting control type or nullptr if the setting control type is unknown

Implements ISettingControlCreator.

◆ CreateSetting()

SettingPtr CSettingsManager::CreateSetting ( const std::string &  settingType,
const std::string &  settingId,
CSettingsManager settingsManager = nullptr 
) const
overridevirtual

Creates a new setting of the given custom setting type.

Parameters
settingTypestring representation of the setting type
settingIdIdentifier of the setting to be created
settingsManagerReference to the settings manager
Returns
A new setting object of the given (custom) setting type or nullptr if the setting type is unknown

Implements ISettingCreator.

◆ FindIntInList()

bool CSettingsManager::FindIntInList ( const std::string &  id,
int  value 
) const

Search in a list of Ints for a given value.

Parameters
idSetting identifier
valuevalue to search for
Returns
True if value was found in list, false otherwise

◆ GetBool()

bool CSettingsManager::GetBool ( const std::string &  id) const

Gets the boolean value of the setting with the given identifier.

Parameters
idSetting identifier
Returns
Boolean value of the setting with the given identifier

◆ GetConditions()

const CSettingConditionsManager & CSettingsManager::GetConditions ( ) const
inline

Gets the setting conditions manager used by the settings manager.

Returns
Setting conditions manager used by the settings manager.

◆ GetDependencies() [1/2]

SettingDependencyMap CSettingsManager::GetDependencies ( const std::string &  id) const

Gets a map of settings (and their dependencies) which depend on the setting with the given identifier.

It is important to note that the returned dependencies are not the dependencies of the setting with the given identifier but the settings (and their dependencies) which depend on the setting with the given identifier.

Parameters
idSetting identifier
Returns
Map of settings (and their dependencies) which depend on the setting with the given identifier

◆ GetDependencies() [2/2]

SettingDependencyMap CSettingsManager::GetDependencies ( std::shared_ptr< const CSetting setting) const

Gets a map of settings (and their dependencies) which depend on the given setting.

It is important to note that the returned dependencies are not the dependencies of the given setting but the settings (and their dependencies) which depend on the given setting.

Parameters
settingSetting object
Returns
Map of settings (and their dependencies) which depend on the given setting

◆ GetInt()

int CSettingsManager::GetInt ( const std::string &  id) const

Gets the integer value of the setting with the given identifier.

Parameters
idSetting identifier
Returns
Integer value of the setting with the given identifier

◆ GetList()

std::vector< std::shared_ptr< CSetting > > CSettingsManager::GetList ( const std::string &  id) const

Gets the values of the list setting with the given identifier.

Parameters
idSetting identifier
Returns
List of values of the setting with the given identifier

◆ GetNumber()

double CSettingsManager::GetNumber ( const std::string &  id) const

Gets the real number value of the setting with the given identifier.

Parameters
idSetting identifier
Returns
Real number value of the setting with the given identifier

◆ GetSection()

SettingSectionPtr CSettingsManager::GetSection ( std::string  section) const

Gets the setting section with the given identifier.

Parameters
sectionSetting section identifier
Returns
Setting section with the given identifier or nullptr if the identifier is unknown

◆ GetSections()

SettingSectionList CSettingsManager::GetSections ( ) const

Gets the full list of setting sections.

Returns
List of setting sections

◆ GetSetting()

SettingPtr CSettingsManager::GetSetting ( const std::string &  id) const

Gets the setting with the given identifier.

Parameters
idSetting identifier
Returns
Setting object with the given identifier or nullptr if the identifier is unknown

◆ GetSettingOptionsFiller()

void * CSettingsManager::GetSettingOptionsFiller ( std::shared_ptr< const CSetting setting)

Gets the implementation of the setting options filler used by the given setting.

Parameters
settingSetting object
Returns
Implementation of the setting options filler (either IntegerSettingOptionsFiller or StringSettingOptionsFiller)

◆ GetString()

std::string CSettingsManager::GetString ( const std::string &  id) const

Gets the string value of the setting with the given identifier.

Parameters
idSetting identifier
Returns
String value of the setting with the given identifier

◆ Initialize()

bool CSettingsManager::Initialize ( const TiXmlElement *  root)

Initializes the settings manager using the setting definitions represented by the given XML element.

Parameters
rootXML element representing setting definitions
Returns
True if the XML element was successfully deserialized into setting definitions, false otherwise

◆ IsInitialized()

bool CSettingsManager::IsInitialized ( ) const
inline

Returns whether the settings system has been initialized or not.

◆ IsLoaded()

bool CSettingsManager::IsLoaded ( ) const
inline

Returns whether the settings system has been loaded or not.

◆ Load()

bool CSettingsManager::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.

Parameters
rootXML element containing setting values
updatedWhether some settings were automatically updated
triggerEventsWhether to trigger ISettingCallback methods
loadedSettingsA list to fill with all the successfully loaded settings
Returns
True if the setting values were successfully loaded, false otherwise

◆ LoadSetting() [1/2]

bool CSettingsManager::LoadSetting ( const TiXmlNode *  node,
const std::string &  settingId 
)

Loads the setting being represented by the given XML node with the given identifier.

Parameters
nodeXML node representing the setting to load
settingIdSetting identifier
Returns
True if the setting was successfully loaded from the given XML node, false otherwise

◆ LoadSetting() [2/2]

bool CSettingsManager::LoadSetting ( const TiXmlNode *  node,
const std::string &  settingId,
bool &  updated 
)

Loads the setting being represented by the given XML node with the given identifier.

Parameters
nodeXML node representing the setting to load
settingIdSetting identifier
updatedSet to true if the setting's value was updated
Returns
True if the setting was successfully loaded from the given XML node, false otherwise

◆ ParseVersion()

uint32_t CSettingsManager::ParseVersion ( const TiXmlElement *  root) const

Try to get the version of the setting definitions/values represented by the given XML element.

Parameters
rootXML element representing setting definitions/values
Returns
Version of the setting definitions/values or 0 if no version has been specified

◆ RegisterCallback()

void CSettingsManager::RegisterCallback ( ISettingCallback callback,
const std::set< std::string > &  settingList 
)

Registers the given ISettingCallback implementation to be triggered for the given list of settings.

Parameters
settingsHandlerISettingsHandler implementation
settingListList of settings to trigger the given ISettingCallback implementation

◆ RegisterSettingControl()

void CSettingsManager::RegisterSettingControl ( const std::string &  controlType,
ISettingControlCreator settingControlCreator 
)

Registers a custom setting control type and its ISettingControlCreator implementation.

When a setting control definition for a registered custom setting control type is found its ISettingControlCreator implementation is called to create and deserialize the setting control definition.

Parameters
controlTypeString representation of the custom setting control type
settingControlCreatorISettingControlCreator implementation

◆ RegisterSettingOptionsFiller() [1/2]

void CSettingsManager::RegisterSettingOptionsFiller ( const std::string &  identifier,
IntegerSettingOptionsFiller  optionsFiller 
)

Registers the given integer setting options filler under the given identifier.

Parameters
identifierSetting options filler identifier
optionsFillerInteger setting options filler implementation

◆ RegisterSettingOptionsFiller() [2/2]

void CSettingsManager::RegisterSettingOptionsFiller ( const std::string &  identifier,
StringSettingOptionsFiller  optionsFiller 
)

Registers the given string setting options filler under the given identifier.

Parameters
identifierSetting options filler identifier
optionsFillerString setting options filler implementation

◆ RegisterSettingsHandler()

void CSettingsManager::RegisterSettingsHandler ( ISettingsHandler settingsHandler,
bool  bFront = false 
)

Registers the given ISettingsHandler implementation.

Parameters
settingsHandlerISettingsHandler implementation
bFrontIf True, insert the handler in front of other registered handlers, insert at the end otherwise.

◆ RegisterSettingType()

void CSettingsManager::RegisterSettingType ( const std::string &  settingType,
ISettingCreator settingCreator 
)

Registers a custom setting type and its ISettingCreator implementation.

When a setting definition for a registered custom setting type is found its ISettingCreator implementation is called to create and deserialize the setting definition.

Parameters
settingTypeString representation of the custom setting type
settingCreatorISettingCreator implementation

◆ RegisterSubSettings()

void CSettingsManager::RegisterSubSettings ( ISubSettings subSettings)

Registers the given ISubSettings implementation.

Parameters
subSettingsISubSettings implementation

◆ RemoveDynamicCondition()

void CSettingsManager::RemoveDynamicCondition ( const std::string &  identifier)

Removes the given dynamic condition.

Parameters
identifierIdentifier of the dynamic condition

◆ Save()

bool CSettingsManager::Save ( TiXmlNode *  root) const
overridevirtual

Saves the setting values to the given XML node.

Parameters
rootXML node
Returns
True if the setting values were successfully saved, false otherwise

Reimplemented from ISubSettings.

◆ SetBool()

bool CSettingsManager::SetBool ( const std::string &  id,
bool  value 
)

Sets the boolean value of the setting with the given identifier.

Parameters
idSetting identifier
valueBoolean value to set
Returns
True if setting the value was successful, false otherwise

◆ SetDefault()

bool CSettingsManager::SetDefault ( const std::string &  id)

Sets the value of the setting to its default.

Parameters
idSetting identifier
Returns
True if setting the value to its default was successful, false otherwise

◆ SetDefaults()

void CSettingsManager::SetDefaults ( )

Sets the value of all settings to their default.

◆ SetInitialized()

void CSettingsManager::SetInitialized ( )

Tells the settings system that the initialization is complete.

Setting values can only be loaded after a complete and successful initialization of the settings system.

◆ SetInt()

bool CSettingsManager::SetInt ( const std::string &  id,
int  value 
)

Sets the integer value of the setting with the given identifier.

Parameters
idSetting identifier
valueInteger value to set
Returns
True if setting the value was successful, false otherwise

◆ SetList()

bool CSettingsManager::SetList ( const std::string &  id,
const std::vector< std::shared_ptr< CSetting > > &  value 
)

Sets the values of the list setting with the given identifier.

Parameters
idSetting identifier
valueValues to set
Returns
True if setting the values was successful, false otherwise

◆ SetLoaded()

void CSettingsManager::SetLoaded ( )
inline

Tells the settings system that all setting values have been loaded.

This manual trigger is necessary to enable the ISettingCallback methods being executed.

◆ SetNumber()

bool CSettingsManager::SetNumber ( const std::string &  id,
double  value 
)

Sets the real number value of the setting with the given identifier.

Parameters
idSetting identifier
valueReal number value to set
Returns
True if setting the value was successful, false otherwise

◆ SetString()

bool CSettingsManager::SetString ( const std::string &  id,
const std::string &  value 
)

Sets the string value of the setting with the given identifier.

Parameters
idSetting identifier
valueString value to set
Returns
True if setting the value was successful, false otherwise

◆ ToggleBool()

bool CSettingsManager::ToggleBool ( const std::string &  id)

Toggles the boolean value of the setting with the given identifier.

Parameters
idSetting identifier
Returns
True if toggling the boolean value was successful, false otherwise

◆ Unload()

void CSettingsManager::Unload ( )

Unloads the previously loaded setting values.

The values of all the settings are reset to their default values.

◆ UnregisterCallback()

void CSettingsManager::UnregisterCallback ( ISettingCallback callback)

Unregisters the given ISettingCallback implementation.

Parameters
callbackISettingCallback implementation

◆ UnregisterSettingOptionsFiller()

void CSettingsManager::UnregisterSettingOptionsFiller ( const std::string &  identifier)

Unregisters the setting options filler registered under the given identifier.

Parameters
identifierSetting options filler identifier

◆ UnregisterSettingsHandler()

void CSettingsManager::UnregisterSettingsHandler ( ISettingsHandler settingsHandler)

Unregisters the given ISettingsHandler implementation.

Parameters
settingsHandlerISettingsHandler implementation

◆ UnregisterSubSettings()

void CSettingsManager::UnregisterSubSettings ( ISubSettings subSettings)

Unregisters the given ISubSettings implementation.

Parameters
subSettingsISubSettings implementation

Member Data Documentation

◆ MinimumSupportedVersion

const uint32_t CSettingsManager::MinimumSupportedVersion = 0
static

◆ Version

const uint32_t CSettingsManager::Version = 2
static

The documentation for this class was generated from the following files: