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; emit helpTextChanged(m_helptext); }
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  void helpTextChanged(const QString &);
101 
102  protected:
103  explicit StandardSetting(Storage *_storage = nullptr)
104  : m_storage(_storage) {}
105  virtual ~StandardSetting();
106  void setParent(StandardSetting *parent);
107  QString m_settingValue;
108  bool m_enabled {true};
109  QString m_label;
110  QString m_helptext;
111  QString m_name;
112  bool m_visible {true};
113 
114  private:
115  bool m_haveChanged {false};
116  Storage *m_storage {nullptr};
117  StandardSetting *m_parent {nullptr};
118  QList<StandardSetting *> m_children;
119  QMap<QString, QList<StandardSetting *> > m_targets;
120 };
121 
123 {
124  public:
125  AutoIncrementSetting(QString _table, QString _column);
126 
127  void Save(void) override; // StandardSetting
128  void edit(MythScreenType * /*screen*/) override { } // StandardSetting
129  void resultEdit(DialogCompletionEvent * /*dce*/) override { } // StandardSetting
130 
131  protected:
132  QString m_table;
133  QString m_column;
134 };
135 
136 /*******************************************************************************
137 * TextEdit Setting *
138 *******************************************************************************/
139 
140 
142 {
143  public:
144  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
145  void edit(MythScreenType *screen) override; // StandardSetting
146  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
147  void SetPasswordEcho(bool b);
148 
149  protected:
150  explicit MythUITextEditSetting(Storage *_storage = nullptr)
151  : StandardSetting(_storage) {}
152  bool m_passwordEcho {false};
153 };
154 
155 
157 {
158  public:
161 };
162 
163 
165 {
166  public:
167  explicit HostTextEditSetting(const QString &name) :
168  MythUITextEditSetting(new HostDBStorage(this, name)) { }
169 };
170 
172 {
173  public:
174  explicit GlobalTextEditSetting(const QString &name) :
175  MythUITextEditSetting(new GlobalDBStorage(this, name)) { }
176 };
177 
178 /*******************************************************************************
179 * Directory Setting *
180 *******************************************************************************/
181 
182 
184 {
185  public:
186  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
187  void edit(MythScreenType *screen) override; // StandardSetting
188  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
189  void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; };
190  void SetNameFilter(QStringList filter) { m_nameFilter = filter; };
191 
192  protected:
193  explicit MythUIFileBrowserSetting(Storage *_storage)
194  : StandardSetting(_storage) {}
195  QDir::Filters m_typeFilter {QDir::AllDirs | QDir::Drives |
196  QDir::Files | QDir::Readable |
197  QDir::Writable | QDir::Executable};
198  QStringList m_nameFilter {"*"};
199 };
200 
201 
203 {
204  public:
205  explicit HostFileBrowserSetting(const QString &name) :
206  MythUIFileBrowserSetting(new HostDBStorage(this, name)) { }
207 };
208 
209 
210 /*******************************************************************************
211 * ComboBox Setting *
212 *******************************************************************************/
213 //TODO implement rw=true
215 {
216  Q_OBJECT
217  public:
218  void setValue(int value) override; // StandardSetting
219  int getValueIndex(const QString &value) const;
220  QString getValueLabel(void) const;
221  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
222  void edit(MythScreenType *screen) override; // StandardSetting
223  void addSelection(const QString &label, QString value = QString(),
224  bool select = false);
225  void clearSelections();
226  void fillSelectionsFromDir(const QDir &dir, bool absPath = true);
227  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
228  virtual int size(void) const;
229 
230  public slots:
231  void setValue(const QString&) override; // StandardSetting
232 
233  protected:
241  MythUIComboBoxSetting(Storage *_storage = nullptr, bool rw = false)
242  : StandardSetting(_storage), m_rewrite(rw) {}
244  QVector<QString> m_labels;
245  QVector<QString> m_values;
246 
247  private:
248  bool m_rewrite;
249  bool m_isSet {false};
250 
251 };
252 
254 {
255  public:
256  HostComboBoxSetting(const QString &name, bool rw = false) :
257  MythUIComboBoxSetting(new HostDBStorage(this, name), rw) { }
258 };
259 
260 
262 {
263  public:
264  GlobalComboBoxSetting(const QString &name, bool rw = false) :
265  MythUIComboBoxSetting(new GlobalDBStorage(this, name), rw) { }
266 };
267 
269 {
270  public:
271  explicit TransMythUIComboBoxSetting(bool rw = false) :
272  MythUIComboBoxSetting(nullptr, rw) { }
273 };
274 
276 {
277  public:
278  HostTimeBoxSetting(const QString &name,
279  const QString &defaultTime = "00:00",
280  const int interval = 1) :
282  {
283  int hour;
284  int minute;
285  QString timeStr;
286 
287  for (hour = 0; hour < 24; hour++)
288  {
289  for (minute = 0; minute < 60; minute += interval)
290  {
291  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
292  addSelection(timeStr, timeStr,
293  timeStr == defaultTime);
294  }
295  }
296  }
297 };
298 
300 {
301  public:
302  GlobalTimeBoxSetting(const QString &name,
303  const QString &defaultTime = "00:00",
304  const int interval = 1) :
306  {
307  int hour;
308  int minute;
309  QString timeStr;
310 
311  for (hour = 0; hour < 24; hour++)
312  {
313  for (minute = 0; minute < 60; minute += interval)
314  {
315  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
316  addSelection(timeStr, timeStr,
317  timeStr == defaultTime);
318  }
319  }
320  }
321 };
322 
323 /*******************************************************************************
324 * SpinBox Setting *
325 *******************************************************************************/
326 
327 
329 {
330  public:
331  //void setValue(int value);
332  int intValue();
333  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
334  void edit(MythScreenType *screen) override; // StandardSetting
335  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
336 
337  protected:
338  // MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
339  // bool allow_single_step = false,
340  // const QString &special_value_text = QString());
341 
342  MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
343  int pageMultiple = 8,
344  QString special_value_text = QString());
345  private:
346  int m_min;
347  int m_max;
348  int m_step;
351 };
352 
354 {
355  public:
356  TransMythUISpinBoxSetting(int min, int max, int step,
357  int pageMultiple = 5,
358  const QString &special_value_text = QString()) :
359  MythUISpinBoxSetting(nullptr, min, max, step, pageMultiple,
360  special_value_text)
361  { }
362 };
363 
365 {
366  public:
367  HostSpinBoxSetting(const QString &name, int min, int max, int step,
368  int pageMultiple = 8,
369  const QString &special_value_text = QString()) :
370  MythUISpinBoxSetting(new HostDBStorage(this, name), min, max, step,
371  pageMultiple, special_value_text)
372  { }
373 };
374 
376 {
377  public:
378  GlobalSpinBoxSetting(const QString &name, int min, int max, int step,
379  int pageMultiple = 8,
380  const QString &special_value_text = QString()) :
381  MythUISpinBoxSetting(new GlobalDBStorage(this, name), min, max, step,
382  pageMultiple, special_value_text)
383  { }
384 };
385 
386 /*******************************************************************************
387 * CheckBox Setting *
388 *******************************************************************************/
389 
391 {
392  Q_OBJECT
393 
394  public:
395  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
396  void edit(MythScreenType *screen) override; // StandardSetting
397  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
398  void setValue(const QString&) override; // StandardSetting
399  virtual void setValue(bool value);
401  bool boolValue() { return m_settingValue == "1"; }
402 
403  signals:
404  void valueChanged(bool);
405 
406  protected:
407  explicit MythUICheckBoxSetting(Storage *_storage = nullptr);
408 
409 };
410 
412 {
413  public:
416 };
417 
419 {
420  public:
421  explicit HostCheckBoxSetting(const QString &name) :
422  MythUICheckBoxSetting(new HostDBStorage(this, name)) { }
423 };
424 
426 {
427  public:
428  explicit GlobalCheckBoxSetting(const QString &name) :
429  MythUICheckBoxSetting(new GlobalDBStorage(this, name)) { }
430 };
431 
432 /*******************************************************************************
433 * Group Setting *
434 *******************************************************************************/
435 
437 {
438  Q_OBJECT
439 
440  public:
441  GroupSetting() = default;
442 
443  void edit(MythScreenType *screen) override; // StandardSetting
444  void resultEdit(DialogCompletionEvent *) override {} // StandardSetting
445  virtual void applyChange() {}
446  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
447  virtual bool canDelete(void) {return false;}
448  virtual void deleteEntry(void) {}
449 };
450 
452 {
453  Q_OBJECT
454 
455  public:
456  explicit ButtonStandardSetting(const QString &label);
457 
458  void edit(MythScreenType *screen) override; // StandardSetting
459  void resultEdit(DialogCompletionEvent *) override {}; // StandardSetting
460 
461  signals:
462  void clicked();
463 };
464 
465 /*******************************************************************************
466 * Standard Dialog Setting *
467 *******************************************************************************/
468 
470 {
471  Q_OBJECT
472 
473  public:
474 
475  StandardSettingDialog(MythScreenStack *parent, const char *name,
476  GroupSetting *groupSettings = nullptr)
477  : MythScreenType(parent, name), m_settingsTree(groupSettings) {}
478  virtual ~StandardSettingDialog();
479  bool Create(void) override; // MythScreenType
480  void customEvent(QEvent *event) override; // MythUIType
481  bool keyPressEvent(QKeyEvent *) override; // MythScreenType
482  void ShowMenu(void) override; // MythScreenType
483  void deleteEntry(void);
484 
485  public slots:
486  void Close(void) override; // MythScreenType
487  void updateSettings(StandardSetting *selectedSetting = nullptr);
488  void editEntry(void);
489  void deleteSelected(void);
490  void deleteEntryConfirmed(bool ok);
491 
492  protected:
493  void Load(void) override; // MythScreenType
494  void Init(void) override; // MythScreenType
495  GroupSetting *GetGroupSettings(void) const;
496  MythUIButtonList *m_buttonList {nullptr};
497 
498  private slots:
499  void settingSelected(MythUIButtonListItem *item);
500  void settingClicked(MythUIButtonListItem *item);
501 
502  private:
503  void LevelUp();
504  void LevelDown();
505  void setCurrentGroupSetting(StandardSetting *groupSettings,
506  StandardSetting *selectedSetting = nullptr);
507  void Save();
508 
509  MythUIText *m_title {nullptr};
510  MythUIText *m_groupHelp {nullptr};
511  MythUIText *m_selectedSettingHelp {nullptr};
512  MythDialogBox *m_menuPopup {nullptr};
513  GroupSetting *m_settingsTree {nullptr};
514  StandardSetting *m_currentGroupSetting {nullptr};
515  bool m_loaded {false};
516 };
517 
519 
520 
521 #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:980
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)
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())
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
bool isEnabled() const
QList< StandardSetting * > m_children
const char * m_name
Definition: ParseText.cpp:328
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 &)