xbmc
SettingControl.h
1 /*
2  * Copyright (C) 2013-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 "settings/lib/ISettingControl.h"
12 #include "settings/lib/ISettingControlCreator.h"
13 
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"
27 
28 class CVariant;
29 
31 {
32 public:
33  // implementation of ISettingControlCreator
34  std::shared_ptr<ISettingControl> CreateControl(const std::string &controlType) const override;
35 
36 protected:
37  CSettingControlCreator() = default;
38  ~CSettingControlCreator() override = default;
39 };
40 
42 {
43 public:
45  {
46  m_format = "boolean";
47  }
48  ~CSettingControlCheckmark() override = default;
49 
50  // implementation of ISettingControl
51  std::string GetType() const override { return "toggle"; }
52  bool SetFormat(const std::string &format) override;
53 };
54 
56 {
57 public:
58  ~CSettingControlFormattedRange() override = default;
59 
60  bool Deserialize(const TiXmlNode *node, bool update = false) override;
61 
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; }
68 
69 protected:
71 
72  int m_formatLabel = -1;
73  std::string m_formatString = "{}";
74  int m_minimumLabel = -1;
75 };
76 
78 {
79 public:
80  CSettingControlSpinner() = default;
81  ~CSettingControlSpinner() override = default;
82 
83  // implementation of ISettingControl
84  std::string GetType() const override { return "spinner"; }
85 
86  // specialization of CSettingControlFormattedRange
87  bool SetFormat(const std::string &format) override;
88 };
89 
91 {
92 public:
94  {
95  m_delayed = true;
96  }
97  ~CSettingControlEdit() override = default;
98 
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;
103 
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; }
110 
111 protected:
112  bool m_hidden = false;
113  bool m_verifyNewValue = false;
114  int m_heading = -1;
115 };
116 
118 {
119 public:
120  CSettingControlButton() = default;
121  ~CSettingControlButton() override = default;
122 
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;
127 
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; }
132 
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; }
141 
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; }
146 
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; }
150 
151  bool CloseDialog() const { return m_closeDialog; }
152  void SetCloseDialog(bool closeDialog) { m_closeDialog = closeDialog; }
153 
154 protected:
155  int m_heading = -1;
156  bool m_hideValue = false;
157 
158  bool m_showAddonDetails = true;
159  bool m_showInstalledAddons = true;
160  bool m_showInstallableAddons = false;
161  bool m_showMoreAddons = true;
162 
163  bool m_useImageThumbs = false;
164  bool m_useFileDirectories = false;
165 
166  std::string m_actionData;
167  bool m_closeDialog = false;
168 };
169 
170 class CSetting;
171 using SettingControlListValueFormatter =
172  std::string (*)(const std::shared_ptr<const CSetting>& setting);
173 
175 {
176 public:
177  CSettingControlList() = default;
178  ~CSettingControlList() override = default;
179 
180  // implementation of ISettingControl
181  std::string GetType() const override { return "list"; }
182 
183  // specialization of CSettingControlFormattedRange
184  bool Deserialize(const TiXmlNode *node, bool update = false) override;
185  bool SetFormat(const std::string &format) override;
186 
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; }
195 
196  SettingControlListValueFormatter GetFormatter() const { return m_formatter; }
197  void SetFormatter(SettingControlListValueFormatter formatter) { m_formatter = formatter; }
198 
199  bool UseDetails() const { return m_useDetails; }
200  void SetUseDetails(bool useDetails) { m_useDetails = useDetails; }
201 
202 protected:
203  int m_heading = -1;
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};
209 };
210 
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);
218 
220 {
221 public:
222  CSettingControlSlider() = default;
223  ~CSettingControlSlider() override = default;
224 
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;
229 
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;
239 
240  SettingControlSliderFormatter GetFormatter() const { return m_formatter; }
241  void SetFormatter(SettingControlSliderFormatter formatter) { m_formatter = formatter; }
242 
243 protected:
244  int m_heading = -1;
245  bool m_popup = false;
246  int m_formatLabel = -1;
247  std::string m_formatString;
248  SettingControlSliderFormatter m_formatter = nullptr;
249 };
250 
252 {
253 public:
254  CSettingControlRange() = default;
255  ~CSettingControlRange() override = default;
256 
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;
261 
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; }
268 
269 protected:
270  int m_formatLabel = 21469;
271  int m_valueFormatLabel = -1;
272  std::string m_valueFormat = "{}";
273 };
274 
276 {
277 public:
278  CSettingControlTitle() = default;
279  ~CSettingControlTitle() override = default;
280 
281  // implementation of ISettingControl
282  std::string GetType() const override { return "title"; }
283  bool Deserialize(const TiXmlNode *node, bool update = false) override;
284 
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; }
289 
290 protected:
291  bool m_separatorHidden = false;
292  bool m_separatorBelowLabel = true;
293 };
294 
296 {
297 public:
299  ~CSettingControlLabel() override = default;
300 
301  // implementation of ISettingControl
302  std::string GetType() const override { return "label"; }
303 };
304 
306 {
307 public:
308  CSettingControlColorButton() { m_format = "string"; }
309  ~CSettingControlColorButton() override = default;
310 
311  // implementation of ISettingControl
312  std::string GetType() const override { return "colorbutton"; }
313  bool SetFormat(const std::string& format) override;
314 };
Definition: SettingControl.h:305
Definition: SettingControl.h:77
Definition: SettingControl.h:41
Definition: SettingControl.h:30
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Definition: SettingControl.h:55
Interface for creating a new setting control of a custom setting control type.
Definition: ISettingControlCreator.h:20
Definition: Variant.h:29
Definition: SettingControl.h:295
Definition: SettingControl.h:251
Definition: SettingControl.h:117
Definition: SettingControl.h:90
Definition: SettingControl.h:219
Definition: SettingControl.h:174
std::shared_ptr< ISettingControl > CreateControl(const std::string &controlType) const override
Creates a new setting control of the given custom setting control type.
Definition: SettingControl.cpp:23
Definition: SettingControl.h:275
Definition: ISettingControl.h:17