xbmc
ProfileManager.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "profiles/Profile.h"
12 #include "settings/lib/ISettingCallback.h"
13 #include "settings/lib/ISettingsHandler.h"
14 #include "threads/CriticalSection.h"
15 
16 #include <memory>
17 #include <stdint.h>
18 #include <vector>
19 
20 class CEventLog;
21 class CEventLogManager;
22 class CSettings;
23 class TiXmlNode;
24 
26  protected ISettingCallback
27 {
28 public:
30  CProfileManager(const CProfileManager&) = delete;
31  CProfileManager& operator=(CProfileManager const&) = delete;
32  ~CProfileManager() override;
33 
34  void Initialize(const std::shared_ptr<CSettings>& settings);
35  void Uninitialize();
36 
37  void OnSettingsLoaded() override;
38  void OnSettingsSaved() const override;
39  void OnSettingsCleared() override;
40 
41  bool Load();
49  bool Save() const;
56  void Clear();
57 
58  bool LoadProfile(unsigned int index);
59  void LogOff();
60 
61  bool DeleteProfile(unsigned int index);
62 
63  void CreateProfileFolders();
64 
68  const CProfile& GetMasterProfile() const;
69 
73  const CProfile& GetCurrentProfile() const;
74 
79  const CProfile* GetProfile(unsigned int index) const;
80 
85  CProfile* GetProfile(unsigned int index);
86 
91  int GetProfileIndex(const std::string &name) const;
92 
96  size_t GetNumberOfProfiles() const { return m_profiles.size(); }
97 
101  void AddProfile(const CProfile &profile);
102 
106  bool UsingLoginScreen() const { return m_usingLoginScreen; }
107 
112  {
113  m_usingLoginScreen = !m_usingLoginScreen;
114  Save();
115  }
116 
120  bool IsMasterProfile() const { return m_currentProfile == 0; }
121 
125 
131 
136  uint32_t GetLastUsedProfileIndex() const { return m_lastUsedProfile; }
137 
141  uint32_t GetCurrentProfileIndex() const { return m_currentProfile; }
142 
146  int GetNextProfileId() const { return m_nextProfileId; }
147 
148  int GetCurrentProfileId() const { return GetCurrentProfile().getId(); }
149 
155  int GetAutoLoginProfileId() const { return m_autoLoginProfile; }
156 
162  void SetAutoLoginProfileId(const int profileId)
163  {
164  m_autoLoginProfile = profileId;
165  Save();
166  }
167 
173  bool GetProfileName(const unsigned int profileId, std::string& name) const;
174 
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;
185 
186  // uses HasSlashAtEnd to determine if a directory or file was meant
187  std::string GetUserDataItem(const std::string& strFile) const;
188 
189  // Event log access
190  CEventLog &GetEventLog();
191 
192 protected:
193  // implementation of ISettingCallback
194  void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;
195 
196 private:
200  void SetCurrentProfileId(unsigned int profileId);
201 
202  void PrepareLoadProfile(unsigned int profileIndex);
203  void FinalizeLoadProfile();
204 
205  // Construction parameters
206  std::shared_ptr<CSettings> m_settings;
207 
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;
219 
220  // Event properties
221  std::unique_ptr<CEventLogManager> m_eventLogs;
222 };
const CProfile * GetProfile(unsigned int index) const
Retrieve the profile from an index.
Definition: ProfileManager.cpp:560
bool GetProfileName(const unsigned int profileId, std::string &name) const
Retrieve the name of a particular profile by index.
Definition: ProfileManager.cpp:631
uint32_t GetCurrentProfileIndex() const
Retrieve the current profile index.
Definition: ProfileManager.h:141
void OnSettingAction(const std::shared_ptr< const CSetting > &setting) override
The given setting has been activated.
Definition: ProfileManager.cpp:729
int GetAutoLoginProfileId() const
Retrieve the autologin profile id Retrieves the autologin profile id. When set to -1...
Definition: ProfileManager.h:155
Wrapper around CSettingsManager responsible for properly setting up the settings manager and register...
Definition: Settings.h:27
void OnSettingsCleared() override
Settings have been cleared.
Definition: ProfileManager.cpp:134
Definition: ISettingCallback.h:16
int GetProfileIndex(const std::string &name) const
Retrieve index of a particular profile by name.
Definition: ProfileManager.cpp:578
void Clear()
Save the user profile information to disk Saves the list of profiles to the profiles.xml file.
Definition: ProfileManager.cpp:249
bool IsMasterProfile() const
Are we the master user?
Definition: ProfileManager.h:120
void UpdateCurrentProfileDate()
Update the date of the current profile.
Definition: ProfileManager.cpp:603
void OnSettingsSaved() const override
Settings have been saved.
Definition: ProfileManager.cpp:128
bool UsingLoginScreen() const
Are we using the login screen?
Definition: ProfileManager.h:106
Definition: EventLog.h:23
int GetNextProfileId() const
Retrieve the next id to use for a new profile.
Definition: ProfileManager.h:146
void OnSettingsLoaded() override
Settings have been loaded.
Definition: ProfileManager.cpp:112
void ToggleLoginScreen()
Toggle login screen use on and off Toggles the login screen state.
Definition: ProfileManager.h:111
uint32_t GetLastUsedProfileIndex() const
Retrieve the last used profile index.
Definition: ProfileManager.h:136
const CProfile & GetCurrentProfile() const
Retrieve the current profile.
Definition: ProfileManager.cpp:550
Definition: ProfileManager.h:25
Definition: settings.py:1
const CProfile & GetMasterProfile() const
Retrieve the master profile.
Definition: ProfileManager.cpp:540
void SetAutoLoginProfileId(const int profileId)
Retrieve the autologin profile id Retrieves the autologin profile id. When set to -1...
Definition: ProfileManager.h:162
Interface defining methods being called by the settings system if an action is performed on multiple/...
Definition: ISettingsHandler.h:16
Definition: Profile.h:19
bool Save() const
Load the user profile information from disk Loads the profiles.xml file and creates the list of profi...
Definition: ProfileManager.cpp:225
void LoadMasterProfileForLogin()
Load the master user for the purposes of logging in Loads the master user. Identical to LoadProfile(0...
Definition: ProfileManager.cpp:614
size_t GetNumberOfProfiles() const
Retrieve the number of profiles.
Definition: ProfileManager.h:96
void AddProfile(const CProfile &profile)
Add a new profile.
Definition: ProfileManager.cpp:590
Definition: EventLogManager.h:18