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 &str);
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  virtual ~StandardSetting();
104  void setParent(StandardSetting *parent);
105  QString m_settingValue;
106  bool m_enabled;
107  QString m_label;
108  QString m_helptext;
109  QString m_name;
110  bool m_visible;
111 
112  private:
116  QList<StandardSetting *> m_children;
117  QMap<QString, QList<StandardSetting *> > m_targets;
118 };
119 
121 {
122  public:
123  AutoIncrementSetting(QString _table, QString _column);
124 
125  void Save(void) override; // StandardSetting
126  void edit(MythScreenType * /*screen*/) override { } // StandardSetting
127  void resultEdit(DialogCompletionEvent * /*dce*/) override { } // StandardSetting
128 
129  protected:
130  QString m_table;
131  QString m_column;
132 };
133 
134 /*******************************************************************************
135 * TextEdit Setting *
136 *******************************************************************************/
137 
138 
140 {
141  public:
142  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
143  void edit(MythScreenType *screen) override; // StandardSetting
144  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
145  void SetPasswordEcho(bool b);
146 
147  protected:
148  explicit MythUITextEditSetting(Storage *_storage = nullptr);
150 };
151 
152 
154 {
155  public:
158 };
159 
160 
162 {
163  public:
164  explicit HostTextEditSetting(const QString &name) :
166 };
167 
169 {
170  public:
171  explicit GlobalTextEditSetting(const QString &name) :
173 };
174 
175 /*******************************************************************************
176 * Directory Setting *
177 *******************************************************************************/
178 
179 
181 {
182  public:
183  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
184  void edit(MythScreenType *screen) override; // StandardSetting
185  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
186  void SetTypeFilter(QDir::Filters filter) { m_typeFilter = filter; };
187  void SetNameFilter(QStringList filter) { m_nameFilter = filter; };
188 
189  protected:
190  explicit MythUIFileBrowserSetting(Storage *_storage);
191  QDir::Filters m_typeFilter;
192  QStringList m_nameFilter;
193 };
194 
195 
197 {
198  public:
199  explicit HostFileBrowserSetting(const QString &name) :
201 };
202 
203 
204 /*******************************************************************************
205 * ComboBox Setting *
206 *******************************************************************************/
207 //TODO implement rw=true
209 {
210  Q_OBJECT
211  public:
212  void setValue(int value) override; // StandardSetting
213  int getValueIndex(const QString &value) const;
214  QString getValueLabel(void) const;
215  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
216  void edit(MythScreenType *screen) override; // StandardSetting
217  void addSelection(const QString &label, QString value = QString(),
218  bool select = false);
219  void clearSelections();
220  void fillSelectionsFromDir(const QDir &dir, bool absPath = true);
221  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
222  virtual int size(void) const;
223 
224  public slots:
225  void setValue(const QString&) override; // StandardSetting
226 
227  protected:
228  MythUIComboBoxSetting(Storage *_storage = nullptr, bool rw = false);
230  QVector<QString> m_labels;
231  QVector<QString> m_values;
232 
233  private:
234  bool m_rewrite;
235  bool m_isSet;
236 
237 };
238 
240 {
241  public:
242  HostComboBoxSetting(const QString &name, bool rw = false) :
243  MythUIComboBoxSetting(new HostDBStorage(this, name), rw) { }
244 };
245 
246 
248 {
249  public:
250  GlobalComboBoxSetting(const QString &name, bool rw = false) :
251  MythUIComboBoxSetting(new GlobalDBStorage(this, name), rw) { }
252 };
253 
255 {
256  public:
257  explicit TransMythUIComboBoxSetting(bool rw = false) :
258  MythUIComboBoxSetting(nullptr, rw) { }
259 };
260 
262 {
263  public:
264  HostTimeBoxSetting(const QString &name,
265  const QString &defaultTime = "00:00",
266  const int interval = 1) :
268  {
269  int hour;
270  int minute;
271  QString timeStr;
272 
273  for (hour = 0; hour < 24; hour++)
274  {
275  for (minute = 0; minute < 60; minute += interval)
276  {
277  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
278  addSelection(timeStr, timeStr,
279  timeStr == defaultTime);
280  }
281  }
282  }
283 };
284 
286 {
287  public:
288  GlobalTimeBoxSetting(const QString &name,
289  const QString &defaultTime = "00:00",
290  const int interval = 1) :
292  {
293  int hour;
294  int minute;
295  QString timeStr;
296 
297  for (hour = 0; hour < 24; hour++)
298  {
299  for (minute = 0; minute < 60; minute += interval)
300  {
301  timeStr = timeStr.sprintf("%02d:%02d", hour, minute);
302  addSelection(timeStr, timeStr,
303  timeStr == defaultTime);
304  }
305  }
306  }
307 };
308 
309 /*******************************************************************************
310 * SpinBox Setting *
311 *******************************************************************************/
312 
313 
315 {
316  public:
317  //void setValue(int value);
318  int intValue();
319  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
320  void edit(MythScreenType *screen) override; // StandardSetting
321  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
322 
323  protected:
324  // MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
325  // bool allow_single_step = false,
326  // const QString &special_value_text = QString());
327 
328  MythUISpinBoxSetting(Storage *_storage, int min, int max, int step,
329  int pageMultiple = 8,
330  const QString &special_value_text = QString());
331  private:
332  int m_min;
333  int m_max;
334  int m_step;
337 };
338 
340 {
341  public:
342  TransMythUISpinBoxSetting(int min, int max, int step,
343  int pageMultiple = 5,
344  const QString &special_value_text = QString()) :
345  MythUISpinBoxSetting(nullptr, min, max, step, pageMultiple,
346  special_value_text)
347  { }
348 };
349 
351 {
352  public:
353  HostSpinBoxSetting(const QString &name, int min, int max, int step,
354  int pageMultiple = 8,
355  const QString &special_value_text = QString()) :
356  MythUISpinBoxSetting(new HostDBStorage(this, name), min, max, step,
357  pageMultiple, special_value_text)
358  { }
359 };
360 
362 {
363  public:
364  GlobalSpinBoxSetting(const QString &name, int min, int max, int step,
365  int pageMultiple = 8,
366  const QString &special_value_text = QString()) :
367  MythUISpinBoxSetting(new GlobalDBStorage(this, name), min, max, step,
368  pageMultiple, special_value_text)
369  { }
370 };
371 
372 /*******************************************************************************
373 * CheckBox Setting *
374 *******************************************************************************/
375 
377 {
378  Q_OBJECT
379 
380  public:
381  void resultEdit(DialogCompletionEvent *dce) override; // StandardSetting
382  void edit(MythScreenType *screen) override; // StandardSetting
383  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
384  void setValue(const QString&) override; // StandardSetting
385  virtual void setValue(bool value);
387  bool boolValue();
388 
389  signals:
390  void valueChanged(bool);
391 
392  protected:
393  explicit MythUICheckBoxSetting(Storage *_storage = nullptr);
394 
395 };
396 
398 {
399  public:
402 };
403 
405 {
406  public:
407  explicit HostCheckBoxSetting(const QString &name) :
409 };
410 
412 {
413  public:
414  explicit GlobalCheckBoxSetting(const QString &name) :
416 };
417 
418 /*******************************************************************************
419 * Group Setting *
420 *******************************************************************************/
421 
423 {
424  Q_OBJECT
425 
426  public:
427  GroupSetting() = default;
428 
429  void edit(MythScreenType *screen) override; // StandardSetting
430  void resultEdit(DialogCompletionEvent *) override {} // StandardSetting
431  virtual void applyChange() {}
432  void updateButton(MythUIButtonListItem *item) override; // StandardSetting
433  virtual bool canDelete(void) {return false;}
434  virtual void deleteEntry(void) {}
435 };
436 
438 {
439  Q_OBJECT
440 
441  public:
442  explicit ButtonStandardSetting(const QString &label);
443 
444  void edit(MythScreenType *screen) override; // StandardSetting
445  void resultEdit(DialogCompletionEvent *) override {}; // StandardSetting
446 
447  signals:
448  void clicked();
449 };
450 
451 /*******************************************************************************
452 * Standard Dialog Setting *
453 *******************************************************************************/
454 
456 {
457  Q_OBJECT
458 
459  public:
460 
461  StandardSettingDialog(MythScreenStack *parent, const char *name,
462  GroupSetting *groupSettings = nullptr);
463  virtual ~StandardSettingDialog();
464  bool Create(void) override; // MythScreenType
465  void customEvent(QEvent *event) override; // MythUIType
466  bool keyPressEvent(QKeyEvent *) override; // MythScreenType
467  void ShowMenu(void) override; // MythScreenType
468  void deleteEntry(void);
469 
470  public slots:
471  void Close(void) override; // MythScreenType
472  void updateSettings(StandardSetting *selectedSetting = nullptr);
473  void editEntry(void);
474  void deleteSelected(void);
475  void deleteEntryConfirmed(bool ok);
476 
477  protected:
478  void Load(void) override; // MythScreenType
479  void Init(void) override; // MythScreenType
480  GroupSetting *GetGroupSettings(void) const;
482 
483  private slots:
484  void settingSelected(MythUIButtonListItem *item);
485  void settingClicked(MythUIButtonListItem *item);
486 
487  private:
488  void LevelUp();
489  void LevelDown();
490  void setCurrentGroupSetting(StandardSetting *groupSettings,
491  StandardSetting *selectedSetting = nullptr);
492  void Save();
493 
500  bool m_loaded;
501 };
502 
504 
505 
506 #endif
MythDialogBox * m_menuPopup
HostTextEditSetting(const QString &name)
void resultEdit(DialogCompletionEvent *) override
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:999
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
MythUIButtonListItemSetting(MythUIButtonList *lbtype, const QString &text)
MythUIText * m_selectedSettingHelp
TransMythUIComboBoxSetting(bool rw=false)
virtual void Open(void)
QString getName(void) const
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
void SetDBValue(const QString &val) override
virtual QString getValue(void) const
GlobalTextEditSetting(const QString &name)
unsigned char b
Definition: ParseText.cpp:340
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)
StandardSetting * m_currentGroupSetting
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)
MythUIButtonList * m_buttonList
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:339
StandardSetting * m_parent
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)
GroupSetting * m_settingsTree
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 &)