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