diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-03-08 02:21:30 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-03-08 02:21:30 +0000 |
commit | b62839fb92560fc2c2249a30d969d4d87ded245c (patch) | |
tree | b2c284dd1b3e3a3b72c19f33002337ae7205eab5 | |
parent | 4c490a75c57694ef960c9dceeaedc7d8f8cbdebe (diff) |
changed: Make CSettings::LoadProfiles add the master user if it doesn't exist.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@28458 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | xbmc/Settings.cpp | 184 | ||||
-rw-r--r-- | xbmc/Settings.h | 16 |
2 files changed, 107 insertions, 93 deletions
diff --git a/xbmc/Settings.cpp b/xbmc/Settings.cpp index 1b278ed879..f2e31195f6 100644 --- a/xbmc/Settings.cpp +++ b/xbmc/Settings.cpp @@ -1004,129 +1004,131 @@ bool CSettings::SaveSettingsToProfile(int index) } -bool CSettings::LoadProfiles(const CStdString& strSettingsFile) +void CSettings::LoadProfiles(const CStdString& profilesFile) { // clear out our profiles m_vecProfiles.clear(); TiXmlDocument profilesDoc; - if (!CFile::Exists(strSettingsFile)) - { // set defaults, or assume no rss feeds?? - return false; - } - if (!profilesDoc.LoadFile(strSettingsFile)) - { - CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", strSettingsFile.c_str(), profilesDoc.ErrorRow(), profilesDoc.ErrorDesc()); - return false; - } - - TiXmlElement *pRootElement = profilesDoc.RootElement(); - if (!pRootElement || strcmpi(pRootElement->Value(),"profiles") != 0) + if (CFile::Exists(profilesFile)) { - CLog::Log(LOGERROR, "Error loading %s, no <profiles> node", strSettingsFile.c_str()); - return false; - } - GetInteger(pRootElement,"lastloaded",m_iLastLoadedProfileIndex,0,0,1000); - if (m_iLastLoadedProfileIndex < 0) - m_iLastLoadedProfileIndex = 0; - - XMLUtils::GetBoolean(pRootElement,"useloginscreen",bUseLoginScreen); + if (profilesDoc.LoadFile(profilesFile)) + { + TiXmlElement *rootElement = profilesDoc.RootElement(); + if (rootElement && strcmpi(rootElement->Value(),"profiles") == 0) + { + GetInteger(rootElement, "lastloaded", m_iLastLoadedProfileIndex, 0, 0, 1000); + XMLUtils::GetBoolean(rootElement, "useloginscreen", bUseLoginScreen); - TiXmlElement* pProfile = pRootElement->FirstChildElement("profile"); - CProfile profile; + TiXmlElement* pProfile = rootElement->FirstChildElement("profile"); + while (pProfile) + { + CProfile profile; + profile.setName("Master user"); + if (CDirectory::Exists("special://home/userdata")) + profile.setDirectory("special://home/userdata"); + else + profile.setDirectory("special://xbmc/userdata"); - while (pProfile) - { - profile.setName("Master user"); - if (CDirectory::Exists("special://home/userdata")) - profile.setDirectory("special://home/userdata"); - else - profile.setDirectory("special://xbmc/userdata"); + CStdString strName; + XMLUtils::GetString(pProfile,"name",strName); + profile.setName(strName); - CStdString strName; - XMLUtils::GetString(pProfile,"name",strName); - profile.setName(strName); + CStdString strDirectory; + XMLUtils::GetPath(pProfile,"directory",strDirectory); + profile.setDirectory(strDirectory); - CStdString strDirectory; - XMLUtils::GetPath(pProfile,"directory",strDirectory); - profile.setDirectory(strDirectory); + CStdString strThumb; + XMLUtils::GetPath(pProfile,"thumbnail",strThumb); + profile.setThumb(strThumb); - CStdString strThumb; - XMLUtils::GetPath(pProfile,"thumbnail",strThumb); - profile.setThumb(strThumb); + bool bHas=true; + XMLUtils::GetBoolean(pProfile, "hasdatabases", bHas); + profile.setDatabases(bHas); - bool bHas=true; - XMLUtils::GetBoolean(pProfile, "hasdatabases", bHas); - profile.setDatabases(bHas); + bHas = true; + XMLUtils::GetBoolean(pProfile, "canwritedatabases", bHas); + profile.setWriteDatabases(bHas); - bHas = true; - XMLUtils::GetBoolean(pProfile, "canwritedatabases", bHas); - profile.setWriteDatabases(bHas); + bHas = true; + XMLUtils::GetBoolean(pProfile, "hassources", bHas); + profile.setSources(bHas); - bHas = true; - XMLUtils::GetBoolean(pProfile, "hassources", bHas); - profile.setSources(bHas); + bHas = true; + XMLUtils::GetBoolean(pProfile, "canwritesources", bHas); + profile.setWriteSources(bHas); - bHas = true; - XMLUtils::GetBoolean(pProfile, "canwritesources", bHas); - profile.setWriteSources(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockaddonmanager", bHas); + profile.setAddonManagerLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockaddonmanager", bHas); - profile.setAddonManagerLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "locksettings", bHas); + profile.setSettingsLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "locksettings", bHas); - profile.setSettingsLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockfiles", bHas); + profile.setFilesLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockfiles", bHas); - profile.setFilesLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockmusic", bHas); + profile.setMusicLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockmusic", bHas); - profile.setMusicLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockvideo", bHas); + profile.setVideoLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockvideo", bHas); - profile.setVideoLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockpictures", bHas); + profile.setPicturesLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockpictures", bHas); - profile.setPicturesLocked(bHas); + bHas = false; + XMLUtils::GetBoolean(pProfile, "lockprograms", bHas); + profile.setProgramsLocked(bHas); - bHas = false; - XMLUtils::GetBoolean(pProfile, "lockprograms", bHas); - profile.setProgramsLocked(bHas); + LockType iLockMode; + int lockMode = (int)LOCK_MODE_EVERYONE; + XMLUtils::GetInt(pProfile,"lockmode",lockMode); + iLockMode = (LockType)lockMode; - LockType iLockMode; - int lockMode = (int)LOCK_MODE_EVERYONE; - XMLUtils::GetInt(pProfile,"lockmode",lockMode); - iLockMode = (LockType)lockMode; + if (iLockMode > LOCK_MODE_QWERTY || iLockMode < LOCK_MODE_EVERYONE) + iLockMode = LOCK_MODE_EVERYONE; + profile.setLockMode(iLockMode); - if (iLockMode > LOCK_MODE_QWERTY || iLockMode < LOCK_MODE_EVERYONE) - iLockMode = LOCK_MODE_EVERYONE; - profile.setLockMode(iLockMode); + CStdString strLockCode; + XMLUtils::GetString(pProfile,"lockcode",strLockCode); + profile.setLockCode(strLockCode); - CStdString strLockCode; - XMLUtils::GetString(pProfile,"lockcode",strLockCode); - profile.setLockCode(strLockCode); + CStdString strDate; + XMLUtils::GetString(pProfile,"lastdate",strDate); + profile.setDate(strDate); - CStdString strDate; - XMLUtils::GetString(pProfile,"lastdate",strDate); - profile.setDate(strDate); + m_vecProfiles.push_back(profile); + pProfile = pProfile->NextSiblingElement("profile"); + } + } + else + CLog::Log(LOGERROR, "Error loading %s, no <profiles> node", profilesFile.c_str()); + } + else + CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", profilesFile.c_str(), profilesDoc.ErrorRow(), profilesDoc.ErrorDesc()); + } + if (m_vecProfiles.empty()) + { // add the master user + CProfile profile; + profile.setName("Master user"); + profile.setDirectory("special://masterprofile/"); + profile.setLockMode(LOCK_MODE_EVERYONE); m_vecProfiles.push_back(profile); - pProfile = pProfile->NextSiblingElement("profile"); } - if (m_iLastLoadedProfileIndex >= (int)GetNumProfiles() || m_iLastLoadedProfileIndex < 0) + // check the validity of the profile index + if (m_iLastLoadedProfileIndex >= m_vecProfiles.size() || m_iLastLoadedProfileIndex < 0) m_iLastLoadedProfileIndex = 0; - - return true; } -bool CSettings::SaveProfiles(const CStdString& strSettingsFile) const +bool CSettings::SaveProfiles(const CStdString& profilesFile) const { TiXmlDocument xmlDoc; TiXmlElement xmlRootElement("profiles"); @@ -1166,7 +1168,7 @@ bool CSettings::SaveProfiles(const CStdString& strSettingsFile) const } } // save the file - return xmlDoc.SaveFile(strSettingsFile); + return xmlDoc.SaveFile(profilesFile); } bool CSettings::LoadUPnPXml(const CStdString& strSettingsFile) diff --git a/xbmc/Settings.h b/xbmc/Settings.h index a4630f7dd0..51d55a9161 100644 --- a/xbmc/Settings.h +++ b/xbmc/Settings.h @@ -324,8 +324,20 @@ public: bool LoadUPnPXml(const CStdString& strSettingsFile); bool SaveUPnPXml(const CStdString& strSettingsFile) const; - bool LoadProfiles(const CStdString& strSettingsFile); - bool SaveProfiles(const CStdString& strSettingsFile) 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; |