MythTV  master
rawsettingseditor.cpp
Go to the documentation of this file.
1 
8 #include "libmythui/mythuitext.h"
10 
11 #include "rawsettingseditor.h"
12 
22  : MythScreenType(parent, name),
23  m_title(tr("Settings Editor"))
24 {
25 }
26 
31 {
32  if (!LoadWindowFromXML("settings-ui.xml", "rawsettingseditor", this))
33  return false;
34 
35  m_settingsList = dynamic_cast<MythUIButtonList *> (GetChild("settings"));
36 
37  m_saveButton = dynamic_cast<MythUIButton *> (GetChild("save"));
38  m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
39  m_textLabel = dynamic_cast<MythUIText *> (GetChild("label-text"));
40 
42  {
43  LOG(VB_GENERAL, LOG_EMERG,
44  "Theme is missing critical theme elements.");
45  return false;
46  }
47 
49 
50  MythUIText *text = dynamic_cast<MythUIText *> (GetChild("heading"));
51  if (text)
52  text->SetText(m_title);
53 
54  MythUIShape *shape = nullptr;
55 
56  for (int i = -8; i <= 8; i++)
57  {
58  text = dynamic_cast<MythUIText *>
59  (GetChild(QString("value%1%2").arg(i >= 0? "+" : "").arg(i)));
60  if (text)
61  m_prevNextTexts[i] = text;
62 
63  shape = dynamic_cast<MythUIShape *>
64  (GetChild(QString("shape%1%2").arg(i >= 0? "+" : "").arg(i)));
65  if (shape)
66  m_prevNextShapes[i] = shape;
67  }
68 
69  m_settingValue = dynamic_cast<MythUITextEdit *> (GetChild("settingvalue"));
70 
74 
77 
79 
80  return true;
81 }
82 
87 {
88  QList<QString>settingsList = m_settings.keys();
89  QList<QString>::iterator it = settingsList.begin();
90 
91  // FIXME, optimize this using gCoreContext->GetSettings()
92  // QMap<QString,QString> kv;
93 
94  while (it != settingsList.end())
95  {
96  QString value = gCoreContext->GetSetting(*it);
97  m_settingValues[*it] = value;
98  m_origValues[*it] = value;
99 
100  ++it;
101  }
102 }
103 
108 {
109  QList<QString>settingsList = m_settings.keys();
110  QList<QString>::iterator it = settingsList.begin();
111 
112  while (it != settingsList.end())
113  {
114  auto *item = new MythUIButtonListItem(m_settingsList, "",
115  QVariant::fromValue(*it));
116 
117  if (m_settings[*it].isEmpty())
118  item->SetText(*it);
119  else
120  item->SetText(m_settings[*it]);
121 
122  ++it;
123  }
124 
128 }
129 
134 {
135  bool changed = false;
136 
137  QHash <QString, QString>::const_iterator it = m_settingValues.constBegin();
138  while (it != m_settingValues.constEnd())
139  {
140  if ((!it.value().isEmpty()) ||
141  ((m_origValues.contains(it.key())) &&
142  (!m_origValues.value(it.key()).isEmpty())))
143  {
144  gCoreContext->SaveSetting(it.key(), it.value());
145  changed = true;
146  }
147 
148  ++it;
149  }
150 
152  gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
153 
154  Close();
155 }
156 
166 {
167  if (!item)
168  return;
169 
170  m_settingValue->SetText(m_settingValues[item->GetData().toString()]);
171  m_textLabel->SetText(item->GetText());
172 
174 }
175 
183 {
184  int curPos = m_settingsList->GetCurrentPos();
185  int recs = m_settingsList->GetCount();
186 
187  if (!recs)
188  return;
189 
190  for (int i = -8; i <= 8; i++)
191  {
192  if (m_prevNextTexts.contains(i))
193  {
194  if (((i < 0) && ((curPos + i) >= 0)) ||
195  ((i > 0) && (((recs-1) - i) >= curPos)))
196  {
197  if (m_prevNextShapes.contains(i))
198  m_prevNextShapes[i]->Show();
199 
200  auto *tmpitem = m_settingsList->GetItemAt(curPos + i);
201  m_prevNextTexts[i]->SetText(
202  m_settingValues[tmpitem->GetData().toString()]);
203  }
204  else
205  {
206  if (m_prevNextShapes.contains(i))
207  m_prevNextShapes[i]->Hide();
208 
209  m_prevNextTexts[i]->SetText(QString());
210  }
211  }
212  }
213 }
214 
222 {
225 }
226 
227 /* vim: set expandtab tabstop=4 shiftwidth=4: */
MythUIButton::Clicked
void Clicked()
MythUIButtonList::GetItemAt
MythUIButtonListItem * GetItemAt(int pos) const
Definition: mythuibuttonlist.cpp:1700
RawSettingsEditor::m_textLabel
MythUIText * m_textLabel
Definition: rawsettingseditor.h:65
MythScreenType::LoadInBackground
void LoadInBackground(const QString &message="")
Definition: mythscreentype.cpp:283
MythCoreContext::SendMessage
void SendMessage(const QString &message)
Definition: mythcorecontext.cpp:1525
MythUIButtonList::GetItemCurrent
MythUIButtonListItem * GetItemCurrent() const
Definition: mythuibuttonlist.cpp:1614
mythuitext.h
RawSettingsEditor::updatePrevNextTexts
void updatePrevNextTexts(void)
Updates previous and next text areas.
Definition: rawsettingseditor.cpp:182
RawSettingsEditor::m_origValues
QHash< QString, QString > m_origValues
Definition: rawsettingseditor.h:72
RawSettingsEditor::m_saveButton
MythUIButton * m_saveButton
Definition: rawsettingseditor.h:62
RawSettingsEditor::m_settingValues
QHash< QString, QString > m_settingValues
Definition: rawsettingseditor.h:73
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:383
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
RawSettingsEditor::m_prevNextShapes
QHash< int, MythUIShape * > m_prevNextShapes
Definition: rawsettingseditor.h:69
RawSettingsEditor::valueChanged
void valueChanged(void)
Tracks current value for a setting when the value is editted.
Definition: rawsettingseditor.cpp:221
RawSettingsEditor::Create
bool Create(void) override
Creates the UI screen.
Definition: rawsettingseditor.cpp:30
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
RawSettingsEditor::Save
void Save(void)
Save editted values and clear settings cache if necessary.
Definition: rawsettingseditor.cpp:133
MythScreenStack
Definition: mythscreenstack.h:16
MythUITextEdit
A text entry and edit widget.
Definition: mythuitextedit.h:34
RawSettingsEditor::m_title
QString m_title
Definition: rawsettingseditor.h:51
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:50
RawSettingsEditor::m_prevNextTexts
QHash< int, MythUIText * > m_prevNextTexts
Definition: rawsettingseditor.h:68
remoteutil.h
mythuibuttonlist.h
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1679
RawSettingsEditor::selectionChanged
void selectionChanged(MythUIButtonListItem *item)
Slot handler for buttonlist current item changes.
Definition: rawsettingseditor.cpp:165
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:198
mythlogging.h
MythCoreContext::BackendIsRunning
static bool BackendIsRunning(void)
a backend process is running on this host
Definition: mythcorecontext.cpp:704
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:240
RawSettingsEditor::m_settingsList
MythUIButtonList * m_settingsList
Definition: rawsettingseditor.h:59
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:203
MythUIButton
A single button widget.
Definition: mythuibutton.h:21
RawSettingsEditor::RawSettingsEditor
RawSettingsEditor(MythScreenStack *parent, const char *name=nullptr)
Raw Settings Editor constructor.
Definition: rawsettingseditor.cpp:21
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3715
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MythUIShape
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:21
RawSettingsEditor::m_cancelButton
MythUIButton * m_cancelButton
Definition: rawsettingseditor.h:63
MythUIButtonListItem::GetText
QString GetText(const QString &name="") const
Definition: mythuibuttonlist.cpp:3368
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
RawSettingsEditor::m_settings
QMap< QString, QString > m_settings
Definition: rawsettingseditor.h:52
mythcorecontext.h
mythuitextedit.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
RawSettingsEditor::m_settingValue
MythUITextEdit * m_settingValue
Definition: rawsettingseditor.h:60
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1581
mythuibutton.h
MythCoreContext::IsMasterHost
bool IsMasterHost(void)
is this the same host as the master
Definition: mythcorecontext.cpp:663
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:885
RawSettingsEditor::Load
void Load(void) override
Loads the current values for the specified settings list.
Definition: rawsettingseditor.cpp:86
rawsettingseditor.h
MythUIType::LosingFocus
void LosingFocus()
MythUIButtonList::GetItemFirst
MythUIButtonListItem * GetItemFirst() const
Definition: mythuibuttonlist.cpp:1660
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:191
mythuishape.h
RawSettingsEditor::Init
void Init(void) override
Initialize the settings screen with the loaded data.
Definition: rawsettingseditor.cpp:107
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:902