Exemple #1
0
bool CSettingNumber::SetValue(double value)
{
  CExclusiveLock lock(m_critical);

  if (value == m_value)
    return true;

  if (!CheckValidity(value))
    return false;

  double oldValue = m_value;
  m_value = value;

  if (!OnSettingChanging(this))
  {
    m_value = oldValue;

    // the setting couldn't be changed because one of the
    // callback handlers failed the OnSettingChanging()
    // callback so we need to let all the callback handlers
    // know that the setting hasn't changed
    OnSettingChanging(this);
    return false;
  }

  m_changed = m_value != m_default;
  OnSettingChanged(this);
  return true;
}
Exemple #2
0
bool CSettingString::SetValue(const std::string &value)
{
  CSingleLock lock(m_critical);

  if (value == m_value)
    return true;
    
  if (!CheckValidity(value))
    return false;

  std::string oldValue = m_value;
  m_value = value;

  if (!OnSettingChanging(this))
  {
    m_value = oldValue;

    // the setting couldn't be changed because one of the
    // callback handlers failed the OnSettingChanging()
    // callback so we need to let all the callback handlers
    // know that the setting hasn't changed
    OnSettingChanging(this);
    return false;
  }

  m_changed = m_value != m_default;
  OnSettingChanged(this);
  return true;
}
Exemple #3
0
bool CSettingList::SetValue(const SettingPtrList &values)
{
    CExclusiveLock lock(m_critical);

    if ((int)values.size() < m_minimumItems ||
            (m_maximumItems > 0 && (int)values.size() > m_maximumItems))
        return false;

    bool equal = values.size() == m_values.size();
    for (size_t index = 0; index < values.size(); index++)
    {
        if (values[index]->GetType() != GetElementType())
            return false;

        if (equal &&
                !values[index]->Equals(m_values[index]->ToString()))
            equal = false;
    }

    if (equal)
        return true;

    SettingPtrList oldValues = m_values;
    m_values.clear();
    m_values.insert(m_values.begin(), values.begin(), values.end());

    if (!OnSettingChanging(this))
    {
        m_values = oldValues;

        // the setting couldn't be changed because one of the
        // callback handlers failed the OnSettingChanging()
        // callback so we need to let all the callback handlers
        // know that the setting hasn't changed
        OnSettingChanging(this);
        return false;
    }

    m_changed = (toString(m_values) != toString(m_defaults));
    OnSettingChanged(this);
    return true;
}