示例#1
0
JSONRPC_STATUS CSettingsOperations::ResetSettingValue(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
  string settingId = parameterObject["setting"].asString();

  CSetting* setting = CSettings::Get().GetSetting(settingId);
  if (setting == NULL ||
      !setting->IsVisible())
    return InvalidParams;

  switch (setting->GetType())
  {
  case SettingTypeBool:
  case SettingTypeInteger:
  case SettingTypeNumber:
  case SettingTypeString:
  case SettingTypeList:
    setting->Reset();
    break;

  case SettingTypeNone:
  case SettingTypeAction:
  default:
    return InvalidParams;
  }

  return ACK;
}
示例#2
0
void CSetting::Copy(const CSetting &setting)
{
  SetVisible(setting.IsVisible());
  SetRequirementsMet(setting.MeetsRequirements());
  m_callback = setting.m_callback;
  m_label = setting.m_label;
  m_help = setting.m_help;
  m_level = setting.m_level;
  m_control = setting.m_control;
  m_dependencies = setting.m_dependencies;
  m_updates = setting.m_updates;
  m_changed = setting.m_changed;
}
示例#3
0
JSONRPC_STATUS CSettingsOperations::GetSettingValue(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
  string settingId = parameterObject["setting"].asString();

  CSetting* setting = CSettings::Get().GetSetting(settingId);
  if (setting == NULL ||
      !setting->IsVisible())
    return InvalidParams;

  CVariant value;
  switch (setting->GetType())
  {
  case SettingTypeBool:
    value = static_cast<CSettingBool*>(setting)->GetValue();
    break;

  case SettingTypeInteger:
    value = static_cast<CSettingInt*>(setting)->GetValue();
    break;

  case SettingTypeNumber:
    value = static_cast<CSettingNumber*>(setting)->GetValue();
    break;

  case SettingTypeString:
    value = static_cast<CSettingString*>(setting)->GetValue();
    break;

  case SettingTypeList:
  {
    SerializeSettingListValues(CSettings::Get().GetList(settingId), value);
    break;
  }

  case SettingTypeNone:
  case SettingTypeAction:
  default:
    return InvalidParams;
  }

  result["value"] = value;

  return OK;
}
示例#4
0
void CSetting::Copy(const CSetting &setting)
{
  SetVisible(setting.IsVisible());
  SetRequirementsMet(setting.MeetsRequirements());
  m_callback = setting.m_callback;
  m_label = setting.m_label;
  m_help = setting.m_help;
  m_level = setting.m_level;
  
  delete m_control;
  if (setting.m_control != NULL)
  {
    m_control = m_settingsManager->CreateControl(setting.m_control->GetType());
    *m_control = *setting.m_control;
  }
  else
    m_control = NULL;

  m_dependencies = setting.m_dependencies;
  m_updates = setting.m_updates;
  m_changed = setting.m_changed;
}
void CGUIDialogPeripheralSettings::InitializeSettings()
{
  if (m_item == NULL)
  {
    m_initialising = false;
    return;
  }

  m_initialising = true;
  bool usePopup = g_SkinInfo->HasSkinFile("DialogSlider.xml");

  CPeripheral *peripheral = g_peripherals.GetByPath(m_item->GetPath());
  if (peripheral == NULL)
  {
    CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__);
    m_initialising = false;
    return;
  }

  m_settingsMap.clear();
  CGUIDialogSettingsManualBase::InitializeSettings();

  CSettingCategory *category = AddCategory("peripheralsettings", -1);
  if (category == NULL)
  {
    CLog::Log(LOGERROR, "CGUIDialogPeripheralSettings: unable to setup settings");
    return;
  }

  CSettingGroup *group = AddGroup(category);
  if (group == NULL)
  {
    CLog::Log(LOGERROR, "CGUIDialogPeripheralSettings: unable to setup settings");
    return;
  }
  
  std::vector<CSetting*> settings = peripheral->GetSettings();
  for (std::vector<CSetting*>::iterator itSetting = settings.begin(); itSetting != settings.end(); ++itSetting)
  {
    CSetting *setting = *itSetting;
    if (setting == NULL)
      continue;

    if (!setting->IsVisible())
    {
      CLog::Log(LOGDEBUG, "%s - invisible", __FUNCTION__);
      continue;
    }

    // we need to create a copy of the setting because the CSetting instances
    // are destroyed when leaving the dialog
    CSetting *settingCopy = NULL;
    switch(setting->GetType())
    {
      case SettingTypeBool:
      {
        CSettingBool *settingBool = new CSettingBool(setting->GetId(), *static_cast<CSettingBool*>(setting));
        settingBool->SetControl(GetCheckmarkControl());

        settingCopy = static_cast<CSetting*>(settingBool);
        break;
      }

      case SettingTypeInteger:
      {
        CSettingInt *intSetting = static_cast<CSettingInt*>(setting);
        if (intSetting == NULL)
          break;
        
        CSettingInt *settingInt = new CSettingInt(setting->GetId(), *intSetting);
        if (settingInt->GetOptions().empty())
          settingInt->SetControl(GetSliderControl("integer", false, -1, usePopup, -1, "%i"));
        else
          settingInt->SetControl(GetSpinnerControl("string"));

        settingCopy = static_cast<CSetting*>(settingInt);
        break;
      }

      case SettingTypeNumber:
      {
        CSettingNumber *settingNumber = new CSettingNumber(setting->GetId(), *static_cast<CSettingNumber*>(setting));
        settingNumber->SetControl(GetSliderControl("number", false, -1, usePopup, -1, "%2.2f"));

        settingCopy = static_cast<CSetting*>(settingNumber);
        break;
      }

      case SettingTypeString:
      {
        CSettingString *settingString = new CSettingString(setting->GetId(), *static_cast<CSettingString*>(setting));
        settingString->SetControl(GetEditControl("string"));

        settingCopy = static_cast<CSetting*>(settingString);
        break;
      }

      default:
        // TODO: add more types if needed
        CLog::Log(LOGDEBUG, "%s - unknown type", __FUNCTION__);
        break;
    }

    if (settingCopy != NULL && settingCopy->GetControl() != NULL)
    {
      settingCopy->SetLevel(SettingLevelBasic);
      group->AddSetting(settingCopy);
      m_settingsMap.insert(std::make_pair(setting->GetId(), setting));
    }
  }

  m_initialising = false;
}
void CGUIDialogPeripheralSettings::CreateSettings()
{
  m_bIsInitialising = true;
  m_usePopupSliders = g_SkinInfo->HasSkinFile("DialogSlider.xml");

  if (m_item)
  {
    CPeripheral *peripheral = g_peripherals.GetByPath(m_item->GetPath());
    if (peripheral)
    {
      vector<CSetting *> settings = peripheral->GetSettings();
      for (size_t iPtr = 0; iPtr < settings.size(); iPtr++)
      {
        CSetting *setting = settings[iPtr];
        if (!setting->IsVisible())
        {
          CLog::Log(LOGDEBUG, "%s - invisible", __FUNCTION__);
          continue;
        }

        switch(setting->GetType())
        {
        case SettingTypeBool:
          {
            CSettingBool *boolSetting = (CSettingBool *) setting;
            if (boolSetting)
            {
              m_boolSettings.insert(make_pair(CStdString(boolSetting->GetId()), boolSetting->GetValue()));
              AddBool(m_settingId++, boolSetting->GetLabel(), &m_boolSettings[boolSetting->GetId()], true);
            }
          }
          break;
        case SettingTypeInteger:
          {
            CSettingInt *intSetting = (CSettingInt *) setting;
            if (intSetting)
            {
              if (intSetting->GetControl()->GetFormat() == "integer")
              {
                m_intSettings.insert(make_pair(CStdString(intSetting->GetId()), (float) intSetting->GetValue()));
                AddSlider(m_settingId++, intSetting->GetLabel(), &m_intSettings[intSetting->GetId()], (float)intSetting->GetMinimum(), (float)intSetting->GetStep(), (float)intSetting->GetMaximum(), CGUIDialogVideoSettings::FormatInteger, false);
              }
              else if (intSetting->GetControl()->GetFormat() == "string")
              {
                m_intTextSettings.insert(make_pair(CStdString(intSetting->GetId()), intSetting->GetValue()));
                vector<pair<int, int> > entries;
                StaticIntegerSettingOptions::const_iterator entriesItr = intSetting->GetOptions().begin();
                while (entriesItr != intSetting->GetOptions().end())
                {
                  entries.push_back(make_pair(entriesItr->first, entriesItr->second));
                  ++entriesItr;
                }
                AddSpin(m_settingId++, intSetting->GetLabel(), &m_intTextSettings[intSetting->GetId()], entries);
              }
            }
          }
          break;
        case SettingTypeNumber:
          {
            CSettingNumber *floatSetting = (CSettingNumber *) setting;
            if (floatSetting)
            {
              m_floatSettings.insert(make_pair(CStdString(floatSetting->GetId()), (float)floatSetting->GetValue()));
              AddSlider(m_settingId++, floatSetting->GetLabel(), &m_floatSettings[floatSetting->GetId()], (float)floatSetting->GetMinimum(), (float)floatSetting->GetStep(), (float)floatSetting->GetMaximum(), CGUIDialogVideoSettings::FormatFloat, false);
            }
          }
          break;
        case SettingTypeString:
          {
            CSettingString *stringSetting = (CSettingString *) setting;
            if (stringSetting)
            {
              m_stringSettings.insert(make_pair(CStdString(stringSetting->GetId()), stringSetting->GetValue()));
              AddString(m_settingId++, stringSetting->GetLabel(), &m_stringSettings[stringSetting->GetId()]);
            }
          }
          break;
        default:
          //TODO add more types if needed
          CLog::Log(LOGDEBUG, "%s - unknown type", __FUNCTION__);
          break;
        }
      }
    }
    else
    {
      CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__);
    }
  }

  m_bIsInitialising = false;
}
void CGUIDialogPeripheralSettings::CreateSettings()
{
  m_bIsInitialising = true;
  m_usePopupSliders = g_SkinInfo->HasSkinFile("DialogSlider.xml");

  if (m_item)
  {
    CPeripheral *peripheral = g_peripherals.GetByPath(m_item->GetPath());
    if (peripheral)
    {
      vector<CSetting *> settings = peripheral->GetSettings();
      for (size_t iPtr = 0; iPtr < settings.size(); iPtr++)
      {
        CSetting *setting = settings[iPtr];
        if (!setting->IsVisible())
        {
          CLog::Log(LOGDEBUG, "%s - invisible", __FUNCTION__);
          continue;
        }

        switch(setting->GetType())
        {
        case SETTINGS_TYPE_BOOL:
          {
            CSettingBool *boolSetting = (CSettingBool *) setting;
            if (boolSetting)
            {
              m_boolSettings.insert(make_pair(CStdString(boolSetting->GetSetting()), boolSetting->GetData()));
              AddBool(boolSetting->GetOrder(), boolSetting->GetLabel(), &m_boolSettings[boolSetting->GetSetting()], true);
            }
          }
          break;
        case SETTINGS_TYPE_INT:
          {
            CSettingInt *intSetting = (CSettingInt *) setting;
            if (intSetting)
            {
              if (intSetting->GetControlType() == SPIN_CONTROL_INT)
              {
                m_intSettings.insert(make_pair(CStdString(intSetting->GetSetting()), (float) intSetting->GetData()));
                AddSlider(intSetting->GetOrder(), intSetting->GetLabel(), &m_intSettings[intSetting->GetSetting()], (float)intSetting->m_iMin, (float)intSetting->m_iStep, (float)intSetting->m_iMax, CGUIDialogVideoSettings::FormatInteger, false);
              }
              else if (intSetting->GetControlType() == SPIN_CONTROL_TEXT)
              {
                m_intTextSettings.insert(make_pair(CStdString(intSetting->GetSetting()), intSetting->GetData()));
                vector<pair<int, int> > entries;
                map<int, int>::iterator entriesItr = intSetting->m_entries.begin();
                while (entriesItr != intSetting->m_entries.end())
                {
                  entries.push_back(make_pair(entriesItr->first, entriesItr->second));
                  ++entriesItr;
                }
                AddSpin(intSetting->GetOrder(), intSetting->GetLabel(), &m_intTextSettings[intSetting->GetSetting()], entries);
              }
            }
          }
          break;
        case SETTINGS_TYPE_FLOAT:
          {
            CSettingFloat *floatSetting = (CSettingFloat *) setting;
            if (floatSetting)
            {
              m_floatSettings.insert(make_pair(CStdString(floatSetting->GetSetting()), floatSetting->GetData()));
              AddSlider(floatSetting->GetOrder(), floatSetting->GetLabel(), &m_floatSettings[floatSetting->GetSetting()], floatSetting->m_fMin, floatSetting->m_fStep, floatSetting->m_fMax, CGUIDialogVideoSettings::FormatFloat, false);
            }
          }
          break;
        case SETTINGS_TYPE_STRING:
          {
            CSettingString *stringSetting = (CSettingString *) setting;
            if (stringSetting)
            {
              m_stringSettings.insert(make_pair(CStdString(stringSetting->GetSetting()), stringSetting->GetData()));
              AddString(stringSetting->GetOrder(), stringSetting->GetLabel(), &m_stringSettings[stringSetting->GetSetting()]);
            }
          }
          break;
        default:
          //TODO add more types if needed
          CLog::Log(LOGDEBUG, "%s - unknown type", __FUNCTION__);
          break;
        }
      }
    }
    else
    {
      CLog::Log(LOGDEBUG, "%s - no peripheral", __FUNCTION__);
    }
  }

  m_bIsInitialising = false;
}
示例#8
0
JSONRPC_STATUS CSettingsOperations::SetSettingValue(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
  string settingId = parameterObject["setting"].asString();
  CVariant value = parameterObject["value"];

  CSetting* setting = CSettings::Get().GetSetting(settingId);
  if (setting == NULL ||
      !setting->IsVisible())
    return InvalidParams;

  switch (setting->GetType())
  {
  case SettingTypeBool:
    if (!value.isBoolean())
      return InvalidParams;

    result = static_cast<CSettingBool*>(setting)->SetValue(value.asBoolean());
    break;

  case SettingTypeInteger:
    if (!value.isInteger() && !value.isUnsignedInteger())
      return InvalidParams;

    result = static_cast<CSettingInt*>(setting)->SetValue((int)value.asInteger());
    break;

  case SettingTypeNumber:
    if (!value.isDouble())
      return InvalidParams;

    result = static_cast<CSettingNumber*>(setting)->SetValue(value.asDouble());
    break;

  case SettingTypeString:
    if (!value.isString())
      return InvalidParams;

    result = static_cast<CSettingString*>(setting)->SetValue(value.asString());
    break;

  case SettingTypeList:
  {
    if (!value.isArray())
      return InvalidParams;

    std::vector<CVariant> values;
    for (CVariant::const_iterator_array itValue = value.begin_array(); itValue != value.end_array(); ++itValue)
      values.push_back(*itValue);

    result = CSettings::Get().SetList(settingId, values);
    break;
  }

  case SettingTypeNone:
  case SettingTypeAction:
  default:
    return InvalidParams;
  }

  return OK;
}