240dad544a2f2578eb0e75dad3b78fbc737b4982
[vuplus_xbmc] / xbmc / settings / dialogs / GUIDialogSettings.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIDialogSettings.h"
22 #include "guilib/GUIEditControl.h"
23 #include "guilib/GUISpinControlEx.h"
24 #include "guilib/GUIRadioButtonControl.h"
25 #include "guilib/GUISettingsSliderControl.h"
26 #include "guilib/GUIImage.h"
27 #include "guilib/GUIControlGroupList.h"
28 #include "guilib/LocalizeStrings.h"
29 #include "utils/log.h"
30 #include "guilib/GUIKeyboardFactory.h"
31
32 #define CONTROL_GROUP_LIST          5
33 #define CONTROL_SETTINGS_LABEL      2
34 #define CONTROL_NONE_AVAILABLE      3
35 #define CONTROL_DEFAULT_BUTTON      7
36 #define CONTROL_DEFAULT_RADIOBUTTON 8
37 #define CONTROL_DEFAULT_SPIN        9
38 #define CONTROL_DEFAULT_SLIDER     10
39 #define CONTROL_DEFAULT_SEPARATOR  11
40 #define CONTROL_DEFAULT_EDIT       12
41 #define CONTROL_DEFAULT_EDIT_NUM   13
42 #define CONTROL_OKAY_BUTTON        28
43 #define CONTROL_CANCEL_BUTTON      29
44 #define CONTROL_START              30
45 #define CONTROL_PAGE               60
46
47 using namespace std;
48
49 CGUIDialogSettings::CGUIDialogSettings(int id, const char *xmlFile)
50     : CGUIDialog(id, xmlFile)
51 {
52   m_pOriginalEdit = NULL;
53   m_pOriginalEditNum = NULL;
54   m_pOriginalSpin = NULL;
55   m_pOriginalRadioButton = NULL;
56   m_pOriginalSettingsButton = NULL;
57   m_pOriginalSlider = NULL;
58   m_pOriginalSeparator = NULL;
59   m_usePopupSliders = false;
60   m_loadType = KEEP_IN_MEMORY;
61 }
62
63 CGUIDialogSettings::~CGUIDialogSettings(void)
64 {
65 }
66
67 bool CGUIDialogSettings::OnMessage(CGUIMessage &message)
68 {
69   switch (message.GetMessage())
70   {
71   case GUI_MSG_CLICKED:
72     {
73       unsigned int iControl = message.GetSenderId();
74       if (iControl >= CONTROL_OKAY_BUTTON && iControl < CONTROL_PAGE)
75         OnClick(iControl);
76       return true;
77     }
78     break;
79   case GUI_MSG_WINDOW_DEINIT:
80     {
81       CGUIDialog::OnMessage(message);
82       FreeControls();
83       m_settings.clear();
84       return true;
85     }
86     break;
87   }
88   return CGUIDialog::OnMessage(message);
89 }
90
91 void CGUIDialogSettings::SetupPage()
92 {
93   // cleanup first, if necessary
94   FreeControls();
95   m_pOriginalEdit = (CGUIEditControl*)GetControl(CONTROL_DEFAULT_EDIT);
96   m_pOriginalEditNum = (CGUIEditControl*)GetControl(CONTROL_DEFAULT_EDIT_NUM);
97   m_pOriginalSpin = (CGUISpinControlEx*)GetControl(CONTROL_DEFAULT_SPIN);
98   m_pOriginalRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_DEFAULT_RADIOBUTTON);
99   m_pOriginalSettingsButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_BUTTON);
100   m_pOriginalSlider = (CGUISettingsSliderControl *)GetControl(CONTROL_DEFAULT_SLIDER);
101   m_pOriginalSeparator = (CGUIImage *)GetControl(CONTROL_DEFAULT_SEPARATOR);
102   if (m_pOriginalEdit) m_pOriginalEdit->SetVisible(false);
103   if (m_pOriginalEditNum) m_pOriginalEditNum->SetVisible(false);
104   if (m_pOriginalSpin) m_pOriginalSpin->SetVisible(false);
105   if (m_pOriginalRadioButton) m_pOriginalRadioButton->SetVisible(false);
106   if (m_pOriginalSettingsButton) m_pOriginalSettingsButton->SetVisible(false);
107   if (m_pOriginalSlider) m_pOriginalSlider->SetVisible(false);
108   if (m_pOriginalSeparator) m_pOriginalSeparator->SetVisible(false);
109
110   // update our settings label
111   if (GetID() == WINDOW_DIALOG_PVR_TIMER_SETTING)
112   {
113     SET_CONTROL_LABEL(CONTROL_SETTINGS_LABEL, g_localizeStrings.Get(19057));
114   }
115   else
116   {
117   SET_CONTROL_LABEL(CONTROL_SETTINGS_LABEL, g_localizeStrings.Get(13395 + GetID() - WINDOW_DIALOG_VIDEO_OSD_SETTINGS));
118   }
119
120   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CONTROL_GROUP_LIST);
121   if (!group)
122     return;
123
124   if (!m_settings.size())
125   { // no settings available
126     SET_CONTROL_VISIBLE(CONTROL_NONE_AVAILABLE);
127     return;
128   }
129   else
130   {
131     SET_CONTROL_HIDDEN(CONTROL_NONE_AVAILABLE);
132   }
133
134   // create our controls
135   for (unsigned int i = 0; i < m_settings.size(); i++)
136   {
137     SettingInfo &setting = m_settings.at(i);
138     AddSetting(setting, group->GetWidth(), CONTROL_START + i);
139   }
140 }
141
142 void CGUIDialogSettings::EnableSettings(unsigned int id, bool enabled)
143 {
144   for (unsigned int i = 0; i < m_settings.size(); i++)
145   {
146     if (m_settings[i].id != id)
147       continue;
148     m_settings[i].enabled = enabled;
149     if (enabled)
150     {
151       CONTROL_ENABLE(i + CONTROL_START);
152     }
153     else
154     {
155       CONTROL_DISABLE(i + CONTROL_START);
156     }
157     return;
158   }
159   CLog::Log(LOGWARNING, "%s - Invalid setting specified", __FUNCTION__);
160 }
161
162 void CGUIDialogSettings::UpdateSetting(unsigned int id)
163 {
164   unsigned int settingNum = (unsigned int)-1;
165   for (unsigned int i = 0; i < m_settings.size(); i++)
166   {
167     if (m_settings[i].id == id)
168     {
169       settingNum = i;
170       break;
171     }
172   }
173   if(settingNum == (unsigned int)-1)
174     return;
175
176   SettingInfo &setting = m_settings.at(settingNum);
177   unsigned int controlID = settingNum + CONTROL_START;
178   if (setting.type == SettingInfo::SPIN)
179   {
180     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(controlID);
181     if (pControl && setting.data) pControl->SetValue(*(int *)setting.data);
182   }
183   else if (setting.type == SettingInfo::CHECK)
184   {
185     CGUIRadioButtonControl *pControl = (CGUIRadioButtonControl *)GetControl(controlID);
186     if (pControl && setting.data) pControl->SetSelected(*(bool *)setting.data);
187   }
188   else if (setting.type == SettingInfo::CHECK_UCHAR)
189   {
190     CGUIRadioButtonControl *pControl = (CGUIRadioButtonControl *)GetControl(controlID);
191     if (pControl && setting.data) pControl->SetSelected(*(unsigned char*)setting.data ? true : false);
192   }
193   else if (setting.type == SettingInfo::SLIDER)
194   {
195     CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(controlID);
196     if (pControl && setting.data)
197     {
198       float value = *(float *)setting.data;
199       pControl->SetFloatValue(value);
200       if (setting.formatFunction.standard) pControl->SetTextValue(setting.formatFunction.standard(value, setting.interval));
201     }
202   }
203   else if (setting.type == SettingInfo::BUTTON_DIALOG)
204   {
205     SET_CONTROL_LABEL(controlID,setting.name);
206     CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(controlID);
207     if (pControl && setting.data) pControl->SetLabel2(*(CStdString *)setting.data);
208   }
209   else if (setting.type == SettingInfo::EDIT)
210   {
211     SET_CONTROL_LABEL(controlID, setting.name);
212     if (setting.data) SET_CONTROL_LABEL2(controlID, string(*(CStdString *)setting.data));
213   }
214   else if (setting.type == SettingInfo::EDIT_NUM)
215   {
216     CGUIEditControl *pControl = (CGUIEditControl *)GetControl(controlID);
217     if (pControl && setting.data) {
218       CStdString strIndex;
219       strIndex.Format("%i", *(int *)setting.data);
220       pControl->SetLabel2(strIndex);
221     }
222   }
223   else if (setting.type == SettingInfo::STRING)
224   {
225     SET_CONTROL_LABEL(controlID, setting.name);
226     string strNewValue = string(*(CStdString *)setting.data);
227     if (strNewValue.empty())
228       strNewValue = "-";
229     SET_CONTROL_LABEL2(controlID, strNewValue);
230   }
231   else if (setting.type == SettingInfo::RANGE)
232   {
233     CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(controlID);
234     float** value = (float **)setting.data;
235     if (pControl && setting.data)
236     {
237       pControl->SetFloatValue(*(value[0]), CGUISliderControl::RangeSelectorLower);
238       pControl->SetFloatValue(*(value[1]), CGUISliderControl::RangeSelectorUpper);
239       if (setting.formatFunction.range) pControl->SetTextValue(setting.formatFunction.range(*(value[0]), *(value[1]), setting.interval));
240     }
241   }
242
243   if (setting.enabled)
244   {
245     CONTROL_ENABLE(controlID);
246   }
247   else
248   {
249     CONTROL_DISABLE(controlID);
250   }
251 }
252
253 bool CGUIDialogSettings::OnBack(int actionID)
254 {
255   OnCancel();
256   return CGUIDialog::OnBack(actionID);
257 }
258
259 void CGUIDialogSettings::OnClick(int iID)
260 {
261   if (iID == CONTROL_OKAY_BUTTON)
262   {
263     OnOkay();
264     Close();
265     return;
266   }
267   if (iID == CONTROL_CANCEL_BUTTON)
268   {
269     OnCancel();
270     Close();
271     return;
272   }
273   unsigned int settingNum = iID - CONTROL_START;
274   if (settingNum >= m_settings.size()) return;
275   SettingInfo &setting = m_settings.at(settingNum);
276   if (setting.type == SettingInfo::SPIN)
277   {
278     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(iID);
279     if (setting.data) *(int *)setting.data = pControl->GetValue();
280   }
281   else if (setting.type == SettingInfo::BUTTON_DIALOG)
282   {
283     CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(iID);
284     if (setting.data) *(CStdString *)setting.data = pControl->GetLabel2();
285   }
286   else if (setting.type == SettingInfo::EDIT)
287   {
288     CGUIEditControl *pControl = (CGUIEditControl *)GetControl(iID);
289     if (setting.data) *(CStdString *)setting.data = pControl->GetLabel2();
290   }
291   else if (setting.type == SettingInfo::EDIT_NUM)
292   {
293     CGUIEditControl *pControl = (CGUIEditControl *)GetControl(iID);
294     if (setting.data) {
295         CStdString strIndex = pControl->GetLabel2();
296         *(int *)setting.data = atol(strIndex.c_str());
297     }
298   }
299   else if (setting.type == SettingInfo::CHECK)
300   {
301     CGUIRadioButtonControl *pControl = (CGUIRadioButtonControl *)GetControl(iID);
302     if (setting.data) *(bool *)setting.data = pControl->IsSelected();
303   }
304   else if (setting.type == SettingInfo::CHECK_UCHAR)
305   {
306     CGUIRadioButtonControl *pControl = (CGUIRadioButtonControl *)GetControl(iID);
307     if (setting.data) *(unsigned char*)setting.data = pControl->IsSelected() ? 1 : 0;
308   }
309   else if (setting.type == SettingInfo::SLIDER)
310   {
311     CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(iID);
312     if (setting.data) *(float *)setting.data = pControl->GetFloatValue();
313     if (setting.formatFunction.standard) pControl->SetTextValue(setting.formatFunction.standard(pControl->GetFloatValue(), setting.interval));
314   }
315   else if (setting.type == SettingInfo::BUTTON && m_usePopupSliders && setting.data)
316   { // we're using popup sliders
317     CGUIDialogSlider::ShowAndGetInput(setting.name, *(float *)setting.data, setting.min, setting.interval, setting.max, this, &setting);
318     if (setting.formatFunction.standard)
319       SET_CONTROL_LABEL2(iID, setting.formatFunction.standard(*(float *)setting.data, setting.interval));
320   }
321   else if (setting.type == SettingInfo::STRING)
322   {
323     CGUIKeyboardFactory::ShowAndGetInput(*(CStdString *) setting.data, true);
324     string strNewValue = string(*(CStdString *)setting.data);
325     if (strNewValue.empty())
326       strNewValue = "-";
327     SET_CONTROL_LABEL2(iID, strNewValue);
328   }
329   else if (setting.type == SettingInfo::RANGE)
330   {
331     CGUISettingsSliderControl *pControl = (CGUISettingsSliderControl *)GetControl(iID);
332     if (setting.data)
333     {
334       *((float **)setting.data)[0] = pControl->GetFloatValue(CGUISliderControl::RangeSelectorLower);
335       *((float **)setting.data)[1] = pControl->GetFloatValue(CGUISliderControl::RangeSelectorUpper);
336     }
337     if (setting.formatFunction.range)
338       pControl->SetTextValue(setting.formatFunction.range(pControl->GetFloatValue(CGUISliderControl::RangeSelectorLower), 
339                                                           pControl->GetFloatValue(CGUISliderControl::RangeSelectorUpper),
340                                                           setting.interval));
341   }
342   OnSettingChanged(setting);
343 }
344
345 void CGUIDialogSettings::FreeControls()
346 {
347   // just clear our group list
348   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CONTROL_GROUP_LIST);
349   if (group)
350   {
351     group->FreeResources();
352     group->ClearAll();
353   }
354 }
355
356 void CGUIDialogSettings::AddSetting(SettingInfo &setting, float width, int iControlID)
357 {
358   CGUIControl *pControl = NULL;
359   if (setting.type == SettingInfo::BUTTON_DIALOG && m_pOriginalSettingsButton)
360   {
361     pControl = new CGUIButtonControl(*m_pOriginalSettingsButton);
362     if (!pControl) return ;
363     ((CGUIButtonControl *)pControl)->SetLabel(setting.name);
364     pControl->SetWidth(width);
365         if (setting.data) ((CGUIButtonControl *)pControl)->SetLabel2(*(CStdString *)setting.data);
366   }
367   else if (setting.type == SettingInfo::BUTTON && m_pOriginalSettingsButton)
368   {
369     pControl = new CGUIButtonControl(*m_pOriginalSettingsButton);
370     if (!pControl) return ;
371     ((CGUIButtonControl *)pControl)->SetLabel(setting.name);
372     if (setting.formatFunction.standard)
373       ((CGUIButtonControl *)pControl)->SetLabel2(setting.formatFunction.standard(*(float *)setting.data, setting.interval));
374     pControl->SetWidth(width);
375   }
376   else if (setting.type == SettingInfo::EDIT && m_pOriginalEdit)
377   {
378     pControl = new CGUIEditControl(*m_pOriginalEdit);
379     if (!pControl) return ;
380     ((CGUIEditControl *)pControl)->SetLabel(setting.name);
381     pControl->SetWidth(width);
382     if (setting.data) ((CGUIEditControl *)pControl)->SetLabel2(*(CStdString *)setting.data);
383   }
384   else if (setting.type == SettingInfo::EDIT_NUM && m_pOriginalEditNum)
385   {
386     pControl = new CGUIEditControl(*m_pOriginalEditNum);
387     if (!pControl) return ;
388     ((CGUIEditControl *)pControl)->SetLabel(setting.name);
389     pControl->SetWidth(width);
390     ((CGUIEditControl *)pControl)->SetInputType(CGUIEditControl::INPUT_TYPE_NUMBER, 0);
391     if (setting.data) {
392         CStdString strIndex;
393         strIndex.Format("%i", *(int *)setting.data);
394         ((CGUIEditControl *)pControl)->SetLabel2(strIndex);
395     }
396   }
397   else if (setting.type == SettingInfo::SEPARATOR && m_pOriginalSeparator)
398   {
399     pControl = new CGUIImage(*m_pOriginalSeparator);
400     if (!pControl) return ;
401     pControl->SetWidth(width);
402   }
403   else if (setting.type == SettingInfo::CHECK || setting.type == SettingInfo::CHECK_UCHAR)
404   {
405     if (!m_pOriginalRadioButton) return;
406     pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
407     if (!pControl) return ;
408     ((CGUIRadioButtonControl *)pControl)->SetLabel(setting.name);
409     pControl->SetWidth(width);
410     if (setting.data) ((CGUIRadioButtonControl *)pControl)->SetSelected(*(bool *)setting.data == 1);
411   }
412   else if (setting.type == SettingInfo::SPIN && setting.entry.size() > 0 && m_pOriginalSpin)
413   {
414     pControl = new CGUISpinControlEx(*m_pOriginalSpin);
415     if (!pControl) return ;
416     pControl->SetWidth(width);
417     ((CGUISpinControlEx *)pControl)->SetText(setting.name);
418     pControl->SetWidth(width);
419     for (unsigned int i = 0; i < setting.entry.size(); i++)
420       ((CGUISpinControlEx *)pControl)->AddLabel(setting.entry[i].second, setting.entry[i].first);
421     if (setting.data) ((CGUISpinControlEx *)pControl)->SetValue(*(int *)setting.data);
422   }
423   else if (setting.type == SettingInfo::SLIDER)
424   {
425     if (!m_pOriginalSlider) return;
426     pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
427     if (!pControl) return ;
428     pControl->SetWidth(width);
429     ((CGUISettingsSliderControl *)pControl)->SetText(setting.name);
430     if (setting.formatFunction.standard)
431       ((CGUISettingsSliderControl *)pControl)->SetTextValue(setting.formatFunction.standard(*(float *)setting.data, setting.interval));
432     ((CGUISettingsSliderControl *)pControl)->SetType(SPIN_CONTROL_TYPE_FLOAT);
433     ((CGUISettingsSliderControl *)pControl)->SetFloatRange(setting.min, setting.max);
434     ((CGUISettingsSliderControl *)pControl)->SetFloatInterval(setting.interval);
435     if (setting.data) ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*(float *)setting.data);
436   }
437   else if (setting.type == SettingInfo::STRING && m_pOriginalSettingsButton)
438   {
439     pControl = new CGUIButtonControl(*m_pOriginalSettingsButton);
440     if (!pControl) return ;
441     ((CGUIButtonControl *)pControl)->SetLabel(setting.name);
442     string strValue = string(*(CStdString *)setting.data);
443     if (strValue.empty())
444       strValue = "-";
445     ((CGUIButtonControl *)pControl)->SetLabel2(strValue);
446     pControl->SetWidth(width);
447   }
448   else if (setting.type == SettingInfo::RANGE)
449   {
450     if (!m_pOriginalSlider) return;
451     pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
452     if (!pControl) return ;
453     pControl->SetWidth(width);
454     ((CGUISettingsSliderControl *)pControl)->SetText(setting.name);
455     if (setting.formatFunction.range)
456       ((CGUISettingsSliderControl *)pControl)->SetTextValue(setting.formatFunction.range(*((float **)setting.data)[0], *((float **)setting.data)[1], setting.interval));
457     ((CGUISettingsSliderControl *)pControl)->SetType(SPIN_CONTROL_TYPE_FLOAT);
458     ((CGUISettingsSliderControl *)pControl)->SetRangeSelection(true);
459     ((CGUISettingsSliderControl *)pControl)->SetFloatRange(setting.min, setting.max);
460     ((CGUISettingsSliderControl *)pControl)->SetFloatInterval(setting.interval);
461     if (setting.data)
462     {
463       ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*((float **)setting.data)[0], CGUISliderControl::RangeSelectorLower);
464       ((CGUISettingsSliderControl *)pControl)->SetFloatValue(*((float **)setting.data)[1], CGUISliderControl::RangeSelectorUpper);
465     }
466   }
467   if (!pControl) return;
468
469   pControl->SetID(iControlID);
470   pControl->SetVisible(true);
471   pControl->SetEnabled(setting.enabled);
472   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CONTROL_GROUP_LIST);
473   if (group)
474   {
475     pControl->AllocResources();
476     group->AddControl(pControl);
477   }
478   else
479     delete pControl;
480 }
481
482 void CGUIDialogSettings::AddEdit(unsigned int id, int label, CStdString *str, bool enabled)
483 {
484   SettingInfo setting;
485   setting.id = id;
486   setting.name = g_localizeStrings.Get(label);
487   setting.type = SettingInfo::EDIT;
488   setting.enabled  = enabled;
489   setting.data = str;
490   m_settings.push_back(setting);
491 }
492
493 void CGUIDialogSettings::AddNumEdit(unsigned int id, int label, int *current, bool enabled)
494 {
495   SettingInfo setting;
496   setting.id = id;
497   setting.name = g_localizeStrings.Get(label);
498   setting.type = SettingInfo::EDIT_NUM;
499   setting.enabled  = enabled;
500   setting.data = current;
501   m_settings.push_back(setting);
502 }
503
504 void CGUIDialogSettings::AddButton(unsigned int id, int label, float *current, float min, float interval, float max, FORMATFUNCTION function)
505 {
506   SettingInfo setting;
507   setting.id = id;
508   setting.name = g_localizeStrings.Get(label);
509   setting.type = SettingInfo::BUTTON;
510   setting.data = current;
511   setting.min = min;
512   setting.max = max;
513   setting.interval = interval;
514   setting.formatFunction.standard = function;
515   m_settings.push_back(setting);
516 }
517
518 void CGUIDialogSettings::AddButton(unsigned int id, int label, CStdString *str, bool bOn)
519 {
520   SettingInfo setting;
521   setting.id = id;
522   setting.name = g_localizeStrings.Get(label);
523   setting.type = SettingInfo::BUTTON_DIALOG;
524   setting.enabled  = bOn;
525   setting.data = str;
526   m_settings.push_back(setting);
527 }
528
529 void CGUIDialogSettings::AddString(unsigned int id, int label, CStdString *current)
530 {
531   SettingInfo setting;
532   setting.id = id;
533   setting.name = g_localizeStrings.Get(label);
534   setting.type = SettingInfo::STRING;
535   setting.data = current;
536   setting.enabled = true;
537   m_settings.push_back(setting);
538 }
539
540 void CGUIDialogSettings::AddBool(unsigned int id, int label, bool *on, bool enabled)
541 {
542   SettingInfo setting;
543   setting.id = id;
544   setting.name = g_localizeStrings.Get(label);
545   setting.type = SettingInfo::CHECK;
546   setting.data = on;
547   setting.enabled = enabled;
548   m_settings.push_back(setting);
549 }
550
551 void CGUIDialogSettings::AddSpin(unsigned int id, int label, int *current, unsigned int max, const SETTINGSTRINGS &entries)
552 {
553   SettingInfo setting;
554   setting.id = id;
555   setting.name = g_localizeStrings.Get(label);
556   setting.type = SettingInfo::SPIN;
557   setting.data = current;
558   for (unsigned int i = 0; i < max; i++)
559     setting.entry.push_back(make_pair(i, entries[i]));
560   m_settings.push_back(setting);
561 }
562
563 void CGUIDialogSettings::AddSpin(unsigned int id, int label, int *current, unsigned int max, const int *entries)
564 {
565   SettingInfo setting;
566   setting.id = id;
567   setting.name = g_localizeStrings.Get(label);
568   setting.type = SettingInfo::SPIN;
569   setting.data = current;
570   for (unsigned int i = 0; i < max; i++)
571     setting.entry.push_back(make_pair(i, g_localizeStrings.Get(entries[i])));
572   m_settings.push_back(setting);
573 }
574
575 void CGUIDialogSettings::AddSpin(unsigned int id, int label, int *current, unsigned int min, unsigned int max, const char* minLabel)
576 {
577   SettingInfo setting;
578   setting.id = id;
579   setting.name = g_localizeStrings.Get(label);
580   setting.type = SettingInfo::SPIN;
581   setting.data = current;
582   for (unsigned int i = min; i <= max; i++)
583   {
584     CStdString format;
585     if (i == min && minLabel)
586       format = minLabel;
587     else
588       format.Format("%i", i);
589     setting.entry.push_back(make_pair(i, format));
590   }
591   m_settings.push_back(setting);
592 }
593
594 void CGUIDialogSettings::AddSpin(unsigned int id, int label, int *current, vector<pair<int, CStdString> > &values)
595 {
596   SettingInfo setting;
597   setting.id = id;
598   setting.name = g_localizeStrings.Get(label);
599   setting.type = SettingInfo::SPIN;
600   setting.data = current;
601   setting.entry = values;
602   if (values.size() <= 1)
603     setting.enabled = false;
604   m_settings.push_back(setting);
605 }
606
607 void CGUIDialogSettings::AddSpin(unsigned int id, int label, int *current, vector<pair<int, int> > &values)
608 {
609   vector<pair<int, CStdString> > entries;
610   for(unsigned i = 0; i < values.size(); i++)
611     entries.push_back(make_pair(values[i].first, g_localizeStrings.Get(values[i].second)));
612   AddSpin(id, label, current, entries);
613 }
614
615 void CGUIDialogSettings::AddSlider(unsigned int id, int label, float *current, float min, float interval, float max, FORMATFUNCTION function, bool allowPopup /* = true*/)
616 {
617   if (m_usePopupSliders && allowPopup)
618   {
619     AddButton(id, label, current, min, interval, max, function);
620     return;
621   }
622   SettingInfo setting;
623   setting.id = id;
624   setting.name = g_localizeStrings.Get(label);
625   setting.type = SettingInfo::SLIDER;
626   setting.min = min;
627   setting.interval = interval;
628   setting.max = max;
629   setting.data = current;
630   setting.formatFunction.standard = function;
631   m_settings.push_back(setting);
632 }
633
634 void CGUIDialogSettings::AddRangeSlider(unsigned int id, int label, float *currentLower, float* currentUpper, float min, float interval, float max, RANGEFORMATFUNCTION function)
635 {
636   SettingInfo setting;
637   setting.id = id;
638   setting.name = g_localizeStrings.Get(label);
639   setting.type = SettingInfo::RANGE;
640   setting.min = min;
641   setting.interval = interval;
642   setting.max = max;
643
644   float** data = new float*[2];
645   data[0] = currentLower;
646   data[1] = currentUpper;
647   setting.data = data;
648
649   setting.formatFunction.range = function;
650   m_settings.push_back(setting);
651 }
652
653 void CGUIDialogSettings::AddSeparator(unsigned int id)
654 {
655   SettingInfo setting;
656   setting.id = id;
657   setting.type = SettingInfo::SEPARATOR;
658   setting.data = NULL;
659   m_settings.push_back(setting);
660 }
661
662 void CGUIDialogSettings::OnInitWindow()
663 {
664   CreateSettings();
665   SetInitialVisibility();
666   SetupPage();
667   // set the default focus control
668   m_lastControlID = CONTROL_START;
669
670   for (unsigned int i = 0; i < m_settings.size(); i++)
671   {
672     if (m_settings.at(i).enabled)
673     {
674       m_lastControlID = CONTROL_START + i;
675       break;
676     }
677   }
678   CGUIDialog::OnInitWindow();
679 }
680
681 void CGUIDialogSettings::OnSliderChange(void *data, CGUISliderControl *slider)
682 {
683   if (!data || !slider)
684     return;
685
686   SettingInfo *setting = (SettingInfo *)data;
687   if (setting->type == SettingInfo::SLIDER || (setting->type == SettingInfo::BUTTON && m_usePopupSliders && !slider->GetRangeSelection()))
688   {
689     *(float *)setting->data = slider->GetFloatValue();
690     OnSettingChanged(*setting);
691     if (setting->formatFunction.standard)
692       slider->SetTextValue(setting->formatFunction.standard(slider->GetFloatValue(), setting->interval));
693   }
694   else if (setting->type == SettingInfo::RANGE || (setting->type == SettingInfo::BUTTON && m_usePopupSliders && slider->GetRangeSelection()))
695   {
696     *((float **)setting->data)[0] = slider->GetFloatValue(CGUISliderControl::RangeSelectorLower);
697     *((float **)setting->data)[1] = slider->GetFloatValue(CGUISliderControl::RangeSelectorUpper);
698     OnSettingChanged(*setting);
699     if (setting->formatFunction.range)
700       slider->SetTextValue(setting->formatFunction.range(slider->GetFloatValue(CGUISliderControl::RangeSelectorLower), slider->GetFloatValue(CGUISliderControl::RangeSelectorUpper), setting->interval));
701   }
702 }