[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / settings / GUISettings.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://www.xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include <vector>
24 #include <map>
25 #include "guilib/Resolution.h"
26 #include "addons/IAddon.h"
27 #include "utils/Observer.h"
28 #include "utils/GlobalsHandling.h"
29
30 class TiXmlNode;
31 class TiXmlElement;
32
33 // Render Methods
34 #define RENDER_METHOD_AUTO      0
35 #define RENDER_METHOD_ARB       1
36 #define RENDER_METHOD_GLSL      2
37 #define RENDER_METHOD_SOFTWARE  3
38 #define RENDER_METHOD_D3D_PS    4
39 #define RENDER_METHOD_DXVA      5
40 #define RENDER_OVERLAYS         99   // to retain compatibility
41
42 // Scaling options.
43 #define SOFTWARE_UPSCALING_DISABLED   0
44 #define SOFTWARE_UPSCALING_SD_CONTENT 1
45 #define SOFTWARE_UPSCALING_ALWAYS     2
46
47 // Apple Remote options.
48 #define APPLE_REMOTE_DISABLED     0
49 #define APPLE_REMOTE_STANDARD     1
50 #define APPLE_REMOTE_UNIVERSAL    2
51 #define APPLE_REMOTE_MULTIREMOTE  3
52
53 // Subtitle colours
54
55 #define SUBTITLE_COLOR_START  0
56 #define SUBTITLE_COLOR_END    7
57
58 // Karaoke colours
59
60 // If you want to add more colors, it should be done the following way:
61 // 1. Increase KARAOKE_COLOR_END
62 // 2. Add a new color description in language/English/strings.xml in block
63 //    with id 22040 + KARAOKE_COLOR_END value
64 // 3. Add a new color hex mask into gLyricColors structure in karaoke/karaokelyricstext.cpp
65 #define KARAOKE_COLOR_START  0
66 #define KARAOKE_COLOR_END    4
67
68 // CDDA Autoaction defines
69 #define AUTOCD_NONE              0
70 #define AUTOCD_PLAY              1
71 #define AUTOCD_RIP               2
72
73 // CDDA ripper defines
74 #define CDDARIP_ENCODER_LAME     0
75 #define CDDARIP_ENCODER_VORBIS   1
76 #define CDDARIP_ENCODER_WAV      2
77 #define CDDARIP_ENCODER_FLAC     3
78
79 #define CDDARIP_QUALITY_CBR      0
80 #define CDDARIP_QUALITY_MEDIUM   1
81 #define CDDARIP_QUALITY_STANDARD 2
82 #define CDDARIP_QUALITY_EXTREME  3
83
84 #define AUDIO_ANALOG      0
85 #define AUDIO_IEC958      1
86 #define AUDIO_HDMI        2
87 #define AUDIO_IS_BITSTREAM(x) ((x) == AUDIO_IEC958 || (x) == AUDIO_HDMI)
88
89 #define VIDEO_NORMAL 0
90 #define VIDEO_LETTERBOX 1
91 #define VIDEO_WIDESCREEN 2
92
93 #define MODCHIP_SMARTXX   0
94 #define MODCHIP_XENIUM    1
95 #define MODCHIP_XECUTER3  2
96
97 // LED settings
98 #define LED_COLOUR_NO_CHANGE 0
99 #define LED_COLOUR_GREEN   1
100 #define LED_COLOUR_ORANGE   2
101 #define LED_COLOUR_RED    3
102 #define LED_COLOUR_CYCLE   4
103 #define LED_COLOUR_OFF    5
104
105 #define FRAME_RATE_LEAVE_AS_IS  0
106 #define FRAME_RATE_CONVERT      1
107 #define FRAME_RATE_USE_PAL60    2
108
109 #define LED_PLAYBACK_OFF     0
110 #define LED_PLAYBACK_VIDEO    1
111 #define LED_PLAYBACK_MUSIC    2
112 #define LED_PLAYBACK_VIDEO_MUSIC 3
113
114 #define SPIN_DOWN_NONE  0
115 #define SPIN_DOWN_MUSIC  1
116 #define SPIN_DOWN_VIDEO  2
117 #define SPIN_DOWN_BOTH  3
118
119 #define AAM_QUIET 1
120 #define AAM_FAST  0
121
122 #define APM_HIPOWER 0
123 #define APM_LOPOWER 1
124 #define APM_HIPOWER_STANDBY 2
125 #define APM_LOPOWER_STANDBY 3
126
127 #define GUIDE_VIEW_CHANNEL          0
128 #define GUIDE_VIEW_NOW              1
129 #define GUIDE_VIEW_NEXT             2
130 #define GUIDE_VIEW_TIMELINE         3
131
132 #define START_LAST_CHANNEL_OFF      0
133 #define START_LAST_CHANNEL_MIN      1
134 #define START_LAST_CHANNEL_ON       2
135
136 #define SETTINGS_TYPE_BOOL      1
137 #define SETTINGS_TYPE_FLOAT     2
138 #define SETTINGS_TYPE_INT       3
139 #define SETTINGS_TYPE_STRING    4
140 #define SETTINGS_TYPE_HEX       5
141 #define SETTINGS_TYPE_SEPARATOR 6
142 #define SETTINGS_TYPE_PATH      7
143 #define SETTINGS_TYPE_ADDON     8
144
145 #define CHECKMARK_CONTROL                      1
146 #define SPIN_CONTROL_FLOAT                     2
147 #define SPIN_CONTROL_INT                       3
148 #define SPIN_CONTROL_INT_PLUS                  4
149 #define SPIN_CONTROL_TEXT                      5
150 #define EDIT_CONTROL_INPUT                     6
151 #define EDIT_CONTROL_HIDDEN_INPUT              7
152 #define EDIT_CONTROL_NUMBER_INPUT              8
153 #define EDIT_CONTROL_IP_INPUT                  9
154 #define EDIT_CONTROL_MD5_INPUT                10
155 #define BUTTON_CONTROL_STANDARD               11
156 #define BUTTON_CONTROL_MISC_INPUT             12
157 #define BUTTON_CONTROL_PATH_INPUT             13
158 #define SEPARATOR_CONTROL                     14
159 #define EDIT_CONTROL_HIDDEN_NUMBER_VERIFY_NEW 15
160
161 #define REPLAY_GAIN_NONE 0
162 #define REPLAY_GAIN_ALBUM 1
163 #define REPLAY_GAIN_TRACK 2
164
165 //AV sync options
166 #define SYNC_DISCON 0
167 #define SYNC_SKIPDUP 1
168 #define SYNC_RESAMPLE 2
169
170 //adjust refreshrate options
171 #define ADJUST_REFRESHRATE_OFF            0
172 #define ADJUST_REFRESHRATE_ALWAYS         1
173 #define ADJUST_REFRESHRATE_ON_STARTSTOP   2
174
175
176 //resampler quality
177 #define RESAMPLE_LOW 0
178 #define RESAMPLE_MID 1
179 #define RESAMPLE_HIGH 2
180 #define RESAMPLE_REALLYHIGH 3
181
182 //0.1 second increments
183 #define MAXREFRESHCHANGEDELAY 200
184
185 enum PowerState
186 {
187   POWERSTATE_QUIT       = 0,
188   POWERSTATE_SHUTDOWN,
189   POWERSTATE_HIBERNATE,
190   POWERSTATE_SUSPEND,
191   POWERSTATE_REBOOT,
192   POWERSTATE_MINIMIZE,
193   POWERSTATE_NONE,
194   POWERSTATE_ASK
195 };
196
197 enum VideoSelectAction
198 {
199   SELECT_ACTION_CHOOSE = 0,
200   SELECT_ACTION_PLAY_OR_RESUME,
201   SELECT_ACTION_RESUME,
202   SELECT_ACTION_INFO,
203   SELECT_ACTION_MORE,
204   SELECT_ACTION_PLAY,
205   SELECT_ACTION_PLAYPART
206 };
207
208 enum SubtitleAlign
209 {
210   SUBTITLE_ALIGN_MANUAL = 0,
211   SUBTITLE_ALIGN_BOTTOM_INSIDE,
212   SUBTITLE_ALIGN_BOTTOM_OUTSIDE,
213   SUBTITLE_ALIGN_TOP_INSIDE,
214   SUBTITLE_ALIGN_TOP_OUTSIDE
215 };
216
217 // replay gain settings struct for quick access by the player multiple
218 // times per second (saves doing settings lookup)
219 struct ReplayGainSettings
220 {
221   int iPreAmp;
222   int iNoGainPreAmp;
223   int iType;
224   bool bAvoidClipping;
225 };
226
227 // base class for all settings types
228 class CSetting
229 {
230 public:
231   CSetting(int iOrder, const char *strSetting, int iLabel, int iControlType) {
232     m_iOrder = iOrder;
233     m_strSetting = strSetting;
234     m_iLabel = iLabel;
235     m_iControlType = iControlType;
236     m_advanced = false;
237     m_visible = true;
238   };
239   virtual ~CSetting() {};
240   virtual int GetType() const { return 0; };
241   int GetControlType() const { return m_iControlType; };
242   virtual void FromString(const CStdString &strValue) {};
243   virtual CStdString ToString() const { return ""; };
244   const char *GetSetting() const { return m_strSetting.c_str(); };
245   int GetLabel() const { return m_iLabel; };
246   int GetOrder() const { return m_iOrder; };
247   void SetOrder(int iOrder) { m_iOrder = iOrder; };
248   void SetAdvanced() { m_advanced = true; };
249   bool IsAdvanced() const { return m_advanced; };
250   // A setting might be invisible in the current session, yet carried over
251   // in the config file.
252   void SetVisible(bool visible) { m_visible = visible; }
253   bool IsVisible() const { return m_visible; }
254 private:
255   int m_iControlType;
256   int m_iLabel;
257   int m_iOrder;
258   bool m_advanced;
259   bool m_visible;
260   CStdString m_strSetting;
261 };
262
263 class CSettingBool : public CSetting
264 {
265 public:
266   CSettingBool(int iOrder, const char *strSetting, int iLabel, bool bData, int iControlType): CSetting(iOrder, strSetting, iLabel, iControlType) { m_bData = bData; };
267   virtual ~CSettingBool() {};
268
269   virtual int GetType() const { return SETTINGS_TYPE_BOOL; };
270   virtual void FromString(const CStdString &strValue);
271   virtual CStdString ToString() const;
272
273   void SetData(bool bData) { m_bData = bData; };
274   bool GetData() const { return m_bData; };
275
276 private:
277   bool m_bData;
278 };
279
280 class CSettingFloat : public CSetting
281 {
282 public:
283   CSettingFloat(int iOrder, const char *strSetting, int iLabel, float fData, float fMin, float fStep, float fMax, int iControlType);
284   virtual ~CSettingFloat() {};
285
286   virtual int GetType() const { return SETTINGS_TYPE_FLOAT; };
287   virtual void FromString(const CStdString &strValue);
288   virtual CStdString ToString() const;
289
290   void SetData(float fData) { m_fData = fData; if (m_fData < m_fMin) m_fData = m_fMin; if (m_fData > m_fMax) m_fData = m_fMax;};
291   float GetData() const { return m_fData; };
292
293   float m_fMin;
294   float m_fStep;
295   float m_fMax;
296
297 private:
298   float m_fData;
299 };
300
301 class CSettingInt : public CSetting
302 {
303 public:
304   CSettingInt(int iOrder, const char *strSetting, int iLabel, int iData, int iMin, int iStep, int iMax, int iControlType, const char *strFormat);
305   CSettingInt(int iOrder, const char *strSetting, int iLabel, int iData, int iMin, int iStep, int iMax, int iControlType, int iFormat, int iLabelMin);
306   CSettingInt(int iOrder, const char *strSetting, int iLabel, int iData, const std::map<int,int>& entries, int iControlType);
307   virtual ~CSettingInt() {};
308
309   virtual int GetType() const { return SETTINGS_TYPE_INT; };
310   virtual void FromString(const CStdString &strValue);
311   virtual CStdString ToString() const;
312
313   void SetData(int iData)
314   {
315     if (m_entries.empty())
316     {
317       m_iData = iData;
318       if (m_iData < m_iMin) m_iData = m_iMin;
319       if (m_iData > m_iMax) m_iData = m_iMax;
320     }
321     else
322     {
323       //if the setting is an std::map, check if iData is a valid value before assigning it
324       for (std::map<int,int>::iterator it = m_entries.begin(); it != m_entries.end(); it++)
325       {
326         if (it->second == iData)
327         {
328           m_iData = iData;
329           break;
330         }
331       }
332     }
333   }
334   int GetData() const { return m_iData; };
335
336   int m_iMin;
337   int m_iStep;
338   int m_iMax;
339   int m_iFormat;
340   int m_iLabelMin;
341   CStdString m_strFormat;
342   std::map<int,int> m_entries;
343
344 protected:
345   int m_iData;
346 };
347
348 class CSettingHex : public CSettingInt
349 {
350 public:
351   CSettingHex(int iOrder, const char *strSetting, int iLabel, int iData, int iMin, int iStep, int iMax, int iControlType, const char *strFormat)
352       : CSettingInt(iOrder, strSetting, iLabel, iData, iMin, iStep, iMax, iControlType, strFormat) {};
353   virtual ~CSettingHex() {};
354   virtual void FromString(const CStdString &strValue);
355   virtual CStdString ToString() const;
356   virtual int GetType() const { return SETTINGS_TYPE_HEX; };
357 };
358
359 class CSettingString : public CSetting
360 {
361 public:
362   CSettingString(int iOrder, const char *strSetting, int iLabel, const char *strData, int iControlType, bool bAllowEmpty, int iHeadingString);
363   virtual ~CSettingString() {};
364
365   virtual int GetType() const { return SETTINGS_TYPE_STRING; };
366   virtual void FromString(const CStdString &strValue);
367   virtual CStdString ToString() const;
368
369   void SetData(const char *strData) { m_strData = strData; };
370   const CStdString &GetData() const { return m_strData; };
371
372   bool m_bAllowEmpty;
373   int m_iHeadingString;
374 private:
375   CStdString m_strData;
376 };
377
378 class CSettingPath : public CSettingString
379 {
380 public:
381   CSettingPath(int iOrder, const char *strSetting, int iLabel, const char *strData, int iControlType, bool bAllowEmpty, int iHeadingString);
382   virtual ~CSettingPath() {};
383
384   virtual int GetType() const { return SETTINGS_TYPE_PATH; };
385 };
386
387 class CSettingAddon : public CSettingString
388 {
389 public:
390   CSettingAddon(int iOrder, const char *strSetting, int iLabel, const char *strData, const ADDON::TYPE type);
391   virtual ~CSettingAddon() {};
392   virtual int GetType() const { return SETTINGS_TYPE_ADDON; };
393
394   const ADDON::TYPE m_type;
395 };
396
397 class CSettingSeparator : public CSetting
398 {
399 public:
400   CSettingSeparator(int iOrder, const char *strSetting);
401   virtual ~CSettingSeparator() {};
402
403   virtual int GetType() const { return SETTINGS_TYPE_SEPARATOR; };
404 };
405
406 class CSettingsCategory
407 {
408 public:
409   CSettingsCategory(const char *strCategory, int labelID)
410   {
411     m_strCategory = strCategory;
412     m_labelID = labelID;
413   }
414   ~CSettingsCategory() {};
415
416   CStdString m_strCategory;
417   int m_labelID;
418   std::vector<CSetting*> m_settings;
419 };
420
421 typedef std::vector<CSettingsCategory *> vecSettingsCategory;
422
423 class CSettingsGroup
424 {
425 public:
426   CSettingsGroup(int groupID, int labelID)
427   {
428     m_groupID = groupID;
429     m_labelID = labelID;
430   }
431   ~CSettingsGroup()
432   {
433     for (unsigned int i = 0; i < m_vecCategories.size(); i++)
434       delete m_vecCategories[i];
435     m_vecCategories.clear();
436   };
437
438   CSettingsCategory* AddCategory(const char *strCategory, int labelID)
439   {
440     CSettingsCategory *pCategory = new CSettingsCategory(strCategory, labelID);
441     if (pCategory)
442       m_vecCategories.push_back(pCategory);
443     return pCategory;
444   }
445   void GetCategories(vecSettingsCategory &vecCategories);
446   int GetLabelID() { return m_labelID; };
447   int GetGroupID() { return m_groupID; };
448 private:
449   vecSettingsCategory m_vecCategories;
450   int m_groupID;
451   int m_labelID;
452 };
453
454 typedef std::vector<CSetting *> vecSettings;
455
456 class CGUISettings : public Observable
457 {
458 public:
459   CGUISettings();
460   ~CGUISettings();
461
462   void Initialize();
463
464   void AddGroup(int groupID, int labelID);
465   CSettingsCategory* AddCategory(int groupID, const char *strCategory, int labelID);
466   CSettingsGroup *GetGroup(int windowID);
467
468   void AddSetting(CSettingsCategory* cat, CSetting* setting);
469   void AddBool(CSettingsCategory* cat, const char *strSetting, int iLabel, bool bSetting, int iControlType = CHECKMARK_CONTROL);
470   bool GetBool(const char *strSetting) const;
471   void SetBool(const char *strSetting, bool bSetting);
472   void ToggleBool(const char *strSetting);
473
474   void AddFloat(CSettingsCategory* cat, const char *strSetting, int iLabel, float fSetting, float fMin, float fStep, float fMax, int iControlType = SPIN_CONTROL_FLOAT);
475   float GetFloat(const char *strSetting) const;
476   void SetFloat(const char *strSetting, float fSetting);
477
478   void AddInt(CSettingsCategory* cat, const char *strSetting, int iLabel, int fSetting, int iMin, int iStep, int iMax, int iControlType, const char *strFormat = NULL);
479   void AddInt(CSettingsCategory* cat, const char *strSetting, int iLabel, int iData, int iMin, int iStep, int iMax, int iControlType, int iFormat, int iLabelMin=-1);
480   void AddInt(CSettingsCategory* cat, const char *strSetting, int iLabel, int iData, const std::map<int,int>& entries, int iControlType);
481   void AddSpin(unsigned int id, int label, int *current, std::vector<std::pair<int, int> > &values);
482   int GetInt(const char *strSetting) const;
483   void SetInt(const char *strSetting, int fSetting);
484
485   void AddHex(CSettingsCategory* cat, const char *strSetting, int iLabel, int fSetting, int iMin, int iStep, int iMax, int iControlType, const char *strFormat = NULL);
486
487   void AddString(CSettingsCategory* cat, const char *strSetting, int iLabel, const char *strData, int iControlType = EDIT_CONTROL_INPUT, bool bAllowEmpty = false, int iHeadingString = -1);
488   void AddPath(CSettingsCategory* cat, const char *strSetting, int iLabel, const char *strData, int iControlType = EDIT_CONTROL_INPUT, bool bAllowEmpty = false, int iHeadingString = -1);
489
490   void AddDefaultAddon(CSettingsCategory* cat, const char *strSetting, int iLabel, const char *strData, const ADDON::TYPE type);
491
492   const CStdString &GetString(const char *strSetting, bool bPrompt=true) const;
493   void SetString(const char *strSetting, const char *strData);
494
495   void AddSeparator(CSettingsCategory* cat, const char *strSetting);
496
497   CSetting *GetSetting(const char *strSetting);
498
499   void GetSettingsGroup(CSettingsCategory* cat, vecSettings &settings);
500   void LoadXML(TiXmlElement *pRootElement, bool hideSettings = false);
501   void SaveXML(TiXmlNode *pRootNode);
502   void LoadMasterLock(TiXmlElement *pRootElement);
503
504   RESOLUTION GetResolution() const;
505   static RESOLUTION GetResFromString(const CStdString &res);
506   void SetResolution(RESOLUTION res);
507   bool SetLanguage(const CStdString &strLanguage);
508
509   //m_LookAndFeelResolution holds the real gui resolution
510   RESOLUTION m_LookAndFeelResolution;
511   ReplayGainSettings m_replayGain;
512
513   void Clear();
514
515 private:
516   typedef std::map<std::string, CSetting*>::iterator mapIter;
517   typedef std::map<std::string, CSetting*>::const_iterator constMapIter;
518   std::map<std::string, CSetting*> settingsMap;
519   std::vector<CSettingsGroup *> settingsGroups;
520   void LoadFromXML(TiXmlElement *pRootElement, mapIter &it, bool advanced = false);
521 };
522
523 XBMC_GLOBAL_REF(CGUISettings, g_guiSettings);
524 #define g_guiSettings XBMC_GLOBAL_USE(CGUISettings)