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(qVariantFromValue(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  LOG(VB_GENERAL, LOG_EMERG,
354  "Can't determine the Id of the last insert "
355  "QSqlQuery.lastInsertId() failed, the workaround "
356  "failed too!");
357  }
358  // XXX -- HACK END:
359  }
360 }
361 
362 AutoIncrementSetting::AutoIncrementSetting(QString _table, QString _column) :
363  m_table(std::move(_table)), m_column(std::move(_column))
364 {
365  setValue("0");
366 }
367 
368 /******************************************************************************
369  Text Setting
370 *******************************************************************************/
371 
373 {
374  m_passwordEcho = b;
375 }
376 
378 {
379  if (!isEnabled())
380  return;
381 
382  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
383 
384  auto *settingdialog =
385  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
387 
388  if (settingdialog->Create())
389  {
390  settingdialog->SetReturnEvent(screen, "editsetting");
391  popupStack->AddScreen(settingdialog);
392  }
393  else
394  delete settingdialog;
395 }
396 
398 {
399  if (m_settingValue != dce->GetResultText())
400  setValue(dce->GetResultText());
401 }
402 
403 
405 {
407  item->DisplayState("textedit", "widgettype");
408 }
409 
410 
411 /******************************************************************************
412  Directory Setting
413 *******************************************************************************/
414 
416 {
417  if (!isEnabled())
418  return;
419 
420  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
421 
422  auto *settingdialog = new MythUIFileBrowser(popupStack, m_settingValue);
423  settingdialog->SetTypeFilter(m_typeFilter);
424  settingdialog->SetNameFilter(m_nameFilter);
425 
426  if (settingdialog->Create())
427  {
428  settingdialog->SetReturnEvent(screen, "editsetting");
429  popupStack->AddScreen(settingdialog);
430  }
431  else
432  delete settingdialog;
433 }
434 
436 {
437  if (m_settingValue != dce->GetResultText())
438  setValue(dce->GetResultText());
439 }
440 
442 {
444  item->DisplayState("filebrowser", "widgettype");
445 }
446 
447 
448 /******************************************************************************
449  ComboBoxSetting
450 *******************************************************************************/
452 {
453  m_labels.clear();
454  m_values.clear();
455 }
456 
458 {
459  if (value >= 0 && value < m_values.size())
460  {
462  m_isSet = true;
463  }
464 }
465 
466 int MythUIComboBoxSetting::getValueIndex(const QString &value) const
467 {
468  return m_values.indexOf(value);
469 }
470 
472 {
473  int index = getValueIndex(getValue());
474  return (index >= 0) ? m_labels.at(index) : QString("");
475 }
476 
477 void MythUIComboBoxSetting::addSelection(const QString &label, QString value,
478  bool select)
479 {
480  value = value.isEmpty() ? label : value;
481  m_labels.push_back(label);
482  m_values.push_back(value);
483 
484  if (select || !m_isSet)
485  {
487  if (!m_isSet)
488  m_isSet = true;
489  }
490 }
491 
493 {
494  m_isSet = false;
495  m_labels.clear();
496  m_values.clear();
497 }
498 
500 {
501  item->DisplayState("combobox", "widgettype");
502  item->setEnabled(isEnabled());
503  item->SetText(m_label);
504  int indexValue = m_values.indexOf(m_settingValue);
505  if (indexValue >= 0)
506  item->SetText(m_labels.value(indexValue), "value");
507  else
508  item->SetText(m_settingValue, "value");
509  item->SetText(getHelpText(), "description");
510  item->setDrawArrow(haveSubSettings());
511 }
512 
514 {
515  if (!isEnabled())
516  return;
517 
518  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
519 
520  auto *menuPopup = new MythDialogBox(getLabel(), popupStack, "optionmenu");
521 
522  if (menuPopup->Create())
523  {
524  popupStack->AddScreen(menuPopup);
525 
526  //connect(menuPopup, SIGNAL(haveResult(QString)),
527  //SLOT(setValue(QString)));
528 
529  menuPopup->SetReturnEvent(screen, "editsetting");
530 
531  if (m_rewrite)
532  menuPopup->AddButton(QObject::tr("New entry"),
533  QString("NEWENTRY"),
534  false,
535  m_settingValue == "");
536  for (int i = 0; i < m_labels.size() && !m_values.empty(); ++i)
537  {
538  QString value = m_values.at(i);
539  menuPopup->AddButton(m_labels.at(i),
540  value,
541  false,
542  value == m_settingValue);
543  }
544  }
545  else
546  delete menuPopup;
547 }
548 
549 void MythUIComboBoxSetting::setValue(const QString& newValue)
550 {
551  StandardSetting::setValue(newValue);
552  m_isSet = true;
553 }
554 
556 {
557  if (dce->GetResult() != -1)
558  {
559  if (m_rewrite && dce->GetData().toString() == "NEWENTRY")
560  {
561  MythScreenStack *popupStack =
562  GetMythMainWindow()->GetStack("popup stack");
563 
564  auto *settingdialog =
565  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
566  false, m_settingValue);
567 
568  if (settingdialog->Create())
569  {
570  connect(settingdialog, SIGNAL(haveResult(QString)),
571  SLOT(setValue(const QString&)));
572  popupStack->AddScreen(settingdialog);
573  }
574  else
575  delete settingdialog;
576  }
577  else if (m_settingValue != dce->GetData().toString())
578  StandardSetting::setValue(dce->GetData().toString());
579  }
580 }
581 
582 void MythUIComboBoxSetting::fillSelectionsFromDir(const QDir &dir, bool absPath)
583 {
584  QFileInfoList il = dir.entryInfoList();
585 
586  for (QFileInfoList::Iterator it = il.begin();
587  it != il.end();
588  ++it )
589  {
590  QFileInfo &fi = *it;
591 
592  if (absPath)
593  addSelection( fi.absoluteFilePath() );
594  else
595  addSelection( fi.fileName() );
596  }
597 }
598 
600 {
601  return m_labels.size();
602 }
603 
604 /******************************************************************************
605  SpinBox Setting
606 *******************************************************************************/
608  int step, int pageMultiple,
609  QString special_value_text)
610  : StandardSetting(_storage),
611  m_min(min),
612  m_max(max),
613  m_step(step),
614  m_pageMultiple(pageMultiple),
615  m_specialValueText(std::move(special_value_text))
616 {
617  // We default to 0 unless 0 is out of range.
618  if (m_min > 0 || m_max < 0)
619  m_settingValue = QString::number(m_min);
620 
621  // The settings pages were coded to assume a parameter true/false
622  // meaning allow_single_step. Many pages use this but it was not
623  // implemented. It is difficult to implement using the current
624  // UI widget design. So I have changed it so you can specify
625  // the size of pageup / pagedown increments as an integer instead.
626  // For compatibility with callers still using true to indicate
627  // allowing single step, the code will set the step size as 1 and
628  // the pageup / pagedown as the requested step.
629 
630  if (m_pageMultiple == 1)
631  {
632  m_pageMultiple = step;
633  m_step = 1;
634  }
635  if (m_pageMultiple == 0)
636  {
637  m_pageMultiple = 5;
638  }
639 }
640 
642 {
643  item->DisplayState("spinbox", "widgettype");
644  item->setEnabled(isEnabled());
645  item->SetText(m_label);
646  if (m_settingValue.toInt() == m_min && !m_specialValueText.isEmpty())
647  item->SetText(m_specialValueText, "value");
648  else
649  item->SetText(m_settingValue, "value");
650  item->SetText(getHelpText(), "description");
651  item->setDrawArrow(haveSubSettings());
652 }
653 
655 {
656  return m_settingValue.toInt();
657 }
658 
660 {
661  if (!isEnabled())
662  return;
663 
664  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
665 
666  auto *settingdialog = new MythSpinBoxDialog(popupStack, getLabel());
667 
668  if (settingdialog->Create())
669  {
670  settingdialog->SetRange(m_min, m_max, m_step, m_pageMultiple);
671  if (!m_specialValueText.isEmpty())
672  settingdialog->AddSelection(m_specialValueText, m_min);
673  settingdialog->SetValue(m_settingValue);
674  settingdialog->SetReturnEvent(screen, "editsetting");
675  popupStack->AddScreen(settingdialog);
676  }
677  else
678  delete settingdialog;
679 }
680 
682 {
683  if (m_settingValue != dce->GetResultText())
684  setValue(dce->GetResultText());
685 }
686 
687 /******************************************************************************
688  MythUICheckBoxSetting
689 *******************************************************************************/
690 
692  StandardSetting(_storage)
693 {
694 }
695 
696 void MythUICheckBoxSetting::setValue(const QString &value)
697 {
699  if (haveChanged())
700  emit valueChanged(value == "1");
701 }
702 
704 {
705  StandardSetting::setValue(value ? "1" : "0");
706  if (haveChanged())
707  emit valueChanged(value);
708 }
709 
711 {
713  item->DisplayState("checkbox", "widgettype");
714  item->setCheckable(true);
715  item->SetText("", "value");
716  if (m_settingValue == "1")
718  else
720 }
721 
723 {
724  if (!isEnabled())
725  return;
726 
727  auto *dce = new DialogCompletionEvent("editsetting", 0, "", "");
728  QCoreApplication::postEvent(screen, dce);
729 }
730 
732 {
733  setValue(!boolValue());
734 }
735 
736 /******************************************************************************
737  Standard setting dialog
738 *******************************************************************************/
739 
741 {
742  if (m_settingsTree)
743  m_settingsTree->deleteLater();
744 }
745 
747 {
748  if (!LoadWindowFromXML("standardsetting-ui.xml", "settingssetup", this))
749  return false;
750 
751  bool error = false;
752  UIUtilE::Assign(this, m_title, "title", &error);
753  UIUtilW::Assign(this, m_groupHelp, "grouphelp", &error);
754  UIUtilE::Assign(this, m_buttonList, "settingslist", &error);
755 
756  UIUtilW::Assign(this, m_selectedSettingHelp, "selectedsettinghelp");
757 
758  if (error)
759  {
760  LOG(VB_GENERAL, LOG_ERR, "Theme elements missing.");
761  return false;
762  }
763 
764  connect(m_buttonList, SIGNAL(itemSelected(MythUIButtonListItem*)),
766  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
768 
769  BuildFocusList();
770 
772 
773  return true;
774 }
775 
777 {
778  if (!item)
779  return;
780 
781  auto *setting = item->GetData().value<StandardSetting*>();
782  if (setting && m_selectedSettingHelp)
783  {
784  disconnect(m_selectedSettingHelp);
785  m_selectedSettingHelp->SetText(setting->getHelpText());
787  }
788 }
789 
791 {
792  auto* setting = item->GetData().value<StandardSetting*>();
793  if (setting)
794  setting->edit(this);
795 }
796 
798 {
799  if (event->type() == DialogCompletionEvent::kEventType)
800  {
801  auto dce = dynamic_cast<DialogCompletionEvent*>(event);
802  if (dce == nullptr)
803  return;
804  QString resultid = dce->GetId();
805 
806  if (resultid == "leveldown")
807  {
808  //a GroupSetting have been clicked
809  LevelDown();
810  }
811  else if (resultid == "editsetting")
812  {
814  if (item)
815  {
816  auto *ss = item->GetData().value<StandardSetting*>();
817  if (ss)
818  ss->resultEdit(dce);
819  }
820  }
821  else if (resultid == "exit")
822  {
823  int buttonnum = dce->GetResult();
824  if (buttonnum == 0)
825  {
826  Save();
828  if (m_settingsTree)
830  }
831  else if (buttonnum == 1)
833  }
834  }
835 }
836 
838 {
839  if (m_settingsTree)
840  {
841  m_settingsTree->Load();
842  m_settingsTree->MoveToThread(QApplication::instance()->thread());
843  }
844 }
845 
847 {
849 }
850 
852 {
853  return m_settingsTree;
854 }
855 
857  StandardSetting *groupSettings, StandardSetting *selectedSetting)
858 {
859  if (!groupSettings)
860  return;
861 
863  {
864  disconnect(m_currentGroupSetting,
865  SIGNAL(settingsChanged(StandardSetting *)), nullptr, nullptr);
867  }
868 
869  m_currentGroupSetting = groupSettings;
871 
873  if (m_groupHelp)
874  {
876  }
877  updateSettings(selectedSetting);
878  connect(m_currentGroupSetting,
879  SIGNAL(settingsChanged(StandardSetting *)),
881 }
882 
884 {
885  m_buttonList->Reset();
887  return;
888 
889  QList<StandardSetting *> *settings =
891  if (!settings)
892  return;
893 
894  QList<StandardSetting *>::const_iterator i;
895  MythUIButtonListItem *selectedItem = nullptr;
896  for (i = settings->constBegin(); i != settings->constEnd(); ++i)
897  {
898  if ((*i)->isVisible())
899  {
900  if (selectedSetting == (*i))
901  selectedItem = (*i)->createButton(m_buttonList);
902  else
903  (*i)->createButton(m_buttonList);
904  }
905  }
906  if (selectedItem)
907  m_buttonList->SetItemCurrent(selectedItem);
909 }
910 
912 {
913  if (m_settingsTree)
914  m_settingsTree->Save();
915 }
916 
918 {
920  return;
921 
923  {
926  }
927 }
928 
930 {
932  if (item)
933  {
934  auto *ss = item->GetData().value<StandardSetting*>();
935  if (ss && ss->haveSubSettings() && ss->isEnabled())
937  }
938 }
939 
941 {
943  {
944  QString label = tr("Exit ?");
945 
946  MythScreenStack *popupStack =
947  GetMythMainWindow()->GetStack("popup stack");
948 
949  auto * menuPopup = new MythDialogBox(label, popupStack, "exitmenu");
950 
951  if (menuPopup->Create())
952  {
953  popupStack->AddScreen(menuPopup);
954 
955  menuPopup->SetReturnEvent(this, "exit");
956 
957  menuPopup->AddButton(tr("Save then Exit"));
958  menuPopup->AddButton(tr("Exit without saving changes"));
959  menuPopup->AddButton(tr("Cancel"));
960  }
961  else
962  delete menuPopup;
963  }
964  else
966 }
967 
968 static QKeyEvent selectEvent
969  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"SELECT"));
970 static QKeyEvent deleteEvent
971  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"DELETE"));
972 
974 {
975  QStringList actions;
976 
977  bool handled = m_buttonList->keyPressEvent(e);
978  if (handled)
979  return true;
980 
981  handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions);
982 
983  //send the key to the selected Item first
985  if (item)
986  {
987  auto *ss = item->GetData().value<StandardSetting*>();
988  if (ss)
989  handled = ss->keyPressEvent(e);
990  }
991  if (handled)
992  return true;
993 
994  for (int i = 0; i < actions.size() && !handled; i++)
995  {
996  QString action = actions[i];
997  handled = true;
998 
999  if (action == "LEFT")
1000  {
1001  if (m_currentGroupSetting &&
1003  Close();
1004  else
1005  LevelUp();
1006  }
1007  else if (action == "RIGHT")
1008  LevelDown();
1009  else if (action == "EDIT")
1010  {
1012  }
1013  else if (action == "DELETE")
1014  deleteEntry();
1015  else
1016  handled = MythScreenType::keyPressEvent(e);
1017  }
1018 
1019  return handled;
1020 }
1021 
1023 {
1025  if (!item)
1026  return;
1027 
1028  auto *source = item->GetData().value<GroupSetting*>();
1029  if (!source)
1030  return;
1031  // m_title->GetText() for screen title
1032  auto *menu = new MythMenu(source->getLabel(), this, "mainmenu");
1033  menu->AddItem(tr("Edit"), SLOT(editEntry()));
1034  if (source->canDelete())
1035  menu->AddItem(tr("Delete"), SLOT(deleteSelected()));
1036 
1037  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1038 
1039  auto *menuPopup = new MythDialogBox(menu, popupStack, "menudialog");
1040  menuPopup->SetReturnEvent(this, "mainmenu");
1041 
1042  if (menuPopup->Create())
1043  popupStack->AddScreen(menuPopup);
1044  else
1045  delete menuPopup;
1046 }
1047 
1049 {
1051 }
1052 
1054 {
1056 }
1057 
1059 {
1061  if (!item)
1062  return;
1063 
1064  auto *source = item->GetData().value<GroupSetting*>();
1065  if (!source)
1066  return;
1067 
1068  if (source->canDelete())
1069  {
1070  QString message = tr("Do you want to delete the '%1' entry?")
1071  .arg(source->getLabel());
1072  ShowOkPopup(message, this, SLOT(deleteEntryConfirmed(bool)), true);
1073  }
1074 }
1075 
1077 {
1078  if (ok)
1079  {
1081  if (!item)
1082  return;
1083  auto *source = item->GetData().value<GroupSetting*>();
1084  if (!source)
1085  return;
1086  source->deleteEntry();
1087 // m_settingsTree->removeChild(source);
1088  source->getParent()->removeChild(source);
1089  m_buttonList->RemoveItem(item);
1090  }
1091 
1092 }
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:782
static QKeyEvent deleteEvent(QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,"DELETE"))
void setParent(StandardSetting *parent)
QString getValueLabel(void) const
virtual bool keyPressEvent(QKeyEvent *)
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
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:50
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
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 ...
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:887
void ShouldRedraw(StandardSetting *)
void setValue(int value) override
virtual int size(void) const
virtual void setLabel(QString str)
StandardSetting * m_currentGroupSetting
void helpTextChanged(const QString &)
void ShouldUpdate(StandardSetting *setting)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
ButtonStandardSetting(const QString &label)
virtual void edit(MythScreenType *screen)=0
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=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 deleteEntryConfirmed(bool ok)
void resultEdit(DialogCompletionEvent *dce) override
virtual void resultEdit(DialogCompletionEvent *dce)=0
Dialog prompting the user to enter a text string.
void setVisible(bool visible)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#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 SetItemCurrent(MythUIButtonListItem *item)
void setValue(const QString &) override
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 Close(void) override
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
Definition: mythdialogbox.h:37
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)
virtual ~StandardSetting()
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)
void valueChanged(const QString &)