2 * Copyright (C) 2005-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 "guilib/ISliderCallback.h"
12 #include "utils/ILocalizer.h"
21 class CGUISpinControlEx
;
22 class CGUIEditControl
;
23 class CGUIButtonControl
;
24 class CGUIRadioButtonControl
;
25 class CGUISettingsSliderControl
;
26 class CGUILabelControl
;
27 class CGUIColorButtonControl
;
30 class CSettingControlSlider
;
37 class CGUIControlBaseSetting
: protected ILocalizer
40 CGUIControlBaseSetting(int id
, std::shared_ptr
<CSetting
> pSetting
, ILocalizer
* localizer
);
41 ~CGUIControlBaseSetting() override
= default;
43 int GetID() const { return m_id
; }
44 std::shared_ptr
<CSetting
> GetSetting() { return m_pSetting
; }
47 \brief Specifies that this setting should update after a delay
48 Useful for settings that have options to navigate through
49 and may take a while, or require additional input to update
50 once the final setting is chosen. Settings default to updating
54 void SetDelayed() { m_delayed
= true; }
57 \brief Returns whether this setting should have delayed update
58 \return true if the setting's update should be delayed
61 bool IsDelayed() const { return m_delayed
; }
64 \brief Returns whether this setting is enabled or disabled
65 This state is independent of the real enabled state of a
66 setting control but represents the enabled state of the
67 setting itself based on specific conditions.
68 \return true if the setting is enabled otherwise false
71 bool IsEnabled() const;
74 \brief Returns whether the setting's value is valid or not
76 bool IsValid() const { return m_valid
; }
78 void SetValid(bool valid
) { m_valid
= valid
; }
80 virtual CGUIControl
* GetControl() { return NULL
; }
81 virtual bool OnClick() { return false; }
82 void UpdateFromControl();
83 void UpdateFromSetting(bool updateDisplayOnly
= false);
84 virtual void Clear() = 0; ///< Clears the attached control
86 // implementation of ILocalizer
87 std::string
Localize(std::uint32_t code
) const override
;
89 virtual void Update(bool fromControl
, bool updateDisplayOnly
);
92 std::shared_ptr
<CSetting
> m_pSetting
;
93 ILocalizer
* m_localizer
;
94 bool m_delayed
= false;
98 class CGUIControlRadioButtonSetting
: public CGUIControlBaseSetting
101 CGUIControlRadioButtonSetting(CGUIRadioButtonControl
* pRadioButton
,
103 std::shared_ptr
<CSetting
> pSetting
,
104 ILocalizer
* localizer
);
105 ~CGUIControlRadioButtonSetting() override
;
107 void Select(bool bSelect
);
109 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pRadioButton
); }
110 bool OnClick() override
;
111 void Clear() override
{ m_pRadioButton
= NULL
; }
114 // specialization of CGUIControlBaseSetting
115 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
118 CGUIRadioButtonControl
* m_pRadioButton
;
121 class CGUIControlColorButtonSetting
: public CGUIControlBaseSetting
124 CGUIControlColorButtonSetting(CGUIColorButtonControl
* pColorControl
,
126 const std::shared_ptr
<CSetting
>& pSetting
,
127 ILocalizer
* localizer
);
128 ~CGUIControlColorButtonSetting() override
;
130 void Select(bool bSelect
);
132 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pColorButton
); }
133 bool OnClick() override
;
134 void Clear() override
{ m_pColorButton
= nullptr; }
137 // specialization of CGUIControlBaseSetting
138 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
141 CGUIColorButtonControl
* m_pColorButton
;
144 class CGUIControlSpinExSetting
: public CGUIControlBaseSetting
147 CGUIControlSpinExSetting(CGUISpinControlEx
* pSpin
,
149 std::shared_ptr
<CSetting
> pSetting
,
150 ILocalizer
* localizer
);
151 ~CGUIControlSpinExSetting() override
;
153 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pSpin
); }
154 bool OnClick() override
;
155 void Clear() override
{ m_pSpin
= NULL
; }
158 // specialization of CGUIControlBaseSetting
159 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
162 void FillControl(bool updateDisplayOnly
);
163 void FillIntegerSettingControl(bool updateValues
);
164 void FillFloatSettingControl();
165 void FillStringSettingControl(bool updateValues
);
166 CGUISpinControlEx
* m_pSpin
;
169 class CGUIControlListSetting
: public CGUIControlBaseSetting
172 CGUIControlListSetting(CGUIButtonControl
* pButton
,
174 std::shared_ptr
<CSetting
> pSetting
,
175 ILocalizer
* localizer
);
176 ~CGUIControlListSetting() override
;
178 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pButton
); }
179 bool OnClick() override
;
180 void Clear() override
{ m_pButton
= NULL
; }
183 // specialization of CGUIControlBaseSetting
184 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
187 bool GetItems(const std::shared_ptr
<const CSetting
>& setting
,
188 CFileItemList
& items
,
189 bool updateItems
) const;
190 bool GetIntegerItems(const std::shared_ptr
<const CSetting
>& setting
,
191 CFileItemList
& items
,
192 bool updateItems
) const;
193 bool GetStringItems(const std::shared_ptr
<const CSetting
>& setting
,
194 CFileItemList
& items
,
195 bool updateItems
) const;
197 CGUIButtonControl
* m_pButton
;
200 class CGUIControlListColorSetting
: public CGUIControlBaseSetting
203 CGUIControlListColorSetting(CGUIButtonControl
* pButton
,
205 std::shared_ptr
<CSetting
> pSetting
,
206 ILocalizer
* localizer
);
207 ~CGUIControlListColorSetting() override
;
209 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pButton
); }
210 bool OnClick() override
;
211 void Clear() override
{ m_pButton
= nullptr; }
214 // specialization of CGUIControlBaseSetting
215 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
218 CGUIButtonControl
* m_pButton
;
221 class CGUIControlButtonSetting
: public CGUIControlBaseSetting
, protected ISliderCallback
224 CGUIControlButtonSetting(CGUIButtonControl
* pButton
,
226 std::shared_ptr
<CSetting
> pSetting
,
227 ILocalizer
* localizer
);
228 ~CGUIControlButtonSetting() override
;
230 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pButton
); }
231 bool OnClick() override
;
232 void Clear() override
{ m_pButton
= NULL
; }
234 static bool GetPath(const std::shared_ptr
<CSettingPath
>& pathSetting
, ILocalizer
* localizer
);
237 // specialization of CGUIControlBaseSetting
238 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
240 // implementations of ISliderCallback
241 void OnSliderChange(void* data
, CGUISliderControl
* slider
) override
;
244 CGUIButtonControl
* m_pButton
;
247 class CGUIControlEditSetting
: public CGUIControlBaseSetting
250 CGUIControlEditSetting(CGUIEditControl
* pButton
,
252 const std::shared_ptr
<CSetting
>& pSetting
,
253 ILocalizer
* localizer
);
254 ~CGUIControlEditSetting() override
;
256 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pEdit
); }
257 bool OnClick() override
;
258 void Clear() override
{ m_pEdit
= NULL
; }
261 // specialization of CGUIControlBaseSetting
262 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
265 static bool InputValidation(const std::string
& input
, void* data
);
267 CGUIEditControl
* m_pEdit
;
270 class CGUIControlSliderSetting
: public CGUIControlBaseSetting
273 CGUIControlSliderSetting(CGUISettingsSliderControl
* pSlider
,
275 std::shared_ptr
<CSetting
> pSetting
,
276 ILocalizer
* localizer
);
277 ~CGUIControlSliderSetting() override
;
279 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pSlider
); }
280 bool OnClick() override
;
281 void Clear() override
{ m_pSlider
= NULL
; }
283 static std::string
GetText(const std::shared_ptr
<CSetting
>& setting
,
284 const CVariant
& value
,
285 const CVariant
& minimum
,
286 const CVariant
& step
,
287 const CVariant
& maximum
,
288 ILocalizer
* localizer
);
291 // specialization of CGUIControlBaseSetting
292 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
295 static bool FormatText(const std::string
& formatString
,
296 const CVariant
& value
,
297 const std::string
& settingId
,
298 std::string
& formattedText
);
300 CGUISettingsSliderControl
* m_pSlider
;
303 class CGUIControlRangeSetting
: public CGUIControlBaseSetting
306 CGUIControlRangeSetting(CGUISettingsSliderControl
* pSlider
,
308 std::shared_ptr
<CSetting
> pSetting
,
309 ILocalizer
* localizer
);
310 ~CGUIControlRangeSetting() override
;
312 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pSlider
); }
313 bool OnClick() override
;
314 void Clear() override
{ m_pSlider
= NULL
; }
317 // specialization of CGUIControlBaseSetting
318 void Update(bool fromControl
, bool updateDisplayOnly
) override
;
321 CGUISettingsSliderControl
* m_pSlider
;
324 class CGUIControlSeparatorSetting
: public CGUIControlBaseSetting
327 CGUIControlSeparatorSetting(CGUIImage
* pImage
, int id
, ILocalizer
* localizer
);
328 ~CGUIControlSeparatorSetting() override
;
330 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pImage
); }
331 bool OnClick() override
{ return false; }
332 void Clear() override
{ m_pImage
= NULL
; }
338 class CGUIControlGroupTitleSetting
: public CGUIControlBaseSetting
341 CGUIControlGroupTitleSetting(CGUILabelControl
* pLabel
, int id
, ILocalizer
* localizer
);
342 ~CGUIControlGroupTitleSetting() override
;
344 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pLabel
); }
345 bool OnClick() override
{ return false; }
346 void Clear() override
{ m_pLabel
= NULL
; }
349 CGUILabelControl
* m_pLabel
;
352 class CGUIControlLabelSetting
: public CGUIControlBaseSetting
355 CGUIControlLabelSetting(CGUIButtonControl
* pButton
,
357 std::shared_ptr
<CSetting
> pSetting
,
358 ILocalizer
* localizer
);
359 ~CGUIControlLabelSetting() override
= default;
361 CGUIControl
* GetControl() override
{ return reinterpret_cast<CGUIControl
*>(m_pButton
); }
362 void Clear() override
{ m_pButton
= NULL
; }
365 CGUIButtonControl
* m_pButton
;