Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
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

Public Member Functions

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

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 ( const 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 ( const std::shared_ptr< CSetting > & setting,
const std::shared_ptr< CSettingSection > & section,
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;.

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 ( )

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.

◆ 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.

◆ 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::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

◆ GetDependencies() [2/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

◆ 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

◆ GetMinimumSupportedVersion()

uint32_t CSettingsManager::GetMinimumSupportedVersion ( ) const
inline

◆ 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 ( const 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

◆ GetVersion()

uint32_t CSettingsManager::GetVersion ( ) const
inline

◆ HasSettings()

bool CSettingsManager::HasSettings ( ) const

Checks whether any settings have been initialized.

Returns
True if at least one setting has been initialized, false otherwise

◆ 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

◆ RemoveDynamicCondition()

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

Removes the given dynamic condition.

Parameters
identifierIdentifier of the dynamic condition

◆ Save()

bool CSettingsManager::Save ( const ISettingsValueSerializer * serializer,
std::string & serializedValues ) const

Saves the setting values using the given serializer.

Parameters
serializerSettings value serializer to use
Returns
True if the setting values were successfully serialized, false otherwise

◆ 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

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: