From 548e229e9f4727b5f070a571c2055d9808e53e54 Mon Sep 17 00:00:00 2001
From: LeechGuy <leechguy@gmail.com>
Date: Sat, 6 Apr 2013 02:28:13 +0200
Subject: Adds <autologin></autologin> to profiles.xml. When set to an invalid
 profile index the lastloaded profile will be loaded. When set to a valid
 index, XBMC will load that profile.

---
 xbmc/profiles/ProfilesManager.cpp | 11 ++++++++++-
 xbmc/profiles/ProfilesManager.h   |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/xbmc/profiles/ProfilesManager.cpp b/xbmc/profiles/ProfilesManager.cpp
index 88049789ee..10db718dc2 100644
--- a/xbmc/profiles/ProfilesManager.cpp
+++ b/xbmc/profiles/ProfilesManager.cpp
@@ -56,6 +56,7 @@
 #define PROFILES_FILE     "special://masterprofile/profiles.xml"
 
 #define XML_PROFILES      "profiles"
+#define XML_AUTO_LOGIN    "autologin"
 #define XML_LAST_LOADED   "lastloaded"
 #define XML_LOGIN_SCREEN  "useloginscreen"
 #define XML_NEXTID        "nextIdProfile"
@@ -67,7 +68,7 @@ using namespace XFILE;
 static CProfile EmptyProfile;
 
 CProfilesManager::CProfilesManager()
-  : m_usingLoginScreen(false), m_lastUsedProfile(0),
+  : m_usingLoginScreen(false), m_autoLoginProfile(-1), m_lastUsedProfile(0),
     m_currentProfile(0), m_nextProfileId(0)
 { }
 
@@ -137,6 +138,7 @@ bool CProfilesManager::Load(const std::string &file)
       {
         XMLUtils::GetUInt(rootElement, XML_LAST_LOADED, m_lastUsedProfile);
         XMLUtils::GetBoolean(rootElement, XML_LOGIN_SCREEN, m_usingLoginScreen);
+        XMLUtils::GetInt(rootElement, XML_AUTO_LOGIN, m_autoLoginProfile);
         XMLUtils::GetInt(rootElement, XML_NEXTID, m_nextProfileId);
         
         CStdString defaultDir("special://home/userdata");
@@ -178,6 +180,12 @@ bool CProfilesManager::Load(const std::string &file)
 
   m_currentProfile = m_lastUsedProfile;
 
+  // check the validity of the auto login profile index
+  if (m_autoLoginProfile < -1 || m_autoLoginProfile >= (int)m_profiles.size())
+    m_autoLoginProfile = -1;
+  else if (m_autoLoginProfile >= 0)
+    m_currentProfile = m_autoLoginProfile;
+
   // the login screen runs as the master profile, so if we're using this, we need to ensure
   // we switch to the master profile
   if (m_usingLoginScreen)
@@ -203,6 +211,7 @@ bool CProfilesManager::Save(const std::string &file) const
 
   XMLUtils::SetInt(pRoot, XML_LAST_LOADED, m_currentProfile);
   XMLUtils::SetBoolean(pRoot, XML_LOGIN_SCREEN, m_usingLoginScreen);
+  XMLUtils::SetInt(pRoot, XML_AUTO_LOGIN, m_autoLoginProfile);
   XMLUtils::SetInt(pRoot, XML_NEXTID, m_nextProfileId);      
 
   for (vector<CProfile>::const_iterator profile = m_profiles.begin(); profile != m_profiles.end(); profile++)
diff --git a/xbmc/profiles/ProfilesManager.h b/xbmc/profiles/ProfilesManager.h
index 4b64a95521..addeaf28ab 100644
--- a/xbmc/profiles/ProfilesManager.h
+++ b/xbmc/profiles/ProfilesManager.h
@@ -164,6 +164,7 @@ protected:
 private:
   std::vector<CProfile> m_profiles;
   bool m_usingLoginScreen;
+  int m_autoLoginProfile;
   uint32_t m_lastUsedProfile;
   uint32_t m_currentProfile;
   int m_nextProfileId; // for tracking the next available id to give to a new profile to ensure id's are not re-used
-- 
cgit v1.2.3