[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / application / ApplicationSettingsHandling.cpp
blob0a2c1b1c2f0419dd9fa4a28ed0e8b7e8c1538c21
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "ApplicationSettingsHandling.h"
11 #include "ServiceBroker.h"
12 #include "addons/AddonManager.h"
13 #include "addons/addoninfo/AddonType.h"
14 #include "addons/gui/GUIDialogAddonSettings.h"
15 #include "application/ApplicationComponents.h"
16 #include "application/ApplicationPlayer.h"
17 #include "application/ApplicationPowerHandling.h"
18 #include "application/ApplicationSkinHandling.h"
19 #include "application/ApplicationVolumeHandling.h"
20 #include "guilib/GUIComponent.h"
21 #include "guilib/GUIWindowManager.h"
22 #include "messaging/ApplicationMessenger.h"
23 #include "settings/Settings.h"
24 #include "settings/SettingsComponent.h"
25 #include "settings/lib/Setting.h"
26 #include "settings/lib/SettingsManager.h"
27 #if defined(TARGET_DARWIN_OSX)
28 #include "utils/StringUtils.h"
29 #endif
31 namespace
33 bool IsPlaying(const std::string& condition,
34 const std::string& value,
35 const SettingConstPtr& setting,
36 void* data)
38 return data ? static_cast<CApplicationPlayer*>(data)->IsPlaying() : false;
40 } // namespace
42 void CApplicationSettingsHandling::RegisterSettings()
44 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
45 CSettingsManager* settingsMgr = settings->GetSettingsManager();
47 settingsMgr->RegisterSettingsHandler(this);
49 settingsMgr->RegisterCallback(this, {CSettings::SETTING_AUDIOOUTPUT_PASSTHROUGH,
50 CSettings::SETTING_LOOKANDFEEL_SKIN,
51 CSettings::SETTING_LOOKANDFEEL_SKINSETTINGS,
52 CSettings::SETTING_LOOKANDFEEL_FONT,
53 CSettings::SETTING_LOOKANDFEEL_SKINTHEME,
54 CSettings::SETTING_LOOKANDFEEL_SKINCOLORS,
55 CSettings::SETTING_LOOKANDFEEL_SKINZOOM,
56 CSettings::SETTING_MUSICPLAYER_REPLAYGAINPREAMP,
57 CSettings::SETTING_MUSICPLAYER_REPLAYGAINNOGAINPREAMP,
58 CSettings::SETTING_MUSICPLAYER_REPLAYGAINTYPE,
59 CSettings::SETTING_MUSICPLAYER_REPLAYGAINAVOIDCLIPPING,
60 CSettings::SETTING_SCRAPERS_MUSICVIDEOSDEFAULT,
61 CSettings::SETTING_SCREENSAVER_MODE,
62 CSettings::SETTING_SCREENSAVER_PREVIEW,
63 CSettings::SETTING_SCREENSAVER_SETTINGS,
64 CSettings::SETTING_AUDIOCDS_SETTINGS,
65 CSettings::SETTING_VIDEOSCREEN_GUICALIBRATION,
66 CSettings::SETTING_VIDEOSCREEN_TESTPATTERN,
67 CSettings::SETTING_VIDEOPLAYER_USEMEDIACODEC,
68 CSettings::SETTING_VIDEOPLAYER_USEMEDIACODECSURFACE,
69 CSettings::SETTING_AUDIOOUTPUT_VOLUMESTEPS,
70 CSettings::SETTING_SOURCE_VIDEOS,
71 CSettings::SETTING_SOURCE_MUSIC,
72 CSettings::SETTING_SOURCE_PICTURES,
73 CSettings::SETTING_VIDEOSCREEN_FAKEFULLSCREEN});
75 auto& components = CServiceBroker::GetAppComponents();
76 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
77 if (!appPlayer)
78 return;
80 settingsMgr->RegisterCallback(
81 &appPlayer->GetSeekHandler(),
82 {CSettings::SETTING_VIDEOPLAYER_SEEKDELAY, CSettings::SETTING_VIDEOPLAYER_SEEKSTEPS,
83 CSettings::SETTING_MUSICPLAYER_SEEKDELAY, CSettings::SETTING_MUSICPLAYER_SEEKSTEPS});
85 settingsMgr->AddDynamicCondition("isplaying", IsPlaying, appPlayer.get());
87 settings->RegisterSubSettings(this);
90 void CApplicationSettingsHandling::UnregisterSettings()
92 const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
93 CSettingsManager* settingsMgr = settings->GetSettingsManager();
94 auto& components = CServiceBroker::GetAppComponents();
95 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
96 if (!appPlayer)
97 return;
99 settings->UnregisterSubSettings(this);
100 settingsMgr->RemoveDynamicCondition("isplaying");
101 settingsMgr->UnregisterCallback(&appPlayer->GetSeekHandler());
102 settingsMgr->UnregisterCallback(this);
103 settingsMgr->UnregisterSettingsHandler(this);
106 void CApplicationSettingsHandling::OnSettingChanged(const std::shared_ptr<const CSetting>& setting)
108 if (!setting)
109 return;
111 auto& components = CServiceBroker::GetAppComponents();
112 const auto appSkin = components.GetComponent<CApplicationSkinHandling>();
113 if (appSkin->OnSettingChanged(*setting))
114 return;
116 const auto appVolume = components.GetComponent<CApplicationVolumeHandling>();
117 if (appVolume->OnSettingChanged(*setting))
118 return;
120 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
121 if (appPower->OnSettingChanged(*setting))
122 return;
124 const std::string& settingId = setting->GetId();
126 if (settingId == CSettings::SETTING_VIDEOSCREEN_FAKEFULLSCREEN)
128 if (CServiceBroker::GetWinSystem()->GetGfxContext().IsFullScreenRoot())
129 CServiceBroker::GetWinSystem()->GetGfxContext().SetVideoResolution(
130 CServiceBroker::GetWinSystem()->GetGfxContext().GetVideoResolution(), true);
132 else if (settingId == CSettings::SETTING_AUDIOOUTPUT_PASSTHROUGH)
134 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MEDIA_RESTART);
138 void CApplicationSettingsHandling::OnSettingAction(const std::shared_ptr<const CSetting>& setting)
140 if (!setting)
141 return;
143 auto& components = CServiceBroker::GetAppComponents();
144 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
145 if (appPower->OnSettingAction(*setting))
146 return;
148 const std::string& settingId = setting->GetId();
149 if (settingId == CSettings::SETTING_LOOKANDFEEL_SKINSETTINGS)
150 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SKIN_SETTINGS);
151 else if (settingId == CSettings::SETTING_AUDIOCDS_SETTINGS)
153 ADDON::AddonPtr addon;
154 if (CServiceBroker::GetAddonMgr().GetAddon(
155 CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(
156 CSettings::SETTING_AUDIOCDS_ENCODER),
157 addon, ADDON::AddonType::AUDIOENCODER, ADDON::OnlyEnabled::CHOICE_YES))
158 CGUIDialogAddonSettings::ShowForAddon(addon);
160 else if (settingId == CSettings::SETTING_VIDEOSCREEN_GUICALIBRATION)
161 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_SCREEN_CALIBRATION);
162 else if (settingId == CSettings::SETTING_SOURCE_VIDEOS)
164 std::vector<std::string> params{"library://video/files.xml", "return"};
165 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_VIDEO_NAV, params);
167 else if (settingId == CSettings::SETTING_SOURCE_MUSIC)
169 std::vector<std::string> params{"library://music/files.xml", "return"};
170 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_NAV, params);
172 else if (settingId == CSettings::SETTING_SOURCE_PICTURES)
173 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_PICTURES);
176 bool CApplicationSettingsHandling::OnSettingUpdate(const std::shared_ptr<CSetting>& setting,
177 const char* oldSettingId,
178 const TiXmlNode* oldSettingNode)
180 if (!setting)
181 return false;
183 #if defined(TARGET_DARWIN_OSX)
184 if (setting->GetId() == CSettings::SETTING_AUDIOOUTPUT_AUDIODEVICE)
186 std::shared_ptr<CSettingString> audioDevice = std::static_pointer_cast<CSettingString>(setting);
187 // Gotham and older didn't enumerate audio devices per stream on osx
188 // add stream0 per default which should be ok for all old settings.
189 if (!StringUtils::EqualsNoCase(audioDevice->GetValue(), "DARWINOSX:default") &&
190 StringUtils::FindWords(audioDevice->GetValue().c_str(), ":stream") == std::string::npos)
192 std::string newSetting = audioDevice->GetValue();
193 newSetting += ":stream0";
194 return audioDevice->SetValue(newSetting);
197 #endif
199 return false;
202 bool CApplicationSettingsHandling::Load(const TiXmlNode* settings)
204 auto& components = CServiceBroker::GetAppComponents();
205 const auto appVolume = components.GetComponent<CApplicationVolumeHandling>();
206 return appVolume->Load(settings);
209 bool CApplicationSettingsHandling::Save(TiXmlNode* settings) const
211 const auto& components = CServiceBroker::GetAppComponents();
212 const auto appVolume = components.GetComponent<CApplicationVolumeHandling>();
213 return appVolume->Save(settings);