Fix keymap.
[vuplus_xbmc] / xbmc / settings / Settings.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #include <set>
23 #include <string>
24 #include <vector>
25
26 #include <boost/shared_ptr.hpp>
27
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"
33
34 class CSetting;
35 class CSettingList;
36 class CSettingSection;
37 class CSettingsManager;
38 class TiXmlElement;
39 class TiXmlNode;
40
41 /*!
42  \brief Wrapper around CSettingsManager responsible for properly setting up
43  the settings manager and registering all the callbacks, handlers and custom
44  setting types.
45  \sa CSettingsManager
46  */
47 class CSettings : public ISettingCreator, public ISettingControlCreator
48 {
49 public:
50   /*!
51    \brief Creates a new settings wrapper around a new settings manager.
52
53    For access to the "global" settings wrapper the static Get() method should
54    be used.
55    */
56   CSettings();
57   virtual ~CSettings();
58
59   /*!
60    \brief Returns a "global" settings wrapper which can be used from anywhere.
61
62    \return "global" settings wrapper
63    */
64   static CSettings& Get();
65
66   // implementation of ISettingCreator
67   virtual CSetting* CreateSetting(const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager = NULL) const;
68
69   // implementation of ISettingControlCreator
70   virtual ISettingControl* CreateControl(const std::string &controlType) const;
71
72   /*!
73    \brief Initializes the setting system with the generic
74    settings definition and platform specific setting definitions.
75
76    \return True if the initialization was successful, false otherwise
77    */
78   bool Initialize();
79   /*!
80    \brief Loads the setting values.
81
82    \return True if the setting values are successfully loaded, false otherwise
83    */
84   bool Load();
85   /*!
86    \brief Loads setting values from the given (XML) file.
87
88    \param file Path to an XML file containing setting values
89    \return True if the setting values were successfully loaded, false otherwise
90    */
91   bool Load(const std::string &file);
92   /*!
93    \brief Loads setting values from the given XML element.
94
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
98    */
99   bool Load(const TiXmlElement *root, bool hide = false);
100   /*!
101    \brief Tells the settings system that all setting values
102    have been loaded.
103
104    This manual trigger is necessary to enable the ISettingCallback methods
105    being executed.
106    */
107   void SetLoaded();
108   /*!
109    \brief Saves the setting values.
110
111    \return True if the setting values were successfully saved, false otherwise
112    */
113   bool Save();
114   /*!
115    \brief Saves the setting values to the given (XML) file.
116
117    \param file Path to an XML file
118    \return True if the setting values were successfully saved, false otherwise
119    */
120   bool Save(const std::string &file);
121   /*!
122    \brief Unloads the previously loaded setting values.
123
124    The values of all the settings are reset to their default values.
125    */
126   void Unload();
127   /*!
128    \brief Uninitializes the settings system.
129
130    Unregisters all previously registered callbacks and destroys all setting
131    objects.
132    */
133   void Uninitialize();
134
135   /*!
136    \brief Registers the given ISettingCallback implementation for the given
137    set of settings.
138
139    \param callback ISettingCallback implementation
140    \param settingList List of setting identifiers for which the given callback shall be triggered
141    */
142   void RegisterCallback(ISettingCallback *callback, const std::set<std::string> &settingList);
143   /*!
144    \brief Unregisters the given ISettingCallback implementation.
145
146    \param callback ISettingCallback implementation
147    */
148   void UnregisterCallback(ISettingCallback *callback);
149
150   /*!
151    \brief Gets the setting with the given identifier.
152
153    \param id Setting identifier
154    \return Setting object with the given identifier or NULL if the identifier is unknown
155    */
156   CSetting* GetSetting(const std::string &id) const;
157   /*!
158    \brief Gets the full list of setting sections.
159
160    \return List of setting sections
161    */
162   std::vector<CSettingSection*> GetSections() const;
163   /*!
164    \brief Gets the setting section with the given identifier.
165
166    \param section Setting section identifier
167    \return Setting section with the given identifier or NULL if the identifier is unknown
168    */
169   CSettingSection* GetSection(const std::string &section) const;
170
171   /*!
172    \brief Gets the boolean value of the setting with the given identifier.
173
174    \param id Setting identifier
175    \return Boolean value of the setting with the given identifier
176    */
177   bool GetBool(const std::string &id) const;
178   /*!
179    \brief Gets the integer value of the setting with the given identifier.
180
181    \param id Setting identifier
182    \return Integer value of the setting with the given identifier
183    */
184   int GetInt(const std::string &id) const;
185   /*!
186    \brief Gets the real number value of the setting with the given identifier.
187
188    \param id Setting identifier
189    \return Real number value of the setting with the given identifier
190    */
191   double GetNumber(const std::string &id) const;
192   /*!
193    \brief Gets the string value of the setting with the given identifier.
194
195    \param id Setting identifier
196    \return String value of the setting with the given identifier
197    */
198   std::string GetString(const std::string &id) const;
199   /*!
200    \brief Gets the values of the list setting with the given identifier.
201
202    \param id Setting identifier
203    \return List of values of the setting with the given identifier
204    */
205   std::vector<CVariant> GetList(const std::string &id) const;
206
207   /*!
208    \brief Sets the boolean value of the setting with the given identifier.
209
210    \param id Setting identifier
211    \param value Boolean value to set
212    \return True if setting the value was successful, false otherwise
213    */
214   bool SetBool(const std::string &id, bool value);
215   /*!
216    \brief Toggles the boolean value of the setting with the given identifier.
217
218    \param id Setting identifier
219    \return True if toggling the boolean value was successful, false otherwise
220    */
221   bool ToggleBool(const std::string &id);
222   /*!
223    \brief Sets the integer value of the setting with the given identifier.
224
225    \param id Setting identifier
226    \param value Integer value to set
227    \return True if setting the value was successful, false otherwise
228    */
229   bool SetInt(const std::string &id, int value);
230   /*!
231    \brief Sets the real number value of the setting with the given identifier.
232
233    \param id Setting identifier
234    \param value Real number value to set
235    \return True if setting the value was successful, false otherwise
236    */
237   bool SetNumber(const std::string &id, double value);
238   /*!
239    \brief Sets the string value of the setting with the given identifier.
240
241    \param id Setting identifier
242    \param value String value to set
243    \return True if setting the value was successful, false otherwise
244    */
245   bool SetString(const std::string &id, const std::string &value);
246   /*!
247    \brief Sets the values of the list setting with the given identifier.
248
249    \param id Setting identifier
250    \param value Values to set
251    \return True if setting the values was successful, false otherwise
252    */
253   bool SetList(const std::string &id, const std::vector<CVariant> &value);
254
255   /*!
256    \brief Loads the setting being represented by the given XML node with the
257    given identifier.
258
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
262    */
263   bool LoadSetting(const TiXmlNode *node, const std::string &settingId);
264
265   static std::vector<CVariant> ListToValues(const CSettingList *setting, const std::vector< boost::shared_ptr<CSetting> > &values);
266 private:
267   CSettings(const CSettings&);
268   CSettings const& operator=(CSettings const&);
269
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();
281   bool Reset();
282
283   bool m_initialized;
284   CSettingsManager *m_settingsManager;
285   CCriticalSection m_critical;
286 };