blob: 71ff616c6c931e11fc3e29692e01706cd22bd40f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*
* Copyright (C) 2013-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "SkinSettings.h"
#include "GUIInfoManager.h"
#include "ServiceBroker.h"
#include "addons/Skin.h"
#include "guilib/GUIComponent.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/StringUtils.h"
#include "utils/XBMCTinyXML.h"
#include "utils/log.h"
#include <memory>
#include <mutex>
#include <string>
#define XML_SKINSETTINGS "skinsettings"
CSkinSettings::CSkinSettings()
{
Clear();
}
CSkinSettings::~CSkinSettings() = default;
CSkinSettings& CSkinSettings::GetInstance()
{
static CSkinSettings sSkinSettings;
return sSkinSettings;
}
int CSkinSettings::TranslateString(const std::string &setting)
{
return g_SkinInfo->TranslateString(setting);
}
const std::string& CSkinSettings::GetString(int setting) const
{
return g_SkinInfo->GetString(setting);
}
void CSkinSettings::SetString(int setting, const std::string &label)
{
g_SkinInfo->SetString(setting, label);
}
int CSkinSettings::TranslateBool(const std::string &setting)
{
return g_SkinInfo->TranslateBool(setting);
}
bool CSkinSettings::GetBool(int setting) const
{
return g_SkinInfo->GetBool(setting);
}
int CSkinSettings::GetInt(int setting) const
{
return g_SkinInfo->GetInt(setting);
}
void CSkinSettings::SetBool(int setting, bool set)
{
g_SkinInfo->SetBool(setting, set);
}
void CSkinSettings::Reset(const std::string &setting)
{
g_SkinInfo->Reset(setting);
}
std::set<ADDON::CSkinSettingPtr> CSkinSettings::GetSettings() const
{
return g_SkinInfo->GetSkinSettings();
}
ADDON::CSkinSettingPtr CSkinSettings::GetSetting(const std::string& settingId)
{
return g_SkinInfo->GetSkinSetting(settingId);
}
std::shared_ptr<const ADDON::CSkinSetting> CSkinSettings::GetSetting(
const std::string& settingId) const
{
return g_SkinInfo->GetSkinSetting(settingId);
}
void CSkinSettings::Reset()
{
g_SkinInfo->Reset();
CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager();
infoMgr.ResetCache();
infoMgr.GetInfoProviders().GetGUIControlsInfoProvider().ResetContainerMovingCache();
}
bool CSkinSettings::Load(const TiXmlNode *settings)
{
if (settings == nullptr)
return false;
const TiXmlElement *rootElement = settings->FirstChildElement(XML_SKINSETTINGS);
// return true in the case skinsettings is missing. It just means that
// it's been migrated and it's not an error
if (rootElement == nullptr)
{
CLog::Log(LOGDEBUG, "CSkinSettings: no <skinsettings> tag found");
return true;
}
std::unique_lock<CCriticalSection> lock(m_critical);
m_settings.clear();
m_settings = ADDON::CSkinInfo::ParseSettings(rootElement);
return true;
}
bool CSkinSettings::Save(TiXmlNode *settings) const
{
if (settings == nullptr)
return false;
// nothing to do here because skin settings saving has been migrated to CSkinInfo
return true;
}
void CSkinSettings::Clear()
{
std::unique_lock<CCriticalSection> lock(m_critical);
m_settings.clear();
}
void CSkinSettings::MigrateSettings(const std::shared_ptr<ADDON::CSkinInfo>& skin)
{
if (skin == nullptr)
return;
std::unique_lock<CCriticalSection> lock(m_critical);
bool settingsMigrated = false;
const std::string& skinId = skin->ID();
std::set<ADDON::CSkinSettingPtr> settingsCopy(m_settings.begin(), m_settings.end());
for (const auto& setting : settingsCopy)
{
if (!StringUtils::StartsWith(setting->name, skinId + "."))
continue;
std::string settingName = setting->name.substr(skinId.size() + 1);
if (setting->GetType() == "string")
{
int settingNumber = skin->TranslateString(settingName);
if (settingNumber >= 0)
skin->SetString(settingNumber, std::dynamic_pointer_cast<ADDON::CSkinSettingString>(setting)->value);
}
else if (setting->GetType() == "bool")
{
int settingNumber = skin->TranslateBool(settingName);
if (settingNumber >= 0)
skin->SetBool(settingNumber, std::dynamic_pointer_cast<ADDON::CSkinSettingBool>(setting)->value);
}
m_settings.erase(setting);
settingsMigrated = true;
}
if (settingsMigrated)
{
// save the skin's settings
skin->SaveSettings();
// save the guisettings.xml
CServiceBroker::GetSettingsComponent()->GetSettings()->Save();
}
}
|