Merge pull request #473 from Montellese/onplaybackspeedchanged
[vuplus_xbmc] / xbmc / settings / Settings.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2008 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, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #define PRE_SKIN_VERSION_9_10_COMPATIBILITY 1
24 #define PRE_SKIN_VERSION_11_COMPATIBILITY 1
25
26 #if defined(HAS_SKIN_TOUCHED) && defined(TARGET_DARWIN_IOS) && !defined(TARGET_DARWIN_IOS_ATV2)
27 #define DEFAULT_SKIN          "skin.touched"
28 #else
29 #define DEFAULT_SKIN          "skin.confluence"
30 #endif
31 #define DEFAULT_FANART_HEIGHT 0
32 #define DEFAULT_WEATHER_ADDON "weather.xbmc.builtin"
33 #define DEFAULT_WEB_INTERFACE "webinterface.default"
34 #ifdef MID
35 #define DEFAULT_VSYNC       VSYNC_DISABLED
36 #define DEFAULT_THUMB_SIZE  256
37 #else  // MID
38 #if defined(__APPLE__) || defined(_WIN32)
39 #define DEFAULT_VSYNC       VSYNC_ALWAYS
40 #else
41 #define DEFAULT_VSYNC       VSYNC_DRIVER
42 #endif
43 #define DEFAULT_THUMB_SIZE  512
44 #endif // MID
45
46 #include "settings/VideoSettings.h"
47 #include "Profile.h"
48 #include "ViewState.h"
49 #include "guilib/Resolution.h"
50 #include "guilib/GraphicContext.h"
51
52 #include <vector>
53 #include <map>
54
55 #define CACHE_AUDIO 0
56 #define CACHE_VIDEO 1
57 #define CACHE_VOB   2
58
59 #define VOLUME_MINIMUM -6000  // -60dB
60 #define VOLUME_MAXIMUM 0      // 0dB
61 #define VOLUME_DRC_MINIMUM 0    // 0dB
62 #define VOLUME_DRC_MAXIMUM 3000 // 30dB
63
64 #define VIEW_MODE_NORMAL        0
65 #define VIEW_MODE_ZOOM          1
66 #define VIEW_MODE_STRETCH_4x3   2
67 #define VIEW_MODE_WIDE_ZOOM    3
68 #define VIEW_MODE_STRETCH_16x9  4
69 #define VIEW_MODE_ORIGINAL      5
70 #define VIEW_MODE_CUSTOM        6
71
72 #define VIDEO_SHOW_ALL 0
73 #define VIDEO_SHOW_UNWATCHED 1
74 #define VIDEO_SHOW_WATCHED 2
75
76 /* FIXME: eventually the profile should dictate where special://masterprofile/ is but for now it
77    makes sense to leave all the profile settings in a user writeable location
78    like special://masterprofile/ */
79 #define PROFILES_FILE "special://masterprofile/profiles.xml"
80
81 class CSkinString
82 {
83 public:
84   CStdString name;
85   CStdString value;
86 };
87
88 class CSkinBool
89 {
90 public:
91   CSkinBool() : value(false) {};
92   CStdString name;
93   bool value;
94 };
95
96 class CGUISettings;
97 class TiXmlElement;
98 class TiXmlNode;
99 class CMediaSource;
100
101 class CSettings
102 {
103 public:
104   CSettings(void);
105   virtual ~CSettings(void);
106
107   void Initialize();
108
109   bool Load();
110   void Save() const;
111   bool Reset();
112
113   void Clear();
114
115   bool LoadProfile(unsigned int index);
116   bool DeleteProfile(unsigned int index);
117   void CreateProfileFolders();
118
119   VECSOURCES *GetSourcesFromType(const CStdString &type);
120   CStdString GetDefaultSourceFromType(const CStdString &type);
121
122   bool UpdateSource(const CStdString &strType, const CStdString strOldName, const CStdString &strUpdateChild, const CStdString &strUpdateValue);
123   bool DeleteSource(const CStdString &strType, const CStdString strName, const CStdString strPath, bool virtualSource = false);
124   bool UpdateShare(const CStdString &type, const CStdString oldName, const CMediaSource &share);
125   bool AddShare(const CStdString &type, const CMediaSource &share);
126
127   int TranslateSkinString(const CStdString &setting);
128   const CStdString &GetSkinString(int setting) const;
129   void SetSkinString(int setting, const CStdString &label);
130
131   int TranslateSkinBool(const CStdString &setting);
132   bool GetSkinBool(int setting) const;
133   void SetSkinBool(int setting, bool set);
134
135   /*! \brief Retreive the watched mode for the given content type
136    \param content Current content type
137    \return the current watch mode for this content type, WATCH_MODE_ALL if the content type is unknown.
138    \sa SetWatchMode, IncrementWatchMode
139    */
140   int GetWatchMode(const CStdString& content) const;
141
142   /*! \brief Set the watched mode for the given content type
143    \param content Current content type
144    \param value Watched mode to set
145    \sa GetWatchMode, IncrementWatchMode
146    */
147   void SetWatchMode(const CStdString& content, int value);
148
149   /*! \brief Cycle the watched mode for the given content type
150    \param content Current content type
151    \sa GetWatchMode, SetWatchMode
152    */
153   void CycleWatchMode(const CStdString& content);
154
155   void ResetSkinSetting(const CStdString &setting);
156   void ResetSkinSettings();
157
158   CStdString m_pictureExtensions;
159   CStdString m_musicExtensions;
160   CStdString m_videoExtensions;
161   CStdString m_discStubExtensions;
162
163   CStdString m_logFolder;
164
165   CStdString m_activeKeyboardMapping;
166
167   bool m_bMyMusicSongInfoInVis;
168   bool m_bMyMusicSongThumbInVis;
169
170   CViewState m_viewStateMusicNavArtists;
171   CViewState m_viewStateMusicNavAlbums;
172   CViewState m_viewStateMusicNavSongs;
173   CViewState m_viewStateMusicLastFM;
174   CViewState m_viewStateVideoNavActors;
175   CViewState m_viewStateVideoNavYears;
176   CViewState m_viewStateVideoNavGenres;
177   CViewState m_viewStateVideoNavTitles;
178   CViewState m_viewStateVideoNavEpisodes;
179   CViewState m_viewStateVideoNavSeasons;
180   CViewState m_viewStateVideoNavTvShows;
181   CViewState m_viewStateVideoNavMusicVideos;
182
183   CViewState m_viewStatePrograms;
184   CViewState m_viewStatePictures;
185   CViewState m_viewStateMusicFiles;
186   CViewState m_viewStateVideoFiles;
187
188   bool m_bMyMusicPlaylistRepeat;
189   bool m_bMyMusicPlaylistShuffle;
190   int m_iMyMusicStartWindow;
191
192   // for scanning
193   bool m_bMyMusicIsScanning;
194
195   CVideoSettings m_defaultVideoSettings;
196   CVideoSettings m_currentVideoSettings;
197
198   float m_fZoomAmount;      // current zoom amount
199   float m_fPixelRatio;      // current pixel ratio
200   float m_fVerticalShift;   // current vertical shift
201   bool  m_bNonLinStretch;   // current non-linear stretch
202
203   bool m_bMyVideoPlaylistRepeat;
204   bool m_bMyVideoPlaylistShuffle;
205   bool m_bMyVideoNavFlatten;
206   bool m_bStartVideoWindowed;
207   bool m_bAddonAutoUpdate;
208   bool m_bAddonNotifications;
209
210   int m_iVideoStartWindow;
211
212   bool m_videoStacking;
213
214   int iAdditionalSubtitleDirectoryChecked;
215
216   int m_HttpApiBroadcastPort;
217   int m_HttpApiBroadcastLevel;
218   int m_nVolumeLevel;                     // measured in milliBels -60dB -> 0dB range.
219   int m_dynamicRangeCompressionLevel;     // measured in milliBels  0dB -> 30dB range.
220   int m_iPreMuteVolumeLevel;    // save the m_nVolumeLevel for proper restore
221   bool m_bMute;
222   int m_iSystemTimeTotalUp;    // Uptime in minutes!
223
224   CStdString m_userAgent;
225
226   struct RssSet
227   {
228     bool rtl;
229     std::vector<int> interval;
230     std::vector<std::string> url;
231   };
232
233   std::map<int,RssSet> m_mapRssUrls;
234   std::map<int, CSkinString> m_skinStrings;
235   std::map<int, CSkinBool> m_skinBools;
236
237   VECSOURCES m_programSources;
238   VECSOURCES m_pictureSources;
239   VECSOURCES m_fileSources;
240   VECSOURCES m_musicSources;
241   VECSOURCES m_videoSources;
242
243   CStdString m_defaultProgramSource;
244   CStdString m_defaultMusicSource;
245   CStdString m_defaultPictureSource;
246   CStdString m_defaultFileSource;
247   CStdString m_defaultMusicLibSource;
248
249   CStdString m_UPnPUUIDServer;
250   int        m_UPnPPortServer;
251   int        m_UPnPMaxReturnedItems;
252   CStdString m_UPnPUUIDRenderer;
253   int        m_UPnPPortRenderer;
254
255   /*! \brief Retrieve the master profile
256    \return const reference to the master profile
257    */
258   const CProfile &GetMasterProfile() const;
259
260   /*! \brief Retreive the current profile
261    \return const reference to the current profile
262    */
263   const CProfile &GetCurrentProfile() const;
264
265   /*! \brief Retreive the profile from an index
266    \param unsigned index of the profile to retrieve
267    \return const pointer to the profile, NULL if the index is invalid
268    */
269   const CProfile *GetProfile(unsigned int index) const;
270
271   /*! \brief Retreive the profile from an index
272    \param unsigned index of the profile to retrieve
273    \return pointer to the profile, NULL if the index is invalid
274    */
275   CProfile *GetProfile(unsigned int index);
276
277   /*! \brief Retreive index of a particular profile by name
278    \param name name of the profile index to retrieve
279    \return index of this profile, -1 if invalid.
280    */
281   int GetProfileIndex(const CStdString &name) const;
282
283   /*! \brief Retrieve the number of profiles
284    \return number of profiles
285    */
286   unsigned int GetNumProfiles() const;
287
288   /*! \brief Add a new profile
289    \param profile CProfile to add
290    */
291   void AddProfile(const CProfile &profile);
292
293   /*! \brief Are we using the login screen?
294    \return true if we're using the login screen, false otherwise
295    */
296   bool UsingLoginScreen() const { return m_usingLoginScreen; };
297
298   /*! \brief Toggle login screen use on and off
299    Toggles the login screen state
300    */
301   void ToggleLoginScreen() { m_usingLoginScreen = !m_usingLoginScreen; };
302
303   /*! \brief Are we the master user?
304    \return true if the current profile is the master user, false otherwise
305    */
306   bool IsMasterUser() const { return 0 == m_currentProfile; };
307
308   /*! \brief Update the date of the current profile
309    */
310   void UpdateCurrentProfileDate();
311
312   /*! \brief Load the master user for the purposes of logging in
313    Loads the master user.  Identical to LoadProfile(0) but doesn't update the last logged in details
314    */
315   void LoadMasterForLogin();
316
317   /*! \brief Retreive the last used profile index
318    \return the last used profile that logged in.  Does not count the master user during login.
319    */
320   unsigned int GetLastUsedProfileIndex() const { return m_lastUsedProfile; };
321
322   /*! \brief Retrieve the current profile index
323    \return the index of the currently logged in profile.
324    */
325   unsigned int GetCurrentProfileIndex() const { return m_currentProfile; };
326
327   /*! \brief Retrieve the next id to use for a new profile
328    \return the unique <id> to be used when creating a new profile
329    */
330   int GetNextProfileId() const { return m_nextIdProfile; }; // used to get the value of m_nextIdProfile for use in new profile creation
331
332   int GetCurrentProfileId() const;
333
334   std::vector<RESOLUTION_INFO> m_ResInfo;
335
336   // utility functions for user data folders
337
338   //uses HasSlashAtEnd to determine if a directory or file was meant
339   CStdString GetUserDataItem(const CStdString& strFile) const;
340   CStdString GetProfileUserDataFolder() const;
341   CStdString GetUserDataFolder() const;
342   CStdString GetDatabaseFolder() const;
343   CStdString GetCDDBFolder() const;
344   CStdString GetThumbnailsFolder() const;
345   CStdString GetMusicThumbFolder() const;
346   CStdString GetLastFMThumbFolder() const;
347   CStdString GetMusicArtistThumbFolder() const;
348   CStdString GetVideoThumbFolder() const;
349   CStdString GetBookmarksThumbFolder() const;
350   CStdString GetSourcesFile() const;
351   CStdString GetVideoFanartFolder() const;
352   CStdString GetMusicFanartFolder() const;
353
354   CStdString GetSettingsFile() const;
355
356   bool LoadUPnPXml(const CStdString& strSettingsFile);
357   bool SaveUPnPXml(const CStdString& strSettingsFile) const;
358
359   /*! \brief Load the user profile information from disk
360    Loads the profiles.xml file and creates the list of profiles. If no profiles
361    exist, a master user is created.  Should be called after special://masterprofile/
362    has been defined.
363    \param profilesFile XML file to load.
364    */
365   void LoadProfiles(const CStdString& profilesFile);
366
367   /*! \brief Save the user profile information to disk
368    Saves the list of profiles to the profiles.xml file.
369    \param profilesFile XML file to save.
370    \return true on success, false on failure to save
371    */
372   bool SaveProfiles(const CStdString& profilesFile) const;
373
374   bool SaveSettings(const CStdString& strSettingsFile, CGUISettings *localSettings = NULL) const;
375
376   void LoadSources();
377   bool SaveSources();
378
379   void LoadRSSFeeds();
380   bool GetInteger(const TiXmlElement* pRootElement, const char *strTagName, int& iValue, const int iDefault, const int iMin, const int iMax);
381   bool GetFloat(const TiXmlElement* pRootElement, const char *strTagName, float& fValue, const float fDefault, const float fMin, const float fMax);
382   static bool GetPath(const TiXmlElement* pRootElement, const char *tagName, CStdString &strValue);
383   static bool GetString(const TiXmlElement* pRootElement, const char *strTagName, CStdString& strValue, const CStdString& strDefaultValue);
384   bool GetString(const TiXmlElement* pRootElement, const char *strTagName, char *szValue, const CStdString& strDefaultValue);
385   bool GetSource(const CStdString &category, const TiXmlNode *source, CMediaSource &share);
386 protected:
387   void GetSources(const TiXmlElement* pRootElement, const CStdString& strTagName, VECSOURCES& items, CStdString& strDefault);
388   bool SetSources(TiXmlNode *root, const char *section, const VECSOURCES &shares, const char *defaultPath);
389   void GetViewState(const TiXmlElement* pRootElement, const CStdString& strTagName, CViewState &viewState, SORT_METHOD defaultSort = SORT_METHOD_LABEL, int defaultView = DEFAULT_VIEW_LIST);
390
391   // functions for writing xml files
392   void SetViewState(TiXmlNode* pRootNode, const CStdString& strTagName, const CViewState &viewState) const;
393
394   bool LoadCalibration(const TiXmlElement* pElement, const CStdString& strSettingsFile);
395   bool SaveCalibration(TiXmlNode* pRootNode) const;
396
397   bool LoadSettings(const CStdString& strSettingsFile);
398 //  bool SaveSettings(const CStdString& strSettingsFile) const;
399
400   bool LoadPlayerCoreFactorySettings(const CStdString& fileStr, bool clear);
401
402   // skin activated settings
403   void LoadSkinSettings(const TiXmlElement* pElement);
404   void SaveSkinSettings(TiXmlNode *pElement) const;
405
406   void LoadUserFolderLayout();
407
408 private:
409   std::vector<CProfile> m_vecProfiles;
410   std::map<CStdString, int> m_watchMode;
411   bool m_usingLoginScreen;
412   unsigned int m_lastUsedProfile;
413   unsigned int m_currentProfile;
414   int m_nextIdProfile; // for tracking the next available id to give to a new profile to ensure id's are not re-used
415 };
416
417 extern class CSettings g_settings;