1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "guilib/ISliderCallback.h"
#include "utils/ILocalizer.h"
#include <functional>
#include <memory>
#include <stdlib.h>
#include <string>
class CGUIControl;
class CGUIImage;
class CGUISpinControlEx;
class CGUIEditControl;
class CGUIButtonControl;
class CGUIRadioButtonControl;
class CGUISettingsSliderControl;
class CGUILabelControl;
class CGUIColorButtonControl;
class CSetting;
class CSettingControlSlider;
class CSettingString;
class CSettingPath;
class CFileItemList;
class CVariant;
class CGUIControlBaseSetting : protected ILocalizer
{
public:
CGUIControlBaseSetting(int id, std::shared_ptr<CSetting> pSetting, ILocalizer* localizer);
~CGUIControlBaseSetting() override = default;
int GetID() const { return m_id; }
std::shared_ptr<CSetting> GetSetting() { return m_pSetting; }
/*!
\brief Specifies that this setting should update after a delay
Useful for settings that have options to navigate through
and may take a while, or require additional input to update
once the final setting is chosen. Settings default to updating
instantly.
\sa IsDelayed()
*/
void SetDelayed() { m_delayed = true; }
/*!
\brief Returns whether this setting should have delayed update
\return true if the setting's update should be delayed
\sa SetDelayed()
*/
bool IsDelayed() const { return m_delayed; }
/*!
\brief Returns whether this setting is enabled or disabled
This state is independent of the real enabled state of a
setting control but represents the enabled state of the
setting itself based on specific conditions.
\return true if the setting is enabled otherwise false
\sa SetEnabled()
*/
bool IsEnabled() const;
/*!
\brief Returns whether the setting's value is valid or not
*/
bool IsValid() const { return m_valid; }
void SetValid(bool valid) { m_valid = valid; }
virtual CGUIControl* GetControl() { return NULL; }
virtual bool OnClick() { return false; }
void UpdateFromControl();
void UpdateFromSetting(bool updateDisplayOnly = false);
virtual void Clear() = 0; ///< Clears the attached control
protected:
// implementation of ILocalizer
std::string Localize(std::uint32_t code) const override;
virtual void Update(bool fromControl, bool updateDisplayOnly);
int m_id;
std::shared_ptr<CSetting> m_pSetting;
ILocalizer* m_localizer;
bool m_delayed;
bool m_valid;
};
class CGUIControlRadioButtonSetting : public CGUIControlBaseSetting
{
public:
CGUIControlRadioButtonSetting(CGUIRadioButtonControl* pRadioButton,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlRadioButtonSetting() override;
void Select(bool bSelect);
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pRadioButton); }
bool OnClick() override;
void Clear() override { m_pRadioButton = NULL; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
CGUIRadioButtonControl* m_pRadioButton;
};
class CGUIControlColorButtonSetting : public CGUIControlBaseSetting
{
public:
CGUIControlColorButtonSetting(CGUIColorButtonControl* pColorControl,
int id,
const std::shared_ptr<CSetting>& pSetting,
ILocalizer* localizer);
~CGUIControlColorButtonSetting() override;
void Select(bool bSelect);
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pColorButton); }
bool OnClick() override;
void Clear() override { m_pColorButton = nullptr; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
CGUIColorButtonControl* m_pColorButton;
};
class CGUIControlSpinExSetting : public CGUIControlBaseSetting
{
public:
CGUIControlSpinExSetting(CGUISpinControlEx* pSpin,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlSpinExSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSpin); }
bool OnClick() override;
void Clear() override { m_pSpin = NULL; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
void FillControl(bool updateDisplayOnly);
void FillIntegerSettingControl(bool updateValues);
void FillFloatSettingControl();
void FillStringSettingControl(bool updateValues);
CGUISpinControlEx* m_pSpin;
};
class CGUIControlListSetting : public CGUIControlBaseSetting
{
public:
CGUIControlListSetting(CGUIButtonControl* pButton,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlListSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
bool OnClick() override;
void Clear() override { m_pButton = NULL; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
bool GetItems(const std::shared_ptr<const CSetting>& setting,
CFileItemList& items,
bool updateItems) const;
bool GetIntegerItems(const std::shared_ptr<const CSetting>& setting,
CFileItemList& items,
bool updateItems) const;
bool GetStringItems(const std::shared_ptr<const CSetting>& setting,
CFileItemList& items,
bool updateItems) const;
CGUIButtonControl* m_pButton;
};
class CGUIControlListColorSetting : public CGUIControlBaseSetting
{
public:
CGUIControlListColorSetting(CGUIButtonControl* pButton,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlListColorSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
bool OnClick() override;
void Clear() override { m_pButton = nullptr; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
CGUIButtonControl* m_pButton;
};
class CGUIControlButtonSetting : public CGUIControlBaseSetting, protected ISliderCallback
{
public:
CGUIControlButtonSetting(CGUIButtonControl* pButton,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlButtonSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
bool OnClick() override;
void Clear() override { m_pButton = NULL; }
static bool GetPath(const std::shared_ptr<CSettingPath>& pathSetting, ILocalizer* localizer);
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
// implementations of ISliderCallback
void OnSliderChange(void* data, CGUISliderControl* slider) override;
private:
CGUIButtonControl* m_pButton;
};
class CGUIControlEditSetting : public CGUIControlBaseSetting
{
public:
CGUIControlEditSetting(CGUIEditControl* pButton,
int id,
const std::shared_ptr<CSetting>& pSetting,
ILocalizer* localizer);
~CGUIControlEditSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pEdit); }
bool OnClick() override;
void Clear() override { m_pEdit = NULL; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
static bool InputValidation(const std::string& input, void* data);
CGUIEditControl* m_pEdit;
};
class CGUIControlSliderSetting : public CGUIControlBaseSetting
{
public:
CGUIControlSliderSetting(CGUISettingsSliderControl* pSlider,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlSliderSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSlider); }
bool OnClick() override;
void Clear() override { m_pSlider = NULL; }
static std::string GetText(const std::shared_ptr<CSetting>& setting,
const CVariant& value,
const CVariant& minimum,
const CVariant& step,
const CVariant& maximum,
ILocalizer* localizer);
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
static bool FormatText(const std::string& formatString,
const CVariant& value,
const std::string& settingId,
std::string& formattedText);
CGUISettingsSliderControl* m_pSlider;
};
class CGUIControlRangeSetting : public CGUIControlBaseSetting
{
public:
CGUIControlRangeSetting(CGUISettingsSliderControl* pSlider,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlRangeSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pSlider); }
bool OnClick() override;
void Clear() override { m_pSlider = NULL; }
protected:
// specialization of CGUIControlBaseSetting
void Update(bool fromControl, bool updateDisplayOnly) override;
private:
CGUISettingsSliderControl* m_pSlider;
};
class CGUIControlSeparatorSetting : public CGUIControlBaseSetting
{
public:
CGUIControlSeparatorSetting(CGUIImage* pImage, int id, ILocalizer* localizer);
~CGUIControlSeparatorSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pImage); }
bool OnClick() override { return false; }
void Clear() override { m_pImage = NULL; }
private:
CGUIImage* m_pImage;
};
class CGUIControlGroupTitleSetting : public CGUIControlBaseSetting
{
public:
CGUIControlGroupTitleSetting(CGUILabelControl* pLabel, int id, ILocalizer* localizer);
~CGUIControlGroupTitleSetting() override;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pLabel); }
bool OnClick() override { return false; }
void Clear() override { m_pLabel = NULL; }
private:
CGUILabelControl* m_pLabel;
};
class CGUIControlLabelSetting : public CGUIControlBaseSetting
{
public:
CGUIControlLabelSetting(CGUIButtonControl* pButton,
int id,
std::shared_ptr<CSetting> pSetting,
ILocalizer* localizer);
~CGUIControlLabelSetting() override = default;
CGUIControl* GetControl() override { return reinterpret_cast<CGUIControl*>(m_pButton); }
void Clear() override { m_pButton = NULL; }
private:
CGUIButtonControl* m_pButton;
};
|