Beispiel #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);
  }
}
Beispiel #2
0
bool CSettingsOperations::SerializeSettingString(std::shared_ptr<const CSettingString> setting, CVariant &obj)
{
  if (setting == NULL)
    return false;

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

  obj["allowempty"] = setting->AllowEmpty();

  switch (setting->GetOptionsType())
  {
    case SettingOptionsTypeStaticTranslatable:
    {
      obj["options"] = CVariant(CVariant::VariantTypeArray);
      const TranslatableStringSettingOptions& options = setting->GetTranslatableOptions();
      for (TranslatableStringSettingOptions::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 StringSettingOptions& options = setting->GetOptions();
      for (StringSettingOptions::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);
      StringSettingOptions options = std::const_pointer_cast<CSettingString>(setting)->UpdateDynamicOptions();
      for (StringSettingOptions::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:
      break;
  }

  std::shared_ptr<const ISettingControl> control = setting->GetControl();
  if (control->GetFormat() == "path")
  {
    if (!SerializeSettingPath(std::static_pointer_cast<const CSettingPath>(setting), obj))
      return false;
  }
  if (control->GetFormat() == "addon")
  {
    if (!SerializeSettingAddon(std::static_pointer_cast<const CSettingAddon>(setting), obj))
      return false;
  }
  if (control->GetFormat() == "date")
  {
    if (!SerializeSettingDate(std::static_pointer_cast<const CSettingDate>(setting), obj))
      return false;
  }
  if (control->GetFormat() == "time")
  {
    if (!SerializeSettingTime(std::static_pointer_cast<const CSettingTime>(setting), obj))
      return false;
  }

  return true;
}