2 * Copyright (C) 2013-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "profiles/Profile.h"
12 #include "settings/lib/ISettingCallback.h"
13 #include "settings/lib/ISettingsHandler.h"
14 #include "threads/CriticalSection.h"
21 class CEventLogManager
;
25 class CProfileManager
: protected ISettingsHandler
,
26 protected ISettingCallback
30 CProfileManager(const CProfileManager
&) = delete;
31 CProfileManager
& operator=(CProfileManager
const&) = delete;
32 ~CProfileManager() override
;
34 void Initialize(const std::shared_ptr
<CSettings
>& settings
);
37 void OnSettingsLoaded() override
;
38 void OnSettingsSaved() const override
;
39 void OnSettingsCleared() override
;
42 /*! \brief Load the user profile information from disk
43 Loads the profiles.xml file and creates the list of profiles.
44 If no profiles exist, a master user is created. Should be called
45 after special://masterprofile/ has been defined.
46 \param file XML file to load.
50 /*! \brief Save the user profile information to disk
51 Saves the list of profiles to the profiles.xml file.
52 \param file XML file to save.
53 \return true on success, false on failure to save
58 bool LoadProfile(unsigned int index
);
61 bool DeleteProfile(unsigned int index
);
63 void CreateProfileFolders();
65 /*! \brief Retrieve the master profile
66 \return const reference to the master profile
68 const CProfile
& GetMasterProfile() const;
70 /*! \brief Retrieve the current profile
71 \return const reference to the current profile
73 const CProfile
& GetCurrentProfile() const;
75 /*! \brief Retrieve the profile from an index
76 \param unsigned index of the profile to retrieve
77 \return const pointer to the profile, NULL if the index is invalid
79 const CProfile
* GetProfile(unsigned int index
) const;
81 /*! \brief Retrieve the profile from an index
82 \param unsigned index of the profile to retrieve
83 \return pointer to the profile, NULL if the index is invalid
85 CProfile
* GetProfile(unsigned int index
);
87 /*! \brief Retrieve index of a particular profile by name
88 \param name name of the profile index to retrieve
89 \return index of this profile, -1 if invalid.
91 int GetProfileIndex(const std::string
&name
) const;
93 /*! \brief Retrieve the number of profiles
94 \return number of profiles
96 size_t GetNumberOfProfiles() const { return m_profiles
.size(); }
98 /*! \brief Add a new profile
99 \param profile CProfile to add
101 void AddProfile(const CProfile
&profile
);
103 /*! \brief Are we using the login screen?
104 \return true if we're using the login screen, false otherwise
106 bool UsingLoginScreen() const { return m_usingLoginScreen
; }
108 /*! \brief Toggle login screen use on and off
109 Toggles the login screen state
111 void ToggleLoginScreen()
113 m_usingLoginScreen
= !m_usingLoginScreen
;
117 /*! \brief Are we the master user?
118 \return true if the current profile is the master user, false otherwise
120 bool IsMasterProfile() const { return m_currentProfile
== 0; }
122 /*! \brief Update the date of the current profile
124 void UpdateCurrentProfileDate();
126 /*! \brief Load the master user for the purposes of logging in
127 Loads the master user. Identical to LoadProfile(0) but doesn't
128 update the last logged in details
130 void LoadMasterProfileForLogin();
132 /*! \brief Retrieve the last used profile index
133 \return the last used profile that logged in. Does not count the
134 master user during login.
136 uint32_t GetLastUsedProfileIndex() const { return m_lastUsedProfile
; }
138 /*! \brief Retrieve the current profile index
139 \return the index of the currently logged in profile.
141 uint32_t GetCurrentProfileIndex() const { return m_currentProfile
; }
143 /*! \brief Retrieve the next id to use for a new profile
144 \return the unique <id> to be used when creating a new profile
146 int GetNextProfileId() const { return m_nextProfileId
; }
148 int GetCurrentProfileId() const { return GetCurrentProfile().getId(); }
150 /*! \brief Retrieve the autologin profile id
151 Retrieves the autologin profile id. When set to -1, then the last
152 used profile will be loaded
153 \return the id to the autologin profile
155 int GetAutoLoginProfileId() const { return m_autoLoginProfile
; }
157 /*! \brief Retrieve the autologin profile id
158 Retrieves the autologin profile id. When set to -1, then the last
159 used profile will be loaded
160 \return the id to the autologin profile
162 void SetAutoLoginProfileId(const int profileId
)
164 m_autoLoginProfile
= profileId
;
168 /*! \brief Retrieve the name of a particular profile by index
169 \param profileId profile index for which to retrieve the name
170 \param name will hold the name of the profile when a valid profile index has been provided
171 \return false if profileId is an invalid index, true if the name parameter is set
173 bool GetProfileName(const unsigned int profileId
, std::string
& name
) const;
175 std::string
GetUserDataFolder() const;
176 std::string
GetProfileUserDataFolder() const;
177 std::string
GetDatabaseFolder() const;
178 std::string
GetCDDBFolder() const;
179 std::string
GetThumbnailsFolder() const;
180 std::string
GetVideoThumbFolder() const;
181 std::string
GetBookmarksThumbFolder() const;
182 std::string
GetLibraryFolder() const;
183 std::string
GetSavestatesFolder() const;
184 std::string
GetSettingsFile() const;
186 // uses HasSlashAtEnd to determine if a directory or file was meant
187 std::string
GetUserDataItem(const std::string
& strFile
) const;
190 CEventLog
&GetEventLog();
193 // implementation of ISettingCallback
194 void OnSettingAction(const std::shared_ptr
<const CSetting
>& setting
) override
;
197 /*! \brief Set the current profile id and update the special://profile path
198 \param profileId profile index
200 void SetCurrentProfileId(unsigned int profileId
);
202 void PrepareLoadProfile(unsigned int profileIndex
);
203 void FinalizeLoadProfile();
205 // Construction parameters
206 std::shared_ptr
<CSettings
> m_settings
;
208 std::vector
<CProfile
> m_profiles
;
209 bool m_usingLoginScreen
= false;
210 bool m_profileLoadedForLogin
= false;
211 bool m_previousProfileLoadedForLogin
= false;
212 int m_autoLoginProfile
= -1;
213 unsigned int m_lastUsedProfile
= 0;
214 unsigned int m_currentProfile
=
215 0; // do not modify directly, use SetCurrentProfileId() function instead
216 int m_nextProfileId
=
217 0; // for tracking the next available id to give to a new profile to ensure id's are not re-used
218 mutable CCriticalSection m_critical
;
221 std::unique_ptr
<CEventLogManager
> m_eventLogs
;