MythTV master
rawsettingseditor.cpp
Go to the documentation of this file.
1
9
10#include "rawsettingseditor.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
73
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: */
static bool BackendIsRunning(void)
a backend process is running on this host
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
void SendMessage(const QString &message)
bool IsMasterHost(void)
is this the same host as the master
Screen in which all other widgets are contained and rendered.
void LoadInBackground(const QString &message="")
void BuildFocusList(void)
virtual void Close()
QString GetText(const QString &name="") const
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
MythUIButtonListItem * GetItemCurrent() const
void SetItemCurrent(MythUIButtonListItem *item)
MythUIButtonListItem * GetItemFirst() const
int GetCurrentPos() const
MythUIButtonListItem * GetItemAt(int pos) const
void itemSelected(MythUIButtonListItem *item)
A single button widget.
Definition: mythuibutton.h:22
void Clicked()
A widget for rendering primitive shapes and lines.
Definition: mythuishape.h:22
A text entry and edit widget.
QString GetText(void) const
void SetText(const QString &text, bool moveCursor=true)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
void LosingFocus(void)
void Init(void) override
Initialize the settings screen with the loaded data.
QHash< QString, QString > m_origValues
void selectionChanged(MythUIButtonListItem *item)
Slot handler for buttonlist current item changes.
void Load(void) override
Loads the current values for the specified settings list.
MythUIText * m_textLabel
RawSettingsEditor(MythScreenStack *parent, const char *name=nullptr)
Raw Settings Editor constructor.
bool Create(void) override
Creates the UI screen.
MythUIButton * m_saveButton
QHash< int, MythUIText * > m_prevNextTexts
QHash< QString, QString > m_settingValues
MythUIButton * m_cancelButton
void Save(void)
Save editted values and clear settings cache if necessary.
QMap< QString, QString > m_settings
QHash< int, MythUIShape * > m_prevNextShapes
MythUITextEdit * m_settingValue
void valueChanged(void)
Tracks current value for a setting when the value is editted.
MythUIButtonList * m_settingsList
void updatePrevNextTexts(void)
Updates previous and next text areas.
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39