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"
31 class CSettingControlCreator
: public ISettingControlCreator
34 // implementation of ISettingControlCreator
35 std::shared_ptr
<ISettingControl
> CreateControl(const std::string
&controlType
) const override
;
38 CSettingControlCreator() = default;
39 ~CSettingControlCreator() override
= default;
42 class CSettingControlCheckmark
: public ISettingControl
45 CSettingControlCheckmark()
49 ~CSettingControlCheckmark() override
= default;
51 // implementation of ISettingControl
52 std::string
GetType() const override
{ return "toggle"; }
53 bool SetFormat(const std::string
&format
) override
;
56 class CSettingControlFormattedRange
: public ISettingControl
59 ~CSettingControlFormattedRange() override
= default;
61 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
63 int GetFormatLabel() const { return m_formatLabel
; }
64 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
65 const std::string
& GetFormatString() const { return m_formatString
; }
66 void SetFormatString(const std::string
&formatString
) { m_formatString
= formatString
; }
67 int GetMinimumLabel() const { return m_minimumLabel
; }
68 void SetMinimumLabel(int minimumLabel
) { m_minimumLabel
= minimumLabel
; }
71 CSettingControlFormattedRange() = default;
73 int m_formatLabel
= -1;
74 std::string m_formatString
= "{}";
75 int m_minimumLabel
= -1;
78 class CSettingControlSpinner
: public CSettingControlFormattedRange
81 CSettingControlSpinner() = default;
82 ~CSettingControlSpinner() override
= default;
84 // implementation of ISettingControl
85 std::string
GetType() const override
{ return "spinner"; }
87 // specialization of CSettingControlFormattedRange
88 bool SetFormat(const std::string
&format
) override
;
91 class CSettingControlEdit
: public ISettingControl
98 ~CSettingControlEdit() override
= default;
100 // implementation of ISettingControl
101 std::string
GetType() const override
{ return "edit"; }
102 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
103 bool SetFormat(const std::string
&format
) override
;
105 bool IsHidden() const { return m_hidden
; }
106 void SetHidden(bool hidden
) { m_hidden
= hidden
; }
107 bool VerifyNewValue() const { return m_verifyNewValue
; }
108 void SetVerifyNewValue(bool verifyNewValue
) { m_verifyNewValue
= verifyNewValue
; }
109 int GetHeading() const { return m_heading
; }
110 void SetHeading(int heading
) { m_heading
= heading
; }
113 bool m_hidden
= false;
114 bool m_verifyNewValue
= false;
118 class CSettingControlButton
: public ISettingControl
121 CSettingControlButton() = default;
122 ~CSettingControlButton() override
= default;
124 // implementation of ISettingControl
125 std::string
GetType() const override
{ return "button"; }
126 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
127 bool SetFormat(const std::string
&format
) override
;
129 int GetHeading() const { return m_heading
; }
130 void SetHeading(int heading
) { m_heading
= heading
; }
131 bool HideValue() const { return m_hideValue
; }
132 void SetHideValue(bool hideValue
) { m_hideValue
= hideValue
; }
134 bool ShowAddonDetails() const { return m_showAddonDetails
; }
135 void SetShowAddonDetails(bool showAddonDetails
) { m_showAddonDetails
= showAddonDetails
; }
136 bool ShowInstalledAddons() const { return m_showInstalledAddons
; }
137 void SetShowInstalledAddons(bool showInstalledAddons
) { m_showInstalledAddons
= showInstalledAddons
; }
138 bool ShowInstallableAddons() const { return m_showInstallableAddons
; }
139 void SetShowInstallableAddons(bool showInstallableAddons
) { m_showInstallableAddons
= showInstallableAddons
; }
140 bool ShowMoreAddons() const { return !m_showInstallableAddons
&& m_showMoreAddons
; }
141 void SetShowMoreAddons(bool showMoreAddons
) { m_showMoreAddons
= showMoreAddons
; }
143 bool UseImageThumbs() const { return m_useImageThumbs
; }
144 void SetUseImageThumbs(bool useImageThumbs
) { m_useImageThumbs
= useImageThumbs
; }
145 bool UseFileDirectories() const { return m_useFileDirectories
; }
146 void SetUseFileDirectories(bool useFileDirectories
) { m_useFileDirectories
= useFileDirectories
; }
148 bool HasActionData() const { return !m_actionData
.empty(); }
149 const std::string
& GetActionData() const { return m_actionData
; }
150 void SetActionData(const std::string
& actionData
) { m_actionData
= actionData
; }
152 bool CloseDialog() const { return m_closeDialog
; }
153 void SetCloseDialog(bool closeDialog
) { m_closeDialog
= closeDialog
; }
157 bool m_hideValue
= false;
159 bool m_showAddonDetails
= true;
160 bool m_showInstalledAddons
= true;
161 bool m_showInstallableAddons
= false;
162 bool m_showMoreAddons
= true;
164 bool m_useImageThumbs
= false;
165 bool m_useFileDirectories
= false;
167 std::string m_actionData
;
168 bool m_closeDialog
= false;
172 using SettingControlListValueFormatter
=
173 std::string (*)(const std::shared_ptr
<const CSetting
>& setting
);
175 class CSettingControlList
: public CSettingControlFormattedRange
178 CSettingControlList() = default;
179 ~CSettingControlList() override
= default;
181 // implementation of ISettingControl
182 std::string
GetType() const override
{ return "list"; }
184 // specialization of CSettingControlFormattedRange
185 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
186 bool SetFormat(const std::string
&format
) override
;
188 int GetHeading() const { return m_heading
; }
189 void SetHeading(int heading
) { m_heading
= heading
; }
190 bool CanMultiSelect() const { return m_multiselect
; }
191 void SetMultiSelect(bool multiselect
) { m_multiselect
= multiselect
; }
192 bool HideValue() const { return m_hideValue
; }
193 void SetHideValue(bool hideValue
) { m_hideValue
= hideValue
; }
194 int GetAddButtonLabel() const { return m_addButtonLabel
; }
195 void SetAddButtonLabel(int label
) { m_addButtonLabel
= label
; }
197 const SettingControlListValueFormatter
& GetFormatter() const { return m_formatter
; }
198 void SetFormatter(SettingControlListValueFormatter formatter
) { m_formatter
= formatter
; }
200 bool UseDetails() const { return m_useDetails
; }
201 void SetUseDetails(bool useDetails
) { m_useDetails
= useDetails
; }
205 bool m_multiselect
= false;
206 bool m_hideValue
= false;
207 int m_addButtonLabel
= -1;
208 SettingControlListValueFormatter m_formatter
= nullptr;
209 bool m_useDetails
{false};
212 class CSettingControlSlider
;
213 using SettingControlSliderFormatter
=
214 std::string (*)(const std::shared_ptr
<const CSettingControlSlider
>& control
,
215 const CVariant
& value
,
216 const CVariant
& minimum
,
217 const CVariant
& step
,
218 const CVariant
& maximum
);
220 class CSettingControlSlider
: public ISettingControl
223 CSettingControlSlider() = default;
224 ~CSettingControlSlider() override
= default;
226 // implementation of ISettingControl
227 std::string
GetType() const override
{ return "slider"; }
228 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
229 bool SetFormat(const std::string
&format
) override
;
231 int GetHeading() const { return m_heading
; }
232 void SetHeading(int heading
) { m_heading
= heading
; }
233 bool UsePopup() const { return m_popup
; }
234 void SetPopup(bool popup
) { m_popup
= popup
; }
235 int GetFormatLabel() const { return m_formatLabel
; }
236 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
237 const std::string
& GetFormatString() const { return m_formatString
; }
238 void SetFormatString(const std::string
&formatString
) { m_formatString
= formatString
; }
239 std::string
GetDefaultFormatString() const;
241 const SettingControlSliderFormatter
& GetFormatter() const { return m_formatter
; }
242 void SetFormatter(SettingControlSliderFormatter formatter
) { m_formatter
= formatter
; }
246 bool m_popup
= false;
247 int m_formatLabel
= -1;
248 std::string m_formatString
;
249 SettingControlSliderFormatter m_formatter
= nullptr;
252 class CSettingControlRange
: public ISettingControl
255 CSettingControlRange() = default;
256 ~CSettingControlRange() override
= default;
258 // implementation of ISettingControl
259 std::string
GetType() const override
{ return "range"; }
260 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
261 bool SetFormat(const std::string
&format
) override
;
263 int GetFormatLabel() const { return m_formatLabel
; }
264 void SetFormatLabel(int formatLabel
) { m_formatLabel
= formatLabel
; }
265 int GetValueFormatLabel() const { return m_valueFormatLabel
; }
266 void SetValueFormatLabel(int valueFormatLabel
) { m_valueFormatLabel
= valueFormatLabel
; }
267 const std::string
& GetValueFormat() const { return m_valueFormat
; }
268 void SetValueFormat(const std::string
&valueFormat
) { m_valueFormat
= valueFormat
; }
271 int m_formatLabel
= 21469;
272 int m_valueFormatLabel
= -1;
273 std::string m_valueFormat
= "{}";
276 class CSettingControlTitle
: public ISettingControl
279 CSettingControlTitle() = default;
280 ~CSettingControlTitle() override
= default;
282 // implementation of ISettingControl
283 std::string
GetType() const override
{ return "title"; }
284 bool Deserialize(const TiXmlNode
*node
, bool update
= false) override
;
286 bool IsSeparatorHidden() const { return m_separatorHidden
; }
287 void SetSeparatorHidden(bool hidden
) { m_separatorHidden
= hidden
; }
288 bool IsSeparatorBelowLabel() const { return m_separatorBelowLabel
; }
289 void SetSeparatorBelowLabel(bool below
) { m_separatorBelowLabel
= below
; }
292 bool m_separatorHidden
= false;
293 bool m_separatorBelowLabel
= true;
296 class CSettingControlLabel
: public ISettingControl
299 CSettingControlLabel();
300 ~CSettingControlLabel() override
= default;
302 // implementation of ISettingControl
303 std::string
GetType() const override
{ return "label"; }
306 class CSettingControlColorButton
: public ISettingControl
309 CSettingControlColorButton() { m_format
= "string"; }
310 ~CSettingControlColorButton() override
= default;
312 // implementation of ISettingControl
313 std::string
GetType() const override
{ return "colorbutton"; }
314 bool SetFormat(const std::string
& format
) override
;