MythTV  master
standardsettings.cpp
Go to the documentation of this file.
1 #include "standardsettings.h"
2 #include <QApplication>
3 #include <QCoreApplication>
4 #include <QThread>
5 #include <utility>
6 
7 #include <mythcontext.h>
8 #include <mythmainwindow.h>
9 #include <mythdialogbox.h>
10 #include <mythuispinbox.h>
11 #include <mythuitext.h>
12 #include <mythuibutton.h>
13 #include <mythuifilebrowser.h>
14 #include "mythlogging.h"
15 
17 {
18  setting->updateButton(this);
19 }
20 
22 {
23  QList<StandardSetting *>::const_iterator i;
24  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
25  delete *i;
26  m_children.clear();
27 
28  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
29  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
30  {
31  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
32  delete *i;
33  }
34  m_targets.clear();
35 }
36 
38 {
39  auto *item = new MythUIButtonListItemSetting(list, m_label);
40  item->SetData(QVariant::fromValue(this));
41  connect(this, SIGNAL(ShouldRedraw(StandardSetting *)),
42  item, SLOT(ShouldUpdate(StandardSetting *)));
43  updateButton(item);
44  return item;
45 }
46 
47 void StandardSetting::setEnabled(bool enabled)
48 {
49  m_enabled = enabled;
50  emit ShouldRedraw(this);
51 }
52 
53 void StandardSetting::setVisible(bool visible)
54 {
55  m_visible = visible;
56  emit settingsChanged(this);
57 }
58 
60 {
61  m_parent = parent;
62 }
63 
65 {
66  if (!child)
67  return;
68 
69  m_children.append(child);
70  child->setParent(this);
71 }
72 
74 {
75  m_children.removeAll(child);
76  emit settingsChanged(this);
77 }
78 
79 bool StandardSetting::keyPressEvent(QKeyEvent * /*e*/)
80 {
81  return false;
82 }
83 
90 {
91  item->setVisible(m_visible);
92  item->DisplayState("standard", "widgettype");
93  item->setEnabled(isEnabled());
94  item->SetText(m_label);
95  item->SetText(m_settingValue, "value");
96  item->SetText(getHelpText(), "description");
98 }
99 
100 void StandardSetting::addTargetedChildren(const QString &value,
101  std::initializer_list<StandardSetting *> settings)
102 {
103  m_targets[value].reserve(settings.size());
104  foreach (StandardSetting *setting, settings)
105  {
106  m_targets[value].append(setting);
107  setting->setParent(this);
108  }
109 }
110 void StandardSetting::addTargetedChild(const QString &value,
111  StandardSetting * setting)
112 {
113  m_targets[value].append(setting);
114  setting->setParent(this);
115 }
116 
117 void StandardSetting::removeTargetedChild(const QString &value,
118  StandardSetting *child)
119 {
120  if (m_targets.contains(value))
121  {
122  m_targets[value].removeAll(child);
123  delete child;
124  }
125 }
126 
127 void StandardSetting::clearTargetedSettings(const QString &value)
128 {
129  if (m_targets.contains(value))
130  {
131  foreach(StandardSetting *setting, m_targets[value])
132  {
133  delete setting;
134  }
135  m_targets[value].clear();
136  }
137 }
138 
139 QList<StandardSetting *> *StandardSetting::getSubSettings()
140 {
141  if (m_targets.contains(m_settingValue) &&
142  !m_targets[m_settingValue].empty())
143  return &m_targets[m_settingValue];
144  return &m_children;
145 }
146 
148 {
149  QList<StandardSetting *> *subSettings = getSubSettings();
150  return subSettings && !subSettings->empty();
151 }
152 
154 {
155  m_children.clear();
156 }
157 
158 void StandardSetting::setValue(int newValue)
159 {
160  setValue(QString::number(newValue));
161 }
162 
163 void StandardSetting::setValue(const QString &newValue)
164 {
165  if (m_settingValue != newValue)
166  {
167  m_settingValue = newValue;
168  m_haveChanged = true;
169 
170  emit valueChanged(newValue);
171  emit valueChanged(this);
172  }
173  emit ShouldRedraw(this);
174 }
175 
180 {
181  if (m_haveChanged)
182  {
183  LOG(VB_GENERAL, LOG_DEBUG,
184  QString("Setting '%1' changed to %2").arg(getLabel())
185  .arg(getValue()));
186  return true;
187  }
188 
189  //we check only the relevant children
190  QList<StandardSetting *> *children = getSubSettings();
191  if (!children)
192  return false;
193 
194  QList<StandardSetting *>::const_iterator i;
195  bool haveChanged = false;
196  for (i = children->constBegin(); !haveChanged && i != children->constEnd();
197  ++i)
198  haveChanged = (*i)->haveChanged();
199 
200  return haveChanged;
201 }
202 
203 void StandardSetting::setChanged(bool changed)
204 {
205  m_haveChanged = changed;
206 }
207 
209 {
210  if (m_storage)
211  m_storage->Load();
212 
213  m_haveChanged = false;
214 
215  QList<StandardSetting *>::const_iterator i;
216  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
217  (*i)->Load();
218 
219  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
220  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
221  {
222  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
223  (*i)->Load();
224  }
225 }
226 
228 {
229  if (m_storage)
230  m_storage->Save();
231 
232  //we save only the relevant children
233  QList<StandardSetting *> *children = getSubSettings();
234  if (children)
235  {
236  for (auto i = children->constBegin(); i != children->constEnd(); ++i)
237  (*i)->Save();
238  }
239 
240  if (!m_haveChanged)
241  return;
242 
243  m_haveChanged = false;
244  emit ChangeSaved();
245 }
246 
247 void StandardSetting::setName(const QString &name)
248 {
249  m_name = name;
250  if (m_label.isEmpty())
251  setLabel(name);
252 }
253 
255 {
256  if (name == m_name)
257  return this;
258 
259  foreach (StandardSetting *setting, *getSubSettings())
260  {
261  StandardSetting *s = setting->byName(name);
262  if (s)
263  return s;
264  }
265  return nullptr;
266 }
267 
268 void StandardSetting::MoveToThread(QThread *thread)
269 {
270  moveToThread(thread);
271 
272  QList<StandardSetting *>::const_iterator i;
273  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
274  (*i)->MoveToThread(thread);
275 
276  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
277  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
278  {
279  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
280  (*i)->MoveToThread(thread);
281  }
282 }
283 
284 /******************************************************************************
285  Group Setting
286 *******************************************************************************/
288 {
289  if (!isEnabled())
290  return;
291 
292  auto *dce = new DialogCompletionEvent("leveldown", 0, "", "");
293  QCoreApplication::postEvent(screen, dce);
294 }
295 
297 {
298  item->DisplayState("group", "widgettype");
299  item->setEnabled(isEnabled());
300  item->SetText(m_label);
301  item->SetText(m_settingValue, "value");
302  item->SetText(getHelpText(), "description");
303  item->setDrawArrow(haveSubSettings());
304 }
305 
307 {
308  setLabel(label);
309 }
310 
312 {
313  emit clicked();
314 }
315 
317 {
318  if (getValue() == "0")
319  {
320  // Generate a new, unique ID
321  QString querystr = "INSERT INTO " + m_table +
322  " (" + m_column + ") VALUES (0);";
323 
324  MSqlQuery query(MSqlQuery::InitCon());
325 
326  if (!query.exec(querystr))
327  {
328  MythDB::DBError("inserting row", query);
329  return;
330  }
331  // XXX -- HACK BEGIN:
332  // lastInsertID fails with "QSqlQuery::value: not positioned on a valid
333  // record" if we get a invalid QVariant we workaround the problem by
334  // taking advantage of mysql always incrementing the auto increment
335  // pointer this breaks if someone modifies the auto increment pointer
336  //setValue(query.lastInsertId().toInt());
337 
338  QVariant var = query.lastInsertId();
339 
340  if (var.type())
341  setValue(var.toInt());
342  else
343  {
344  querystr = "SELECT MAX(" + m_column + ") FROM " +
345  m_table + ";";
346  if (query.exec(querystr) && query.next())
347  {
348  int lii = query.value(0).toInt();
349  lii = lii ? lii : 1;
350  setValue(lii);
351  }
352  else
353  {
354  LOG(VB_GENERAL, LOG_EMERG,
355  "Can't determine the Id of the last insert "
356  "QSqlQuery.lastInsertId() failed, the workaround "
357  "failed too!");
358  }
359  }
360  // XXX -- HACK END:
361  }
362 }
363 
364 AutoIncrementSetting::AutoIncrementSetting(QString _table, QString _column) :
365  m_table(std::move(_table)), m_column(std::move(_column))
366 {
367  setValue("0");
368 }
369 
370 /******************************************************************************
371  Text Setting
372 *******************************************************************************/
373 
375 {
376  m_passwordEcho = b;
377 }
378 
380 {
381  if (!isEnabled())
382  return;
383 
384  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
385 
386  auto *settingdialog =
387  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
389 
390  if (settingdialog->Create())
391  {
392  settingdialog->SetReturnEvent(screen, "editsetting");
393  popupStack->AddScreen(settingdialog);
394  }
395  else
396  delete settingdialog;
397 }
398 
400 {
401  if (m_settingValue != dce->GetResultText())
402  setValue(dce->GetResultText());
403 }
404 
405 
407 {
409  item->DisplayState("textedit", "widgettype");
410 }
411 
412 
413 /******************************************************************************
414  Directory Setting
415 *******************************************************************************/
416 
418 {
419  if (!isEnabled())
420  return;
421 
422  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
423 
424  auto *settingdialog = new MythUIFileBrowser(popupStack, m_settingValue);
425  settingdialog->SetTypeFilter(m_typeFilter);
426  settingdialog->SetNameFilter(m_nameFilter);
427 
428  if (settingdialog->Create())
429  {
430  settingdialog->SetReturnEvent(screen, "editsetting");
431  popupStack->AddScreen(settingdialog);
432  }
433  else
434  delete settingdialog;
435 }
436 
438 {
439  if (m_settingValue != dce->GetResultText())
440  setValue(dce->GetResultText());
441 }
442 
444 {
446  item->DisplayState("filebrowser", "widgettype");
447 }
448 
449 
450 /******************************************************************************
451  ComboBoxSetting
452 *******************************************************************************/
454 {
455  m_labels.clear();
456  m_values.clear();
457 }
458 
460 {
461  if (value >= 0 && value < m_values.size())
462  {
464  m_isSet = true;
465  }
466 }
467 
468 int MythUIComboBoxSetting::getValueIndex(const QString &value) const
469 {
470  return m_values.indexOf(value);
471 }
472 
474 {
475  int index = getValueIndex(getValue());
476  return (index >= 0) ? m_labels.at(index) : QString("");
477 }
478 
479 void MythUIComboBoxSetting::addSelection(const QString &label, QString value,
480  bool select)
481 {
482  value = value.isEmpty() ? label : value;
483  m_labels.push_back(label);
484  m_values.push_back(value);
485 
486  if (select || !m_isSet)
487  {
489  if (!m_isSet)
490  m_isSet = true;
491  }
492 }
493 
495 {
496  m_isSet = false;
497  m_labels.clear();
498  m_values.clear();
499 }
500 
502 {
503  item->DisplayState("combobox", "widgettype");
504  item->setEnabled(isEnabled());
505  item->SetText(m_label);
506  int indexValue = m_values.indexOf(m_settingValue);
507  if (indexValue >= 0)
508  item->SetText(m_labels.value(indexValue), "value");
509  else
510  item->SetText(m_settingValue, "value");
511  item->SetText(getHelpText(), "description");
512  item->setDrawArrow(haveSubSettings());
513 }
514 
516 {
517  if (!isEnabled())
518  return;
519 
520  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
521 
522  auto *menuPopup = new MythDialogBox(getLabel(), popupStack, "optionmenu");
523 
524  if (menuPopup->Create())
525  {
526  popupStack->AddScreen(menuPopup);
527 
528  //connect(menuPopup, SIGNAL(haveResult(QString)),
529  //SLOT(setValue(QString)));
530 
531  menuPopup->SetReturnEvent(screen, "editsetting");
532 
533  if (m_rewrite)
534  {
535  menuPopup->AddButton(QObject::tr("New entry"),
536  QString("NEWENTRY"),
537  false,
538  m_settingValue == "");
539  }
540  for (int i = 0; i < m_labels.size() && !m_values.empty(); ++i)
541  {
542  QString value = m_values.at(i);
543  menuPopup->AddButton(m_labels.at(i),
544  value,
545  false,
546  value == m_settingValue);
547  }
548  }
549  else
550  delete menuPopup;
551 }
552 
553 void MythUIComboBoxSetting::setValue(const QString& newValue)
554 {
555  StandardSetting::setValue(newValue);
556  m_isSet = true;
557 }
558 
560 {
561  if (dce->GetResult() != -1)
562  {
563  if (m_rewrite && dce->GetData().toString() == "NEWENTRY")
564  {
565  MythScreenStack *popupStack =
566  GetMythMainWindow()->GetStack("popup stack");
567 
568  auto *settingdialog =
569  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
570  false, m_settingValue);
571 
572  if (settingdialog->Create())
573  {
574  connect(settingdialog, SIGNAL(haveResult(QString)),
575  SLOT(setValue(const QString&)));
576  popupStack->AddScreen(settingdialog);
577  }
578  else
579  delete settingdialog;
580  }
581  else if (m_settingValue != dce->GetData().toString())
582  StandardSetting::setValue(dce->GetData().toString());
583  }
584 }
585 
586 void MythUIComboBoxSetting::fillSelectionsFromDir(const QDir &dir, bool absPath)
587 {
588  foreach (auto & fi, dir.entryInfoList())
589  {
590  if (absPath)
591  addSelection( fi.absoluteFilePath() );
592  else
593  addSelection( fi.fileName() );
594  }
595 }
596 
598 {
599  return m_labels.size();
600 }
601 
602 /******************************************************************************
603  SpinBox Setting
604 *******************************************************************************/
606  int step, int pageMultiple,
607  QString special_value_text)
608  : StandardSetting(_storage),
609  m_min(min),
610  m_max(max),
611  m_step(step),
612  m_pageMultiple(pageMultiple),
613  m_specialValueText(std::move(special_value_text))
614 {
615  // We default to 0 unless 0 is out of range.
616  if (m_min > 0 || m_max < 0)
617  m_settingValue = QString::number(m_min);
618 
619  // The settings pages were coded to assume a parameter true/false
620  // meaning allow_single_step. Many pages use this but it was not
621  // implemented. It is difficult to implement using the current
622  // UI widget design. So I have changed it so you can specify
623  // the size of pageup / pagedown increments as an integer instead.
624  // For compatibility with callers still using true to indicate
625  // allowing single step, the code will set the step size as 1 and
626  // the pageup / pagedown as the requested step.
627 
628  if (m_pageMultiple == 1)
629  {
630  m_pageMultiple = step;
631  m_step = 1;
632  }
633  if (m_pageMultiple == 0)
634  {
635  m_pageMultiple = 5;
636  }
637 }
638 
640 {
641  item->DisplayState("spinbox", "widgettype");
642  item->setEnabled(isEnabled());
643  item->SetText(m_label);
644  if (m_settingValue.toInt() == m_min && !m_specialValueText.isEmpty())
645  item->SetText(m_specialValueText, "value");
646  else
647  item->SetText(m_settingValue, "value");
648  item->SetText(getHelpText(), "description");
649  item->setDrawArrow(haveSubSettings());
650 }
651 
653 {
654  return m_settingValue.toInt();
655 }
656 
658 {
659  if (!isEnabled())
660  return;
661 
662  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
663 
664  auto *settingdialog = new MythSpinBoxDialog(popupStack, getLabel());
665 
666  if (settingdialog->Create())
667  {
668  settingdialog->SetRange(m_min, m_max, m_step, m_pageMultiple);
669  if (!m_specialValueText.isEmpty())
670  settingdialog->AddSelection(m_specialValueText, m_min);
671  settingdialog->SetValue(m_settingValue);
672  settingdialog->SetReturnEvent(screen, "editsetting");
673  popupStack->AddScreen(settingdialog);
674  }
675  else
676  delete settingdialog;
677 }
678 
680 {
681  if (m_settingValue != dce->GetResultText())
682  setValue(dce->GetResultText());
683 }
684 
685 /******************************************************************************
686  MythUICheckBoxSetting
687 *******************************************************************************/
688 
690  StandardSetting(_storage)
691 {
692 }
693 
694 void MythUICheckBoxSetting::setValue(const QString &value)
695 {
697  if (haveChanged())
698  emit valueChanged(value == "1");
699 }
700 
702 {
703  StandardSetting::setValue(value ? "1" : "0");
704  if (haveChanged())
705  emit valueChanged(value);
706 }
707 
709 {
711  item->DisplayState("checkbox", "widgettype");
712  item->setCheckable(true);
713  item->SetText("", "value");
714  if (m_settingValue == "1")
716  else
718 }
719 
721 {
722  if (!isEnabled())
723  return;
724 
725  auto *dce = new DialogCompletionEvent("editsetting", 0, "", "");
726  QCoreApplication::postEvent(screen, dce);
727 }
728 
730 {
731  setValue(!boolValue());
732 }
733 
734 /******************************************************************************
735  Standard setting dialog
736 *******************************************************************************/
737 
739 {
740  if (m_settingsTree)
741  m_settingsTree->deleteLater();
742 }
743 
745 {
746  if (!LoadWindowFromXML("standardsetting-ui.xml", "settingssetup", this))
747  return false;
748 
749  bool error = false;
750  UIUtilE::Assign(this, m_title, "title", &error);
751  UIUtilW::Assign(this, m_groupHelp, "grouphelp", &error);
752  UIUtilE::Assign(this, m_buttonList, "settingslist", &error);
753 
754  UIUtilW::Assign(this, m_selectedSettingHelp, "selectedsettinghelp");
755 
756  if (error)
757  {
758  LOG(VB_GENERAL, LOG_ERR, "Theme elements missing.");
759  return false;
760  }
761 
762  connect(m_buttonList, SIGNAL(itemSelected(MythUIButtonListItem*)),
764  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
766 
767  BuildFocusList();
768 
770 
771  return true;
772 }
773 
775 {
776  if (!item)
777  return;
778 
779  auto *setting = item->GetData().value<StandardSetting*>();
780  if (setting && m_selectedSettingHelp)
781  {
782  disconnect(m_selectedSettingHelp);
783  m_selectedSettingHelp->SetText(setting->getHelpText());
785  }
786 }
787 
789 {
790  auto* setting = item->GetData().value<StandardSetting*>();
791  if (setting)
792  setting->edit(this);
793 }
794 
796 {
797  if (event->type() == DialogCompletionEvent::kEventType)
798  {
799  auto *dce = dynamic_cast<DialogCompletionEvent*>(event);
800  if (dce == nullptr)
801  return;
802  QString resultid = dce->GetId();
803 
804  if (resultid == "leveldown")
805  {
806  //a GroupSetting have been clicked
807  LevelDown();
808  }
809  else if (resultid == "editsetting")
810  {
812  if (item)
813  {
814  auto *ss = item->GetData().value<StandardSetting*>();
815  if (ss)
816  ss->resultEdit(dce);
817  }
818  }
819  else if (resultid == "exit")
820  {
821  int buttonnum = dce->GetResult();
822  if (buttonnum == 0)
823  {
824  Save();
826  if (m_settingsTree)
828  }
829  else if (buttonnum == 1)
831  }
832  }
833 }
834 
836 {
837  if (m_settingsTree)
838  {
839  m_settingsTree->Load();
840  m_settingsTree->MoveToThread(QApplication::instance()->thread());
841  }
842 }
843 
845 {
847 }
848 
850 {
851  return m_settingsTree;
852 }
853 
855  StandardSetting *groupSettings, StandardSetting *selectedSetting)
856 {
857  if (!groupSettings)
858  return;
859 
861  {
862  disconnect(m_currentGroupSetting,
863  SIGNAL(settingsChanged(StandardSetting *)), nullptr, nullptr);
865  }
866 
867  m_currentGroupSetting = groupSettings;
869 
871  if (m_groupHelp)
872  {
874  }
875  updateSettings(selectedSetting);
876  connect(m_currentGroupSetting,
877  SIGNAL(settingsChanged(StandardSetting *)),
879 }
880 
882 {
883  m_buttonList->Reset();
885  return;
886 
887  QList<StandardSetting *> *settings =
889  if (!settings)
890  return;
891 
892  QList<StandardSetting *>::const_iterator i;
893  MythUIButtonListItem *selectedItem = nullptr;
894  for (i = settings->constBegin(); i != settings->constEnd(); ++i)
895  {
896  if ((*i)->isVisible())
897  {
898  if (selectedSetting == (*i))
899  selectedItem = (*i)->createButton(m_buttonList);
900  else
901  (*i)->createButton(m_buttonList);
902  }
903  }
904  if (selectedItem)
905  m_buttonList->SetItemCurrent(selectedItem);
907 }
908 
910 {
911  if (m_settingsTree)
912  m_settingsTree->Save();
913 }
914 
916 {
918  return;
919 
921  {
924  }
925 }
926 
928 {
930  if (item)
931  {
932  auto *ss = item->GetData().value<StandardSetting*>();
933  if (ss && ss->haveSubSettings() && ss->isEnabled())
935  }
936 }
937 
939 {
941  {
942  QString label = tr("Exit ?");
943 
944  MythScreenStack *popupStack =
945  GetMythMainWindow()->GetStack("popup stack");
946 
947  auto * menuPopup = new MythDialogBox(label, popupStack, "exitmenu");
948 
949  if (menuPopup->Create())
950  {
951  popupStack->AddScreen(menuPopup);
952 
953  menuPopup->SetReturnEvent(this, "exit");
954 
955  menuPopup->AddButton(tr("Save then Exit"));
956  menuPopup->AddButton(tr("Exit without saving changes"));
957  menuPopup->AddButton(tr("Cancel"));
958  }
959  else
960  delete menuPopup;
961  }
962  else
964 }
965 
966 static QKeyEvent selectEvent
967  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"SELECT"));
968 static QKeyEvent deleteEvent
969  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"DELETE"));
970 
972 {
973  QStringList actions;
974 
975  bool handled = m_buttonList->keyPressEvent(e);
976  if (handled)
977  return true;
978 
979  handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions);
980 
981  //send the key to the selected Item first
983  if (item)
984  {
985  auto *ss = item->GetData().value<StandardSetting*>();
986  if (ss)
987  handled = ss->keyPressEvent(e);
988  }
989  if (handled)
990  return true;
991 
992  for (int i = 0; i < actions.size() && !handled; i++)
993  {
994  QString action = actions[i];
995  handled = true;
996 
997  if (action == "LEFT")
998  {
999  if (m_currentGroupSetting &&
1001  Close();
1002  else
1003  LevelUp();
1004  }
1005  else if (action == "RIGHT")
1006  LevelDown();
1007  else if (action == "EDIT")
1008  {
1010  }
1011  else if (action == "DELETE")
1012  deleteEntry();
1013  else
1014  handled = MythScreenType::keyPressEvent(e);
1015  }
1016 
1017  return handled;
1018 }
1019 
1021 {
1023  if (!item)
1024  return;
1025 
1026  auto *source = item->GetData().value<GroupSetting*>();
1027  if (!source)
1028  return;
1029  // m_title->GetText() for screen title
1030  auto *menu = new MythMenu(source->getLabel(), this, "mainmenu");
1031  menu->AddItem(tr("Edit"), SLOT(editEntry()));
1032  if (source->canDelete())
1033  menu->AddItem(tr("Delete"), SLOT(deleteSelected()));
1034 
1035  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1036 
1037  auto *menuPopup = new MythDialogBox(menu, popupStack, "menudialog");
1038  menuPopup->SetReturnEvent(this, "mainmenu");
1039 
1040  if (menuPopup->Create())
1041  popupStack->AddScreen(menuPopup);
1042  else
1043  delete menuPopup;
1044 }
1045 
1047 {
1049 }
1050 
1052 {
1054 }
1055 
1057 {
1059  if (!item)
1060  return;
1061 
1062  auto *source = item->GetData().value<GroupSetting*>();
1063  if (!source)
1064  return;
1065 
1066  if (source->canDelete())
1067  {
1068  QString message = tr("Do you want to delete the '%1' entry?")
1069  .arg(source->getLabel());
1070  ShowOkPopup(message, this, SLOT(deleteEntryConfirmed(bool)), true);
1071  }
1072 }
1073 
1075 {
1076  if (ok)
1077  {
1079  if (!item)
1080  return;
1081  auto *source = item->GetData().value<GroupSetting*>();
1082  if (!source)
1083  return;
1084  source->deleteEntry();
1085 // m_settingsTree->removeChild(source);
1086  source->getParent()->removeChild(source);
1087  m_buttonList->RemoveItem(item);
1088  }
1089 
1090 }
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
static QKeyEvent deleteEvent(QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,"DELETE"))
void setParent(StandardSetting *parent)
QString getValueLabel(void) const
void edit(MythScreenType *screen) override
void edit(MythScreenType *screen) override
virtual void clearSettings()
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void edit(MythScreenType *screen) override
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
void MoveToThread(QThread *thread)
static void error(const char *str,...)
Definition: vbi.c:42
virtual bool keyPressEvent(QKeyEvent *event)
StandardSetting * getParent() const
void settingsChanged(StandardSetting *selectedSetting=nullptr)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
virtual void Load(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
void edit(MythScreenType *screen) override
virtual bool haveSubSettings()
QVector< QString > m_values
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
QString getLabel(void) const
void setVisible(bool flag)
void setChanged(bool changed)
MythScreenStack * GetStack(const QString &stackname)
void setDrawArrow(bool flag)
MythUIText * m_selectedSettingHelp
int getValueIndex(const QString &value) const
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
MythUISpinBoxSetting(Storage *_storage, int min, int max, int step, int pageMultiple=8, QString special_value_text=QString())
void clearTargetedSettings(const QString &value)
virtual void Open(void)
void settingSelected(MythUIButtonListItem *item)
static MythThemedMenu * menu
void customEvent(QEvent *event) override
void RemoveItem(MythUIButtonListItem *item)
void BuildFocusList(void)
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
static Type kEventType
Definition: mythdialogbox.h:57
void settingClicked(MythUIButtonListItem *item)
void resultEdit(DialogCompletionEvent *dce) override
void setEnabled(bool flag)
virtual QString getValue(void) const
void resultEdit(DialogCompletionEvent *dce) override
virtual void setName(const QString &name)
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
QVariant value(int i) const
Definition: mythdbcon.h:198
virtual void Close()
void setCheckable(bool flag)
void edit(MythScreenType *screen) override
~StandardSetting() override
void LoadInBackground(const QString &message="")
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:888
void setValue(int value) override
virtual int size(void) const
virtual void setLabel(QString str)
StandardSetting * m_currentGroupSetting
void ShouldUpdate(StandardSetting *setting)
ButtonStandardSetting(const QString &label)
virtual void edit(MythScreenType *screen)=0
void valueChanged(const QString &newValue)
bool haveChanged()
Return true if the setting have changed or any of its children.
void Save(void) override
MythUIButtonList * m_buttonList
virtual void applyChange()
void resultEdit(DialogCompletionEvent *dce) override
virtual void setEnabled(bool enabled)
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
void SetText(const QString &text, const QString &name="", const QString &state="")
void fillSelectionsFromDir(const QDir &dir, bool absPath=true)
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
virtual void Save(void)=0
StandardSetting * m_parent
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
virtual void Load(void)=0
bool isEnabled() const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
QList< StandardSetting * > m_children
virtual QList< StandardSetting * > * getSubSettings()
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
virtual void addChild(StandardSetting *child)
void Reset() override
Reset the widget to it's original state, should not reset changes made by the theme.
MythMainWindow * GetMythMainWindow(void)
MythUIButtonListItem * createButton(MythUIButtonList *list)
virtual void Save(void)
void setValue(const QString &newValue) override
void deleteEntryConfirmed(bool ok)
void resultEdit(DialogCompletionEvent *dce) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void resultEdit(DialogCompletionEvent *dce)=0
Dialog prompting the user to enter a text string.
void setVisible(bool visible)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool Create(void) override
void addTargetedChildren(const QString &value, std::initializer_list< StandardSetting * > settings)
void updateSettings(StandardSetting *selectedSetting=nullptr)
void edit(MythScreenType *screen) override
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
GroupSetting * m_settingsTree
GroupSetting * GetGroupSettings(void) const
void removeTargetedChild(const QString &value, StandardSetting *child)
virtual void Close(void)
void ShouldRedraw(StandardSetting *setting)
void SetItemCurrent(MythUIButtonListItem *item)
void edit(MythScreenType *screen) override
Dialog prompting the user to enter a number using a spin box.
void ShowMenu(void) override
QMap< QString, QList< StandardSetting * > > m_targets
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
MythUICheckBoxSetting(Storage *_storage=nullptr)
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
void resultEdit(DialogCompletionEvent *dce) override
Screen in which all other widgets are contained and rendered.
virtual void deleteEntry(void)
void helpTextChanged(const QString &newValue)
void Close(void) override
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:41
static QKeyEvent selectEvent(QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,"SELECT"))
void DisplayState(const QString &state, const QString &name)
void addTargetedChild(const QString &value, StandardSetting *setting)
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
virtual void setValue(const QString &newValue)
void setCurrentGroupSetting(StandardSetting *groupSettings, StandardSetting *selectedSetting=nullptr)
QString getHelpText(void) const
void setChecked(CheckState state)
StandardSetting * byName(const QString &name)
virtual void removeChild(StandardSetting *child)
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
MythUIButtonListItem * GetItemCurrent() const
AutoIncrementSetting(QString _table, QString _column)