Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: a setting should be disabled if its parent setting is disabled #4771

Merged
merged 1 commit into from May 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion xbmc/settings/lib/Setting.cpp
Expand Up @@ -149,9 +149,18 @@ bool CSetting::Deserialize(const TiXmlNode *node, bool update /* = false */)

bool CSetting::IsEnabled() const
{
if (m_dependencies.empty())
if (m_dependencies.empty() && m_parentSetting.empty())
return m_enabled;

// if the setting has a parent setting and that parent setting is disabled
// the setting should automatically also be disabled
if (!m_parentSetting.empty())
{
CSetting *parentSetting = m_settingsManager->GetSetting(m_parentSetting);
if (parentSetting != NULL && !parentSetting->IsEnabled())
return false;
}

bool enabled = true;
for (SettingDependencies::const_iterator depIt = m_dependencies.begin(); depIt != m_dependencies.end(); ++depIt)
{
Expand Down
31 changes: 30 additions & 1 deletion xbmc/settings/lib/SettingsManager.cpp
Expand Up @@ -207,6 +207,16 @@ void CSettingsManager::SetInitialized()
if (itSettingDep->second.setting == NULL)
continue;

// if the setting has a parent setting, add it to its children
std::string parentSettingId = itSettingDep->second.setting->GetParent();
if (!parentSettingId.empty())
{
SettingMap::iterator itParentSetting = m_settings.find(parentSettingId);
if (itParentSetting != m_settings.end())
itParentSetting->second.children.insert(itSettingDep->first);
}

// handle all dependencies of the setting
const SettingDependencies& deps = itSettingDep->second.setting->GetDependencies();
for (SettingDependencies::const_iterator depIt = deps.begin(); depIt != deps.end(); ++depIt)
{
Expand Down Expand Up @@ -815,6 +825,20 @@ void CSettingsManager::OnSettingPropertyChanged(const CSetting *setting, const c
callback != settingData.callbacks.end();
++callback)
(*callback)->OnSettingPropertyChanged(setting, propertyName);

// check the changed property and if it may have an influence on the
// children of the setting
SettingDependencyType dependencyType = SettingDependencyTypeNone;
if (StringUtils::EqualsNoCase(propertyName, "enabled"))
dependencyType = SettingDependencyTypeEnable;
else if (StringUtils::EqualsNoCase(propertyName, "visible"))
dependencyType = SettingDependencyTypeVisible;

if (dependencyType != SettingDependencyTypeNone)
{
for (std::set<std::string>::const_iterator childIt = settingIt->second.children.begin(); childIt != settingIt->second.children.end(); ++childIt)
UpdateSettingByDependency(*childIt, dependencyType);
}
}

CSetting* CSettingsManager::CreateSetting(const std::string &settingType, const std::string &settingId, CSettingsManager *settingsManager /* = NULL */) const
Expand Down Expand Up @@ -1017,12 +1041,17 @@ bool CSettingsManager::UpdateSetting(const TiXmlNode *node, CSetting *setting, c
}

void CSettingsManager::UpdateSettingByDependency(const std::string &settingId, const CSettingDependency &dependency)
{
UpdateSettingByDependency(settingId, dependency.GetType());
}

void CSettingsManager::UpdateSettingByDependency(const std::string &settingId, SettingDependencyType dependencyType)
{
CSetting *setting = GetSetting(settingId);
if (setting == NULL)
return;

switch (dependency.GetType())
switch (dependencyType)
{
case SettingDependencyTypeEnable:
// just trigger the property changed callback and a call to
Expand Down
2 changes: 2 additions & 0 deletions xbmc/settings/lib/SettingsManager.h
Expand Up @@ -409,6 +409,7 @@ class CSettingsManager : public ISettingCreator, public ISettingControlCreator,
bool UpdateSettings(const TiXmlNode *root);
bool UpdateSetting(const TiXmlNode *node, CSetting *setting, const CSettingUpdate& update);
void UpdateSettingByDependency(const std::string &settingId, const CSettingDependency &dependency);
void UpdateSettingByDependency(const std::string &settingId, SettingDependencyType dependencyType);

typedef enum {
SettingOptionsFillerTypeNone = 0,
Expand All @@ -422,6 +423,7 @@ class CSettingsManager : public ISettingCreator, public ISettingControlCreator,
typedef struct {
CSetting *setting;
SettingDependencyMap dependencies;
std::set<std::string> children;
CallbackSet callbacks;
} Setting;

Expand Down