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 
6 #include <mythcontext.h>
7 #include <mythmainwindow.h>
8 #include <mythdialogbox.h>
9 #include <mythuispinbox.h>
10 #include <mythuitext.h>
11 #include <mythuibutton.h>
12 #include <mythuifilebrowser.h>
13 #include "mythlogging.h"
14 
16 {
17  setting->updateButton(this);
18 }
19 
21  m_settingValue(""),
22  m_enabled(true), m_label(""), m_helptext(""), m_visible(true),
23  m_haveChanged(false),
24  m_storage(_storage),
25  m_parent(nullptr)
26 {
27 }
28 
30 {
31  QList<StandardSetting *>::const_iterator i;
32  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
33  delete *i;
34  m_children.clear();
35 
36  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
37  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
38  {
39  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
40  delete *i;
41  }
42  m_targets.clear();
43 }
44 
46 {
49  item->SetData(qVariantFromValue(this));
50  connect(this, SIGNAL(ShouldRedraw(StandardSetting *)),
51  item, SLOT(ShouldUpdate(StandardSetting *)));
52  updateButton(item);
53  return item;
54 }
55 
57 {
58  m_enabled = b;
59  emit ShouldRedraw(this);
60 }
61 
62 void StandardSetting::setVisible(bool visible)
63 {
64  m_visible = visible;
65  emit settingsChanged(this);
66 }
67 
69 {
70  m_parent = parent;
71 }
72 
74 {
75  if (!child)
76  return;
77 
78  m_children.append(child);
79  child->setParent(this);
80 }
81 
83 {
84  m_children.removeAll(child);
85  emit settingsChanged(this);
86 }
87 
89 {
90  return false;
91 }
92 
99 {
100  item->setVisible(m_visible);
101  item->DisplayState("standard", "widgettype");
102  item->setEnabled(isEnabled());
103  item->SetText(m_label);
104  item->SetText(m_settingValue, "value");
105  item->SetText(getHelpText(), "description");
106  item->setDrawArrow(haveSubSettings());
107 }
108 
109 void StandardSetting::addTargetedChildren(const QString &value,
110  std::initializer_list<StandardSetting *> settings)
111 {
112  m_targets[value].reserve(settings.size());
113  foreach (StandardSetting *setting, settings)
114  {
115  m_targets[value].append(setting);
116  setting->setParent(this);
117  }
118 }
119 void StandardSetting::addTargetedChild(const QString &value,
120  StandardSetting * setting)
121 {
122  m_targets[value].append(setting);
123  setting->setParent(this);
124 }
125 
126 void StandardSetting::removeTargetedChild(const QString &value,
127  StandardSetting *child)
128 {
129  if (m_targets.contains(value))
130  {
131  m_targets[value].removeAll(child);
132  delete child;
133  }
134 }
135 
136 void StandardSetting::clearTargetedSettings(const QString &value)
137 {
138  if (m_targets.contains(value))
139  {
140  foreach(StandardSetting *setting, m_targets[value])
141  {
142  delete setting;
143  }
144  m_targets[value].clear();
145  }
146 }
147 
148 QList<StandardSetting *> *StandardSetting::getSubSettings()
149 {
150  if (m_targets.contains(m_settingValue) &&
151  m_targets[m_settingValue].size() > 0)
152  return &m_targets[m_settingValue];
153  return &m_children;
154 }
155 
157 {
158  QList<StandardSetting *> *subSettings = getSubSettings();
159  return subSettings && subSettings->size() > 0;
160 }
161 
163 {
164  m_children.clear();
165 }
166 
167 void StandardSetting::setValue(int newValue)
168 {
169  setValue(QString::number(newValue));
170 }
171 
172 void StandardSetting::setValue(const QString &newValue)
173 {
174  if (m_settingValue != newValue)
175  {
176  m_settingValue = newValue;
177  m_haveChanged = true;
178 
179  emit valueChanged(newValue);
180  emit valueChanged(this);
181  }
182  emit ShouldRedraw(this);
183 }
184 
189 {
190  if (m_haveChanged)
191  {
192  LOG(VB_GENERAL, LOG_DEBUG,
193  QString("Setting %1 changed to %2").arg(getLabel())
194  .arg(getValue()));
195  return true;
196  }
197 
198  //we check only the relevant children
199  QList<StandardSetting *> *children = getSubSettings();
200  if (!children)
201  return false;
202 
203  QList<StandardSetting *>::const_iterator i;
204  bool haveChanged = false;
205  for (i = children->constBegin(); !haveChanged && i != children->constEnd();
206  ++i)
207  haveChanged = (*i)->haveChanged();
208 
209  return haveChanged;
210 }
211 
212 void StandardSetting::setChanged(bool changed)
213 {
214  m_haveChanged = changed;
215 }
216 
218 {
219  if (m_storage)
220  m_storage->Load();
221 
222  m_haveChanged = false;
223 
224  QList<StandardSetting *>::const_iterator i;
225  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
226  (*i)->Load();
227 
228  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
229  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
230  {
231  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
232  (*i)->Load();
233  }
234 }
235 
237 {
238  if (m_storage)
239  m_storage->Save();
240 
241  //we save only the relevant children
242  QList<StandardSetting *> *children = getSubSettings();
243  if (children)
244  {
245  for (auto i = children->constBegin(); i != children->constEnd(); ++i)
246  (*i)->Save();
247  }
248 
249  if (!m_haveChanged)
250  return;
251 
252  m_haveChanged = false;
253  emit ChangeSaved();
254 }
255 
256 void StandardSetting::setName(const QString &name)
257 {
258  m_name = name;
259  if (m_label.isEmpty())
260  setLabel(name);
261 }
262 
264 {
265  if (name == m_name)
266  return this;
267 
268  foreach (StandardSetting *setting, *getSubSettings())
269  {
270  StandardSetting *s = setting->byName(name);
271  if (s)
272  return s;
273  }
274  return nullptr;
275 }
276 
277 void StandardSetting::MoveToThread(QThread *thread)
278 {
279  moveToThread(thread);
280 
281  QList<StandardSetting *>::const_iterator i;
282  for (i = m_children.constBegin(); i != m_children.constEnd(); ++i)
283  (*i)->MoveToThread(thread);
284 
285  QMap<QString, QList<StandardSetting *> >::const_iterator iMap;
286  for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap)
287  {
288  for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i)
289  (*i)->MoveToThread(thread);
290  }
291 }
292 
293 /******************************************************************************
294  Group Setting
295 *******************************************************************************/
297 {
298  if (!isEnabled())
299  return;
300 
301  DialogCompletionEvent *dce =
302  new DialogCompletionEvent("leveldown", 0, "", "");
303  QCoreApplication::postEvent(screen, dce);
304 }
305 
307 {
308  item->DisplayState("group", "widgettype");
309  item->setEnabled(isEnabled());
310  item->SetText(m_label);
311  item->SetText(m_settingValue, "value");
312  item->SetText(getHelpText(), "description");
313  item->setDrawArrow(haveSubSettings());
314 }
315 
317 {
318  setLabel(label);
319 }
320 
322 {
323  emit clicked();
324 }
325 
327 {
328  if (getValue() == "0")
329  {
330  // Generate a new, unique ID
331  QString querystr = "INSERT INTO " + m_table +
332  " (" + m_column + ") VALUES (0);";
333 
334  MSqlQuery query(MSqlQuery::InitCon());
335 
336  if (!query.exec(querystr))
337  {
338  MythDB::DBError("inserting row", query);
339  return;
340  }
341  // XXX -- HACK BEGIN:
342  // lastInsertID fails with "QSqlQuery::value: not positioned on a valid
343  // record" if we get a invalid QVariant we workaround the problem by
344  // taking advantage of mysql always incrementing the auto increment
345  // pointer this breaks if someone modifies the auto increment pointer
346  //setValue(query.lastInsertId().toInt());
347 
348  QVariant var = query.lastInsertId();
349 
350  if (var.type())
351  setValue(var.toInt());
352  else
353  {
354  querystr = "SELECT MAX(" + m_column + ") FROM " +
355  m_table + ";";
356  if (query.exec(querystr) && query.next())
357  {
358  int lii = query.value(0).toInt();
359  lii = lii ? lii : 1;
360  setValue(lii);
361  }
362  else
363  LOG(VB_GENERAL, LOG_EMERG,
364  "Can't determine the Id of the last insert "
365  "QSqlQuery.lastInsertId() failed, the workaround "
366  "failed too!");
367  }
368  // XXX -- HACK END:
369  }
370 }
371 
372 AutoIncrementSetting::AutoIncrementSetting(QString _table, QString _column) :
373  StandardSetting(),
374  m_table(_table), m_column(_column)
375 {
376  setValue("0");
377 }
378 
379 /******************************************************************************
380  Text Setting
381 *******************************************************************************/
382 
384  StandardSetting(_storage), m_passwordEcho(false)
385 {
386 }
387 
389 {
390  m_passwordEcho = b;
391 }
392 
394 {
395  if (!isEnabled())
396  return;
397 
398  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
399 
400  MythTextInputDialog *settingdialog =
401  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
403 
404  if (settingdialog->Create())
405  {
406  settingdialog->SetReturnEvent(screen, "editsetting");
407  popupStack->AddScreen(settingdialog);
408  }
409  else
410  delete settingdialog;
411 }
412 
414 {
415  if (m_settingValue != dce->GetResultText())
416  setValue(dce->GetResultText());
417 }
418 
419 
421 {
423  item->DisplayState("textedit", "widgettype");
424 }
425 
426 
427 /******************************************************************************
428  Directory Setting
429 *******************************************************************************/
430 
432  StandardSetting(_storage)
433 {
434  m_typeFilter = (QDir::AllDirs | QDir::Drives | QDir::Files |
435  QDir::Readable | QDir::Writable | QDir::Executable);
436  m_nameFilter.clear();
437  m_nameFilter << "*";
438 }
439 
441 {
442  if (!isEnabled())
443  return;
444 
445  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
446 
447  MythUIFileBrowser *settingdialog = new MythUIFileBrowser(popupStack,
449  settingdialog->SetTypeFilter(m_typeFilter);
450  settingdialog->SetNameFilter(m_nameFilter);
451 
452  if (settingdialog->Create())
453  {
454  settingdialog->SetReturnEvent(screen, "editsetting");
455  popupStack->AddScreen(settingdialog);
456  }
457  else
458  delete settingdialog;
459 }
460 
462 {
463  if (m_settingValue != dce->GetResultText())
464  setValue(dce->GetResultText());
465 }
466 
468 {
470  item->DisplayState("filebrowser", "widgettype");
471 }
472 
473 
474 /******************************************************************************
475  ComboBoxSetting
476 *******************************************************************************/
485  StandardSetting(_storage),
486  m_rewrite(rw),
487  m_isSet(false)
488 {
489 }
490 
492 {
493  m_labels.clear();
494  m_values.clear();
495 }
496 
498 {
499  if (value >= 0 && value < m_values.size())
500  {
502  m_isSet = true;
503  }
504 }
505 
506 int MythUIComboBoxSetting::getValueIndex(const QString &value) const
507 {
508  return m_values.indexOf(value);
509 }
510 
512 {
513  int index = getValueIndex(getValue());
514  return (index >= 0) ? m_labels.at(index) : QString("");
515 }
516 
517 void MythUIComboBoxSetting::addSelection(const QString &label, QString value,
518  bool select)
519 {
520  value = value.isEmpty() ? label : value;
521  m_labels.push_back(label);
522  m_values.push_back(value);
523 
524  if (select || !m_isSet)
525  {
527  if (!m_isSet)
528  m_isSet = true;
529  }
530 }
531 
533 {
534  m_isSet = false;
535  m_labels.clear();
536  m_values.clear();
537 }
538 
540 {
541  item->DisplayState("combobox", "widgettype");
542  item->setEnabled(isEnabled());
543  item->SetText(m_label);
544  int indexValue = m_values.indexOf(m_settingValue);
545  if (indexValue >= 0)
546  item->SetText(m_labels.value(indexValue), "value");
547  else
548  item->SetText(m_settingValue, "value");
549  item->SetText(getHelpText(), "description");
550  item->setDrawArrow(haveSubSettings());
551 }
552 
554 {
555  if (!isEnabled())
556  return;
557 
558  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
559 
560  MythDialogBox *menuPopup =
561  new MythDialogBox(getLabel(), popupStack, "optionmenu");
562 
563  if (menuPopup->Create())
564  {
565  popupStack->AddScreen(menuPopup);
566 
567  //connect(menuPopup, SIGNAL(haveResult(QString)),
568  //SLOT(setValue(QString)));
569 
570  menuPopup->SetReturnEvent(screen, "editsetting");
571 
572  if (m_rewrite)
573  menuPopup->AddButton(QObject::tr("New entry"),
574  QString("NEWENTRY"),
575  false,
576  m_settingValue == "");
577  for (int i = 0; i < m_labels.size() && m_values.size(); ++i)
578  {
579  QString value = m_values.at(i);
580  menuPopup->AddButton(m_labels.at(i),
581  value,
582  false,
583  value == m_settingValue);
584  }
585  }
586  else
587  delete menuPopup;
588 }
589 
590 void MythUIComboBoxSetting::setValue(const QString& newValue)
591 {
592  StandardSetting::setValue(newValue);
593  m_isSet = true;
594 }
595 
597 {
598  if (dce->GetResult() != -1)
599  {
600  if (m_rewrite && dce->GetData().toString() == "NEWENTRY")
601  {
602  MythScreenStack *popupStack =
603  GetMythMainWindow()->GetStack("popup stack");
604 
605  MythTextInputDialog *settingdialog =
606  new MythTextInputDialog(popupStack, getLabel(), FilterNone,
607  false, m_settingValue);
608 
609  if (settingdialog->Create())
610  {
611  connect(settingdialog, SIGNAL(haveResult(QString)),
612  SLOT(setValue(const QString&)));
613  popupStack->AddScreen(settingdialog);
614  }
615  else
616  delete settingdialog;
617  }
618  else if (m_settingValue != dce->GetData().toString())
619  StandardSetting::setValue(dce->GetData().toString());
620  }
621 }
622 
623 void MythUIComboBoxSetting::fillSelectionsFromDir(const QDir &dir, bool absPath)
624 {
625  QFileInfoList il = dir.entryInfoList();
626 
627  for (QFileInfoList::Iterator it = il.begin();
628  it != il.end();
629  ++it )
630  {
631  QFileInfo &fi = *it;
632 
633  if (absPath)
634  addSelection( fi.absoluteFilePath() );
635  else
636  addSelection( fi.fileName() );
637  }
638 }
639 
641 {
642  return m_labels.size();
643 }
644 
645 /******************************************************************************
646  SpinBox Setting
647 *******************************************************************************/
649  int step, int pageMultiple,
650  const QString &special_value_text)
651  : StandardSetting(_storage),
652  m_min(min),
653  m_max(max),
654  m_step(step),
655  m_pageMultiple(pageMultiple),
656  m_special_value_text(special_value_text)
657 {
658  //we default to 0 unless 0 is out of range
659  if (m_min > 0 || m_max < 0)
660  m_settingValue = QString::number(m_min);
661 
662  // The setings pages were coded to assume a parameter true/false
663  // meaning allow_single_step. Many pages use this but it was not
664  // implemented. It is difficult to implement using the current
665  // UI widget design. So I have changed it so you can specify
666  // the size of pageup / pagedown increments as an integer instead
667  // For compatibility with callers still using true to indicate
668  // allowing single step, the code will set the step size as 1 and
669  // the pageup / pagedown as the requested step.
670 
671  if (m_pageMultiple == 1)
672  {
673  m_pageMultiple = step;
674  m_step = 1;
675  }
676  if (m_pageMultiple == 0)
677  {
678  m_pageMultiple = 5;
679  }
680 }
681 
683 {
684  item->DisplayState("spinbox", "widgettype");
685  item->setEnabled(isEnabled());
686  item->SetText(m_label);
687  if (m_settingValue.toInt() == m_min && !m_special_value_text.isEmpty())
688  item->SetText(m_special_value_text, "value");
689  else
690  item->SetText(m_settingValue, "value");
691  item->SetText(getHelpText(), "description");
692  item->setDrawArrow(haveSubSettings());
693 }
694 
696 {
697  return m_settingValue.toInt();
698 }
699 
701 {
702  if (!isEnabled())
703  return;
704 
705  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
706 
707  MythSpinBoxDialog *settingdialog = new MythSpinBoxDialog(popupStack,
708  getLabel());
709 
710  if (settingdialog->Create())
711  {
712  settingdialog->SetRange(m_min, m_max, m_step, m_pageMultiple);
713  if (!m_special_value_text.isEmpty())
714  settingdialog->AddSelection(m_special_value_text, m_min);
715  settingdialog->SetValue(m_settingValue);
716  settingdialog->SetReturnEvent(screen, "editsetting");
717  popupStack->AddScreen(settingdialog);
718  }
719  else
720  delete settingdialog;
721 }
722 
724 {
725  if (m_settingValue != dce->GetResultText())
726  setValue(dce->GetResultText());
727 }
728 
729 /******************************************************************************
730  MythUICheckBoxSetting
731 *******************************************************************************/
732 
734  StandardSetting(_storage)
735 {
736 }
737 
739 {
740  return m_settingValue == "1";
741 }
742 
743 void MythUICheckBoxSetting::setValue(const QString &value)
744 {
746  if (haveChanged())
747  emit valueChanged(value == "1");
748 }
749 
751 {
752  StandardSetting::setValue(value ? "1" : "0");
753  if (haveChanged())
754  emit valueChanged(value);
755 }
756 
758 {
760  item->DisplayState("checkbox", "widgettype");
761  item->setCheckable(true);
762  item->SetText("", "value");
763  if (m_settingValue == "1")
765  else
767 }
768 
770 {
771  if (!isEnabled())
772  return;
773 
774  DialogCompletionEvent *dce =
775  new DialogCompletionEvent("editsetting", 0, "", "");
776  QCoreApplication::postEvent(screen, dce);
777 }
778 
780 {
781  setValue(!boolValue());
782 }
783 
784 /******************************************************************************
785  Standard setting dialog
786 *******************************************************************************/
787 
789  const char *name,
790  GroupSetting *groupSettings) :
791  MythScreenType(parent, name),
792  m_buttonList(nullptr),
793  m_title(nullptr),
794  m_groupHelp(nullptr),
795  m_selectedSettingHelp(nullptr),
796  m_menuPopup(nullptr),
797  m_settingsTree(groupSettings),
798  m_currentGroupSetting(nullptr),
799  m_loaded(false)
800 {
801 }
802 
804 {
805  if (m_settingsTree)
806  m_settingsTree->deleteLater();
807 }
808 
810 {
811  if (!LoadWindowFromXML("standardsetting-ui.xml", "settingssetup", this))
812  return false;
813 
814  bool error = false;
815  UIUtilE::Assign(this, m_title, "title", &error);
816  UIUtilW::Assign(this, m_groupHelp, "grouphelp", &error);
817  UIUtilE::Assign(this, m_buttonList, "settingslist", &error);
818 
819  UIUtilW::Assign(this, m_selectedSettingHelp, "selectedsettinghelp");
820 
821  if (error)
822  {
823  LOG(VB_GENERAL, LOG_ERR, "Theme elements missing.");
824  return false;
825  }
826 
827  connect(m_buttonList, SIGNAL(itemSelected(MythUIButtonListItem*)),
829  connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
831 
832  BuildFocusList();
833 
835 
836  return true;
837 }
838 
840 {
841  if (!item)
842  return;
843 
844  StandardSetting *setting = item->GetData().value<StandardSetting*>();
845  if (setting && m_selectedSettingHelp)
846  {
848  }
849 }
850 
852 {
853  StandardSetting* setting = item->GetData().value<StandardSetting*>();
854  if (setting)
855  setting->edit(this);
856 }
857 
859 {
860  if (event->type() == DialogCompletionEvent::kEventType)
861  {
863  QString resultid = dce->GetId();
864 
865  if (resultid == "leveldown")
866  {
867  //a GroupSetting have been clicked
868  LevelDown();
869  }
870  else if (resultid == "editsetting")
871  {
873  if (item)
874  {
875  StandardSetting *ss = item->GetData().value<StandardSetting*>();
876  if (ss)
877  ss->resultEdit(dce);
878  }
879  }
880  else if (resultid == "exit")
881  {
882  int buttonnum = dce->GetResult();
883  if (buttonnum == 0)
884  {
885  Save();
887  if (m_settingsTree)
889  }
890  else if (buttonnum == 1)
892  }
893  }
894 }
895 
897 {
898  if (m_settingsTree)
899  {
900  m_settingsTree->Load();
901  m_settingsTree->MoveToThread(QApplication::instance()->thread());
902  }
903 }
904 
906 {
908 }
909 
911 {
912  return m_settingsTree;
913 }
914 
916  StandardSetting *groupSettings, StandardSetting *selectedSetting)
917 {
918  if (!groupSettings)
919  return;
920 
922  {
923  disconnect(m_currentGroupSetting,
924  SIGNAL(settingsChanged(StandardSetting *)), nullptr, nullptr);
926  }
927 
928  m_currentGroupSetting = groupSettings;
930 
932  if (m_groupHelp)
933  {
935  }
936  updateSettings(selectedSetting);
937  connect(m_currentGroupSetting,
938  SIGNAL(settingsChanged(StandardSetting *)),
940 }
941 
943 {
944  m_buttonList->Reset();
946  return;
947 
948  QList<StandardSetting *> *settings =
950  if (!settings)
951  return;
952 
953  QList<StandardSetting *>::const_iterator i;
954  MythUIButtonListItem *selectedItem = nullptr;
955  for (i = settings->constBegin(); i != settings->constEnd(); ++i)
956  {
957  if ((*i)->isVisible())
958  {
959  if (selectedSetting == (*i))
960  selectedItem = (*i)->createButton(m_buttonList);
961  else
962  (*i)->createButton(m_buttonList);
963  }
964  }
965  if (selectedItem)
966  m_buttonList->SetItemCurrent(selectedItem);
968 }
969 
971 {
972  if (m_settingsTree)
973  m_settingsTree->Save();
974 }
975 
977 {
979  return;
980 
982  {
985  }
986 }
987 
989 {
991  if (item)
992  {
993  StandardSetting *ss = item->GetData().value<StandardSetting*>();
994  if (ss && ss->haveSubSettings() && ss->isEnabled())
996  }
997 }
998 
1000 {
1001  if (m_settingsTree->haveChanged())
1002  {
1003  QString label = tr("Exit ?");
1004 
1005  MythScreenStack *popupStack =
1006  GetMythMainWindow()->GetStack("popup stack");
1007 
1008  MythDialogBox * menuPopup =
1009  new MythDialogBox(label, popupStack, "exitmenu");
1010 
1011  if (menuPopup->Create())
1012  {
1013  popupStack->AddScreen(menuPopup);
1014 
1015  menuPopup->SetReturnEvent(this, "exit");
1016 
1017  menuPopup->AddButton(tr("Save then Exit"));
1018  menuPopup->AddButton(tr("Exit without saving changes"));
1019  menuPopup->AddButton(tr("Cancel"));
1020  }
1021  else
1022  delete menuPopup;
1023  }
1024  else
1026 }
1027 
1028 static QKeyEvent selectEvent
1029  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"SELECT"));
1030 static QKeyEvent deleteEvent
1031  (QKeyEvent(QEvent::KeyPress,0,Qt::NoModifier,"DELETE"));
1032 
1034 {
1035  QStringList actions;
1036 
1037  bool handled = m_buttonList->keyPressEvent(e);
1038  if (handled)
1039  return true;
1040 
1041  handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions);
1042 
1043  //send the key to the selected Item first
1045  if (item)
1046  {
1047  StandardSetting *ss = item->GetData().value<StandardSetting*>();
1048  if (ss)
1049  handled = ss->keyPressEvent(e);
1050  }
1051  if (handled)
1052  return true;
1053 
1054  for (int i = 0; i < actions.size() && !handled; i++)
1055  {
1056  QString action = actions[i];
1057  handled = true;
1058 
1059  if (action == "LEFT")
1060  {
1061  if (m_currentGroupSetting &&
1063  Close();
1064  else
1065  LevelUp();
1066  }
1067  else if (action == "RIGHT")
1068  LevelDown();
1069  else if (action == "EDIT")
1070  {
1072  }
1073  else if (action == "DELETE")
1074  deleteEntry();
1075  else
1076  handled = MythScreenType::keyPressEvent(e);
1077  }
1078 
1079  return handled;
1080 }
1081 
1083 {
1085  if (!item)
1086  return;
1087 
1088  GroupSetting *source = item->GetData().value<GroupSetting*>();
1089  if (!source)
1090  return;
1091  // m_title->GetText() for screen title
1092  MythMenu *menu = new MythMenu(source->getLabel(), this, "mainmenu");
1093  menu->AddItem(tr("Edit"), SLOT(editEntry()));
1094  if (source->canDelete())
1095  menu->AddItem(tr("Delete"), SLOT(deleteSelected()));
1096 
1097  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
1098 
1099  MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack,
1100  "menudialog");
1101  menuPopup->SetReturnEvent(this, "mainmenu");
1102 
1103  if (menuPopup->Create())
1104  popupStack->AddScreen(menuPopup);
1105  else
1106  delete menuPopup;
1107 }
1108 
1110 {
1112 }
1113 
1115 {
1117 }
1118 
1120 {
1122  if (!item)
1123  return;
1124 
1125  GroupSetting *source = item->GetData().value<GroupSetting*>();
1126  if (!source)
1127  return;
1128 
1129  if (source->canDelete())
1130  {
1131  QString message = tr("Do you want to delete the '%1' entry?")
1132  .arg(source->getLabel());
1133  ShowOkPopup(message, this, SLOT(deleteEntryConfirmed(bool)), true);
1134  }
1135 }
1136 
1138 {
1139  if (ok)
1140  {
1142  if (!item)
1143  return;
1144  GroupSetting *source = item->GetData().value<GroupSetting*>();
1145  if (!source)
1146  return;
1147  source->deleteEntry();
1148 // m_settingsTree->removeChild(source);
1149  source->getParent()->removeChild(source);
1150  m_buttonList->RemoveItem(item);
1151  }
1152 
1153 }
MythUITextEditSetting(Storage *_storage=nullptr)
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:794
static QKeyEvent deleteEvent(QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,"DELETE"))
void setParent(StandardSetting *parent)
MythUIFileBrowserSetting(Storage *_storage)
QString getValueLabel(void) const
virtual bool canDelete(void)
void AddSelection(QString label, int value)
virtual bool keyPressEvent(QKeyEvent *)
void edit(MythScreenType *screen) override
void edit(MythScreenType *screen) override
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
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:41
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 setName(const QString &str)
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:168
bool Create(void) override
QString getLabel(void) const
void setVisible(bool flag)
StandardSetting(Storage *_storage=nullptr)
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
StandardSettingDialog(MythScreenStack *parent, const char *name, GroupSetting *groupSettings=nullptr)
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
MythUIComboBoxSetting(Storage *_storage=nullptr, bool rw=false)
Create a Setting Widget to select the value from a list.
void settingClicked(MythUIButtonListItem *item)
void resultEdit(DialogCompletionEvent *dce) override
void setEnabled(bool flag)
virtual QString getValue(void) const
unsigned char b
Definition: ParseText.cpp:340
void resultEdit(DialogCompletionEvent *dce) override
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:182
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 ...
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:85
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:889
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:547
virtual void Save(void)=0
const char * name
Definition: ParseText.cpp:339
StandardSetting * m_parent
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
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:615
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 &)