예제 #1
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
bool CSettingList::fromValues(const std::vector<std::string> &strValues, SettingPtrList &values) const
{
    if ((int)strValues.size() < m_minimumItems ||
            (m_maximumItems > 0 && (int)strValues.size() > m_maximumItems))
        return false;

    bool ret = true;
    int index = 0;
    for (std::vector<std::string>::const_iterator itValue = strValues.begin(); itValue != strValues.end(); ++itValue)
    {
        CSetting *settingValue = m_definition->Clone(StringUtils::Format("%s.%d", m_id.c_str(), index++));
        if (settingValue == NULL ||
                !settingValue->FromString(*itValue))
        {
            delete settingValue;
            ret = false;
            break;
        }

        values.push_back(SettingPtr(settingValue));
    }

    if (!ret)
        values.clear();

    return ret;
}
예제 #2
0
파일: Settings.cpp 프로젝트: Anankin/xbmc
bool CSettings::SetList(const std::string &id, const std::vector<CVariant> &value)
{
  CSetting *setting = m_settingsManager->GetSetting(id);
  if (setting == NULL || setting->GetType() != SettingTypeList)
    return false;

  CSettingList *listSetting = static_cast<CSettingList*>(setting);
  SettingPtrList newValues;
  bool ret = true;
  int index = 0;
  for (std::vector<CVariant>::const_iterator itValue = value.begin(); itValue != value.end(); ++itValue)
  {
    CSetting *settingValue = listSetting->GetDefinition()->Clone(StringUtils::Format("%s.%d", listSetting->GetId().c_str(), index++));
    if (settingValue == NULL)
      return false;

    switch (listSetting->GetElementType())
    {
      case SettingTypeBool:
        if (!itValue->isBoolean())
          return false;
        ret = static_cast<CSettingBool*>(settingValue)->SetValue(itValue->asBoolean());
        break;

      case SettingTypeInteger:
        if (!itValue->isInteger())
          return false;
        ret = static_cast<CSettingInt*>(settingValue)->SetValue((int)itValue->asInteger());
        break;

      case SettingTypeNumber:
        if (!itValue->isDouble())
          return false;
        ret = static_cast<CSettingNumber*>(settingValue)->SetValue(itValue->asDouble());
        break;

      case SettingTypeString:
        if (!itValue->isString())
          return false;
        ret = static_cast<CSettingString*>(settingValue)->SetValue(itValue->asString());
        break;

      default:
        ret = false;
        break;
    }

    if (!ret)
    {
      delete settingValue;
      return false;
    }

    newValues.push_back(SettingPtr(settingValue));
  }

  return listSetting->SetValue(newValues);
}
예제 #3
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
void CSettingList::Reset()
{
    CExclusiveLock lock(m_critical);
    SettingPtrList values;
    for (SettingPtrList::const_iterator it = m_defaults.begin(); it != m_defaults.end(); ++it)
        values.push_back(SettingPtr((*it)->Clone((*it)->GetId())));

    SetValue(values);
}
예제 #4
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
std::string CSettingList::toString(const SettingPtrList &values) const
{
    std::vector<std::string> strValues;
    for (SettingPtrList::const_iterator it = values.begin(); it != values.end(); ++it)
    {
        if (*it != NULL)
            strValues.push_back((*it)->ToString());
    }

    return StringUtils::Join(strValues, m_delimiter);
}
예제 #5
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
void CSettingList::SetDefault(const SettingPtrList &values)
{
    CExclusiveLock lock(m_critical);

    m_defaults.clear();
    m_defaults.insert(m_defaults.begin(), values.begin(), values.end());

    if (!m_changed)
    {
        m_values.clear();
        for (SettingPtrList::const_iterator it = m_defaults.begin(); it != m_defaults.end(); ++it)
            m_values.push_back(SettingPtr((*it)->Clone((*it)->GetId())));
    }
}
예제 #6
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
void CSettingList::copy(const SettingPtrList &srcValues, SettingPtrList &dstValues)
{
    dstValues.clear();

    for (SettingPtrList::const_iterator itValue = srcValues.begin(); itValue != srcValues.end(); ++itValue)
    {
        if (*itValue == NULL)
            continue;

        CSetting *valueCopy = (*itValue)->Clone((*itValue)->GetId());
        if (valueCopy == NULL)
            continue;

        dstValues.push_back(SettingPtr(valueCopy));
    }
}
예제 #7
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
bool CSettingList::Equals(const std::string &value) const
{
    SettingPtrList values;
    if (!fromString(value, values) ||
            values.size() != m_values.size())
        return false;

    bool ret = true;
    for (size_t index = 0; index < values.size(); index++)
    {
        if (!m_values[index]->Equals(values[index]->ToString()))
        {
            ret = false;
            break;
        }
    }

    return ret;
}
예제 #8
0
파일: Setting.cpp 프로젝트: B0k0/xbmc
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;
}