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  {
114  "", qVariantFromValue(*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 
150  if (changed && (!gCoreContext->IsMasterHost() || gCoreContext->BackendIsRunning()))
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  MythUIButtonListItem *tmpitem;
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  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: */
void valueChanged(void)
Tracks current value for a setting when the value is editted.
QHash< QString, QString > m_settingValues
void Show(void)
void LosingFocus()
void Save(void)
Save editted values and clear settings cache if necessary.
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
bool Create(void) override
Creates the UI screen.
void SaveSetting(const QString &key, int newValue)
QHash< int, MythUIText * > m_prevNextTexts
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
MythUIButton * m_saveButton
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythUIButtonListItem * GetItemAt(int pos) const
MythUIButtonList * m_settingsList
void BuildFocusList(void)
void SendMessage(const QString &message)
QHash< int, MythUIShape * > m_prevNextShapes
void Hide(void)
virtual void Close()
QString GetSetting(const QString &key, const QString &defaultval="")
bool BackendIsRunning(void)
a backend process is running on this host
void selectionChanged(MythUIButtonListItem *item)
Slot handler for buttonlist current item changes.
MythUIButton * m_cancelButton
RawSettingsEditor(MythScreenStack *parent, const char *name=nullptr)
Raw Settings Editor constructor.
void SetText(const QString &text, const QString &name="", const QString &state="")
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:21
const char * name
Definition: ParseText.cpp:328
QMap< QString, QString > m_settings
MythUITextEdit * m_settingValue
bool IsMasterHost(void)
is this the same host as the master
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetText(const QString &text, bool moveCursor=true)
QString GetText(const QString &name="") const
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetItemCurrent(MythUIButtonListItem *item)
MythUIText * m_textLabel
MythUIButtonListItem * GetItemFirst() const
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
void Init(void) override
Initialize the settings screen with the loaded data.
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
QHash< QString, QString > m_origValues
void Load(void) override
Loads the current values for the specified settings list.
void updatePrevNextTexts(void)
Updates previous and next text areas.
QString GetText(void) const
MythUIButtonListItem * GetItemCurrent() const
void LoadInBackground(QString message="")