Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / profiles / Profile.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "Profile.h"
22 #include "GUIInfoManager.h"
23 #include "utils/XMLUtils.h"
24
25 CProfile::CLock::CLock(LockType type, const CStdString &password)
26 {
27   programs = false;
28   pictures = false;
29   files = false;
30   video = false;
31   music = false;
32   settings = LOCK_LEVEL::NONE;
33   addonManager = false;
34   mode = type;
35   code = password;
36 }
37
38 void CProfile::CLock::Validate()
39 {
40   if (mode != LOCK_MODE_EVERYONE && (code == "-" || code.empty()))
41     mode = LOCK_MODE_EVERYONE;
42   
43   if (code.empty() || mode == LOCK_MODE_EVERYONE)
44     code = "-";
45 }
46
47 CProfile::CProfile(const CStdString &directory, const CStdString &name, const int id)
48 {
49   m_id = id;
50   m_directory = directory;
51   m_name = name;
52   m_bDatabases = true;
53   m_bCanWrite = true;
54   m_bSources = true;
55   m_bCanWriteSources = true;
56   m_bAddons = true;
57 }
58
59 CProfile::~CProfile(void)
60 {}
61
62 void CProfile::setDate()
63 {
64   CStdString strDate = g_infoManager.GetDate(true);
65   CStdString strTime = g_infoManager.GetTime();
66   if (strDate.empty() || strTime.empty())
67     setDate("-");
68   else
69     setDate(strDate+" - "+strTime);
70 }
71
72 void CProfile::Load(const TiXmlNode *node, int nextIdProfile)
73 {
74   if (!XMLUtils::GetInt(node, "id", m_id))
75     m_id = nextIdProfile; 
76
77   XMLUtils::GetString(node, "name", m_name);
78   XMLUtils::GetPath(node, "directory", m_directory);
79   XMLUtils::GetPath(node, "thumbnail", m_thumb);
80   XMLUtils::GetBoolean(node, "hasdatabases", m_bDatabases);
81   XMLUtils::GetBoolean(node, "canwritedatabases", m_bCanWrite);
82   XMLUtils::GetBoolean(node, "hassources", m_bSources);
83   XMLUtils::GetBoolean(node, "canwritesources", m_bCanWriteSources);
84   XMLUtils::GetBoolean(node, "lockaddonmanager", m_locks.addonManager);
85   XMLUtils::GetInt(node, "locksettings", (int&)m_locks.settings);
86   XMLUtils::GetBoolean(node, "lockfiles", m_locks.files);
87   XMLUtils::GetBoolean(node, "lockmusic", m_locks.music);
88   XMLUtils::GetBoolean(node, "lockvideo", m_locks.video);
89   XMLUtils::GetBoolean(node, "lockpictures", m_locks.pictures);
90   XMLUtils::GetBoolean(node, "lockprograms", m_locks.programs);
91   
92   int lockMode = m_locks.mode;
93   XMLUtils::GetInt(node, "lockmode", lockMode);
94   m_locks.mode = (LockType)lockMode;
95   if (m_locks.mode > LOCK_MODE_QWERTY || m_locks.mode < LOCK_MODE_EVERYONE)
96     m_locks.mode = LOCK_MODE_EVERYONE;
97   
98   XMLUtils::GetString(node, "lockcode", m_locks.code);
99   XMLUtils::GetString(node, "lastdate", m_date);
100 }
101
102 void CProfile::Save(TiXmlNode *root) const
103 {
104   TiXmlElement profileNode("profile");
105   TiXmlNode *node = root->InsertEndChild(profileNode);
106
107   XMLUtils::SetInt(node, "id", m_id);
108   XMLUtils::SetString(node, "name", m_name);
109   XMLUtils::SetPath(node, "directory", m_directory);
110   XMLUtils::SetPath(node, "thumbnail", m_thumb);
111   XMLUtils::SetBoolean(node, "hasdatabases", m_bDatabases);
112   XMLUtils::SetBoolean(node, "canwritedatabases", m_bCanWrite);
113   XMLUtils::SetBoolean(node, "hassources", m_bSources);
114   XMLUtils::SetBoolean(node, "canwritesources", m_bCanWriteSources);
115   XMLUtils::SetBoolean(node, "lockaddonmanager", m_locks.addonManager);
116   XMLUtils::SetInt(node, "locksettings", m_locks.settings);
117   XMLUtils::SetBoolean(node, "lockfiles", m_locks.files);
118   XMLUtils::SetBoolean(node, "lockmusic", m_locks.music);
119   XMLUtils::SetBoolean(node, "lockvideo", m_locks.video);
120   XMLUtils::SetBoolean(node, "lockpictures", m_locks.pictures);
121   XMLUtils::SetBoolean(node, "lockprograms", m_locks.programs);
122
123   XMLUtils::SetInt(node, "lockmode", m_locks.mode);
124   XMLUtils::SetString(node,"lockcode", m_locks.code);
125   XMLUtils::SetString(node, "lastdate", m_date);
126 }
127
128 void CProfile::SetLocks(const CProfile::CLock &locks)
129 {
130   m_locks = locks;
131   m_locks.Validate();
132 }