2 * Copyright (C) 2013-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 "settings/lib/ISettingControl.h"
12 #include "settings/lib/ISettingControlCreator.h"
14 #define SETTING_XML_ELM_CONTROL_FORMATLABEL "formatlabel"
15 #define SETTING_XML_ELM_CONTROL_HIDDEN "hidden"
16 #define SETTING_XML_ELM_CONTROL_VERIFYNEW "verifynew"
17 #define SETTING_XML_ELM_CONTROL_HEADING "heading"
18 #define SETTING_XML_ELM_CONTROL_HIDEVALUE "hidevalue"
19 #define SETTING_XML_ELM_CONTROL_MULTISELECT "multiselect"
20 #define SETTING_XML_ELM_CONTROL_POPUP "popup"
21 #define SETTING_XML_ELM_CONTROL_FORMATVALUE "value"
22 #define SETTING_XML_ELM_CONTROL_ADDBUTTONLABEL "addbuttonlabel"
23 #define SETTING_XML_ATTR_SHOW_MORE "more"
24 #define SETTING_XML_ATTR_SHOW_DETAILS "details"
25 #define SETTING_XML_ATTR_SEPARATOR_POSITION "separatorposition"
26 #define SETTING_XML_ATTR_HIDE_SEPARATOR "hideseparator"
30 class CSettingControlCreator
: public ISettingControlCreator
33 // implementation of ISettingControlCreator
34 std::shared_ptr
<ISettingControl
> CreateControl(const std::string
&controlType
) const override
;
37 CSettingControlCreator() = default;
38 ~CSettingControlCreator() override
= default;
41 class CSettingControlCheckmark
: public ISettingControl
44 CSettingControlCheckmark()
48 ~CSettingControlCheckmark() override
= default;
50 // implementation of ISettingControl
51 std::string
GetType() const override
{ return "toggle"; }
52 bool SetFormat(const std::string
&format
) override
;
55 class CSettingControlFormattedRange
: public ISettingControl
58 ~CSettingControlFormattedRange() override
= default;
60 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
62 int GetFormatLabel() const { return m_formatLabel
; }
63 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
64 const std::string
& GetFormatString() const { return m_formatString
; }
65 void SetFormatString(const std::string
&formatString
) { m_formatString
= formatString
; }
66 int GetMinimumLabel() const { return m_minimumLabel
; }
67 void SetMinimumLabel(int minimumLabel
) { m_minimumLabel
= minimumLabel
; }
70 CSettingControlFormattedRange() = default;
72 int m_formatLabel
= -1;
73 std::string m_formatString
= "{}";
74 int m_minimumLabel
= -1;
77 class CSettingControlSpinner
: public CSettingControlFormattedRange
80 CSettingControlSpinner() = default;
81 ~CSettingControlSpinner() override
= default;
83 // implementation of ISettingControl
84 std::string
GetType() const override
{ return "spinner"; }
86 // specialization of CSettingControlFormattedRange
87 bool SetFormat(const std::string
&format
) override
;
90 class CSettingControlEdit
: public ISettingControl
97 ~CSettingControlEdit() override
= default;
99 // implementation of ISettingControl
100 std::string
GetType() const override
{ return "edit"; }
101 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
102 bool SetFormat(const std::string
&format
) override
;
104 bool IsHidden() const { return m_hidden
; }
105 void SetHidden(bool hidden
) { m_hidden
= hidden
; }
106 bool VerifyNewValue() const { return m_verifyNewValue
; }
107 void SetVerifyNewValue(bool verifyNewValue
) { m_verifyNewValue
= verifyNewValue
; }
108 int GetHeading() const { return m_heading
; }
109 void SetHeading(int heading
) { m_heading
= heading
; }
112 bool m_hidden
= false;
113 bool m_verifyNewValue
= false;
117 class CSettingControlButton
: public ISettingControl
120 CSettingControlButton() = default;
121 ~CSettingControlButton() override
= default;
123 // implementation of ISettingControl
124 std::string
GetType() const override
{ return "button"; }
125 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
126 bool SetFormat(const std::string
&format
) override
;
128 int GetHeading() const { return m_heading
; }
129 void SetHeading(int heading
) { m_heading
= heading
; }
130 bool HideValue() const { return m_hideValue
; }
131 void SetHideValue(bool hideValue
) { m_hideValue
= hideValue
; }
133 bool ShowAddonDetails() const { return m_showAddonDetails
; }
134 void SetShowAddonDetails(bool showAddonDetails
) { m_showAddonDetails
= showAddonDetails
; }
135 bool ShowInstalledAddons() const { return m_showInstalledAddons
; }
136 void SetShowInstalledAddons(bool showInstalledAddons
) { m_showInstalledAddons
= showInstalledAddons
; }
137 bool ShowInstallableAddons() const { return m_showInstallableAddons
; }
138 void SetShowInstallableAddons(bool showInstallableAddons
) { m_showInstallableAddons
= showInstallableAddons
; }
139 bool ShowMoreAddons() const { return !m_showInstallableAddons
&& m_showMoreAddons
; }
140 void SetShowMoreAddons(bool showMoreAddons
) { m_showMoreAddons
= showMoreAddons
; }
142 bool UseImageThumbs() const { return m_useImageThumbs
; }
143 void SetUseImageThumbs(bool useImageThumbs
) { m_useImageThumbs
= useImageThumbs
; }
144 bool UseFileDirectories() const { return m_useFileDirectories
; }
145 void SetUseFileDirectories(bool useFileDirectories
) { m_useFileDirectories
= useFileDirectories
; }
147 bool HasActionData() const { return !m_actionData
.empty(); }
148 const std::string
& GetActionData() const { return m_actionData
; }
149 void SetActionData(const std::string
& actionData
) { m_actionData
= actionData
; }
151 bool CloseDialog() const { return m_closeDialog
; }
152 void SetCloseDialog(bool closeDialog
) { m_closeDialog
= closeDialog
; }
156 bool m_hideValue
= false;
158 bool m_showAddonDetails
= true;
159 bool m_showInstalledAddons
= true;
160 bool m_showInstallableAddons
= false;
161 bool m_showMoreAddons
= true;
163 bool m_useImageThumbs
= false;
164 bool m_useFileDirectories
= false;
166 std::string m_actionData
;
167 bool m_closeDialog
= false;
171 using SettingControlListValueFormatter
=
172 std::string (*)(const std::shared_ptr
<const CSetting
>& setting
);
174 class CSettingControlList
: public CSettingControlFormattedRange
177 CSettingControlList() = default;
178 ~CSettingControlList() override
= default;
180 // implementation of ISettingControl
181 std::string
GetType() const override
{ return "list"; }
183 // specialization of CSettingControlFormattedRange
184 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
185 bool SetFormat(const std::string
&format
) override
;
187 int GetHeading() const { return m_heading
; }
188 void SetHeading(int heading
) { m_heading
= heading
; }
189 bool CanMultiSelect() const { return m_multiselect
; }
190 void SetMultiSelect(bool multiselect
) { m_multiselect
= multiselect
; }
191 bool HideValue() const { return m_hideValue
; }
192 void SetHideValue(bool hideValue
) { m_hideValue
= hideValue
; }
193 int GetAddButtonLabel() const { return m_addButtonLabel
; }
194 void SetAddButtonLabel(int label
) { m_addButtonLabel
= label
; }
196 SettingControlListValueFormatter
GetFormatter() const { return m_formatter
; }
197 void SetFormatter(SettingControlListValueFormatter formatter
) { m_formatter
= formatter
; }
199 bool UseDetails() const { return m_useDetails
; }
200 void SetUseDetails(bool useDetails
) { m_useDetails
= useDetails
; }
204 bool m_multiselect
= false;
205 bool m_hideValue
= false;
206 int m_addButtonLabel
= -1;
207 SettingControlListValueFormatter m_formatter
= nullptr;
208 bool m_useDetails
{false};
211 class CSettingControlSlider
;
212 using SettingControlSliderFormatter
=
213 std::string (*)(const std::shared_ptr
<const CSettingControlSlider
>& control
,
214 const CVariant
& value
,
215 const CVariant
& minimum
,
216 const CVariant
& step
,
217 const CVariant
& maximum
);
219 class CSettingControlSlider
: public ISettingControl
222 CSettingControlSlider() = default;
223 ~CSettingControlSlider() override
= default;
225 // implementation of ISettingControl
226 std::string
GetType() const override
{ return "slider"; }
227 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
228 bool SetFormat(const std::string
&format
) override
;
230 int GetHeading() const { return m_heading
; }
231 void SetHeading(int heading
) { m_heading
= heading
; }
232 bool UsePopup() const { return m_popup
; }
233 void SetPopup(bool popup
) { m_popup
= popup
; }
234 int GetFormatLabel() const { return m_formatLabel
; }
235 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
236 const std::string
& GetFormatString() const { return m_formatString
; }
237 void SetFormatString(const std::string
&formatString
) { m_formatString
= formatString
; }
238 std::string
GetDefaultFormatString() const;
240 SettingControlSliderFormatter
GetFormatter() const { return m_formatter
; }
241 void SetFormatter(SettingControlSliderFormatter formatter
) { m_formatter
= formatter
; }
245 bool m_popup
= false;
246 int m_formatLabel
= -1;
247 std::string m_formatString
;
248 SettingControlSliderFormatter m_formatter
= nullptr;
251 class CSettingControlRange
: public ISettingControl
254 CSettingControlRange() = default;
255 ~CSettingControlRange() override
= default;
257 // implementation of ISettingControl
258 std::string
GetType() const override
{ return "range"; }
259 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
260 bool SetFormat(const std::string
&format
) override
;
262 int GetFormatLabel() const { return m_formatLabel
; }
263 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
264 int GetValueFormatLabel() const { return m_valueFormatLabel
; }
265 void SetValueFormatLabel(int valueFormatLabel
) { m_valueFormatLabel
= valueFormatLabel
; }
266 const std::string
& GetValueFormat() const { return m_valueFormat
; }
267 void SetValueFormat(const std::string
&valueFormat
) { m_valueFormat
= valueFormat
; }
270 int m_formatLabel
= 21469;
271 int m_valueFormatLabel
= -1;
272 std::string m_valueFormat
= "{}";
275 class CSettingControlTitle
: public ISettingControl
278 CSettingControlTitle() = default;
279 ~CSettingControlTitle() override
= default;
281 // implementation of ISettingControl
282 std::string
GetType() const override
{ return "title"; }
283 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
285 bool IsSeparatorHidden() const { return m_separatorHidden
; }
286 void SetSeparatorHidden(bool hidden
) { m_separatorHidden
= hidden
; }
287 bool IsSeparatorBelowLabel() const { return m_separatorBelowLabel
; }
288 void SetSeparatorBelowLabel(bool below
) { m_separatorBelowLabel
= below
; }
291 bool m_separatorHidden
= false;
292 bool m_separatorBelowLabel
= true;
295 class CSettingControlLabel
: public ISettingControl
298 CSettingControlLabel();
299 ~CSettingControlLabel() override
= default;
301 // implementation of ISettingControl
302 std::string
GetType() const override
{ return "label"; }
305 class CSettingControlColorButton
: public ISettingControl
308 CSettingControlColorButton() { m_format
= "string"; }
309 ~CSettingControlColorButton() override
= default;
311 // implementation of ISettingControl
312 std::string
GetType() const override
{ return "colorbutton"; }
313 bool SetFormat(const std::string
& format
) override
;