Debian Codegraph @

xbmc/profiles/Profile.cpp

raw
1 /*
2 * Copyright (C) 2005-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 #include "Profile.h"
10
11 #include "XBDateTime.h"
12 #include "utils/XMLUtils.h"
13
14 CProfile::CLock::CLock(LockType type, const std::string &password):
15 code(password)
16 {
17 programs = false;
18 pictures = false;
19 files = false;
20 video = false;
21 music = false;
22 settings = LOCK_LEVEL::NONE;
23 addonManager = false;
24 games = false;
25 mode = type;
26 }
27
28 void CProfile::CLock::Validate()
29 {
30 if (mode != LOCK_MODE_EVERYONE && (code == "-" || code.empty()))
31 mode = LOCK_MODE_EVERYONE;
32
33 if (code.empty() || mode == LOCK_MODE_EVERYONE)
34 code = "-";
35 }
36
37 CProfile::CProfile(const std::string &directory, const std::string &name, const int id):
38 m_directory(directory),
39 m_name(name)
40 {
41 m_id = id;
42 m_bDatabases = true;
43 m_bCanWrite = true;
44 m_bSources = true;
45 m_bCanWriteSources = true;
46 m_bAddons = true;
47 }
48
49 CProfile::~CProfile(void) = default;
50
51 void CProfile::setDate()
52 {
53 const CDateTime now = CDateTime::GetCurrentDateTime();
54 std::string strDate = now.GetAsLocalizedDate(false);
55 std::string strTime = now.GetAsLocalizedTime(TIME_FORMAT_GUESS);
56 if (strDate.empty() || strTime.empty())
57 setDate("-");
58 else
59 setDate(strDate+" - "+strTime);
60 }
61
62 void CProfile::Load(const TiXmlNode *node, int nextIdProfile)
63 {
64 if (!XMLUtils::GetInt(node, "id", m_id))
65 m_id = nextIdProfile;
66
67 XMLUtils::GetString(node, "name", m_name);
68 XMLUtils::GetPath(node, "directory", m_directory);
69 XMLUtils::GetPath(node, "thumbnail", m_thumb);
70 XMLUtils::GetBoolean(node, "hasdatabases", m_bDatabases);
71 XMLUtils::GetBoolean(node, "canwritedatabases", m_bCanWrite);
72 XMLUtils::GetBoolean(node, "hassources", m_bSources);
73 XMLUtils::GetBoolean(node, "canwritesources", m_bCanWriteSources);
74 XMLUtils::GetBoolean(node, "lockaddonmanager", m_locks.addonManager);
75 int settings = m_locks.settings;
76 XMLUtils::GetInt(node, "locksettings", settings);
77 m_locks.settings = (LOCK_LEVEL::SETTINGS_LOCK)settings;
78 XMLUtils::GetBoolean(node, "lockfiles", m_locks.files);
79 XMLUtils::GetBoolean(node, "lockmusic", m_locks.music);
80 XMLUtils::GetBoolean(node, "lockvideo", m_locks.video);
81 XMLUtils::GetBoolean(node, "lockpictures", m_locks.pictures);
82 XMLUtils::GetBoolean(node, "lockprograms", m_locks.programs);
83 XMLUtils::GetBoolean(node, "lockgames", m_locks.games);
84
85 int lockMode = m_locks.mode;
86 XMLUtils::GetInt(node, "lockmode", lockMode);
87 m_locks.mode = (LockType)lockMode;
88 if (m_locks.mode > LOCK_MODE_QWERTY || m_locks.mode < LOCK_MODE_EVERYONE)
89 m_locks.mode = LOCK_MODE_EVERYONE;
90
91 XMLUtils::GetString(node, "lockcode", m_locks.code);
92 XMLUtils::GetString(node, "lastdate", m_date);
93 }
94
95 void CProfile::Save(TiXmlNode *root) const
96 {
97 TiXmlElement profileNode("profile");
98 TiXmlNode *node = root->InsertEndChild(profileNode);
99
100 XMLUtils::SetInt(node, "id", m_id);
101 XMLUtils::SetString(node, "name", m_name);
102 XMLUtils::SetPath(node, "directory", m_directory);
103 XMLUtils::SetPath(node, "thumbnail", m_thumb);
104 XMLUtils::SetBoolean(node, "hasdatabases", m_bDatabases);
105 XMLUtils::SetBoolean(node, "canwritedatabases", m_bCanWrite);
106 XMLUtils::SetBoolean(node, "hassources", m_bSources);
107 XMLUtils::SetBoolean(node, "canwritesources", m_bCanWriteSources);
108 XMLUtils::SetBoolean(node, "lockaddonmanager", m_locks.addonManager);
109 XMLUtils::SetInt(node, "locksettings", m_locks.settings);
110 XMLUtils::SetBoolean(node, "lockfiles", m_locks.files);
111 XMLUtils::SetBoolean(node, "lockmusic", m_locks.music);
112 XMLUtils::SetBoolean(node, "lockvideo", m_locks.video);
113 XMLUtils::SetBoolean(node, "lockpictures", m_locks.pictures);
114 XMLUtils::SetBoolean(node, "lockprograms", m_locks.programs);
115 XMLUtils::SetBoolean(node, "lockgames", m_locks.games);
116
117 XMLUtils::SetInt(node, "lockmode", m_locks.mode);
118 XMLUtils::SetString(node,"lockcode", m_locks.code);
119 XMLUtils::SetString(node, "lastdate", m_date);
120 }
121
122 void CProfile::SetLocks(const CProfile::CLock &locks)
123 {
124 m_locks = locks;
125 m_locks.Validate();
126 }