2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "addons/IAddon.h"
12 #include "settings/SettingControl.h"
13 #include "settings/SettingCreator.h"
14 #include "settings/SettingsBase.h"
15 #include "settings/lib/ISettingCallback.h"
23 enum class SettingDependencyOperator
;
25 class CSettingCategory
;
27 class CSettingDependency
;
30 struct StringSettingOption
;
36 class IAddonInstanceHandler
;
38 class CAddonSettings
: public CSettingControlCreator
,
39 public CSettingCreator
,
41 public ISettingCallback
44 CAddonSettings(const std::shared_ptr
<IAddon
>& addon
, AddonInstanceId instanceId
);
45 ~CAddonSettings() override
= default;
47 // specialization of CSettingsBase
48 bool Initialize() override
{ return false; }
50 // implementations of CSettingsBase
51 bool Load() override
{ return false; }
54 // specialization of CSettingCreator
55 std::shared_ptr
<CSetting
> CreateSetting(
56 const std::string
& settingType
,
57 const std::string
& settingId
,
58 CSettingsManager
* settingsManager
= nullptr) const override
;
60 // implementation of ISettingCallback
61 void OnSettingAction(const std::shared_ptr
<const CSetting
>& setting
) override
;
63 const std::string
& GetAddonId() const { return m_addonId
; }
65 bool Initialize(const CXBMCTinyXML
& doc
, bool allowEmpty
= false);
66 bool Load(const CXBMCTinyXML
& doc
);
67 bool Save(CXBMCTinyXML
& doc
) const;
69 bool HasSettings() const;
71 std::string
GetSettingLabel(int label
) const;
73 std::shared_ptr
<CSetting
> AddSetting(const std::string
& settingId
, bool value
);
74 std::shared_ptr
<CSetting
> AddSetting(const std::string
& settingId
, int value
);
75 std::shared_ptr
<CSetting
> AddSetting(const std::string
& settingId
, double value
);
76 std::shared_ptr
<CSetting
> AddSetting(const std::string
& settingId
, const std::string
& value
);
79 // specializations of CSettingsBase
80 void InitializeSettingTypes() override
;
81 void InitializeControls() override
;
82 void InitializeConditions() override
;
84 // implementation of CSettingsBase
85 bool InitializeDefinitions() override
{ return false; }
88 bool AddInstanceSettings();
89 bool InitializeDefinitions(const CXBMCTinyXML
& doc
);
91 bool ParseSettingVersion(const CXBMCTinyXML
& doc
, uint32_t& version
) const;
93 std::shared_ptr
<CSettingGroup
> ParseOldSettingElement(
94 const TiXmlElement
* categoryElement
,
95 const std::shared_ptr
<CSettingCategory
>& category
,
96 std::set
<std::string
>& settingIds
);
98 std::shared_ptr
<CSettingCategory
> ParseOldCategoryElement(uint32_t& categoryId
,
99 const TiXmlElement
* categoryElement
,
100 std::set
<std::string
>& settingIds
);
102 bool InitializeFromOldSettingDefinitions(const CXBMCTinyXML
& doc
);
103 std::shared_ptr
<CSetting
> InitializeFromOldSettingAction(const std::string
& settingId
,
104 const TiXmlElement
* settingElement
,
105 const std::string
& defaultValue
);
106 std::shared_ptr
<CSetting
> InitializeFromOldSettingLabel();
107 std::shared_ptr
<CSetting
> InitializeFromOldSettingBool(const std::string
& settingId
,
108 const TiXmlElement
* settingElement
,
109 const std::string
& defaultValue
);
110 std::shared_ptr
<CSetting
> InitializeFromOldSettingTextIpAddress(
111 const std::string
& settingId
,
112 const std::string
& settingType
,
113 const TiXmlElement
* settingElement
,
114 const std::string
& defaultValue
,
115 const int settingLabel
);
116 std::shared_ptr
<CSetting
> InitializeFromOldSettingNumber(const std::string
& settingId
,
117 const TiXmlElement
* settingElement
,
118 const std::string
& defaultValue
,
119 const int settingLabel
);
120 std::shared_ptr
<CSetting
> InitializeFromOldSettingPath(const std::string
& settingId
,
121 const std::string
& settingType
,
122 const TiXmlElement
* settingElement
,
123 const std::string
& defaultValue
,
124 const int settingLabel
);
125 std::shared_ptr
<CSetting
> InitializeFromOldSettingDate(const std::string
& settingId
,
126 const TiXmlElement
* settingElement
,
127 const std::string
& defaultValue
,
128 const int settingLabel
);
129 std::shared_ptr
<CSetting
> InitializeFromOldSettingTime(const std::string
& settingId
,
130 const TiXmlElement
* settingElement
,
131 const std::string
& defaultValue
,
132 const int settingLabel
);
133 std::shared_ptr
<CSetting
> InitializeFromOldSettingSelect(
134 const std::string
& settingId
,
135 const TiXmlElement
* settingElement
,
136 const std::string
& defaultValue
,
137 const int settingLabel
,
138 const std::string
& settingValues
,
139 const std::vector
<std::string
>& settingLValues
);
140 std::shared_ptr
<CSetting
> InitializeFromOldSettingAddon(const std::string
& settingId
,
141 const TiXmlElement
* settingElement
,
142 const std::string
& defaultValue
,
143 const int settingLabel
);
144 std::shared_ptr
<CSetting
> InitializeFromOldSettingEnums(
145 const std::string
& settingId
,
146 const std::string
& settingType
,
147 const TiXmlElement
* settingElement
,
148 const std::string
& defaultValue
,
149 const std::string
& settingValues
,
150 const std::vector
<std::string
>& settingLValues
);
151 std::shared_ptr
<CSetting
> InitializeFromOldSettingFileEnum(const std::string
& settingId
,
152 const TiXmlElement
* settingElement
,
153 const std::string
& defaultValue
,
154 const std::string
& settingValues
);
155 std::shared_ptr
<CSetting
> InitializeFromOldSettingRangeOfNum(const std::string
& settingId
,
156 const TiXmlElement
* settingElement
,
157 const std::string
& defaultValue
);
158 std::shared_ptr
<CSetting
> InitializeFromOldSettingSlider(const std::string
& settingId
,
159 const TiXmlElement
* settingElement
,
160 const std::string
& defaultValue
);
161 std::shared_ptr
<CSetting
> InitializeFromOldSettingFileWithSource(
162 const std::string
& settingId
,
163 const TiXmlElement
* settingElement
,
164 const std::string
& defaultValue
,
167 bool LoadOldSettingValues(const CXBMCTinyXML
& doc
,
168 std::map
<std::string
, std::string
>& settings
) const;
170 struct ConditionExpression
172 SettingDependencyOperator m_operator
;
174 int32_t m_relativeSettingIndex
;
178 bool ParseOldLabel(const TiXmlElement
* element
, const std::string
& settingId
, int& labelId
);
179 bool ParseOldCondition(const std::shared_ptr
<const CSetting
>& setting
,
180 const std::vector
<std::shared_ptr
<const CSetting
>>& settings
,
181 const std::string
& condition
,
182 CSettingDependency
& dependeny
) const;
183 static bool ParseOldConditionExpression(std::string str
, ConditionExpression
& expression
);
185 static void FileEnumSettingOptionsFiller(const std::shared_ptr
<const CSetting
>& setting
,
186 std::vector
<StringSettingOption
>& list
,
187 std::string
& current
,
190 // store these values so that we don't always have to access the weak pointer
191 const std::string m_addonId
;
192 const std::string m_addonPath
;
193 const std::string m_addonProfile
;
194 const AddonInstanceId m_instanceId
{ADDON_SETTINGS_ID
};
195 std::weak_ptr
<IAddon
> m_addon
;
197 uint32_t m_unidentifiedSettingId
= 0;
198 int m_unknownSettingLabelId
;
199 std::map
<int, std::string
> m_unknownSettingLabels
;