MythTV  master
standardsettings.h
Go to the documentation of this file.
1 #ifndef STANDARDSETTINGS_H_
2 #define STANDARDSETTINGS_H_
3 
4 #include "mythexp.h"
5 #include "mythuibuttonlist.h"
6 #include "mythdialogbox.h"
7 #include "mythstorage.h"
8 
9 #include <QMap>
10 #include <QObject>
11 #include <initializer_list>
12 
13 class StandardSetting;
14 
15 class MythUIButtonListItemSetting : public QObject, public MythUIButtonListItem
16 {
17  Q_OBJECT
18 
19  public:
20  MythUIButtonListItemSetting (MythUIButtonList *lbtype, const QString &text)
21  : MythUIButtonListItem(lbtype, text) {}
22 
23  public slots:
24  void ShouldUpdate(StandardSetting *setting);
25 };
26 
27 class MPUBLIC StandardSetting : public QObject, public StorageUser
28 {
29  Q_OBJECT
30 
31  public:
32  virtual void setLabel(QString str) { m_label = str; }
33  QString getLabel(void) const { return m_label; }
34 
35  virtual void setHelpText(const QString &str) { m_helptext = str; }
36  QString getHelpText(void) const { return m_helptext; }
37 
38  virtual void setName(const QString &name);
39  QString getName(void) const { return m_name; }
40  StandardSetting * byName(const QString &name);
41 
42  bool isVisible(void) const { return m_visible; }
43  bool isEnabled() const { return m_enabled; }
44  bool haveChanged();
45  void setChanged(bool changed);
46  StandardSetting *getParent() const {return m_parent;}
47 
48  // Gets
49  virtual QString getValue(void) const {return m_settingValue;}
50 
51  virtual void updateButton(MythUIButtonListItem *item);
52 
53  // StorageUser
54  void SetDBValue(const QString &val) override { setValue(val); } // StorageUser
55  QString GetDBValue(void) const override { return getValue(); } // StorageUser
56 
57  MythUIButtonListItem *createButton(MythUIButtonList *list);
58 
59  //subsettings
60  virtual void addChild(StandardSetting *child);
61  virtual void removeChild(StandardSetting *child);
62  virtual QList<StandardSetting *> *getSubSettings();
63  virtual bool haveSubSettings();
64  virtual void clearSettings();
65  void clearTargetedSettings(const QString &value);
66 
67  virtual void edit(MythScreenType *screen) = 0;
68  virtual void resultEdit(DialogCompletionEvent *dce) = 0;
69 
70  virtual void Load(void);
71  virtual void Save(void);
72 
73  virtual void Open(void) {}
74  virtual void Close(void) {}
75 
76  Storage *GetStorage(void) const { return m_storage; }
77 
78  void addTargetedChild(const QString &value, StandardSetting *setting);
79  void addTargetedChildren(const QString &value,
80  std::initializer_list<StandardSetting *> settings);
81  void removeTargetedChild(const QString &value, StandardSetting *child);
82 
83  virtual bool keyPressEvent(QKeyEvent *);
84 
85  void MoveToThread(QThread *thread);
86 
87  public slots:
88  virtual void setEnabled(bool enabled);
89  void setVisible(bool visible);
90  virtual void setValue(const QString &newValue);
91  virtual void setValue(int newValue);
92  virtual void childChanged(StandardSetting *) {}
93 
94  signals:
95  void valueChanged(const QString &);
96  void valueChanged(StandardSetting *);
97  void ShouldRedraw(StandardSetting *);
98  void settingsChanged(StandardSetting *selectedSetting = nullptr);
99  void ChangeSaved();
100 
101  protected:
102  explicit StandardSetting(Storage *_storage = nullptr)
103  : m_storage(_storage) {}
104  virtual ~StandardSetting();
105  void setParent(StandardSetting *parent);
106  QString m_settingValue;
107  bool m_enabled {true};
108  QString m_label;
109  QString m_helptext;
110  QString m_name;
111  bool m_visible {true};
112 
113  private:
114  bool m_haveChanged {false};
115  Storage *m_storage {nullptr};
116  StandardSetting *m_parent {nullptr};
117  QList<StandardSetting *> m_children;
118  QMap<QString, QList<StandardSetting *> > m_targets;
119 };
120 
122 {
123  public:
124  AutoIncrementSetting(QString _table, QString _column);
125 
126  void Save(void) override; // StandardSetting
127  void edit(MythScreenType * /*screen*/) override { } // StandardSetting
128  void resultEdit(DialogCompletionEvent * /*dce*/) override { } // StandardSetting
129 
130  protected:
131  QString m_table;
132  QString m_column;
133 };
134 
135 /*******************************************************************************
136 * TextEdit Setting *
137 *******************************************************************************/
138 
139 
141 {
142  public:
143  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
144  void edit(MythScreenType *screen) override; // StandardSetting
145  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
146  void SetPasswordEcho(bool b);
147 
148  protected:
149  explicit MythUITextEditSetting(Storage *_storage = nullptr)
150  : StandardSetting(_storage) {}
151  bool m_passwordEcho {false};
152 };
153 
154 
156 {
157  public:
160 };
161 
162 
164 {
165  public:
166  explicit HostTextEditSetting(const QString &name) :
168 };
169 
171 {
172  public:
173  explicit GlobalTextEditSetting(const QString &name) :
175 };
176 
177 /*******************************************************************************
178 * Directory Setting *
179 *******************************************************************************/
180 
181 
183 {
184  public:
185  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
186  void edit(MythScreenType *screen) override; // StandardSetting
187  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
188  void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; };
189  void SetNameFilter(QStringList filter) { m_nameFilter = filter; };
190 
191  protected:
192  explicit MythUIFileBrowserSetting(Storage *_storage)
193  : StandardSetting(_storage) {}
194  QDir::Filters m_typeFilter {QDir::AllDirs | QDir::Drives |
195  QDir::Files | QDir::Readable |
196  QDir::Writable | QDir::Executable};
197  QStringList m_nameFilter {"*"};
198 };
199 
200 
202 {
203  public:
204  explicit HostFileBrowserSetting(const QString &name) :
206 };
207 
208 
209 /*******************************************************************************
210 * ComboBox Setting *
211 *******************************************************************************/
212 //TODO implement rw=true
214 {
215  Q_OBJECT
216  public:
217  void setValue(int value) override; // StandardSetting
218  int getValueIndex(const QString &value) const;
219  QString getValueLabel(void) const;
220  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
221  void edit(MythScreenType *screen) override; // StandardSetting
222  void addSelection(const QString &label, QString value = QString(),
223  bool select = false);
224  void clearSelections();
225  void fillSelectionsFromDir(const QDir &dir, bool absPath = true);
226  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
227  virtual int size(void) const;
228 
229  public slots:
230  void setValue(const QString&) override; // StandardSetting
231 
232  protected:
240  MythUIComboBoxSetting(Storage *_storage = nullptr, bool rw = false)
241  : StandardSetting(_storage), m_rewrite(rw) {}
243  QVector<QString> m_labels;
244  QVector<QString> m_values;
245 
246  private:
247  bool m_rewrite;
248  bool m_isSet {false};
249 
250 };
251 
253 {
254  public:
255  HostComboBoxSetting(const QString &name, bool rw = false) :
256  MythUIComboBoxSetting(new HostDBStorage(this, name), rw) { }
257 };
258 
259 
261 {
262  public:
263  GlobalComboBoxSetting(const QString &name, bool rw = false) :
264  MythUIComboBoxSetting(new GlobalDBStorage(this, name), rw) { }
265 };
266 
268 {
269  public:
270  explicit TransMythUIComboBoxSetting(bool rw = false) :
271  MythUIComboBoxSetting(nullptr, rw) { }
272 };
273 
275 {
276  public:
277  HostTimeBoxSetting(const QString &name,
278  const QString &defaultTime = "00:00",
279  const int interval = 1) :
281  {
282  int hour;
283  int minute;
284  QString timeStr;
285 
286  for (hour = 0; hour < 24; hour++)
287  {
288  for (minute = 0; minute < 60; minute += interval)
289  {
290  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
291  addSelection(timeStr, timeStr,
292  timeStr == defaultTime);
293  }
294  }
295  }
296 };
297 
299 {
300  public:
301  GlobalTimeBoxSetting(const QString &name,
302  const QString &defaultTime = "00:00",
303  const int interval = 1) :
305  {
306  int hour;
307  int minute;
308  QString timeStr;
309 
310  for (hour = 0; hour < 24; hour++)
311  {
312  for (minute = 0; minute < 60; minute += interval)
313  {
314  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
315  addSelection(timeStr, timeStr,
316  timeStr == defaultTime);
317  }
318  }
319  }
320 };
321 
322 /*******************************************************************************
323 * SpinBox Setting *
324 *******************************************************************************/
325 
326 
328 {
329  public:
330  //void setValue(int value);
331  int intValue();
332  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
333  void edit(MythScreenType *screen) override; // StandardSetting
334  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
335 
336  protected:
337  // MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
338  // bool allow_single_step = false,
339  // const QString &special_value_text = QString());
340 
341  MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
342  int pageMultiple = 8,
343  const QString &special_value_text = QString());
344  private:
345  int m_min;
346  int m_max;
347  int m_step;
350 };
351 
353 {
354  public:
355  TransMythUISpinBoxSetting(int min, int max, int step,
356  int pageMultiple = 5,
357  const QString &special_value_text = QString()) :
358  MythUISpinBoxSetting(nullptr, min, max, step, pageMultiple,
359  special_value_text)
360  { }
361 };
362 
364 {
365  public:
366  HostSpinBoxSetting(const QString &name, int min, int max, int step,
367  int pageMultiple = 8,
368  const QString &special_value_text = QString()) :
369  MythUISpinBoxSetting(new HostDBStorage(this, name), min, max, step,
370  pageMultiple, special_value_text)
371  { }
372 };
373 
375 {
376  public:
377  GlobalSpinBoxSetting(const QString &name, int min, int max, int step,
378  int pageMultiple = 8,
379  const QString &special_value_text = QString()) :
380  MythUISpinBoxSetting(new GlobalDBStorage(this, name), min, max, step,
381  pageMultiple, special_value_text)
382  { }
383 };
384 
385 /*******************************************************************************
386 * CheckBox Setting *
387 *******************************************************************************/
388 
390 {
391  Q_OBJECT
392 
393  public:
394  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
395  void edit(MythScreenType *screen) override; // StandardSetting
396  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
397  void setValue(const QString&) override; // StandardSetting
398  virtual void setValue(bool value);
400  bool boolValue() { return m_settingValue == "1"; }
401 
402  signals:
403  void valueChanged(bool);
404 
405  protected:
406  explicit MythUICheckBoxSetting(Storage *_storage = nullptr);
407 
408 };
409 
411 {
412  public:
415 };
416 
418 {
419  public:
420  explicit HostCheckBoxSetting(const QString &name) :
422 };
423 
425 {
426  public:
427  explicit GlobalCheckBoxSetting(const QString &name) :
429 };
430 
431 /*******************************************************************************
432 * Group Setting *
433 *******************************************************************************/
434 
436 {
437  Q_OBJECT
438 
439  public:
440  GroupSetting() = default;
441 
442  void edit(MythScreenType *screen) override; // StandardSetting
443  void resultEdit(DialogCompletionEvent *) override {} // StandardSetting
444  virtual void applyChange() {}
445  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
446  virtual bool canDelete(void) {return false;}
447  virtual void deleteEntry(void) {}
448 };
449 
451 {
452  Q_OBJECT
453 
454  public:
455  explicit ButtonStandardSetting(const QString &label);
456 
457  void edit(MythScreenType *screen) override; // StandardSetting
458  void resultEdit(DialogCompletionEvent *) override {}; // StandardSetting
459 
460  signals:
461  void clicked();
462 };
463 
464 /*******************************************************************************
465 * Standard Dialog Setting *
466 *******************************************************************************/
467 
469 {
470  Q_OBJECT
471 
472  public:
473 
475  GroupSetting *groupSettings = nullptr)
476  : MythScreenType(parent, name), m_settingsTree(groupSettings) {}
477  virtual ~StandardSettingDialog();
478  bool Create(void) override; // MythScreenType
479  void customEvent(QEvent *event) override; // MythUIType
480  bool keyPressEvent(QKeyEvent *) override; // MythScreenType
481  void ShowMenu(void) override; // MythScreenType
482  void deleteEntry(void);
483 
484  public slots:
485  void Close(void) override; // MythScreenType
486  void updateSettings(StandardSetting *selectedSetting = nullptr);
487  void editEntry(void);
488  void deleteSelected(void);
489  void deleteEntryConfirmed(bool ok);
490 
491  protected:
492  void Load(void) override; // MythScreenType
493  void Init(void) override; // MythScreenType
494  GroupSetting *GetGroupSettings(void) const;
495  MythUIButtonList *m_buttonList {nullptr};
496 
497  private slots:
498  void settingSelected(MythUIButtonListItem *item);
499  void settingClicked(MythUIButtonListItem *item);
500 
501  private:
502  void LevelUp();
503  void LevelDown();
504  void setCurrentGroupSetting(StandardSetting *groupSettings,
505  StandardSetting *selectedSetting = nullptr);
506  void Save();
507 
508  MythUIText *m_title {nullptr};
509  MythUIText *m_groupHelp {nullptr};
510  MythUIText *m_selectedSettingHelp {nullptr};
511  MythDialogBox *m_menuPopup {nullptr};
512  GroupSetting *m_settingsTree {nullptr};
513  StandardSetting *m_currentGroupSetting {nullptr};
514  bool m_loaded {false};
515 };
516 
518 
519 
520 #endif
MythUITextEditSetting(Storage *_storage=nullptr)
HostTextEditSetting(const QString &name)
void resultEdit(DialogCompletionEvent *) override
MythUIFileBrowserSetting(Storage *_storage)
HostCheckBoxSetting(const QString &name)
unsigned int slots[4]
Definition: element.c:38
virtual bool canDelete(void)
virtual void ShowMenu(void)
#define MPUBLIC
Definition: mythexp.h:10
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
void customEvent(QEvent *event) override
Definition: mythuitype.cpp:977
Storage * GetStorage(void) const
StandardSetting * getParent() const
void SetNameFilter(QStringList filter)
virtual bool Create(void)
Basic menu dialog, message and a list of options.
void addSelection(const QString &label, QString value=QString(), bool select=false)
QVector< QString > m_labels
virtual void setHelpText(const QString &str)
QVector< QString > m_values
QString getLabel(void) const
void resultEdit(DialogCompletionEvent *) override
void resultEdit(DialogCompletionEvent *) override
StandardSetting(Storage *_storage=nullptr)
MythUIButtonListItemSetting(MythUIButtonList *lbtype, const QString &text)
TransMythUIComboBoxSetting(bool rw=false)
virtual void Open(void)
QString getName(void) const
StandardSettingDialog(MythScreenStack *parent, const char *name, GroupSetting *groupSettings=nullptr)
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
MythUIComboBoxSetting(Storage *_storage=nullptr, bool rw=false)
Create a Setting Widget to select the value from a list.
void SetDBValue(const QString &val) override
virtual QString getValue(void) const
GlobalTextEditSetting(const QString &name)
unsigned char b
Definition: ParseText.cpp:329
HostTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
virtual void Close()
HostSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
Q_DECLARE_METATYPE(StandardSetting *)
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
QString GetDBValue(void) const override
virtual void setLabel(QString str)
void ShouldUpdate(StandardSetting *setting)
virtual void edit(MythScreenType *screen)=0
HostFileBrowserSetting(const QString &name)
GlobalTimeBoxSetting(const QString &name, const QString &defaultTime="00:00", const int interval=1)
HostComboBoxSetting(const QString &name, bool rw=false)
virtual void applyChange()
GlobalSpinBoxSetting(const QString &name, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
const char * name
Definition: ParseText.cpp:328
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
bool isEnabled() const
QList< StandardSetting * > m_children
virtual void childChanged(StandardSetting *)
virtual void Save(void)
void edit(MythScreenType *) override
virtual void resultEdit(DialogCompletionEvent *dce)=0
bool keyPressEvent(QKeyEvent *) override
Key event handler.
TransMythUISpinBoxSetting(int min, int max, int step, int pageMultiple=5, const QString &special_value_text=QString())
void SetTypeFilter(QDir::Filters filter)
virtual void Close(void)
virtual void Init(void)
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
virtual void Load(void)
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
QMap< QString, QList< StandardSetting * > > m_targets
Screen in which all other widgets are contained and rendered.
virtual void deleteEntry(void)
GlobalCheckBoxSetting(const QString &name)
bool isVisible(void) const
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:37
virtual void setValue(const QString &newValue)
GlobalComboBoxSetting(const QString &name, bool rw=false)
QString getHelpText(void) const
static void fillSelectionsFromDir(const QDir &dir, AudioOutput::ADCVect *list)
void valueChanged(const QString &)