Exemple #1
0
void CGUIWindowSettingsCategory::UpdateControl(const std::string &dependingSetting, const CSettingDependency &dependency)
{
  if (dependingSetting.empty())
    return;

  BaseSettingControlPtr pControl = GetSettingControl(dependingSetting);
  if (pControl == NULL)
    return;

  CSetting *pSetting = pControl->GetSetting();
  if (pSetting == NULL)
    return;

  CheckDependency(pControl, dependency);

  const SettingDependencyMap& deps = m_settings.GetDependencies(pSetting->GetId());
  for (SettingDependencyMap::const_iterator depsIt = deps.begin(); depsIt != deps.end(); depsIt++)
  {
    for (SettingDependencies::const_iterator depIt = depsIt->second.begin(); depIt != depsIt->second.end(); depIt++)
      UpdateControl(depsIt->first, *depIt);
  }

  // update GUI of the changed setting as the change could have been triggered by something else
  pControl->Update();
}
void CGUIWindowSettingsCategory::OnClick(BaseSettingControlPtr pSettingControl)
{
  if (pSettingControl->GetSetting()->GetId() == RESET_SETTING_ID)
  {
    OnAction(CAction(ACTION_SETTINGS_RESET));
    return;
  }

  // we need to first set the delayed setting and then execute OnClick()
  // because OnClick() triggers OnSettingChanged() and there we need to
  // know if the changed setting is delayed or not
  if (pSettingControl->IsDelayed())
  {
    m_delayedSetting = pSettingControl;
    if (m_delayedTimer.IsRunning())
      m_delayedTimer.Restart();
    else
      m_delayedTimer.Start(SETTING_DELAY);

    return;
  }

  // if changing the setting fails
  // we need to restore the proper state
  if (!pSettingControl->OnClick())
    pSettingControl->Update();
}
Exemple #3
0
void CGUIWindowSettingsCategory::UpdateSettings()
{
  for (vector<BaseSettingControlPtr>::iterator it = m_settingControls.begin(); it != m_settingControls.end(); it++)
  {
    BaseSettingControlPtr pSettingControl = *it;
    CSetting *pSetting = pSettingControl->GetSetting();
    CGUIControl *pControl = pSettingControl->GetControl();
    if (pSetting == NULL || pControl == NULL)
      continue;

    // update the setting's control's state (enabled/disabled etc)
    const SettingDependencies &deps = pSetting->GetDependencies();
    for (SettingDependencies::const_iterator dep = deps.begin(); dep != deps.end(); dep++)
    {
      // don't check "update" dependencies here as all the controls are already
      // setup properly based on the existing values
      if (dep->GetType() == SettingDependencyTypeUpdate)
        continue;

      CheckDependency(pSettingControl, *dep);
    }

    pSettingControl->Update();
  }
}
void CGUIDialogMediaFilter::UpdateControls()
{
  for (map<std::string, Filter>::iterator itFilter = m_filters.begin(); itFilter != m_filters.end(); itFilter++)
  {
    if (itFilter->second.controlType != "list")
      continue;

    std::vector<std::string> items;
    int size = GetItems(itFilter->second, items, true);

    std::string label = g_localizeStrings.Get(itFilter->second.label);
    BaseSettingControlPtr control = GetSettingControl(itFilter->second.setting->GetId());
    if (control == NULL)
      continue;

    if (size <= 0 ||
       (size == 1 && itFilter->second.field != FieldSet && itFilter->second.field != FieldTag))
       CONTROL_DISABLE(control->GetID());
    else
    {
      CONTROL_ENABLE(control->GetID());
      label = StringUtils::Format(g_localizeStrings.Get(21470).c_str(), label.c_str(), size);
    }
    SET_CONTROL_LABEL(control->GetID(), label);
  }
}
Exemple #5
0
void CGUIDialogNetworkSetup::OnProtocolChange()
{
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROTOCOL);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
  {
    CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), settingControl->GetID());
    if (!OnMessage(msg))
      return;
    m_protocol = (NET_PROTOCOL)msg.GetParam1();
    // set defaults for the port
    if (m_protocol == NET_PROTOCOL_FTP)
      m_port = "21";
    else if (m_protocol == NET_PROTOCOL_HTTP || 
       m_protocol == NET_PROTOCOL_RSS || 
       m_protocol == NET_PROTOCOL_DAV)
      m_port = "80";
    else if (m_protocol == NET_PROTOCOL_HTTPS || m_protocol == NET_PROTOCOL_DAVS)
      m_port = "443";
    else if (m_protocol == NET_PROTOCOL_SFTP)
      m_port = "22";
    else
      m_port = "0";

    UpdateButtons();
  }
}
Exemple #6
0
void CGUIWindowSettingsCategory::CheckDependency(BaseSettingControlPtr pSettingControl, const CSettingDependency &dependency)
{
  if (pSettingControl == NULL || pSettingControl->GetControl() == NULL)
    return;

  CSetting *pSetting = pSettingControl->GetSetting();
  if (pSetting == NULL)
    return;

  switch (dependency.GetType())
  {
    case SettingDependencyTypeEnable:
      pSettingControl->SetEnabled(dependency.Check());
      break;

    case SettingDependencyTypeUpdate:
    {
      FillControl(pSetting, pSettingControl->GetControl());
      break;
    }

    case SettingDependencyTypeNone:
    default:
      break;
  }
}
void CGUIDialogLockSettings::setLockCodeLabel()
{
  // adjust label2 of the lock code button
  if (m_locks.mode > LOCK_MODE_QWERTY)
    m_locks.mode = LOCK_MODE_EVERYONE;
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_LOCKCODE);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), g_localizeStrings.Get(m_locks.mode == LOCK_MODE_EVERYONE ? 1223 : 12336 + m_locks.mode));
}
void CGUIDialogPVRTimerSettings::SetButtonLabels()
{
  // timer start time
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_TMR_BEGIN);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
  {
    if (!m_bIsNewTimer && m_bStartAnytime)
      SET_CONTROL_LABEL2(settingControl->GetID(), g_localizeStrings.Get(19161)); // "any time"
    else
      SET_CONTROL_LABEL2(settingControl->GetID(), m_timerStartTimeStr);
  }

  // timer end time
  settingControl = GetSettingControl(SETTING_TMR_END);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
  {
    if (!m_bIsNewTimer && m_bEndAnytime)
      SET_CONTROL_LABEL2(settingControl->GetID(), g_localizeStrings.Get(19161)); // "any time"
    else
      SET_CONTROL_LABEL2(settingControl->GetID(), m_timerEndTimeStr);
  }

  // weekdays
  settingControl = GetSettingControl(SETTING_TMR_WEEKDAYS);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(),
                       CPVRTimerInfoTag::GetWeekdaysString(
                        m_iWeekdays, m_timerType->IsEpgBased(), true));
}
void CGUIDialogContentSettings::ToggleState(const std::string &settingid, bool enabled)
{
  BaseSettingControlPtr settingControl = GetSettingControl(settingid);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
  {
    if (enabled)
      CONTROL_ENABLE(settingControl->GetID());
    else
      CONTROL_DISABLE(settingControl->GetID());
  }
}
void CGUIWindowSettingsCategory::OnSettingPropertyChanged(const CSetting *setting, const char *propertyName)
{
  if (setting == NULL || propertyName == NULL)
    return;

  BaseSettingControlPtr settingControl = GetSettingControl(setting->GetId());
  if (settingControl == NULL)
    return;

  settingControl->Update();
}
Exemple #11
0
void CGUIDialogNetworkSetup::OnDeinitWindow(int nextWindowID)
{
  // clear protocol spinner
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROTOCOL);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
  {
    CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), settingControl->GetID());
    OnMessage(msg);
  }

  CGUIDialogSettingsManualBase::OnDeinitWindow(nextWindowID);
}
void CGUIDialogPVRTimerSettings::setButtonLabels()
{
  // timer start time
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_TMR_BEGIN);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), m_timerStartTimeStr);

  // timer end time
  settingControl = GetSettingControl(SETTING_TMR_END);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), m_timerEndTimeStr);
}
void CGUIWindowSettingsCategory::OnSettingChanged(const CSetting *setting)
{
  if (setting == NULL || setting->GetType() == SettingTypeNone ||
      setting->GetType() == SettingTypeAction)
    return;

  BaseSettingControlPtr pControl = GetSettingControl(setting->GetId());
  if (pControl == NULL)
    return;

  pControl->Update();
}
Exemple #14
0
void CGUIDialogSettingsBase::UpdateSettings()
{
  for (vector<BaseSettingControlPtr>::iterator it = m_settingControls.begin(); it != m_settingControls.end(); it++)
  {
    BaseSettingControlPtr pSettingControl = *it;
    CSetting *pSetting = pSettingControl->GetSetting();
    CGUIControl *pControl = pSettingControl->GetControl();
    if (pSetting == NULL || pControl == NULL)
      continue;

    pSettingControl->Update();
  }
}
Exemple #15
0
void CGUIDialogSettingsBase::UpdateSettingControl(BaseSettingControlPtr pSettingControl)
{
  if (pSettingControl == NULL)
    return;

  // we send a thread message so that it's processed the following frame (some settings won't
  // like being changed during Render())
  CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), pSettingControl->GetID());
  g_windowManager.SendThreadMessage(message, GetID());
}
Exemple #16
0
void CGUIWindowSettingsCategory::OnSettingChanged(const CSetting *setting)
{
  if (setting == NULL || setting->GetType() == SettingTypeNone ||
      setting->GetType() == SettingTypeAction)
    return;

  BaseSettingControlPtr pControl = GetSettingControl(setting->GetId());
  if (pControl == NULL)
    return;

  const SettingDependencyMap& deps = m_settings.GetDependencies(setting->GetId());
  for (SettingDependencyMap::const_iterator depsIt = deps.begin(); depsIt != deps.end(); depsIt++)
  {
    for (SettingDependencies::const_iterator depIt = depsIt->second.begin(); depIt != depsIt->second.end(); depIt++)
      UpdateControl(depsIt->first, *depIt);
  }
  
  // update GUI of the changed setting as the change could have been triggered by something else
  pControl->Update();
}
Exemple #17
0
void CGUIDialogSettingsBase::OnClick(BaseSettingControlPtr pSettingControl)
{
  if (AllowResettingSettings() &&
      pSettingControl->GetSetting()->GetId() == SETTINGS_RESET_SETTING_ID)
  {
    OnAction(CAction(ACTION_SETTINGS_RESET));
    return;
  }

  // we need to first set the delayed setting and then execute OnClick()
  // because OnClick() triggers OnSettingChanged() and there we need to
  // know if the changed setting is delayed or not
  if (pSettingControl->IsDelayed())
  {
    m_delayedSetting = pSettingControl;
    // for some controls we need to update its displayed data/text before
    // OnClick() is called after the delay timer has expired because
    // otherwise the displayed value of the control does not match with
    // the user's interaction
    pSettingControl->Update(true);

    // either start or restart the delay timer which will result in a call to
    // the control's OnClick() method to update the setting's value
    if (m_delayedTimer.IsRunning())
      m_delayedTimer.Restart();
    else
      m_delayedTimer.Start(GetDelayMs());

    return;
  }

  // if changing the setting fails
  // we need to restore the proper state
  if (!pSettingControl->OnClick())
    pSettingControl->Update();
}
Exemple #18
0
void CGUIDialogProfileSettings::updateProfileDirectory()
{
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROFILE_DIRECTORY);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), m_directory);
}
Exemple #19
0
CGUIControl* CGUIWindowSettingsCategory::AddSetting(CSetting *pSetting, float width, int &iControlID)
{
  if (pSetting == NULL)
    return NULL;

  BaseSettingControlPtr pSettingControl;
  CGUIControl *pControl = NULL;

  switch (pSetting->GetControl().GetType())
  {
    case SettingControlTypeCheckmark:
    {
      pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
      if (pControl == NULL)
        return NULL;

      ((CGUIRadioButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
      pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeSpinner:
    {
      pControl = new CGUISpinControlEx(*m_pOriginalSpin);
      if (pControl == NULL)
        return NULL;

      ((CGUISpinControlEx *)pControl)->SetText(g_localizeStrings.Get(pSetting->GetLabel()));
      pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeEdit:
    {
      pControl = new CGUIEditControl(*m_pOriginalEdit);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIEditControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
      pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeButton:
    {
      pControl = new CGUIButtonControl(*m_pOriginalButton);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIButtonControl *)pControl)->SetLabel(g_localizeStrings.Get(pSetting->GetLabel()));
      pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeNone:
    default:
      return NULL;
  }

  if (pSetting->GetControl().GetDelayed())
    pSettingControl->SetDelayed();

  return AddSettingControl(pControl, pSettingControl, width, iControlID);
}
Exemple #20
0
CGUIControl* CGUIDialogSettingsBase::AddSetting(CSetting *pSetting, float width, int &iControlID)
{
  if (pSetting == NULL)
    return NULL;

  BaseSettingControlPtr pSettingControl;
  CGUIControl *pControl = NULL;

  // determine the label and any possible indentation in case of sub settings
  string label = GetLocalizedString(pSetting->GetLabel());
  int parentLevels = 0;
  CSetting *parentSetting = GetSetting(pSetting->GetParent());
  while (parentSetting != NULL)
  {
    parentLevels++;
    parentSetting = GetSetting(parentSetting->GetParent());
  }

  if (parentLevels > 0)
  {
    // add additional 2 spaces indentation for anything past one level
    string indentation;
    for (int index = 1; index < parentLevels; index++)
      indentation.append("  ");
    label = StringUtils::Format(g_localizeStrings.Get(168).c_str(), indentation.c_str(), label.c_str());
  }

  // create the proper controls
  if (!pSetting->GetControl())
    return NULL;

  std::string controlType = pSetting->GetControl()->GetType();
  if (controlType == "toggle")
  {
    if (m_pOriginalRadioButton != NULL)
      pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
    if (pControl == NULL)
      return NULL;

    ((CGUIRadioButtonControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "spinner")
  {
    if (m_pOriginalSpin != NULL)
      pControl = new CGUISpinControlEx(*m_pOriginalSpin);
    if (pControl == NULL)
      return NULL;

    ((CGUISpinControlEx *)pControl)->SetText(label);
    pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting));
  }
  else if (controlType == "edit")
  {
    if (m_pOriginalEdit != NULL)
      pControl = new CGUIEditControl(*m_pOriginalEdit);
    if (pControl == NULL)
      return NULL;
      
    ((CGUIEditControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "list")
  {
    if (m_pOriginalButton != NULL)
      pControl = new CGUIButtonControl(*m_pOriginalButton);
    if (pControl == NULL)
      return NULL;

    ((CGUIButtonControl *)pControl)->SetLabel(label);
    pSettingControl.reset(new CGUIControlListSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
  }
  else if (controlType == "button" || controlType == "slider")
  {
    if (controlType == "button" ||
        static_cast<const CSettingControlSlider*>(pSetting->GetControl())->UsePopup())
    {
      if (m_pOriginalButton != NULL)
        pControl = new CGUIButtonControl(*m_pOriginalButton);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIButtonControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
    }
    else
    {
      if (m_pOriginalSlider != NULL)
        pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
      if (pControl == NULL)
        return NULL;
      
      ((CGUISettingsSliderControl *)pControl)->SetText(label);
      pSettingControl.reset(new CGUIControlSliderSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting));
    }
  }
  else if (controlType == "range")
  {
    if (m_pOriginalSlider != NULL)
      pControl = new CGUISettingsSliderControl(*m_pOriginalSlider);
    if (pControl == NULL)
      return NULL;

    ((CGUISettingsSliderControl *)pControl)->SetText(label);
    pSettingControl.reset(new CGUIControlRangeSetting((CGUISettingsSliderControl *)pControl, iControlID, pSetting));
  }
  else
    return NULL;

  if (pSetting->GetControl()->GetDelayed())
    pSettingControl->SetDelayed();

  return AddSettingControl(pControl, pSettingControl, width, iControlID);
}
Exemple #21
0
void CGUIDialogNetworkSetup::UpdateButtons()
{
  // Address label
  BaseSettingControlPtr addressControl = GetSettingControl(SETTING_SERVER_ADDRESS);
  if (addressControl != NULL && addressControl->GetControl() != NULL)
  {
    int addressControlID = addressControl->GetID();
    SET_CONTROL_LABEL2(addressControlID, m_server);
    if (m_protocol == NET_PROTOCOL_SMB)
    {
      SET_CONTROL_LABEL(addressControlID, 1010);  // Server name
    }
    else
    {
      SET_CONTROL_LABEL(addressControlID, 1009);  // Server Address
    }
    SendMessage(GUI_MSG_SET_TYPE, addressControlID, CGUIEditControl::INPUT_TYPE_TEXT, 1016);
  }

  // remote path
  BaseSettingControlPtr pathControl = GetSettingControl(SETTING_REMOTE_PATH);
  if (pathControl != NULL && pathControl->GetControl() != NULL)
  {
    int pathControlID = pathControl->GetID();
    SET_CONTROL_LABEL2(pathControlID, m_path);
    CONTROL_ENABLE_ON_CONDITION(pathControlID, m_protocol != NET_PROTOCOL_UPNP);
    if (m_protocol == NET_PROTOCOL_FTP ||
        m_protocol == NET_PROTOCOL_HTTP ||
        m_protocol == NET_PROTOCOL_HTTPS ||
        m_protocol == NET_PROTOCOL_RSS ||
        m_protocol == NET_PROTOCOL_DAV ||
        m_protocol == NET_PROTOCOL_DAVS||
        m_protocol == NET_PROTOCOL_SFTP||
        m_protocol == NET_PROTOCOL_NFS)
    {
      SET_CONTROL_LABEL(pathControlID, 1011);  // Remote Path
    }
    else
    {
      SET_CONTROL_LABEL(pathControlID, 1012);  // Shared Folder
    }
    SendMessage(GUI_MSG_SET_TYPE, pathControlID, CGUIEditControl::INPUT_TYPE_TEXT, 1017);
  }

  // username
  BaseSettingControlPtr userControl = GetSettingControl(SETTING_USERNAME);
  if (userControl != NULL && userControl->GetControl() != NULL)
  {
    int userControlID = userControl->GetID();
    SET_CONTROL_LABEL2(userControlID, m_username);
    CONTROL_ENABLE_ON_CONDITION(userControlID, m_protocol != NET_PROTOCOL_UPNP &&
                                               m_protocol != NET_PROTOCOL_NFS);

    SendMessage(GUI_MSG_SET_TYPE, userControlID, CGUIEditControl::INPUT_TYPE_TEXT, 1019);
  }

  // port
  BaseSettingControlPtr portControl = GetSettingControl(SETTING_PORT_NUMBER);
  if (portControl != NULL && portControl->GetControl() != NULL)
  {
    int portControlID = portControl->GetID();
    SET_CONTROL_LABEL2(portControlID, m_port);
    CONTROL_ENABLE_ON_CONDITION(portControlID, m_protocol == NET_PROTOCOL_FTP ||
                                               m_protocol == NET_PROTOCOL_HTTP ||
                                               m_protocol == NET_PROTOCOL_HTTPS ||
                                               m_protocol == NET_PROTOCOL_DAV ||
                                               m_protocol == NET_PROTOCOL_DAVS ||
                                               m_protocol == NET_PROTOCOL_RSS ||
                                               m_protocol == NET_PROTOCOL_SFTP);

    SendMessage(GUI_MSG_SET_TYPE, portControlID, CGUIEditControl::INPUT_TYPE_NUMBER, 1018);
  }

  // password
  BaseSettingControlPtr passControl = GetSettingControl(SETTING_PASSWORD);
  if (passControl != NULL && passControl->GetControl() != NULL)
  {
    int passControlID = passControl->GetID();
    SET_CONTROL_LABEL2(passControlID, m_password);
    CONTROL_ENABLE_ON_CONDITION(passControlID, m_protocol != NET_PROTOCOL_UPNP &&
                                                  m_protocol != NET_PROTOCOL_NFS);

    SendMessage(GUI_MSG_SET_TYPE, passControlID, CGUIEditControl::INPUT_TYPE_PASSWORD, 12326);
  }

  // server browse should be disabled if we are in FTP, HTTP, HTTPS, RSS, DAV or DAVS
  BaseSettingControlPtr browseControl = GetSettingControl(SETTING_SERVER_BROWSE);
  if (browseControl != NULL && browseControl->GetControl() != NULL)
  {
    int browseControlID = browseControl->GetID();
    CONTROL_ENABLE_ON_CONDITION(browseControlID, !m_server.empty() || !(m_protocol == NET_PROTOCOL_FTP ||
                                                                        m_protocol == NET_PROTOCOL_HTTP ||
                                                                        m_protocol == NET_PROTOCOL_HTTPS ||
                                                                        m_protocol == NET_PROTOCOL_DAV ||
                                                                        m_protocol == NET_PROTOCOL_DAVS ||
                                                                        m_protocol == NET_PROTOCOL_RSS ||
                                                                        m_protocol == NET_PROTOCOL_SFTP));
  }
}
Exemple #22
0
void CGUIDialogProfileSettings::UpdateProfileImage()
{
  BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROFILE_IMAGE);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), URIUtils::GetFileName(m_thumb));
}
CGUIControl* CGUIWindowSettingsCategory::AddSetting(CSetting *pSetting, float width, int &iControlID)
{
  if (pSetting == NULL)
    return NULL;

  BaseSettingControlPtr pSettingControl;
  CGUIControl *pControl = NULL;

  // determine the label and any possible indentation in case of sub settings
  string label = g_localizeStrings.Get(pSetting->GetLabel());
  int parentLevels = 0;
  CSetting *parentSetting = m_settings.GetSetting(pSetting->GetParent());
  while (parentSetting != NULL)
  {
    parentLevels++;
    parentSetting = m_settings.GetSetting(parentSetting->GetParent());
  }

  if (parentLevels > 0)
  {
    // add additional 2 spaces indentation for anything past one level
    string indentation;
    for (int index = 1; index < parentLevels; index++)
      indentation.append("  ");
    label = StringUtils::Format(g_localizeStrings.Get(168).c_str(), indentation.c_str(), label.c_str());
  }

  // create the proper controls
  switch (pSetting->GetControl().GetType())
  {
    case SettingControlTypeCheckmark:
    {
      pControl = new CGUIRadioButtonControl(*m_pOriginalRadioButton);
      if (pControl == NULL)
        return NULL;

      ((CGUIRadioButtonControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlRadioButtonSetting((CGUIRadioButtonControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeSpinner:
    {
      pControl = new CGUISpinControlEx(*m_pOriginalSpin);
      if (pControl == NULL)
        return NULL;

      ((CGUISpinControlEx *)pControl)->SetText(label);
      pSettingControl.reset(new CGUIControlSpinExSetting((CGUISpinControlEx *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeEdit:
    {
      pControl = new CGUIEditControl(*m_pOriginalEdit);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIEditControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlEditSetting((CGUIEditControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeList:
    {
      pControl = new CGUIButtonControl(*m_pOriginalButton);
      if (pControl == NULL)
        return NULL;

      ((CGUIButtonControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlListSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeButton:
    {
      pControl = new CGUIButtonControl(*m_pOriginalButton);
      if (pControl == NULL)
        return NULL;
      
      ((CGUIButtonControl *)pControl)->SetLabel(label);
      pSettingControl.reset(new CGUIControlButtonSetting((CGUIButtonControl *)pControl, iControlID, pSetting));
      break;
    }
    
    case SettingControlTypeNone:
    default:
      return NULL;
  }

  if (pSetting->GetControl().GetDelayed())
    pSettingControl->SetDelayed();

  return AddSettingControl(pControl, pSettingControl, width, iControlID);
}
void CGUIDialogContentSettings::SetLabel2(const std::string &settingid, const std::string &label)
{
  BaseSettingControlPtr settingControl = GetSettingControl(settingid);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_LABEL2(settingControl->GetID(), label);
}
void CGUIDialogContentSettings::SetFocus(const std::string &settingid)
{
  BaseSettingControlPtr settingControl = GetSettingControl(settingid);
  if (settingControl != NULL && settingControl->GetControl() != NULL)
    SET_CONTROL_FOCUS(settingControl->GetID(), 0);
}
Exemple #26
0
bool CGUIDialogSettingsBase::OnMessage(CGUIMessage &message)
{
  switch (message.GetMessage())
  {
    case GUI_MSG_WINDOW_INIT:
    {
      m_delayedSetting.reset();
      if (message.GetParam1() != WINDOW_INVALID)
      { // coming to this window first time (ie not returning back from some other window)
        // so we reset our section and control states
        m_iCategory = 0;
        ResetControlStates();
      }

      if (AllowResettingSettings())
      {
        m_resetSetting = new CSettingAction(SETTINGS_RESET_SETTING_ID);
        m_resetSetting->SetLabel(10041);
        m_resetSetting->SetHelp(10045);
        m_resetSetting->SetControl(CreateControl("button"));
      }

      m_dummyCategory = new CSettingCategory(SETTINGS_EMPTY_CATEGORY_ID);
      m_dummyCategory->SetLabel(10046);
      m_dummyCategory->SetHelp(10047);
      break;
    }

    case GUI_MSG_WINDOW_DEINIT:
    {
      // cancel any delayed changes
      if (m_delayedSetting != NULL)
      {
        m_delayedTimer.Stop();
        CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), m_delayedSetting->GetID());
        OnMessage(message);
      }
      
      CGUIDialog::OnMessage(message);
      FreeControls();
      return true;
    }
    
    case GUI_MSG_FOCUSED:
    {
      CGUIDialog::OnMessage(message);
      int focusedControl = GetFocusedControlID();

      // cancel any delayed changes
      if (m_delayedSetting != NULL && m_delayedSetting->GetID() != focusedControl)
      {
        m_delayedTimer.Stop();
        CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), m_delayedSetting->GetID(), 1); // param1 = 1 for "reset the control if it's invalid"
        g_windowManager.SendThreadMessage(message, GetID());
      }
      // update the value of the previous setting (in case it was invalid)
      else if (m_iSetting >= CONTROL_SETTINGS_START_CONTROL && m_iSetting < (int)(CONTROL_SETTINGS_START_CONTROL + m_settingControls.size()))
      {
        BaseSettingControlPtr control = GetSettingControl(m_iSetting);
        if (control != NULL && control->GetSetting() != NULL && !control->IsValid())
        {
          CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), m_iSetting, 1); // param1 = 1 for "reset the control if it's invalid"
          g_windowManager.SendThreadMessage(message, GetID());
        }
      }

      CVariant description;

      // check if we have changed the category and need to create new setting controls
      if (focusedControl >= CONTROL_SETTINGS_START_BUTTONS && focusedControl < (int)(CONTROL_SETTINGS_START_BUTTONS + m_categories.size()))
      {
        int categoryIndex = focusedControl - CONTROL_SETTINGS_START_BUTTONS;
        const CSettingCategory* category = m_categories.at(categoryIndex);
        if (categoryIndex != m_iCategory)
        {
          if (!category->CanAccess())
          {
            // unable to go to this category - focus the previous one
            SET_CONTROL_FOCUS(CONTROL_SETTINGS_START_BUTTONS + m_iCategory, 0);
            return false;
          }

          m_iCategory = categoryIndex;
          CreateSettings();
        }

        description = category->GetHelp();
      }
      else if (focusedControl >= CONTROL_SETTINGS_START_CONTROL && focusedControl < (int)(CONTROL_SETTINGS_START_CONTROL + m_settingControls.size()))
      {
        m_iSetting = focusedControl;
        CSetting *setting = GetSettingControl(focusedControl)->GetSetting();
        if (setting != NULL)
          description = setting->GetHelp();
      }

      // set the description of the currently focused category/setting
      if (description.isInteger() ||
          (description.isString() && !description.empty()))
        SetDescription(description);

      return true;
    }

    case GUI_MSG_CLICKED:
    {
      int iControl = message.GetSenderId();
      if (iControl == CONTROL_SETTINGS_OKAY_BUTTON)
      {
        OnOkay();
        Close();
        return true;
      }

      if (iControl == CONTROL_SETTINGS_CANCEL_BUTTON)
      {
        OnCancel();
        Close();
        return true;
      }

      BaseSettingControlPtr control = GetSettingControl(iControl);
      if (control != NULL)
        OnClick(control);

      break;
    }
    
    case GUI_MSG_UPDATE_ITEM:
    {
      if (m_delayedSetting != NULL && m_delayedSetting->GetID() == message.GetControlId())
      {
        // first get the delayed setting and reset its member variable
        // to avoid handling the delayed setting twice in case the OnClick()
        // performed later causes the window to be deinitialized (e.g. when
        // changing the language)
        BaseSettingControlPtr delayedSetting = m_delayedSetting;
        m_delayedSetting.reset();

        // if updating the setting fails and param1 has been specifically set
        // we need to call OnSettingChanged() to restore a valid value in the
        // setting control
        if (!delayedSetting->OnClick() && message.GetParam1() != 0)
          OnSettingChanged(delayedSetting->GetSetting());
        return true;
      }

      if (message.GetControlId() >= CONTROL_SETTINGS_START_CONTROL && message.GetControlId() < (int)(CONTROL_SETTINGS_START_CONTROL + m_settingControls.size()))
      {
        BaseSettingControlPtr settingControl = GetSettingControl(message.GetControlId());
        if (settingControl.get() != NULL && settingControl->GetSetting() != NULL)
        {
          settingControl->Update();
          return true;
        }
      }
      break;
    }
    
    case GUI_MSG_UPDATE:
    {
      if (IsActive() && HasID(message.GetSenderId()))
      {
        int focusedControl = GetFocusedControlID();
        CreateSettings();
        SET_CONTROL_FOCUS(focusedControl, 0);
      }
      break;
    }

    default:
      break;
  }

  return CGUIDialog::OnMessage(message);
}
bool CGUIWindowSettingsCategory::OnMessage(CGUIMessage &message)
{
  switch (message.GetMessage())
  {
    case GUI_MSG_WINDOW_INIT:
    {
      m_delayedSetting.reset();
      if (message.GetParam1() != WINDOW_INVALID && !m_returningFromSkinLoad)
      { // coming to this window first time (ie not returning back from some other window)
        // so we reset our section and control states
        m_iCategory = 0;
        ResetControlStates();
      }
      
      m_iSection = (int)message.GetParam2() - (int)CGUIWindow::GetID();
      CGUIWindow::OnMessage(message);
      m_returningFromSkinLoad = false;
      return true;
    }

    case GUI_MSG_WINDOW_DEINIT:
    {
      // cancel any delayed changes
      if (m_delayedSetting != NULL)
      {
        m_delayedTimer.Stop();
        CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), GetID());
        OnMessage(message);
      }
      
      CGUIWindow::OnMessage(message);
      FreeControls();
      return true;
    }
    
    case GUI_MSG_FOCUSED:
    {
      CGUIWindow::OnMessage(message);
      if (!m_returningFromSkinLoad)
      {
        int focusedControl = GetFocusedControlID();

        // cancel any delayed changes if the focused control has changed
        if (m_delayedSetting != NULL && m_delayedSetting->GetID() != focusedControl)
        {
          m_delayedTimer.Stop();
          CGUIMessage message(GUI_MSG_UPDATE_ITEM, GetID(), GetID(), 1); // param1 = 1 for "reset the control if it's invalid"
          g_windowManager.SendThreadMessage(message, GetID());
        }

        // check if we have changed the category and need to create new setting controls
        if (focusedControl >= CONTROL_START_BUTTONS && focusedControl < (int)(CONTROL_START_BUTTONS + m_categories.size()))
        {
          int categoryIndex = focusedControl - CONTROL_START_BUTTONS;
          if (categoryIndex != m_iCategory)
          {
            if (!m_categories[categoryIndex]->CanAccess())
            {
              // unable to go to this category - focus the previous one
              SET_CONTROL_FOCUS(CONTROL_START_BUTTONS + m_iCategory, 0);
              return false;
            }

            m_iCategory = categoryIndex;
            CreateSettings();
          }
        }
        else if (focusedControl >= CONTROL_START_CONTROL && focusedControl < (int)(CONTROL_START_CONTROL + m_settingControls.size()))
        {
          CSetting *setting = GetSettingControl(focusedControl)->GetSetting();
          if (setting != NULL)
            SetDescription(setting->GetHelp());
        }
      }
      return true;
    }

    case GUI_MSG_CLICKED:
    {
      BaseSettingControlPtr control = GetSettingControl(message.GetSenderId());
      if (control != NULL)
        OnClick(control);

      break;
    }

    case GUI_MSG_LOAD_SKIN:
    {
      if (IsActive())
        m_returningFromSkinLoad = true;
      break;
    }
    
    case GUI_MSG_UPDATE_ITEM:
    {
      if (m_delayedSetting != NULL)
      {
        // first get the delayed setting and reset its member variable
        // to avoid handling the delayed setting twice in case the OnClick()
        // performed later causes the window to be deinitialized (e.g. when
        // changing the language)
        BaseSettingControlPtr delayedSetting = m_delayedSetting;
        m_delayedSetting.reset();

        // if updating the setting fails and param1 has been specifically set
        // we need to call OnSettingChanged() to restore a valid value in the
        // setting control
        if (!delayedSetting->OnClick() && message.GetParam1() != 0)
          OnSettingChanged(delayedSetting->GetSetting());
        return true;
      }
      break;
    }
    
    case GUI_MSG_UPDATE:
    {
      if (IsActive() && HasID(message.GetSenderId()))
      {
        int focusedControl = GetFocusedControlID();
        CreateSettings();
        SET_CONTROL_FOCUS(focusedControl, 0);
      }
      break;
    }

    case GUI_MSG_NOTIFY_ALL:
    {
      if (message.GetParam1() == GUI_MSG_WINDOW_RESIZE)
      {
        if (IsActive() && CDisplaySettings::Get().GetCurrentResolution() != g_graphicsContext.GetVideoResolution())
        {
          CDisplaySettings::Get().SetCurrentResolution(g_graphicsContext.GetVideoResolution(), true);
          CreateSettings();
        }
      }
      break;
    }
  }

  return CGUIWindow::OnMessage(message);
}