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 {
41  item->SetData(qVariantFromValue(this));
42  connect(this, SIGNAL(ShouldRedraw(StandardSetting *)),
43  item, SLOT(ShouldUpdate(StandardSetting *)));
44  updateButton(item);
45  return item;
46 }
47 
48 void StandardSetting::setEnabled(bool enabled)
49 {
50  m_enabled = enabled;
51  emit ShouldRedraw(this);
52 }
53 
54 void StandardSetting::setVisible(bool visible)
55 {
56  m_visible = visible;
57  emit settingsChanged(this);
58 }
59 
61 {
62  m_parent = parent;
63 }
64 
66 {
67  if (!child)
68  return;
69 
70  m_children.append(child);
71  child->setParent(this);
72 }
73 
75 {
76  m_children.removeAll(child);
77  emit settingsChanged(this);
78 }
79 
80 bool StandardSetting::keyPressEvent(QKeyEvent * /*e*/)
81 {
82  return false;
83 }
84 
91 {
92  item->setVisible(m_visible);
93  item->DisplayState("standard", "widgettype");
94  item->setEnabled(isEnabled());
95  item->SetText(m_label);
96  item->SetText(m_settingValue, "value");
97  item->SetText(getHelpText(), "description");
99 }
100 
101 void StandardSetting::addTargetedChildren(const QString &value,
102  std::initializer_list<StandardSetting *> settings)
103 {
104  m_targets[value].reserve(settings.size());
105  foreach (StandardSetting *setting, settings)
106  {
107  m_targets[value].append(setting);
108  setting->setParent(this);
109  }
110 }
111 void StandardSetting::addTargetedChild(const QString &value,
112  StandardSetting * setting)
113 {
114  m_targets[value].append(setting);
115  setting->setParent(this);
116 }
117 
118 void StandardSetting::removeTargetedChild(const QString &value,
119  StandardSetting *child)
120 {
121  if (m_targets.contains(value))
122  {
123  m_targets[value].removeAll(child);
124  delete child;
125  }
126 }
127 
128 void StandardSetting::clearTargetedSettings(const QString &value)
129 {
130  if (m_targets.contains(value))
131  {
132  foreach(StandardSetting *setting, m_targets[value])
133  {
134  delete setting;
135  }
136  m_targets[value].clear();
137  }
138 }
139 
140 QList<StandardSetting *> *StandardSetting::getSubSettings()
141 {
142  if (m_targets.contains(m_settingValue) &&
143  !m_targets[m_settingValue].empty())
144  return &m_targets[m_settingValue];
145  return &m_children;
146 }
147 
149 {
150  QList<StandardSetting *> *subSettings = getSubSettings();
151  return subSettings && !subSettings->empty();
152 }
153 
155 {
156  m_children.clear();
157 }
158 
159 void StandardSetting::setValue(int newValue)
160 {
161  setValue(QString::number(newValue));
162 }
163 
164 void StandardSetting::setValue(const QString &newValue)
165 {
166  if (m_settingValue != newValue)
167  {
168  m_settingValue = newValue;
169  m_haveChanged = true;
170 
171  emit valueChanged(newValue);
172  emit valueChanged(this);
173  }
174  emit ShouldRedraw(this);
175 }
176 
181 {
182  if (m_haveChanged)
183  {
184  LOG(VB_GENERAL, LOG_DEBUG,
185  QString("Setting '%1' changed to %2").arg(getLabel())
186  .arg(getValue()));
187  return true;
188  }
189 
190  //we check only the relevant children
191  QList<StandardSetting *> *children = getSubSettings();
192  if (!children)
193  return false;
194 
195  QList<StandardSetting *>::const_iterator i;
196  bool haveChanged = false;
197  for (i = children->constBegin(); !haveChanged && i != children->constEnd();
198  ++i)
199  haveChanged = (*i)->haveChanged();
200 
201  return haveChanged;
202 }
203 
204 void StandardSetting::setChanged(bool changed)
205 {
206  m_haveChanged = changed;
207 }
208 
210 {
211  if (m_storage)
212  m_storage->Load();
213 
214  m_haveChanged = false;
215 
216  QList<StandardSetting *>::const_iterator i;
217  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
218  (*i)->Load();
219 
220  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
221  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
222  {
223  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
224  (*i)->Load();
225  }
226 }
227 
229 {
230  if (m_storage)
231  m_storage->Save();
232 
233  //we save only the relevant children
234  QList<StandardSetting *> *children = getSubSettings();
235  if (children)
236  {
237  for (auto i = children->constBegin(); i != children->constEnd(); ++i)
238  (*i)->Save();
239  }
240 
241  if (!m_haveChanged)
242  return;
243 
244  m_haveChanged = false;
245  emit ChangeSaved();
246 }
247 
248 void StandardSetting::setName(const QString &name)
249 {
250  m_name = name;
251  if (m_label.isEmpty())
252  setLabel(name);
253 }
254 
256 {
257  if (name == m_name)
258  return this;
259 
260  foreach (StandardSetting *setting, *getSubSettings())
261  {
262  StandardSetting *s = setting->byName(name);
263  if (s)
264  return s;
265  }
266  return nullptr;
267 }
268 
269 void StandardSetting::MoveToThread(QThread *thread)
270 {
271  moveToThread(thread);
272 
273  QList<StandardSetting *>::const_iterator i;
274  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
275  (*i)->MoveToThread(thread);
276 
277  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
278  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
279  {
280  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
281  (*i)->MoveToThread(thread);
282  }
283 }
284 
285 /******************************************************************************
286  Group Setting
287 *******************************************************************************/
289 {
290  if (!isEnabled())
291  return;
292 
293  DialogCompletionEvent *dce =
294  new DialogCompletionEvent("leveldown", 0, "", "");
295  QCoreApplication::postEvent(screen, dce);
296 }
297 
299 {
300  item->DisplayState("group", "widgettype");
301  item->setEnabled(isEnabled());
302  item->SetText(m_label);
303  item->SetText(m_settingValue, "value");
304  item->SetText(getHelpText(), "description");
305  item->setDrawArrow(haveSubSettings());
306 }
307 
309 {
310  setLabel(label);
311 }
312 
314 {
315  emit clicked();
316 }
317 
319 {
320  if (getValue() == "0")
321  {
322  // Generate a new, unique ID
323  QString querystr = "INSERT INTO " + m_table +
324  " (" + m_column + ") VALUES (0);";
325 
326  MSqlQuery query(MSqlQuery::InitCon());
327 
328  if (!query.exec(querystr))
329  {
330  MythDB::DBError("inserting row", query);
331  return;
332  }
333  // XXX -- HACK BEGIN:
334  // lastInsertID fails with "QSqlQuery::value: not positioned on a valid
335  // record" if we get a invalid QVariant we workaround the problem by
336  // taking advantage of mysql always incrementing the auto increment
337  // pointer this breaks if someone modifies the auto increment pointer
338  //setValue(query.lastInsertId().toInt());
339 
340  QVariant var = query.lastInsertId();
341 
342  if (var.type())
343  setValue(var.toInt());
344  else
345  {
346  querystr = "SELECT MAX(" + m_column + ") FROM " +
347  m_table + ";";
348  if (query.exec(querystr) && query.next())
349  {
350  int lii = query.value(0).toInt();
351  lii = lii ? lii : 1;
352  setValue(lii);
353  }
354  else
355  LOG(VB_GENERAL, LOG_EMERG,
356  "Can't determine the Id of the last insert "
357  "QSqlQuery.lastInsertId() failed, the workaround "
358  "failed too!");
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  MythTextInputDialog *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  MythUIFileBrowser *settingdialog = new MythUIFileBrowser(popupStack,
426  settingdialog->SetTypeFilter(m_typeFilter);
427  settingdialog->SetNameFilter(m_nameFilter);
428 
429  if (settingdialog->Create())
430  {
431  settingdialog->SetReturnEvent(screen, "editsetting");
432  popupStack->AddScreen(settingdialog);
433  }
434  else
435  delete settingdialog;
436 }
437 
439 {
440  if (m_settingValue != dce->GetResultText())
441  setValue(dce->GetResultText());
442 }
443 
445 {
447  item->DisplayState("filebrowser", "widgettype");
448 }
449 
450 
451 /******************************************************************************
452  ComboBoxSetting
453 *******************************************************************************/
455 {
456  m_labels.clear();
457  m_values.clear();
458 }
459 
461 {
462  if (value >= 0 && value < m_values.size())
463  {
465  m_isSet = true;
466  }
467 }
468 
469 int MythUIComboBoxSetting::getValueIndex(const QString &value) const
470 {
471  return m_values.indexOf(value);
472 }
473 
475 {
476  int index = getValueIndex(getValue());
477  return (index >= 0) ? m_labels.at(index) : QString("");
478 }
479 
480 void MythUIComboBoxSetting::addSelection(const QString &label, QString value,
481  bool select)
482 {
483  value = value.isEmpty() ? label : value;
484  m_labels.push_back(label);
485  m_values.push_back(value);
486 
487  if (select || !m_isSet)
488  {
490  if (!m_isSet)
491  m_isSet = true;
492  }
493 }
494 
496 {
497  m_isSet = false;
498  m_labels.clear();
499  m_values.clear();
500 }
501 
503 {
504  item->DisplayState("combobox", "widgettype");
505  item->setEnabled(isEnabled());
506  item->SetText(m_label);
507  int indexValue = m_values.indexOf(m_settingValue);
508  if (indexValue >= 0)
509  item->SetText(m_labels.value(indexValue), "value");
510  else
511  item->SetText(m_settingValue, "value");
512  item->SetText(getHelpText(), "description");
513  item->setDrawArrow(haveSubSettings());
514 }
515 
517 {
518  if (!isEnabled())
519  return;
520 
521  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
522 
523  MythDialogBox *menuPopup =
524  new MythDialogBox(getLabel(), popupStack, "optionmenu");
525 
526  if (menuPopup->Create())
527  {
528  popupStack->AddScreen(menuPopup);
529 
530  //connect(menuPopup, SIGNAL(haveResult(QString)),
531  //SLOT(setValue(QString)));
532 
533  menuPopup->SetReturnEvent(screen, "editsetting");
534 
535  if (m_rewrite)
536  menuPopup->AddButton(QObject::tr("New entry"),
537  QString("NEWENTRY"),
538  false,
539  m_settingValue == "");
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  MythTextInputDialog *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  QFileInfoList il = dir.entryInfoList();
589 
590  for (QFileInfoList::Iterator it = il.begin();
591  it != il.end();
592  ++it )
593  {
594  QFileInfo &fi = *it;
595 
596  if (absPath)
597  addSelection( fi.absoluteFilePath() );
598  else
599  addSelection( fi.fileName() );
600  }
601 }
602 
604 {
605  return m_labels.size();
606 }
607 
608 /******************************************************************************
609  SpinBox Setting
610 *******************************************************************************/
612  int step, int pageMultiple,
613  const QString &special_value_text)
614  : StandardSetting(_storage),
615  m_min(min),
616  m_max(max),
617  m_step(step),
618  m_pageMultiple(pageMultiple),
619  m_special_value_text(special_value_text)
620 {
621  //we default to 0 unless 0 is out of range
622  if (m_min > 0 || m_max < 0)
623  m_settingValue = QString::number(m_min);
624 
625  // The setings pages were coded to assume a parameter true/false
626  // meaning allow_single_step. Many pages use this but it was not
627  // implemented. It is difficult to implement using the current
628  // UI widget design. So I have changed it so you can specify
629  // the size of pageup / pagedown increments as an integer instead
630  // For compatibility with callers still using true to indicate
631  // allowing single step, the code will set the step size as 1 and
632  // the pageup / pagedown as the requested step.
633 
634  if (m_pageMultiple == 1)
635  {
636  m_pageMultiple = step;
637  m_step = 1;
638  }
639  if (m_pageMultiple == 0)
640  {
641  m_pageMultiple = 5;
642  }
643 }
644 
646 {
647  item->DisplayState("spinbox", "widgettype");
648  item->setEnabled(isEnabled());
649  item->SetText(m_label);
650  if (m_settingValue.toInt() == m_min && !m_special_value_text.isEmpty())
651  item->SetText(m_special_value_text, "value");
652  else
653  item->SetText(m_settingValue, "value");
654  item->SetText(getHelpText(), "description");
655  item->setDrawArrow(haveSubSettings());
656 }
657 
659 {
660  return m_settingValue.toInt();
661 }
662 
664 {
665  if (!isEnabled())
666  return;
667 
668  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
669 
670  MythSpinBoxDialog *settingdialog = new MythSpinBoxDialog(popupStack,
671  getLabel());
672 
673  if (settingdialog->Create())
674  {
675  settingdialog->SetRange(m_min, m_max, m_step, m_pageMultiple);
676  if (!m_special_value_text.isEmpty())
677  settingdialog->AddSelection(m_special_value_text, m_min);
678  settingdialog->SetValue(m_settingValue);
679  settingdialog->SetReturnEvent(screen, "editsetting");
680  popupStack->AddScreen(settingdialog);
681  }
682  else
683  delete settingdialog;
684 }
685 
687 {
688  if (m_settingValue != dce->GetResultText())
689  setValue(dce->GetResultText());
690 }
691 
692 /******************************************************************************
693  MythUICheckBoxSetting
694 *******************************************************************************/
695 
697  StandardSetting(_storage)
698 {
699 }
700 
701 void MythUICheckBoxSetting::setValue(const QString &value)
702 {
704  if (haveChanged())
705  emit valueChanged(value == "1");
706 }
707 
709 {
710  StandardSetting::setValue(value ? "1" : "0");
711  if (haveChanged())
712  emit valueChanged(value);
713 }
714 
716 {
718  item->DisplayState("checkbox", "widgettype");
719  item->setCheckable(true);
720  item->SetText("", "value");
721  if (m_settingValue == "1")
723  else
725 }
726 
728 {
729  if (!isEnabled())
730  return;
731 
732  DialogCompletionEvent *dce =
733  new DialogCompletionEvent("editsetting", 0, "", "");
734  QCoreApplication::postEvent(screen, dce);
735 }
736 
738 {
739  setValue(!boolValue());
740 }
741 
742 /******************************************************************************
743  Standard setting dialog
744 *******************************************************************************/
745 
747 {
748  if (m_settingsTree)
749  m_settingsTree->deleteLater();
750 }
751 
753 {
754  if (!LoadWindowFromXML("standardsetting-ui.xml", "settingssetup", this))
755  return false;
756 
757  bool error = false;
758  UIUtilE::Assign(this, m_title, "title", &error);
759  UIUtilW::Assign(this, m_groupHelp, "grouphelp", &error);
760  UIUtilE::Assign(this, m_buttonList, "settingslist", &error);
761 
762  UIUtilW::Assign(this, m_selectedSettingHelp, "selectedsettinghelp");
763 
764  if (error)
765  {
766  LOG(VB_GENERAL, LOG_ERR, "Theme elements missing.");
767  return false;
768  }
769 
770  connect(m_buttonList, SIGNAL(itemSelected(MythUIButtonListItem*)),
772  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
774 
775  BuildFocusList();
776 
778 
779  return true;
780 }
781 
783 {
784  if (!item)
785  return;
786 
787  StandardSetting *setting = item->GetData().value<StandardSetting*>();
788  if (setting && m_selectedSettingHelp)
789  {
791  }
792 }
793 
795 {
796  StandardSetting* setting = item->GetData().value<StandardSetting*>();
797  if (setting)
798  setting->edit(this);
799 }
800 
802 {
803  if (event->type() == DialogCompletionEvent::kEventType)
804  {
806  QString resultid = dce->GetId();
807 
808  if (resultid == "leveldown")
809  {
810  //a GroupSetting have been clicked
811  LevelDown();
812  }
813  else if (resultid == "editsetting")
814  {
816  if (item)
817  {
818  StandardSetting *ss = item->GetData().value<StandardSetting*>();
819  if (ss)
820  ss->resultEdit(dce);
821  }
822  }
823  else if (resultid == "exit")
824  {
825  int buttonnum = dce->GetResult();
826  if (buttonnum == 0)
827  {
828  Save();
830  if (m_settingsTree)
832  }
833  else if (buttonnum == 1)
835  }
836  }
837 }
838 
840 {
841  if (m_settingsTree)
842  {
843  m_settingsTree->Load();
844  m_settingsTree->MoveToThread(QApplication::instance()->thread());
845  }
846 }
847 
849 {
851 }
852 
854 {
855  return m_settingsTree;
856 }
857 
859  StandardSetting *groupSettings, StandardSetting *selectedSetting)
860 {
861  if (!groupSettings)
862  return;
863 
865  {
866  disconnect(m_currentGroupSetting,
867  SIGNAL(settingsChanged(StandardSetting *)), nullptr, nullptr);
869  }
870 
871  m_currentGroupSetting = groupSettings;
873 
875  if (m_groupHelp)
876  {
878  }
879  updateSettings(selectedSetting);
880  connect(m_currentGroupSetting,
881  SIGNAL(settingsChanged(StandardSetting *)),
883 }
884 
886 {
887  m_buttonList->Reset();
889  return;
890 
891  QList<StandardSetting *> *settings =
893  if (!settings)
894  return;
895 
896  QList<StandardSetting *>::const_iterator i;
897  MythUIButtonListItem *selectedItem = nullptr;
898  for (i = settings->constBegin(); i != settings->constEnd(); ++i)
899  {
900  if ((*i)->isVisible())
901  {
902  if (selectedSetting == (*i))
903  selectedItem = (*i)->createButton(m_buttonList);
904  else
905  (*i)->createButton(m_buttonList);
906  }
907  }
908  if (selectedItem)
909  m_buttonList->SetItemCurrent(selectedItem);
911 }
912 
914 {
915  if (m_settingsTree)
916  m_settingsTree->Save();
917 }
918 
920 {
922  return;
923 
925  {
928  }
929 }
930 
932 {
934  if (item)
935  {
936  StandardSetting *ss = item->GetData().value<StandardSetting*>();
937  if (ss && ss->haveSubSettings() && ss->isEnabled())
939  }
940 }
941 
943 {
945  {
946  QString label = tr("Exit ?");
947 
948  MythScreenStack *popupStack =
949  GetMythMainWindow()->GetStack("popup stack");
950 
951  MythDialogBox * menuPopup =
952  new MythDialogBox(label, popupStack, "exitmenu");
953 
954  if (menuPopup->Create())
955  {
956  popupStack->AddScreen(menuPopup);
957 
958  menuPopup->SetReturnEvent(this, "exit");
959 
960  menuPopup->AddButton(tr("Save then Exit"));
961  menuPopup->AddButton(tr("Exit without saving changes"));
962  menuPopup->AddButton(tr("Cancel"));
963  }
964  else
965  delete menuPopup;
966  }
967  else
969 }
970 
971 static QKeyEvent selectEvent
972  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"SELECT"));
973 static QKeyEvent deleteEvent
974  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"DELETE"));
975 
977 {
978  QStringList actions;
979 
980  bool handled = m_buttonList->keyPressEvent(e);
981  if (handled)
982  return true;
983 
984  handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions);
985 
986  //send the key to the selected Item first
988  if (item)
989  {
990  StandardSetting *ss = item->GetData().value<StandardSetting*>();
991  if (ss)
992  handled = ss->keyPressEvent(e);
993  }
994  if (handled)
995  return true;
996 
997  for (int i = 0; i < actions.size() && !handled; i++)
998  {
999  QString action = actions[i];
1000  handled = true;
1001 
1002  if (action == "LEFT")
1003  {
1004  if (m_currentGroupSetting &&
1006  Close();
1007  else
1008  LevelUp();
1009  }
1010  else if (action == "RIGHT")
1011  LevelDown();
1012  else if (action == "EDIT")
1013  {
1015  }
1016  else if (action == "DELETE")
1017  deleteEntry();
1018  else
1019  handled = MythScreenType::keyPressEvent(e);
1020  }
1021 
1022  return handled;
1023 }
1024 
1026 {
1028  if (!item)
1029  return;
1030 
1031  GroupSetting *source = item->GetData().value<GroupSetting*>();
1032  if (!source)
1033  return;
1034  // m_title->GetText() for screen title
1035  MythMenu *menu = new MythMenu(source->getLabel(), this, "mainmenu");
1036  menu->AddItem(tr("Edit"), SLOT(editEntry()));
1037  if (source->canDelete())
1038  menu->AddItem(tr("Delete"), SLOT(deleteSelected()));
1039 
1040  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1041 
1042  MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack,
1043  "menudialog");
1044  menuPopup->SetReturnEvent(this, "mainmenu");
1045 
1046  if (menuPopup->Create())
1047  popupStack->AddScreen(menuPopup);
1048  else
1049  delete menuPopup;
1050 }
1051 
1053 {
1055 }
1056 
1058 {
1060 }
1061 
1063 {
1065  if (!item)
1066  return;
1067 
1068  GroupSetting *source = item->GetData().value<GroupSetting*>();
1069  if (!source)
1070  return;
1071 
1072  if (source->canDelete())
1073  {
1074  QString message = tr("Do you want to delete the '%1' entry?")
1075  .arg(source->getLabel());
1076  ShowOkPopup(message, this, SLOT(deleteEntryConfirmed(bool)), true);
1077  }
1078 }
1079 
1081 {
1082  if (ok)
1083  {
1085  if (!item)
1086  return;
1087  GroupSetting *source = item->GetData().value<GroupSetting*>();
1088  if (!source)
1089  return;
1090  source->deleteEntry();
1091 // m_settingsTree->removeChild(source);
1092  source->getParent()->removeChild(source);
1093  m_buttonList->RemoveItem(item);
1094  }
1095 
1096 }
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
void AddSelection(const QString &label, int value)
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 canDelete(void)
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)
void SetData(QVariant data)
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)
void SetReturnEvent(QObject *retobject, const QString &resultid)
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:136
bool Create(void) override
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 ...
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
unsigned char b
Definition: ParseText.cpp:329
void resultEdit(DialogCompletionEvent *dce) override
virtual void setName(const QString &name)
void SetNameFilter(QStringList filter)
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 AddButton(const QString &title, QVariant data=0, bool newMenu=false, bool setCurrent=false)
void edit(MythScreenType *screen) override
bool Create(void) override
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 ShouldUpdate(StandardSetting *setting)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
void SetReturnEvent(QObject *retobject, const QString &resultid)
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
void SetTypeFilter(QDir::Filters filter)
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
const char * name
Definition: ParseText.cpp:328
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)
MythUISpinBoxSetting(Storage *_storage, int min, int max, int step, int pageMultiple=8, const QString &special_value_text=QString())
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 SetReturnEvent(QObject *retobject, const QString &resultid)
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
void SetValue(const QString &value)
Can be called only after MythSpinBoxDialog::Create() return successfully The range need to be set bef...
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 SetRange(int low, int high, int step, uint pageMultiple=5)
Set the lower and upper bounds of the spinbox, the interval and page amount.
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()
bool Create(void) override
void setCurrentGroupSetting(StandardSetting *groupSettings, StandardSetting *selectedSetting=nullptr)
void SetReturnEvent(QObject *retobject, const QString &resultid)
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
void LoadInBackground(QString message="")
bool Create(void) override
AutoIncrementSetting(QString _table, QString _column)
void valueChanged(const QString &)