00001
00002 #include "mythcorecontext.h"
00003 #include "mythlogging.h"
00004 #include "mythuibutton.h"
00005 #include "mythuibuttonlist.h"
00006 #include "mythuitext.h"
00007 #include "mythuitextedit.h"
00008 #include "rawsettingseditor.h"
00009 #include "remoteutil.h"
00010
00019 RawSettingsEditor::RawSettingsEditor(MythScreenStack *parent, const char *name)
00020 : MythScreenType(parent, name),
00021 m_title(tr("Settings Editor")),
00022
00023 m_settingsList(NULL), m_settingValue(NULL),
00024
00025 m_saveButton(NULL), m_cancelButton(NULL),
00026
00027 m_textLabel(NULL)
00028 {
00029 }
00030
00034 RawSettingsEditor::~RawSettingsEditor()
00035 {
00036 }
00037
00041 bool RawSettingsEditor::Create(void)
00042 {
00043 if (!LoadWindowFromXML("settings-ui.xml", "rawsettingseditor", this))
00044 return false;
00045
00046 m_settingsList = dynamic_cast<MythUIButtonList *> (GetChild("settings"));
00047
00048 m_saveButton = dynamic_cast<MythUIButton *> (GetChild("save"));
00049 m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));
00050 m_textLabel = dynamic_cast<MythUIText *> (GetChild("label-text"));
00051
00052 if (!m_settingsList || !m_textLabel || !m_saveButton || !m_cancelButton)
00053 {
00054 LOG(VB_GENERAL, LOG_EMERG,
00055 "Theme is missing critical theme elements.");
00056 return false;
00057 }
00058
00059 BuildFocusList();
00060
00061 MythUIText *text = dynamic_cast<MythUIText *> (GetChild("heading"));
00062 if (text)
00063 text->SetText(m_title);
00064
00065 MythUIShape *shape = NULL;
00066
00067 for (int i = -8; i <= 8; i++)
00068 {
00069 text = dynamic_cast<MythUIText *>
00070 (GetChild(QString("value%1%2").arg(i >= 0? "+" : "").arg(i)));
00071 if (text)
00072 m_prevNextTexts[i] = text;
00073
00074 shape = dynamic_cast<MythUIShape *>
00075 (GetChild(QString("shape%1%2").arg(i >= 0? "+" : "").arg(i)));
00076 if (shape)
00077 m_prevNextShapes[i] = shape;
00078 }
00079
00080 m_settingValue = dynamic_cast<MythUITextEdit *> (GetChild("settingvalue"));
00081
00082 connect(m_settingsList, SIGNAL(itemSelected(MythUIButtonListItem*)),
00083 SLOT(selectionChanged(MythUIButtonListItem*)));
00084 connect(m_settingValue, SIGNAL(LosingFocus()), SLOT(valueChanged()));
00085
00086 connect(m_saveButton, SIGNAL(Clicked()), this, SLOT(Save()));
00087 connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
00088
00089 LoadInBackground();
00090
00091 return true;
00092 }
00093
00097 void RawSettingsEditor::Load(void)
00098 {
00099 QList<QString>settingsList = m_settings.keys();
00100 QList<QString>::iterator it = settingsList.begin();
00101
00102
00103
00104
00105 while (it != settingsList.end())
00106 {
00107 QString value = gCoreContext->GetSetting(*it);
00108 m_settingValues[*it] = value;
00109 m_origValues[*it] = value;
00110
00111 ++it;
00112 }
00113 m_settingValues.detach();
00114 m_origValues.detach();
00115 }
00116
00120 void RawSettingsEditor::Init(void)
00121 {
00122 QList<QString>settingsList = m_settings.keys();
00123 QList<QString>::iterator it = settingsList.begin();
00124
00125 while (it != settingsList.end())
00126 {
00127 MythUIButtonListItem *item = new MythUIButtonListItem(m_settingsList,
00128 "", qVariantFromValue(*it));
00129
00130 if (m_settings[*it].isEmpty())
00131 item->SetText(*it);
00132 else
00133 item->SetText(m_settings[*it]);
00134
00135 ++it;
00136 }
00137
00138 m_settingsList->SetItemCurrent(0);
00139 m_textLabel->SetText(m_settingsList->GetItemFirst()->GetText());
00140 updatePrevNextTexts();
00141 }
00142
00146 void RawSettingsEditor::Save(void)
00147 {
00148 bool changed = false;
00149
00150 QHash <QString, QString>::const_iterator it = m_settingValues.constBegin();
00151 while (it != m_settingValues.constEnd())
00152 {
00153 if ((!it.value().isEmpty()) ||
00154 ((m_origValues.contains(it.key())) &&
00155 (!m_origValues.value(it.key()).isEmpty())))
00156 {
00157 gCoreContext->SaveSetting(it.key(), it.value());
00158 changed = true;
00159 }
00160
00161 ++it;
00162 }
00163
00164 if (changed && (!gCoreContext->IsMasterHost() || gCoreContext->BackendIsRunning()))
00165 gCoreContext->SendMessage("CLEAR_SETTINGS_CACHE");
00166
00167 Close();
00168 }
00169
00178 void RawSettingsEditor::selectionChanged(MythUIButtonListItem *item)
00179 {
00180 if (!item)
00181 return;
00182
00183 m_settingValue->SetText(m_settingValues[item->GetData().toString()]);
00184 m_textLabel->SetText(item->GetText());
00185
00186 updatePrevNextTexts();
00187 }
00188
00195 void RawSettingsEditor::updatePrevNextTexts(void)
00196 {
00197 MythUIButtonListItem *tmpitem;
00198 int curPos = m_settingsList->GetCurrentPos();
00199 int recs = m_settingsList->GetCount();
00200
00201 if (!recs)
00202 return;
00203
00204 for (int i = -8; i <= 8; i++)
00205 {
00206 if (m_prevNextTexts.contains(i))
00207 {
00208 if (((i < 0) && ((curPos + i) >= 0)) ||
00209 ((i > 0) && (((recs-1) - i) >= curPos)))
00210 {
00211 if (m_prevNextShapes.contains(i))
00212 m_prevNextShapes[i]->Show();
00213
00214 tmpitem = m_settingsList->GetItemAt(curPos + i);
00215 m_prevNextTexts[i]->SetText(
00216 m_settingValues[tmpitem->GetData().toString()]);
00217 }
00218 else
00219 {
00220 if (m_prevNextShapes.contains(i))
00221 m_prevNextShapes[i]->Hide();
00222
00223 m_prevNextTexts[i]->SetText(QString());
00224 }
00225 }
00226 }
00227 }
00228
00235 void RawSettingsEditor::valueChanged(void)
00236 {
00237 m_settingValues[m_settingsList->GetItemCurrent()->GetData().toString()] =
00238 m_settingValue->GetText();
00239 }
00240
00241