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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/*
* Copyright (C) 2017-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.
*/
#pragma once
#include "addons/IAddon.h"
#include "settings/SettingControl.h"
#include "settings/SettingCreator.h"
#include "settings/SettingsBase.h"
#include "settings/lib/ISettingCallback.h"
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
enum class SettingDependencyOperator;
class CSettingCategory;
class CSettingGroup;
class CSettingDependency;
class CXBMCTinyXML;
struct StringSettingOption;
namespace ADDON
{
class IAddon;
class IAddonInstanceHandler;
class CAddonSettings : public CSettingControlCreator,
public CSettingCreator,
public CSettingsBase,
public ISettingCallback
{
public:
CAddonSettings(const std::shared_ptr<const IAddon>& addon, AddonInstanceId instanceId);
~CAddonSettings() override = default;
// specialization of CSettingsBase
bool Initialize() override { return false; }
// implementations of CSettingsBase
bool Load() override { return false; }
bool Save() override { return false; }
// specialization of CSettingCreator
std::shared_ptr<CSetting> CreateSetting(
const std::string& settingType,
const std::string& settingId,
CSettingsManager* settingsManager = nullptr) const override;
// implementation of ISettingCallback
void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override;
const std::string& GetAddonId() const { return m_addonId; }
bool Initialize(const CXBMCTinyXML& doc, bool allowEmpty = false);
bool Load(const CXBMCTinyXML& doc);
bool Save(CXBMCTinyXML& doc) const;
bool HasSettings() const;
std::string GetSettingLabel(int label) const;
std::shared_ptr<CSetting> AddSetting(const std::string& settingId, bool value);
std::shared_ptr<CSetting> AddSetting(const std::string& settingId, int value);
std::shared_ptr<CSetting> AddSetting(const std::string& settingId, double value);
std::shared_ptr<CSetting> AddSetting(const std::string& settingId, const std::string& value);
protected:
// specializations of CSettingsBase
void InitializeSettingTypes() override;
void InitializeControls() override;
void InitializeConditions() override;
// implementation of CSettingsBase
bool InitializeDefinitions() override { return false; }
private:
bool AddInstanceSettings();
bool InitializeDefinitions(const CXBMCTinyXML& doc);
bool ParseSettingVersion(const CXBMCTinyXML& doc, uint32_t& version) const;
std::shared_ptr<CSettingGroup> ParseOldSettingElement(
const TiXmlElement* categoryElement,
const std::shared_ptr<CSettingCategory>& category,
std::set<std::string>& settingIds);
std::shared_ptr<CSettingCategory> ParseOldCategoryElement(uint32_t& categoryId,
const TiXmlElement* categoryElement,
std::set<std::string>& settingIds);
bool InitializeFromOldSettingDefinitions(const CXBMCTinyXML& doc);
std::shared_ptr<CSetting> InitializeFromOldSettingAction(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue);
std::shared_ptr<CSetting> InitializeFromOldSettingLabel();
std::shared_ptr<CSetting> InitializeFromOldSettingBool(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue);
std::shared_ptr<CSetting> InitializeFromOldSettingTextIpAddress(
const std::string& settingId,
const std::string& settingType,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingNumber(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingPath(const std::string& settingId,
const std::string& settingType,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingDate(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingTime(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingSelect(
const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel,
const std::string& settingValues,
const std::vector<std::string>& settingLValues);
std::shared_ptr<CSetting> InitializeFromOldSettingAddon(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const int settingLabel);
std::shared_ptr<CSetting> InitializeFromOldSettingEnums(
const std::string& settingId,
const std::string& settingType,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const std::string& settingValues,
const std::vector<std::string>& settingLValues);
std::shared_ptr<CSetting> InitializeFromOldSettingFileEnum(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
const std::string& settingValues);
std::shared_ptr<CSetting> InitializeFromOldSettingRangeOfNum(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue);
std::shared_ptr<CSetting> InitializeFromOldSettingSlider(const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue);
std::shared_ptr<CSetting> InitializeFromOldSettingFileWithSource(
const std::string& settingId,
const TiXmlElement* settingElement,
const std::string& defaultValue,
std::string source);
bool LoadOldSettingValues(const CXBMCTinyXML& doc,
std::map<std::string, std::string>& settings) const;
struct ConditionExpression
{
SettingDependencyOperator m_operator;
bool m_negated;
int32_t m_relativeSettingIndex;
std::string m_value;
};
bool ParseOldLabel(const TiXmlElement* element, const std::string& settingId, int& labelId);
bool ParseOldCondition(const std::shared_ptr<const CSetting>& setting,
const std::vector<std::shared_ptr<const CSetting>>& settings,
const std::string& condition,
CSettingDependency& dependeny) const;
static bool ParseOldConditionExpression(std::string str, ConditionExpression& expression);
static void FileEnumSettingOptionsFiller(const std::shared_ptr<const CSetting>& setting,
std::vector<StringSettingOption>& list,
std::string& current,
void* data);
// store these values so that we don't always have to access the weak pointer
const std::string m_addonId;
const std::string m_addonPath;
const std::string m_addonProfile;
const AddonInstanceId m_instanceId{ADDON_SETTINGS_ID};
uint32_t m_unidentifiedSettingId;
int m_unknownSettingLabelId;
std::map<int, std::string> m_unknownSettingLabels;
Logger m_logger;
};
} // namespace ADDON
|