示例#1
0
// \brief Show CGUIDialogMediaSource dialog and prompt for a new media source.
// \return True if the media source is added, false otherwise.
bool CGUIDialogMediaSource::ShowAndAddMediaSource(const std::string &type)
{
  CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE);
  if (!dialog) return false;
  dialog->Initialize();
  dialog->SetShare(CMediaSource());
  dialog->SetTypeOfMedia(type);
  dialog->Open();
  bool confirmed(dialog->IsConfirmed());
  if (confirmed)
  { // yay, add this share
    CMediaSource share;
    unsigned int i, j = 2;
    bool bConfirmed = false;
    VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(type);
    std::string strName = dialog->m_name;
    while (!bConfirmed)
    {
      for (i = 0;i<pShares->size();++i)
      {
        if (StringUtils::EqualsNoCase((*pShares)[i].strName, strName))
          break;
      }
      if (i < pShares->size()) // found a match -  try next
        strName = StringUtils::Format("%s (%i)", dialog->m_name.c_str(), j++);
      else
        bConfirmed = true;
    }
    share.FromNameAndPaths(type, strName, dialog->GetPaths());
    if (dialog->m_paths->Size() > 0) {
      share.m_strThumbnailImage = dialog->m_paths->Get(0)->GetArt("thumb");
    }
    CMediaSourceSettings::GetInstance().AddShare(type, share);
  }
  dialog->m_paths->Clear();
  return confirmed;
}
示例#2
0
bool CGUIDialogMediaSource::ShowAndEditMediaSource(const std::string &type, const CMediaSource &share)
{
  std::string strOldName = share.strName;
  CGUIDialogMediaSource *dialog = (CGUIDialogMediaSource *)g_windowManager.GetWindow(WINDOW_DIALOG_MEDIA_SOURCE);
  if (!dialog) return false;
  dialog->Initialize();
  dialog->SetShare(share);
  dialog->SetTypeOfMedia(type, true);
  dialog->Open();
  bool confirmed(dialog->IsConfirmed());
  if (confirmed)
  { // yay, add this share
    unsigned int i, j = 2;
    bool bConfirmed = false;
    VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(type);
    std::string strName = dialog->m_name;
    while (!bConfirmed)
    {
      for (i = 0;i<pShares->size();++i)
      {
        if (StringUtils::EqualsNoCase((*pShares)[i].strName, strName))
          break;
      }
      if (i < pShares->size() && (*pShares)[i].strName != strOldName) // found a match -  try next
        strName = StringUtils::Format("%s (%i)", dialog->m_name.c_str(), j++);
      else
        bConfirmed = true;
    }

    CMediaSource newShare;
    newShare.FromNameAndPaths(type, strName, dialog->GetPaths());
    CMediaSourceSettings::GetInstance().UpdateShare(type, strOldName, newShare);
  }
  dialog->m_paths->Clear();
  return confirmed;
}