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/>.
26 #include <boost/shared_ptr.hpp>
28 #include "settings/lib/ISettingCallback.h"
29 #include "settings/lib/ISettingControlCreator.h"
30 #include "settings/lib/ISettingCreator.h"
31 #include "threads/CriticalSection.h"
32 #include "utils/Variant.h"
36 class CSettingSection;
37 class CSettingsManager;
42 \brief Wrapper around CSettingsManager responsible for properly setting up
43 the settings manager and registering all the callbacks, handlers and custom
47 class CSettings : public ISettingCreator, public ISettingControlCreator
51 \brief Creates a new settings wrapper around a new settings manager.
53 For access to the "global" settings wrapper the static Get() method should
60 \brief Returns a "global" settings wrapper which can be used from anywhere.
62 \return "global" settings wrapper
64 static CSettings& Get();
66 // implementation of ISettingCreator
67 virtual CSetting* CreateSetting(const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager = NULL) const;
69 // implementation of ISettingControlCreator
70 virtual ISettingControl* CreateControl(const std::string &controlType) const;
73 \brief Initializes the setting system with the generic
74 settings definition and platform specific setting definitions.
76 \return True if the initialization was successful, false otherwise
80 \brief Loads the setting values.
82 \return True if the setting values are successfully loaded, false otherwise
86 \brief Loads setting values from the given (XML) file.
88 \param file Path to an XML file containing setting values
89 \return True if the setting values were successfully loaded, false otherwise
91 bool Load(const std::string &file);
93 \brief Loads setting values from the given XML element.
95 \param root XML element containing setting values
96 \param hide Whether to hide the loaded settings or not
97 \return True if the setting values were successfully loaded, false otherwise
99 bool Load(const TiXmlElement *root, bool hide = false);
101 \brief Tells the settings system that all setting values
104 This manual trigger is necessary to enable the ISettingCallback methods
109 \brief Saves the setting values.
111 \return True if the setting values were successfully saved, false otherwise
115 \brief Saves the setting values to the given (XML) file.
117 \param file Path to an XML file
118 \return True if the setting values were successfully saved, false otherwise
120 bool Save(const std::string &file);
122 \brief Unloads the previously loaded setting values.
124 The values of all the settings are reset to their default values.
128 \brief Uninitializes the settings system.
130 Unregisters all previously registered callbacks and destroys all setting
136 \brief Registers the given ISettingCallback implementation for the given
139 \param callback ISettingCallback implementation
140 \param settingList List of setting identifiers for which the given callback shall be triggered
142 void RegisterCallback(ISettingCallback *callback, const std::set<std::string> &settingList);
144 \brief Unregisters the given ISettingCallback implementation.
146 \param callback ISettingCallback implementation
148 void UnregisterCallback(ISettingCallback *callback);
151 \brief Gets the setting with the given identifier.
153 \param id Setting identifier
154 \return Setting object with the given identifier or NULL if the identifier is unknown
156 CSetting* GetSetting(const std::string &id) const;
158 \brief Gets the full list of setting sections.
160 \return List of setting sections
162 std::vector<CSettingSection*> GetSections() const;
164 \brief Gets the setting section with the given identifier.
166 \param section Setting section identifier
167 \return Setting section with the given identifier or NULL if the identifier is unknown
169 CSettingSection* GetSection(const std::string §ion) const;
172 \brief Gets the boolean value of the setting with the given identifier.
174 \param id Setting identifier
175 \return Boolean value of the setting with the given identifier
177 bool GetBool(const std::string &id) const;
179 \brief Gets the integer value of the setting with the given identifier.
181 \param id Setting identifier
182 \return Integer value of the setting with the given identifier
184 int GetInt(const std::string &id) const;
186 \brief Gets the real number value of the setting with the given identifier.
188 \param id Setting identifier
189 \return Real number value of the setting with the given identifier
191 double GetNumber(const std::string &id) const;
193 \brief Gets the string value of the setting with the given identifier.
195 \param id Setting identifier
196 \return String value of the setting with the given identifier
198 std::string GetString(const std::string &id) const;
200 \brief Gets the values of the list setting with the given identifier.
202 \param id Setting identifier
203 \return List of values of the setting with the given identifier
205 std::vector<CVariant> GetList(const std::string &id) const;
208 \brief Sets the boolean value of the setting with the given identifier.
210 \param id Setting identifier
211 \param value Boolean value to set
212 \return True if setting the value was successful, false otherwise
214 bool SetBool(const std::string &id, bool value);
216 \brief Toggles the boolean value of the setting with the given identifier.
218 \param id Setting identifier
219 \return True if toggling the boolean value was successful, false otherwise
221 bool ToggleBool(const std::string &id);
223 \brief Sets the integer value of the setting with the given identifier.
225 \param id Setting identifier
226 \param value Integer value to set
227 \return True if setting the value was successful, false otherwise
229 bool SetInt(const std::string &id, int value);
231 \brief Sets the real number value of the setting with the given identifier.
233 \param id Setting identifier
234 \param value Real number value to set
235 \return True if setting the value was successful, false otherwise
237 bool SetNumber(const std::string &id, double value);
239 \brief Sets the string value of the setting with the given identifier.
241 \param id Setting identifier
242 \param value String value to set
243 \return True if setting the value was successful, false otherwise
245 bool SetString(const std::string &id, const std::string &value);
247 \brief Sets the values of the list setting with the given identifier.
249 \param id Setting identifier
250 \param value Values to set
251 \return True if setting the values was successful, false otherwise
253 bool SetList(const std::string &id, const std::vector<CVariant> &value);
256 \brief Loads the setting being represented by the given XML node with the
259 \param node XML node representing the setting to load
260 \param settingId Setting identifier
261 \return True if the setting was successfully loaded from the given XML node, false otherwise
263 bool LoadSetting(const TiXmlNode *node, const std::string &settingId);
265 static std::vector<CVariant> ListToValues(const CSettingList *setting, const std::vector< boost::shared_ptr<CSetting> > &values);
267 CSettings(const CSettings&);
268 CSettings const& operator=(CSettings const&);
270 bool Initialize(const std::string &file);
271 bool InitializeDefinitions();
272 void InitializeSettingTypes();
273 void InitializeControls();
274 void InitializeVisibility();
275 void InitializeDefaults();
276 void InitializeOptionFillers();
277 void InitializeConditions();
278 void InitializeISettingsHandlers();
279 void InitializeISubSettings();
280 void InitializeISettingCallbacks();
284 CSettingsManager *m_settingsManager;
285 CCriticalSection m_critical;