Skip to content

Commit

Permalink
Merge pull request #306 from Dak0ta/master
Browse files Browse the repository at this point in the history
Add Unique Identifier to Profiles in profiles.xml
  • Loading branch information
jmarshallnz committed Jul 28, 2011
2 parents 6331a46 + 1920f48 commit b9e483e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion xbmc/settings/GUIDialogProfileSettings.cpp
Expand Up @@ -322,7 +322,7 @@ bool CGUIDialogProfileSettings::ShowForProfile(unsigned int iProfile, bool first
}*/ }*/


// check for old profile settings // check for old profile settings
CProfile profile; CProfile profile(dialog->m_strDirectory,dialog->m_strName,g_settings.GetNextProfileId());
g_settings.AddProfile(profile); g_settings.AddProfile(profile);
bool bExists = CFile::Exists(URIUtils::AddFileToFolder("special://masterprofile/", bool bExists = CFile::Exists(URIUtils::AddFileToFolder("special://masterprofile/",
dialog->m_strDirectory+"/guisettings.xml")); dialog->m_strDirectory+"/guisettings.xml"));
Expand Down
9 changes: 7 additions & 2 deletions xbmc/settings/Profile.cpp
Expand Up @@ -45,8 +45,9 @@ void CProfile::CLock::Validate()
code = "-"; code = "-";
} }


CProfile::CProfile(const CStdString &directory, const CStdString &name) CProfile::CProfile(const CStdString &directory, const CStdString &name, const int id)
{ {
m_id = id;
m_directory = directory; m_directory = directory;
m_name = name; m_name = name;
m_bDatabases = true; m_bDatabases = true;
Expand All @@ -69,8 +70,11 @@ void CProfile::setDate()
setDate(strDate+" - "+strTime); setDate(strDate+" - "+strTime);
} }


void CProfile::Load(const TiXmlNode *node) void CProfile::Load(const TiXmlNode *node, int nextIdProfile)
{ {
if (!XMLUtils::GetInt(node, "id", m_id))
m_id = nextIdProfile;

XMLUtils::GetString(node, "name", m_name); XMLUtils::GetString(node, "name", m_name);
XMLUtils::GetPath(node, "directory", m_directory); XMLUtils::GetPath(node, "directory", m_directory);
XMLUtils::GetPath(node, "thumbnail", m_thumb); XMLUtils::GetPath(node, "thumbnail", m_thumb);
Expand Down Expand Up @@ -101,6 +105,7 @@ void CProfile::Save(TiXmlNode *root) const
TiXmlElement profileNode("profile"); TiXmlElement profileNode("profile");
TiXmlNode *node = root->InsertEndChild(profileNode); TiXmlNode *node = root->InsertEndChild(profileNode);


XMLUtils::SetInt(node, "id", m_id);
XMLUtils::SetString(node, "name", m_name); XMLUtils::SetString(node, "name", m_name);
XMLUtils::SetPath(node, "directory", m_directory); XMLUtils::SetPath(node, "directory", m_directory);
XMLUtils::SetPath(node, "thumbnail", m_thumb); XMLUtils::SetPath(node, "thumbnail", m_thumb);
Expand Down
6 changes: 4 additions & 2 deletions xbmc/settings/Profile.h
Expand Up @@ -49,13 +49,14 @@ class CProfile
bool programs; bool programs;
}; };


CProfile(const CStdString &directory = "", const CStdString &name = ""); CProfile(const CStdString &directory = "", const CStdString &name = "", const int id = -1);
~CProfile(void); ~CProfile(void);


void Load(const TiXmlNode *node); void Load(const TiXmlNode *node, int nextIdProfile);
void Save(TiXmlNode *root) const; void Save(TiXmlNode *root) const;


const CStdString& getDate() const { return m_date;} const CStdString& getDate() const { return m_date;}
const int getId() const { return m_id; }
const CStdString& getName() const { return m_name;} const CStdString& getName() const { return m_name;}
const CStdString& getDirectory() const { return m_directory;} const CStdString& getDirectory() const { return m_directory;}
const CStdString& getThumb() const { return m_thumb;} const CStdString& getThumb() const { return m_thumb;}
Expand Down Expand Up @@ -89,6 +90,7 @@ class CProfile


private: private:
CStdString m_directory; CStdString m_directory;
int m_id;
CStdString m_name; CStdString m_name;
CStdString m_date; CStdString m_date;
CStdString m_thumb; CStdString m_thumb;
Expand Down
19 changes: 15 additions & 4 deletions xbmc/settings/Settings.cpp
Expand Up @@ -137,6 +137,7 @@ void CSettings::Initialize()
m_usingLoginScreen = false; m_usingLoginScreen = false;
m_lastUsedProfile = 0; m_lastUsedProfile = 0;
m_currentProfile = 0; m_currentProfile = 0;
m_nextIdProfile = 0;


m_activeKeyboardMapping = "default"; m_activeKeyboardMapping = "default";
} }
Expand Down Expand Up @@ -1023,6 +1024,7 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)
{ {
XMLUtils::GetUInt(rootElement, "lastloaded", m_lastUsedProfile); XMLUtils::GetUInt(rootElement, "lastloaded", m_lastUsedProfile);
XMLUtils::GetBoolean(rootElement, "useloginscreen", m_usingLoginScreen); XMLUtils::GetBoolean(rootElement, "useloginscreen", m_usingLoginScreen);
XMLUtils::GetInt(rootElement, "nextIdProfile", m_nextIdProfile);


TiXmlElement* pProfile = rootElement->FirstChildElement("profile"); TiXmlElement* pProfile = rootElement->FirstChildElement("profile");


Expand All @@ -1032,8 +1034,8 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)
while (pProfile) while (pProfile)
{ {
CProfile profile(defaultDir); CProfile profile(defaultDir);
profile.Load(pProfile); profile.Load(pProfile,GetNextProfileId());
m_vecProfiles.push_back(profile); AddProfile(profile);
pProfile = pProfile->NextSiblingElement("profile"); pProfile = pProfile->NextSiblingElement("profile");
} }
} }
Expand All @@ -1046,8 +1048,8 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)


if (m_vecProfiles.empty()) if (m_vecProfiles.empty())
{ // add the master user { // add the master user
CProfile profile("special://masterprofile/", "Master user"); CProfile profile("special://masterprofile/", "Master user",0);
m_vecProfiles.push_back(profile); AddProfile(profile);
} }


// check the validity of the previous profile index // check the validity of the previous profile index
Expand All @@ -1070,6 +1072,7 @@ bool CSettings::SaveProfiles(const CStdString& profilesFile) const
if (!pRoot) return false; if (!pRoot) return false;
XMLUtils::SetInt(pRoot,"lastloaded", m_currentProfile); XMLUtils::SetInt(pRoot,"lastloaded", m_currentProfile);
XMLUtils::SetBoolean(pRoot,"useloginscreen",m_usingLoginScreen); XMLUtils::SetBoolean(pRoot,"useloginscreen",m_usingLoginScreen);
XMLUtils::SetInt(pRoot,"nextIdProfile",m_nextIdProfile);
for (unsigned int i = 0; i < m_vecProfiles.size(); ++i) for (unsigned int i = 0; i < m_vecProfiles.size(); ++i)
m_vecProfiles[i].Save(pRoot); m_vecProfiles[i].Save(pRoot);


Expand Down Expand Up @@ -1857,6 +1860,11 @@ const CProfile &CSettings::GetCurrentProfile() const
return emptyProfile; return emptyProfile;
} }


int CSettings::GetCurrentProfileId() const
{
return GetCurrentProfile().getId();
}

void CSettings::UpdateCurrentProfileDate() void CSettings::UpdateCurrentProfileDate()
{ {
if (m_currentProfile < m_vecProfiles.size()) if (m_currentProfile < m_vecProfiles.size())
Expand Down Expand Up @@ -1892,6 +1900,9 @@ int CSettings::GetProfileIndex(const CStdString &name) const


void CSettings::AddProfile(const CProfile &profile) void CSettings::AddProfile(const CProfile &profile)
{ {
//data integrity check - covers off migration from old profiles.xml, incrementing of the m_nextIdProfile,and bad data coming in
m_nextIdProfile = max(m_nextIdProfile, profile.getId() + 1);

m_vecProfiles.push_back(profile); m_vecProfiles.push_back(profile);
} }


Expand Down
8 changes: 8 additions & 0 deletions xbmc/settings/Settings.h
Expand Up @@ -319,6 +319,13 @@ class CSettings
*/ */
unsigned int GetCurrentProfileIndex() const { return m_currentProfile; }; unsigned int GetCurrentProfileIndex() const { return m_currentProfile; };


/*! \brief Retrieve the next id to use for a new profile
\return the unique <id> to be used when creating a new profile
*/
int GetNextProfileId() const { return m_nextIdProfile; }; // used to get the value of m_nextIdProfile for use in new profile creation

int GetCurrentProfileId() const;

std::vector<RESOLUTION_INFO> m_ResInfo; std::vector<RESOLUTION_INFO> m_ResInfo;


// utility functions for user data folders // utility functions for user data folders
Expand Down Expand Up @@ -399,6 +406,7 @@ class CSettings
bool m_usingLoginScreen; bool m_usingLoginScreen;
unsigned int m_lastUsedProfile; unsigned int m_lastUsedProfile;
unsigned int m_currentProfile; unsigned int m_currentProfile;
int m_nextIdProfile; // for tracking the next available id to give to a new profile to ensure id's are not re-used
}; };


extern class CSettings g_settings; extern class CSettings g_settings;

0 comments on commit b9e483e

Please sign in to comment.