settings: a setting should be disabled if its parent setting is disabled
authormontellese <montellese@xbmc.org>
Fri, 23 May 2014 16:42:54 +0000 (18:42 +0200)
committermontellese <montellese@xbmc.org>
Fri, 23 May 2014 16:43:30 +0000 (18:43 +0200)
xbmc/settings/lib/Setting.cpp
xbmc/settings/lib/SettingsManager.cpp
xbmc/settings/lib/SettingsManager.h

index b5b8e35..d219bcb 100644 (file)
@@ -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)
   {
index 1c38367..fe601c6 100644 (file)
@@ -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)
     {
@@ -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
@@ -1018,11 +1042,16 @@ 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
index 57abb6b..66cdc22 100644 (file)
@@ -409,6 +409,7 @@ private:
   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,
@@ -422,6 +423,7 @@ private:
   typedef struct {
     CSetting *setting;
     SettingDependencyMap dependencies;
+    std::set<std::string> children;
     CallbackSet callbacks;
   } Setting;