void CGUIDialogExtendedProgressBar::UpdateState(unsigned int currentTime)
{
  string strHeader;
  string strTitle;
  float  fProgress(-1.0f);

  {
    CSingleLock lock(m_critSection);

    // delete finished items
    for (int iPtr = m_handles.size() - 1; iPtr >= 0; iPtr--)
    {
      if (m_handles.at(iPtr)->IsFinished())
      {
        delete m_handles.at(iPtr);
        m_handles.erase(m_handles.begin() + iPtr);
      }
    }

    if (!m_handles.size())
    {
      Close(false, 0, true, false);
      return;
    }

    // ensure the current item is in our range
    if (m_iCurrentItem >= m_handles.size())
      m_iCurrentItem = m_handles.size() - 1;

    // update the current item ptr
    if (currentTime > m_iLastSwitchTime &&
        currentTime - m_iLastSwitchTime >= ITEM_SWITCH_TIME_MS)
    {
      m_iLastSwitchTime = currentTime;

      // select next item
      if (++m_iCurrentItem > m_handles.size() - 1)
        m_iCurrentItem = 0;
    }

    CGUIDialogProgressBarHandle *handle = m_handles.at(m_iCurrentItem);
    if (handle)
    {
      strTitle  = handle->Text();
      strHeader = handle->Title();
      fProgress = handle->Percentage();
    }
  }

  SET_CONTROL_LABEL(CONTROL_LABELHEADER, strHeader);
  SET_CONTROL_LABEL(CONTROL_LABELTITLE, strTitle);

  if (fProgress > -1.0f)
  {
    SET_CONTROL_VISIBLE(CONTROL_PROGRESS);
    CGUIProgressControl* pProgressCtrl=(CGUIProgressControl*)GetControl(CONTROL_PROGRESS);
    if (pProgressCtrl) pProgressCtrl->SetPercentage(fProgress);
  }
}