[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / profiles / ProfilesManager.h
1 #pragma once
2 /*
3  *      Copyright (C) 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 <vector>
23
24 #include "profiles/Profile.h"
25 #include "settings/lib/ISettingsHandler.h"
26 #include "threads/CriticalSection.h"
27
28 class TiXmlNode;
29
30 class CProfilesManager : public ISettingsHandler
31 {
32 public:
33   static CProfilesManager& Get();
34
35   virtual void OnSettingsLoaded();
36   virtual bool OnSettingsSaved();
37   virtual void OnSettingsCleared();
38
39   bool Load();
40   /*! \brief Load the user profile information from disk
41     Loads the profiles.xml file and creates the list of profiles.
42     If no profiles exist, a master user is created. Should be called
43     after special://masterprofile/ has been defined.
44     \param file XML file to load.
45     */
46   bool Load(const std::string &file);
47
48   bool Save();
49   /*! \brief Save the user profile information to disk
50     Saves the list of profiles to the profiles.xml file.
51     \param file XML file to save.
52     \return true on success, false on failure to save
53     */
54   bool Save(const std::string &file) const;
55
56   void Clear();
57
58   bool LoadProfile(size_t index);
59   bool DeleteProfile(size_t index);
60
61   void CreateProfileFolders();
62
63   /*! \brief Retrieve the master profile
64     \return const reference to the master profile
65     */
66   const CProfile& GetMasterProfile() const;
67
68   /*! \brief Retreive the current profile
69     \return const reference to the current profile
70     */
71   const CProfile& GetCurrentProfile() const;
72
73   /*! \brief Retreive the profile from an index
74     \param unsigned index of the profile to retrieve
75     \return const pointer to the profile, NULL if the index is invalid
76     */
77   const CProfile* GetProfile(size_t index) const;
78
79   /*! \brief Retreive the profile from an index
80     \param unsigned index of the profile to retrieve
81     \return pointer to the profile, NULL if the index is invalid
82     */
83   CProfile* GetProfile(size_t index);
84
85   /*! \brief Retreive index of a particular profile by name
86     \param name name of the profile index to retrieve
87     \return index of this profile, -1 if invalid.
88     */
89   int GetProfileIndex(const std::string &name) const;
90
91   /*! \brief Retrieve the number of profiles
92     \return number of profiles
93     */
94   size_t GetNumberOfProfiles() const { return m_profiles.size(); }
95
96   /*! \brief Add a new profile
97     \param profile CProfile to add
98     */
99   void AddProfile(const CProfile &profile);
100
101   /*! \brief Are we using the login screen?
102     \return true if we're using the login screen, false otherwise
103     */
104   bool UsingLoginScreen() const { return m_usingLoginScreen; }
105
106   /*! \brief Toggle login screen use on and off
107     Toggles the login screen state
108     */
109   void ToggleLoginScreen() { m_usingLoginScreen = !m_usingLoginScreen; }
110
111   /*! \brief Are we the master user?
112     \return true if the current profile is the master user, false otherwise
113     */
114   bool IsMasterProfile() const { return m_currentProfile == 0; }
115
116   /*! \brief Update the date of the current profile
117     */
118   void UpdateCurrentProfileDate();
119
120   /*! \brief Load the master user for the purposes of logging in
121     Loads the master user.  Identical to LoadProfile(0) but doesn't
122     update the last logged in details
123     */
124   void LoadMasterProfileForLogin();
125
126   /*! \brief Retreive the last used profile index
127     \return the last used profile that logged in.  Does not count the
128     master user during login.
129     */
130   uint32_t GetLastUsedProfileIndex() const { return m_lastUsedProfile; }
131
132   /*! \brief Retrieve the current profile index
133     \return the index of the currently logged in profile.
134     */
135   uint32_t GetCurrentProfileIndex() const { return m_currentProfile; }
136
137   /*! \brief Retrieve the next id to use for a new profile
138     \return the unique <id> to be used when creating a new profile
139     */
140   int GetNextProfileId() const { return m_nextProfileId; }
141
142   int GetCurrentProfileId() const { return GetCurrentProfile().getId(); }
143
144   /*! \brief Retrieve the autologin profile id
145     Retrieves the autologin profile id. When set to -1, then the last
146     used profile will be loaded
147     \return the id to the autologin profile
148     */
149   int GetAutoLoginProfileId() const { return m_autoLoginProfile; }
150
151   /*! \brief Retrieve the autologin profile id
152     Retrieves the autologin profile id. When set to -1, then the last
153     used profile will be loaded
154     \return the id to the autologin profile
155     */
156   void SetAutoLoginProfileId(const int profileId) { m_autoLoginProfile = profileId; }
157
158   /*! \brief Retrieve the name of a particular profile by index
159     \param profileId profile index for which to retrieve the name
160     \param name will hold the name of the profile when a valid profile index has been provided
161     \return false if profileId is an invalid index, true if the name parameter is set
162     */
163   bool GetProfileName(const size_t profileId, std::string& name) const;
164
165   std::string GetUserDataFolder() const;
166   std::string GetProfileUserDataFolder() const;
167   std::string GetDatabaseFolder() const;
168   std::string GetCDDBFolder() const;
169   std::string GetThumbnailsFolder() const;
170   std::string GetVideoThumbFolder() const;
171   std::string GetBookmarksThumbFolder() const;
172   std::string GetLibraryFolder() const;
173   std::string GetSettingsFile() const;
174
175   // uses HasSlashAtEnd to determine if a directory or file was meant
176   std::string GetUserDataItem(const std::string& strFile) const;
177
178 protected:
179   CProfilesManager();
180   CProfilesManager(const CProfilesManager&);
181   CProfilesManager const& operator=(CProfilesManager const&);
182   virtual ~CProfilesManager();
183
184 private:
185   /*! \brief Set the current profile id and update the special://profile path
186     \param profileId profile index
187     */
188   void SetCurrentProfileId(size_t profileId);
189
190   std::vector<CProfile> m_profiles;
191   bool m_usingLoginScreen;
192   int m_autoLoginProfile;
193   uint32_t m_lastUsedProfile;
194   uint32_t m_currentProfile; // do not modify directly, use SetCurrentProfileId() function instead
195   int m_nextProfileId; // for tracking the next available id to give to a new profile to ensure id's are not re-used
196   CCriticalSection m_critical;
197 };