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