3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include "settings/ISettingCallback.h"
26 #include "settings/ISettingControlCreator.h"
27 #include "settings/ISettingCreator.h"
28 #include "threads/CriticalSection.h"
29 #include "utils/Variant.h"
32 class CSettingSection;
33 class CSettingsManager;
38 \brief Wrapper around CSettingsManager responsible for properly setting up
39 the settings manager and registering all the callbacks, handlers and custom
43 class CSettings : public ISettingCreator, public ISettingControlCreator
47 \brief Creates a new settings wrapper around a new settings manager.
49 For access to the "global" settings wrapper the static Get() method should
56 \brief Returns a "global" settings wrapper which can be used from anywhere.
58 \return "global" settings wrapper
60 static CSettings& Get();
62 // implementation of ISettingCreator
63 virtual CSetting* CreateSetting(const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager = NULL) const;
65 // implementation of ISettingControlCreator
66 virtual ISettingControl* CreateControl(const std::string &controlType) const;
69 \brief Initializes the setting system with the generic
70 settings definition and platform specific setting definitions.
72 \return True if the initialization was successful, false otherwise
76 \brief Loads the setting values.
78 \return True if the setting values are successfully loaded, false otherwise
82 \brief Loads setting values from the given (XML) file.
84 \param file Path to an XML file containing setting values
85 \return True if the setting values were successfully loaded, false otherwise
87 bool Load(const std::string &file);
89 \brief Loads setting values from the given XML element.
91 \param root XML element containing setting values
92 \param hide Whether to hide the loaded settings or not
93 \return True if the setting values were successfully loaded, false otherwise
95 bool Load(const TiXmlElement *root, bool hide = false);
97 \brief Tells the settings system that all setting values
100 This manual trigger is necessary to enable the ISettingCallback methods
105 \brief Saves the setting values.
107 \return True if the setting values were successfully saved, false otherwise
111 \brief Saves the setting values to the given (XML) file.
113 \param file Path to an XML file
114 \return True if the setting values were successfully saved, false otherwise
116 bool Save(const std::string &file);
118 \brief Unloads the previously loaded setting values.
120 The values of all the settings are reset to their default values.
124 \brief Uninitializes the settings system.
126 Unregisters all previously registered callbacks and destroys all setting
132 \brief Registers the given ISettingCallback implementation for the given
135 \param callback ISettingCallback implementation
136 \param settingList List of setting identifiers for which the given callback shall be triggered
138 void RegisterCallback(ISettingCallback *callback, const std::set<std::string> &settingList);
140 \brief Unregisters the given ISettingCallback implementation.
142 \param callback ISettingCallback implementation
144 void UnregisterCallback(ISettingCallback *callback);
147 \brief Gets the setting with the given identifier.
149 \param id Setting identifier
150 \return Setting object with the given identifier or NULL if the identifier is unknown
152 CSetting* GetSetting(const std::string &id) const;
154 \brief Gets the setting section with the given identifier.
156 \param section Setting section identifier
157 \return Setting section with the given identifier or NULL if the identifier is unknown
159 CSettingSection* GetSection(const std::string §ion) const;
162 \brief Gets the boolean value of the setting with the given identifier.
164 \param id Setting identifier
165 \return Boolean value of the setting with the given identifier
167 bool GetBool(const std::string &id) const;
169 \brief Gets the integer value of the setting with the given identifier.
171 \param id Setting identifier
172 \return Integer value of the setting with the given identifier
174 int GetInt(const std::string &id) const;
176 \brief Gets the real number value of the setting with the given identifier.
178 \param id Setting identifier
179 \return Real number value of the setting with the given identifier
181 double GetNumber(const std::string &id) const;
183 \brief Gets the string value of the setting with the given identifier.
185 \param id Setting identifier
186 \return String value of the setting with the given identifier
188 std::string GetString(const std::string &id) const;
190 \brief Gets the values of the list setting with the given identifier.
192 \param id Setting identifier
193 \return List of values of the setting with the given identifier
195 std::vector<CVariant> GetList(const std::string &id) const;
198 \brief Sets the boolean value of the setting with the given identifier.
200 \param id Setting identifier
201 \param value Boolean value to set
202 \return True if setting the value was successful, false otherwise
204 bool SetBool(const std::string &id, bool value);
206 \brief Toggles the boolean value of the setting with the given identifier.
208 \param id Setting identifier
209 \return True if toggling the boolean value was successful, false otherwise
211 bool ToggleBool(const std::string &id);
213 \brief Sets the integer value of the setting with the given identifier.
215 \param id Setting identifier
216 \param value Integer value to set
217 \return True if setting the value was successful, false otherwise
219 bool SetInt(const std::string &id, int value);
221 \brief Sets the real number value of the setting with the given identifier.
223 \param id Setting identifier
224 \param value Real number value to set
225 \return True if setting the value was successful, false otherwise
227 bool SetNumber(const std::string &id, double value);
229 \brief Sets the string value of the setting with the given identifier.
231 \param id Setting identifier
232 \param value String value to set
233 \return True if setting the value was successful, false otherwise
235 bool SetString(const std::string &id, const std::string &value);
237 \brief Sets the values of the list setting with the given identifier.
239 \param id Setting identifier
240 \param value Values to set
241 \return True if setting the values was successful, false otherwise
243 bool SetList(const std::string &id, const std::vector<CVariant> &value);
246 \brief Loads the setting being represented by the given XML node with the
249 \param node XML node representing the setting to load
250 \param settingId Setting identifier
251 \return True if the setting was successfully loaded from the given XML node, false otherwise
253 bool LoadSetting(const TiXmlNode *node, const std::string &settingId);
256 CSettings(const CSettings&);
257 CSettings const& operator=(CSettings const&);
259 bool Initialize(const std::string &file);
260 bool InitializeDefinitions();
261 void InitializeSettingTypes();
262 void InitializeControls();
263 void InitializeVisibility();
264 void InitializeDefaults();
265 void InitializeOptionFillers();
266 void InitializeConditions();
267 void InitializeISettingsHandlers();
268 void InitializeISubSettings();
269 void InitializeISettingCallbacks();
273 CSettingsManager *m_settingsManager;
274 CCriticalSection m_critical;