Exemple #1
0
void CGUIWindowSettingsCategory::UpdateSettings()
{
  for (vector<BaseSettingControlPtr>::iterator it = m_settingControls.begin(); it != m_settingControls.end(); it++)
  {
    BaseSettingControlPtr pSettingControl = *it;
    CSetting *pSetting = pSettingControl->GetSetting();
    CGUIControl *pControl = pSettingControl->GetControl();
    if (pSetting == NULL || pControl == NULL)
      continue;

    // update the setting's control's state (enabled/disabled etc)
    const SettingDependencies &deps = pSetting->GetDependencies();
    for (SettingDependencies::const_iterator dep = deps.begin(); dep != deps.end(); dep++)
    {
      // don't check "update" dependencies here as all the controls are already
      // setup properly based on the existing values
      if (dep->GetType() == SettingDependencyTypeUpdate)
        continue;

      CheckDependency(pSettingControl, *dep);
    }

    pSettingControl->Update();
  }
}
Exemple #2
0
bool CSetting::IsEnabled() const
{
    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)
    {
        if (depIt->GetType() != SettingDependencyTypeEnable)
            continue;

        if (!depIt->Check())
        {
            enabled = false;
            break;
        }
    }

    return enabled;
}
Exemple #3
0
void CSettingsManager::SetInitialized()
{
  CExclusiveLock lock(m_settingsCritical);
  if (m_initialized)
    return;

  m_initialized = true;

  for (SettingMap::iterator setting = m_settings.begin(); setting != m_settings.end(); )
  {
    SettingMap::iterator tmpIterator = setting++;
    if (tmpIterator->second.setting == NULL)
      m_settings.erase(tmpIterator);
  }

  // figure out all the dependencies between settings
  for (SettingMap::iterator itSettingDep = m_settings.begin(); itSettingDep != m_settings.end(); ++itSettingDep)
  {
    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)
    {
      std::set<std::string> settingIds = depIt->GetSettings();
      for (std::set<std::string>::const_iterator itSettingId = settingIds.begin(); itSettingId != settingIds.end(); ++itSettingId)
      {
        SettingMap::iterator setting = m_settings.find(*itSettingId);
        if (setting == m_settings.end())
          continue;

        bool newDep = true;
        SettingDependencies &settingDeps = setting->second.dependencies[itSettingDep->first];
        for (SettingDependencies::const_iterator itDeps = settingDeps.begin(); itDeps != settingDeps.end(); ++itDeps)
        {
          if (itDeps->GetType() == depIt->GetType())
          {
            newDep = false;
            break;
          }
        }

        if (newDep)
          settingDeps.push_back(*depIt);
      }
    }
  }
}
Exemple #4
0
bool CSetting::IsEnabled() const
{
  bool enabled = true;
  for (SettingDependencies::const_iterator depIt = m_dependencies.begin(); depIt != m_dependencies.end(); ++depIt)
  {
    if (depIt->GetType() != SettingDependencyTypeEnable)
      continue;

    if (!depIt->Check())
    {
      enabled = false;
      break;
    }
  }

  return enabled;
}
Exemple #5
0
bool CSetting::IsVisible() const
{
  if (!ISetting::IsVisible())
    return false;

  bool visible = true;
  for (SettingDependencies::const_iterator depIt = m_dependencies.begin(); depIt != m_dependencies.end(); ++depIt)
  {
    if (depIt->GetType() != SettingDependencyTypeVisible)
      continue;

    if (!depIt->Check())
    {
      visible = false;
      break;
    }
  }

  return visible;
}
Exemple #6
0
bool CSettingsManager::Initialize(const TiXmlElement *root)
{
  CExclusiveLock lock(m_critical);
  CExclusiveLock settingsLock(m_settingsCritical);
  if (m_initialized || root == NULL)
    return false;

  if (!StringUtils::EqualsNoCase(root->ValueStr(), SETTING_XML_ROOT))
  {
    CLog::Log(LOGERROR, "CSettingsManager: error reading settings definition: doesn't contain <settings> tag");
    return false;
  }

  const TiXmlNode *sectionNode = root->FirstChild(SETTING_XML_ELM_SECTION);
  while (sectionNode != NULL)
  {
    std::string sectionId;
    if (CSettingSection::DeserializeIdentification(sectionNode, sectionId))
    {
      CSettingSection *section = NULL;
      SettingSectionMap::iterator itSection = m_sections.find(sectionId);
      bool update = (itSection != m_sections.end());
      if (!update)
        section = new CSettingSection(sectionId, this);
      else
        section = itSection->second;

      if (section->Deserialize(sectionNode, update))
      {
        section->CheckRequirements();
        if (!update)
          m_sections[section->GetId()] = section;

        // get all settings and add them to the settings map
        for (SettingCategoryList::const_iterator categoryIt = section->GetCategories().begin(); categoryIt != section->GetCategories().end(); ++categoryIt)
        {
          (*categoryIt)->CheckRequirements();
          for (SettingGroupList::const_iterator groupIt = (*categoryIt)->GetGroups().begin(); groupIt != (*categoryIt)->GetGroups().end(); ++groupIt)
          {
            (*groupIt)->CheckRequirements();
            for (SettingList::const_iterator settingIt = (*groupIt)->GetSettings().begin(); settingIt != (*groupIt)->GetSettings().end(); ++settingIt)
            {
              (*settingIt)->CheckRequirements();

              const std::string &settingId = (*settingIt)->GetId();
              SettingMap::iterator setting = m_settings.find(settingId);
              if (setting == m_settings.end())
              {
                Setting tmpSetting = { NULL };
                std::pair<SettingMap::iterator, bool> tmpIt = m_settings.insert(make_pair(settingId, tmpSetting));
                setting = tmpIt.first;
              }
                
              if (setting->second.setting == NULL)
              {
                setting->second.setting = *settingIt;
                (*settingIt)->m_callback = this;
              }
            }
          }
        }
      }
      else
      {
        CLog::Log(LOGWARNING, "CSettingsManager: unable to read section \"%s\"", sectionId.c_str());
        if (!update)
          delete section;
      }
    }
      
    sectionNode = sectionNode->NextSibling(SETTING_XML_ELM_SECTION);
  }

  for (SettingMap::iterator itSettingDep = m_settings.begin(); itSettingDep != m_settings.end(); ++itSettingDep)
  {
    if (itSettingDep->second.setting == NULL)
      continue;

    const SettingDependencies& deps = itSettingDep->second.setting->GetDependencies();
    for (SettingDependencies::const_iterator depIt = deps.begin(); depIt != deps.end(); ++depIt)
    {
      std::set<std::string> settingIds = depIt->GetSettings();
      for (std::set<std::string>::const_iterator itSettingId = settingIds.begin(); itSettingId != settingIds.end(); ++itSettingId)
      {
        SettingMap::iterator setting = m_settings.find(*itSettingId);
        if (setting == m_settings.end())
          continue;

        bool newDep = true;
        SettingDependencies &settingDeps = setting->second.dependencies[itSettingDep->first];
        for (SettingDependencies::const_iterator itDeps = settingDeps.begin(); itDeps != settingDeps.end(); ++itDeps)
        {
          if (itDeps->GetType() == depIt->GetType())
          {
            newDep = false;
            break;
          }
        }

        if (newDep)
          settingDeps.push_back(*depIt);
      }
    }
  }

  return true;
}