PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/xbmc/settings/GUIWindowSettingsCategory.cpp

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