merged: Linuxport revisions through to r15292.
[xbmc:xbmc-antiquated.git] / xbmc / GUIWindowSettingsCategory.cpp
1 /*
2  *      Copyright (C) 2005-2008 Team XBMC
3  *      http://www.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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include "stdafx.h"
23 #include "GUIWindowSettingsCategory.h"
24 #include "Application.h"
25 #include "KeyboardLayoutConfiguration.h"
26 #include "FileSystem/HDDirectory.h"
27 #include "Util.h"
28 #include "GUILabelControl.h"
29 #include "GUICheckMarkControl.h"
30 #include "utils/Weather.h"
31 #include "MusicDatabase.h"
32 #include "ProgramDatabase.h"
33 #include "ViewDatabase.h"
34 #include "XBAudioConfig.h"
35 #include "XBVideoConfig.h"
36 #ifdef HAS_XBOX_HARDWARE
37 #include "utils/LED.h"
38 #include "utils/FanController.h"
39 #include "xbox/XKHDD.h"
40 #endif
41 #ifdef HAS_LCD
42 #include "utils/LCDFactory.h"
43 #endif
44 #include "PlayListPlayer.h"
45 #include "SkinInfo.h"
46 #include "GUIAudioManager.h"
47 #include "AudioContext.h"
48 #include "lib/libscrobbler/scrobbler.h"
49 #include "GUIPassword.h"
50 #include "utils/GUIInfoManager.h"
51 #include "GUIDialogGamepad.h"
52 #include "GUIDialogNumeric.h"
53 #include "GUIDialogFileBrowser.h"
54 #include "GUIFontManager.h"
55 #include "GUIDialogContextMenu.h"
56 #include "GUIWindowPrograms.h"
57 #include "MediaManager.h"
58 #include "xbox/network.h"
59 #include "lib/libGoAhead/WebServer.h"
60 #include "GUIControlGroupList.h"
61 #include "XBTimeZone.h"
62 #include "VideoDatabase.h"
63 #include "GUIWindowManager.h"
64 #include "GUIDialogOK.h"
65 #include "GUIDialogYesNo.h"
66 #include "GUIDialogKeyboard.h"
67 #include "FileSystem/Directory.h"
68 #include "utils/ScraperParser.h"
69 #include "FileItem.h"
70 #include "GUIToggleButtonControl.h"
71
72 using namespace std;
73 using namespace DIRECTORY;
74
75 #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
76 #define CATEGORY_GROUP_ID               3
77 #define SETTINGS_GROUP_ID               5
78 #endif
79
80 #define CONTROL_GROUP_BUTTONS           0
81 #define CONTROL_GROUP_SETTINGS          1
82 #define CONTROL_SETTINGS_LABEL          2
83 #define CONTROL_BUTTON_AREA             3
84 #define CONTROL_BUTTON_GAP              4
85 #define CONTROL_AREA                    5
86 #define CONTROL_GAP                     6
87 #define CONTROL_DEFAULT_BUTTON          7
88 #define CONTROL_DEFAULT_RADIOBUTTON     8
89 #define CONTROL_DEFAULT_SPIN            9
90 #define CONTROL_DEFAULT_CATEGORY_BUTTON 10
91 #define CONTROL_DEFAULT_SEPARATOR       11
92 #define CONTROL_DEFAULT_EDIT            12
93 #define CONTROL_START_BUTTONS           30
94 #define CONTROL_START_CONTROL           50
95
96 CGUIWindowSettingsCategory::CGUIWindowSettingsCategory(void)
97     : CGUIWindow(WINDOW_SETTINGS_MYPICTURES, "SettingsCategory.xml")
98 {
99   m_pOriginalSpin = NULL;
100   m_pOriginalRadioButton = NULL;
101   m_pOriginalButton = NULL;
102   m_pOriginalCategoryButton = NULL;
103   m_pOriginalImage = NULL;
104   // set the correct ID range...
105   m_dwIDRange = 8;
106   m_iScreen = 0;
107   // set the network settings so that we don't reset them unnecessarily
108   m_iNetworkAssignment = -1;
109   m_strErrorMessage = "";
110   m_strOldTrackFormat = "";
111   m_strOldTrackFormatRight = "";
112   m_iSectionBeforeJump=-1;
113   m_iControlBeforeJump=-1;
114   m_iWindowBeforeJump=WINDOW_INVALID;
115   m_returningFromSkinLoad = false;
116 }
117
118 CGUIWindowSettingsCategory::~CGUIWindowSettingsCategory(void)
119 {}
120
121 bool CGUIWindowSettingsCategory::OnAction(const CAction &action)
122 {
123   if (action.wID == ACTION_PREVIOUS_MENU)
124   {
125     g_settings.Save();
126     if (m_iWindowBeforeJump!=WINDOW_INVALID)
127     {
128       JumpToPreviousSection();
129       return true;
130     }
131     m_lastControlID = 0; // don't save the control as we go to a different window each time
132     m_gWindowManager.PreviousWindow();
133     return true;
134   }
135   return CGUIWindow::OnAction(action);
136 }
137
138 bool CGUIWindowSettingsCategory::OnMessage(CGUIMessage &message)
139 {
140   switch (message.GetMessage())
141   {
142   case GUI_MSG_CLICKED:
143     {
144       unsigned int iControl = message.GetSenderId();
145       /*   if (iControl >= CONTROL_START_BUTTONS && iControl < CONTROL_START_BUTTONS + m_vecSections.size())
146          {
147           // change the setting...
148           m_iSection = iControl-CONTROL_START_BUTTONS;
149           CheckNetworkSettings();
150           CreateSettings();
151           return true;
152          }*/
153       for (unsigned int i = 0; i < m_vecSettings.size(); i++)
154       {
155         if (m_vecSettings[i]->GetID() == iControl)
156           OnClick(m_vecSettings[i]);
157       }
158     }
159     break;
160   case GUI_MSG_FOCUSED:
161     {
162       CGUIWindow::OnMessage(message);
163       DWORD focusedControl = GetFocusedControlID();
164       if (focusedControl >= CONTROL_START_BUTTONS && focusedControl < (DWORD) (CONTROL_START_BUTTONS + m_vecSections.size()) &&
165           focusedControl - CONTROL_START_BUTTONS != (DWORD) m_iSection)
166       {
167         // changing section, check for updates
168         CheckForUpdates();
169
170         if (m_vecSections[focusedControl-CONTROL_START_BUTTONS]->m_strCategory == "masterlock")
171         {
172           if (!g_passwordManager.IsMasterLockUnlocked(true))
173           { // unable to go to this category - focus the previous one
174             SET_CONTROL_FOCUS(CONTROL_START_BUTTONS + m_iSection, 0);
175             return false;
176           }
177         }
178         m_iSection = focusedControl - CONTROL_START_BUTTONS;
179         CheckNetworkSettings();
180
181         CreateSettings();
182       }
183       return true;
184     }
185   case GUI_MSG_LOAD_SKIN:
186     {
187       // Do we need to reload the language file
188       if (!m_strNewLanguage.IsEmpty())
189       {
190         g_guiSettings.SetString("locale.language", m_strNewLanguage);
191         g_settings.Save();
192
193         CStdString strLangInfoPath;
194         strLangInfoPath.Format("Q:\\language\\%s\\langinfo.xml", m_strNewLanguage.c_str());
195         g_langInfo.Load(strLangInfoPath);
196
197         if (g_langInfo.ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode())
198         {
199           CLog::Log(LOGINFO, "Language needs a ttf font, loading first ttf font available");
200           CStdString strFontSet;
201           if (g_fontManager.GetFirstFontSetUnicode(strFontSet))
202           {
203             m_strNewSkinFontSet=strFontSet;
204           }
205           else
206             CLog::Log(LOGERROR, "No ttf font found but needed: %s", strFontSet.c_str());
207         }
208
209         g_charsetConverter.reset();
210
211         CStdString strKeyboardLayoutConfigurationPath;
212         strKeyboardLayoutConfigurationPath.Format("Q:\\language\\%s\\keyboardmap.xml", m_strNewLanguage.c_str());
213         CLog::Log(LOGINFO, "load keyboard layout configuration info file: %s", strKeyboardLayoutConfigurationPath.c_str());
214         g_keyboardLayoutConfiguration.Load(strKeyboardLayoutConfigurationPath);
215
216         CStdString strLanguagePath;
217         strLanguagePath.Format("Q:\\language\\%s\\strings.xml", m_strNewLanguage.c_str());
218         g_localizeStrings.Load(strLanguagePath);
219
220         // also tell our weather to reload, as this must be localized
221         g_weatherManager.ResetTimer();
222       }
223
224       // Do we need to reload the skin font set
225       if (!m_strNewSkinFontSet.IsEmpty())
226       {
227         g_guiSettings.SetString("lookandfeel.font", m_strNewSkinFontSet);
228         g_settings.Save();
229       }
230
231       // Reload another skin
232       if (!m_strNewSkin.IsEmpty())
233       {
234         g_guiSettings.SetString("lookandfeel.skin", m_strNewSkin);
235         g_settings.Save();
236       }
237
238       // Reload a skin theme
239       if (!m_strNewSkinTheme.IsEmpty())
240       {
241         g_guiSettings.SetString("lookandfeel.skintheme", m_strNewSkinTheme);
242         // also set the default color theme
243         CStdString colorTheme(m_strNewSkinTheme);
244         CUtil::ReplaceExtension(colorTheme, ".xml", colorTheme);
245         if (colorTheme.Equals("Textures.xml"))
246           colorTheme = "defaults.xml";
247         g_guiSettings.SetString("lookandfeel.skincolors", colorTheme);
248         g_settings.Save();
249       }
250
251       // Reload a skin color
252       if (!m_strNewSkinColors.IsEmpty())
253       {
254         g_guiSettings.SetString("lookandfeel.skincolors", m_strNewSkinColors);
255         g_settings.Save();
256       }
257
258       // Reload a resolution
259       if (m_NewResolution != INVALID)
260       {
261         g_guiSettings.SetInt("videoscreen.resolution", m_NewResolution);
262         //set the gui resolution, if newRes is AUTORES newRes will be set to the highest available resolution
263         g_graphicsContext.SetVideoResolution(m_NewResolution, TRUE);
264         //set our lookandfeelres to the resolution set in graphiccontext
265         g_guiSettings.m_LookAndFeelResolution = m_NewResolution;
266       }
267
268       if (IsActive())
269         m_returningFromSkinLoad = true;
270     }
271     break;
272   case GUI_MSG_WINDOW_INIT:
273     {
274       if (message.GetParam1() != WINDOW_INVALID && !m_returningFromSkinLoad)
275       { // coming to this window first time (ie not returning back from some other window)
276         // so we reset our section and control states
277         m_iSection = 0;
278         ResetControlStates();
279       }
280       m_returningFromSkinLoad = false;
281       m_iScreen = (int)message.GetParam2() - (int)m_dwWindowId;
282       return CGUIWindow::OnMessage(message);
283     }
284     break;
285   case GUI_MSG_WINDOW_DEINIT:
286     {
287       // Hardware based stuff
288       // TODO: This should be done in a completely separate screen
289       // to give warning to the user that it writes to the EEPROM.
290       if ((g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL))
291       {
292         g_audioConfig.SetAC3Enabled(g_guiSettings.GetBool("audiooutput.ac3passthrough"));
293         g_audioConfig.SetDTSEnabled(g_guiSettings.GetBool("audiooutput.dtspassthrough"));
294         if (g_audioConfig.NeedsSave())
295         { // should we perhaps show a dialog here?
296           g_audioConfig.Save();
297         }
298       }
299       switch(g_guiSettings.GetInt("videooutput.aspect"))
300       {
301       case VIDEO_NORMAL:
302         g_videoConfig.SetNormal();
303         break;
304       case VIDEO_LETTERBOX:
305         g_videoConfig.SetLetterbox(true);
306         break;
307       case VIDEO_WIDESCREEN:
308         g_videoConfig.SetWidescreen(true);
309         break;
310       }
311       g_videoConfig.Set480p(g_guiSettings.GetBool("videooutput.hd480p"));
312       g_videoConfig.Set720p(g_guiSettings.GetBool("videooutput.hd720p"));
313       g_videoConfig.Set1080i(g_guiSettings.GetBool("videooutput.hd1080i"));
314
315       if (g_videoConfig.NeedsSave())
316         g_videoConfig.Save();
317
318       if (g_timezone.GetTimeZoneIndex() != g_guiSettings.GetInt("locale.timezone"))
319         g_timezone.SetTimeZoneIndex(g_guiSettings.GetInt("locale.timezone"));
320
321       if (g_timezone.GetDST() != g_guiSettings.GetBool("locale.usedst"))
322         g_timezone.SetDST(g_guiSettings.GetBool("locale.usedst"));
323
324       CheckForUpdates();
325       CheckNetworkSettings();
326       CGUIWindow::OnMessage(message);
327       FreeControls();
328       return true;
329     }
330     break;
331   }
332   return CGUIWindow::OnMessage(message);
333 }
334
335 void CGUIWindowSettingsCategory::SetupControls()
336 {
337   // cleanup first, if necessary
338   FreeControls();
339   m_pOriginalSpin = (CGUISpinControlEx*)GetControl(CONTROL_DEFAULT_SPIN);
340   m_pOriginalRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_DEFAULT_RADIOBUTTON);
341   m_pOriginalCategoryButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_CATEGORY_BUTTON);
342   m_pOriginalButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_BUTTON);
343   m_pOriginalImage = (CGUIImage *)GetControl(CONTROL_DEFAULT_SEPARATOR);
344   if (!m_pOriginalCategoryButton || !m_pOriginalSpin || !m_pOriginalRadioButton || !m_pOriginalButton)
345     return ;
346   m_pOriginalEdit = (CGUIEditControl *)GetControl(CONTROL_DEFAULT_EDIT);
347   if (!m_pOriginalEdit || m_pOriginalEdit->GetControlType() != CGUIControl::GUICONTROL_EDIT)
348     m_pOriginalEdit = new CGUIEditControl(*m_pOriginalButton);
349   m_pOriginalSpin->SetVisible(false);
350   m_pOriginalRadioButton->SetVisible(false);
351   m_pOriginalButton->SetVisible(false);
352   m_pOriginalCategoryButton->SetVisible(false);
353   m_pOriginalEdit->SetVisible(false);
354   if (m_pOriginalImage) m_pOriginalImage->SetVisible(false);
355   // setup our control groups...
356 #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
357   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CATEGORY_GROUP_ID);
358   if (!group || group->GetControlType() != CGUIControl::GUICONTROL_GROUPLIST)
359   {
360     // get the area to use...
361     CGUIControl *area = (CGUIControl *)GetControl(CONTROL_BUTTON_AREA);
362     const CGUIControl *gap = GetControl(CONTROL_BUTTON_GAP);
363     if (!area || !gap)
364       return;
365     Remove(area);
366     group = new CGUIControlGroupList(GetID(), CATEGORY_GROUP_ID, area->GetXPosition(), area->GetYPosition(),
367                                      area->GetWidth(), 1080, gap->GetHeight() - m_pOriginalCategoryButton->GetHeight(),
368                                      0, VERTICAL, false);
369     group->SetNavigation(CATEGORY_GROUP_ID, CATEGORY_GROUP_ID, SETTINGS_GROUP_ID, SETTINGS_GROUP_ID);
370     Insert(group, gap);
371     area->FreeResources();
372     delete area;
373   }
374 #endif
375   // get a list of different sections
376   CSettingsGroup *pSettingsGroup = g_guiSettings.GetGroup(m_iScreen);
377   if (!pSettingsGroup) return ;
378   // update the screen string
379   SET_CONTROL_LABEL(CONTROL_SETTINGS_LABEL, pSettingsGroup->GetLabelID());
380   // get the categories we need
381   pSettingsGroup->GetCategories(m_vecSections);
382   // run through and create our buttons...
383   int j=0;
384   for (unsigned int i = 0; i < m_vecSections.size(); i++)
385   {
386     if (m_vecSections[i]->m_dwLabelID == 12360 && g_settings.m_iLastLoadedProfileIndex != 0)
387       continue;
388     CGUIButtonControl *pButton = NULL;
389     if (m_pOriginalCategoryButton->GetControlType() == CGUIControl::GUICONTROL_TOGGLEBUTTON)
390       pButton = new CGUIToggleButtonControl(*(CGUIToggleButtonControl *)m_pOriginalCategoryButton);
391     else
392       pButton = new CGUIButtonControl(*m_pOriginalCategoryButton);
393     pButton->SetLabel(g_localizeStrings.Get(m_vecSections[i]->m_dwLabelID));
394     pButton->SetID(CONTROL_START_BUTTONS + j);
395     pButton->SetVisible(true);
396     pButton->AllocResources();
397     group->AddControl(pButton);
398     j++;
399   }
400   if (m_iSection < 0 || m_iSection >= (int)m_vecSections.size())
401     m_iSection = 0;
402   CreateSettings();
403   // set focus correctly
404   m_dwDefaultFocusControlID = CONTROL_START_BUTTONS;
405 }
406
407 void CGUIWindowSettingsCategory::CreateSettings()
408 {
409   FreeSettingsControls();
410
411   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
412 #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
413   if (!group || group->GetControlType() != CGUIControl::GUICONTROL_GROUPLIST)
414   {
415     CGUIControl *area = (CGUIControl *)GetControl(CONTROL_AREA);
416     const CGUIControl *gap = GetControl(CONTROL_GAP);
417     Remove(area);
418     group = new CGUIControlGroupList(GetID(), SETTINGS_GROUP_ID, area->GetXPosition(), area->GetYPosition(),
419                                      area->GetWidth(), 1080, gap->GetHeight() - m_pOriginalButton->GetHeight(), 0, VERTICAL, false);
420     group->SetNavigation(SETTINGS_GROUP_ID, SETTINGS_GROUP_ID, CATEGORY_GROUP_ID, CATEGORY_GROUP_ID);
421     Insert(group, gap);
422     area->FreeResources();
423     delete area;
424   }
425 #endif
426   if (!group)
427     return;
428   vecSettings settings;
429   g_guiSettings.GetSettingsGroup(m_vecSections[m_iSection]->m_strCategory, settings);
430   int iControlID = CONTROL_START_CONTROL;
431   for (unsigned int i = 0; i < settings.size(); i++)
432   {
433     CSetting *pSetting = settings[i];
434     AddSetting(pSetting, group->GetWidth(), iControlID);
435     CStdString strSetting = pSetting->GetSetting();
436     if (strSetting.Equals("myprograms.ntscmode"))
437     {
438       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
439       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
440       for (int i = pSettingInt->m_iMin; i <= pSettingInt->m_iMax; i++)
441       {
442         pControl->AddLabel(g_localizeStrings.Get(16106 + i), i);
443       }
444       pControl->SetValue(pSettingInt->GetData());
445     }
446     else if (strSetting.Equals("mymusic.visualisation"))
447     {
448       FillInVisualisations(pSetting, GetSetting(pSetting->GetSetting())->GetID());
449     }
450     else if (strSetting.Equals("musiclibrary.defaultscraper"))
451     {
452       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
453       FillInMusicScrapers(pControl,g_stSettings.m_defaultMusicScraper);
454     }
455     else if (strSetting.Equals("karaoke.port0voicemask"))
456     {
457       FillInVoiceMasks(0, pSetting);
458     }
459     else if (strSetting.Equals("karaoke.port1voicemask"))
460     {
461       FillInVoiceMasks(1, pSetting);
462     }
463     else if (strSetting.Equals("karaoke.port2voicemask"))
464     {
465       FillInVoiceMasks(2, pSetting);
466     }
467     else if (strSetting.Equals("karaoke.port3voicemask"))
468     {
469       FillInVoiceMasks(3, pSetting);
470     }
471     else if (strSetting.Equals("audiooutput.mode"))
472     {
473       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
474       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
475       pControl->AddLabel(g_localizeStrings.Get(338), AUDIO_ANALOG);
476       if (g_audioConfig.HasDigitalOutput())
477         pControl->AddLabel(g_localizeStrings.Get(339), AUDIO_DIGITAL);
478       pControl->SetValue(pSettingInt->GetData());
479     }
480     else if (strSetting.Equals("videooutput.aspect"))
481     {
482       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
483       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
484       pControl->AddLabel(g_localizeStrings.Get(21375), VIDEO_NORMAL);
485       pControl->AddLabel(g_localizeStrings.Get(21376), VIDEO_LETTERBOX);
486       pControl->AddLabel(g_localizeStrings.Get(21377), VIDEO_WIDESCREEN);
487       pControl->SetValue(pSettingInt->GetData());
488     }
489     else if (strSetting.Equals("cddaripper.encoder"))
490     {
491       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
492       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
493       pControl->AddLabel("Lame", CDDARIP_ENCODER_LAME);
494       pControl->AddLabel("Vorbis", CDDARIP_ENCODER_VORBIS);
495       pControl->AddLabel("Wav", CDDARIP_ENCODER_WAV);
496       pControl->SetValue(pSettingInt->GetData());
497     }
498     else if (strSetting.Equals("cddaripper.quality"))
499     {
500       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
501       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
502       pControl->AddLabel(g_localizeStrings.Get(604), CDDARIP_QUALITY_CBR);
503       pControl->AddLabel(g_localizeStrings.Get(601), CDDARIP_QUALITY_MEDIUM);
504       pControl->AddLabel(g_localizeStrings.Get(602), CDDARIP_QUALITY_STANDARD);
505       pControl->AddLabel(g_localizeStrings.Get(603), CDDARIP_QUALITY_EXTREME);
506       pControl->SetValue(pSettingInt->GetData());
507     }
508     else if (strSetting.Equals("lcd.type"))
509     {
510       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
511       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
512       pControl->AddLabel(g_localizeStrings.Get(351), LCD_TYPE_NONE);
513       pControl->AddLabel("LCD - HD44780", LCD_TYPE_LCD_HD44780);
514       pControl->AddLabel("LCD - KS0073", LCD_TYPE_LCD_KS0073);
515       pControl->AddLabel("VFD", LCD_TYPE_VFD);
516       pControl->SetValue(pSettingInt->GetData());
517     }
518     else if (strSetting.Equals("lcd.modchip"))
519     {
520       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
521       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
522       pControl->AddLabel("SmartXX", MODCHIP_SMARTXX);
523       pControl->AddLabel("Xenium", MODCHIP_XENIUM);
524       pControl->AddLabel("Xecuter3", MODCHIP_XECUTER3);
525       pControl->SetValue(pSettingInt->GetData());
526     }
527     else if (strSetting.Equals("harddisk.aamlevel"))
528     {
529       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
530       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
531       pControl->AddLabel(g_localizeStrings.Get(21388), AAM_QUIET);
532       pControl->AddLabel(g_localizeStrings.Get(21387), AAM_FAST);
533       pControl->SetValue(pSettingInt->GetData());
534     }
535     else if (strSetting.Equals("harddisk.apmlevel"))
536     {
537       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
538       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
539       pControl->AddLabel(g_localizeStrings.Get(21391), APM_HIPOWER);
540       pControl->AddLabel(g_localizeStrings.Get(21392), APM_LOPOWER);
541       pControl->AddLabel(g_localizeStrings.Get(21393), APM_HIPOWER_STANDBY);
542       pControl->AddLabel(g_localizeStrings.Get(21394), APM_LOPOWER_STANDBY);
543       pControl->SetValue(pSettingInt->GetData());
544     }
545     else if (strSetting.Equals("system.targettemperature"))
546     {
547       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
548       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
549       for (int i = pSettingInt->m_iMin; i <= pSettingInt->m_iMax; i++)
550       {
551         CTemperature temp=CTemperature::CreateFromCelsius(i);
552         pControl->AddLabel(temp.ToString(), i);
553       }
554       pControl->SetValue(pSettingInt->GetData());
555     }
556     else if (strSetting.Equals("system.fanspeed") || strSetting.Equals("system.minfanspeed")) 
557     {
558       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
559       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
560       CStdString strPercentMask = g_localizeStrings.Get(14047);
561       for (int i=pSettingInt->m_iMin; i <= pSettingInt->m_iMax; i += pSettingInt->m_iStep)
562       {
563         CStdString strLabel;
564         strLabel.Format(strPercentMask.c_str(), i*2);
565         pControl->AddLabel(strLabel, i);
566       }
567       pControl->SetValue(int(pSettingInt->GetData()));
568     }
569     else if (strSetting.Equals("harddisk.remoteplayspindown"))
570     {
571       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
572       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
573       pControl->AddLabel(g_localizeStrings.Get(474), SPIN_DOWN_NONE);
574       pControl->AddLabel(g_localizeStrings.Get(475), SPIN_DOWN_MUSIC);
575       pControl->AddLabel(g_localizeStrings.Get(13002), SPIN_DOWN_VIDEO);
576       pControl->AddLabel(g_localizeStrings.Get(476), SPIN_DOWN_BOTH);
577       pControl->SetValue(pSettingInt->GetData());
578     }
579     else if (strSetting.Equals("servers.webserverpassword"))
580     { // get password from the webserver if it's running (and update our settings)
581       if (g_application.m_pWebServer)
582       {
583         ((CSettingString *)GetSetting(strSetting)->GetSetting())->SetData(g_application.m_pWebServer->GetPassword());
584         g_settings.Save();
585       }
586     }
587     else if (strSetting.Equals("network.assignment"))
588     {
589       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
590       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
591       pControl->AddLabel(g_localizeStrings.Get(718), NETWORK_DASH);
592       pControl->AddLabel(g_localizeStrings.Get(716), NETWORK_DHCP);
593       pControl->AddLabel(g_localizeStrings.Get(717), NETWORK_STATIC);
594       pControl->SetValue(pSettingInt->GetData());
595     }
596     else if (strSetting.Equals("subtitles.style"))
597     {
598       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
599       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
600       pControl->AddLabel(g_localizeStrings.Get(738), FONT_STYLE_NORMAL);
601       pControl->AddLabel(g_localizeStrings.Get(739), FONT_STYLE_BOLD);
602       pControl->AddLabel(g_localizeStrings.Get(740), FONT_STYLE_ITALICS);
603       pControl->AddLabel(g_localizeStrings.Get(741), FONT_STYLE_BOLD_ITALICS);
604       pControl->SetValue(pSettingInt->GetData());
605     }
606     else if (strSetting.Equals("subtitles.color"))
607     {
608       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
609       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
610       for (int i = SUBTITLE_COLOR_START; i <= SUBTITLE_COLOR_END; i++)
611         pControl->AddLabel(g_localizeStrings.Get(760 + i), i);
612       pControl->SetValue(pSettingInt->GetData());
613     }
614     else if (strSetting.Equals("subtitles.height"))
615     {
616       FillInSubtitleHeights(pSetting);
617     }
618     else if (strSetting.Equals("subtitles.font"))
619     {
620       FillInSubtitleFonts(pSetting);
621     }
622     else if (strSetting.Equals("subtitles.charset") || strSetting.Equals("locale.charset"))
623     {
624       FillInCharSets(pSetting);
625     }
626     else if (strSetting.Equals("lookandfeel.font"))
627     {
628       FillInSkinFonts(pSetting);
629     }
630     else if (strSetting.Equals("lookandfeel.skin"))
631     {
632       FillInSkins(pSetting);
633     }
634     else if (strSetting.Equals("lookandfeel.soundskin"))
635     {
636       FillInSoundSkins(pSetting);
637     }
638     else if (strSetting.Equals("locale.language"))
639     {
640       FillInLanguages(pSetting);
641     }
642     else if (strSetting.Equals("locale.timezone"))
643     {
644       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
645       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
646       for (int i=0; i < g_timezone.GetNumberOfTimeZones(); i++)
647         pControl->AddLabel(g_timezone.GetTimeZoneString(i), i);
648       pControl->SetValue(pSettingInt->GetData());
649     }
650     else if (strSetting.Equals("videoscreen.resolution"))
651     {
652       FillInResolutions(pSetting, false);
653     }
654     else if (strSetting.Equals("lookandfeel.skintheme"))
655     {
656       FillInSkinThemes(pSetting);
657     }
658     else if (strSetting.Equals("lookandfeel.skincolors"))
659     {
660       FillInSkinColors(pSetting);
661     }
662     else if (strSetting.Equals("screensaver.mode"))
663     {
664       FillInScreenSavers(pSetting);
665     }
666     else if (strSetting.Equals("videoplayer.displayresolution") || strSetting.Equals("pictures.displayresolution"))
667     {
668       FillInResolutions(pSetting, true);
669     }
670     else if (strSetting.Equals("videoplayer.framerateconversions"))
671     {
672       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
673       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
674       pControl->AddLabel(g_localizeStrings.Get(231), FRAME_RATE_LEAVE_AS_IS); // "None"
675       pControl->AddLabel(g_videoConfig.HasPAL() ? g_localizeStrings.Get(12380) : g_localizeStrings.Get(12381), FRAME_RATE_CONVERT); // "Play PAL videos at NTSC rates" or "Play NTSC videos at PAL rates"
676       if (g_videoConfig.HasPAL() && g_videoConfig.HasPAL60())
677         pControl->AddLabel(g_localizeStrings.Get(12382), FRAME_RATE_USE_PAL60); // "Play NTSC videos in PAL60"
678       pControl->SetValue(pSettingInt->GetData());
679     }
680     else if (strSetting.Equals("videolibrary.flattentvshows"))
681     {
682       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
683       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
684       pControl->AddLabel(g_localizeStrings.Get(20420), 0); // Never
685       pControl->AddLabel(g_localizeStrings.Get(20421), 1); // One Season
686       pControl->AddLabel(g_localizeStrings.Get(20422), 2); // Always
687       pControl->SetValue(pSettingInt->GetData());
688     }
689     else if (strSetting.Equals("system.ledcolour"))
690     {
691       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
692       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
693       pControl->AddLabel(g_localizeStrings.Get(13340), LED_COLOUR_NO_CHANGE);
694       pControl->AddLabel(g_localizeStrings.Get(13341), LED_COLOUR_GREEN);
695       pControl->AddLabel(g_localizeStrings.Get(13342), LED_COLOUR_ORANGE);
696       pControl->AddLabel(g_localizeStrings.Get(13343), LED_COLOUR_RED);
697       pControl->AddLabel(g_localizeStrings.Get(13344), LED_COLOUR_CYCLE);
698       pControl->AddLabel(g_localizeStrings.Get(351), LED_COLOUR_OFF);
699       pControl->SetValue(pSettingInt->GetData());
700     }
701     else if (strSetting.Equals("system.leddisableonplayback") || strSetting.Equals("lcd.disableonplayback"))
702     {
703       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
704       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
705       pControl->AddLabel(g_localizeStrings.Get(106), LED_PLAYBACK_OFF);     // No
706       pControl->AddLabel(g_localizeStrings.Get(13002), LED_PLAYBACK_VIDEO);   // Video Only
707       pControl->AddLabel(g_localizeStrings.Get(475), LED_PLAYBACK_MUSIC);    // Music Only
708       pControl->AddLabel(g_localizeStrings.Get(476), LED_PLAYBACK_VIDEO_MUSIC); // Video & Music
709       pControl->SetValue(pSettingInt->GetData());
710     }
711     else if (strSetting.Equals("videoplayer.rendermethod"))
712     {
713       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
714       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
715       pControl->AddLabel(g_localizeStrings.Get(13355), RENDER_LQ_RGB_SHADER);
716       pControl->AddLabel(g_localizeStrings.Get(13356), RENDER_OVERLAYS);
717       pControl->AddLabel(g_localizeStrings.Get(13357), RENDER_HQ_RGB_SHADER);
718       pControl->AddLabel(g_localizeStrings.Get(21397), RENDER_HQ_RGB_SHADERV2);
719       pControl->SetValue(pSettingInt->GetData());
720     }
721     else if (strSetting.Equals("musicplayer.replaygaintype"))
722     {
723       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
724       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
725       pControl->AddLabel(g_localizeStrings.Get(351), REPLAY_GAIN_NONE);
726       pControl->AddLabel(g_localizeStrings.Get(639), REPLAY_GAIN_TRACK);
727       pControl->AddLabel(g_localizeStrings.Get(640), REPLAY_GAIN_ALBUM);
728       pControl->SetValue(pSettingInt->GetData());
729     }
730     else if (strSetting.Equals("lookandfeel.startupwindow"))
731     {
732       FillInStartupWindow(pSetting);
733     }
734     else if (strSetting.Equals("servers.ftpserveruser"))
735     {
736       FillInFTPServerUser(pSetting);
737     }
738     else if (strSetting.Equals("autodetect.nickname"))
739     {
740 #ifdef HAS_XBOX_HARDWARE
741       CStdString strXboxNickNameOut;
742       if (CUtil::GetXBOXNickName(strXboxNickNameOut))
743         g_guiSettings.SetString("autodetect.nickname", strXboxNickNameOut.c_str());
744 #endif
745     }
746     else if (strSetting.Equals("videoplayer.externaldvdplayer"))
747     {
748       CSettingString *pSettingString = (CSettingString *)pSetting;
749       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(GetSetting(strSetting)->GetID());
750       if (pSettingString->GetData().IsEmpty())
751         pControl->SetLabel2(g_localizeStrings.Get(20009));
752     }
753     else if (strSetting.Equals("locale.country"))
754     {
755       FillInRegions(pSetting);
756     }
757     else if (strSetting.Equals("musicfiles.viewmode"))
758     {
759       FillInViewModes(pSetting, WINDOW_MUSIC_FILES);
760     }
761     else if (strSetting.Equals("myvideos.viewmode"))
762     {
763       FillInViewModes(pSetting, WINDOW_VIDEO_FILES);
764     }
765     else if (strSetting.Equals("programfiles.viewmode"))
766     {
767       FillInViewModes(pSetting, WINDOW_PROGRAMS);
768     }
769     else if (strSetting.Equals("pictures.viewmode"))
770     {
771       FillInViewModes(pSetting, WINDOW_PICTURES);
772     }
773     else if (strSetting.Equals("musicfiles.sortmethod"))
774     {
775       FillInSortMethods(pSetting, WINDOW_MUSIC_FILES);
776     }
777     else if (strSetting.Equals("myvideos.sortmethod"))
778     {
779       FillInSortMethods(pSetting, WINDOW_VIDEO_FILES);
780     }
781     else if (strSetting.Equals("programfiles.sortmethod"))
782     {
783       FillInSortMethods(pSetting, WINDOW_PROGRAMS);
784     }
785     else if (strSetting.Equals("pictures.sortmethod"))
786     {
787       FillInSortMethods(pSetting, WINDOW_PICTURES);
788     }
789     else if (strSetting.Equals("musicfiles.sortorder") ||
790              strSetting.Equals("myvideos.sortorder") ||
791              strSetting.Equals("pictures.sortorder") ||
792              strSetting.Equals("programfiles.sortorder"))
793     {
794       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
795       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(strSetting)->GetID());
796       pControl->AddLabel(g_localizeStrings.Get(584), SORT_ORDER_ASC);
797       pControl->AddLabel(g_localizeStrings.Get(585), SORT_ORDER_DESC);
798       pControl->SetValue(pSettingInt->GetData());
799     }
800   }
801   // update our settings (turns controls on/off as appropriate)
802   UpdateSettings();
803 }
804
805 void CGUIWindowSettingsCategory::UpdateSettings()
806 {
807   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
808   {
809     CBaseSettingControl *pSettingControl = m_vecSettings[i];
810     pSettingControl->Update();
811     CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
812     if (strSetting.Equals("filelists.allowfiledeletion"))
813     {
814       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
815       if (pControl) pControl->SetEnabled(!g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].filesLocked() || g_passwordManager.bMasterUser);
816     }
817     else if (strSetting.Equals("filelists.disableaddsourcebuttons"))
818     {
819       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
820       if (pControl) pControl->SetEnabled(g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].canWriteSources() || g_passwordManager.bMasterUser);
821     }
822     else if (strSetting.Equals("myprograms.ntscmode"))
823     { // set visibility based on our other setting...
824       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
825       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("myprograms.gameautoregion"));
826     }
827     else if (strSetting.Equals("masterlock.startuplock") || strSetting.Equals("masterlock.enableshutdown") || strSetting.Equals("masterlock.automastermode"))
828     {
829       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
830       if (pControl) pControl->SetEnabled(g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE);
831     }
832     else if (strSetting.Equals("masterlock.loginlock"))
833     {
834       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
835       if (pControl) pControl->SetEnabled(g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE && g_settings.bUseLoginScreen);
836     }
837     else if (strSetting.Equals("screensaver.uselock"))
838     {
839       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
840       if (pControl) pControl->SetEnabled(g_settings.m_vecProfiles[0].getLockMode() != LOCK_MODE_EVERYONE                                    &&
841                                          g_settings.m_vecProfiles[g_settings.m_iLastLoadedProfileIndex].getLockMode() != LOCK_MODE_EVERYONE &&
842                                          !g_guiSettings.GetString("screensaver.mode").Equals("Black"));
843     }
844     else if (strSetting.Equals("upnp.musicshares") || strSetting.Equals("upnp.videoshares") || strSetting.Equals("upnp.pictureshares"))
845     {
846       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
847       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("upnp.server"));
848     }
849     else if (!strSetting.Equals("remoteevents.enabled")
850              && strSetting.Left(13).Equals("remoteevents."))
851     {
852       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
853       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("remoteevents.enabled"));
854     }
855     else if (strSetting.Equals("mymusic.clearplaylistsonend"))
856     { // disable repeat and repeat one if clear playlists is enabled
857       if (g_guiSettings.GetBool("mymusic.clearplaylistsonend"))
858       {
859         g_playlistPlayer.SetRepeat(PLAYLIST_MUSIC, PLAYLIST::REPEAT_NONE);
860         g_stSettings.m_bMyMusicPlaylistRepeat = false;
861         g_settings.Save();
862       }
863     }
864     else if (strSetting.Equals("cddaripper.quality"))
865     { // only visible if we are doing non-WAV ripping
866       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
867       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("cddaripper.encoder") != CDDARIP_ENCODER_WAV);
868     }
869     else if (strSetting.Equals("cddaripper.bitrate"))
870     { // only visible if we are ripping to CBR
871       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
872       if (pControl) pControl->SetEnabled((g_guiSettings.GetInt("cddaripper.encoder") != CDDARIP_ENCODER_WAV) &&
873                                            (g_guiSettings.GetInt("cddaripper.quality") == CDDARIP_QUALITY_CBR));
874     }
875     else if (strSetting.Equals("musicplayer.outputtoallspeakers") || strSetting.Equals("audiooutput.ac3passthrough") || strSetting.Equals("audiooutput.dtspassthrough"))
876     { // only visible if we are in digital mode
877       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
878       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("audiooutput.mode") == AUDIO_DIGITAL);
879     }
880     else if (strSetting.Equals("videooutput.hd480p") || strSetting.Equals("videooutput.hd720p") || strSetting.Equals("videooutput.hd1080i"))
881     {
882       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
883       // disable if we do not have the HDTV pack and are not NTSC
884 #ifdef HAS_XBOX_HARDWARE
885       if (pControl) pControl->SetEnabled(g_videoConfig.HasNTSC() && g_videoConfig.HasHDPack());
886 #endif
887     }
888     else if (strSetting.Equals("musicplayer.crossfadealbumtracks"))
889     {
890       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
891       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("musicplayer.crossfade") > 0);
892     }
893     else if (strSetting.Left(12).Equals("karaoke.port") || strSetting.Equals("karaoke.volume"))
894     {
895       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
896       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("karaoke.voiceenabled"));
897     }
898     else if (strSetting.Equals("system.fanspeed"))
899     { // only visible if we have fancontrolspeed enabled
900       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
901       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("system.fanspeedcontrol"));
902     }
903     else if (strSetting.Equals("system.targettemperature") || strSetting.Equals("system.minfanspeed"))
904     { // only visible if we have autotemperature enabled
905       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
906       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("system.autotemperature"));
907     }
908     else if (strSetting.Equals("harddisk.remoteplayspindowndelay"))
909     { // only visible if we have spin down enabled
910       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
911       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("harddisk.remoteplayspindown") != SPIN_DOWN_NONE);
912     }
913     else if (strSetting.Equals("harddisk.remoteplayspindownminduration"))
914     { // only visible if we have spin down enabled
915       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
916       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("harddisk.remoteplayspindown") != SPIN_DOWN_NONE);
917     }
918     else if (strSetting.Equals("servers.ftpserveruser") || strSetting.Equals("servers.ftpserverpassword") || strSetting.Equals("servers.ftpautofatx"))
919     {
920       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
921       pControl->SetEnabled(g_guiSettings.GetBool("servers.ftpserver"));
922     }
923     else if (strSetting.Equals("servers.webserverpassword"))
924     { // Fill in a blank pass if we don't have it
925       CGUIEditControl *pControl = (CGUIEditControl *)GetControl(pSettingControl->GetID());
926       if (((CSettingString *)pSettingControl->GetSetting())->GetData().size() == 0 && pControl)
927       {
928         pControl->SetLabel2(g_localizeStrings.Get(734));
929         pControl->SetEnabled(g_guiSettings.GetBool("servers.webserver"));
930       }
931     }
932     else if (strSetting.Equals("servers.webserverport"))
933     {
934       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
935       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("servers.webserver"));
936     }
937     else if (strSetting.Equals("network.ipaddress") || strSetting.Equals("network.subnet") || strSetting.Equals("network.gateway") || strSetting.Equals("network.dns"))
938     {
939       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
940       if (pControl)
941       {
942         if (g_guiSettings.GetInt("network.assignment") != NETWORK_STATIC)
943         {
944           //We are in non Static Mode! Setting the Received IP Information
945           if(strSetting.Equals("network.ipaddress"))
946             pControl->SetLabel2(g_network.m_networkinfo.ip);
947           else if(strSetting.Equals("network.subnet"))
948             pControl->SetLabel2(g_network.m_networkinfo.subnet);
949           else if(strSetting.Equals("network.gateway"))
950             pControl->SetLabel2(g_network.m_networkinfo.gateway);
951           else if(strSetting.Equals("network.dns"))
952             pControl->SetLabel2(g_network.m_networkinfo.DNS1);
953         }
954         pControl->SetEnabled(g_guiSettings.GetInt("network.assignment") == NETWORK_STATIC);
955       }
956     }
957     else if (strSetting.Equals("network.httpproxyserver") || strSetting.Equals("network.httpproxyport"))
958     {
959       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
960       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("network.usehttpproxy"));
961     }
962     else if (strSetting.Equals("postprocessing.verticaldeblocklevel"))
963     {
964       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
965       pControl->SetEnabled(g_guiSettings.GetBool("postprocessing.verticaldeblocking") &&
966                            g_guiSettings.GetBool("postprocessing.enable") &&
967                            !g_guiSettings.GetBool("postprocessing.auto"));
968     }
969     else if (strSetting.Equals("postprocessing.horizontaldeblocklevel"))
970     {
971       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
972       pControl->SetEnabled(g_guiSettings.GetBool("postprocessing.horizontaldeblocking") &&
973                            g_guiSettings.GetBool("postprocessing.enable") &&
974                            !g_guiSettings.GetBool("postprocessing.auto"));
975     }
976     else if (strSetting.Equals("postprocessing.verticaldeblocking") || strSetting.Equals("postprocessing.horizontaldeblocking") || strSetting.Equals("postprocessing.autobrightnesscontrastlevels") || strSetting.Equals("postprocessing.dering"))
977     {
978       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
979       pControl->SetEnabled(g_guiSettings.GetBool("postprocessing.enable") &&
980                            !g_guiSettings.GetBool("postprocessing.auto"));
981     }
982     else if (strSetting.Equals("postprocessing.auto"))
983     {
984       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
985       pControl->SetEnabled(g_guiSettings.GetBool("postprocessing.enable"));
986     }
987     else if (strSetting.Equals("VideoPlayer.InvertFieldSync"))
988     {
989       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
990       pControl->SetEnabled(g_guiSettings.GetBool("VideoPlayer.FieldSync"));
991     }
992     else if (strSetting.Equals("subtitles.color") || strSetting.Equals("subtitles.style") || strSetting.Equals("subtitles.charset"))
993     {
994       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
995       pControl->SetEnabled(CUtil::IsUsingTTFSubtitles());
996     }
997     else if (strSetting.Equals("locale.charset"))
998     { // TODO: Determine whether we are using a TTF font or not.
999       //   CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1000       //   if (pControl) pControl->SetEnabled(g_guiSettings.GetString("lookandfeel.font").Right(4) == ".ttf");
1001     }
1002     else if (strSetting.Equals("screensaver.dimlevel"))
1003     {
1004       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
1005       pControl->SetEnabled(g_guiSettings.GetString("screensaver.mode") == "Dim");
1006     }
1007     else if (strSetting.Equals("screensaver.slideshowpath"))
1008     {
1009       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(GetSetting(strSetting)->GetID());
1010       pControl->SetEnabled(g_guiSettings.GetString("screensaver.mode") == "SlideShow");
1011     }
1012     else if (strSetting.Equals("screensaver.slideshowshuffle"))
1013     {
1014       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
1015       pControl->SetEnabled(g_guiSettings.GetString("screensaver.mode") == "SlideShow");
1016     }
1017     else if (strSetting.Equals("screensaver.preview"))
1018     {
1019       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
1020       pControl->SetEnabled(g_guiSettings.GetString("screensaver.mode") != "None");
1021     }
1022     else if (strSetting.Left(16).Equals("weather.areacode"))
1023     {
1024       CSettingString *pSetting = (CSettingString *)GetSetting(strSetting)->GetSetting();
1025       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(GetSetting(strSetting)->GetID());
1026       pControl->SetLabel2(g_weatherManager.GetAreaCity(pSetting->GetData()));
1027     }
1028     else if (strSetting.Equals("system.leddisableonplayback"))
1029     {
1030       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
1031       // LED_COLOUR_NO_CHANGE: we can't disable the LED on playback, 
1032       //                       we have no previos reference LED COLOUR, to set the LED colour back
1033       pControl->SetEnabled(g_guiSettings.GetInt("system.ledcolour") != LED_COLOUR_NO_CHANGE && g_guiSettings.GetInt("system.ledcolour") != LED_COLOUR_OFF);
1034     }
1035     else if (strSetting.Equals("musicfiles.trackformat"))
1036     {
1037       if (m_strOldTrackFormat != g_guiSettings.GetString("musicfiles.trackformat"))
1038       {
1039         CUtil::DeleteMusicDatabaseDirectoryCache();
1040         m_strOldTrackFormat = g_guiSettings.GetString("musicfiles.trackformat");
1041       }
1042     }
1043     else if (strSetting.Equals("musicfiles.trackformatright"))
1044     {
1045       if (m_strOldTrackFormatRight != g_guiSettings.GetString("musicfiles.trackformatright"))
1046       {
1047         CUtil::DeleteMusicDatabaseDirectoryCache();
1048         m_strOldTrackFormatRight = g_guiSettings.GetString("musicfiles.trackformatright");
1049       }
1050     }
1051 #ifdef HAS_TIME_SERVER
1052     else if (strSetting.Equals("locale.timeserveraddress"))
1053     {
1054       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1055       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("locale.timeserver"));
1056     }
1057     else if (strSetting.Equals("locale.time") || strSetting.Equals("locale.date"))
1058     {
1059       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1060       if (pControl) pControl->SetEnabled(!g_guiSettings.GetBool("locale.timeserver"));
1061       SYSTEMTIME curTime;
1062       GetLocalTime(&curTime);
1063       CStdString time;
1064       if (strSetting.Equals("locale.time"))
1065         time = g_infoManager.GetTime();
1066       else
1067         time = g_infoManager.GetDate();
1068       CSettingString *pSettingString = (CSettingString*)pSettingControl->GetSetting();
1069       pSettingString->SetData(time);
1070       pSettingControl->Update();
1071     }
1072 #endif
1073     else if (strSetting.Equals("autodetect.nickname") || strSetting.Equals("autodetect.senduserpw"))
1074     {
1075       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1076       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("autodetect.onoff") && (g_settings.m_iLastLoadedProfileIndex == 0));
1077     }
1078     else if ( strSetting.Equals("autodetect.popupinfo"))
1079     {
1080       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1081       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("autodetect.onoff"));
1082     }
1083     else if (strSetting.Equals("videoplayer.externaldvdplayer"))
1084     {
1085       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1086       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("videoplayer.useexternaldvdplayer"));
1087     }
1088     else if (strSetting.Equals("myprograms.trainerpath") || strSetting.Equals("cddaripper.path") || strSetting.Equals("mymusic.recordingpath") || strSetting.Equals("pictures.screenshotpath"))
1089     {
1090       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
1091       if (pControl && g_guiSettings.GetString(strSetting, false).IsEmpty())
1092         pControl->SetLabel2("");
1093     }
1094     else if (strSetting.Equals("myprograms.dashboard"))
1095     {
1096       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1097       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("myprograms.usedashpath"));
1098     }
1099     else if (strSetting.Equals("lcd.enableonpaused"))
1100     {
1101       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1102       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("lcd.disableonplayback") != LED_PLAYBACK_OFF && g_guiSettings.GetInt("lcd.type") != LCD_TYPE_NONE);
1103     }
1104     else if (strSetting.Equals("system.ledenableonpaused"))
1105     {
1106       // LED_COLOUR_NO_CHANGE: we can't enable LED on paused, 
1107       //                       we have no previos reference LED COLOUR, to set the LED colour back
1108       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1109       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("system.leddisableonplayback") != LED_PLAYBACK_OFF && g_guiSettings.GetInt("system.ledcolour") != LED_COLOUR_OFF && g_guiSettings.GetInt("system.ledcolour") != LED_COLOUR_NO_CHANGE);
1110     }
1111     else if (strSetting.Equals("lcd.modchip") || strSetting.Equals("lcd.backlight") || strSetting.Equals("lcd.disableonplayback"))
1112     {
1113       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1114       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("lcd.type") != LCD_TYPE_NONE);
1115     }
1116     else if (strSetting.Equals("lcd.contrast"))
1117     {
1118       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1119       // X3 can't controll the Contrast via software graying out!
1120       if(g_guiSettings.GetInt("lcd.type") != LCD_TYPE_NONE)
1121       {
1122         if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("lcd.modchip") != MODCHIP_XECUTER3);
1123       }
1124       else 
1125       { 
1126         if (pControl) pControl->SetEnabled(false); 
1127       }
1128     }
1129     else if (strSetting.Equals("lookandfeel.soundsduringplayback"))
1130     {
1131       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1132       if (pControl) pControl->SetEnabled(g_guiSettings.GetString("lookandfeel.soundskin") != "OFF");
1133     }
1134     else if (!strSetting.Equals("musiclibrary.enabled")
1135       && strSetting.Left(13).Equals("musiclibrary."))
1136     {
1137       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1138       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("musiclibrary.enabled"));
1139     }
1140     else if (!strSetting.Equals("videolibrary.enabled")
1141       && strSetting.Left(13).Equals("videolibrary."))
1142     {
1143       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1144       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("videolibrary.enabled"));
1145     }
1146     else if (strSetting.Equals("lookandfeel.rssfeedsrtl"))
1147     { // only visible if rss is enabled
1148       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1149       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("lookandfeel.enablerssfeeds"));
1150     }
1151   }
1152 }
1153
1154 void CGUIWindowSettingsCategory::UpdateRealTimeSettings()
1155 {
1156   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
1157   {
1158     CBaseSettingControl *pSettingControl = m_vecSettings[i];
1159     CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
1160     if (strSetting.Equals("locale.time") || strSetting.Equals("locale.date"))
1161     {
1162 #ifdef HAS_TIME_SERVER
1163       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1164       if (pControl) pControl->SetEnabled(!g_guiSettings.GetBool("locale.timeserver"));
1165 #endif
1166       SYSTEMTIME curTime;
1167       GetLocalTime(&curTime);
1168       CStdString time;
1169       if (strSetting.Equals("locale.time"))
1170         time = g_infoManager.GetTime();
1171       else
1172         time = g_infoManager.GetDate();
1173       CSettingString *pSettingString = (CSettingString*)pSettingControl->GetSetting();
1174       pSettingString->SetData(time);
1175       pSettingControl->Update();
1176     }
1177   }
1178 }
1179
1180 void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
1181 {
1182   CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
1183   if (strSetting.Left(16).Equals("weather.areacode"))
1184   {
1185     CStdString strSearch;
1186     if (CGUIDialogKeyboard::ShowAndGetInput(strSearch, g_localizeStrings.Get(14024), false))
1187     {
1188       strSearch.Replace(" ", "+");
1189       CStdString strResult = ((CSettingString *)pSettingControl->GetSetting())->GetData();
1190       if (g_weatherManager.GetSearchResults(strSearch, strResult))
1191         ((CSettingString *)pSettingControl->GetSetting())->SetData(strResult);
1192       g_weatherManager.ResetTimer();
1193     }
1194   }
1195
1196   // if OnClick() returns false, the setting hasn't changed or doesn't
1197   // require immediate update
1198   if (!pSettingControl->OnClick())
1199   {
1200     UpdateSettings();
1201     return;
1202   }
1203
1204   OnSettingChanged(pSettingControl);
1205 }
1206
1207 void CGUIWindowSettingsCategory::CheckForUpdates()
1208 {
1209   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
1210   {
1211     CBaseSettingControl *pSettingControl = m_vecSettings[i];
1212     if (pSettingControl->NeedsUpdate())
1213     {
1214       OnSettingChanged(pSettingControl);
1215       pSettingControl->Reset();
1216     }
1217   }
1218 }
1219
1220 void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingControl)
1221 {
1222   CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
1223
1224   // ok, now check the various special things we need to do
1225   if (strSetting.Equals("mymusic.visualisation"))
1226   { // new visualisation choosen...
1227     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1228     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1229     if (pControl->GetValue() == 0)
1230       pSettingString->SetData("None");
1231     else
1232       pSettingString->SetData(pControl->GetCurrentLabel() + ".vis");
1233   }
1234   else if (strSetting.Equals("system.debuglogging"))
1235   {
1236     if (g_guiSettings.GetBool("system.debuglogging") && g_advancedSettings.m_logLevel < LOG_LEVEL_DEBUG_FREEMEM)
1237     {
1238       g_advancedSettings.m_logLevel = LOG_LEVEL_DEBUG_FREEMEM;
1239       CLog::Log(LOGNOTICE, "Enabled debug logging due to GUI setting");
1240     }
1241     else if (!g_guiSettings.GetBool("system.debuglogging") && g_advancedSettings.m_logLevel == LOG_LEVEL_DEBUG_FREEMEM)
1242     {
1243       CLog::Log(LOGNOTICE, "Disabled debug logging due to GUI setting");
1244       g_advancedSettings.m_logLevel = LOG_LEVEL_NORMAL;
1245     }
1246   }
1247   /*else if (strSetting.Equals("musicfiles.repeat"))
1248   {
1249     g_playlistPlayer.SetRepeat(PLAYLIST_MUSIC_TEMP, g_guiSettings.GetBool("musicfiles.repeat") ? PLAYLIST::REPEAT_ALL : PLAYLIST::REPEAT_NONE);
1250   }*/
1251   else if (strSetting.Equals("karaoke.port0voicemask"))
1252   {
1253     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1254     g_guiSettings.SetString("karaoke.port0voicemask", pControl->GetCurrentLabel());
1255     FillInVoiceMaskValues(0, g_guiSettings.GetSetting("karaoke.port0voicemask"));
1256   }
1257   else if (strSetting.Equals("karaoke.port1voicemask"))
1258   {
1259     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1260     g_guiSettings.SetString("karaoke.port1voicemask", pControl->GetCurrentLabel());
1261     FillInVoiceMaskValues(1, g_guiSettings.GetSetting("karaoke.port1voicemask"));
1262   }
1263   else if (strSetting.Equals("karaoke.port2voicemask"))
1264   {
1265     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1266     g_guiSettings.SetString("karaoke.port2voicemask", pControl->GetCurrentLabel());
1267     FillInVoiceMaskValues(2, g_guiSettings.GetSetting("karaoke.port2voicemask"));
1268   }
1269   else if (strSetting.Equals("karaoke.port2voicemask"))
1270   {
1271     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1272     g_guiSettings.SetString("karaoke.port3voicemask", pControl->GetCurrentLabel());
1273     FillInVoiceMaskValues(3, g_guiSettings.GetSetting("karaoke.port3voicemask"));
1274   }
1275   else if (strSetting.Equals("musiclibrary.cleanup"))
1276   {
1277     CMusicDatabase musicdatabase;
1278     musicdatabase.Clean();
1279     CUtil::DeleteMusicDatabaseDirectoryCache();
1280   }
1281   else if (strSetting.Equals("musiclibrary.defaultscraper"))
1282   {
1283     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1284     g_guiSettings.SetString("musiclibrary.defaultscraper", pControl->GetCurrentLabel());
1285     FillInMusicScrapers(pControl,pControl->GetCurrentLabel());
1286   }
1287   else if (strSetting.Equals("videolibrary.cleanup"))
1288   {
1289     if (CGUIDialogYesNo::ShowAndGetInput(313, 333, 0, 0))
1290     {
1291       CVideoDatabase videodatabase;
1292       videodatabase.Open();
1293       videodatabase.CleanDatabase();
1294       videodatabase.Close();
1295     }
1296   }
1297   else if (strSetting.Equals("videolibrary.export"))
1298   {
1299     CStdString path(g_settings.GetDatabaseFolder());
1300     VECSOURCES shares;
1301     g_mediaManager.GetLocalDrives(shares);
1302     if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(661), path, true))
1303     {
1304       CUtil::AddFileToFolder(path, "videodb.xml", path);
1305       CVideoDatabase videodatabase;
1306       videodatabase.Open();
1307       videodatabase.ExportToXML(path);
1308       videodatabase.Close();
1309     }
1310   }
1311   else if (strSetting.Equals("musiclibrary.export"))
1312   {
1313     CStdString path(g_settings.GetDatabaseFolder());
1314     VECSOURCES shares;
1315     g_mediaManager.GetLocalDrives(shares);
1316     if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(661), path, true))
1317     {
1318       CUtil::AddFileToFolder(path, "musicdb.xml", path);
1319       CMusicDatabase musicdatabase;
1320       musicdatabase.Open();
1321       musicdatabase.ExportToXML(path);
1322       musicdatabase.Close();
1323     }
1324   }
1325   else if (strSetting.Equals("videolibrary.import"))
1326   {
1327     CStdString path(g_settings.GetDatabaseFolder());
1328     VECSOURCES shares;
1329     g_mediaManager.GetLocalDrives(shares);
1330     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, "videodb.xml", g_localizeStrings.Get(651) , path))
1331     {
1332       CVideoDatabase videodatabase;
1333       videodatabase.Open();
1334       videodatabase.ImportFromXML(path);
1335       videodatabase.Close();
1336     }
1337   }
1338   else if (strSetting.Equals("musiclibrary.import"))
1339   {
1340     CStdString path(g_settings.GetDatabaseFolder());
1341     VECSOURCES shares;
1342     g_mediaManager.GetLocalDrives(shares);
1343     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, "musicdb.xml", g_localizeStrings.Get(651) , path))
1344     {
1345       CMusicDatabase musicdatabase;
1346       musicdatabase.Open();
1347       musicdatabase.ImportFromXML(path);
1348       musicdatabase.Close();
1349     }
1350   }
1351   else if (strSetting.Equals("musicplayer.jumptoaudiohardware") || strSetting.Equals("videoplayer.jumptoaudiohardware"))
1352   {
1353     JumpToSection(WINDOW_SETTINGS_SYSTEM, "audiooutput");
1354   }
1355   else if (strSetting.Equals("musicplayer.jumptocache") || strSetting.Equals("videoplayer.jumptocache"))
1356   {
1357     JumpToSection(WINDOW_SETTINGS_SYSTEM, "cache");
1358   }
1359   else if (strSetting.Equals("weather.jumptolocale"))
1360   {
1361     JumpToSection(WINDOW_SETTINGS_APPEARANCE, "locale");
1362   }
1363   else if (strSetting.Equals("lastfm.enable") || strSetting.Equals("lastfm.username") || strSetting.Equals("lastfm.password"))
1364   {
1365     if (g_guiSettings.GetBool("lastfm.enable") || g_guiSettings.GetBool("lastfm.recordtoprofile"))
1366     {
1367       CStdString strPassword=g_guiSettings.GetString("lastfm.password");
1368       CStdString strUserName=g_guiSettings.GetString("lastfm.username");
1369       if (!strUserName.IsEmpty() || !strPassword.IsEmpty())
1370         CScrobbler::GetInstance()->Init();
1371     }
1372     else
1373     {
1374       CScrobbler::GetInstance()->Term();
1375     }
1376   }
1377   else if (strSetting.Equals("musicplayer.outputtoallspeakers"))
1378   {
1379     if (!g_application.IsPlaying())
1380     {
1381       g_audioContext.SetActiveDevice(CAudioContext::DEFAULT_DEVICE);
1382     }
1383   }
1384   else if (strSetting.Left(22).Equals("MusicPlayer.ReplayGain"))
1385   { // Update our replaygain settings
1386     g_guiSettings.m_replayGain.iType = g_guiSettings.GetInt("musicplayer.replaygaintype");
1387     g_guiSettings.m_replayGain.iPreAmp = g_guiSettings.GetInt("musicplayer.replaygainpreamp");
1388     g_guiSettings.m_replayGain.iNoGainPreAmp = g_guiSettings.GetInt("musicplayer.replaygainnogainpreamp");
1389     g_guiSettings.m_replayGain.bAvoidClipping = g_guiSettings.GetBool("musicplayer.replaygainavoidclipping");
1390   }
1391 #ifdef HAS_LCD
1392   else if (strSetting.Equals("lcd.type"))
1393   {
1394     g_lcd->Initialize();
1395   }
1396   else if (strSetting.Equals("lcd.backlight"))
1397   {
1398     g_lcd->SetBackLight(((CSettingInt *)pSettingControl->GetSetting())->GetData());
1399   }
1400   else if (strSetting.Equals("lcd.modchip"))
1401   {
1402     g_lcd->Stop();
1403     CLCDFactory factory;
1404     delete g_lcd;
1405     g_lcd = factory.Create();
1406     g_lcd->Initialize();
1407   }
1408   else if (strSetting.Equals("lcd.contrast"))
1409   {
1410     g_lcd->SetContrast(((CSettingInt *)pSettingControl->GetSetting())->GetData());
1411   }
1412 #endif
1413 #ifdef HAS_XBOX_HARDWARE
1414   else if (strSetting.Equals("system.targettemperature"))
1415   {
1416     CSettingInt *pSetting = (CSettingInt*)pSettingControl->GetSetting();
1417     CFanController::Instance()->SetTargetTemperature(pSetting->GetData());
1418   }
1419   else if (strSetting.Equals("system.fanspeed"))
1420   {
1421     CSettingInt *pSetting = (CSettingInt*)pSettingControl->GetSetting();
1422     int iControlID = pSettingControl->GetID();
1423     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1424     g_graphicsContext.SendMessage(msg);
1425     int iSpeed = (RESOLUTION)msg.GetParam1();
1426     g_guiSettings.SetInt("system.fanspeed", iSpeed);
1427     CFanController::Instance()->SetFanSpeed(iSpeed);
1428   }
1429   else if (strSetting.Equals("system.autotemperature"))
1430   {
1431     CSettingBool *pSetting = (CSettingBool*)pSettingControl->GetSetting();
1432     if (pSetting->GetData())
1433     {
1434       g_guiSettings.SetBool("system.fanspeedcontrol", false);
1435       CFanController::Instance()->Start(g_guiSettings.GetInt("system.targettemperature"), g_guiSettings.GetInt("system.minfanspeed") );
1436     }
1437     else
1438       CFanController::Instance()->Stop();
1439   }
1440   else if (strSetting.Equals("system.minfanspeed"))
1441   {
1442     CSettingInt *pSetting = (CSettingInt*)pSettingControl->GetSetting();
1443     CFanController::Instance()->SetMinFanSpeed(pSetting->GetData());
1444   }
1445   else if (strSetting.Equals("system.fanspeedcontrol"))
1446   {
1447     CSettingBool *pSetting = (CSettingBool*)pSettingControl->GetSetting();
1448     if (pSetting->GetData())
1449     {
1450       g_guiSettings.SetBool("system.autotemperature", false);
1451       CFanController::Instance()->Stop();
1452       CFanController::Instance()->SetFanSpeed(g_guiSettings.GetInt("system.fanspeed"));
1453     }
1454     else
1455       CFanController::Instance()->RestoreStartupSpeed();
1456   }
1457   else if (strSetting.Equals("harddisk.aamlevel"))
1458   {
1459     CSettingInt * pSetting = (CSettingInt*)pSettingControl->GetSetting();
1460     int setting_level = pSetting->GetData();
1461
1462     if (setting_level == AAM_QUIET)
1463       XKHDD::SetAAMLevel(0x80);
1464     else if (setting_level == AAM_FAST)
1465       XKHDD::SetAAMLevel(0xFE);
1466   }
1467   else if (strSetting.Equals("harddisk.apmlevel"))
1468   {
1469     CSettingInt * pSetting = (CSettingInt*)pSettingControl->GetSetting();
1470     int setting_level = pSetting->GetData();
1471
1472     switch(setting_level)
1473     {
1474     case APM_LOPOWER:
1475       XKHDD::SetAPMLevel(0x80);
1476       break;
1477     case APM_HIPOWER:
1478       XKHDD::SetAPMLevel(0xFE);
1479       break;
1480     case APM_LOPOWER_STANDBY:
1481       XKHDD::SetAPMLevel(0x01);
1482       break;
1483     case APM_HIPOWER_STANDBY:
1484       XKHDD::SetAPMLevel(0x7F);
1485       break;
1486     }
1487   }
1488   else if (strSetting.Equals("autodetect.nickname") )
1489   {
1490     CStdString strXboxNickNameIn = g_guiSettings.GetString("autodetect.nickname");
1491     CUtil::SetXBOXNickName(strXboxNickNameIn, strXboxNickNameIn);
1492   }
1493 #endif
1494   else if (strSetting.Equals("servers.ftpserver"))
1495   {
1496     g_application.StopFtpServer();
1497     if (g_guiSettings.GetBool("servers.ftpserver"))
1498       g_application.StartFtpServer();
1499   }
1500   else if (strSetting.Equals("servers.ftpserverpassword"))
1501   {
1502    SetFTPServerUserPass();
1503   }
1504   else if (strSetting.Equals("servers.ftpserveruser"))
1505   {
1506     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1507     g_guiSettings.SetString("servers.ftpserveruser", pControl->GetCurrentLabel());
1508   }
1509
1510   else if (strSetting.Equals("servers.webserver") || strSetting.Equals("servers.webserverport") || strSetting.Equals("servers.webserverpassword"))
1511   {
1512     if (strSetting.Equals("servers.webserverport"))
1513     {
1514       CSettingString *pSetting = (CSettingString *)pSettingControl->GetSetting();
1515       // check that it's a valid port
1516       int port = atoi(pSetting->GetData().c_str());
1517       if (port <= 0 || port > 65535)
1518         pSetting->SetData("80");
1519     }
1520     g_application.StopWebServer();
1521     if (g_guiSettings.GetBool("servers.webserver"))
1522     {
1523       g_application.StartWebServer();
1524       g_application.m_pWebServer->SetPassword(g_guiSettings.GetString("servers.webserverpassword").c_str());
1525     }
1526   }
1527   
1528   else if (strSetting.Equals("network.ipaddress"))
1529   {
1530     if (g_guiSettings.GetInt("network.assignment") == NETWORK_STATIC)
1531     {
1532       CStdString strDefault = g_guiSettings.GetString("network.ipaddress").Left(g_guiSettings.GetString("network.ipaddress").ReverseFind('.'))+".1";
1533       if (g_guiSettings.GetString("network.gateway").Equals("0.0.0.0"))
1534         g_guiSettings.SetString("network.gateway",strDefault);
1535       if (g_guiSettings.GetString("network.dns").Equals("0.0.0.0"))
1536         g_guiSettings.SetString("network.dns",strDefault);
1537
1538     }
1539   }
1540     
1541   else if (strSetting.Equals("network.httpproxyport"))
1542   {
1543     CSettingString *pSetting = (CSettingString *)pSettingControl->GetSetting();
1544     // check that it's a valid port
1545     int port = atoi(pSetting->GetData().c_str());
1546     if (port <= 0 || port > 65535)
1547       pSetting->SetData("8080");
1548   }
1549   else if (strSetting.Equals("videoplayer.calibrate") || strSetting.Equals("videoscreen.guicalibration"))
1550   { // activate the video calibration screen
1551     m_gWindowManager.ActivateWindow(WINDOW_SCREEN_CALIBRATION);
1552   }
1553   else if (strSetting.Equals("videoplayer.externaldvdplayer"))
1554   {
1555     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1556     CStdString path = pSettingString->GetData();
1557     VECSOURCES shares;
1558     g_mediaManager.GetLocalDrives(shares);
1559     // TODO 2.0: Localize this
1560     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, ".xbe", g_localizeStrings.Get(655), path))
1561       pSettingString->SetData(path);
1562   }
1563   else if (strSetting.Equals("subtitles.height"))
1564   {
1565     if (!CUtil::IsUsingTTFSubtitles())
1566     {
1567       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1568       ((CSettingInt *)pSettingControl->GetSetting())->FromString(pControl->GetCurrentLabel());
1569     }
1570   }
1571   else if (strSetting.Equals("subtitles.font"))
1572   {
1573     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1574     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1575     pSettingString->SetData(pControl->GetCurrentLabel());
1576     FillInSubtitleHeights(g_guiSettings.GetSetting("subtitles.height"));
1577   }
1578   else if (strSetting.Equals("subtitles.charset"))
1579   {
1580     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1581     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1582     CStdString newCharset="DEFAULT";
1583     if (pControl->GetValue()!=0)
1584      newCharset = g_charsetConverter.getCharsetNameByLabel(pControl->GetCurrentLabel());
1585     if (newCharset != "" && (newCharset != pSettingString->GetData() || newCharset=="DEFAULT"))
1586     {
1587       pSettingString->SetData(newCharset);
1588       g_charsetConverter.reset();
1589     }
1590   }
1591   else if (strSetting.Equals("locale.charset"))
1592   {
1593     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1594     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1595     CStdString newCharset="DEFAULT";
1596     if (pControl->GetValue()!=0)
1597      newCharset = g_charsetConverter.getCharsetNameByLabel(pControl->GetCurrentLabel());
1598     if (newCharset != "" && (newCharset != pSettingString->GetData() || newCharset=="DEFAULT"))
1599     {
1600       pSettingString->SetData(newCharset);
1601       g_charsetConverter.reset();
1602     }
1603   }
1604   else if (strSetting.Equals("lookandfeel.font"))
1605   { // new font choosen...
1606     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1607     CStdString strSkinFontSet = pControl->GetCurrentLabel();
1608     if (strSkinFontSet != ".svn" && strSkinFontSet != g_guiSettings.GetString("lookandfeel.font"))
1609     {
1610       m_strNewSkinFontSet = strSkinFontSet;
1611       g_application.DelayLoadSkin();
1612     }
1613     else
1614     { // Do not reload the language we are already using
1615       m_strNewSkinFontSet.Empty();
1616       g_application.CancelDelayLoadSkin();
1617     }
1618   }
1619   else if (strSetting.Equals("lookandfeel.skin"))
1620   { // new skin choosen...
1621     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1622     CStdString strSkin = pControl->GetCurrentLabel();
1623     CStdString strSkinPath = "Q:\\skin\\" + strSkin;
1624     if (g_SkinInfo.Check(strSkinPath))
1625     {
1626       m_strErrorMessage.Empty();
1627       pControl->SettingsCategorySetSpinTextColor(pControl->GetButtonLabelInfo().textColor);
1628       if (strSkin != ".svn" && strSkin != g_guiSettings.GetString("lookandfeel.skin"))
1629       {
1630         m_strNewSkin = strSkin;
1631         g_application.DelayLoadSkin();
1632       }
1633       else
1634       { // Do not reload the skin we are already using
1635         m_strNewSkin.Empty();
1636         g_application.CancelDelayLoadSkin();
1637       }
1638     }
1639     else
1640     {
1641       m_strErrorMessage.Format("Incompatible skin. We require skins of version %0.2f or higher", g_SkinInfo.GetMinVersion());
1642       m_strNewSkin.Empty();
1643       g_application.CancelDelayLoadSkin();
1644       pControl->SettingsCategorySetSpinTextColor(pControl->GetButtonLabelInfo().disabledColor);
1645     }
1646   }
1647   else if (strSetting.Equals("lookandfeel.soundskin"))
1648   { // new sound skin choosen...
1649     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1650     if (pControl->GetValue()==0)
1651       g_guiSettings.SetString("lookandfeel.soundskin", "OFF");
1652     else if (pControl->GetValue()==1)
1653       g_guiSettings.SetString("lookandfeel.soundskin", "SKINDEFAULT");
1654     else
1655       g_guiSettings.SetString("lookandfeel.soundskin", pControl->GetCurrentLabel());
1656
1657     g_audioManager.Load();
1658   }
1659   else if (strSetting.Equals("lookandfeel.soundsduringplayback"))
1660   {
1661     if (g_guiSettings.GetBool("lookandfeel.soundsduringplayback"))
1662       g_audioManager.Enable(true);
1663     else
1664       g_audioManager.Enable(!g_application.IsPlaying() || g_application.IsPaused());
1665   }
1666   else if (strSetting.Equals("lookandfeel.enablemouse"))
1667   {
1668     g_Mouse.SetEnabled(g_guiSettings.GetBool("lookandfeel.enablemouse"));
1669   }
1670   else if (strSetting.Equals("videoscreen.resolution"))
1671   { // new resolution choosen... - update if necessary
1672     CSettingInt *pSettingInt = (CSettingInt *)pSettingControl->GetSetting();
1673     int iControlID = pSettingControl->GetID();
1674     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1675     g_graphicsContext.SendMessage(msg);
1676     m_NewResolution = (RESOLUTION)msg.GetParam1();
1677     // reset our skin if necessary
1678     // delay change of resolution
1679     if (m_NewResolution != g_guiSettings.m_LookAndFeelResolution)
1680     {
1681       g_application.DelayLoadSkin();
1682     }
1683     else
1684     { // Do not reload the resolution we are using
1685       m_NewResolution = INVALID;
1686       g_application.CancelDelayLoadSkin();
1687     }
1688   }
1689   else if (strSetting.Equals("system.ledcolour"))
1690   { 
1691 #ifdef HAS_XBOX_HARDWARE
1692     // Alter LED Colour immediately
1693     int iData =  ((CSettingInt *)pSettingControl->GetSetting())->GetData();
1694     if (iData == LED_COLOUR_NO_CHANGE)
1695       // LED_COLOUR_NO_CHANGE: to prevent "led off" on colour immediately change, set to default green! 
1696       //                       (we have no previos reference LED COLOUR, to set the LED colour back)
1697       //                       on next boot the colour will not changed and the default BIOS led colour will used
1698       ILED::CLEDControl(LED_COLOUR_GREEN); 
1699     else
1700       ILED::CLEDControl(iData);
1701 #endif
1702   }
1703   else if (strSetting.Equals("locale.language"))
1704   { // new language chosen...
1705     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1706     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1707     CStdString strLanguage = pControl->GetCurrentLabel();
1708     if (strLanguage != ".svn" && strLanguage != pSettingString->GetData())
1709     {
1710       m_strNewLanguage = strLanguage;
1711       g_application.DelayLoadSkin();
1712     }
1713     else
1714     { // Do not reload the language we are already using
1715       m_strNewLanguage.Empty();
1716       g_application.CancelDelayLoadSkin();
1717     }
1718   }
1719   else if (strSetting.Equals("lookandfeel.skintheme"))
1720   { //a new Theme was chosen
1721     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1722     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1723
1724     CStdString strSkinTheme;
1725
1726     if (pControl->GetValue() == 0) // Use default theme
1727       strSkinTheme = "SKINDEFAULT";
1728     else
1729       strSkinTheme = pControl->GetCurrentLabel() + ".xpr";
1730
1731     if (strSkinTheme != pSettingString->GetData())
1732     {
1733       m_strNewSkinTheme = strSkinTheme;
1734       g_application.DelayLoadSkin();
1735     }
1736     else
1737     { // Do not reload the skin theme we are using
1738       m_strNewSkinTheme.Empty();
1739       g_application.CancelDelayLoadSkin();
1740     }
1741   }
1742   else if (strSetting.Equals("lookandfeel.skincolors"))
1743   { //a new color was chosen
1744     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1745     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1746
1747     CStdString strSkinColor;
1748
1749     if (pControl->GetValue() == 0) // Use default colors
1750       strSkinColor = "SKINDEFAULT";
1751     else
1752       strSkinColor = pControl->GetCurrentLabel() + ".xml";
1753
1754     if (strSkinColor != pSettingString->GetData())
1755     {
1756       m_strNewSkinColors = strSkinColor;
1757       g_application.DelayLoadSkin();
1758     }
1759     else
1760     { // Do not reload the skin colors we are using
1761       m_strNewSkinColors.Empty();
1762       g_application.CancelDelayLoadSkin();
1763     }
1764   }
1765   else if (strSetting.Equals("videoplayer.displayresolution"))
1766   {
1767     CSettingInt *pSettingInt = (CSettingInt *)pSettingControl->GetSetting();
1768     int iControlID = pSettingControl->GetID();
1769     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1770     g_graphicsContext.SendMessage(msg);
1771     pSettingInt->SetData(msg.GetParam1());
1772   }
1773   else if (strSetting.Equals("videoscreen.flickerfilter") || strSetting.Equals("videoscreen.soften"))
1774   { // reset display
1775     g_graphicsContext.SetVideoResolution(g_guiSettings.m_LookAndFeelResolution, TRUE);
1776   }
1777   else if (strSetting.Equals("screensaver.mode"))
1778   {
1779     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1780     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1781     int iValue = pControl->GetValue();
1782     CStdString strScreenSaver;
1783     if (iValue == 0)
1784       strScreenSaver = "None";
1785     else if (iValue == 1)
1786       strScreenSaver = "Dim";
1787     else if (iValue == 2)
1788       strScreenSaver = "Black";
1789     else if (iValue == 3)
1790       strScreenSaver = "SlideShow"; // PictureSlideShow
1791     else
1792       strScreenSaver = pControl->GetCurrentLabel() + ".xbs";
1793     pSettingString->SetData(strScreenSaver);
1794   }
1795   else if (strSetting.Equals("screensaver.preview"))
1796   {
1797     g_application.ActivateScreenSaver(true);
1798   }
1799   else if (strSetting.Equals("screensaver.slideshowpath"))
1800   {
1801     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1802     CStdString path = pSettingString->GetData();
1803     if (CGUIDialogFileBrowser::ShowAndGetDirectory(g_settings.m_pictureSources, g_localizeStrings.Get(pSettingString->m_iHeadingString), path))
1804       pSettingString->SetData(path);
1805   }
1806   else if (strSetting.Equals("myprograms.dashboard"))
1807   {
1808     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1809     CStdString path = pSettingString->GetData();
1810     VECSOURCES shares;
1811     g_mediaManager.GetLocalDrives(shares);
1812     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, ".xbe", g_localizeStrings.Get(pSettingString->m_iHeadingString), path))
1813       pSettingString->SetData(path);
1814   }
1815   else if (strSetting.Equals("myprograms.trainerpath") || strSetting.Equals("pictures.screenshotpath") || strSetting.Equals("mymusic.recordingpath") || strSetting.Equals("cddaripper.path") || strSetting.Equals("subtitles.custompath"))
1816   {
1817     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1818     CStdString path = g_guiSettings.GetString(strSetting,false);
1819     VECSOURCES shares;
1820     g_mediaManager.GetLocalDrives(shares);
1821     UpdateSettings();
1822     bool bWriteOnly = true;
1823     if (strSetting.Equals("myprograms.trainerpath"))
1824       bWriteOnly = false;
1825
1826     if (strSetting.Equals("subtitles.custompath"))
1827     {
1828       bWriteOnly = false;
1829       shares = g_settings.m_videoSources;
1830     }
1831     if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(pSettingString->m_iHeadingString), path, bWriteOnly))
1832     {
1833       pSettingString->SetData(path);
1834
1835       if (strSetting.Equals("myprograms.trainerpath"))
1836       {
1837         if (CGUIDialogYesNo::ShowAndGetInput(12012,20135,20022,20022))
1838         {
1839           CGUIWindowPrograms* pWindow = (CGUIWindowPrograms*)m_gWindowManager.GetWindow(WINDOW_PROGRAMS);
1840           if (pWindow)
1841             pWindow->PopulateTrainersList();
1842         }
1843       }
1844     }
1845   }
1846   else if (strSetting.Left(22).Equals("MusicPlayer.ReplayGain"))
1847   { // Update our replaygain settings
1848     g_guiSettings.m_replayGain.iType = g_guiSettings.GetInt("musicplayer.replaygaintype");
1849     g_guiSettings.m_replayGain.iPreAmp = g_guiSettings.GetInt("musicplayer.replaygainpreamp");
1850     g_guiSettings.m_replayGain.iNoGainPreAmp = g_guiSettings.GetInt("musicplayer.replaygainnogainpreamp");
1851     g_guiSettings.m_replayGain.bAvoidClipping = g_guiSettings.GetBool("musicplayer.replaygainavoidclipping");
1852   }
1853   else if (strSetting.Equals("locale.country"))
1854   {
1855     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1856
1857     const CStdString& strRegion=pControl->GetCurrentLabel();
1858     g_langInfo.SetCurrentRegion(strRegion);
1859     g_guiSettings.SetString("locale.country", strRegion);
1860   }
1861 #ifdef HAS_TIME_SERVER
1862   else if (strSetting.Equals("locale.timeserver") || strSetting.Equals("locale.timeserveraddress"))
1863   {
1864     g_application.StopTimeServer();
1865     if (g_guiSettings.GetBool("locale.timeserver"))
1866       g_application.StartTimeServer();
1867   }
1868 #endif
1869   else if (strSetting.Equals("locale.time"))
1870   {
1871     SYSTEMTIME curTime;
1872     GetLocalTime(&curTime);
1873     if (CGUIDialogNumeric::ShowAndGetTime(curTime, g_localizeStrings.Get(14066)))
1874     { // yay!
1875       SYSTEMTIME curDate;
1876       GetLocalTime(&curDate);
1877       CUtil::SetSysDateTimeYear(curDate.wYear, curDate.wMonth, curDate.wDay, curTime.wHour, curTime.wMinute);
1878     }
1879   }
1880   else if (strSetting.Equals("locale.date"))
1881   {
1882     SYSTEMTIME curDate;
1883     GetLocalTime(&curDate);
1884     if (CGUIDialogNumeric::ShowAndGetDate(curDate, g_localizeStrings.Get(14067)))
1885     { // yay!
1886       SYSTEMTIME curTime;
1887       GetLocalTime(&curTime);
1888       CUtil::SetSysDateTimeYear(curDate.wYear, curDate.wMonth, curDate.wDay, curTime.wHour, curTime.wMinute);
1889     }
1890   }
1891   else if (strSetting.Equals("smb.winsserver") || strSetting.Equals("smb.workgroup") )
1892   {
1893     if (g_guiSettings.GetString("smb.winsserver") == "0.0.0.0")
1894       g_guiSettings.SetString("smb.winsserver", "");
1895
1896     /* okey we really don't need to restarat, only deinit samba, but that could be damn hard if something is playing*/
1897     //TODO - General way of handling setting changes that require restart
1898
1899     CGUIDialogOK *dlg = (CGUIDialogOK *)m_gWindowManager.GetWindow(WINDOW_DIALOG_YES_NO);
1900     if (!dlg) return ;
1901     dlg->SetHeading( g_localizeStrings.Get(14038) );
1902     dlg->SetLine( 0, g_localizeStrings.Get(14039) );
1903     dlg->SetLine( 1, g_localizeStrings.Get(14040));
1904     dlg->SetLine( 2, "");
1905     dlg->DoModal();
1906
1907     if (dlg->IsConfirmed())
1908     {
1909       g_applicationMessenger.RestartApp();
1910     }
1911   }
1912   else if (strSetting.Equals("upnp.client"))
1913   {
1914 #ifdef HAS_UPNP
1915     if (g_guiSettings.GetBool("upnp.client"))
1916       g_application.StartUPnPClient();
1917     else
1918       g_application.StopUPnPClient();
1919 #endif
1920   }
1921   else if (strSetting.Equals("upnp.server"))
1922   {
1923 #ifdef HAS_UPNP
1924     if (g_guiSettings.GetBool("upnp.server"))
1925       g_application.StartUPnPServer();
1926     else
1927       g_application.StopUPnPServer();
1928 #endif
1929   }
1930   else if (strSetting.Equals("upnp.renderer"))
1931   {
1932 #ifdef HAS_UPNP
1933     if (g_guiSettings.GetBool("upnp.renderer"))
1934       g_application.StartUPnPRenderer();
1935     else
1936       g_application.StopUPnPRenderer();
1937 #endif
1938   }
1939   else if (strSetting.Equals("remoteevents.enabled"))
1940   {
1941 #ifdef HAS_EVENT_SERVER
1942     if (g_guiSettings.GetBool("remoteevents.enabled"))
1943       g_application.StartEventServer();
1944     else
1945       g_application.StopEventServer();
1946 #endif
1947   }
1948   else if (strSetting.Equals("remoteevents.allinterfaces"))
1949   {
1950 #ifdef HAS_EVENT_SERVER
1951     if (g_guiSettings.GetBool("remoteevents.enabled"))
1952     {
1953       g_application.StopEventServer();
1954       g_application.StartEventServer();
1955     }
1956 #endif
1957   }
1958   else if (strSetting.Equals("remoteevents.initialdelay") || 
1959            strSetting.Equals("remoteevents.continuousdelay"))    
1960   {
1961 #ifdef HAS_EVENT_SERVER
1962     if (g_guiSettings.GetBool("remoteevents.enabled"))
1963     {
1964       g_application.RefreshEventServer();
1965     }
1966 #endif      
1967   }
1968   else if (strSetting.Equals("upnp.musicshares"))
1969   {
1970     CStdString filename;
1971     CUtil::AddFileToFolder(g_settings.GetUserDataFolder(), "upnpserver.xml", filename);
1972     CStdString strDummy;
1973     g_settings.LoadUPnPXml(filename);
1974     if (CGUIDialogFileBrowser::ShowAndGetSource(strDummy,false,&g_settings.m_UPnPMusicSources,"upnpmusic"))
1975       g_settings.SaveUPnPXml(filename);
1976     else
1977       g_settings.LoadUPnPXml(filename);
1978   }
1979   else if (strSetting.Equals("upnp.videoshares"))
1980   {
1981     CStdString filename;
1982     CUtil::AddFileToFolder(g_settings.GetUserDataFolder(), "upnpserver.xml", filename);
1983     CStdString strDummy;
1984     g_settings.LoadUPnPXml(filename);
1985     if (CGUIDialogFileBrowser::ShowAndGetSource(strDummy,false,&g_settings.m_UPnPVideoSources,"upnpvideo"))
1986       g_settings.SaveUPnPXml(filename);
1987     else
1988       g_settings.LoadUPnPXml(filename);
1989   }
1990   else if (strSetting.Equals("upnp.pictureshares"))
1991   {
1992     CStdString filename;
1993     CUtil::AddFileToFolder(g_settings.GetUserDataFolder(), "upnpserver.xml", filename);
1994     CStdString strDummy;
1995     g_settings.LoadUPnPXml(filename);
1996     if (CGUIDialogFileBrowser::ShowAndGetSource(strDummy,false,&g_settings.m_UPnPPictureSources,"upnppictures"))
1997       g_settings.SaveUPnPXml(filename);
1998     else
1999       g_settings.LoadUPnPXml(filename);
2000   }
2001   else if (strSetting.Equals("masterlock.lockcode"))
2002   {
2003     // Now Prompt User to enter the old and then the new MasterCode!
2004     if(g_passwordManager.SetMasterLockMode())
2005     {
2006       // We asked for the master password and saved the new one!
2007       // Nothing todo here
2008     }
2009   }
2010   else if (strSetting.Equals("musicfiles.savefolderviews"))
2011   {
2012     ClearFolderViews(pSettingControl->GetSetting(), WINDOW_MUSIC_FILES);
2013   }
2014   else if (strSetting.Equals("myvideos.savefolderviews"))
2015   {
2016     ClearFolderViews(pSettingControl->GetSetting(), WINDOW_VIDEO_FILES);
2017   }
2018   else if (strSetting.Equals("programfiles.savefolderviews"))
2019   {
2020     ClearFolderViews(pSettingControl->GetSetting(), WINDOW_PROGRAMS);
2021   }
2022   else if (strSetting.Equals("pictures.savefolderviews"))
2023   {
2024     ClearFolderViews(pSettingControl->GetSetting(), WINDOW_PICTURES);
2025   }
2026
2027   else if (strSetting.Equals("lookandfeel.skinzoom"))
2028   {
2029     g_fontManager.ReloadTTFFonts();
2030   }
2031   else if (strSetting.Equals("videolibrary.flattentvshows") ||
2032            strSetting.Equals("videolibrary.removeduplicates"))
2033   {
2034     CUtil::DeleteVideoDatabaseDirectoryCache();
2035   }
2036   UpdateSettings();
2037 }
2038
2039 void CGUIWindowSettingsCategory::FreeControls()
2040 {
2041   // clear the category group
2042   CGUIControlGroupList *control = (CGUIControlGroupList *)GetControl(CATEGORY_GROUP_ID);
2043 #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
2044   if (control && control->GetControlType() == CGUIControl::GUICONTROL_GROUPLIST)
2045 #else
2046   if (control)
2047 #endif
2048   {
2049     control->FreeResources();
2050     control->ClearAll();
2051   }
2052   m_vecSections.clear();
2053   FreeSettingsControls();
2054 }
2055
2056 void CGUIWindowSettingsCategory::FreeSettingsControls()
2057 {
2058   // clear the settings group
2059   CGUIControlGroupList *control = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
2060 #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
2061   if (control && control->GetControlType() == CGUIControl::GUICONTROL_GROUPLIST)
2062 #else
2063   if (control)
2064 #endif
2065   {
2066     control->FreeResources();
2067     control->ClearAll();
2068   }
2069   m_vecSettings.clear();
2070 }
2071
2072 void CGUIWindowSettingsCategory::AddSetting(CSetting *pSetting, float width, int &iControlID)
2073 {
2074   CBaseSettingControl *pSettingControl = NULL;
2075   CGUIControl *pControl = NULL;
2076   if (pSetting->GetControlType() == CHECKMARK_CONTROL)
2077   {
2078     pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
2079     if (!pControl) return ;
2080     ((CGUIRadioButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2081     pControl->SetWidth(width);
2082     pSettingControl = new CRadioButtonSettingControl((CGUIRadioButtonControl *)pControl, iControlID, pSetting);
2083   }
2084   else if (pSetting->GetControlType() == SPIN_CONTROL_FLOAT || pSetting->GetControlType() == SPIN_CONTROL_INT_PLUS || pSetting->GetControlType() == SPIN_CONTROL_TEXT || pSetting->GetControlType() == SPIN_CONTROL_INT)
2085   {
2086     pControl = new CGUISpinControlEx(*m_pOriginalSpin);
2087     if (!pControl) return ;
2088     pControl->SetWidth(width);
2089     ((CGUISpinControlEx *)pControl)->SetText(g_localizeStrings.Get(pSetting->GetLabel()));
2090     pSettingControl = new CSpinExSettingControl((CGUISpinControlEx *)pControl, iControlID, pSetting);
2091   }
2092   else if (pSetting->GetControlType() == SEPARATOR_CONTROL && m_pOriginalImage)
2093   {
2094     pControl = new CGUIImage(*m_pOriginalImage);
2095     if (!pControl) return;
2096     pControl->SetWidth(width);
2097     pSettingControl = new CSeparatorSettingControl((CGUIImage *)pControl, iControlID, pSetting);
2098   }
2099   else if (pSetting->GetControlType() == EDIT_CONTROL_INPUT ||
2100            pSetting->GetControlType() == EDIT_CONTROL_HIDDEN_INPUT ||
2101            pSetting->GetControlType() == EDIT_CONTROL_NUMBER_INPUT ||
2102            pSetting->GetControlType() == EDIT_CONTROL_IP_INPUT)
2103   {
2104     pControl = new CGUIEditControl(*m_pOriginalEdit);
2105     if (!pControl) return ;
2106     ((CGUIEditControl *)pControl)->SettingsCategorySetTextAlign(XBFONT_CENTER_Y);
2107     ((CGUIEditControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2108     pControl->SetWidth(width);
2109     pSettingControl = new CEditSettingControl((CGUIEditControl *)pControl, iControlID, pSetting);
2110   }
2111   else if (pSetting->GetControlType() != SEPARATOR_CONTROL) // button control
2112   {
2113     pControl = new CGUIButtonControl(*m_pOriginalButton);
2114     if (!pControl) return ;
2115     ((CGUIButtonControl *)pControl)->SettingsCategorySetTextAlign(XBFONT_CENTER_Y);
2116     ((CGUIButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2117     pControl->SetWidth(width);
2118     pSettingControl = new CButtonSettingControl((CGUIButtonControl *)pControl, iControlID, pSetting);
2119   }
2120   if (!pControl) return;
2121   pControl->SetID(iControlID++);
2122   pControl->SetVisible(true);
2123   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
2124   if (group)
2125   {
2126     pControl->AllocResources();
2127     group->AddControl(pControl);
2128     m_vecSettings.push_back(pSettingControl);
2129   }
2130 }
2131
2132 void CGUIWindowSettingsCategory::Render()
2133 {
2134   // update realtime changeable stuff
2135   UpdateRealTimeSettings();
2136   // update alpha status of current button
2137   bool bAlphaFaded = false;
2138   CGUIControl *control = GetFirstFocusableControl(CONTROL_START_BUTTONS + m_iSection);
2139   if (control && !control->HasFocus())
2140   {
2141     if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
2142     {
2143       control->SetFocus(true);
2144       ((CGUIButtonControl *)control)->SetAlpha(0x80);
2145       bAlphaFaded = true;
2146     }
2147     else if (control->GetControlType() == CGUIControl::GUICONTROL_TOGGLEBUTTON)
2148     {
2149       control->SetFocus(true);
2150       ((CGUIButtonControl *)control)->SetSelected(true);
2151       bAlphaFaded = true;
2152     }
2153   }
2154   CGUIWindow::Render();
2155   if (bAlphaFaded)
2156   {
2157     control->SetFocus(false);
2158     if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
2159       ((CGUIButtonControl *)control)->SetAlpha(0xFF);
2160     else
2161       ((CGUIButtonControl *)control)->SetSelected(false);
2162   }
2163   // render the error message if necessary
2164   if (m_strErrorMessage.size())
2165   {
2166     CGUIFont *pFont = g_fontManager.GetFont("font13");
2167     float fPosY = g_graphicsContext.GetHeight() * 0.8f;
2168     float fPosX = g_graphicsContext.GetWidth() * 0.5f;
2169     CGUITextLayout::DrawText(pFont, fPosX, fPosY, 0xffffffff, 0, m_strErrorMessage, XBFONT_CENTER_X);
2170   }
2171 }
2172
2173 void CGUIWindowSettingsCategory::CheckNetworkSettings()
2174 {
2175   // check if our network needs restarting (requires a reset, so check well!)
2176   if (m_iNetworkAssignment == -1)
2177   {
2178     // nothing to do here, folks - move along.
2179     return ;
2180   }
2181   // we need a reset if:
2182   // 1.  The Network Assignment has changed OR
2183   // 2.  The Network Assignment is STATIC and one of the network fields have changed
2184   if (m_iNetworkAssignment != g_guiSettings.GetInt("network.assignment") ||
2185       (m_iNetworkAssignment == NETWORK_STATIC && (
2186          m_strNetworkIPAddress != g_guiSettings.GetString("network.ipaddress") ||
2187          m_strNetworkSubnet != g_guiSettings.GetString("network.subnet") ||
2188          m_strNetworkGateway != g_guiSettings.GetString("network.gateway") ||
2189          m_strNetworkDNS != g_guiSettings.GetString("network.dns"))))
2190   {
2191 /*    // our network settings have changed - we should prompt the user to reset XBMC
2192     if (CGUIDialogYesNo::ShowAndGetInput(14038, 14039, 14040, 0))
2193     {
2194       // reset settings
2195       g_applicationMessenger.RestartApp();
2196       // Todo: aquire new network settings without restart app!
2197     }
2198     else*/
2199     {
2200       g_network.NetworkMessage(CNetwork::SERVICES_DOWN,1);
2201       g_network.Deinitialize();
2202       g_network.Initialize(g_guiSettings.GetInt("network.assignment"),
2203         g_guiSettings.GetString("network.ipaddress").c_str(),
2204         g_guiSettings.GetString("network.subnet").c_str(),
2205         g_guiSettings.GetString("network.gateway").c_str(),
2206         g_guiSettings.GetString("network.dns").c_str());
2207     }
2208
2209
2210     // update our settings variables    
2211     m_iNetworkAssignment = g_guiSettings.GetInt("network.assignment");
2212     m_strNetworkIPAddress = g_guiSettings.GetString("network.ipaddress");
2213     m_strNetworkSubnet = g_guiSettings.GetString("network.subnet");
2214     m_strNetworkGateway = g_guiSettings.GetString("network.gateway");
2215     m_strNetworkDNS = g_guiSettings.GetString("network.dns");
2216
2217     // replace settings
2218     /*   g_guiSettings.SetInt("network.assignment", m_iNetworkAssignment);
2219        g_guiSettings.SetString("network.ipaddress", m_strNetworkIPAddress);
2220        g_guiSettings.SetString("network.subnet", m_strNetworkSubnet);
2221        g_guiSettings.SetString("network.gateway", m_strNetworkGateway);
2222        g_guiSettings.SetString("network.dns", m_strNetworkDNS);*/
2223   }
2224 }
2225
2226 void CGUIWindowSettingsCategory::FillInSubtitleHeights(CSetting *pSetting)
2227 {
2228   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2229   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2230   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2231   pControl->Clear();
2232   if (CUtil::IsUsingTTFSubtitles())
2233   { // easy - just fill as per usual
2234     CStdString strLabel;
2235     for (int i = pSettingInt->m_iMin; i <= pSettingInt->m_iMax; i += pSettingInt->m_iStep)
2236     {
2237       if (pSettingInt->m_iFormat > -1)
2238       {
2239         CStdString strFormat = g_localizeStrings.Get(pSettingInt->m_iFormat);
2240         strLabel.Format(strFormat, i);
2241       }
2242       else
2243         strLabel.Format(pSettingInt->m_strFormat, i);
2244       pControl->AddLabel(strLabel, i);
2245     }
2246     pControl->SetValue(pSettingInt->GetData());
2247   }
2248   else
2249   {
2250     if (g_guiSettings.GetString("subtitles.font").size())
2251     {
2252       //find font sizes...
2253       CHDDirectory directory;
2254       CFileItemList items;
2255       CStdString strPath = "Q:\\system\\players\\mplayer\\font\\";
2256       strPath += g_guiSettings.GetString("subtitles.font");
2257       strPath += "\\";
2258       directory.GetDirectory(strPath, items);
2259       int iCurrentSize = 0;
2260       int iSize = 0;
2261       for (int i = 0; i < items.Size(); ++i)
2262       {
2263         CFileItemPtr pItem = items[i];
2264         if (pItem->m_bIsFolder)
2265         {
2266           if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2267           int iSizeTmp = atoi(pItem->GetLabel().c_str());
2268           if (iSizeTmp == pSettingInt->GetData())
2269             iCurrentSize = iSize;
2270           pControl->AddLabel(pItem->GetLabel(), iSize++);
2271         }
2272       }
2273       pControl->SetValue(iCurrentSize);
2274     }
2275   }
2276 }
2277
2278 void CGUIWindowSettingsCategory::FillInSubtitleFonts(CSetting *pSetting)
2279 {
2280   CSettingString *pSettingString = (CSettingString*)pSetting;
2281   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2282   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2283   pControl->Clear();
2284   int iCurrentFont = 0;
2285   int iFont = 0;
2286
2287   // Find mplayer fonts...
2288   {
2289     CHDDirectory directory;
2290     CFileItemList items;
2291     CStdString strPath = "Q:\\system\\players\\mplayer\\font\\";
2292     directory.GetDirectory(strPath, items);
2293     for (int i = 0; i < items.Size(); ++i)
2294     {
2295       CFileItemPtr pItem = items[i];
2296       if (pItem->m_bIsFolder)
2297       {
2298         if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2299         if (strcmpi(pItem->GetLabel().c_str(), pSettingString->GetData().c_str()) == 0)
2300           iCurrentFont = iFont;
2301         pControl->AddLabel(pItem->GetLabel(), iFont++);
2302       }
2303     }
2304   }
2305
2306   // find TTF fonts
2307   {
2308     CHDDirectory directory;
2309     CFileItemList items;
2310     CStdString strPath = "Q:\\media\\Fonts\\";
2311     if (directory.GetDirectory(strPath, items))
2312     {
2313       for (int i = 0; i < items.Size(); ++i)
2314       {
2315         CFileItemPtr pItem = items[i];
2316
2317         if (!pItem->m_bIsFolder)
2318         {
2319
2320           if ( !CUtil::GetExtension(pItem->GetLabel()).Equals(".ttf") ) continue;
2321           if (pItem->GetLabel().Equals(pSettingString->GetData(), false))
2322             iCurrentFont = iFont;
2323
2324           pControl->AddLabel(pItem->GetLabel(), iFont++);
2325         }
2326
2327       }
2328     }
2329   }
2330   pControl->SetValue(iCurrentFont);
2331 }
2332
2333 void CGUIWindowSettingsCategory::FillInSkinFonts(CSetting *pSetting)
2334 {
2335   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2336   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2337   pControl->Clear();
2338
2339   int iSkinFontSet = 0;
2340
2341   m_strNewSkinFontSet.Empty();
2342
2343   RESOLUTION res;
2344   CStdString strPath = g_SkinInfo.GetSkinPath("Font.xml", &res);
2345
2346   TiXmlDocument xmlDoc;
2347   if (!xmlDoc.LoadFile(strPath.c_str()))
2348   {
2349     CLog::Log(LOGERROR, "Couldn't load %s", strPath.c_str());
2350     return ;
2351   }
2352
2353   TiXmlElement* pRootElement = xmlDoc.RootElement();
2354
2355   CStdString strValue = pRootElement->Value();
2356   if (strValue != CStdString("fonts"))
2357   {
2358     CLog::Log(LOGERROR, "file %s doesnt start with <fonts>", strPath.c_str());
2359     return ;
2360   }
2361
2362   const TiXmlNode *pChild = pRootElement->FirstChild();
2363   strValue = pChild->Value();
2364   if (strValue == "fontset")
2365   {
2366     while (pChild)
2367     {
2368       strValue = pChild->Value();
2369       if (strValue == "fontset")
2370       {
2371         const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id");
2372         const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode");
2373
2374         bool isUnicode=(unicodeAttr && stricmp(unicodeAttr, "true") == 0);
2375
2376         bool isAllowed=true;
2377         if (g_langInfo.ForceUnicodeFont() && !isUnicode)
2378           isAllowed=false;
2379
2380         if (idAttr != NULL && isAllowed)
2381         {
2382           pControl->AddLabel(idAttr, iSkinFontSet);
2383           if (strcmpi(idAttr, g_guiSettings.GetString("lookandfeel.font").c_str()) == 0)
2384             pControl->SetValue(iSkinFontSet);
2385           iSkinFontSet++;
2386         }
2387       }
2388       pChild = pChild->NextSibling();
2389     }
2390
2391   }
2392   else
2393   {
2394     // Since no fontset is defined, there is no selection of a fontset, so disable the component
2395     pControl->AddLabel(g_localizeStrings.Get(13278), 1);
2396     pControl->SetValue(1);
2397     pControl->SetEnabled(false);
2398   }
2399 }
2400
2401 void CGUIWindowSettingsCategory::FillInSkins(CSetting *pSetting)
2402 {
2403   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2404   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2405   pControl->Clear();
2406   pControl->SetShowRange(true);
2407
2408   m_strNewSkin.Empty();
2409
2410   //find skins...
2411   CHDDirectory directory;
2412   CFileItemList items;
2413   CStdString strPath = "Q:\\skin\\";
2414   directory.GetDirectory(strPath, items);
2415
2416   int iCurrentSkin = 0;
2417   int iSkin = 0;
2418   vector<CStdString> vecSkins;
2419   for (int i = 0; i < items.Size(); ++i)
2420   {
2421     CFileItemPtr pItem = items[i];
2422     if (pItem->m_bIsFolder)
2423     {
2424       if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2425       if (strcmpi(pItem->GetLabel().c_str(), "fonts") == 0) continue;
2426       if (strcmpi(pItem->GetLabel().c_str(), "media") == 0) continue;
2427       //   if (g_SkinInfo.Check(pItem->m_strPath))
2428       //   {
2429       vecSkins.push_back(pItem->GetLabel());
2430       //   }
2431     }
2432   }
2433
2434   sort(vecSkins.begin(), vecSkins.end(), sortstringbyname());
2435   for (unsigned int i = 0; i < vecSkins.size(); ++i)
2436   {
2437     CStdString strSkin = vecSkins[i];
2438     if (strcmpi(strSkin.c_str(), g_guiSettings.GetString("lookandfeel.skin").c_str()) == 0)
2439     {
2440       iCurrentSkin = iSkin;
2441     }
2442     pControl->AddLabel(strSkin, iSkin++);
2443   }
2444   pControl->SetValue(iCurrentSkin);
2445   return ;
2446 }
2447
2448 void CGUIWindowSettingsCategory::FillInSoundSkins(CSetting *pSetting)
2449 {
2450   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2451   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2452   pControl->Clear();
2453   pControl->SetShowRange(true);
2454
2455   m_strNewSkin.Empty();
2456
2457   //find skins...
2458   CFileItemList items;
2459   CStdString strPath = "Q:\\sounds\\";
2460   CDirectory::GetDirectory(strPath, items);
2461
2462   int iCurrentSoundSkin = 0;
2463   int iSoundSkin = 0;
2464   vector<CStdString> vecSoundSkins;
2465   int i;
2466   for (i = 0; i < items.Size(); ++i)
2467   {
2468     CFileItemPtr pItem = items[i];
2469     if (pItem->m_bIsFolder)
2470     {
2471       if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2472       if (strcmpi(pItem->GetLabel().c_str(), "fonts") == 0) continue;
2473       if (strcmpi(pItem->GetLabel().c_str(), "media") == 0) continue;
2474       vecSoundSkins.push_back(pItem->GetLabel());
2475     }
2476   }
2477
2478   pControl->AddLabel(g_localizeStrings.Get(474), iSoundSkin++); // Off
2479   pControl->AddLabel(g_localizeStrings.Get(15109), iSoundSkin++); // Skin Default
2480
2481   if (g_guiSettings.GetString("lookandfeel.soundskin")=="SKINDEFAULT")
2482     iCurrentSoundSkin=1;
2483
2484   sort(vecSoundSkins.begin(), vecSoundSkins.end(), sortstringbyname());
2485   for (i = 0; i < (int) vecSoundSkins.size(); ++i)
2486   {
2487     CStdString strSkin = vecSoundSkins[i];
2488     if (strcmpi(strSkin.c_str(), g_guiSettings.GetString("lookandfeel.soundskin").c_str()) == 0)
2489     {
2490       iCurrentSoundSkin = iSoundSkin;
2491     }
2492     pControl->AddLabel(strSkin, iSoundSkin++);
2493   }
2494   pControl->SetValue(iCurrentSoundSkin);
2495   return ;
2496 }
2497
2498 void CGUIWindowSettingsCategory::FillInCharSets(CSetting *pSetting)
2499 {
2500   CSettingString *pSettingString = (CSettingString*)pSetting;
2501   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2502   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2503   pControl->Clear();
2504   int iCurrentCharset = 0;
2505   vector<CStdString> vecCharsets = g_charsetConverter.getCharsetLabels();
2506
2507   CStdString strCurrentCharsetLabel="DEFAULT";
2508   if (pSettingString->GetData()!="DEFAULT")
2509     strCurrentCharsetLabel = g_charsetConverter.getCharsetLabelByName(pSettingString->GetData());
2510
2511   sort(vecCharsets.begin(), vecCharsets.end(), sortstringbyname());
2512
2513   vecCharsets.insert(vecCharsets.begin(), g_localizeStrings.Get(13278)); // "Default"
2514
2515   bool bIsAuto=(pSettingString->GetData()=="DEFAULT");
2516
2517   for (int i = 0; i < (int) vecCharsets.size(); ++i)
2518   {
2519     CStdString strCharsetLabel = vecCharsets[i];
2520
2521     if (!bIsAuto && strCharsetLabel == strCurrentCharsetLabel)
2522       iCurrentCharset = i;
2523
2524     pControl->AddLabel(strCharsetLabel, i);
2525   }
2526
2527   pControl->SetValue(iCurrentCharset);
2528 }
2529
2530 void CGUIWindowSettingsCategory::FillInVisualisations(CSetting *pSetting, int iControlID)
2531 {
2532   CSettingString *pSettingString = (CSettingString*)pSetting;
2533   if (!pSetting) return;
2534   int iWinID = m_gWindowManager.GetActiveWindow();
2535   {
2536     CGUIMessage msg(GUI_MSG_LABEL_RESET, iWinID, iControlID);
2537     g_graphicsContext.SendMessage(msg);
2538   }
2539   vector<CStdString> vecVis;
2540   //find visz....
2541   CHDDirectory directory;
2542   CFileItemList items;
2543   CStdString strPath = "Q:\\visualisations\\";
2544   directory.GetDirectory(strPath, items);
2545   for (int i = 0; i < items.Size(); ++i)
2546   {
2547     CFileItemPtr pItem = items[i];
2548     if (!pItem->m_bIsFolder)
2549     {
2550       CStdString strExtension;
2551       CUtil::GetExtension(pItem->m_strPath, strExtension);
2552       if (strExtension == ".vis")
2553       {
2554         CStdString strLabel = pItem->GetLabel();
2555         vecVis.push_back(strLabel.Mid(0, strLabel.size() - 4));
2556       }
2557     }
2558   }
2559
2560   CStdString strDefaultVis = pSettingString->GetData();
2561   if (!strDefaultVis.Equals("None"))
2562     strDefaultVis.Delete(strDefaultVis.size() - 4, 4);
2563
2564   sort(vecVis.begin(), vecVis.end(), sortstringbyname());
2565
2566   // add the "disabled" setting first
2567   int iVis = 0;
2568   int iCurrentVis = 0;
2569   {
2570     CGUIMessage msg(GUI_MSG_LABEL_ADD, iWinID, iControlID, iVis++);
2571     msg.SetLabel(231);
2572     g_graphicsContext.SendMessage(msg);
2573   }
2574   for (int i = 0; i < (int) vecVis.size(); ++i)
2575   {
2576     CStdString strVis = vecVis[i];
2577
2578     if (strcmpi(strVis.c_str(), strDefaultVis.c_str()) == 0)
2579       iCurrentVis = iVis;
2580
2581     {
2582       CGUIMessage msg(GUI_MSG_LABEL_ADD, iWinID, iControlID, iVis++);
2583       msg.SetLabel(strVis);
2584       g_graphicsContext.SendMessage(msg);
2585     }
2586   }
2587   {
2588     CGUIMessage msg(GUI_MSG_ITEM_SELECT, iWinID, iControlID, iCurrentVis);
2589     g_graphicsContext.SendMessage(msg);
2590   }
2591 }
2592
2593 void CGUIWindowSettingsCategory::FillInVoiceMasks(DWORD dwPort, CSetting *pSetting)
2594 {
2595   CSettingString *pSettingString = (CSettingString*)pSetting;
2596   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2597   pControl->SetShowRange(true); // show the range
2598   int iCurrentMask = 0;
2599   int iMask = 0;
2600   vector<CStdString> vecMask;
2601
2602   //find masks in xml...
2603   TiXmlDocument xmlDoc;
2604   if ( !xmlDoc.LoadFile( "Q:\\system\\voicemasks.xml" ) ) return ;
2605   TiXmlElement* pRootElement = xmlDoc.RootElement();
2606   CStdString strValue = pRootElement->Value();
2607   if ( strValue != "VoiceMasks") return ;
2608   if (pRootElement)
2609   {
2610     const TiXmlNode *pChild = pRootElement->FirstChild("Name");
2611     while (pChild)
2612     {
2613       if (pChild->FirstChild())
2614       {
2615         CStdString strName = pChild->FirstChild()->Value();
2616         vecMask.push_back(strName);
2617       }
2618       pChild = pChild->NextSibling("Name");
2619     }
2620   }
2621   xmlDoc.Clear();
2622
2623
2624   CStdString strDefaultMask = pSettingString->GetData();
2625
2626   sort(vecMask.begin(), vecMask.end(), sortstringbyname());
2627 //  CStdString strCustom = "Custom";
2628   CStdString strNone = "None";
2629 //  vecMask.insert(vecMask.begin(), strCustom);
2630   vecMask.insert(vecMask.begin(), strNone);
2631   for (int i = 0; i < (int) vecMask.size(); ++i)
2632   {
2633     CStdString strMask = vecMask[i];
2634
2635     if (strcmpi(strMask.c_str(), strDefaultMask.c_str()) == 0)
2636       iCurrentMask = iMask;
2637
2638     pControl->AddLabel(strMask, iMask++);
2639   }
2640
2641   pControl->SetValue(iCurrentMask);
2642 }
2643
2644 void CGUIWindowSettingsCategory::FillInVoiceMaskValues(DWORD dwPort, CSetting *pSetting)
2645 {
2646   CStdString strCurMask = g_guiSettings.GetString(pSetting->GetSetting());
2647   if (strCurMask.CompareNoCase("None") == 0 || strCurMask.CompareNoCase("Custom") == 0 )
2648   {
2649 #ifndef HAS_XBOX_AUDIO
2650 #define XVOICE_MASK_PARAM_DISABLED (-1.0f)
2651 #endif
2652     g_stSettings.m_karaokeVoiceMask[dwPort].energy = XVOICE_MASK_PARAM_DISABLED;
2653     g_stSettings.m_karaokeVoiceMask[dwPort].pitch = XVOICE_MASK_PARAM_DISABLED;
2654     g_stSettings.m_karaokeVoiceMask[dwPort].whisper = XVOICE_MASK_PARAM_DISABLED;
2655     g_stSettings.m_karaokeVoiceMask[dwPort].robotic = XVOICE_MASK_PARAM_DISABLED;
2656     return;
2657   }
2658
2659   //find mask values in xml...
2660   TiXmlDocument xmlDoc;
2661   if ( !xmlDoc.LoadFile( "Q:\\system\\voicemasks.xml" ) ) return ;
2662   TiXmlElement* pRootElement = xmlDoc.RootElement();
2663   CStdString strValue = pRootElement->Value();
2664   if ( strValue != "VoiceMasks") return ;
2665   if (pRootElement)
2666   {
2667     const TiXmlNode *pChild = pRootElement->FirstChild("Name");
2668     while (pChild)
2669     {
2670       CStdString strMask = pChild->FirstChild()->Value();
2671       if (strMask.CompareNoCase(strCurMask) == 0)
2672       {
2673         for (int i = 0; i < 4;i++)
2674         {
2675           pChild = pChild->NextSibling();
2676           if (pChild)
2677           {
2678             CStdString strValue = pChild->Value();
2679             if (strValue.CompareNoCase("fSpecEnergyWeight") == 0)
2680             {
2681               if (pChild->FirstChild())
2682               {
2683                 CStdString strName = pChild->FirstChild()->Value();
2684                 g_stSettings.m_karaokeVoiceMask[dwPort].energy = (float) atof(strName.c_str());
2685               }
2686             }
2687             else if (strValue.CompareNoCase("fPitchScale") == 0)
2688             {
2689               if (pChild->FirstChild())
2690               {
2691                 CStdString strName = pChild->FirstChild()->Value();
2692                 g_stSettings.m_karaokeVoiceMask[dwPort].pitch = (float) atof(strName.c_str());
2693               }
2694             }
2695             else if (strValue.CompareNoCase("fWhisperValue") == 0)
2696             {
2697               if (pChild->FirstChild())
2698               {
2699                 CStdString strName = pChild->FirstChild()->Value();
2700                 g_stSettings.m_karaokeVoiceMask[dwPort].whisper = (float) atof(strName.c_str());
2701               }
2702             }
2703             else if (strValue.CompareNoCase("fRoboticValue") == 0)
2704             {
2705               if (pChild->FirstChild())
2706               {
2707                 CStdString strName = pChild->FirstChild()->Value();
2708                 g_stSettings.m_karaokeVoiceMask[dwPort].robotic = (float) atof(strName.c_str());
2709               }
2710             }
2711           }
2712         }
2713         break;
2714       }
2715       pChild = pChild->NextSibling("Name");
2716     }
2717   }
2718   xmlDoc.Clear();
2719 }
2720
2721 void CGUIWindowSettingsCategory::FillInResolutions(CSetting *pSetting, bool playbackSetting)
2722 {
2723   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2724   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2725   pControl->Clear();
2726   // Find the valid resolutions and add them as necessary
2727   vector<RESOLUTION> res;
2728   g_graphicsContext.GetAllowedResolutions(res, false);
2729
2730   /* add the virtual resolutions */
2731   res.push_back(AUTORES);
2732
2733   for (vector<RESOLUTION>::iterator it = res.begin(); it != res.end();it++)
2734   {
2735     RESOLUTION res = *it;
2736     if (res == AUTORES)
2737     {
2738       if (playbackSetting)
2739       {
2740         //  TODO: localize 2.0
2741         if (g_videoConfig.Has1080i() || g_videoConfig.Has720p())
2742           pControl->AddLabel(g_localizeStrings.Get(20049) , res); // Best Available
2743         else if (g_videoConfig.HasWidescreen())
2744           pControl->AddLabel(g_localizeStrings.Get(20050) , res); // Autoswitch between 16x9 and 4x3
2745         else
2746           continue;   // don't have a choice of resolution (other than 480p vs NTSC, which isn't a choice)
2747       }
2748       else  // "Auto"
2749         pControl->AddLabel(g_localizeStrings.Get(14061), res);
2750     }
2751     else
2752     {
2753       pControl->AddLabel(g_settings.m_ResInfo[res].strMode, res);
2754     }
2755   }
2756   pControl->SetValue(pSettingInt->GetData());
2757 }
2758
2759 void CGUIWindowSettingsCategory::FillInLanguages(CSetting *pSetting)
2760 {
2761   CSettingString *pSettingString = (CSettingString*)pSetting;
2762   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2763   pControl->Clear();
2764   m_strNewLanguage.Empty();
2765   //find languages...
2766   CHDDirectory directory;
2767   CFileItemList items;
2768
2769   CStdString strPath = "Q:\\language\\";
2770   directory.GetDirectory(strPath, items);
2771
2772   int iCurrentLang = 0;
2773   int iLanguage = 0;
2774   vector<CStdString> vecLanguage;
2775   for (int i = 0; i < items.Size(); ++i)
2776   {
2777     CFileItemPtr pItem = items[i];
2778     if (pItem->m_bIsFolder)
2779     {
2780       if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2781       if (strcmpi(pItem->GetLabel().c_str(), "fonts") == 0) continue;
2782       if (strcmpi(pItem->GetLabel().c_str(), "media") == 0) continue;
2783       vecLanguage.push_back(pItem->GetLabel());
2784     }
2785   }
2786
2787   sort(vecLanguage.begin(), vecLanguage.end(), sortstringbyname());
2788   for (unsigned int i = 0; i < vecLanguage.size(); ++i)
2789   {
2790     CStdString strLanguage = vecLanguage[i];
2791     if (strcmpi(strLanguage.c_str(), pSettingString->GetData().c_str()) == 0)
2792       iCurrentLang = iLanguage;
2793     pControl->AddLabel(strLanguage, iLanguage++);