MythTV master
standardsettings.h
Go to the documentation of this file.
1#ifndef STANDARDSETTINGS_H_
2#define STANDARDSETTINGS_H_
3
4#include <initializer_list>
5#include <utility>
6
7#include <QMap>
8#include <QObject>
9
10#include "libmythui/mythuiexp.h"
14
15class StandardSetting;
16
18{
19 Q_OBJECT
20
21 public:
22 MythUIButtonListItemSetting (MythUIButtonList *lbtype, const QString &text)
23 : MythUIButtonListItem(lbtype, text) {}
24
25 public slots:
26 void ShouldUpdate(StandardSetting *setting);
27};
28
29class MUI_PUBLIC StandardSetting : public QObject, public StorageUser
30{
31 Q_OBJECT
32
33 public:
34 virtual void setLabel(QString str) { m_label = std::move(str); }
35 QString getLabel(void) const { return m_label; }
36
37 virtual void setHelpText(const QString &str) { m_helptext = str; emit helpTextChanged(m_helptext); }
38 QString getHelpText(void) const { return m_helptext; }
39
40 virtual void setName(const QString &name);
41 QString getName(void) const { return m_name; }
42 StandardSetting * byName(const QString &name);
43
44 bool isVisible(void) const { return m_visible; }
45 bool isEnabled() const { return m_enabled; }
46 bool isReadOnly() const { return m_readonly; }
47 bool haveChanged();
48 void setChanged(bool changed);
49 StandardSetting *getParent() const {return m_parent;}
50
51 // Gets
52 virtual QString getValue(void) const {return m_settingValue;}
53
54 virtual void updateButton(MythUIButtonListItem *item);
55
56 // StorageUser
57 void SetDBValue(const QString &val) override { setValue(val); } // StorageUser
58 QString GetDBValue(void) const override { return getValue(); } // StorageUser
59
60 MythUIButtonListItem *createButton(MythUIButtonList *list);
61
62 //subsettings
63 virtual void addChild(StandardSetting *child);
64 virtual void removeChild(StandardSetting *child);
65 virtual QList<StandardSetting *> *getSubSettings();
66 virtual bool haveSubSettings();
67 virtual void clearSettings();
68 void clearTargetedSettings(const QString &value);
69
70 virtual void edit(MythScreenType *screen) = 0;
71 virtual void resultEdit(DialogCompletionEvent *dce) = 0;
72
73 virtual void Load(void);
74 virtual void Save(void);
75
76 virtual void Open(void) {}
77 virtual void Close(void) {}
78
79 Storage *GetStorage(void) const { return m_storage; }
80
81 void addTargetedChild(const QString &value, StandardSetting *setting);
82 void addTargetedChildren(const QString &value,
83 std::initializer_list<StandardSetting *> settings);
84 void removeTargetedChild(const QString &value, StandardSetting *child);
85
86 virtual bool keyPressEvent(QKeyEvent *event);
87
88 void MoveToThread(QThread *thread);
89
90 public slots:
91 virtual void setEnabled(bool enabled);
92 virtual void setReadOnly(bool readonly);
93 void setVisible(bool visible);
94 virtual void setValue(const QString &newValue);
95 virtual void setValue(int newValue);
96 virtual void childChanged(StandardSetting */*child*/) {}
97
98 signals:
99 void valueChanged(const QString &newValue);
102 void settingsChanged(StandardSetting *selectedSetting = nullptr);
104 void helpTextChanged(const QString &newValue);
105
106 protected:
107 explicit StandardSetting(Storage *_storage = nullptr)
108 : m_storage(_storage) {}
109 ~StandardSetting() override;
110 void setParent(StandardSetting *parent);
112 bool m_enabled {true};
113 bool m_readonly {false};
114 QString m_label;
115 QString m_helptext;
116 QString m_name;
117 bool m_visible {true};
118
119 private:
120 bool m_haveChanged {false};
121 Storage *m_storage {nullptr};
122 StandardSetting *m_parent {nullptr};
123 QList<StandardSetting *> m_children;
124 QMap<QString, QList<StandardSetting *> > m_targets;
125};
126
128{
129 public:
130 AutoIncrementSetting(QString _table, QString _column);
131
132 void Save(void) override; // StandardSetting
133 void edit(MythScreenType * /*screen*/) override { } // StandardSetting
134 void resultEdit(DialogCompletionEvent * /*dce*/) override { } // StandardSetting
135
136 protected:
137 QString m_table;
138 QString m_column;
139};
140
141/*******************************************************************************
142* TextEdit Setting *
143*******************************************************************************/
144
145
147{
148 public:
149 void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
150 void edit(MythScreenType *screen) override; // StandardSetting
151 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
152 void SetPasswordEcho(bool b);
153
154 protected:
155 explicit MythUITextEditSetting(Storage *_storage = nullptr)
156 : StandardSetting(_storage) {}
157 bool m_passwordEcho {false};
158};
159
160
162{
163 public:
165};
166
167
169{
170 public:
171 explicit HostTextEditSetting(const QString &name) :
172 MythUITextEditSetting(new HostDBStorage(this, name)) { }
173
175 {
176 delete GetStorage();
177 }
178};
179
181{
182 public:
183 explicit GlobalTextEditSetting(const QString &name) :
184 MythUITextEditSetting(new GlobalDBStorage(this, name)) { }
185
187 {
188 delete GetStorage();
189 }
190};
191
192/*******************************************************************************
193* Directory Setting *
194*******************************************************************************/
195
196
198{
199 public:
200 void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
201 void edit(MythScreenType *screen) override; // StandardSetting
202 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
203 void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; };
204 void SetNameFilter(QStringList filter) { m_nameFilter = std::move(filter); };
205
206 protected:
208 : StandardSetting(_storage) {}
209 QDir::Filters m_typeFilter {QDir::AllDirs | QDir::Drives |
210 QDir::Files | QDir::Readable |
211 QDir::Writable | QDir::Executable};
212 QStringList m_nameFilter {"*"};
213};
214
215
217{
218 public:
219 explicit HostFileBrowserSetting(const QString &name) :
220 MythUIFileBrowserSetting(new HostDBStorage(this, name)) { }
221
223 {
224 delete GetStorage();
225 }
226};
227
228
229/*******************************************************************************
230* ComboBox Setting *
231*******************************************************************************/
232//TODO implement rw=true
234{
235 Q_OBJECT
236 public:
237 void setValue(int value) override; // StandardSetting
238 int getValueIndex(const QString &value) const;
239 QString getValueLabel(void) const;
240 void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
241 void edit(MythScreenType *screen) override; // StandardSetting
242 void addSelection(const QString &label, QString value = QString(),
243 bool select = false);
244 void clearSelections();
245 void fillSelectionsFromDir(const QDir &dir, bool absPath = true);
246 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
247 virtual int size(void) const;
248
249 public slots:
250 void setValue(const QString &newValue) override; // StandardSetting
251
252 protected:
260 explicit MythUIComboBoxSetting(Storage *_storage = nullptr, bool rw = false)
261 : StandardSetting(_storage), m_rewrite(rw) {}
262 ~MythUIComboBoxSetting() override;
263 QVector<QString> m_labels;
264 QVector<QString> m_values;
265
266 private:
268 bool m_isSet {false};
269
270};
271
273{
274 public:
275 explicit HostComboBoxSetting(const QString &name, bool rw = false) :
276 MythUIComboBoxSetting(new HostDBStorage(this, name), rw) { }
277
279 {
280 delete GetStorage();
281 }
282};
283
284
286{
287 public:
288 explicit GlobalComboBoxSetting(const QString &name, bool rw = false) :
289 MythUIComboBoxSetting(new GlobalDBStorage(this, name), rw) { }
290
292 {
293 delete GetStorage();
294 }
295};
296
298{
299 public:
300 explicit TransMythUIComboBoxSetting(bool rw = false) :
301 MythUIComboBoxSetting(nullptr, rw) { }
302};
303
305{
306 public:
307 explicit HostTimeBoxSetting(const QString &name,
308 const QString &defaultTime = "00:00",
309 const int interval = 1) :
311 {
312 for (int hour = 0; hour < 24; hour++)
313 {
314 for (int minute = 0; minute < 60; minute += interval)
315 {
316 QString timeStr = QString("%1:%2")
317 .arg(hour, 2,10,QChar('0'))
318 .arg(minute,2,10,QChar('0'));
319 addSelection(timeStr, timeStr,
320 timeStr == defaultTime);
321 }
322 }
323 }
324};
325
327{
328 public:
329 explicit GlobalTimeBoxSetting(const QString &name,
330 const QString &defaultTime = "00:00",
331 const int interval = 1) :
333 {
334 for (int hour = 0; hour < 24; hour++)
335 {
336 for (int minute = 0; minute < 60; minute += interval)
337 {
338 QString timeStr = QString("%1:%2")
339 .arg(hour, 2,10,QChar('0'))
340 .arg(minute,2,10,QChar('0'));
341 addSelection(timeStr, timeStr,
342 timeStr == defaultTime);
343 }
344 }
345 }
346};
347
348/*******************************************************************************
349* SpinBox Setting *
350*******************************************************************************/
351
352
354{
355 public:
356 //void setValue(int value);
357 int intValue();
358 void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
359 void edit(MythScreenType *screen) override; // StandardSetting
360 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
361
362 protected:
363 // MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
364 // bool allow_single_step = false,
365 // const QString &special_value_text = QString());
366
367 MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
368 int pageMultiple = 8,
369 QString special_value_text = QString());
370 private:
371 int m_min;
372 int m_max;
376};
377
379{
380 public:
381 TransMythUISpinBoxSetting(int min, int max, int step,
382 int pageMultiple = 5,
383 const QString &special_value_text = QString()) :
384 MythUISpinBoxSetting(nullptr, min, max, step, pageMultiple,
385 special_value_text)
386 { }
387};
388
390{
391 public:
392 HostSpinBoxSetting(const QString &name, int min, int max, int step,
393 int pageMultiple = 8,
394 const QString &special_value_text = QString()) :
395 MythUISpinBoxSetting(new HostDBStorage(this, name), min, max, step,
396 pageMultiple, special_value_text)
397 { }
398
400 {
401 delete GetStorage();
402 }
403};
404
406{
407 public:
408 GlobalSpinBoxSetting(const QString &name, int min, int max, int step,
409 int pageMultiple = 8,
410 const QString &special_value_text = QString()) :
411 MythUISpinBoxSetting(new GlobalDBStorage(this, name), min, max, step,
412 pageMultiple, special_value_text)
413 { }
414
416 {
417 delete GetStorage();
418 }
419};
420
421/*******************************************************************************
422* CheckBox Setting *
423*******************************************************************************/
424
426{
427 Q_OBJECT
428
429 public:
430 void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
431 void edit(MythScreenType *screen) override; // StandardSetting
432 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
433 void setValue(const QString &newValue) override; // StandardSetting
434 virtual void setValue(bool value);
436 bool boolValue() { return m_settingValue == "1"; }
437
438 signals:
439 void valueChanged(bool);
440
441 protected:
442 explicit MythUICheckBoxSetting(Storage *_storage = nullptr);
443
444};
445
447{
448 public:
450};
451
453{
454 public:
455 explicit HostCheckBoxSetting(const QString &name) :
456 MythUICheckBoxSetting(new HostDBStorage(this, name)) { }
457
459 {
460 delete GetStorage();
461 }
462};
463
465{
466 public:
467 explicit GlobalCheckBoxSetting(const QString &name) :
468 MythUICheckBoxSetting(new GlobalDBStorage(this, name)) { }
469
471 {
472 delete GetStorage();
473 }
474};
475
476/*******************************************************************************
477* Group Setting *
478*******************************************************************************/
479
481{
482 Q_OBJECT
483
484 public:
485 GroupSetting() = default;
486
487 void edit(MythScreenType *screen) override; // StandardSetting
488 void resultEdit(DialogCompletionEvent */*dce*/) override {} // StandardSetting
489 virtual void applyChange() {}
490 void updateButton(MythUIButtonListItem *item) override; // StandardSetting
491 virtual bool canDelete(void) {return false;}
492 virtual void deleteEntry(void) {}
493};
494
496{
497 Q_OBJECT
498
499 public:
500 explicit ButtonStandardSetting(const QString &label);
501
502 void edit(MythScreenType *screen) override; // StandardSetting
503 void resultEdit(DialogCompletionEvent */*dce*/) override {}; // StandardSetting
504
505 signals:
506 void clicked();
507};
508
509/*******************************************************************************
510* Standard Dialog Setting *
511*******************************************************************************/
512
514{
515 Q_OBJECT
516
517 public:
518
519 StandardSettingDialog(MythScreenStack *parent, const char *name,
520 GroupSetting *groupSettings = nullptr)
521 : MythScreenType(parent, name), m_settingsTree(groupSettings) {}
522 ~StandardSettingDialog() override;
523 bool Create(void) override; // MythScreenType
524 void customEvent(QEvent *event) override; // MythUIType
525 bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
526 void ShowMenu(void) override; // MythScreenType
527 void deleteEntry(void);
528
529 public slots:
530 void Close(void) override; // MythScreenType
531 void updateSettings(StandardSetting *selectedSetting = nullptr);
532 void editEntry(void);
533 void deleteSelected(void);
534 void deleteEntryConfirmed(bool ok);
535
536 protected:
537 void Load(void) override; // MythScreenType
538 void Init(void) override; // MythScreenType
539 GroupSetting *GetGroupSettings(void) const;
540 MythUIButtonList *m_buttonList {nullptr};
541
542 private slots:
543 void settingSelected(MythUIButtonListItem *item);
544 void settingClicked(MythUIButtonListItem *item);
545
546 private:
547 void LevelUp();
548 void LevelDown();
549 void setCurrentGroupSetting(StandardSetting *groupSettings,
550 StandardSetting *selectedSetting = nullptr);
551 void Save();
552
553 MythUIText *m_title {nullptr};
554 MythUIText *m_groupHelp {nullptr};
555 MythUIText *m_selectedSettingHelp {nullptr};
556 MythDialogBox *m_menuPopup {nullptr};
557 GroupSetting *m_settingsTree {nullptr};
558 StandardSetting *m_currentGroupSetting {nullptr};
559 bool m_loaded {false};
560};
561
563
564
565#endif
void resultEdit(DialogCompletionEvent *) override
void edit(MythScreenType *) override
void resultEdit(DialogCompletionEvent *) override
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
~GlobalCheckBoxSetting() override
GlobalCheckBoxSetting(const QString &name)
GlobalComboBoxSetting(const QString &name, bool rw=false)
~GlobalComboBoxSetting() override
~GlobalSpinBoxSetting() override
GlobalSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
GlobalTextEditSetting(const QString &name)
~GlobalTextEditSetting() override
GlobalTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
virtual void applyChange()
virtual void deleteEntry(void)
GroupSetting()=default
virtual bool canDelete(void)
void resultEdit(DialogCompletionEvent *) override
~HostCheckBoxSetting() override
HostCheckBoxSetting(const QString &name)
HostComboBoxSetting(const QString &name, bool rw=false)
~HostComboBoxSetting() override
~HostFileBrowserSetting() override
HostFileBrowserSetting(const QString &name)
~HostSpinBoxSetting() override
HostSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
HostTextEditSetting(const QString &name)
~HostTextEditSetting() override
HostTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
Basic menu dialog, message and a list of options.
Screen in which all other widgets are contained and rendered.
void ShouldUpdate(StandardSetting *setting)
MythUIButtonListItemSetting(MythUIButtonList *lbtype, const QString &text)
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
QVector< QString > m_labels
QVector< QString > m_values
MythUIComboBoxSetting(Storage *_storage=nullptr, bool rw=false)
Create a Setting Widget to select the value from a list.
void SetNameFilter(QStringList filter)
void SetTypeFilter(QDir::Filters filter)
MythUIFileBrowserSetting(Storage *_storage)
MythUITextEditSetting(Storage *_storage=nullptr)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
StandardSettingDialog(MythScreenStack *parent, const char *name, GroupSetting *groupSettings=nullptr)
void valueChanged(StandardSetting *setting)
void helpTextChanged(const QString &newValue)
QString getHelpText(void) const
virtual void Open(void)
bool isVisible(void) const
bool isEnabled() const
void SetDBValue(const QString &val) override
QString getName(void) const
void settingsChanged(StandardSetting *selectedSetting=nullptr)
virtual void setHelpText(const QString &str)
QString getLabel(void) const
StandardSetting * getParent() const
virtual void Close(void)
virtual void edit(MythScreenType *screen)=0
void ShouldRedraw(StandardSetting *setting)
virtual void childChanged(StandardSetting *)
QMap< QString, QList< StandardSetting * > > m_targets
virtual void resultEdit(DialogCompletionEvent *dce)=0
virtual void setValue(const QString &newValue)
Storage * GetStorage(void) const
QList< StandardSetting * > m_children
StandardSetting(Storage *_storage=nullptr)
bool isReadOnly() const
QString GetDBValue(void) const override
void valueChanged(const QString &newValue)
virtual QString getValue(void) const
virtual void setLabel(QString str)
TransMythUICheckBoxSetting()=default
TransMythUIComboBoxSetting(bool rw=false)
TransMythUISpinBoxSetting(int min, int max, int step, int pageMultiple=5, const QString &special_value_text=QString())
TransTextEditSetting()=default
#define MUI_PUBLIC
Definition: mythuiexp.h:9
Q_DECLARE_METATYPE(StandardSetting *)
uint fillSelectionsFromDir(const QDir &dir, uint minor_min, uint minor_max, const QString &card, const QRegularExpression &driver, bool allow_duplicates, V2CaptureDeviceList *pList, const QString &cardType)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:89