Ejemplo n.º 1
0
void CSettingsManager::UpdateSettingByDependency(const std::string &settingId, const CSettingDependency &dependency)
{
  CSetting *setting = GetSetting(settingId);
  if (setting == NULL)
    return;

  switch (dependency.GetType())
  {
    case SettingDependencyTypeEnable:
      // just trigger the property changed callback and a call to
      // CSetting::IsEnabled() will automatically determine the new
      // enabled state
      OnSettingPropertyChanged(setting, "enabled");
      break;

    case SettingDependencyTypeUpdate:
    {
      SettingType type = (SettingType)setting->GetType();
      if (type == SettingTypeInteger)
      {
        CSettingInt *settingInt = ((CSettingInt*)setting);
        if (settingInt->GetOptionsType() == SettingOptionsTypeDynamic)
          settingInt->UpdateDynamicOptions();
      }
      else if (type == SettingTypeString)
      {
        CSettingString *settingString = ((CSettingString*)setting);
        if (settingString->GetOptionsType() == SettingOptionsTypeDynamic)
          settingString->UpdateDynamicOptions();
      }
      break;
    }

    case SettingDependencyTypeVisible:
      // just trigger the property changed callback and a call to
      // CSetting::IsVisible() will automatically determine the new
      // visible state
      OnSettingPropertyChanged(setting, "visible");
      break;

    case SettingDependencyTypeNone:
    default:
      break;
  }
}
Ejemplo n.º 2
0
void CSetting::SetEnabled(bool enabled)
{
    if (!m_dependencies.empty() ||
            m_enabled == enabled)
        return;

    m_enabled = enabled;
    OnSettingPropertyChanged(this, "enabled");
}
Ejemplo n.º 3
0
DynamicStringSettingOptions CSettingString::UpdateDynamicOptions()
{
    CExclusiveLock lock(m_critical);
    DynamicStringSettingOptions options;
    if (m_optionsFiller == NULL &&
            (m_optionsFillerName.empty() || m_settingsManager == NULL))
        return options;

    if (m_optionsFiller == NULL)
    {
        m_optionsFiller = (StringSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(this);
        if (m_optionsFiller == NULL)
            return options;
    }

    std::string bestMatchingValue = m_value;
    m_optionsFiller(this, options, bestMatchingValue, m_optionsFillerData);

    if (bestMatchingValue != m_value)
        SetValue(bestMatchingValue);

    // check if the list of items has changed
    bool changed = m_dynamicOptions.size() != options.size();
    if (!changed)
    {
        for (size_t index = 0; index < options.size(); index++)
        {
            if (options[index].first.compare(m_dynamicOptions[index].first) != 0 ||
                    options[index].second.compare(m_dynamicOptions[index].second) != 0)
            {
                changed = true;
                break;
            }
        }
    }

    if (changed)
    {
        m_dynamicOptions = options;
        OnSettingPropertyChanged(this, "options");
    }

    return options;
}
Ejemplo n.º 4
0
DynamicIntegerSettingOptions CSettingInt::UpdateDynamicOptions()
{
  CExclusiveLock lock(m_critical);
  DynamicIntegerSettingOptions options;
  if (m_optionsFiller.empty() || m_settingsManager == NULL)
    return options;

  IntegerSettingOptionsFiller filler = (IntegerSettingOptionsFiller)m_settingsManager->GetSettingOptionsFiller(this);
  if (filler == NULL)
    return options;

  int bestMatchingValue = m_value;
  filler(this, options, bestMatchingValue);

  if (bestMatchingValue != m_value)
    SetValue(bestMatchingValue);

  bool changed = m_dynamicOptions.size() != options.size();
  if (!changed)
  {
    for (size_t index = 0; index < options.size(); index++)
    {
      if (options[index].first.compare(m_dynamicOptions[index].first) != 0 ||
          options[index].second != m_dynamicOptions[index].second)
      {
        changed = true;
        break;
      }
    }
  }

  if (changed)
  {
    m_dynamicOptions = options;
    OnSettingPropertyChanged(this, "options");
  }

  return options;
}