Exemple #1
0
void CGUIWindowSettingsCategory::FillControl(CSetting *pSetting, CGUIControl *pSettingControl)
{
  void *filler = CSettings::Get().GetSettingOptionsFiller(pSetting);
  if (filler == NULL)
    return;

  if (pSetting->GetType() == SettingTypeInteger)
  {
    CSettingInt *pSettingInt = (CSettingInt*)pSetting;

    // get the list of options and the current option
    IntegerSettingOptions options;
    int currentOption = pSettingInt->GetValue();
    ((IntegerSettingOptionsFiller)filler)(pSetting, options, currentOption);

    // clear the spinner control
    CGUISpinControlEx *pSpinControl = (CGUISpinControlEx *)pSettingControl;
    pSpinControl->Clear();

    // fill the spinner control
    for (IntegerSettingOptions::const_iterator option = options.begin(); option != options.end(); option++)
      pSpinControl->AddLabel(option->first, option->second);

    // set the current option
    pSpinControl->SetValue(currentOption);

    // check if the current setting has changed
    if (currentOption != pSettingInt->GetValue())
      pSettingInt->SetValue(currentOption);
  }
  else if (pSetting->GetType() == SettingTypeString)
  {
    CSettingString *pSettingString = (CSettingString*)pSetting;

    // get the list of options and the current option
    StringSettingOptions options;
    std::string currentOption = pSettingString->GetValue();
    ((StringSettingOptionsFiller)filler)(pSetting, options, currentOption);

    // clear the spinner control
    CGUISpinControlEx *pSpinControl = (CGUISpinControlEx *)pSettingControl;
    pSpinControl->Clear();

    // fill the spinner control
    for (StringSettingOptions::const_iterator option = options.begin(); option != options.end(); option++)
      pSpinControl->AddLabel(option->first, option->second);

    // set the current option
    pSpinControl->SetStringValue(currentOption);

    // check if the current setting has changed
    if (currentOption.compare(pSettingString->GetValue()) != 0)
      pSettingString->SetValue(currentOption);
  }
}
Exemple #2
0
bool CSettingsOperations::SerializeSettingInt(std::shared_ptr<const CSettingInt> setting, CVariant &obj)
{
  if (setting == NULL)
    return false;

  obj["value"] = setting->GetValue();
  obj["default"] = setting->GetDefault();

  switch (setting->GetOptionsType())
  {
    case SettingOptionsTypeStaticTranslatable:
    {
      obj["options"] = CVariant(CVariant::VariantTypeArray);
      const TranslatableIntegerSettingOptions& options = setting->GetTranslatableOptions();
      for (TranslatableIntegerSettingOptions::const_iterator itOption = options.begin(); itOption != options.end(); ++itOption)
      {
        CVariant varOption(CVariant::VariantTypeObject);
        varOption["label"] = g_localizeStrings.Get(itOption->first);
        varOption["value"] = itOption->second;
        obj["options"].push_back(varOption);
      }
      break;
    }

    case SettingOptionsTypeStatic:
    {
      obj["options"] = CVariant(CVariant::VariantTypeArray);
      const IntegerSettingOptions& options = setting->GetOptions();
      for (IntegerSettingOptions::const_iterator itOption = options.begin(); itOption != options.end(); ++itOption)
      {
        CVariant varOption(CVariant::VariantTypeObject);
        varOption["label"] = itOption->first;
        varOption["value"] = itOption->second;
        obj["options"].push_back(varOption);
      }
      break;
    }

    case SettingOptionsTypeDynamic:
    {
      obj["options"] = CVariant(CVariant::VariantTypeArray);
      IntegerSettingOptions options = std::const_pointer_cast<CSettingInt>(setting)->UpdateDynamicOptions();
      for (IntegerSettingOptions::const_iterator itOption = options.begin(); itOption != options.end(); ++itOption)
      {
        CVariant varOption(CVariant::VariantTypeObject);
        varOption["label"] = itOption->first;
        varOption["value"] = itOption->second;
        obj["options"].push_back(varOption);
      }
      break;
    }

    case SettingOptionsTypeNone:
    default:
      obj["minimum"] = setting->GetMinimum();
      obj["step"] = setting->GetStep();
      obj["maximum"] = setting->GetMaximum();
      break;
  }

  return true;
}