Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 402 lines (324 sloc) 13.684 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
#pragma once
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#define PRE_SKIN_VERSION_9_10_COMPATIBILITY 1
#define PRE_SKIN_VERSION_11_COMPATIBILITY 1

//FIXME - after eden - make that one nicer somehow...
#if defined(TARGET_DARWIN_IOS) && !defined(TARGET_DARWIN_IOS_ATV2)
#include "system.h" //for HAS_SKIN_TOUCHED
#endif

#if defined(HAS_SKIN_TOUCHED) && defined(TARGET_DARWIN_IOS) && !defined(TARGET_DARWIN_IOS_ATV2)
#define DEFAULT_SKIN "skin.touched"
#else
#define DEFAULT_SKIN "skin.confluence"
#endif
#define DEFAULT_WEB_INTERFACE "webinterface.default"
#ifdef MID
#define DEFAULT_VSYNC VSYNC_DISABLED
#else // MID
#if defined(TARGET_DARWIN) || defined(_WIN32) || defined(TARGET_RASPBERRY_PI)
#define DEFAULT_VSYNC VSYNC_ALWAYS
#else
#define DEFAULT_VSYNC VSYNC_DRIVER
#endif
#endif // MID

#include "settings/VideoSettings.h"
#include "Profile.h"
#include "view/ViewState.h"
#include "guilib/Resolution.h"
#include "guilib/GraphicContext.h"

#include <vector>
#include <map>

#define CACHE_AUDIO 0
#define CACHE_VIDEO 1
#define CACHE_VOB 2

#define VOLUME_MINIMUM 0.0f // -60dB
#define VOLUME_MAXIMUM 1.0f // 0dB
#define VOLUME_DYNAMIC_RANGE 90.0f // 60dB
#define VOLUME_CONTROL_STEPS 90 // 90 steps
#define VOLUME_DRC_MINIMUM 0 // 0dB
#define VOLUME_DRC_MAXIMUM 6000 // 60dB

#define VIEW_MODE_NORMAL 0
#define VIEW_MODE_ZOOM 1
#define VIEW_MODE_STRETCH_4x3 2
#define VIEW_MODE_WIDE_ZOOM 3
#define VIEW_MODE_STRETCH_16x9 4
#define VIEW_MODE_ORIGINAL 5
#define VIEW_MODE_CUSTOM 6

#define VIDEO_SHOW_ALL 0
#define VIDEO_SHOW_UNWATCHED 1
#define VIDEO_SHOW_WATCHED 2

/* FIXME: eventually the profile should dictate where special://masterprofile/ is but for now it
makes sense to leave all the profile settings in a user writeable location
like special://masterprofile/ */
#define PROFILES_FILE "special://masterprofile/profiles.xml"

class CSkinString
{
public:
  CStdString name;
  CStdString value;
};

class CSkinBool
{
public:
  CSkinBool() : value(false) {};
  CStdString name;
  bool value;
};

class CGUISettings;
class TiXmlElement;
class TiXmlNode;
class CMediaSource;

class CSettings
{
public:
  CSettings(void);
  virtual ~CSettings(void);

  void Initialize();

  bool Load();
  void Save() const;
  bool Reset();

  void Clear();

  bool LoadProfile(unsigned int index);
  bool DeleteProfile(unsigned int index);
  void CreateProfileFolders();

  VECSOURCES *GetSourcesFromType(const CStdString &type);
  CStdString GetDefaultSourceFromType(const CStdString &type);

  bool UpdateSource(const CStdString &strType, const CStdString strOldName, const CStdString &strUpdateChild, const CStdString &strUpdateValue);
  bool DeleteSource(const CStdString &strType, const CStdString strName, const CStdString strPath, bool virtualSource = false);
  bool UpdateShare(const CStdString &type, const CStdString oldName, const CMediaSource &share);
  bool AddShare(const CStdString &type, const CMediaSource &share);

  int TranslateSkinString(const CStdString &setting);
  const CStdString &GetSkinString(int setting) const;
  void SetSkinString(int setting, const CStdString &label);

  int TranslateSkinBool(const CStdString &setting);
  bool GetSkinBool(int setting) const;
  void SetSkinBool(int setting, bool set);

  /*! \brief Retreive the watched mode for the given content type
\param content Current content type
\return the current watch mode for this content type, WATCH_MODE_ALL if the content type is unknown.
\sa SetWatchMode, IncrementWatchMode
*/
  int GetWatchMode(const CStdString& content) const;

  /*! \brief Set the watched mode for the given content type
\param content Current content type
\param value Watched mode to set
\sa GetWatchMode, IncrementWatchMode
*/
  void SetWatchMode(const CStdString& content, int value);

  /*! \brief Cycle the watched mode for the given content type
\param content Current content type
\sa GetWatchMode, SetWatchMode
*/
  void CycleWatchMode(const CStdString& content);

  void ResetSkinSetting(const CStdString &setting);
  void ResetSkinSettings();

  CStdString m_pictureExtensions;
  CStdString m_musicExtensions;
  CStdString m_videoExtensions;
  CStdString m_discStubExtensions;

  CStdString m_logFolder;

  bool m_bMyMusicSongInfoInVis;
  bool m_bMyMusicSongThumbInVis;

  CViewState m_viewStateMusicNavArtists;
  CViewState m_viewStateMusicNavAlbums;
  CViewState m_viewStateMusicNavSongs;
  CViewState m_viewStateVideoNavActors;
  CViewState m_viewStateVideoNavYears;
  CViewState m_viewStateVideoNavGenres;
  CViewState m_viewStateVideoNavTitles;
  CViewState m_viewStateVideoNavEpisodes;
  CViewState m_viewStateVideoNavSeasons;
  CViewState m_viewStateVideoNavTvShows;
  CViewState m_viewStateVideoNavMusicVideos;

  CViewState m_viewStatePrograms;
  CViewState m_viewStatePictures;
  CViewState m_viewStateMusicFiles;
  CViewState m_viewStateVideoFiles;

  bool m_bMyMusicPlaylistRepeat;
  bool m_bMyMusicPlaylistShuffle;
  int m_iMyMusicStartWindow;

  CVideoSettings m_defaultVideoSettings;
  CVideoSettings m_currentVideoSettings;

  float m_fZoomAmount; // current zoom amount
  float m_fPixelRatio; // current pixel ratio
  float m_fVerticalShift; // current vertical shift
  bool m_bNonLinStretch; // current non-linear stretch

  bool m_bMyVideoPlaylistRepeat;
  bool m_bMyVideoPlaylistShuffle;
  bool m_bMyVideoNavFlatten;
  bool m_bStartVideoWindowed;
  bool m_bAddonAutoUpdate;
  bool m_bAddonNotifications;
  bool m_bAddonForeignFilter;

  int m_iVideoStartWindow;

  bool m_videoStacking;

  int iAdditionalSubtitleDirectoryChecked;

  float m_fVolumeLevel; // float 0.0 - 1.0 range
  bool m_bMute;
  int m_iSystemTimeTotalUp; // Uptime in minutes!

  CStdString m_userAgent;

  struct RssSet
  {
    bool rtl;
    std::vector<int> interval;
    std::vector<std::string> url;
  };

  std::map<int,RssSet> m_mapRssUrls;
  std::map<int, CSkinString> m_skinStrings;
  std::map<int, CSkinBool> m_skinBools;

  VECSOURCES m_programSources;
  VECSOURCES m_pictureSources;
  VECSOURCES m_fileSources;
  VECSOURCES m_musicSources;
  VECSOURCES m_videoSources;

  CStdString m_defaultProgramSource;
  CStdString m_defaultMusicSource;
  CStdString m_defaultPictureSource;
  CStdString m_defaultFileSource;
  CStdString m_defaultMusicLibSource;

  int m_musicNeedsUpdate; ///< if a database update means an update is required (set to the version number of the db)
  int m_videoNeedsUpdate; ///< if a database update means an update is required (set to the version number of the db)

  /*! \brief Retrieve the master profile
\return const reference to the master profile
*/
  const CProfile &GetMasterProfile() const;

  /*! \brief Retreive the current profile
\return const reference to the current profile
*/
  const CProfile &GetCurrentProfile() const;

  /*! \brief Retreive the profile from an index
\param unsigned index of the profile to retrieve
\return const pointer to the profile, NULL if the index is invalid
*/
  const CProfile *GetProfile(unsigned int index) const;

  /*! \brief Retreive the profile from an index
\param unsigned index of the profile to retrieve
\return pointer to the profile, NULL if the index is invalid
*/
  CProfile *GetProfile(unsigned int index);

  /*! \brief Retreive index of a particular profile by name
\param name name of the profile index to retrieve
\return index of this profile, -1 if invalid.
*/
  int GetProfileIndex(const CStdString &name) const;

  /*! \brief Retrieve the number of profiles
\return number of profiles
*/
  unsigned int GetNumProfiles() const;

  /*! \brief Add a new profile
\param profile CProfile to add
*/
  void AddProfile(const CProfile &profile);

  /*! \brief Are we using the login screen?
\return true if we're using the login screen, false otherwise
*/
  bool UsingLoginScreen() const { return m_usingLoginScreen; };

  /*! \brief Toggle login screen use on and off
Toggles the login screen state
*/
  void ToggleLoginScreen() { m_usingLoginScreen = !m_usingLoginScreen; };

  /*! \brief Are we the master user?
\return true if the current profile is the master user, false otherwise
*/
  bool IsMasterUser() const { return 0 == m_currentProfile; };

  /*! \brief Update the date of the current profile
*/
  void UpdateCurrentProfileDate();

  /*! \brief Load the master user for the purposes of logging in
Loads the master user. Identical to LoadProfile(0) but doesn't update the last logged in details
*/
  void LoadMasterForLogin();

  /*! \brief Retreive the last used profile index
\return the last used profile that logged in. Does not count the master user during login.
*/
  unsigned int GetLastUsedProfileIndex() const { return m_lastUsedProfile; };

  /*! \brief Retrieve the current profile index
\return the index of the currently logged in profile.
*/
  unsigned int GetCurrentProfileIndex() const { return m_currentProfile; };

  /*! \brief Retrieve the next id to use for a new profile
\return the unique <id> to be used when creating a new profile
*/
  int GetNextProfileId() const { return m_nextIdProfile; }; // used to get the value of m_nextIdProfile for use in new profile creation

  int GetCurrentProfileId() const;

  std::vector<RESOLUTION_INFO> m_ResInfo;
  std::vector<RESOLUTION_INFO> m_Calibrations;

  // utility functions for user data folders

  //uses HasSlashAtEnd to determine if a directory or file was meant
  CStdString GetUserDataItem(const CStdString& strFile) const;
  CStdString GetProfileUserDataFolder() const;
  CStdString GetUserDataFolder() const;
  CStdString GetDatabaseFolder() const;
  CStdString GetCDDBFolder() const;
  CStdString GetThumbnailsFolder() const;
  CStdString GetVideoThumbFolder() const;
  CStdString GetBookmarksThumbFolder() const;
  CStdString GetLibraryFolder() const;
  CStdString GetSourcesFile() const;

  CStdString GetSettingsFile() const;

  /*! \brief Load the user profile information from disk
Loads the profiles.xml file and creates the list of profiles. If no profiles
exist, a master user is created. Should be called after special://masterprofile/
has been defined.
\param profilesFile XML file to load.
*/
  void LoadProfiles(const CStdString& profilesFile);

  /*! \brief Save the user profile information to disk
Saves the list of profiles to the profiles.xml file.
\param profilesFile XML file to save.
\return true on success, false on failure to save
*/
  bool SaveProfiles(const CStdString& profilesFile) const;

  bool SaveSettings(const CStdString& strSettingsFile, CGUISettings *localSettings = NULL) const;

  void LoadSources();
  bool SaveSources();

  void LoadRSSFeeds();
  bool GetInteger(const TiXmlElement* pRootElement, const char *strTagName, int& iValue, const int iDefault, const int iMin, const int iMax);
  bool GetFloat(const TiXmlElement* pRootElement, const char *strTagName, float& fValue, const float fDefault, const float fMin, const float fMax);
  static bool GetPath(const TiXmlElement* pRootElement, const char *tagName, CStdString &strValue);
  static bool GetString(const TiXmlElement* pRootElement, const char *strTagName, CStdString& strValue, const CStdString& strDefaultValue);
  bool GetString(const TiXmlElement* pRootElement, const char *strTagName, char *szValue, const CStdString& strDefaultValue);
  bool GetSource(const CStdString &category, const TiXmlNode *source, CMediaSource &share);

  void ApplyCalibrations();
  void UpdateCalibrations();
protected:
  void GetSources(const TiXmlElement* pRootElement, const CStdString& strTagName, VECSOURCES& items, CStdString& strDefault);
  bool SetSources(TiXmlNode *root, const char *section, const VECSOURCES &shares, const char *defaultPath);
  void GetViewState(const TiXmlElement* pRootElement, const CStdString& strTagName, CViewState &viewState, SORT_METHOD defaultSort = SORT_METHOD_LABEL, int defaultView = DEFAULT_VIEW_LIST);

  // functions for writing xml files
  void SetViewState(TiXmlNode* pRootNode, const CStdString& strTagName, const CViewState &viewState) const;

  bool LoadCalibration(const TiXmlElement* pElement, const CStdString& strSettingsFile);
  bool SaveCalibration(TiXmlNode* pRootNode) const;

  bool LoadSettings(const CStdString& strSettingsFile);
// bool SaveSettings(const CStdString& strSettingsFile) const;

  // skin activated settings
  void LoadSkinSettings(const TiXmlElement* pElement);
  void SaveSkinSettings(TiXmlNode *pElement) const;

  void LoadUserFolderLayout();

private:
  std::vector<CProfile> m_vecProfiles;
  std::map<CStdString, int> m_watchMode;
  bool m_usingLoginScreen;
  unsigned int m_lastUsedProfile;
  unsigned int m_currentProfile;
  int m_nextIdProfile; // for tracking the next available id to give to a new profile to ensure id's are not re-used
};

extern class CSettings g_settings;
Something went wrong with that request. Please try again.