3 * Copyright (C) 2013 Team XBMC
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)
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.
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/>.
24 #include "profiles/Profile.h"
25 #include "settings/lib/ISettingsHandler.h"
26 #include "threads/CriticalSection.h"
30 class CProfilesManager : public ISettingsHandler
33 static CProfilesManager& Get();
35 virtual void OnSettingsLoaded();
36 virtual bool OnSettingsSaved();
37 virtual void OnSettingsCleared();
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.
46 bool Load(const std::string &file);
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
54 bool Save(const std::string &file) const;
58 bool LoadProfile(size_t index);
59 bool DeleteProfile(size_t index);
61 void CreateProfileFolders();
63 /*! \brief Retrieve the master profile
64 \return const reference to the master profile
66 const CProfile& GetMasterProfile() const;
68 /*! \brief Retreive the current profile
69 \return const reference to the current profile
71 const CProfile& GetCurrentProfile() const;
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
77 const CProfile* GetProfile(size_t index) const;
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
83 CProfile* GetProfile(size_t index);
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.
89 int GetProfileIndex(const std::string &name) const;
91 /*! \brief Retrieve the number of profiles
92 \return number of profiles
94 size_t GetNumberOfProfiles() const { return m_profiles.size(); }
96 /*! \brief Add a new profile
97 \param profile CProfile to add
99 void AddProfile(const CProfile &profile);
101 /*! \brief Are we using the login screen?
102 \return true if we're using the login screen, false otherwise
104 bool UsingLoginScreen() const { return m_usingLoginScreen; }
106 /*! \brief Toggle login screen use on and off
107 Toggles the login screen state
109 void ToggleLoginScreen() { m_usingLoginScreen = !m_usingLoginScreen; }
111 /*! \brief Are we the master user?
112 \return true if the current profile is the master user, false otherwise
114 bool IsMasterProfile() const { return m_currentProfile == 0; }
116 /*! \brief Update the date of the current profile
118 void UpdateCurrentProfileDate();
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
124 void LoadMasterProfileForLogin();
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.
130 uint32_t GetLastUsedProfileIndex() const { return m_lastUsedProfile; }
132 /*! \brief Retrieve the current profile index
133 \return the index of the currently logged in profile.
135 uint32_t GetCurrentProfileIndex() const { return m_currentProfile; }
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
140 int GetNextProfileId() const { return m_nextProfileId; }
142 int GetCurrentProfileId() const { return GetCurrentProfile().getId(); }
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
149 int GetAutoLoginProfileId() const { return m_autoLoginProfile; }
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
156 void SetAutoLoginProfileId(const int profileId) { m_autoLoginProfile = profileId; }
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
163 bool GetProfileName(const size_t profileId, std::string& name) const;
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;
175 // uses HasSlashAtEnd to determine if a directory or file was meant
176 std::string GetUserDataItem(const std::string& strFile) const;
180 CProfilesManager(const CProfilesManager&);
181 CProfilesManager const& operator=(CProfilesManager const&);
182 virtual ~CProfilesManager();
185 /*! \brief Set the current profile id and update the special://profile path
186 \param profileId profile index
188 void SetCurrentProfileId(size_t profileId);
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;