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