kodi
GUIControlSettings.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "guilib/ISliderCallback.h"
12 #include "utils/ILocalizer.h"
13 
14 #include <functional>
15 #include <memory>
16 #include <stdlib.h>
17 #include <string>
18 
19 class CGUIControl;
20 class CGUIImage;
21 class CGUISpinControlEx;
22 class CGUIEditControl;
23 class CGUIButtonControl;
26 class CGUILabelControl;
28 
29 class CSetting;
31 class CSettingString;
32 class CSettingPath;
33 
34 class CFileItemList;
35 class CVariant;
36 
38 {
39 public:
40  CGUIControlBaseSetting(int id, std::shared_ptr<CSetting> pSetting, ILocalizer* localizer);
41  ~CGUIControlBaseSetting() override = default;
42 
43  int GetID() const { return m_id; }
44  std::shared_ptr<CSetting> GetSetting() { return m_pSetting; }
45 
54  void SetDelayed() { m_delayed = true; }
55 
61  bool IsDelayed() const { return m_delayed; }
62 
71  bool IsEnabled() const;
72 
76  bool IsValid() const { return m_valid; }
77 
78  void SetValid(bool valid) { m_valid = valid; }
79 
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;
85 protected:
86  // implementation of ILocalizer
87  std::string Localize(std::uint32_t code) const override;
88 
89  virtual void Update(bool fromControl, bool updateDisplayOnly);
90 
91  int m_id;
92  std::shared_ptr<CSetting> m_pSetting;
93  ILocalizer* m_localizer;
94  bool m_delayed = false;
95  bool m_valid = true;
96 };
97 
99 {
100 public:
102  int id,
103  std::shared_ptr<CSetting> pSetting,
104  ILocalizer* localizer);
105  ~CGUIControlRadioButtonSetting() override;
106 
107  void Select(bool bSelect);
108 
109  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pRadioButton); }
110  bool OnClick() override;
111  void Clear() override { m_pRadioButton = NULL; }
112 
113 protected:
114  // specialization of CGUIControlBaseSetting
115  void Update(bool fromControl, bool updateDisplayOnly) override;
116 
117 private:
118  CGUIRadioButtonControl* m_pRadioButton;
119 };
120 
122 {
123 public:
125  int id,
126  const std::shared_ptr<CSetting>& pSetting,
127  ILocalizer* localizer);
128  ~CGUIControlColorButtonSetting() override;
129 
130  void Select(bool bSelect);
131 
132  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pColorButton); }
133  bool OnClick() override;
134  void Clear() override { m_pColorButton = nullptr; }
135 
136 protected:
137  // specialization of CGUIControlBaseSetting
138  void Update(bool fromControl, bool updateDisplayOnly) override;
139 
140 private:
141  CGUIColorButtonControl* m_pColorButton;
142 };
143 
145 {
146 public:
148  int id,
149  std::shared_ptr<CSetting> pSetting,
150  ILocalizer* localizer);
151  ~CGUIControlSpinExSetting() override;
152 
153  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSpin); }
154  bool OnClick() override;
155  void Clear() override { m_pSpin = NULL; }
156 
157 protected:
158  // specialization of CGUIControlBaseSetting
159  void Update(bool fromControl, bool updateDisplayOnly) override;
160 
161 private:
162  void FillControl(bool updateDisplayOnly);
163  void FillIntegerSettingControl(bool updateValues);
164  void FillFloatSettingControl();
165  void FillStringSettingControl(bool updateValues);
166  CGUISpinControlEx* m_pSpin;
167 };
168 
170 {
171 public:
173  int id,
174  std::shared_ptr<CSetting> pSetting,
175  ILocalizer* localizer);
176  ~CGUIControlListSetting() override;
177 
178  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
179  bool OnClick() override;
180  void Clear() override { m_pButton = NULL; }
181 
182 protected:
183  // specialization of CGUIControlBaseSetting
184  void Update(bool fromControl, bool updateDisplayOnly) override;
185 
186 private:
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;
196 
197  CGUIButtonControl* m_pButton;
198 };
199 
201 {
202 public:
204  int id,
205  std::shared_ptr<CSetting> pSetting,
206  ILocalizer* localizer);
207  ~CGUIControlListColorSetting() override;
208 
209  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
210  bool OnClick() override;
211  void Clear() override { m_pButton = nullptr; }
212 
213 protected:
214  // specialization of CGUIControlBaseSetting
215  void Update(bool fromControl, bool updateDisplayOnly) override;
216 
217 private:
218  CGUIButtonControl* m_pButton;
219 };
220 
222 {
223 public:
225  int id,
226  std::shared_ptr<CSetting> pSetting,
227  ILocalizer* localizer);
228  ~CGUIControlButtonSetting() override;
229 
230  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
231  bool OnClick() override;
232  void Clear() override { m_pButton = NULL; }
233 
234  static bool GetPath(const std::shared_ptr<CSettingPath>& pathSetting, ILocalizer* localizer);
235 
236 protected:
237  // specialization of CGUIControlBaseSetting
238  void Update(bool fromControl, bool updateDisplayOnly) override;
239 
240  // implementations of ISliderCallback
241  void OnSliderChange(void* data, CGUISliderControl* slider) override;
242 
243 private:
244  CGUIButtonControl* m_pButton;
245 };
246 
248 {
249 public:
251  int id,
252  const std::shared_ptr<CSetting>& pSetting,
253  ILocalizer* localizer);
254  ~CGUIControlEditSetting() override;
255 
256  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pEdit); }
257  bool OnClick() override;
258  void Clear() override { m_pEdit = NULL; }
259 
260 protected:
261  // specialization of CGUIControlBaseSetting
262  void Update(bool fromControl, bool updateDisplayOnly) override;
263 
264 private:
265  static bool InputValidation(const std::string& input, void* data);
266 
267  CGUIEditControl* m_pEdit;
268 };
269 
271 {
272 public:
274  int id,
275  std::shared_ptr<CSetting> pSetting,
276  ILocalizer* localizer);
277  ~CGUIControlSliderSetting() override;
278 
279  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSlider); }
280  bool OnClick() override;
281  void Clear() override { m_pSlider = NULL; }
282 
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);
289 
290 protected:
291  // specialization of CGUIControlBaseSetting
292  void Update(bool fromControl, bool updateDisplayOnly) override;
293 
294 private:
295  static bool FormatText(const std::string& formatString,
296  const CVariant& value,
297  const std::string& settingId,
298  std::string& formattedText);
299 
300  CGUISettingsSliderControl* m_pSlider;
301 };
302 
304 {
305 public:
307  int id,
308  std::shared_ptr<CSetting> pSetting,
309  ILocalizer* localizer);
310  ~CGUIControlRangeSetting() override;
311 
312  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSlider); }
313  bool OnClick() override;
314  void Clear() override { m_pSlider = NULL; }
315 
316 protected:
317  // specialization of CGUIControlBaseSetting
318  void Update(bool fromControl, bool updateDisplayOnly) override;
319 
320 private:
321  CGUISettingsSliderControl* m_pSlider;
322 };
323 
325 {
326 public:
327  CGUIControlSeparatorSetting(CGUIImage* pImage, int id, ILocalizer* localizer);
328  ~CGUIControlSeparatorSetting() override;
329 
330  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pImage); }
331  bool OnClick() override { return false; }
332  void Clear() override { m_pImage = NULL; }
333 
334 private:
335  CGUIImage* m_pImage;
336 };
337 
339 {
340 public:
341  CGUIControlGroupTitleSetting(CGUILabelControl* pLabel, int id, ILocalizer* localizer);
342  ~CGUIControlGroupTitleSetting() override;
343 
344  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pLabel); }
345  bool OnClick() override { return false; }
346  void Clear() override { m_pLabel = NULL; }
347 
348 private:
349  CGUILabelControl* m_pLabel;
350 };
351 
353 {
354 public:
356  int id,
357  std::shared_ptr<CSetting> pSetting,
358  ILocalizer* localizer);
359  ~CGUIControlLabelSetting() override = default;
360 
361  CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
362  void Clear() override { m_pButton = NULL; }
363 
364 private:
365  CGUIButtonControl* m_pButton;
366 };
Definition: GUIControlSettings.h:37
Interface class for callback from the slider dialog.
Definition: ISliderCallback.h:24
Definition: GUIControlSettings.h:169
Definition: GUIEditControl.h:26
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:258
Definition: GUIControlSettings.h:338
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:180
Definition: GUIButtonControl.h:27
Definition: GUIControlSettings.h:270
Definition: GUIControlSettings.h:200
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:332
Represents a list of files.
Definition: FileItem.h:702
virtual void Clear()=0
Clears the attached control.
bool IsValid() const
Returns whether the setting&#39;s value is valid or not.
Definition: GUIControlSettings.h:76
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:134
Base class for controls.
Definition: GUIControl.h:83
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
String setting implementation.
Definition: Setting.h:423
Definition: GUISettingsSliderControl.h:23
Definition: GUIControlSettings.h:247
Definition: Variant.h:31
Definition: GUIControlSettings.h:303
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:111
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:155
Definition: GUILabelControl.h:24
Definition: GUIControlSettings.h:352
Definition: ILocalizer.h:14
Definition: GUIColorButtonControl.h:24
Definition: GUIControlSettings.h:98
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:211
bool IsEnabled() const
Returns whether this setting is enabled or disabled This state is independent of the real enabled sta...
Definition: GUIControlSettings.cpp:301
Definition: inftrees.h:24
Definition: GUIImage.h:27
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:346
Definition: SettingPath.h:17
Definition: GUISliderControl.h:37
Definition: GUISpinControlEx.h:23
Definition: SettingControl.h:219
Definition: GUIControlSettings.h:144
bool IsDelayed() const
Returns whether this setting should have delayed update.
Definition: GUIControlSettings.h:61
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:281
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:362
Definition: GUIRadioButtonControl.h:22
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:314
Definition: GUIControlSettings.h:324
Definition: GUIControlSettings.h:121
Definition: GUIControlSettings.h:221
void SetDelayed()
Specifies that this setting should update after a delay Useful for settings that have options to navi...
Definition: GUIControlSettings.h:54
void Clear() override
Clears the attached control.
Definition: GUIControlSettings.h:232