[pvr] fixed - start and stop the pvr manager via app messenger when updating the...
[vuplus_xbmc] / xbmc / settings / GUIWindowSettingsCategory.cpp
1 /*
2  *      Copyright (C) 2005-2012 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, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "system.h"
22 #include "GUIUserMessages.h"
23 #include "GUIWindowSettingsCategory.h"
24 #include "Application.h"
25 #include "ApplicationMessenger.h"
26 #include "interfaces/Builtins.h"
27 #include "input/KeyboardLayoutConfiguration.h"
28 #include "filesystem/Directory.h"
29 #include "Util.h"
30 #include "guilib/GUISpinControlEx.h"
31 #include "guilib/GUIRadioButtonControl.h"
32 #include "guilib/GUIEditControl.h"
33 #include "guilib/GUIImage.h"
34 #include "utils/Weather.h"
35 #include "music/MusicDatabase.h"
36 #include "video/VideoDatabase.h"
37 #include "ViewDatabase.h"
38 #ifdef HAS_LCD
39 #include "utils/LCDFactory.h"
40 #endif
41 #include "PlayListPlayer.h"
42 #include "addons/Skin.h"
43 #include "guilib/GUIAudioManager.h"
44 #include "network/libscrobbler/lastfmscrobbler.h"
45 #include "network/libscrobbler/librefmscrobbler.h"
46 #include "GUIPassword.h"
47 #include "GUIInfoManager.h"
48 #include "dialogs/GUIDialogGamepad.h"
49 #include "dialogs/GUIDialogNumeric.h"
50 #include "dialogs/GUIDialogFileBrowser.h"
51 #include "addons/GUIDialogAddonSettings.h"
52 #include "addons/GUIWindowAddonBrowser.h"
53 #include "dialogs/GUIDialogContextMenu.h"
54 #include "dialogs/GUIDialogYesNo.h"
55 #include "dialogs/GUIDialogOK.h"
56 #include "dialogs/GUIDialogProgress.h"
57 #include "dialogs/GUIDialogKaiToast.h"
58 #include "addons/Visualisation.h"
59 #include "addons/AddonManager.h"
60 #include "addons/AddonInstaller.h"
61 #include "storage/MediaManager.h"
62 #include "network/Network.h"
63 #include "guilib/GUIControlGroupList.h"
64 #include "guilib/GUIWindowManager.h"
65 #include "guilib/GUIFontManager.h"
66 #include "cores/AudioEngine/AEFactory.h"
67 #ifdef _LINUX
68 #include "LinuxTimezone.h"
69 #include <dlfcn.h>
70 #ifdef HAS_HAL
71 #include "HALManager.h"
72 #endif
73 #endif
74 #if defined(TARGET_DARWIN_OSX)
75 #include "XBMCHelper.h"
76 #endif
77 #include "network/GUIDialogAccessPoints.h"
78 #include "filesystem/Directory.h"
79
80 #include "FileItem.h"
81 #include "guilib/GUIToggleButtonControl.h"
82 #include "filesystem/SpecialProtocol.h"
83
84 #include "network/Zeroconf.h"
85 #include "peripherals/Peripherals.h"
86 #include "peripherals/dialogs/GUIDialogPeripheralManager.h"
87 #include "peripherals/devices/PeripheralImon.h"
88
89 #ifdef _WIN32
90 #include "WIN32Util.h"
91 #endif
92 #include <map>
93 #include "Settings.h"
94 #include "AdvancedSettings.h"
95 #include "input/MouseStat.h"
96 #if defined(TARGET_WINDOWS)
97 #include "input/windows/WINJoystick.h"
98 #elif defined(HAS_SDL_JOYSTICK)
99 #include "input/SDLJoystick.h"
100 #endif
101 #include "guilib/LocalizeStrings.h"
102 #include "LangInfo.h"
103 #include "utils/StringUtils.h"
104 #include "utils/URIUtils.h"
105 #include "utils/SystemInfo.h"
106 #include "windowing/WindowingFactory.h"
107 #include "pvr/dialogs/GUIDialogPVRChannelManager.h"
108 #include "pvr/PVRManager.h"
109 #include "pvr/addons/PVRClients.h"
110
111 #if defined(HAVE_LIBCRYSTALHD)
112 #include "cores/dvdplayer/DVDCodecs/Video/CrystalHD.h"
113 #endif
114
115 #if defined(HAS_AIRPLAY)
116 #include "network/AirPlayServer.h"
117 #endif
118
119 #if defined(HAS_WEB_SERVER)
120 #include "network/WebServer.h"
121 #endif
122
123 using namespace std;
124 using namespace XFILE;
125 using namespace ADDON;
126 using namespace PVR;
127 using namespace PERIPHERALS;
128
129 #define CONTROL_GROUP_BUTTONS           0
130 #define CONTROL_GROUP_SETTINGS          1
131 #define CONTROL_SETTINGS_LABEL          2
132 #define CATEGORY_GROUP_ID               3
133 #define SETTINGS_GROUP_ID               5
134 #define CONTROL_DEFAULT_BUTTON          7
135 #define CONTROL_DEFAULT_RADIOBUTTON     8
136 #define CONTROL_DEFAULT_SPIN            9
137 #define CONTROL_DEFAULT_CATEGORY_BUTTON 10
138 #define CONTROL_DEFAULT_SEPARATOR       11
139 #define CONTROL_DEFAULT_EDIT            12
140 #define CONTROL_START_BUTTONS           -100
141 #define CONTROL_START_CONTROL           -80
142
143 CGUIWindowSettingsCategory::CGUIWindowSettingsCategory(void)
144     : CGUIWindow(WINDOW_SETTINGS_MYPICTURES, "SettingsCategory.xml")
145 {
146   m_loadType = KEEP_IN_MEMORY;
147   m_pOriginalSpin = NULL;
148   m_pOriginalRadioButton = NULL;
149   m_pOriginalButton = NULL;
150   m_pOriginalCategoryButton = NULL;
151   m_pOriginalImage = NULL;
152   m_pOriginalEdit = NULL;
153   // set the correct ID range...
154   m_idRange.clear();
155   m_idRange.push_back(WINDOW_SETTINGS_MYPICTURES);
156   m_idRange.push_back(WINDOW_SETTINGS_MYPROGRAMS);
157   m_idRange.push_back(WINDOW_SETTINGS_MYWEATHER);
158   m_idRange.push_back(WINDOW_SETTINGS_MYMUSIC);
159   m_idRange.push_back(WINDOW_SETTINGS_SYSTEM);
160   m_idRange.push_back(WINDOW_SETTINGS_MYVIDEOS);
161   m_idRange.push_back(WINDOW_SETTINGS_SERVICE);
162   m_idRange.push_back(WINDOW_SETTINGS_APPEARANCE);
163   m_idRange.push_back(WINDOW_SETTINGS_MYPVR);
164
165   m_iScreen = 0;
166   m_strOldTrackFormat = "";
167   m_strOldTrackFormatRight = "";
168   m_returningFromSkinLoad = false;
169   m_delayedSetting = NULL;
170 }
171
172 CGUIWindowSettingsCategory::~CGUIWindowSettingsCategory(void)
173 {
174   FreeControls();
175   delete m_pOriginalEdit;
176 }
177
178 bool CGUIWindowSettingsCategory::OnBack(int actionID)
179 {
180   g_settings.Save();
181   m_lastControlID = 0; // don't save the control as we go to a different window each time
182   return CGUIWindow::OnBack(actionID);
183 }
184
185 bool CGUIWindowSettingsCategory::OnMessage(CGUIMessage &message)
186 {
187   switch (message.GetMessage())
188   {
189   case GUI_MSG_CLICKED:
190     {
191       unsigned int iControl = message.GetSenderId();
192       for (unsigned int i = 0; i < m_vecSettings.size(); i++)
193       {
194         if (m_vecSettings[i]->GetID() == (int)iControl)
195           OnClick(m_vecSettings[i]);
196       }
197     }
198     break;
199   case GUI_MSG_FOCUSED:
200     {
201       CGUIWindow::OnMessage(message);
202       int focusedControl = GetFocusedControlID();
203       if (focusedControl >= CONTROL_START_BUTTONS && focusedControl < (int)(CONTROL_START_BUTTONS + m_vecSections.size()) &&
204           focusedControl - CONTROL_START_BUTTONS != m_iSection && !m_returningFromSkinLoad)
205       {
206         // changing section, check for updates and cancel any delayed changes
207         m_delayedSetting = NULL;
208         CheckForUpdates();
209
210         if (m_vecSections[focusedControl-CONTROL_START_BUTTONS]->m_strCategory == "masterlock")
211         {
212           if (!g_passwordManager.IsMasterLockUnlocked(true))
213           { // unable to go to this category - focus the previous one
214             SET_CONTROL_FOCUS(CONTROL_START_BUTTONS + m_iSection, 0);
215             return false;
216           }
217         }
218         if (m_vecSections[focusedControl-CONTROL_START_BUTTONS]->m_strCategory == "pvrparental")
219         {
220           if (!g_PVRManager.CheckParentalPIN(g_localizeStrings.Get(19262).c_str()))
221           { // unable to go to this category - focus the previous one
222             SET_CONTROL_FOCUS(CONTROL_START_BUTTONS + m_iSection, 0);
223             return false;
224           }
225         }
226
227         m_iSection = focusedControl - CONTROL_START_BUTTONS;
228
229         CreateSettings();
230       }
231       return true;
232     }
233     break;
234   case GUI_MSG_LOAD_SKIN:
235     {
236       if (IsActive())
237         m_returningFromSkinLoad = true;
238     }
239     break;
240   case GUI_MSG_WINDOW_INIT:
241     {
242       m_delayedSetting = NULL;
243       if (message.GetParam1() != WINDOW_INVALID && !m_returningFromSkinLoad)
244       { // coming to this window first time (ie not returning back from some other window)
245         // so we reset our section and control states
246         m_iSection = 0;
247         ResetControlStates();
248       }
249       m_iScreen = (int)message.GetParam2() - (int)CGUIWindow::GetID();
250       CGUIWindow::OnMessage(message);
251       m_returningFromSkinLoad = false;
252       return true;
253     }
254     break;
255   case GUI_MSG_UPDATE_ITEM:
256     if (m_delayedSetting)
257     {
258       OnSettingChanged(m_delayedSetting);
259       m_delayedSetting = NULL;
260       return true;
261     }
262     break;
263   case GUI_MSG_UPDATE:
264     if (HasID(message.GetSenderId()))
265     {
266       int focusedControl = GetFocusedControlID();
267       CreateSettings();
268       SET_CONTROL_FOCUS(focusedControl, 0);
269     }
270     break;
271   case GUI_MSG_NOTIFY_ALL:
272     {
273       if (message.GetParam1() == GUI_MSG_WINDOW_RESIZE)
274       {
275         // Cancel delayed setting - it's only used for res changing anyway
276         m_delayedSetting = NULL;
277         if (IsActive() && g_guiSettings.GetResolution() != g_graphicsContext.GetVideoResolution())
278         {
279           g_guiSettings.SetResolution(g_graphicsContext.GetVideoResolution());
280           CreateSettings();
281         }
282       }
283     }
284     break;
285   case GUI_MSG_WINDOW_DEINIT:
286     {
287       m_delayedSetting = NULL;
288
289       CheckForUpdates();
290       CGUIWindow::OnMessage(message);
291       FreeControls();
292       return true;
293     }
294     break;
295   }
296   return CGUIWindow::OnMessage(message);
297 }
298
299 void CGUIWindowSettingsCategory::SetupControls()
300 {
301   // cleanup first, if necessary
302   FreeControls();
303   m_pOriginalSpin = (CGUISpinControlEx*)GetControl(CONTROL_DEFAULT_SPIN);
304   m_pOriginalRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_DEFAULT_RADIOBUTTON);
305   m_pOriginalCategoryButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_CATEGORY_BUTTON);
306   m_pOriginalButton = (CGUIButtonControl *)GetControl(CONTROL_DEFAULT_BUTTON);
307   m_pOriginalImage = (CGUIImage *)GetControl(CONTROL_DEFAULT_SEPARATOR);
308   if (!m_pOriginalCategoryButton || !m_pOriginalSpin || !m_pOriginalRadioButton || !m_pOriginalButton)
309     return ;
310   m_pOriginalEdit = (CGUIEditControl *)GetControl(CONTROL_DEFAULT_EDIT);
311   if (!m_pOriginalEdit || m_pOriginalEdit->GetControlType() != CGUIControl::GUICONTROL_EDIT)
312   {
313     delete m_pOriginalEdit;
314     m_pOriginalEdit = new CGUIEditControl(*m_pOriginalButton);
315   }
316   m_pOriginalSpin->SetVisible(false);
317   m_pOriginalRadioButton->SetVisible(false);
318   m_pOriginalButton->SetVisible(false);
319   m_pOriginalCategoryButton->SetVisible(false);
320   m_pOriginalEdit->SetVisible(false);
321   if (m_pOriginalImage) m_pOriginalImage->SetVisible(false);
322   // setup our control groups...
323   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(CATEGORY_GROUP_ID);
324   if (!group)
325     return;
326   // get a list of different sections
327   CSettingsGroup *pSettingsGroup = g_guiSettings.GetGroup(m_iScreen);
328   if (!pSettingsGroup) return ;
329   // update the screen string
330   SET_CONTROL_LABEL(CONTROL_SETTINGS_LABEL, pSettingsGroup->GetLabelID());
331   // get the categories we need
332   pSettingsGroup->GetCategories(m_vecSections);
333   // run through and create our buttons...
334   int j=0;
335   for (unsigned int i = 0; i < m_vecSections.size(); i++)
336   {
337     if (m_vecSections[i]->m_labelID == 12360 && !g_settings.IsMasterUser())
338       continue;
339     CGUIButtonControl *pButton = NULL;
340     if (m_pOriginalCategoryButton->GetControlType() == CGUIControl::GUICONTROL_TOGGLEBUTTON)
341       pButton = new CGUIToggleButtonControl(*(CGUIToggleButtonControl *)m_pOriginalCategoryButton);
342     else
343       pButton = new CGUIButtonControl(*m_pOriginalCategoryButton);
344     pButton->SetLabel(g_localizeStrings.Get(m_vecSections[i]->m_labelID));
345     pButton->SetID(CONTROL_START_BUTTONS + j);
346     pButton->SetVisible(true);
347     pButton->AllocResources();
348     group->AddControl(pButton);
349     j++;
350   }
351   if (m_iSection < 0 || m_iSection >= (int)m_vecSections.size())
352     m_iSection = 0;
353   CreateSettings();
354   // set focus correctly
355   m_defaultControl = CONTROL_START_BUTTONS;
356 }
357
358 CGUIControl* CGUIWindowSettingsCategory::AddIntBasedSpinControl(CSetting *pSetting, float groupWidth, int &iControlID)
359 {
360   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
361   CGUISpinControlEx *pControl = (CGUISpinControlEx *)AddSetting(pSetting, groupWidth, iControlID);
362   if (!pSettingInt->m_entries.empty())
363   {
364     for (map<int,int>::iterator it=pSettingInt->m_entries.begin(); it != pSettingInt->m_entries.end();++it)
365       pControl->AddLabel(g_localizeStrings.Get(it->first), it->second);
366     pControl->SetValue(pSettingInt->GetData());
367   }
368   return pControl;
369 }
370
371 void CGUIWindowSettingsCategory::CreateSettings()
372 {
373   FreeSettingsControls();
374
375   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
376   if (!group)
377     return;
378   vecSettings settings;
379   g_guiSettings.GetSettingsGroup(m_vecSections[m_iSection], settings);
380   int iControlID = CONTROL_START_CONTROL;
381   for (unsigned int i = 0; i < settings.size(); i++)
382   {
383     CSetting *pSetting = settings[i];
384     CStdString strSetting = pSetting->GetSetting();
385     if (pSetting->GetType() == SETTINGS_TYPE_INT)
386     {
387       CGUISpinControlEx *pControl = (CGUISpinControlEx *)AddIntBasedSpinControl(pSetting, group->GetWidth(), iControlID);
388       CSettingInt *pSettingInt = (CSettingInt*)pSetting;
389       if (strSetting.Equals("videoplayer.pauseafterrefreshchange"))
390       {
391         pControl->AddLabel(g_localizeStrings.Get(13551), 0);
392
393         for (int i = 1; i <= MAXREFRESHCHANGEDELAY; i++)
394         {
395           CStdString delayText;
396           delayText.Format(g_localizeStrings.Get(13553).c_str(), (double)i / 10.0);
397           pControl->AddLabel(delayText, i);
398         }
399         pControl->SetValue(pSettingInt->GetData());
400       }
401       else if (strSetting.Equals("subtitles.color"))
402       {
403         for (int i = SUBTITLE_COLOR_START; i <= SUBTITLE_COLOR_END; i++)
404           pControl->AddLabel(g_localizeStrings.Get(760 + i), i);
405         pControl->SetValue(pSettingInt->GetData());
406       }
407       else if (strSetting.Equals("lookandfeel.startupwindow"))
408         FillInStartupWindow(pSetting);
409       else if (strSetting.Equals("subtitles.height") || strSetting.Equals("karaoke.fontheight") )
410         FillInSubtitleHeights(pSetting, pControl);
411       else if (strSetting.Equals("videoscreen.screen"))
412         FillInScreens(strSetting, g_guiSettings.GetResolution());
413       else if (strSetting.Equals("videoscreen.resolution"))
414         FillInResolutions(strSetting, g_guiSettings.GetInt("videoscreen.screen"), g_guiSettings.GetResolution(), false);
415       else if (strSetting.Equals("epg.defaultguideview"))
416         FillInEpgGuideView(pSetting);
417       else if (strSetting.Equals("pvrplayback.startlast"))
418         FillInPvrStartLastChannel(pSetting);
419       continue;
420     }
421 #ifdef HAS_WEB_SERVER
422     else if (strSetting.Equals("services.webserverport"))
423     {
424       AddSetting(pSetting, group->GetWidth(), iControlID);
425       CBaseSettingControl *control = GetSetting(pSetting->GetSetting());
426       control->SetDelayed();
427       continue;
428     }
429 #endif
430     else if (strSetting.Equals("services.esport"))
431     {
432 #ifdef HAS_EVENT_SERVER
433       AddSetting(pSetting, group->GetWidth(), iControlID);
434       CBaseSettingControl *control = GetSetting(pSetting->GetSetting());
435       control->SetDelayed();
436       continue;
437 #endif
438     }
439     else if (strSetting.Equals("network.httpproxyport"))
440     {
441       AddSetting(pSetting, group->GetWidth(), iControlID);
442       CBaseSettingControl *control = GetSetting(pSetting->GetSetting());
443       control->SetDelayed();
444       continue;
445     }
446     else if (strSetting.Equals("subtitles.font") || strSetting.Equals("karaoke.font") )
447     {
448       AddSetting(pSetting, group->GetWidth(), iControlID);
449       FillInSubtitleFonts(pSetting);
450       continue;
451     }
452     else if (strSetting.Equals("subtitles.charset") || strSetting.Equals("locale.charset") || strSetting.Equals("karaoke.charset"))
453     {
454       AddSetting(pSetting, group->GetWidth(), iControlID);
455       FillInCharSets(pSetting);
456       continue;
457     }
458     else if (strSetting.Equals("lookandfeel.font"))
459     {
460       AddSetting(pSetting, group->GetWidth(), iControlID);
461       FillInSkinFonts(pSetting);
462       continue;
463     }
464     else if (strSetting.Equals("lookandfeel.soundskin"))
465     {
466       AddSetting(pSetting, group->GetWidth(), iControlID);
467       FillInSoundSkins(pSetting);
468       continue;
469     }
470     else if (strSetting.Equals("locale.language"))
471     {
472       AddSetting(pSetting, group->GetWidth(), iControlID);
473       GetSetting(pSetting->GetSetting())->SetDelayed();
474       FillInLanguages(pSetting);
475       continue;
476     }
477     else if (strSetting.Equals("locale.audiolanguage") || strSetting.Equals("locale.subtitlelanguage"))
478     {
479       AddSetting(pSetting, group->GetWidth(), iControlID);
480       vector<CStdString> languages;
481       languages.push_back(g_localizeStrings.Get(308));
482       languages.push_back(g_localizeStrings.Get(309));
483       vector<CStdString> languageKeys;
484       languageKeys.push_back("original");
485       languageKeys.push_back("default");
486       FillInLanguages(pSetting, languages, languageKeys);
487       continue;
488     }
489 #ifdef _LINUX
490     else if (strSetting.Equals("locale.timezonecountry"))
491     {
492       CStdString myTimezoneCountry = g_guiSettings.GetString("locale.timezonecountry");
493       int myTimezeoneCountryIndex = 0;
494
495       CGUISpinControlEx *pControl = (CGUISpinControlEx *)AddSetting(pSetting, group->GetWidth(), iControlID);
496       vector<CStdString> countries = g_timezone.GetCounties();
497       for (unsigned int i=0; i < countries.size(); i++)
498       {
499         if (countries[i] == myTimezoneCountry)
500            myTimezeoneCountryIndex = i;
501         pControl->AddLabel(countries[i], i);
502       }
503       pControl->SetValue(myTimezeoneCountryIndex);
504       continue;
505     }
506     else if (strSetting.Equals("locale.timezone"))
507     {
508       CStdString myTimezoneCountry = g_guiSettings.GetString("locale.timezonecountry");
509       CStdString myTimezone = g_guiSettings.GetString("locale.timezone");
510       int myTimezoneIndex = 0;
511
512       CGUISpinControlEx *pControl = (CGUISpinControlEx *)AddSetting(pSetting, group->GetWidth(), iControlID);
513       pControl->Clear();
514       vector<CStdString> timezones = g_timezone.GetTimezonesByCountry(myTimezoneCountry);
515       for (unsigned int i=0; i < timezones.size(); i++)
516       {
517         if (timezones[i] == myTimezone)
518            myTimezoneIndex = i;
519         pControl->AddLabel(timezones[i], i);
520       }
521       pControl->SetValue(myTimezoneIndex);
522       continue;
523     }
524 #endif
525     else if (strSetting.Equals("videoscreen.screenmode"))
526     {
527       AddSetting(pSetting, group->GetWidth(), iControlID);
528       FillInRefreshRates(strSetting, g_guiSettings.GetResolution(), false);
529       continue;
530     }
531     else if (strSetting.Equals("lookandfeel.skintheme"))
532     {
533       AddSetting(pSetting, group->GetWidth(), iControlID);
534       FillInSkinThemes(pSetting);
535       continue;
536     }
537     else if (strSetting.Equals("lookandfeel.skincolors"))
538     {
539       AddSetting(pSetting, group->GetWidth(), iControlID);
540       FillInSkinColors(pSetting);
541       continue;
542     }
543     /*
544     FIXME: setting is hidden in GUI because not supported properly.
545     else if (strSetting.Equals("videoplayer.displayresolution") || strSetting.Equals("pictures.displayresolution"))
546     {
547       FillInResolutions(pSetting);
548     }
549     */
550     else if (strSetting.Equals("locale.country"))
551     {
552       AddSetting(pSetting, group->GetWidth(), iControlID);
553       FillInRegions(pSetting);
554       continue;
555     }
556     else if (strSetting.Equals("network.interface"))
557     {
558       FillInNetworkInterfaces(pSetting, group->GetWidth(), iControlID);
559       continue;
560     }
561     else if (strSetting.Equals("audiooutput.audiodevice"))
562     {
563       AddSetting(pSetting, group->GetWidth(), iControlID);
564       FillInAudioDevices(pSetting);
565       continue;
566     }
567     else if (strSetting.Equals("audiooutput.passthroughdevice"))
568     {
569       AddSetting(pSetting, group->GetWidth(), iControlID);
570       FillInAudioDevices(pSetting,true);
571       continue;
572     }
573     AddSetting(pSetting, group->GetWidth(), iControlID);
574   }
575
576   if (m_vecSections[m_iSection]->m_strCategory == "network")
577      NetworkInterfaceChanged();
578
579   // update our settings (turns controls on/off as appropriate)
580   UpdateSettings();
581 }
582
583 void CGUIWindowSettingsCategory::UpdateSettings()
584 {
585   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
586   {
587     CBaseSettingControl *pSettingControl = m_vecSettings[i];
588     pSettingControl->Update();
589     CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
590 #ifdef HAVE_LIBVDPAU
591     if (strSetting.Equals("videoplayer.vdpauUpscalingLevel"))
592     {
593       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
594       if (pControl)
595       {
596         pControl->SetEnabled(true);
597       }
598     }
599     else
600 #endif
601     if (strSetting.Equals("videoscreen.resolution"))
602     {
603       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
604       if (pControl)
605         pControl->SetEnabled(g_guiSettings.GetInt("videoscreen.screen") != DM_WINDOWED);
606     }
607     else if (strSetting.Equals("videoscreen.screenmode"))
608     {
609       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
610       if (pControl)
611         pControl->SetEnabled(g_guiSettings.GetInt("videoscreen.screen") != DM_WINDOWED);
612     }
613     else if (strSetting.Equals("videoscreen.fakefullscreen"))
614     {
615       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
616       if (pControl)
617         pControl->SetEnabled(g_guiSettings.GetInt("videoscreen.screen") != DM_WINDOWED);
618     }
619 #if defined(TARGET_DARWIN_OSX) || defined(_WIN32)
620     else if (strSetting.Equals("videoscreen.blankdisplays"))
621     {
622       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
623       if (pControl)
624       {
625         if (g_Windowing.IsFullScreen())
626           pControl->SetEnabled(true);
627         else
628           pControl->SetEnabled(false);
629       }
630     }
631 #endif
632 #if defined(TARGET_DARWIN_OSX)
633     else if (strSetting.Equals("input.appleremotemode"))
634     {
635       int remoteMode = g_guiSettings.GetInt("input.appleremotemode");
636
637       // if it's not disabled, start the event server or else apple remote won't work
638       if ( remoteMode != APPLE_REMOTE_DISABLED )
639       {
640         g_guiSettings.SetBool("services.esenabled", true);
641         if (!g_application.StartEventServer())
642           CGUIDialogKaiToast::QueueNotification("DefaultIconWarning.png", g_localizeStrings.Get(33102), g_localizeStrings.Get(33100));
643       }
644
645       // if XBMC helper is running, prompt user before effecting change
646       if ( XBMCHelper::GetInstance().IsRunning() && XBMCHelper::GetInstance().GetMode()!=remoteMode )
647       {
648         bool cancelled;
649         if (!CGUIDialogYesNo::ShowAndGetInput(13144, 13145, 13146, 13147, -1, -1, cancelled, 10000))
650         {
651           // user declined, restore previous spinner state and appleremote mode
652           CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
653           g_guiSettings.SetInt("input.appleremotemode", XBMCHelper::GetInstance().GetMode());
654           pControl->SetValue(XBMCHelper::GetInstance().GetMode());
655         }
656         else
657         {
658           // reload configuration
659           XBMCHelper::GetInstance().Configure();
660         }
661       }
662       else
663       {
664         // set new configuration.
665         XBMCHelper::GetInstance().Configure();
666       }
667
668       if (XBMCHelper::GetInstance().ErrorStarting() == true)
669       {
670         // inform user about error
671         CGUIDialogOK::ShowAndGetInput(13620, 13621, 20022, 20022);
672
673         // reset spinner to disabled state
674         CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
675         pControl->SetValue(APPLE_REMOTE_DISABLED);
676       }
677     }
678     else if (strSetting.Equals("input.appleremotealwayson"))
679      {
680        CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
681        if (pControl)
682        {
683          int value = g_guiSettings.GetInt("input.appleremotemode");
684          if (value != APPLE_REMOTE_DISABLED)
685            pControl->SetEnabled(true);
686          else
687            pControl->SetEnabled(false);
688        }
689      }
690      else if (strSetting.Equals("input.appleremotesequencetime"))
691      {
692        CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
693        if (pControl)
694        {
695          int value = g_guiSettings.GetInt("input.appleremotemode");
696          if (value == APPLE_REMOTE_UNIVERSAL)
697            pControl->SetEnabled(true);
698          else
699            pControl->SetEnabled(false);
700        }
701      }
702 #endif
703     else if (strSetting.Equals("filelists.allowfiledeletion"))
704     {
705       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
706       if (pControl) pControl->SetEnabled(!g_settings.GetCurrentProfile().filesLocked() || g_passwordManager.bMasterUser);
707     }
708     else if (strSetting.Equals("filelists.showaddsourcebuttons"))
709     {
710       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
711       if (pControl) pControl->SetEnabled(g_settings.GetCurrentProfile().canWriteSources() || g_passwordManager.bMasterUser);
712     }
713     else if (strSetting.Equals("masterlock.startuplock"))
714     {
715       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
716       if (pControl) pControl->SetEnabled(g_settings.GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE);
717     }
718     else if (strSetting.Equals("pvrmanager.channelscan"))
719     {
720       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
721       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("pvrmanager.enabled") && g_PVRClients && g_PVRClients->GetClientsSupportingChannelScan().size() > 0);
722     }
723     else if (strSetting.Equals("pvrmanager.channelmanager") || strSetting.Equals("pvrmenu.searchicons"))
724     {
725       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
726       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("pvrmanager.enabled"));
727     }
728     else if (!strSetting.Equals("pvrparental.enabled") &&
729         (strSetting.Equals("pvrparental.pin") || strSetting.Equals("pvrparental.duration")))
730     {
731       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
732       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("pvrparental.enabled"));
733     }
734     else if (!strSetting.Equals("services.esenabled")
735              && strSetting.Left(11).Equals("services.es"))
736     {
737       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
738       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("services.esenabled"));
739     }
740     else if (strSetting.Equals("services.upnpannounce"))
741     {
742       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
743       pControl->SetEnabled(g_guiSettings.GetBool("services.upnpserver"));
744     }
745     else if (strSetting.Equals("audiocds.quality"))
746     { // only visible if we are doing non-WAV ripping
747       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
748       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("audiocds.encoder") != CDDARIP_ENCODER_WAV &&
749                                          g_guiSettings.GetInt("audiocds.encoder") != CDDARIP_ENCODER_FLAC);
750     }
751     else if (strSetting.Equals("audiocds.bitrate"))
752     { // only visible if we are ripping to CBR
753       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
754       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("audiocds.encoder") != CDDARIP_ENCODER_WAV &&
755                                          g_guiSettings.GetInt("audiocds.encoder") != CDDARIP_ENCODER_FLAC &&
756                                          g_guiSettings.GetInt("audiocds.quality") == CDDARIP_QUALITY_CBR);
757     }
758     else if (strSetting.Equals("audiocds.compressionlevel"))
759     { // only visible if we are doing FLAC ripping
760       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
761       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("audiocds.encoder") == CDDARIP_ENCODER_FLAC);
762     }
763     else if (
764              strSetting.Equals("audiooutput.passthroughdevice") ||
765              strSetting.Equals("audiooutput.ac3passthrough") ||
766              strSetting.Equals("audiooutput.dtspassthrough") ||
767              strSetting.Equals("audiooutput.passthroughaac"))
768     { // only visible if we are in digital mode
769       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
770       if (pControl) pControl->SetEnabled(AUDIO_IS_BITSTREAM(g_guiSettings.GetInt("audiooutput.mode")));
771     }
772     else if (
773              strSetting.Equals("audiooutput.multichannellpcm" ) ||
774              strSetting.Equals("audiooutput.truehdpassthrough") ||
775              strSetting.Equals("audiooutput.dtshdpassthrough" ))
776     {
777       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
778       if (pControl)
779       {
780         if (strSetting.Equals("audiooutput.dtshdpassthrough") && !g_guiSettings.GetBool("audiooutput.dtspassthrough"))
781           pControl->SetEnabled(false);
782         else
783           pControl->SetEnabled(g_guiSettings.GetInt("audiooutput.mode") == AUDIO_HDMI);
784       }
785     }
786     else if (strSetting.Equals("musicplayer.crossfade"))
787     {
788       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
789       if (pControl) pControl->SetEnabled(g_guiSettings.GetString("audiooutput.audiodevice").find("wasapi:") == CStdString::npos);
790     }
791     else if (strSetting.Equals("musicplayer.crossfadealbumtracks"))
792     {
793       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
794       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("musicplayer.crossfade") > 0 &&
795                                          g_guiSettings.GetString("audiooutput.audiodevice").find("wasapi:") == CStdString::npos);
796     }
797 #ifdef HAS_WEB_SERVER
798     else if (strSetting.Equals("services.webserverusername") ||
799              strSetting.Equals("services.webserverpassword"))
800     {
801       CGUIEditControl *pControl = (CGUIEditControl *)GetControl(pSettingControl->GetID());
802       if (pControl)
803         pControl->SetEnabled(g_guiSettings.GetBool("services.webserver"));
804     }
805 #endif
806 #ifdef HAS_AIRPLAY
807     else if ( strSetting.Equals("services.airplaypassword") ||
808               strSetting.Equals("services.useairplaypassword"))
809     {
810       if (strSetting.Equals("services.airplaypassword"))
811       {
812         CGUIEditControl *pControl = (CGUIEditControl *)GetControl(pSettingControl->GetID());
813         if (pControl)
814           pControl->SetEnabled(g_guiSettings.GetBool("services.useairplaypassword"));
815       }
816       else//useairplaypassword
817       {
818         CGUIRadioButtonControl *pControl = (CGUIRadioButtonControl *)GetControl(pSettingControl->GetID());
819         if (pControl)
820           pControl->SetEnabled(g_guiSettings.GetBool("services.airplay"));
821       }
822
823       //set credentials to airplay server
824       if (g_guiSettings.GetBool("services.airplay"))
825       {
826         CStdString password = g_guiSettings.GetString("services.airplaypassword");
827         CAirPlayServer::SetCredentials(g_guiSettings.GetBool("services.useairplaypassword"),
828                                        password);
829       }
830     }
831 #endif//HAS_AIRPLAY
832     else if (strSetting.Equals("network.ipaddress") || strSetting.Equals("network.subnet") || strSetting.Equals("network.gateway") || strSetting.Equals("network.dns"))
833     {
834 #ifdef _LINUX
835       bool enabled = (geteuid() == 0);
836 #else
837       bool enabled = false;
838 #endif
839       CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.assignment")->GetID());
840       if (pControl1)
841          enabled = (pControl1->GetValue() == NETWORK_STATIC);
842
843        CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
844        if (pControl) pControl->SetEnabled(enabled);
845     }
846     else if (strSetting.Equals("network.assignment"))
847     {
848       CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.assignment")->GetID());
849 #ifdef HAS_LINUX_NETWORK
850       if (pControl1)
851          pControl1->SetEnabled(geteuid() == 0);
852 #endif
853     }
854     else if (strSetting.Equals("network.essid") || strSetting.Equals("network.enc") || strSetting.Equals("network.key"))
855     {
856       // Get network information
857       CGUISpinControlEx *ifaceControl = (CGUISpinControlEx *)GetControl(GetSetting("network.interface")->GetID());
858       CStdString ifaceName = ifaceControl->GetLabel();
859       CNetworkInterface* iface = g_application.getNetwork().GetInterfaceByName(ifaceName);
860       bool bIsWireless = iface->IsWireless();
861
862 #ifdef HAS_LINUX_NETWORK
863       bool enabled = bIsWireless && (geteuid() == 0);
864 #else
865       bool enabled = bIsWireless;
866 #endif
867       CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.assignment")->GetID());
868       if (pControl1)
869          enabled &= (pControl1->GetValue() != NETWORK_DISABLED);
870
871       if (strSetting.Equals("network.key"))
872       {
873          pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.enc")->GetID());
874          if (pControl1) enabled &= (pControl1->GetValue() != ENC_NONE);
875       }
876
877        CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
878        if (pControl) pControl->SetEnabled(enabled);
879     }
880     else if (strSetting.Equals("network.httpproxyserver")   || strSetting.Equals("network.httpproxyport") ||
881              strSetting.Equals("network.httpproxyusername") || strSetting.Equals("network.httpproxypassword"))
882     {
883       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
884       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("network.usehttpproxy"));
885     }
886 #ifdef HAS_LINUX_NETWORK
887     else if (strSetting.Equals("network.key"))
888     {
889       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
890       CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.enc")->GetID());
891       if (pControl && pControl1)
892          pControl->SetEnabled(!pControl1->IsDisabled() && pControl1->GetValue() > 0);
893     }
894     else if (strSetting.Equals("network.save"))
895     {
896       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
897       pControl->SetEnabled(geteuid() == 0);
898     }
899 #endif
900     else if (strSetting.Equals("scrobbler.lastfmusername") || strSetting.Equals("scrobbler.lastfmpass"))
901     {
902       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
903       if (pControl)
904         pControl->SetEnabled(g_guiSettings.GetBool("scrobbler.lastfmsubmit") | g_guiSettings.GetBool("scrobbler.lastfmsubmitradio"));
905     }
906     else if (strSetting.Equals("scrobbler.librefmusername") || strSetting.Equals("scrobbler.librefmpass"))
907     {
908       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
909       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("scrobbler.librefmsubmit"));
910     }
911     else if (strSetting.Equals("subtitles.color") || strSetting.Equals("subtitles.style") || strSetting.Equals("subtitles.charset"))
912     {
913       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
914       pControl->SetEnabled(CUtil::IsUsingTTFSubtitles());
915     }
916     else if (strSetting.Equals("locale.charset"))
917     { // TODO: Determine whether we are using a TTF font or not.
918       //   CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
919       //   if (pControl) pControl->SetEnabled(g_guiSettings.GetString("lookandfeel.font").Right(4) == ".ttf");
920     }
921     else if (strSetting.Equals("screensaver.settings"))
922     {
923       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
924       AddonPtr addon;
925       if (CAddonMgr::Get().GetAddon(g_guiSettings.GetString("screensaver.mode"), addon, ADDON_SCREENSAVER))
926         pControl->SetEnabled(addon->HasSettings());
927       else
928         pControl->SetEnabled(false);
929     }
930     else if (strSetting.Equals("screensaver.preview")           ||
931              strSetting.Equals("screensaver.usedimonpause")     ||
932              strSetting.Equals("screensaver.usemusicvisinstead"))
933     {
934       CGUIControl *pControl = (CGUIControl *)GetControl(GetSetting(strSetting)->GetID());
935       pControl->SetEnabled(!g_guiSettings.GetString("screensaver.mode").IsEmpty());
936       if (strSetting.Equals("screensaver.usedimonpause") && g_guiSettings.GetString("screensaver.mode").Equals("screensaver.xbmc.builtin.dim"))
937         pControl->SetEnabled(false);
938     }
939     else if (strSetting.Equals("musicfiles.trackformat"))
940     {
941       if (m_strOldTrackFormat != g_guiSettings.GetString("musicfiles.trackformat"))
942       {
943         CUtil::DeleteMusicDatabaseDirectoryCache();
944         m_strOldTrackFormat = g_guiSettings.GetString("musicfiles.trackformat");
945       }
946     }
947     else if (strSetting.Equals("musicfiles.trackformatright"))
948     {
949       if (m_strOldTrackFormatRight != g_guiSettings.GetString("musicfiles.trackformatright"))
950       {
951         CUtil::DeleteMusicDatabaseDirectoryCache();
952         m_strOldTrackFormatRight = g_guiSettings.GetString("musicfiles.trackformatright");
953       }
954     }
955 #ifdef HAS_TIME_SERVER
956     else if (strSetting.Equals("locale.timeserveraddress"))
957     {
958       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
959       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("locale.timeserver"));
960     }
961 #endif
962     else if (strSetting.Equals("audiocds.recordingpath") || strSetting.Equals("debug.screenshotpath"))
963     {
964       CGUIButtonControl *pControl = (CGUIButtonControl *)GetControl(pSettingControl->GetID());
965       if (pControl && g_guiSettings.GetString(strSetting, false).IsEmpty())
966         pControl->SetLabel2("");
967     }
968     else if (strSetting.Equals("lookandfeel.rssedit"))
969     {
970       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
971       pControl->SetEnabled(g_guiSettings.GetBool("lookandfeel.enablerssfeeds"));
972     }
973     else if (strSetting.Equals("lookandfeel.skinsettings"))
974     {
975       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
976       pControl->SetEnabled(g_SkinInfo->HasSkinFile("SkinSettings.xml"));
977     }
978     else if (strSetting.Equals("videoplayer.pauseafterrefreshchange"))
979     {
980       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
981       if (pControl) pControl->SetEnabled(g_guiSettings.GetInt("videoplayer.adjustrefreshrate") != ADJUST_REFRESHRATE_OFF);
982     }
983     else if (strSetting.Equals("videoplayer.synctype"))
984     {
985       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
986       if (pControl) pControl->SetEnabled(g_guiSettings.GetBool("videoplayer.usedisplayasclock"));
987     }
988     else if (strSetting.Equals("videoplayer.maxspeedadjust"))
989     {
990       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
991       if (pControl)
992       {
993         bool enabled = (g_guiSettings.GetBool("videoplayer.usedisplayasclock")) &&
994             (g_guiSettings.GetInt("videoplayer.synctype") == SYNC_RESAMPLE);
995         pControl->SetEnabled(enabled);
996       }
997     }
998     else if (strSetting.Equals("videoplayer.resamplequality"))
999     {
1000       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1001       if (pControl)
1002       {
1003         bool enabled = (g_guiSettings.GetBool("videoplayer.usedisplayasclock")) &&
1004             (g_guiSettings.GetInt("videoplayer.synctype") == SYNC_RESAMPLE);
1005         pControl->SetEnabled(enabled);
1006       }
1007     }
1008     else if (strSetting.Equals("weather.addonsettings"))
1009     {
1010       AddonPtr addon;
1011       if (CAddonMgr::Get().GetAddon(g_guiSettings.GetString("weather.addon"), addon, ADDON_SCRIPT_WEATHER))
1012       {
1013         CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1014         if (pControl)
1015           pControl->SetEnabled(addon->HasSettings());
1016       }
1017     }
1018     else if (strSetting.Equals("input.peripherals"))
1019     {
1020       CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1021       if (pControl)
1022         pControl->SetEnabled(g_peripherals.GetNumberOfPeripherals() > 0);
1023     }
1024   }
1025
1026   g_guiSettings.SetChanged();
1027   g_guiSettings.NotifyObservers(ObservableMessageGuiSettings);
1028 }
1029
1030 void CGUIWindowSettingsCategory::OnClick(CBaseSettingControl *pSettingControl)
1031 {
1032   CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
1033   if (strSetting.Equals("weather.addonsettings"))
1034   {
1035     CStdString name = g_guiSettings.GetString("weather.addon");
1036     AddonPtr addon;
1037     if (CAddonMgr::Get().GetAddon(name, addon, ADDON_SCRIPT_WEATHER))
1038     { // TODO: maybe have ShowAndGetInput return a bool if settings changed, then only reset weather if true.
1039       CGUIDialogAddonSettings::ShowAndGetInput(addon);
1040       g_weatherManager.Refresh();
1041     }
1042   }
1043   else if (strSetting.Equals("lookandfeel.rssedit"))
1044   {
1045     AddonPtr addon;
1046     CAddonMgr::Get().GetAddon("script.rss.editor",addon);
1047     if (!addon)
1048     {
1049       if (!CGUIDialogYesNo::ShowAndGetInput(g_localizeStrings.Get(24076), g_localizeStrings.Get(24100),"RSS Editor",g_localizeStrings.Get(24101)))
1050         return;
1051       CAddonInstaller::Get().Install("script.rss.editor", true, "", false);
1052     }
1053     CBuiltins::Execute("RunScript(script.rss.editor)");
1054   }
1055   else if (pSettingControl->GetSetting()->GetType() == SETTINGS_TYPE_ADDON)
1056   { // prompt for the addon
1057     CSettingAddon *setting = (CSettingAddon *)pSettingControl->GetSetting();
1058     CStdString addonID = setting->GetData();
1059     if (CGUIWindowAddonBrowser::SelectAddonID(setting->m_type, addonID, setting->m_type == ADDON_SCREENSAVER || setting->m_type == ADDON_VIZ || setting->m_type == ADDON_SCRIPT_WEATHER) == 1)
1060       setting->SetData(addonID);
1061     else
1062       return;
1063   }
1064   else if (strSetting.Equals("input.peripherals"))
1065   {
1066     CGUIDialogPeripheralManager *dialog = (CGUIDialogPeripheralManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_MANAGER);
1067     if (dialog)
1068       dialog->DoModal();
1069     return;
1070   }
1071
1072   // if OnClick() returns false, the setting hasn't changed or doesn't
1073   // require immediate update
1074   if (!pSettingControl->OnClick())
1075   {
1076     UpdateSettings();
1077     if (!pSettingControl->IsDelayed())
1078       return;
1079   }
1080
1081   if (pSettingControl->IsDelayed())
1082   { // delayed setting
1083     m_delayedSetting = pSettingControl;
1084     m_delayedTimer.StartZero();
1085   }
1086   else
1087     OnSettingChanged(pSettingControl);
1088 }
1089
1090 void CGUIWindowSettingsCategory::CheckForUpdates()
1091 {
1092   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
1093   {
1094     CBaseSettingControl *pSettingControl = m_vecSettings[i];
1095     if (pSettingControl->NeedsUpdate())
1096     {
1097       OnSettingChanged(pSettingControl);
1098       pSettingControl->Reset();
1099     }
1100   }
1101 }
1102
1103 void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingControl)
1104 {
1105   CStdString strSetting = pSettingControl->GetSetting()->GetSetting();
1106
1107   // ok, now check the various special things we need to do
1108   if (pSettingControl->GetSetting()->GetType() == SETTINGS_TYPE_ADDON)
1109   {
1110     CSettingAddon *pSettingAddon = (CSettingAddon*)pSettingControl->GetSetting();
1111     if (pSettingAddon->m_type == ADDON_SKIN)
1112     {
1113       g_application.ReloadSkin();
1114     }
1115     else if (pSettingAddon->m_type == ADDON_SCRIPT_WEATHER)
1116     {
1117       g_weatherManager.Refresh();
1118     }
1119   }
1120   else if (strSetting.Equals("musicplayer.visualisation"))
1121   { // new visualisation choosen...
1122     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1123     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1124     if (pControl->GetValue() == 0)
1125       pSettingString->SetData("None");
1126     else
1127       pSettingString->SetData(pControl->GetCurrentLabel());
1128   }
1129   else if (strSetting.Equals("debug.showloginfo"))
1130   {
1131     g_advancedSettings.SetDebugMode(g_guiSettings.GetBool("debug.showloginfo"));
1132   }
1133   /*else if (strSetting.Equals("musicfiles.repeat"))
1134   {
1135     g_playlistPlayer.SetRepeat(PLAYLIST_MUSIC_TEMP, g_guiSettings.GetBool("musicfiles.repeat") ? PLAYLIST::REPEAT_ALL : PLAYLIST::REPEAT_NONE);
1136   }*/
1137   else if (strSetting.Equals("musiclibrary.cleanup"))
1138   {
1139     CMusicDatabase musicdatabase;
1140     musicdatabase.Clean();
1141     CUtil::DeleteMusicDatabaseDirectoryCache();
1142   }
1143   else if (strSetting.Equals("videolibrary.cleanup"))
1144   {
1145     if (CGUIDialogYesNo::ShowAndGetInput(313, 333, 0, 0))
1146       g_application.StartVideoCleanup();
1147   }
1148   else if (strSetting.Equals("videolibrary.export"))
1149     CBuiltins::Execute("exportlibrary(video)");
1150   else if (strSetting.Equals("musiclibrary.export"))
1151     CBuiltins::Execute("exportlibrary(music)");
1152   else if (strSetting.Equals("karaoke.export") )
1153   {
1154     CContextButtons choices;
1155     choices.Add(1, g_localizeStrings.Get(22034));
1156     choices.Add(2, g_localizeStrings.Get(22035));
1157
1158     int retVal = CGUIDialogContextMenu::ShowAndGetChoice(choices);
1159     if ( retVal > 0 )
1160     {
1161       CStdString path(g_settings.GetDatabaseFolder());
1162       VECSOURCES shares;
1163       g_mediaManager.GetLocalDrives(shares);
1164       if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(661), path, true))
1165       {
1166         CMusicDatabase musicdatabase;
1167         musicdatabase.Open();
1168
1169         if ( retVal == 1 )
1170         {
1171           URIUtils::AddFileToFolder(path, "karaoke.html", path);
1172           musicdatabase.ExportKaraokeInfo( path, true );
1173         }
1174         else
1175         {
1176           URIUtils::AddFileToFolder(path, "karaoke.csv", path);
1177           musicdatabase.ExportKaraokeInfo( path, false );
1178         }
1179         musicdatabase.Close();
1180       }
1181     }
1182   }
1183   else if (strSetting.Equals("videolibrary.import"))
1184   {
1185     CStdString path;
1186     VECSOURCES shares;
1187     g_mediaManager.GetLocalDrives(shares);
1188     if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(651) , path))
1189     {
1190       CVideoDatabase videodatabase;
1191       videodatabase.Open();
1192       videodatabase.ImportFromXML(path);
1193       videodatabase.Close();
1194     }
1195   }
1196   else if (strSetting.Equals("musiclibrary.import"))
1197   {
1198     CStdString path;
1199     VECSOURCES shares;
1200     g_mediaManager.GetLocalDrives(shares);
1201     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, "musicdb.xml", g_localizeStrings.Get(651) , path))
1202     {
1203       CMusicDatabase musicdatabase;
1204       musicdatabase.Open();
1205       musicdatabase.ImportFromXML(path);
1206       musicdatabase.Close();
1207     }
1208   }
1209   else if (strSetting.Equals("karaoke.importcsv"))
1210   {
1211     CStdString path(g_settings.GetDatabaseFolder());
1212     VECSOURCES shares;
1213     g_mediaManager.GetLocalDrives(shares);
1214     if (CGUIDialogFileBrowser::ShowAndGetFile(shares, "karaoke.csv", g_localizeStrings.Get(651) , path))
1215     {
1216       CMusicDatabase musicdatabase;
1217       musicdatabase.Open();
1218       musicdatabase.ImportKaraokeInfo(path);
1219       musicdatabase.Close();
1220     }
1221   }
1222   else if (strSetting.Equals("scrobbler.lastfmsubmit") || strSetting.Equals("scrobbler.lastfmsubmitradio") || strSetting.Equals("scrobbler.lastfmusername") || strSetting.Equals("scrobbler.lastfmpass"))
1223   {
1224     CStdString strPassword=g_guiSettings.GetString("scrobbler.lastfmpass");
1225     CStdString strUserName=g_guiSettings.GetString("scrobbler.lastfmusername");
1226     if ((g_guiSettings.GetBool("scrobbler.lastfmsubmit") ||
1227          g_guiSettings.GetBool("scrobbler.lastfmsubmitradio")) &&
1228          !strUserName.IsEmpty() && !strPassword.IsEmpty())
1229     {
1230       CLastfmScrobbler::GetInstance()->Init();
1231     }
1232     else
1233     {
1234       CLastfmScrobbler::GetInstance()->Term();
1235     }
1236   }
1237   else if (strSetting.Equals("scrobbler.librefmsubmit") || strSetting.Equals("scrobbler.librefmsubmitradio") || strSetting.Equals("scrobbler.librefmusername") || strSetting.Equals("scrobbler.librefmpass"))
1238   {
1239     CStdString strPassword=g_guiSettings.GetString("scrobbler.librefmpass");
1240     CStdString strUserName=g_guiSettings.GetString("scrobbler.librefmusername");
1241     if ((g_guiSettings.GetBool("scrobbler.librefmsubmit") ||
1242          g_guiSettings.GetBool("scrobbler.librefmsubmitradio")) &&
1243          !strUserName.IsEmpty() && !strPassword.IsEmpty())
1244     {
1245       CLibrefmScrobbler::GetInstance()->Init();
1246     }
1247     else
1248     {
1249       CLibrefmScrobbler::GetInstance()->Term();
1250     }
1251   }
1252   else if (strSetting.Left(22).Equals("MusicPlayer.ReplayGain"))
1253   { // Update our replaygain settings
1254     g_guiSettings.m_replayGain.iType = g_guiSettings.GetInt("musicplayer.replaygaintype");
1255     g_guiSettings.m_replayGain.iPreAmp = g_guiSettings.GetInt("musicplayer.replaygainpreamp");
1256     g_guiSettings.m_replayGain.iNoGainPreAmp = g_guiSettings.GetInt("musicplayer.replaygainnogainpreamp");
1257     g_guiSettings.m_replayGain.bAvoidClipping = g_guiSettings.GetBool("musicplayer.replaygainavoidclipping");
1258   }
1259 #ifdef HAS_LCD
1260   else if (strSetting.Equals("videoscreen.haslcd"))
1261   {
1262     g_lcd->Stop();
1263     CLCDFactory factory;
1264     delete g_lcd;
1265     g_lcd = factory.Create();
1266     g_lcd->Initialize();
1267   }
1268 #endif
1269 #ifdef HAS_WEB_SERVER
1270   else if ( strSetting.Equals("services.webserver") || strSetting.Equals("services.webserverport"))
1271   {
1272     if (strSetting.Equals("services.webserverport"))
1273       ValidatePortNumber(pSettingControl, "8080", "80");
1274     g_application.StopWebServer();
1275     if (g_guiSettings.GetBool("services.webserver"))
1276       if (!g_application.StartWebServer())
1277       {
1278         CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33101), "", g_localizeStrings.Get(33100), "");
1279         g_guiSettings.SetBool("services.webserver", false);
1280       }
1281   }
1282   else if (strSetting.Equals("services.webserverusername") || strSetting.Equals("services.webserverpassword"))
1283   {
1284     g_application.m_WebServer.SetCredentials(g_guiSettings.GetString("services.webserverusername"), g_guiSettings.GetString("services.webserverpassword"));
1285   }
1286 #endif
1287   else if (strSetting.Equals("services.zeroconf"))
1288   {
1289 #ifdef HAS_ZEROCONF
1290     //ifdef zeroconf here because it's only found in guisettings if defined
1291     if(g_guiSettings.GetBool("services.zeroconf"))
1292     {
1293       CZeroconf::GetInstance()->Stop();
1294       CZeroconf::GetInstance()->Start();
1295     }
1296 #ifdef HAS_AIRPLAY
1297     else
1298     {
1299       g_application.StopAirplayServer(true);
1300       g_guiSettings.SetBool("services.airplay", false);
1301       CZeroconf::GetInstance()->Stop();
1302     }
1303 #endif
1304 #endif
1305   }
1306   else if (strSetting.Equals("services.airplay"))
1307   {
1308 #ifdef HAS_AIRPLAY
1309     if (g_guiSettings.GetBool("services.airplay"))
1310     {
1311 #ifdef HAS_ZEROCONF
1312       // AirPlay needs zeroconf
1313       if(!g_guiSettings.GetBool("services.zeroconf"))
1314       {
1315         g_guiSettings.SetBool("services.zeroconf", true);
1316         CZeroconf::GetInstance()->Stop();
1317         CZeroconf::GetInstance()->Start();
1318       }
1319 #endif //HAS_ZEROCONF
1320       g_application.StartAirplayServer();//will stop the server before internal
1321     }
1322     else
1323       g_application.StopAirplayServer(true);//will stop the server before internal
1324 #endif//HAS_AIRPLAY
1325   }
1326   else if (strSetting.Equals("network.ipaddress"))
1327   {
1328     if (g_guiSettings.GetInt("network.assignment") == NETWORK_STATIC)
1329     {
1330       CStdString strDefault = g_guiSettings.GetString("network.ipaddress").Left(g_guiSettings.GetString("network.ipaddress").ReverseFind('.'))+".1";
1331       if (g_guiSettings.GetString("network.gateway").Equals("0.0.0.0"))
1332         g_guiSettings.SetString("network.gateway",strDefault);
1333       if (g_guiSettings.GetString("network.dns").Equals("0.0.0.0"))
1334         g_guiSettings.SetString("network.dns",strDefault);
1335
1336     }
1337   }
1338
1339   else if (strSetting.Equals("network.httpproxyport"))
1340   {
1341     ValidatePortNumber(pSettingControl, "8080", "8080", false);
1342   }
1343   else if (strSetting.Equals("videoplayer.calibrate") || strSetting.Equals("videoscreen.guicalibration"))
1344   { // activate the video calibration screen
1345     g_windowManager.ActivateWindow(WINDOW_SCREEN_CALIBRATION);
1346   }
1347   else if (strSetting.Equals("videoscreen.testpattern"))
1348   { // activate the test pattern
1349     g_windowManager.ActivateWindow(WINDOW_TEST_PATTERN);
1350   }
1351   else if (strSetting.Equals("subtitles.height"))
1352   {
1353     if (!CUtil::IsUsingTTFSubtitles())
1354     {
1355       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1356       ((CSettingInt *)pSettingControl->GetSetting())->FromString(pControl->GetCurrentLabel());
1357     }
1358   }
1359   else if (strSetting.Equals("subtitles.font"))
1360   {
1361     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1362     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1363     pSettingString->SetData(pControl->GetCurrentLabel());
1364     CSetting *pSetting = (CSetting *)g_guiSettings.GetSetting("subtitles.height");
1365     FillInSubtitleHeights(pSetting, (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID()));
1366   }
1367   else if (strSetting.Equals("subtitles.charset"))
1368   {
1369     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1370     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1371     CStdString newCharset="DEFAULT";
1372     if (pControl->GetValue()!=0)
1373      newCharset = g_charsetConverter.getCharsetNameByLabel(pControl->GetCurrentLabel());
1374     if (newCharset != "" && (newCharset != pSettingString->GetData() || newCharset=="DEFAULT"))
1375     {
1376       pSettingString->SetData(newCharset);
1377       g_charsetConverter.reset();
1378     }
1379   }
1380   else if (strSetting.Equals("karaoke.fontheight"))
1381   {
1382     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1383     ((CSettingInt *)pSettingControl->GetSetting())->FromString(pControl->GetCurrentLabel());
1384   }
1385   else if (strSetting.Equals("karaoke.font"))
1386   {
1387     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1388     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1389     pSettingString->SetData(pControl->GetCurrentLabel());
1390     CSetting *pSetting = (CSetting *)g_guiSettings.GetSetting("karaoke.fontheight");
1391     FillInSubtitleHeights(pSetting, (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID()));
1392   }
1393   else if (strSetting.Equals("karaoke.charset"))
1394   {
1395     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1396     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1397     CStdString newCharset="DEFAULT";
1398     if (pControl->GetValue()!=0)
1399       newCharset = g_charsetConverter.getCharsetNameByLabel(pControl->GetCurrentLabel());
1400     if (newCharset != "" && (newCharset != pSettingString->GetData() || newCharset=="DEFAULT"))
1401     {
1402       pSettingString->SetData(newCharset);
1403       g_charsetConverter.reset();
1404     }
1405   }
1406   else if (strSetting.Equals("locale.charset"))
1407   {
1408     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1409     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1410     CStdString newCharset="DEFAULT";
1411     if (pControl->GetValue()!=0)
1412      newCharset = g_charsetConverter.getCharsetNameByLabel(pControl->GetCurrentLabel());
1413     if (newCharset != "" && (newCharset != pSettingString->GetData() || newCharset=="DEFAULT"))
1414     {
1415       pSettingString->SetData(newCharset);
1416       g_charsetConverter.reset();
1417     }
1418   }
1419   else if (strSetting.Equals("lookandfeel.font"))
1420   { // new font choosen...
1421     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1422     CStdString strSkinFontSet = m_SkinFontSetIDs[pControl->GetCurrentLabel()];
1423     if (strSkinFontSet != ".svn" && strSkinFontSet != g_guiSettings.GetString("lookandfeel.font"))
1424     {
1425       g_guiSettings.SetString("lookandfeel.font", strSkinFontSet);
1426       g_application.ReloadSkin();
1427     }
1428   }
1429   else if (strSetting.Equals("lookandfeel.soundskin"))
1430   { // new sound skin choosen...
1431     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1432     if (pControl->GetValue()==0)
1433       g_guiSettings.SetString("lookandfeel.soundskin", "OFF");
1434     else if (pControl->GetValue()==1)
1435       g_guiSettings.SetString("lookandfeel.soundskin", "SKINDEFAULT");
1436     else
1437       g_guiSettings.SetString("lookandfeel.soundskin", pControl->GetCurrentLabel());
1438
1439     g_audioManager.Enable(true);
1440     g_audioManager.Load();
1441   }
1442   else if (strSetting.Equals("lookandfeel.skinsettings"))
1443   {
1444     g_windowManager.ActivateWindow(WINDOW_SKIN_SETTINGS);
1445   }
1446   else if (strSetting.Equals("input.enablemouse"))
1447   {
1448     g_Mouse.SetEnabled(g_guiSettings.GetBool("input.enablemouse"));
1449   }
1450   else if (strSetting.Equals("input.enablejoystick") || strSetting.Equals("input.disablejoystickwithimon"))
1451   {
1452 #if defined(HAS_SDL_JOYSTICK)
1453     g_Joystick.SetEnabled(g_guiSettings.GetBool("input.enablejoystick")  
1454         && (CPeripheralImon::GetCountOfImonsConflictWithDInput() == 0 || !g_guiSettings.GetBool("input.disablejoystickwithimon")) );
1455 #endif
1456   }
1457   else if (strSetting.Equals("videoscreen.screen"))
1458   {
1459     DisplayMode mode = g_guiSettings.GetInt("videoscreen.screen");
1460     // Cascade
1461     FillInResolutions("videoscreen.resolution", mode, RES_DESKTOP, true);
1462   }
1463   else if (strSetting.Equals("videoscreen.resolution"))
1464   {
1465     RESOLUTION nextRes = (RESOLUTION) g_guiSettings.GetInt("videoscreen.resolution");
1466     // Cascade
1467     FillInRefreshRates("videoscreen.screenmode", nextRes, true);
1468   }
1469   else if (strSetting.Equals("videoscreen.screenmode"))
1470   {
1471     int iControlID = pSettingControl->GetID();
1472     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1473     g_windowManager.SendMessage(msg);
1474     RESOLUTION nextRes = (RESOLUTION)msg.GetParam1();
1475
1476     OnRefreshRateChanged(nextRes);
1477   }
1478   else if (strSetting.Equals("videoscreen.vsync"))
1479   {
1480     int iControlID = pSettingControl->GetID();
1481     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1482     g_windowManager.SendMessage(msg);
1483 // DXMERGE: This may be useful
1484 //    g_videoConfig.SetVSyncMode((VSYNC)msg.GetParam1());
1485   }
1486   else if (strSetting.Equals("videoscreen.fakefullscreen"))
1487   {
1488     if (g_graphicsContext.IsFullScreenRoot())
1489       g_graphicsContext.SetVideoResolution(g_graphicsContext.GetVideoResolution(), true);
1490   }
1491   else if (strSetting.Equals("locale.audiolanguage"))
1492   { // new audio language chosen...
1493     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1494     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1495     int iLanguage = pControl->GetValue();
1496     if (iLanguage < 2)
1497     {
1498       if (iLanguage < 1)
1499         g_guiSettings.SetString(strSetting, "original");
1500       else
1501         g_guiSettings.SetString(strSetting, "default");
1502       g_langInfo.SetAudioLanguage("");
1503     }
1504     else
1505     {
1506       CStdString strLanguage = pControl->GetCurrentLabel();
1507       if (strLanguage != pSettingString->GetData())
1508       {
1509         g_guiSettings.SetString(strSetting, strLanguage);
1510         g_langInfo.SetAudioLanguage(strLanguage);
1511       }
1512     }
1513   }
1514   else if (strSetting.Equals("locale.subtitlelanguage"))
1515   { // new subtitle language chosen...
1516     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1517     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1518     int iLanguage = pControl->GetValue();
1519     if (iLanguage < 2)
1520     {
1521       if (iLanguage < 1)
1522         g_guiSettings.SetString(strSetting, "original");
1523       else
1524         g_guiSettings.SetString(strSetting, "default");
1525       g_langInfo.SetSubtitleLanguage("");
1526     }
1527     else
1528     {
1529       CStdString strLanguage = pControl->GetCurrentLabel();
1530       if (strLanguage != pSettingString->GetData())
1531       {
1532         g_guiSettings.SetString(strSetting, strLanguage);
1533         g_langInfo.SetSubtitleLanguage(strLanguage);
1534       }
1535     }
1536   }
1537   else if (strSetting.Equals("locale.language"))
1538   { // new language chosen...
1539     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1540     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1541     CStdString strLanguage = pControl->GetCurrentLabel();
1542     if (strLanguage != ".svn" && strLanguage != pSettingString->GetData())
1543       g_guiSettings.SetLanguage(strLanguage);
1544   }
1545   else if (strSetting.Equals("lookandfeel.skintheme"))
1546   { //a new Theme was chosen
1547     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1548     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1549
1550     CStdString strSkinTheme;
1551
1552     if (pControl->GetValue() == 0) // Use default theme
1553       strSkinTheme = "SKINDEFAULT";
1554     else
1555       strSkinTheme = pControl->GetCurrentLabel();
1556
1557     if (strSkinTheme != pSettingString->GetData())
1558     {
1559       g_guiSettings.SetString("lookandfeel.skintheme", strSkinTheme);
1560       // also set the default color theme
1561       CStdString colorTheme(URIUtils::ReplaceExtension(strSkinTheme, ".xml"));
1562       if (colorTheme.Equals("Textures.xml"))
1563         colorTheme = "defaults.xml";
1564       g_guiSettings.SetString("lookandfeel.skincolors", colorTheme);
1565       g_application.ReloadSkin();
1566     }
1567   }
1568   else if (strSetting.Equals("lookandfeel.skincolors"))
1569   { //a new color was chosen
1570     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1571     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1572
1573     CStdString strSkinColor;
1574
1575     if (pControl->GetValue() == 0) // Use default colors
1576       strSkinColor = "SKINDEFAULT";
1577     else
1578       strSkinColor = pControl->GetCurrentLabel() + ".xml";
1579
1580     if (strSkinColor != pSettingString->GetData())
1581     {
1582       g_guiSettings.SetString("lookandfeel.skincolors", strSkinColor);
1583       g_application.ReloadSkin();
1584     }
1585   }
1586   else if (strSetting.Equals("videoplayer.displayresolution"))
1587   {
1588     CSettingInt *pSettingInt = (CSettingInt *)pSettingControl->GetSetting();
1589     int iControlID = pSettingControl->GetID();
1590     CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControlID);
1591     g_windowManager.SendMessage(msg);
1592     pSettingInt->SetData(msg.GetParam1());
1593   }
1594   else if (strSetting.Equals("videoscreen.flickerfilter") || strSetting.Equals("videoscreen.soften"))
1595   { // reset display
1596     g_graphicsContext.SetVideoResolution(g_guiSettings.m_LookAndFeelResolution);
1597   }
1598   else if (strSetting.Equals("screensaver.preview"))
1599   {
1600     g_application.ActivateScreenSaver(true);
1601   }
1602   else if (strSetting.Equals("screensaver.settings"))
1603   {
1604     AddonPtr addon;
1605     if (CAddonMgr::Get().GetAddon(g_guiSettings.GetString("screensaver.mode"), addon, ADDON_SCREENSAVER))
1606       CGUIDialogAddonSettings::ShowAndGetInput(addon);
1607   }
1608   else if (strSetting.Equals("debug.screenshotpath") || strSetting.Equals("audiocds.recordingpath") || strSetting.Equals("subtitles.custompath") || strSetting.Equals("pvrmenu.iconpath"))
1609   {
1610     CSettingString *pSettingString = (CSettingString *)pSettingControl->GetSetting();
1611     CStdString path = g_guiSettings.GetString(strSetting,false);
1612     VECSOURCES shares;
1613
1614     bool bWriteOnly = true;
1615
1616     if (strSetting.Equals("pvrmenu.iconpath"))
1617     {
1618       bWriteOnly = false;
1619     }
1620     else if (strSetting.Equals("subtitles.custompath"))
1621     {
1622       bWriteOnly = false;
1623       shares = g_settings.m_videoSources;
1624     }
1625
1626     g_mediaManager.GetNetworkLocations(shares);
1627     g_mediaManager.GetLocalDrives(shares);
1628
1629     UpdateSettings();
1630
1631     if (CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(pSettingString->m_iHeadingString), path, bWriteOnly))
1632     {
1633       pSettingString->SetData(path);
1634     }
1635   }
1636   else if (strSetting.Left(22).Equals("MusicPlayer.ReplayGain"))
1637   { // Update our replaygain settings
1638     g_guiSettings.m_replayGain.iType = g_guiSettings.GetInt("musicplayer.replaygaintype");
1639     g_guiSettings.m_replayGain.iPreAmp = g_guiSettings.GetInt("musicplayer.replaygainpreamp");
1640     g_guiSettings.m_replayGain.iNoGainPreAmp = g_guiSettings.GetInt("musicplayer.replaygainnogainpreamp");
1641     g_guiSettings.m_replayGain.bAvoidClipping = g_guiSettings.GetBool("musicplayer.replaygainavoidclipping");
1642   }
1643   else if (strSetting.Equals("locale.country"))
1644   {
1645     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1646
1647     const CStdString& strRegion=pControl->GetCurrentLabel();
1648     g_langInfo.SetCurrentRegion(strRegion);
1649     g_guiSettings.SetString("locale.country", strRegion);
1650     g_weatherManager.Refresh(); // need to reset our weather, as temperatures need re-translating.
1651   }
1652 #ifdef HAS_TIME_SERVER
1653   else if (strSetting.Equals("locale.timeserver") || strSetting.Equals("locale.timeserveraddress"))
1654   {
1655     g_application.StopTimeServer();
1656     if (g_guiSettings.GetBool("locale.timeserver"))
1657       g_application.StartTimeServer();
1658   }
1659 #endif
1660   else if (strSetting.Equals("smb.winsserver") || strSetting.Equals("smb.workgroup") )
1661   {
1662     if (g_guiSettings.GetString("smb.winsserver") == "0.0.0.0")
1663       g_guiSettings.SetString("smb.winsserver", "");
1664
1665     /* okey we really don't need to restarat, only deinit samba, but that could be damn hard if something is playing*/
1666     //TODO - General way of handling setting changes that require restart
1667
1668     if (CGUIDialogYesNo::ShowAndGetInput(14038, 14039, 14040, -1, -1))
1669     {
1670       g_settings.Save();
1671       CApplicationMessenger::Get().RestartApp();
1672     }
1673   }
1674   else if (strSetting.Equals("services.upnpserver"))
1675   {
1676 #ifdef HAS_UPNP
1677     if (g_guiSettings.GetBool("services.upnpserver"))
1678       g_application.StartUPnPServer();
1679     else
1680       g_application.StopUPnPServer();
1681 #endif
1682   }
1683   else if (strSetting.Equals("services.upnprenderer"))
1684   {
1685 #ifdef HAS_UPNP
1686     if (g_guiSettings.GetBool("services.upnprenderer"))
1687       g_application.StartUPnPRenderer();
1688     else
1689       g_application.StopUPnPRenderer();
1690 #endif
1691   }
1692   else if (strSetting.Equals("services.esenabled"))
1693   {
1694 #ifdef HAS_EVENT_SERVER
1695     if (g_guiSettings.GetBool("services.esenabled"))
1696     {
1697       if (!g_application.StartEventServer())
1698       {
1699         CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33102), "", g_localizeStrings.Get(33100), "");
1700         g_guiSettings.SetBool("services.esenabled", false);
1701         CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1702         if (pControl) pControl->SetEnabled(false);
1703       }
1704     }
1705     else
1706     {
1707       if (!g_application.StopEventServer(true, true))
1708       {
1709         g_guiSettings.SetBool("services.esenabled", true);
1710         CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1711         if (pControl) pControl->SetEnabled(true);
1712       }
1713     }
1714 #endif
1715 #ifdef HAS_JSONRPC
1716     if (g_guiSettings.GetBool("services.esenabled"))
1717     {
1718       if (!g_application.StartJSONRPCServer())
1719         CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33103), "", g_localizeStrings.Get(33100), "");
1720     }
1721     else
1722       g_application.StopJSONRPCServer(false);
1723 #endif
1724   }
1725   else if (strSetting.Equals("services.esport"))
1726   {
1727 #ifdef HAS_EVENT_SERVER
1728     ValidatePortNumber(pSettingControl, "9777", "9777");
1729     //restart eventserver without asking user
1730     if (g_application.StopEventServer(true, false))
1731     {
1732       if (!g_application.StartEventServer())
1733         CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33102), "", g_localizeStrings.Get(33100), "");
1734     }
1735 #if defined(TARGET_DARWIN_OSX)
1736     //reconfigure XBMCHelper for port changes
1737     XBMCHelper::GetInstance().Configure();
1738 #endif
1739 #endif
1740   }
1741   else if (strSetting.Equals("services.esallinterfaces"))
1742   {
1743 #ifdef HAS_EVENT_SERVER
1744     if (g_guiSettings.GetBool("services.esenabled"))
1745     {
1746       if (g_application.StopEventServer(true, true))
1747       {
1748         if (!g_application.StartEventServer())
1749           CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33102), "", g_localizeStrings.Get(33100), "");
1750       }
1751       else
1752       {
1753         g_guiSettings.SetBool("services.esenabled", true);
1754         CGUIControl *pControl = (CGUIControl *)GetControl(pSettingControl->GetID());
1755         if (pControl) pControl->SetEnabled(true);
1756       }
1757     }
1758 #endif
1759 #ifdef HAS_JSONRPC
1760     if (g_guiSettings.GetBool("services.esenabled"))
1761     {
1762       if (!g_application.StartJSONRPCServer())
1763         CGUIDialogOK::ShowAndGetInput(g_localizeStrings.Get(33103), "", g_localizeStrings.Get(33100), "");
1764     }
1765     else
1766       g_application.StopJSONRPCServer(false);
1767 #endif
1768   }
1769   else if (strSetting.Equals("services.esinitialdelay") ||
1770            strSetting.Equals("services.escontinuousdelay"))
1771   {
1772 #ifdef HAS_EVENT_SERVER
1773     if (g_guiSettings.GetBool("services.esenabled"))
1774     {
1775       g_application.RefreshEventServer();
1776     }
1777 #endif
1778   }
1779   else if (strSetting.Equals("pvrmanager.enabled"))
1780   {
1781     if (g_guiSettings.GetBool("pvrmanager.enabled"))
1782       CApplicationMessenger::Get().ExecBuiltIn("XBMC.StartPVRManager", false);
1783     else
1784       CApplicationMessenger::Get().ExecBuiltIn("XBMC.StopPVRManager", false);
1785   }
1786   else if (strSetting.Equals("masterlock.lockcode"))
1787   {
1788     // Now Prompt User to enter the old and then the new MasterCode!
1789     if(g_passwordManager.SetMasterLockMode())
1790     {
1791       // We asked for the master password and saved the new one!
1792       // Nothing todo here
1793     }
1794   }
1795   else if (strSetting.Equals("network.interface"))
1796   {
1797      NetworkInterfaceChanged();
1798   }
1799 #ifdef HAS_LINUX_NETWORK
1800   else if (strSetting.Equals("network.save"))
1801   {
1802      NetworkAssignment iAssignment;
1803      CStdString sIPAddress;
1804      CStdString sNetworkMask;
1805      CStdString sDefaultGateway;
1806      CStdString sWirelessNetwork;
1807      CStdString sWirelessKey;
1808      CStdString sDns;
1809      EncMode iWirelessEnc;
1810      CStdString ifaceName;
1811
1812      CGUISpinControlEx *ifaceControl = (CGUISpinControlEx *)GetControl(GetSetting("network.interface")->GetID());
1813      ifaceName = ifaceControl->GetLabel();
1814      CNetworkInterface* iface = g_application.getNetwork().GetInterfaceByName(ifaceName);
1815
1816      // Update controls with information
1817      CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.assignment")->GetID());
1818      if (pControl1) iAssignment = (NetworkAssignment) pControl1->GetValue();
1819      CGUIButtonControl* pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.ipaddress")->GetID());
1820      if (pControl2) sIPAddress = pControl2->GetLabel2();
1821      pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.subnet")->GetID());
1822      if (pControl2) sNetworkMask = pControl2->GetLabel2();
1823      pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.gateway")->GetID());
1824      if (pControl2) sDefaultGateway = pControl2->GetLabel2();
1825      pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.dns")->GetID());
1826      if (pControl2) sDns = pControl2->GetLabel2();
1827      pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.enc")->GetID());
1828      if (pControl1) iWirelessEnc = (EncMode) pControl1->GetValue();
1829      pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.essid")->GetID());
1830      if (pControl2) sWirelessNetwork = pControl2->GetLabel2();
1831      pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.key")->GetID());
1832      if (pControl2) sWirelessKey = pControl2->GetLabel2();
1833
1834      CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
1835      pDlgProgress->SetLine(0, "");
1836      pDlgProgress->SetLine(1, g_localizeStrings.Get(784));
1837      pDlgProgress->SetLine(2, "");
1838      pDlgProgress->StartModal();
1839      pDlgProgress->Progress();
1840
1841      std::vector<CStdString> nameServers;
1842      nameServers.push_back(sDns);
1843      g_application.getNetwork().SetNameServers(nameServers);
1844      iface->SetSettings(iAssignment, sIPAddress, sNetworkMask, sDefaultGateway, sWirelessNetwork, sWirelessKey, iWirelessEnc);
1845
1846      pDlgProgress->Close();
1847
1848      if (iAssignment == NETWORK_DISABLED)
1849         CGUIDialogOK::ShowAndGetInput(0, 788, 0, 0);
1850      else if (iface->IsConnected())
1851         CGUIDialogOK::ShowAndGetInput(0, 785, 0, 0);
1852      else
1853         CGUIDialogOK::ShowAndGetInput(0, 786, 0, 0);
1854   }
1855   else if (strSetting.Equals("network.essid"))
1856   {
1857     CGUIDialogAccessPoints *dialog = (CGUIDialogAccessPoints *)g_windowManager.GetWindow(WINDOW_DIALOG_ACCESS_POINTS);
1858     if (dialog)
1859     {
1860        CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting("network.interface")->GetID());
1861        dialog->SetInterfaceName(pControl->GetLabel());
1862        dialog->DoModal();
1863
1864        if (dialog->WasItemSelected())
1865        {
1866           CGUIButtonControl* pControl2 = (CGUIButtonControl *)GetControl(GetSetting("network.essid")->GetID());
1867           if (pControl2) pControl2->SetLabel2(dialog->GetSelectedAccessPointEssId());
1868           pControl = (CGUISpinControlEx *)GetControl(GetSetting("network.enc")->GetID());
1869           if (pControl) pControl->SetValue(dialog->GetSelectedAccessPointEncMode());
1870        }
1871     }
1872   }
1873 #endif
1874 #ifdef _LINUX
1875   else if (strSetting.Equals("locale.timezonecountry"))
1876   {
1877     CGUISpinControlEx *pControlCountry = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1878     CStdString country = pControlCountry->GetCurrentLabel();
1879
1880     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezone")->GetID());
1881     pControl->Clear();
1882     vector<CStdString> timezones = g_timezone.GetTimezonesByCountry(country);
1883     for (unsigned int i=0; i < timezones.size(); i++)
1884     {
1885       pControl->AddLabel(timezones[i], i);
1886     }
1887
1888     g_timezone.SetTimezone(pControl->GetLabel());
1889     g_guiSettings.SetString("locale.timezonecountry",pControlCountry->GetLabel().c_str());
1890
1891     CGUISpinControlEx *tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezone")->GetID());
1892     g_guiSettings.SetString("locale.timezone", tzControl->GetLabel().c_str());
1893
1894     CDateTime::ResetTimezoneBias();
1895   }
1896   else  if (strSetting.Equals("locale.timezone"))
1897   {
1898      CGUISpinControlEx *tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezone")->GetID());
1899      g_timezone.SetTimezone(tzControl->GetLabel());
1900      g_guiSettings.SetString("locale.timezone", tzControl->GetLabel().c_str());
1901
1902      tzControl = (CGUISpinControlEx *)GetControl(GetSetting("locale.timezonecountry")->GetID());
1903      g_guiSettings.SetString("locale.timezonecountry", tzControl->GetLabel().c_str());
1904
1905      CDateTime::ResetTimezoneBias();
1906   }
1907 #endif
1908   else if (strSetting.Equals("lookandfeel.skinzoom"))
1909   {
1910     g_windowManager.SendMessage(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_WINDOW_RESIZE);
1911   }
1912   else if (strSetting.Equals("videolibrary.flattentvshows") ||
1913            strSetting.Equals("videolibrary.removeduplicates") ||
1914            strSetting.Equals("videolibrary.groupmoviesets"))
1915   {
1916     CUtil::DeleteVideoDatabaseDirectoryCache();
1917   }
1918   else if (strSetting.Equals("pvrmenu.searchicons") && g_PVRManager.IsStarted())
1919   {
1920     g_PVRManager.SearchMissingChannelIcons();
1921   }
1922   else if (strSetting.Equals("pvrmanager.resetdb"))
1923   {
1924     if (g_PVRManager.CheckParentalPIN(g_localizeStrings.Get(19262).c_str()) &&
1925         CGUIDialogYesNo::ShowAndGetInput(19098, 19186, 750, 0))
1926     {
1927       CDateTime::ResetTimezoneBias();
1928       g_PVRManager.ResetDatabase();
1929     }
1930   }
1931   else if (strSetting.Equals("epg.resetepg"))
1932   {
1933     if (CGUIDialogYesNo::ShowAndGetInput(19098, 19188, 750, 0))
1934     {
1935       CDateTime::ResetTimezoneBias();
1936       g_PVRManager.ResetEPG();
1937     }
1938   }
1939   else if (strSetting.Equals("pvrmanager.channelscan") && g_PVRManager.IsStarted())
1940   {
1941     if (CGUIDialogYesNo::ShowAndGetInput(19098, 19118, 19194, 0))
1942       g_PVRManager.StartChannelScan();
1943   }
1944   else if (strSetting.Equals("pvrmanager.channelmanager") && g_PVRManager.IsStarted())
1945   {
1946     CGUIDialogPVRChannelManager *dialog = (CGUIDialogPVRChannelManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_CHANNEL_MANAGER);
1947     if (dialog)
1948     {
1949        dialog->DoModal();
1950     }
1951   }
1952   else if (strSetting.compare(0, 12, "audiooutput.") == 0)
1953   {
1954     if (strSetting.Equals("audiooutput.audiodevice"))
1955     {
1956       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1957 #if defined(TARGET_DARWIN)
1958       g_guiSettings.SetString("audiooutput.audiodevice", pControl->GetCurrentLabel());
1959 #else
1960       g_guiSettings.SetString("audiooutput.audiodevice", m_AnalogAudioSinkMap[pControl->GetCurrentLabel()]);
1961 #endif
1962     }
1963 #if !defined(TARGET_DARWIN)
1964     else if (strSetting.Equals("audiooutput.passthroughdevice"))
1965     {
1966       CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(pSettingControl->GetID());
1967       g_guiSettings.SetString("audiooutput.passthroughdevice", m_DigitalAudioSinkMap[pControl->GetCurrentLabel()]);
1968     }
1969 #endif
1970     else if (strSetting.Equals("audiooutput.guisoundmode"))
1971     {
1972       CAEFactory::SetSoundMode(g_guiSettings.GetInt("audiooutput.guisoundmode"));
1973     }
1974
1975     CAEFactory::OnSettingsChange(strSetting);
1976   }
1977   else if (strSetting.Equals("pvrparental.enabled"))
1978   {
1979     if (g_guiSettings.GetBool("pvrparental.enabled") && g_guiSettings.GetString("pvrparental.pin").GetLength() == 0)
1980     {
1981       CStdString newPassword = "";
1982       bool bNewPassword = CGUIDialogNumeric::ShowAndVerifyNewPassword(newPassword);
1983       if (bNewPassword)
1984       {
1985         // password set... save it
1986         g_guiSettings.SetString("pvrparental.pin", newPassword);
1987       }
1988       else
1989       {
1990         // password not set... disable parental
1991         g_guiSettings.SetBool("pvrparental.enabled", false);
1992       }
1993     }
1994   }
1995
1996   UpdateSettings();
1997 }
1998
1999 void CGUIWindowSettingsCategory::FreeControls()
2000 {
2001   // clear the category group
2002   CGUIControlGroupList *control = (CGUIControlGroupList *)GetControl(CATEGORY_GROUP_ID);
2003   if (control)
2004   {
2005     control->FreeResources();
2006     control->ClearAll();
2007   }
2008   m_vecSections.clear();
2009   FreeSettingsControls();
2010 }
2011
2012 void CGUIWindowSettingsCategory::FreeSettingsControls()
2013 {
2014   // clear the settings group
2015   CGUIControlGroupList *control = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
2016   if (control)
2017   {
2018     control->FreeResources();
2019     control->ClearAll();
2020   }
2021
2022   for(int i = 0; (size_t)i < m_vecSettings.size(); i++)
2023   {
2024     delete m_vecSettings[i];
2025   }
2026   m_vecSettings.clear();
2027 }
2028
2029 CGUIControl* CGUIWindowSettingsCategory::AddSetting(CSetting *pSetting, float width, int &iControlID)
2030 {
2031   if (!pSetting->IsVisible()) return NULL;  // not displayed in current session
2032   CBaseSettingControl *pSettingControl = NULL;
2033   CGUIControl *pControl = NULL;
2034   if (pSetting->GetControlType() == CHECKMARK_CONTROL)
2035   {
2036     pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
2037     if (!pControl) return NULL;
2038     ((CGUIRadioButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2039     pControl->SetWidth(width);
2040     pSettingControl = new CRadioButtonSettingControl((CGUIRadioButtonControl *)pControl, iControlID, pSetting);
2041   }
2042   else if (pSetting->GetControlType() == SPIN_CONTROL_FLOAT || pSetting->GetControlType() == SPIN_CONTROL_INT_PLUS || pSetting->GetControlType() == SPIN_CONTROL_TEXT || pSetting->GetControlType() == SPIN_CONTROL_INT)
2043   {
2044     pControl = new CGUISpinControlEx(*m_pOriginalSpin);
2045     if (!pControl) return NULL;
2046     pControl->SetWidth(width);
2047     ((CGUISpinControlEx *)pControl)->SetText(g_localizeStrings.Get(pSetting->GetLabel()));
2048     pSettingControl = new CSpinExSettingControl((CGUISpinControlEx *)pControl, iControlID, pSetting);
2049   }
2050   else if (pSetting->GetControlType() == SEPARATOR_CONTROL && m_pOriginalImage)
2051   {
2052     pControl = new CGUIImage(*m_pOriginalImage);
2053     if (!pControl) return NULL;
2054     pControl->SetWidth(width);
2055     pSettingControl = new CSeparatorSettingControl((CGUIImage *)pControl, iControlID, pSetting);
2056   }
2057   else if (pSetting->GetControlType() == EDIT_CONTROL_INPUT ||
2058            pSetting->GetControlType() == EDIT_CONTROL_HIDDEN_INPUT ||
2059            pSetting->GetControlType() == EDIT_CONTROL_MD5_INPUT ||
2060            pSetting->GetControlType() == EDIT_CONTROL_NUMBER_INPUT ||
2061            pSetting->GetControlType() == EDIT_CONTROL_IP_INPUT ||
2062            pSetting->GetControlType() == EDIT_CONTROL_HIDDEN_NUMBER_VERIFY_NEW )
2063   {
2064     pControl = new CGUIEditControl(*m_pOriginalEdit);
2065     if (!pControl) return NULL;
2066     ((CGUIEditControl *)pControl)->SettingsCategorySetTextAlign(XBFONT_CENTER_Y);
2067     ((CGUIEditControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2068     pControl->SetWidth(width);
2069     pSettingControl = new CEditSettingControl((CGUIEditControl *)pControl, iControlID, pSetting);
2070   }
2071   else if (pSetting->GetControlType() != SEPARATOR_CONTROL) // button control
2072   {
2073     pControl = new CGUIButtonControl(*m_pOriginalButton);
2074     if (!pControl) return NULL;
2075     ((CGUIButtonControl *)pControl)->SettingsCategorySetTextAlign(XBFONT_CENTER_Y);
2076     ((CGUIButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
2077     pControl->SetWidth(width);
2078     pSettingControl = new CButtonSettingControl((CGUIButtonControl *)pControl, iControlID, pSetting);
2079   }
2080   if (!pControl)
2081   {
2082     delete pSettingControl;
2083     return NULL;
2084   }
2085   pControl->SetID(iControlID++);
2086   pControl->SetVisible(true);
2087   CGUIControlGroupList *group = (CGUIControlGroupList *)GetControl(SETTINGS_GROUP_ID);
2088   if (group)
2089   {
2090     pControl->AllocResources();
2091     group->AddControl(pControl);
2092   }
2093   m_vecSettings.push_back(pSettingControl);
2094   return pControl;
2095 }
2096
2097 void CGUIWindowSettingsCategory::FrameMove()
2098 {
2099   if (m_delayedSetting && m_delayedTimer.GetElapsedMilliseconds() > 3000)
2100   { // we send a thread message so that it's processed the following frame (some settings won't
2101     // like being changed during Render())
2102     CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), GetID());
2103     g_windowManager.SendThreadMessage(message, GetID());
2104     m_delayedTimer.Stop();
2105   }
2106   CGUIWindow::FrameMove();
2107 }
2108
2109 void CGUIWindowSettingsCategory::DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions)
2110 {
2111   // update alpha status of current button
2112   bool bAlphaFaded = false;
2113   CGUIControl *control = GetFirstFocusableControl(CONTROL_START_BUTTONS + m_iSection);
2114   if (control && !control->HasFocus())
2115   {
2116     if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
2117     {
2118       control->SetFocus(true);
2119       ((CGUIButtonControl *)control)->SetAlpha(0x80);
2120       bAlphaFaded = true;
2121     }
2122     else if (control->GetControlType() == CGUIControl::GUICONTROL_TOGGLEBUTTON)
2123     {
2124       control->SetFocus(true);
2125       ((CGUIButtonControl *)control)->SetSelected(true);
2126       bAlphaFaded = true;
2127     }
2128   }
2129   CGUIWindow::DoProcess(currentTime, dirtyregions);
2130   if (bAlphaFaded)
2131   {
2132     control->SetFocus(false);
2133     if (control->GetControlType() == CGUIControl::GUICONTROL_BUTTON)
2134       ((CGUIButtonControl *)control)->SetAlpha(0xFF);
2135     else
2136       ((CGUIButtonControl *)control)->SetSelected(false);
2137   }
2138 }
2139
2140 void CGUIWindowSettingsCategory::Render()
2141 {
2142   CGUIWindow::Render();
2143 }
2144
2145 void CGUIWindowSettingsCategory::FillInSubtitleHeights(CSetting *pSetting, CGUISpinControlEx *pControl)
2146 {
2147   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2148   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2149   pControl->Clear();
2150   if (CUtil::IsUsingTTFSubtitles())
2151   { // easy - just fill as per usual
2152     CStdString strLabel;
2153     for (int i = pSettingInt->m_iMin; i <= pSettingInt->m_iMax; i += pSettingInt->m_iStep)
2154     {
2155       if (pSettingInt->m_iFormat > -1)
2156       {
2157         CStdString strFormat = g_localizeStrings.Get(pSettingInt->m_iFormat);
2158         strLabel.Format(strFormat, i);
2159       }
2160       else
2161         strLabel.Format(pSettingInt->m_strFormat, i);
2162       pControl->AddLabel(strLabel, i);
2163     }
2164     pControl->SetValue(pSettingInt->GetData());
2165   }
2166 }
2167
2168 void CGUIWindowSettingsCategory::FillInSubtitleFonts(CSetting *pSetting)
2169 {
2170   CSettingString *pSettingString = (CSettingString*)pSetting;
2171   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2172   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2173   pControl->Clear();
2174   int iCurrentFont = 0;
2175   int iFont = 0;
2176
2177   // find TTF fonts
2178   {
2179     CFileItemList items;
2180     CFileItemList items2;
2181     CDirectory::GetDirectory("special://home/media/Fonts/", items2);
2182
2183     if (CDirectory::GetDirectory("special://xbmc/media/Fonts/", items))
2184     {
2185       items.Append(items2);
2186       for (int i = 0; i < items.Size(); ++i)
2187       {
2188         CFileItemPtr pItem = items[i];
2189
2190         if (!pItem->m_bIsFolder)
2191         {
2192
2193           if ( !URIUtils::GetExtension(pItem->GetLabel()).Equals(".ttf") ) continue;
2194           if (pItem->GetLabel().Equals(pSettingString->GetData(), false))
2195             iCurrentFont = iFont;
2196
2197           pControl->AddLabel(pItem->GetLabel(), iFont++);
2198         }
2199
2200       }
2201     }
2202   }
2203   pControl->SetValue(iCurrentFont);
2204 }
2205
2206 void CGUIWindowSettingsCategory::FillInSkinFonts(CSetting *pSetting)
2207 {
2208   CBaseSettingControl *setting = GetSetting(pSetting->GetSetting());
2209   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(setting->GetID());
2210   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2211   pControl->Clear();
2212   setting->SetDelayed();
2213
2214   m_SkinFontSetIDs.clear();
2215   int iSkinFontSet = 0;
2216
2217   CStdString strPath = g_SkinInfo->GetSkinPath("Font.xml");
2218
2219   CXBMCTinyXML xmlDoc;
2220   if (!xmlDoc.LoadFile(strPath))
2221   {
2222     CLog::Log(LOGERROR, "Couldn't load %s", strPath.c_str());
2223     return ;
2224   }
2225
2226   TiXmlElement* pRootElement = xmlDoc.RootElement();
2227
2228   CStdString strValue = pRootElement->Value();
2229   if (strValue != CStdString("fonts"))
2230   {
2231     CLog::Log(LOGERROR, "file %s doesnt start with <fonts>", strPath.c_str());
2232     return ;
2233   }
2234
2235   const TiXmlNode *pChild = pRootElement->FirstChild();
2236   strValue = pChild->Value();
2237   if (strValue == "fontset")
2238   {
2239     while (pChild)
2240     {
2241       strValue = pChild->Value();
2242       if (strValue == "fontset")
2243       {
2244         const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id");
2245         const char* idLocAttr = ((TiXmlElement*) pChild)->Attribute("idloc");
2246         const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode");
2247
2248         bool isUnicode=(unicodeAttr && stricmp(unicodeAttr, "true") == 0);
2249
2250         bool isAllowed=true;
2251         if (g_langInfo.ForceUnicodeFont() && !isUnicode)
2252           isAllowed=false;
2253
2254         if (idAttr != NULL && isAllowed)
2255         {
2256           if (idLocAttr)
2257           {
2258             pControl->AddLabel(g_localizeStrings.Get(atoi(idLocAttr)), iSkinFontSet);
2259             m_SkinFontSetIDs[g_localizeStrings.Get(atoi(idLocAttr))] = idAttr;
2260           }
2261           else
2262           {
2263             pControl->AddLabel(idAttr, iSkinFontSet);
2264             m_SkinFontSetIDs[idAttr] = idAttr;
2265           }
2266           if (strcmpi(idAttr, g_guiSettings.GetString("lookandfeel.font").c_str()) == 0)
2267             pControl->SetValue(iSkinFontSet);
2268           iSkinFontSet++;
2269         }
2270       }
2271       pChild = pChild->NextSibling();
2272     }
2273
2274   }
2275   else
2276   {
2277     // Since no fontset is defined, there is no selection of a fontset, so disable the component
2278     pControl->AddLabel(g_localizeStrings.Get(13278), 1);
2279     pControl->SetValue(1);
2280     pControl->SetEnabled(false);
2281   }
2282 }
2283
2284 void CGUIWindowSettingsCategory::FillInSoundSkins(CSetting *pSetting)
2285 {
2286   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2287   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2288   pControl->Clear();
2289   pControl->SetShowRange(true);
2290
2291   //find skins...
2292   CFileItemList items;
2293   CDirectory::GetDirectory("special://xbmc/sounds/", items);
2294   CDirectory::GetDirectory("special://home/sounds/", items);
2295
2296   int iCurrentSoundSkin = 0;
2297   int iSoundSkin = 0;
2298   vector<CStdString> vecSoundSkins;
2299   int i;
2300   for (i = 0; i < items.Size(); ++i)
2301   {
2302     CFileItemPtr pItem = items[i];
2303     if (pItem->m_bIsFolder)
2304     {
2305       if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2306       if (strcmpi(pItem->GetLabel().c_str(), "fonts") == 0) continue;
2307       if (strcmpi(pItem->GetLabel().c_str(), "media") == 0) continue;
2308       vecSoundSkins.push_back(pItem->GetLabel());
2309     }
2310   }
2311
2312   pControl->AddLabel(g_localizeStrings.Get(474), iSoundSkin++); // Off
2313   pControl->AddLabel(g_localizeStrings.Get(15109), iSoundSkin++); // Skin Default
2314
2315   if (g_guiSettings.GetString("lookandfeel.soundskin")=="SKINDEFAULT")
2316     iCurrentSoundSkin=1;
2317
2318   sort(vecSoundSkins.begin(), vecSoundSkins.end(), sortstringbyname());
2319   for (i = 0; i < (int) vecSoundSkins.size(); ++i)
2320   {
2321     CStdString strSkin = vecSoundSkins[i];
2322     if (strcmpi(strSkin.c_str(), g_guiSettings.GetString("lookandfeel.soundskin").c_str()) == 0)
2323     {
2324       iCurrentSoundSkin = iSoundSkin;
2325     }
2326     pControl->AddLabel(strSkin, iSoundSkin++);
2327   }
2328   pControl->SetValue(iCurrentSoundSkin);
2329   return ;
2330 }
2331
2332 void CGUIWindowSettingsCategory::FillInCharSets(CSetting *pSetting)
2333 {
2334   CSettingString *pSettingString = (CSettingString*)pSetting;
2335   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2336   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2337   pControl->Clear();
2338   int iCurrentCharset = 0;
2339   vector<CStdString> vecCharsets = g_charsetConverter.getCharsetLabels();
2340
2341   CStdString strCurrentCharsetLabel="DEFAULT";
2342   if (pSettingString->GetData()!="DEFAULT")
2343     strCurrentCharsetLabel = g_charsetConverter.getCharsetLabelByName(pSettingString->GetData());
2344
2345   sort(vecCharsets.begin(), vecCharsets.end(), sortstringbyname());
2346
2347   vecCharsets.insert(vecCharsets.begin(), g_localizeStrings.Get(13278)); // "Default"
2348
2349   bool bIsAuto=(pSettingString->GetData()=="DEFAULT");
2350
2351   for (int i = 0; i < (int) vecCharsets.size(); ++i)
2352   {
2353     CStdString strCharsetLabel = vecCharsets[i];
2354
2355     if (!bIsAuto && strCharsetLabel == strCurrentCharsetLabel)
2356       iCurrentCharset = i;
2357
2358     pControl->AddLabel(strCharsetLabel, i);
2359   }
2360
2361   pControl->SetValue(iCurrentCharset);
2362 }
2363
2364 DisplayMode CGUIWindowSettingsCategory::FillInScreens(CStdString strSetting, RESOLUTION res)
2365 {
2366   DisplayMode mode;
2367   if (res == RES_WINDOW)
2368     mode = DM_WINDOWED;
2369   else
2370     mode = g_settings.m_ResInfo[res].iScreen;
2371
2372   // we expect "videoscreen.screen" but it might be hidden on some platforms,
2373   // so check that we actually have a visable control.
2374   CBaseSettingControl *control = GetSetting(strSetting);
2375   if (control)
2376   {
2377     control->SetDelayed();
2378     CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(control->GetID());
2379     pControl->Clear();
2380
2381     CStdString strScreen;
2382     if (g_advancedSettings.m_canWindowed)
2383       pControl->AddLabel(g_localizeStrings.Get(242), -1);
2384
2385     for (int idx = 0; idx < g_Windowing.GetNumScreens(); idx++)
2386     {
2387       strScreen.Format(g_localizeStrings.Get(241), g_settings.m_ResInfo[RES_DESKTOP + idx].iScreen + 1);
2388       pControl->AddLabel(strScreen, g_settings.m_ResInfo[RES_DESKTOP + idx].iScreen);
2389     }
2390     pControl->SetValue(mode);
2391     g_guiSettings.SetInt("videoscreen.screen", mode);
2392   }
2393
2394   return mode;
2395 }
2396
2397 void CGUIWindowSettingsCategory::FillInResolutions(CStdString strSetting, DisplayMode mode, RESOLUTION res, bool UserChange)
2398 {
2399   CBaseSettingControl *control = GetSetting(strSetting);
2400   control->SetDelayed();
2401   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(control->GetID());
2402
2403   pControl->Clear();
2404
2405   RESOLUTION spinres = RES_INVALID; // index of the resolution in the spinner that has same screen/width/height as res
2406
2407   if (mode == DM_WINDOWED)
2408   {
2409     pControl->AddLabel(g_localizeStrings.Get(242), RES_WINDOW);
2410     spinres = RES_WINDOW;
2411   }
2412   else
2413   {
2414     vector<RESOLUTION_WHR> resolutions = g_Windowing.ScreenResolutions(mode);
2415
2416     for (unsigned int idx = 0; idx < resolutions.size(); idx++)
2417     {
2418       CStdString strRes;
2419       strRes.Format("%dx%d%s", resolutions[idx].width, resolutions[idx].height,
2420         (resolutions[idx].interlaced == D3DPRESENTFLAG_INTERLACED) ? "i" : "p");
2421       pControl->AddLabel(strRes, resolutions[idx].ResInfo_Index);
2422
2423       RESOLUTION_INFO res1 = g_settings.m_ResInfo[res];
2424       RESOLUTION_INFO res2 = g_settings.m_ResInfo[resolutions[idx].ResInfo_Index];
2425       if (   res1.iScreen == res2.iScreen
2426           && res1.iScreenWidth  == res2.iScreenWidth
2427           && res1.iScreenHeight == res2.iScreenHeight
2428           && (res1.dwFlags & D3DPRESENTFLAG_INTERLACED) == (res2.dwFlags & D3DPRESENTFLAG_INTERLACED))
2429         spinres = (RESOLUTION) resolutions[idx].ResInfo_Index;
2430     }
2431   }
2432
2433   if (UserChange)
2434   {
2435     // Auto-select the windowed or desktop resolution of the screen
2436     int autoresolution = RES_DESKTOP;
2437     if (mode == DM_WINDOWED)
2438     {
2439       autoresolution = RES_WINDOW;
2440     }
2441     else
2442     {
2443       for (int idx=0; idx < g_Windowing.GetNumScreens(); idx++)
2444         if (g_settings.m_ResInfo[RES_DESKTOP + idx].iScreen == mode)
2445         {
2446           autoresolution = RES_DESKTOP + idx;
2447           break;
2448         }
2449     }
2450     pControl->SetValue(autoresolution);
2451
2452     // Cascade
2453     FillInRefreshRates("videoscreen.screenmode", (RESOLUTION) autoresolution, true);
2454   }
2455   else
2456   {
2457     // select the entry equivalent to the resolution passed by the res parameter
2458     pControl->SetValue(spinres);
2459   }
2460 }
2461
2462 void CGUIWindowSettingsCategory::FillInRefreshRates(CStdString strSetting, RESOLUTION res, bool UserChange)
2463 {
2464   // The only meaningful parts of res here are iScreen, iScreenWidth, iScreenHeight
2465
2466   vector<REFRESHRATE> refreshrates;
2467   if (res > RES_WINDOW)
2468     refreshrates = g_Windowing.RefreshRates(g_settings.m_ResInfo[res].iScreen,
2469       g_settings.m_ResInfo[res].iScreenWidth,
2470       g_settings.m_ResInfo[res].iScreenHeight,
2471       g_settings.m_ResInfo[res].dwFlags);
2472
2473   // The control setting doesn't exist when not in standalone mode, don't manipulate it
2474   CBaseSettingControl *control = GetSetting(strSetting);
2475   CGUISpinControlEx *pControl= NULL;
2476
2477   // Populate
2478   if (control)
2479   {
2480     control->SetDelayed();
2481     pControl = (CGUISpinControlEx *)GetControl(control->GetID());
2482     pControl->Clear();
2483
2484     if (res == RES_WINDOW)
2485     {
2486       pControl->AddLabel(g_localizeStrings.Get(242), RES_WINDOW);
2487     }
2488     else
2489     {
2490       for (unsigned int idx = 0; idx < refreshrates.size(); idx++)
2491       {
2492         CStdString strRR;
2493         strRR.Format("%.02f", refreshrates[idx].RefreshRate);
2494         pControl->AddLabel(strRR, refreshrates[idx].ResInfo_Index);
2495       }
2496     }
2497   }
2498
2499   // Select a rate
2500   if (UserChange)
2501   {
2502     RESOLUTION newresolution;
2503     if (res == RES_WINDOW)
2504       newresolution = RES_WINDOW;
2505     else
2506       newresolution = (RESOLUTION) g_Windowing.DefaultRefreshRate(g_settings.m_ResInfo[res].iScreen, refreshrates).ResInfo_Index;
2507
2508     if (pControl)
2509       pControl->SetValue(newresolution);
2510
2511     OnRefreshRateChanged(newresolution);
2512   }
2513   else
2514   {
2515     if (pControl)
2516       pControl->SetValue(res);
2517   }
2518 }
2519
2520 void CGUIWindowSettingsCategory::OnRefreshRateChanged(RESOLUTION nextRes)
2521 {
2522   RESOLUTION lastRes = g_graphicsContext.GetVideoResolution();
2523   bool cancelled = false;
2524
2525   g_guiSettings.SetResolution(nextRes);
2526   g_graphicsContext.SetVideoResolution(nextRes);
2527
2528   if (!CGUIDialogYesNo::ShowAndGetInput(13110, 13111, 20022, 20022, -1, -1, cancelled, 10000))
2529   {
2530     g_guiSettings.SetResolution(lastRes);
2531     g_graphicsContext.SetVideoResolution(lastRes);
2532
2533     DisplayMode mode = FillInScreens("videoscreen.screen", lastRes);
2534     FillInResolutions("videoscreen.resolution", mode, lastRes, false);
2535     FillInRefreshRates("videoscreen.screenmode", lastRes, false);
2536   }
2537 }
2538
2539 void CGUIWindowSettingsCategory::FillInLanguages(CSetting *pSetting, const std::vector<CStdString> &languages /* = std::vector<CStdString>() */, const std::vector<CStdString> &languageKeys /* = std::vector<CStdString>() */)
2540 {
2541   CSettingString *pSettingString = (CSettingString *)pSetting;
2542   CBaseSettingControl *setting = GetSetting(pSetting->GetSetting());
2543   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(setting->GetID());
2544   pControl->Clear();
2545
2546   //find languages...
2547   CFileItemList items;
2548   CDirectory::GetDirectory("special://xbmc/language/", items);
2549
2550   int iCurrentLang = 0;
2551   vector<CStdString> vecLanguage;
2552   for (int i = 0; i < items.Size(); ++i)
2553   {
2554     CFileItemPtr pItem = items[i];
2555     if (pItem->m_bIsFolder)
2556     {
2557       if (strcmpi(pItem->GetLabel().c_str(), ".svn") == 0) continue;
2558       if (strcmpi(pItem->GetLabel().c_str(), "fonts") == 0) continue;
2559       if (strcmpi(pItem->GetLabel().c_str(), "media") == 0) continue;
2560       vecLanguage.push_back(pItem->GetLabel());
2561     }
2562   }
2563
2564   sort(vecLanguage.begin(), vecLanguage.end(), sortstringbyname());
2565   // Add language options passed by parameter at the beginning
2566   if (languages.size() > 0)
2567     vecLanguage.insert(vecLanguage.begin(), languages.begin(), languages.begin() + languages.size());
2568   for (unsigned int i = 0; i < vecLanguage.size(); ++i)
2569   {
2570     CStdString strLanguage = vecLanguage[i];
2571     if ((i < languageKeys.size() && strcmpi(languageKeys[i].c_str(), pSettingString->GetData().c_str()) == 0) ||
2572         strcmpi(strLanguage.c_str(), pSettingString->GetData().c_str()) == 0)
2573       iCurrentLang = i;
2574     pControl->AddLabel(strLanguage, i);
2575   }
2576
2577   pControl->SetValue(iCurrentLang);
2578 }
2579
2580 void CGUIWindowSettingsCategory::FillInRegions(CSetting *pSetting)
2581 {
2582   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2583   pControl->SetType(SPIN_CONTROL_TYPE_TEXT);
2584   pControl->Clear();
2585
2586   int iCurrentRegion=0;
2587   CStdStringArray regions;
2588   g_langInfo.GetRegionNames(regions);
2589
2590   CStdString strCurrentRegion=g_langInfo.GetCurrentRegion();
2591
2592   sort(regions.begin(), regions.end(), sortstringbyname());
2593
2594   for (int i = 0; i < (int) regions.size(); ++i)
2595   {
2596     const CStdString& strRegion = regions[i];
2597
2598     if (strRegion == strCurrentRegion)
2599       iCurrentRegion = i;
2600
2601     pControl->AddLabel(strRegion, i);
2602   }
2603
2604   pControl->SetValue(iCurrentRegion);
2605 }
2606
2607 CBaseSettingControl *CGUIWindowSettingsCategory::GetSetting(const CStdString &strSetting)
2608 {
2609   for (unsigned int i = 0; i < m_vecSettings.size(); i++)
2610   {
2611     if (m_vecSettings[i]->GetSetting()->GetSetting() == strSetting)
2612       return m_vecSettings[i];
2613   }
2614   return NULL;
2615 }
2616
2617 void CGUIWindowSettingsCategory::FillInSkinThemes(CSetting *pSetting)
2618 {
2619   // There is a default theme (just Textures.xpr/xbt)
2620   // any other *.xpr|*.xbt files are additional themes on top of this one.
2621   CSettingString *pSettingString = (CSettingString *)pSetting;
2622   CBaseSettingControl *setting = GetSetting(pSetting->GetSetting());
2623   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(setting->GetID());
2624   CStdString strSettingString = g_guiSettings.GetString("lookandfeel.skintheme");
2625   setting->SetDelayed();
2626
2627   // Clear and add. the Default Label
2628   pControl->Clear();
2629   pControl->SetShowRange(true);
2630   pControl->AddLabel(g_localizeStrings.Get(15109), 0); // "SKINDEFAULT" The standard Textures.xpr/xbt will be used
2631
2632   CStdString strDefaultTheme = pSettingString->GetData();
2633
2634   // Search for Themes in the Current skin!
2635   vector<CStdString> vecTheme;
2636   CUtil::GetSkinThemes(vecTheme);
2637
2638   // Remove the extension from the current Theme (backward compat)
2639   URIUtils::RemoveExtension(strSettingString);
2640
2641   // Sort the Themes for GUI and list them
2642   int iCurrentTheme = 0;
2643   for (int i = 0; i < (int) vecTheme.size(); ++i)
2644   {
2645     CStdString strTheme = vecTheme[i];
2646     // Is the Current Theme our Used Theme! If yes set the ID!
2647     if (strTheme.CompareNoCase(strSettingString) == 0 )
2648       iCurrentTheme = i + 1; // 1: #of Predefined Theme [Label]
2649     pControl->AddLabel(strTheme, i + 1);
2650   }
2651   // Set the Choosen Theme
2652   pControl->SetValue(iCurrentTheme);
2653 }
2654
2655 void CGUIWindowSettingsCategory::FillInSkinColors(CSetting *pSetting)
2656 {
2657   // There is a default theme (just defaults.xml)
2658   // any other *.xml files are additional color themes on top of this one.
2659   CBaseSettingControl *setting = GetSetting(pSetting->GetSetting());
2660   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(setting->GetID());
2661   CStdString strSettingString = g_guiSettings.GetString("lookandfeel.skincolors");
2662   setting->SetDelayed();
2663
2664   // Clear and add. the Default Label
2665   pControl->Clear();
2666   pControl->SetShowRange(true);
2667   pControl->AddLabel(g_localizeStrings.Get(15109), 0); // "SKINDEFAULT"! The standard defaults.xml will be used!
2668
2669   // Search for colors in the Current skin!
2670   vector<CStdString> vecColors;
2671
2672   CStdString strPath;
2673   URIUtils::AddFileToFolder(g_SkinInfo->Path(),"colors",strPath);
2674
2675   CFileItemList items;
2676   CDirectory::GetDirectory(CSpecialProtocol::TranslatePathConvertCase(strPath), items, ".xml");
2677   // Search for Themes in the Current skin!
2678   for (int i = 0; i < items.Size(); ++i)
2679   {
2680     CFileItemPtr pItem = items[i];
2681     if (!pItem->m_bIsFolder && pItem->GetLabel().CompareNoCase("defaults.xml") != 0)
2682     { // not the default one
2683       CStdString strLabel = pItem->GetLabel();
2684       vecColors.push_back(strLabel.Mid(0, strLabel.size() - 4));
2685     }
2686   }
2687   sort(vecColors.begin(), vecColors.end(), sortstringbyname());
2688
2689   // Remove the .xml extension from the Themes
2690   if (URIUtils::GetExtension(strSettingString) == ".xml")
2691     URIUtils::RemoveExtension(strSettingString);
2692
2693   int iCurrentColor = 0;
2694   for (int i = 0; i < (int) vecColors.size(); ++i)
2695   {
2696     CStdString strColor = vecColors[i];
2697     // Is the Current Theme our Used Theme! If yes set the ID!
2698     if (strColor.CompareNoCase(strSettingString) == 0 )
2699       iCurrentColor = i + 1; // 1: #of Predefined Theme [Label]
2700     pControl->AddLabel(strColor, i + 1);
2701   }
2702   // Set the Choosen Theme
2703   pControl->SetValue(iCurrentColor);
2704 }
2705
2706 void CGUIWindowSettingsCategory::FillInStartupWindow(CSetting *pSetting)
2707 {
2708   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2709   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2710   pControl->Clear();
2711
2712   const vector<CSkinInfo::CStartupWindow> &startupWindows = g_SkinInfo->GetStartupWindows();
2713
2714   // TODO: How should we localize this?
2715   // In the long run there is no way to do it really without the skin having some
2716   // translation information built in to it, which isn't really feasible.
2717
2718   // Alternatively we could lookup the strings in the english strings file to get
2719   // their id and then get the string from that
2720
2721   // easier would be to have the skinner use the "name" as the label number.
2722
2723   // eg <window id="0">513</window>
2724
2725   bool currentSettingFound(false);
2726   for (vector<CSkinInfo::CStartupWindow>::const_iterator it = startupWindows.begin(); it != startupWindows.end(); it++)
2727   {
2728     CStdString windowName((*it).m_name);
2729     if (StringUtils::IsNaturalNumber(windowName))
2730       windowName = g_localizeStrings.Get(atoi(windowName.c_str()));
2731     int windowID((*it).m_id);
2732     pControl->AddLabel(windowName, windowID);
2733     if (pSettingInt->GetData() == windowID)
2734       currentSettingFound = true;
2735   }
2736
2737   // ok, now check whether our current option is one of these
2738   // and set it's value
2739   if (!currentSettingFound)
2740   { // nope - set it to the "default" option - the first one
2741     pSettingInt->SetData(startupWindows[0].m_id);
2742   }
2743   pControl->SetValue(pSettingInt->GetData());
2744 }
2745
2746 void CGUIWindowSettingsCategory::OnInitWindow()
2747 {
2748   m_strOldTrackFormat = g_guiSettings.GetString("musicfiles.trackformat");
2749   m_strOldTrackFormatRight = g_guiSettings.GetString("musicfiles.trackformatright");
2750   SetupControls();
2751   CGUIWindow::OnInitWindow();
2752 }
2753
2754 void CGUIWindowSettingsCategory::FillInViewModes(CSetting *pSetting, int windowID)
2755 {
2756   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2757   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2758   pControl->AddLabel("Auto", DEFAULT_VIEW_AUTO);
2759   bool found(false);
2760   int foundType = 0;
2761   CGUIWindow *window = g_windowManager.GetWindow(windowID);
2762   if (window)
2763   {
2764     window->Initialize();
2765     for (int i = 50; i < 60; i++)
2766     {
2767       CGUIBaseContainer *control = (CGUIBaseContainer *)window->GetControl(i);
2768       if (control)
2769       {
2770         int type = (control->GetType() << 16) | i;
2771         pControl->AddLabel(control->GetLabel(), type);
2772         if (type == pSettingInt->GetData())
2773           found = true;
2774         else if ((type >> 16) == (pSettingInt->GetData() >> 16))
2775           foundType = type;
2776       }
2777     }
2778     window->ClearAll();
2779   }
2780   if (!found)
2781     pSettingInt->SetData(foundType ? foundType : (DEFAULT_VIEW_AUTO));
2782   pControl->SetValue(pSettingInt->GetData());
2783 }
2784
2785 void CGUIWindowSettingsCategory::FillInSortMethods(CSetting *pSetting, int windowID)
2786 {
2787   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2788   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2789   CFileItemList items("C:");
2790   CGUIViewState *state = CGUIViewState::GetViewState(windowID, items);
2791   if (state)
2792   {
2793     bool found(false);
2794     vector< pair<int,int> > sortMethods;
2795     state->GetSortMethods(sortMethods);
2796     for (unsigned int i = 0; i < sortMethods.size(); i++)
2797     {
2798       pControl->AddLabel(g_localizeStrings.Get(sortMethods[i].second), sortMethods[i].first);
2799       if (sortMethods[i].first == pSettingInt->GetData())
2800         found = true;
2801     }
2802     if (!found && sortMethods.size())
2803       pSettingInt->SetData(sortMethods[0].first);
2804   }
2805   pControl->SetValue(pSettingInt->GetData());
2806   delete state;
2807 }
2808
2809 void CGUIWindowSettingsCategory::FillInNetworkInterfaces(CSetting *pSetting, float groupWidth, int &iControlID)
2810 {
2811   CGUISpinControlEx *pControl = (CGUISpinControlEx *)AddSetting(pSetting, groupWidth, iControlID);
2812   pControl->Clear();
2813
2814   // query list of interfaces
2815   vector<CStdString> vecInterfaces;
2816   std::vector<CNetworkInterface*>& ifaces = g_application.getNetwork().GetInterfaceList();
2817   std::vector<CNetworkInterface*>::const_iterator iter = ifaces.begin();
2818   while (iter != ifaces.end())
2819   {
2820     CNetworkInterface* iface = *iter;
2821     vecInterfaces.push_back(iface->GetName());
2822     ++iter;
2823   }
2824   sort(vecInterfaces.begin(), vecInterfaces.end(), sortstringbyname());
2825
2826   int iInterface = 0;
2827   for (unsigned int i = 0; i < vecInterfaces.size(); ++i)
2828     pControl->AddLabel(vecInterfaces[i], iInterface++);
2829 }
2830
2831 void CGUIWindowSettingsCategory::FillInEpgGuideView(CSetting *pSetting)
2832 {
2833   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2834   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2835   pControl->Clear();
2836
2837   pControl->AddLabel(g_localizeStrings.Get(19029), GUIDE_VIEW_CHANNEL);
2838   pControl->AddLabel(g_localizeStrings.Get(19030), GUIDE_VIEW_NOW);
2839   pControl->AddLabel(g_localizeStrings.Get(19031), GUIDE_VIEW_NEXT);
2840   pControl->AddLabel(g_localizeStrings.Get(19032), GUIDE_VIEW_TIMELINE);
2841
2842   pControl->SetValue(pSettingInt->GetData());
2843 }
2844
2845 void CGUIWindowSettingsCategory::FillInPvrStartLastChannel(CSetting *pSetting)
2846 {
2847   CSettingInt *pSettingInt = (CSettingInt*)pSetting;
2848   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2849   pControl->Clear();
2850
2851   pControl->AddLabel(g_localizeStrings.Get(106),   START_LAST_CHANNEL_OFF);
2852   pControl->AddLabel(g_localizeStrings.Get(19190), START_LAST_CHANNEL_MIN);
2853   pControl->AddLabel(g_localizeStrings.Get(107),   START_LAST_CHANNEL_ON);
2854
2855   pControl->SetValue(pSettingInt->GetData());
2856 }
2857
2858 void CGUIWindowSettingsCategory::FillInAudioDevices(CSetting* pSetting, bool Passthrough)
2859 {
2860   CGUISpinControlEx *pControl = (CGUISpinControlEx *)GetControl(GetSetting(pSetting->GetSetting())->GetID());
2861   pControl->Clear();
2862
2863   CStdString currentDevice = Passthrough ? g_guiSettings.GetString("audiooutput.passthroughdevice") : g_guiSettings.GetString("audiooutput.audiodevice");
2864
2865   if (Passthrough)
2866   {
2867     m_DigitalAudioSinkMap.clear();
2868     m_DigitalAudioSinkMap["Error - no devices found"] = "null:";
2869   }
2870   else
2871   {
2872     m_AnalogAudioSinkMap.clear();
2873     m_AnalogAudioSinkMap["Error - no devices found"] = "null:";
2874   }
2875
2876   int numberSinks = 0;
2877
2878   int selectedValue = -1;
2879   AEDeviceList sinkList;
2880   CAEFactory::EnumerateOutputDevices(sinkList, Passthrough);
2881 #if !defined(TARGET_DARWIN)
2882   if (sinkList.size()==0)
2883   {
2884     pControl->AddLabel("Error - no devices found", 0);
2885     numberSinks = 1;
2886     selectedValue = 0;
2887   }
2888   else
2889   {
2890 #endif
2891     AEDeviceList::const_iterator iter = sinkList.begin();
2892     for (int i=0; iter != sinkList.end(); iter++)
2893     {
2894       CStdString label = (*iter).first;
2895       CStdString sink  = (*iter).second;
2896       pControl->AddLabel(label.c_str(), i);
2897
2898       if (currentDevice.Equals(sink))
2899         selectedValue = i;
2900
2901       if (Passthrough)
2902         m_DigitalAudioSinkMap[label] = sink;
2903       else
2904         m_AnalogAudioSinkMap[label] = sink;
2905
2906       i++;
2907     }
2908
2909     numberSinks = sinkList.size();
2910 #if !defined(TARGET_DARWIN)
2911   }
2912 #endif
2913
2914   if (selectedValue < 0)
2915   {
2916     CLog::Log(LOGWARNING, "Failed to find previously selected audio sink");
2917     pControl->AddLabel(currentDevice, numberSinks);
2918     pControl->SetValue(numberSinks);
2919   }
2920   else
2921     pControl->SetValue(selectedValue);
2922 }
2923
2924 void CGUIWindowSettingsCategory::NetworkInterfaceChanged(void)
2925 {
2926 #if 0
2927    NetworkAssignment iAssignment;
2928    CStdString sIPAddress;
2929    CStdString sNetworkMask;
2930    CStdString sDefaultGateway;
2931    CStdString sWirelessNetwork;
2932    CStdString sWirelessKey;
2933    EncMode iWirelessEnc;
2934    bool bIsWireless;
2935    CStdString ifaceName;
2936
2937    // Get network information
2938    CGUISpinControlEx *ifaceControl = (CGUISpinControlEx *)GetControl(GetSetting("network.interface")->GetID());
2939    ifaceName = ifaceControl->GetLabel();
2940    CNetworkInterface* iface = g_application.getNetwork().GetInterfaceByName(ifaceName);
2941    iface->GetSettings(iAssignment, sIPAddress, sNetworkMask, sDefaultGateway, sWirelessNetwork, sWirelessKey, iWirelessEnc);
2942    bIsWireless = iface->IsWireless();
2943
2944    CStdString dns;
2945    std::vector<CStdString> dnss = g_application.getNetwork().GetNameServers();
2946    if (dnss.size() >= 1)
2947       dns = dnss[0];
2948
2949    // Update controls with information
2950    CGUISpinControlEx* pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.assignment")->GetID());
2951    if (pControl1) pControl1->SetValue(iAssignment);
2952    GetSetting("network.dns")->GetSetting()->FromString(dns);
2953    if (iAssignment == NETWORK_STATIC || iAssignment == NETWORK_DISABLED)
2954    {
2955      GetSetting("network.ipaddress")->GetSetting()->FromString(sIPAddress);
2956      GetSetting("network.subnet")->GetSetting()->FromString(sNetworkMask);
2957      GetSetting("network.gateway")->GetSetting()->FromString(sDefaultGateway);
2958    }
2959    else
2960    {
2961      GetSetting("network.ipaddress")->GetSetting()->FromString(iface->GetCurrentIPAddress());
2962      GetSetting("network.subnet")->GetSetting()->FromString(iface->GetCurrentNetmask());
2963      GetSetting("network.gateway")->GetSetting()->FromString(iface->GetCurrentDefaultGateway());
2964    }
2965
2966    pControl1 = (CGUISpinControlEx *)GetControl(GetSetting("network.enc")->GetID());
2967    if (pControl1) pControl1->SetValue(iWirelessEnc);
2968
2969    if (bIsWireless)
2970    {
2971       GetSetting("network.essid")->GetSetting()->FromString(sWirelessNetwork);
2972       GetSetting("network.key")->GetSetting()->FromString(sWirelessKey);
2973    }
2974    else
2975    {
2976       GetSetting("network.essid")->GetSetting()->FromString("");
2977       GetSetting("network.key")->GetSetting()->FromString("");
2978    }
2979 #endif
2980 }
2981
2982 void CGUIWindowSettingsCategory::ValidatePortNumber(CBaseSettingControl* pSettingControl, const CStdString& userPort, const CStdString& privPort, bool listening/*=true*/)
2983 {
2984   CSettingString *pSetting = (CSettingString *)pSettingControl->GetSetting();
2985   // check that it's a valid port
2986   int port = atoi(pSetting->GetData().c_str());
2987 #ifdef _LINUX
2988   if (listening && !CUtil::CanBindPrivileged() && (port < 1024 || port > 65535))
2989   {
2990     CGUIDialogOK::ShowAndGetInput(257, 850, 852, -1);
2991     pSetting->SetData(userPort.c_str());
2992   }
2993   else
2994 #endif
2995   if (port <= 0 || port > 65535)
2996   {
2997     CGUIDialogOK::ShowAndGetInput(257, 850, 851, -1);
2998     pSetting->SetData(privPort.c_str());
2999   }
3000 }