Exemple #1
0
void CPVRClients::ProcessMenuHooks(int iClientID, PVR_MENUHOOK_CAT cat)
{
  PVR_MENUHOOKS *hooks = NULL;

  // get client id
  if (iClientID < 0 && cat == PVR_MENUHOOK_SETTING)
  {
    PVR_CLIENTMAP clients;
    GetConnectedClients(clients);

    if (clients.size() == 1)
    {
      iClientID = clients.begin()->first;
    }
    else if (clients.size() > 1)
    {
      // have user select client
      CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
      pDialog->Reset();
      pDialog->SetHeading(19196);

      PVR_CLIENTMAP_ITR itrClients;
      for (itrClients = clients.begin(); itrClients != clients.end(); itrClients++)
      {
        pDialog->Add(itrClients->second->GetBackendName());
      }
      pDialog->DoModal();

      int selection = pDialog->GetSelectedLabel();
      if (selection >= 0)
      {
        itrClients = clients.begin();
        for (int i = 0; i < selection; i++)
          itrClients++;
        iClientID = itrClients->first;
      }
    }
  }

  if (iClientID < 0)
    iClientID = GetPlayingClientID();

  PVR_CLIENT client;
  if (GetConnectedClient(iClientID, client) && client->HaveMenuHooks(cat))
  {
    hooks = client->GetMenuHooks();
    std::vector<int> hookIDs;

    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetHeading(19196);
    for (unsigned int i = 0; i < hooks->size(); i++)
      pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId));
    pDialog->DoModal();

    int selection = pDialog->GetSelectedLabel();
    if (selection >= 0)
      client->CallMenuHook(hooks->at(selection));
  }
}
Exemple #2
0
void CPVRClients::ProcessMenuHooks(int iClientID)
{
  PVR_MENUHOOKS *hooks = NULL;
  CSingleLock lock(m_critSection);

  if (iClientID < 0)
    iClientID = GetPlayingClientID();

  if (GetMenuHooks(iClientID, hooks))
  {
    boost::shared_ptr<CPVRClient> client = m_clientMap.find(iClientID)->second;
    lock.Leave();
    std::vector<long> hookIDs;

    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetHeading(19196);
    for (unsigned int i = 0; i < hooks->size(); i++)
      pDialog->Add(client->GetString(hooks->at(i).string_id));
    pDialog->DoModal();

    int selection = pDialog->GetSelectedLabel();
    if (selection >= 0)
    {
      client->CallMenuHook(hooks->at(selection));
    }
  }
  else
  {
    CLog::Log(LOGERROR, "PVR - %s - cannot find client %d",__FUNCTION__, iClientID);
  }
}
void CPVRClients::ProcessMenuHooks(int iClientID)
{
  PVR_MENUHOOKS *hooks = NULL;

  if (iClientID < 0)
    iClientID = GetPlayingClientID();

  if (GetMenuHooks(iClientID, hooks))
  {
    boost::shared_ptr<CPVRClient> client;
    if (!GetValidClient(iClientID, client))
      return;
    std::vector<int> hookIDs;

    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetHeading(19196);
    for (unsigned int i = 0; i < hooks->size(); i++)
      pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId));
    pDialog->DoModal();

    int selection = pDialog->GetSelectedLabel();
    if (selection >= 0)
    {
      client->CallMenuHook(hooks->at(selection));
    }
  }
  else
  {
    CLog::Log(LOGERROR, "PVR - %s - cannot find client %d",__FUNCTION__, iClientID);
  }
}
Exemple #4
0
void CPVRClients::ProcessMenuHooks(int iClientID)
{
  PVR_MENUHOOKS *hooks = NULL;

  if (iClientID < 0)
    iClientID = GetPlayingClientID();

  boost::shared_ptr<CPVRClient> client;
  if (GetConnectedClient(iClientID, client) && client->HaveMenuHooks())
  {
    hooks = client->GetMenuHooks();
    std::vector<int> hookIDs;

    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetHeading(19196);
    for (unsigned int i = 0; i < hooks->size(); i++)
      pDialog->Add(client->GetString(hooks->at(i).iLocalizedStringId));
    pDialog->DoModal();

    int selection = pDialog->GetSelectedLabel();
    if (selection >= 0)
      client->CallMenuHook(hooks->at(selection));
  }
}
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel()
{
  int iSelection = 0;
  if (g_PVRClients->ConnectedClientAmount() > 1)
  {
    CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    if (!pDlgSelect)
      return false;

    pDlgSelect->SetHeading(19213); // Select Client

    PVR_CLIENT_ITR itr;
    for (itr = m_clientsWithSettingsList.begin() ; itr != m_clientsWithSettingsList.end(); ++itr)
      pDlgSelect->Add((*itr)->Name());
    pDlgSelect->DoModal();

    iSelection = pDlgSelect->GetSelectedLabel();
  }

  if (iSelection >= 0 && iSelection < (int)m_clientsWithSettingsList.size())
  {
    int iClientID = m_clientsWithSettingsList[iSelection]->GetID();

    CPVRChannelPtr channel(new CPVRChannel(m_bIsRadio));
    channel->SetChannelName(g_localizeStrings.Get(19204)); // New channel
    channel->SetEPGEnabled(g_PVRClients->SupportsEPG(iClientID));
    channel->SetClientID(iClientID);

    if (g_PVRClients->OpenDialogChannelAdd(channel))
      Update();
    else
      CGUIDialogOK::ShowAndGetInput(2103, 0, 16029, 0);  // Add-on error;Check the log file for details.
  }
  return true;
}
Exemple #6
0
PVR_ERROR CPVRClients::DeleteAllRecordingsFromTrash()
{
  PVR_ERROR error(PVR_ERROR_NO_ERROR);
  PVR_CLIENTMAP clients;
  GetConnectedClients(clients);

  std::vector<PVR_CLIENT> suppClients;
  for (PVR_CLIENTMAP_CITR itrClients = clients.begin(); itrClients != clients.end(); ++itrClients)
  {
    if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0)
      suppClients.push_back(itrClients->second);
  }

  int selection = 0;
  if (suppClients.size() > 1)
  {
    // have user select client
    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetHeading(CVariant{19292});       //Delete all permanently
    pDialog->Add(g_localizeStrings.Get(24032)); // All Add-ons

    PVR_CLIENTMAP_CITR itrClients;
    for (itrClients = clients.begin(); itrClients != clients.end(); ++itrClients)
    {
      if (itrClients->second->SupportsRecordingsUndelete() && itrClients->second->GetRecordingsAmount(true) > 0)
        pDialog->Add(itrClients->second->GetBackendName());
    }
    pDialog->Open();
    selection = pDialog->GetSelectedLabel();
  }

  if (selection == 0)
  {
    typedef std::vector<PVR_CLIENT>::const_iterator suppClientsCITR;
    for (suppClientsCITR itrSuppClients = suppClients.begin(); itrSuppClients != suppClients.end(); ++itrSuppClients)
    {
      PVR_ERROR currentError = (*itrSuppClients)->DeleteAllRecordingsFromTrash();
      if (currentError != PVR_ERROR_NO_ERROR)
      {
        CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, (*itrSuppClients)->GetID(), CPVRClient::ToString(currentError));
        error = currentError;
      }
    }
  }
  else if (selection >= 1 && selection <= (int)suppClients.size())
  {
    PVR_ERROR currentError = suppClients[selection-1]->DeleteAllRecordingsFromTrash();
    if (currentError != PVR_ERROR_NO_ERROR)
    {
      CLog::Log(LOGERROR, "PVR - %s - cannot delete all recordings from client '%d': %s",__FUNCTION__, suppClients[selection-1]->GetID(), CPVRClient::ToString(currentError));
      error = currentError;
    }
  }

  return error;
}
Exemple #7
0
void CGUIWindowVideoNav::OnLinkMovieToTvShow(int itemnumber, bool bRemove)
{
  CFileItemList list;
  if (bRemove)
  {
    vector<int> ids;
    if (!m_database.GetLinksToTvShow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId,ids))
      return;
    for (unsigned int i=0;i<ids.size();++i)
    {
      CVideoInfoTag tag;
      m_database.GetTvShowInfo("",tag,ids[i]);
      CFileItemPtr show(new CFileItem(tag));
      list.Add(show);
    }
  }
  else
  {
    m_database.GetTvShowsNav("videodb://2/2",list);

    // remove already linked shows
    vector<int> ids;
    if (!m_database.GetLinksToTvShow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId,ids))
      return;
    for (int i=0;i<list.Size();)
    {
      unsigned int j;
      for (j=0;j<ids.size();++j)
      {
        if (list[i]->GetVideoInfoTag()->m_iDbId == ids[j])
          break;
      }
      if (j == ids.size())
        i++;
      else
        list.Remove(i);
    }
  }
  int iSelectedLabel = 0;
  if (list.Size() > 1)
  {
    list.Sort(g_guiSettings.GetBool("filelists.ignorethewhensorting") ? SORT_METHOD_LABEL_IGNORE_THE : SORT_METHOD_LABEL, SORT_ORDER_ASC);
    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDialog->Reset();
    pDialog->SetItems(&list);
    pDialog->SetHeading(20356);
    pDialog->DoModal();
    iSelectedLabel = pDialog->GetSelectedLabel();
  }
  if (iSelectedLabel > -1)
  {
    m_database.LinkMovieToTvshow(m_vecItems->Get(itemnumber)->GetVideoInfoTag()->m_iDbId,
                                 list[iSelectedLabel]->GetVideoInfoTag()->m_iDbId, bRemove);
    CUtil::DeleteVideoDatabaseDirectoryCache();
  }
}
bool CGUIWindowSettingsProfile::GetAutoLoginProfileChoice(int &iProfile)
{
  CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  if (!dialog) return false;

  // add items
  // "Most recent" option comes first, so up indices by 1
  int autoLoginProfileId = CProfilesManager::Get().GetAutoLoginProfileId() + 1;
  CFileItemList items;
  CFileItemPtr item(new CFileItem());
  item->SetLabel(g_localizeStrings.Get(37014)); // Most recent
  item->SetIconImage("unknown-user.png");
  items.Add(item);

  for (unsigned int i = 0; i < CProfilesManager::Get().GetNumberOfProfiles(); i++)
  {
    const CProfile *profile = CProfilesManager::Get().GetProfile(i);
    CStdString locked = g_localizeStrings.Get(profile->getLockMode() > 0 ? 20166 : 20165);
    CFileItemPtr item(new CFileItem(profile->getName()));
    item->SetProperty("Addon.Summary", locked); // lock setting
    CStdString thumb = profile->getThumb();
    if (thumb.IsEmpty())
      thumb = "unknown-user.png";
    item->SetIconImage(thumb);
    items.Add(item);
  }

  dialog->SetHeading(20093); // Profile name
  dialog->Reset();
  dialog->SetUseDetails(true);
  dialog->EnableButton(true, 222); // Cancel
  dialog->SetItems(&items);
  dialog->SetSelected(autoLoginProfileId);
  dialog->DoModal();

  if (dialog->IsButtonPressed() || dialog->GetSelectedLabel() < 0)
    return false; // user cancelled
  iProfile = dialog->GetSelectedLabel() - 1;

  return true;
}
bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem& item, const std::string& directory)
{

  CFileItemList items;

  if (!XFILE::CDirectory::GetDirectory(directory, items, XFILE::CDirectory::CHints(), true))
  {
    CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get play directory for %s", directory.c_str());
    return true;
  }

  if (items.IsEmpty())
  {
    CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", directory.c_str());
    return true;
  }

  CGUIDialogSelect* dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  while (true)
  {
    dialog->Reset();
    dialog->SetHeading(CVariant{25006}); // Select playback item
    dialog->SetItems(items);
    dialog->SetUseDetails(true);
    dialog->Open();

    CFileItemPtr item_new = dialog->GetSelectedItem();
    if (!item_new || dialog->GetSelectedLabel() < 0)
    {
      CLog::Log(LOGDEBUG, "CGUIWindowVideoBase::ShowPlaySelection - User aborted %s", directory.c_str());
      break;
    }

    if (item_new->m_bIsFolder == false)
    {
      std::string original_path = item.GetPath();
      item.Reset();
      item = *item_new;
      item.SetProperty("original_listitem_url", original_path);
      return true;
    }

    items.Clear();
    if (!XFILE::CDirectory::GetDirectory(item_new->GetPath(), items, XFILE::CDirectory::CHints(), true) || items.IsEmpty())
    {
      CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items %s", item_new->GetPath().c_str());
      break;
    }
  }

  return false;
}
Exemple #10
0
void CPeripherals::OnSettingAction(const CSetting *setting)
{
  if (setting == NULL)
    return;

  const std::string &settingId = setting->GetId();
  if (settingId == CSettings::SETTING_INPUT_PERIPHERALS)
  {

    CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);

    CFileItemList items;
    GetDirectory("peripherals://all/", items);

    int iPos = -1;
    do
    {
      pDialog->Reset();
      pDialog->SetHeading(CVariant{35000});
      pDialog->SetUseDetails(true);
      pDialog->SetItems(items);
      pDialog->SetSelected(iPos);
      pDialog->Open();

      iPos = pDialog->IsConfirmed() ? pDialog->GetSelectedLabel() : -1;

      if (iPos >= 0)
      {
        CFileItemPtr pItem = items.Get(iPos);
        CGUIDialogPeripheralSettings *pSettingsDialog = (CGUIDialogPeripheralSettings *)g_windowManager.GetWindow(WINDOW_DIALOG_PERIPHERAL_SETTINGS);
        if (pItem && pSettingsDialog)
        {
          // pass peripheral item properties to settings dialog so skin authors
          // can use it to show more detailed information about the device
          pSettingsDialog->SetProperty("vendor", pItem->GetProperty("vendor"));
          pSettingsDialog->SetProperty("product", pItem->GetProperty("product"));
          pSettingsDialog->SetProperty("bus", pItem->GetProperty("bus"));
          pSettingsDialog->SetProperty("location", pItem->GetProperty("location"));
          pSettingsDialog->SetProperty("class", pItem->GetProperty("class"));
          pSettingsDialog->SetProperty("version", pItem->GetProperty("version"));

          // open settings dialog
          pSettingsDialog->SetFileItem(pItem.get());
          pSettingsDialog->Open();
        }
      }
    } while (pDialog->IsConfirmed());
  }
}
/// \brief Search the current directory for a string got from the virtual keyboard
void CGUIWindowVideoInfo::OnSearch(CStdString& strSearch)
{
  if (m_dlgProgress)
  {
    m_dlgProgress->SetHeading(194);
    m_dlgProgress->SetLine(0, strSearch);
    m_dlgProgress->SetLine(1, "");
    m_dlgProgress->SetLine(2, "");
    m_dlgProgress->StartModal();
    m_dlgProgress->Progress();
  }
  CFileItemList items;
  DoSearch(strSearch, items);

  if (items.Size())
  {
    CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDlgSelect->Reset();
    pDlgSelect->SetHeading(283);
    items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC);

    for (int i = 0; i < (int)items.Size(); i++)
    {
      CFileItem* pItem = items[i];
      pDlgSelect->Add(pItem->GetLabel());
    }

    pDlgSelect->DoModal();

    int iItem = pDlgSelect->GetSelectedLabel();
    if (iItem < 0)
    {
      if (m_dlgProgress) m_dlgProgress->Close();
      return ;
    }

    CFileItem* pSelItem = new CFileItem(*items[iItem]);

    OnSearchItemFound(pSelItem);

    delete pSelItem;
    if (m_dlgProgress) m_dlgProgress->Close();
  }
  else
  {
    if (m_dlgProgress) m_dlgProgress->Close();
    CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0);
  }
}
/// \brief Search the current directory for a string got from the virtual keyboard
void CGUIDialogVideoInfo::OnSearch(CStdString& strSearch)
{
  CGUIDialogProgress *progress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
  if (progress)
  {
    progress->SetHeading(194);
    progress->SetLine(0, strSearch);
    progress->SetLine(1, "");
    progress->SetLine(2, "");
    progress->StartModal();
    progress->Progress();
  }
  CFileItemList items;
  DoSearch(strSearch, items);

  if (progress)
    progress->Close();

  if (items.Size())
  {
    CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
    pDlgSelect->Reset();
    pDlgSelect->SetHeading(283);

    for (int i = 0; i < (int)items.Size(); i++)
    {
      CFileItemPtr pItem = items[i];
      pDlgSelect->Add(pItem->GetLabel());
    }

    pDlgSelect->DoModal();

    int iItem = pDlgSelect->GetSelectedLabel();
    if (iItem < 0)
      return;

    CFileItem* pSelItem = new CFileItem(*items[iItem]);

    OnSearchItemFound(pSelItem);

    delete pSelItem;
  }
  else
  {
    CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0);
  }
}
RENDER_STEREO_MODE CStereoscopicsManager::GetStereoModeByUserChoice(const std::string &heading)
{
  RENDER_STEREO_MODE mode = GetStereoMode();
  // if no stereo mode is set already, suggest mode of current video by preselecting it
  if (mode == RENDER_STEREO_MODE_OFF && g_infoManager.EvaluateBool("videoplayer.isstereoscopic"))
    mode = GetStereoModeOfPlayingVideo();

  CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  pDlgSelect->Reset();
  if (heading.empty())
    pDlgSelect->SetHeading(CVariant{g_localizeStrings.Get(36528)});
  else
    pDlgSelect->SetHeading(CVariant{heading});

  // prepare selectable stereo modes
  std::vector<RENDER_STEREO_MODE> selectableModes;
  for (int i = RENDER_STEREO_MODE_OFF; i < RENDER_STEREO_MODE_COUNT; i++)
  {
    RENDER_STEREO_MODE selectableMode = (RENDER_STEREO_MODE) i;
    if (g_Windowing.SupportsStereo(selectableMode))
    {
      selectableModes.push_back(selectableMode);
      std::string label = GetLabelForStereoMode((RENDER_STEREO_MODE) i);
      pDlgSelect->Add( label );
      if (mode == selectableMode)
        pDlgSelect->SetSelected( label );
    }
    // inject AUTO pseudo mode after OFF
    if (i == RENDER_STEREO_MODE_OFF)
    {
      selectableModes.push_back(RENDER_STEREO_MODE_AUTO);
      pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_AUTO));
    }
  }

  pDlgSelect->Open();

  int iItem = pDlgSelect->GetSelectedLabel();
  if (iItem > -1 && pDlgSelect->IsConfirmed())
    mode = (RENDER_STEREO_MODE) selectableModes[iItem];
  else
    mode = GetStereoMode();

  return mode;
}
Exemple #14
0
void CGUIDialogSongInfo::OnSetUserrating()
{
  CGUIDialogSelect *dialog = (CGUIDialogSelect *)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  if (dialog)
  {
    dialog->SetHeading(CVariant{ 38023 });
    dialog->Add(g_localizeStrings.Get(38022));
    for (int i = 1; i <= 5; i++)
      dialog->Add(StringUtils::Format("%s: %i", g_localizeStrings.Get(563).c_str(), i));

    dialog->Open();

    int iItem = dialog->GetSelectedLabel();
    if (iItem < 0)
      return;

    SetUserrating('0' + iItem); // This is casting the int rating to char
  }
}
Exemple #15
0
INFO_RET CMusicInfoScanner::DownloadAlbumInfo(const CAlbum& album, const ADDON::ScraperPtr& info, CMusicAlbumInfo& albumInfo, CGUIDialogProgress* pDialog)
{
  if (m_handle)
  {
    m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20321).c_str(), info->Name().c_str()));
    m_handle->SetText(StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator) + " - " + album.strAlbum);
  }

  // clear our scraper cache
  info->ClearCache();

  CMusicInfoScraper scraper(info);
  bool bMusicBrainz = false;
  if (!album.strMusicBrainzAlbumID.empty())
  {
    CScraperUrl musicBrainzURL;
    if (ResolveMusicBrainz(album.strMusicBrainzAlbumID, info, musicBrainzURL))
    {
      CMusicAlbumInfo albumNfo("nfo", musicBrainzURL);
      scraper.GetAlbums().clear();
      scraper.GetAlbums().push_back(albumNfo);
      bMusicBrainz = true;
    }
  }

  // handle nfo files
  std::string path = album.strPath;
  if (path.empty())
    m_musicDatabase.GetAlbumPath(album.idAlbum, path);

  std::string strNfo = URIUtils::AddFileToFolder(path, "album.nfo");
  CNfoFile::NFOResult result = CNfoFile::NO_NFO;
  CNfoFile nfoReader;
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    result = nfoReader.Create(strNfo, info);
    if (result == CNfoFile::FULL_NFO)
    {
      CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
      nfoReader.GetDetails(albumInfo.GetAlbum());
      return INFO_ADDED;
    }
    else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO)
    {
      CScraperUrl scrUrl(nfoReader.ScraperUrl());
      CMusicAlbumInfo albumNfo("nfo",scrUrl);
      ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo();
      CLog::Log(LOGDEBUG,"-- nfo-scraper: %s", nfoReaderScraper->Name().c_str());
      CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str());
      scraper.SetScraperInfo(nfoReaderScraper);
      scraper.GetAlbums().clear();
      scraper.GetAlbums().push_back(albumNfo);
    }
    else
      CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str());
  }

  if (!scraper.CheckValidOrFallback(CSettings::Get().GetString("musiclibrary.albumsscraper")))
  { // the current scraper is invalid, as is the default - bail
    CLog::Log(LOGERROR, "%s - current and default scrapers are invalid.  Pick another one", __FUNCTION__);
    return INFO_ERROR;
  }

  if (!scraper.GetAlbumCount())
  {
    scraper.FindAlbumInfo(album.strAlbum, StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator));

    while (!scraper.Completed())
    {
      if (m_bStop)
      {
        scraper.Cancel();
        return INFO_CANCELLED;
      }
      Sleep(1);
    }
  }

  CGUIDialogSelect *pDlg = NULL;
  int iSelectedAlbum=0;
  if (result == CNfoFile::NO_NFO && !bMusicBrainz)
  {
    iSelectedAlbum = -1; // set negative so that we can detect a failure
    if (scraper.Succeeded() && scraper.GetAlbumCount() >= 1)
    {
      double bestRelevance = 0;
      double minRelevance = THRESHOLD;
      if (scraper.GetAlbumCount() > 1) // score the matches
      {
        //show dialog with all albums found
        if (pDialog)
        {
          pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
          pDlg->SetHeading(g_localizeStrings.Get(181).c_str());
          pDlg->Reset();
          pDlg->EnableButton(true, 413); // manual
        }

        for (int i = 0; i < scraper.GetAlbumCount(); ++i)
        {
          CMusicAlbumInfo& info = scraper.GetAlbum(i);
          double relevance = info.GetRelevance();
          if (relevance < 0)
            relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum, album.strAlbum, StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator), StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator));

          // if we're doing auto-selection (ie querying all albums at once, then allow 95->100% for perfect matches)
          // otherwise, perfect matches only
          if (relevance >= max(minRelevance, bestRelevance))
          { // we auto-select the best of these
            bestRelevance = relevance;
            iSelectedAlbum = i;
          }
          if (pDialog)
          {
            // set the label to [relevance]  album - artist
            std::string strTemp = StringUtils::Format("[%0.2f]  %s", relevance, info.GetTitle2().c_str());
            CFileItem item(strTemp);
            item.m_idepth = i; // use this to hold the index of the album in the scraper
            pDlg->Add(&item);
          }
          if (relevance > .99f) // we're so close, no reason to search further
            break;
        }

        if (pDialog && bestRelevance < THRESHOLD)
        {
          pDlg->Sort(false);
          pDlg->DoModal();

          // and wait till user selects one
          if (pDlg->GetSelectedLabel() < 0)
          { // none chosen
            if (!pDlg->IsButtonPressed())
              return INFO_CANCELLED;

            // manual button pressed
            std::string strNewAlbum = album.strAlbum;
            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewAlbum, g_localizeStrings.Get(16011), false)) return INFO_CANCELLED;
            if (strNewAlbum == "") return INFO_CANCELLED;

            std::string strNewArtist = StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator);
            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED;

            pDialog->SetLine(0, strNewAlbum);
            pDialog->SetLine(1, strNewArtist);
            pDialog->Progress();

            CAlbum newAlbum = album;
            newAlbum.strAlbum = strNewAlbum;
            newAlbum.artist = StringUtils::Split(strNewArtist, g_advancedSettings.m_musicItemSeparator);

            return DownloadAlbumInfo(newAlbum, info, albumInfo, pDialog);
          }
          iSelectedAlbum = pDlg->GetSelectedItem()->m_idepth;
        }
      }
      else
      {
        CMusicAlbumInfo& info = scraper.GetAlbum(0);
        double relevance = info.GetRelevance();
        if (relevance < 0)
          relevance = CUtil::AlbumRelevance(info.GetAlbum().strAlbum,
                                            album.strAlbum,
                                            StringUtils::Join(info.GetAlbum().artist, g_advancedSettings.m_musicItemSeparator),
                                            StringUtils::Join(album.artist, g_advancedSettings.m_musicItemSeparator));
        if (relevance < THRESHOLD)
          return INFO_NOT_FOUND;

        iSelectedAlbum = 0;
      }
    }

    if (iSelectedAlbum < 0)
      return INFO_NOT_FOUND;

  }

  scraper.LoadAlbumInfo(iSelectedAlbum);
  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      return INFO_CANCELLED;
    }
    Sleep(1);
  }

  if (!scraper.Succeeded())
    return INFO_ERROR;

  albumInfo = scraper.GetAlbum(iSelectedAlbum);
  
  if (result == CNfoFile::COMBINED_NFO)
    nfoReader.GetDetails(albumInfo.GetAlbum(), NULL, true);
  
  return INFO_ADDED;
}
Exemple #16
0
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, bool& bCanceled, CGUIDialogProgress* pDialog)
{
  XFILE::MUSICDATABASEDIRECTORY::CQueryParams params;
  XFILE::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params);
  bCanceled = false;
  CArtist artist;
  m_musicDatabase.Open();
  if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info
    return true;

  // find artist info
  ADDON::ScraperPtr info;
  if (!m_musicDatabase.GetScraperForPath(strPath, info, ADDON::ADDON_SCRAPER_ARTISTS) || !info)
  {
    m_musicDatabase.Close();
    return false;
  }

  if (m_handle)
  {
    m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320), info->Name().c_str()));
    m_handle->SetText(strArtist);
  }

  // clear our scraper cache
  info->ClearCache();

  CMusicInfoScraper scraper(info);
  // handle nfo files
  CStdString strArtistPath, strNfo;
  m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath);
  URIUtils::AddFileToFolder(strArtistPath,"artist.nfo",strNfo);
  CNfoFile::NFOResult result=CNfoFile::NO_NFO;
  CNfoFile nfoReader;
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    result = nfoReader.Create(strNfo, info);
    if (result == CNfoFile::FULL_NFO)
    {
      CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
      CArtist artist;
      nfoReader.GetDetails(artist);
      m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
      map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist);
      m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork);
      m_musicDatabase.Close();
      return true;
    }
    else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO)
    {
      CScraperUrl scrUrl(nfoReader.ScraperUrl());
      CMusicArtistInfo artist("nfo",scrUrl);
      info = nfoReader.GetScraperInfo();
      CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",info->Name().c_str());
      CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str());
      scraper.SetScraperInfo(info);
      scraper.GetArtists().push_back(artist);
    }
    else
      CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str());
  }

  if (!scraper.GetArtistCount())
  {
    scraper.FindArtistInfo(strArtist);

    while (!scraper.Completed())
    {
      if (m_bStop)
      {
        scraper.Cancel();
        bCanceled = true;
      }
      Sleep(1);
    }
  }

  int iSelectedArtist = 0;
  if (result == CNfoFile::NO_NFO)
  {
    if (scraper.Succeeded() && scraper.GetArtistCount() >= 1)
    {
      // now load the first match
      if (pDialog && scraper.GetArtistCount() > 1)
      {
        // if we found more then 1 album, let user choose one
        CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
        if (pDlg)
        {
          pDlg->SetHeading(g_localizeStrings.Get(21890));
          pDlg->Reset();
          pDlg->EnableButton(true, 413); // manual

          for (int i = 0; i < scraper.GetArtistCount(); ++i)
          {
            // set the label to artist
            CFileItem item(scraper.GetArtist(i).GetArtist());
            CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist;
            if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty())
              strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")";
            if (!scraper.GetArtist(i).GetArtist().genre.empty())
            {
              CStdString genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator);
              if (!genres.empty())
                strTemp.Format("[%s] %s", genres.c_str(), strTemp.c_str());
            }
            item.SetLabel(strTemp);
            item.m_idepth = i; // use this to hold the index of the album in the scraper
            pDlg->Add(&item);
          }
          pDlg->DoModal();

          // and wait till user selects one
          if (pDlg->GetSelectedLabel() < 0)
          { // none chosen
            if (!pDlg->IsButtonPressed())
            {
              bCanceled = true;
              return false;
            }
            // manual button pressed
            CStdString strNewArtist = strArtist;
            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;

            if (pDialog)
            {
              pDialog->SetLine(0, strNewArtist);
              pDialog->Progress();
            }
            m_musicDatabase.Close();
            return DownloadArtistInfo(strPath,strNewArtist,bCanceled,pDialog);
          }
          iSelectedArtist = pDlg->GetSelectedItem()->m_idepth;
        }
      }
    }
    else
    {
      m_musicDatabase.Close();
      return false;
    }
  }

  scraper.LoadArtistInfo(iSelectedArtist, strArtist);
  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      bCanceled = true;
    }
    Sleep(1);
  }

  if (scraper.Succeeded())
  {
    artist = scraper.GetArtist(iSelectedArtist).GetArtist();
    if (result == CNfoFile::COMBINED_NFO)
      nfoReader.GetDetails(artist,NULL,true);
    m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
  }

  // check thumb stuff
  map<string, string> artwork = GetArtistArtwork(params.GetArtistId(), &artist);
  m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork);

  m_musicDatabase.Close();
  return true;
}
bool CGUIDialogAddonSettings::ShowVirtualKeyboard(int iControl)
{
  int controlId = CONTROL_START_SETTING;
  bool bCloseDialog = false;

  const TiXmlElement *setting = GetFirstSetting();
  while (setting)
  {
    if (controlId == iControl)
    {
      const CGUIControl* control = GetControl(controlId);
      const std::string id = XMLUtils::GetAttribute(setting, "id");
      const std::string type = XMLUtils::GetAttribute(setting, "type");

      //Special handling for actions: does not require id attribute. TODO: refactor me.
      if (control && control->GetControlType() == CGUIControl::GUICONTROL_BUTTON && type == "action")
      {
        const char *option = setting->Attribute("option");
        std::string action = XMLUtils::GetAttribute(setting, "action");
        if (!action.empty())
        {
          // replace $CWD with the url of plugin/script
          StringUtils::Replace(action, "$CWD", m_addon->Path());
          StringUtils::Replace(action, "$ID", m_addon->ID());
          if (option)
            bCloseDialog = (strcmpi(option, "close") == 0);
          CApplicationMessenger::Get().ExecBuiltIn(action);
        }
        break;
      }

      if (control && control->GetControlType() == CGUIControl::GUICONTROL_BUTTON &&
          !id.empty() && !type.empty())
      {
        const char *option = setting->Attribute("option");
        const char *source = setting->Attribute("source");
        std::string value = m_buttonValues[id];
        std::string label = GetString(setting->Attribute("label"));

        if (type == "text")
        {
          // get any options
          bool bHidden  = false;
          bool bEncoded = false;
          if (option)
          {
            bHidden = (strstr(option, "hidden") != NULL);
            bEncoded = (strstr(option, "urlencoded") != NULL);
          }
          if (bEncoded)
            value = CURL::Decode(value);

          if (CGUIKeyboardFactory::ShowAndGetInput(value, label, true, bHidden))
          {
            // if hidden hide input
            if (bHidden)
            {
              std::string hiddenText;
              hiddenText.append(value.size(), L'*');
              ((CGUIButtonControl *)control)->SetLabel2(hiddenText);
            }
            else
              ((CGUIButtonControl*) control)->SetLabel2(value);
            if (bEncoded)
              value = CURL::Encode(value);
          }
        }
        else if (type == "number" && CGUIDialogNumeric::ShowAndGetNumber(value, label))
        {
          ((CGUIButtonControl*) control)->SetLabel2(value);
        }
        else if (type == "ipaddress" && CGUIDialogNumeric::ShowAndGetIPAddress(value, label))
        {
          ((CGUIButtonControl*) control)->SetLabel2(value);
        }
        else if (type == "select")
        {
          CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
          if (pDlg)
          {
            pDlg->SetHeading(label.c_str());
            pDlg->Reset();

            int selected = -1;
            vector<std::string> valuesVec;
            if (setting->Attribute("values"))
              StringUtils::Tokenize(setting->Attribute("values"), valuesVec, "|");
            else if (setting->Attribute("lvalues"))
            { // localize
              StringUtils::Tokenize(setting->Attribute("lvalues"), valuesVec, "|");
              for (unsigned int i = 0; i < valuesVec.size(); i++)
              {
                if (i == (unsigned int)atoi(value.c_str()))
                  selected = i;
                std::string localized = m_addon->GetString(atoi(valuesVec[i].c_str()));
                if (localized.empty())
                  localized = g_localizeStrings.Get(atoi(valuesVec[i].c_str()));
                valuesVec[i] = localized;
              }
            }
            else if (source)
            {
              valuesVec = GetFileEnumValues(source, XMLUtils::GetAttribute(setting, "mask"), XMLUtils::GetAttribute(setting, "option"));
            }

            for (unsigned int i = 0; i < valuesVec.size(); i++)
            {
              pDlg->Add(valuesVec[i]);
              if (selected == (int)i || (selected < 0 && StringUtils::EqualsNoCase(valuesVec[i], value)))
                pDlg->SetSelected(i); // FIXME: the SetSelected() does not select "i", it always defaults to the first position
            }
            pDlg->DoModal();
            int iSelected = pDlg->GetSelectedLabel();
            if (iSelected >= 0)
            {
              if (setting->Attribute("lvalues"))
                value = StringUtils::Format("%i", iSelected);
              else
                value = valuesVec[iSelected];
              ((CGUIButtonControl*) control)->SetLabel2(valuesVec[iSelected]);
            }
          }
        }
        else if (type == "audio" || type == "video"
              || type == "image" || type == "executable"
              || type == "file"  || type == "folder")
        {
          // setup the shares
          VECSOURCES *shares = NULL;
          if (source && strcmpi(source, "") != 0)
            shares = CMediaSourceSettings::Get().GetSources(source);

          VECSOURCES localShares;
          if (!shares)
          {
            g_mediaManager.GetLocalDrives(localShares);
            if (!source || strcmpi(source, "local") != 0)
              g_mediaManager.GetNetworkLocations(localShares);
          }
          else // always append local drives
          {
            localShares = *shares;
            g_mediaManager.GetLocalDrives(localShares);
          }

          if (type == "folder")
          {
            // get any options
            bool bWriteOnly = false;
            if (option)
              bWriteOnly = (strcmpi(option, "writeable") == 0);

            if (CGUIDialogFileBrowser::ShowAndGetDirectory(localShares, label, value, bWriteOnly))
              ((CGUIButtonControl*) control)->SetLabel2(value);
          }
          else if (type == "image")
          {
            if (CGUIDialogFileBrowser::ShowAndGetImage(localShares, label, value))
              ((CGUIButtonControl*) control)->SetLabel2(value);
          }
          else
          {
            // set the proper mask
            std::string strMask;
            if (setting->Attribute("mask"))
            {
              strMask = setting->Attribute("mask");
              // convert mask qualifiers
              StringUtils::Replace(strMask, "$AUDIO", g_advancedSettings.GetMusicExtensions());
              StringUtils::Replace(strMask, "$VIDEO", g_advancedSettings.m_videoExtensions);
              StringUtils::Replace(strMask, "$IMAGE", g_advancedSettings.m_pictureExtensions);
#if defined(_WIN32_WINNT)
              StringUtils::Replace(strMask, "$EXECUTABLE", ".exe|.bat|.cmd|.py");
#else
              StringUtils::Replace(strMask, "$EXECUTABLE", "");
#endif
            }
            else
            {
              if (type == "video")
                strMask = g_advancedSettings.m_videoExtensions;
              else if (type == "audio")
                strMask = g_advancedSettings.GetMusicExtensions();
              else if (type == "executable")
#if defined(_WIN32_WINNT)
                strMask = ".exe|.bat|.cmd|.py";
#else
                strMask = "";
#endif
            }

            // get any options
            bool bUseThumbs = false;
            bool bUseFileDirectories = false;
            if (option)
            {
              vector<string> options = StringUtils::Split(option, '|');
              bUseThumbs = find(options.begin(), options.end(), "usethumbs") != options.end();
              bUseFileDirectories = find(options.begin(), options.end(), "treatasfolder") != options.end();
            }

            if (CGUIDialogFileBrowser::ShowAndGetFile(localShares, strMask, label, value, bUseThumbs, bUseFileDirectories))
              ((CGUIButtonControl*) control)->SetLabel2(value);
          }
        }
        else if (type == "date")
        {
          CDateTime date;
          if (!value.empty())
            date.SetFromDBDate(value);
          SYSTEMTIME timedate;
          date.GetAsSystemTime(timedate);
          if(CGUIDialogNumeric::ShowAndGetDate(timedate, label))
          {
            date = timedate;
            value = date.GetAsDBDate();
            ((CGUIButtonControl*) control)->SetLabel2(value);
          }
        }
        else if (type == "time")
        {
          SYSTEMTIME timedate;
          if (value.size() >= 5)
          {
            // assumes HH:MM
            timedate.wHour = atoi(value.substr(0, 2).c_str());
            timedate.wMinute = atoi(value.substr(3, 2).c_str());
          }
          if (CGUIDialogNumeric::ShowAndGetTime(timedate, label))
          {
            value = StringUtils::Format("%02d:%02d", timedate.wHour, timedate.wMinute);
            ((CGUIButtonControl*) control)->SetLabel2(value);
          }
        }
        else if (type == "addon")
        {
          const char *strType = setting->Attribute("addontype");
          if (strType)
          {
            vector<string> addonTypes = StringUtils::Split(strType, ',');
            vector<ADDON::TYPE> types;
            for (vector<string>::iterator i = addonTypes.begin(); i != addonTypes.end(); ++i)
            {
              StringUtils::Trim(*i);
              ADDON::TYPE type = TranslateType(*i);
              if (type != ADDON_UNKNOWN)
                types.push_back(type);
            }
            if (types.size() > 0)
            {
              const char *strMultiselect = setting->Attribute("multiselect");
              bool multiSelect = strMultiselect && strcmpi(strMultiselect, "true") == 0;
              if (multiSelect)
              {
                // construct vector of addon IDs (IDs are comma seperated in single string)
                vector<string> addonIDs = StringUtils::Split(value, ',');
                if (CGUIWindowAddonBrowser::SelectAddonID(types, addonIDs, false) == 1)
                {
                  value = StringUtils::Join(addonIDs, ",");
                  ((CGUIButtonControl*) control)->SetLabel2(GetAddonNames(value));
                }
              }
              else // no need of string splitting/joining if we select only 1 addon
                if (CGUIWindowAddonBrowser::SelectAddonID(types, value, false) == 1)
                  ((CGUIButtonControl*) control)->SetLabel2(GetAddonNames(value));
            }
          }
        }
        m_buttonValues[id] = value;
        break;
      }
    }
    setting = setting->NextSiblingElement("setting");
    controlId++;
  }
  EnableControls();
  return bCloseDialog;
}
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel(CGUIMessage &message)
{
  std::vector<long> clients;

  CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  if (!pDlgSelect)
    return false;

  pDlgSelect->SetHeading(19213); // Select Client
  pDlgSelect->Add(g_localizeStrings.Get(19209));
  clients.push_back(PVR_VIRTUAL_CLIENT_ID);

  PVR_CLIENTMAP clientMap;
  if (g_PVRClients->GetConnectedClients(clientMap) > 0)
  {
    PVR_CLIENTMAP_ITR itr;
    for (itr = clientMap.begin() ; itr != clientMap.end(); itr++)
    {
      clients.push_back((*itr).first);
      pDlgSelect->Add((*itr).second->Name());
    }
  }
  pDlgSelect->DoModal();

  int selection = pDlgSelect->GetSelectedLabel();
  if (selection >= 0 && selection <= (int) clients.size())
  {
    int clientID = clients[selection];
    if (clientID == PVR_VIRTUAL_CLIENT_ID)
    {
      CStdString strURL = "";
      if (CGUIKeyboardFactory::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false))
      {
        if (!strURL.empty())
        {
          CPVRChannel *newchannel = new CPVRChannel(m_bIsRadio);
          newchannel->SetChannelName(g_localizeStrings.Get(19204));
          newchannel->SetEPGEnabled(false);
          newchannel->SetVirtual(true);
          newchannel->SetStreamURL(strURL);
          newchannel->SetClientID(PVR_VIRTUAL_CLIENT_ID);
          if (g_PVRChannelGroups->CreateChannel(*newchannel))
            g_PVRChannelGroups->GetGroupAll(m_bIsRadio)->Persist();

          CFileItemPtr channel(new CFileItem(*newchannel));
          if (channel)
          {
            channel->SetProperty("ActiveChannel", true);
            channel->SetProperty("Name", g_localizeStrings.Get(19204));
            channel->SetProperty("UseEPG", false);
            channel->SetProperty("Icon", newchannel->IconPath());
            channel->SetProperty("EPGSource", (int)0);
            channel->SetProperty("ClientName", g_localizeStrings.Get(19209));
            channel->SetProperty("ParentalLocked", false);

            m_channelItems->AddFront(channel, m_iSelected);
            m_viewControl.SetItems(*m_channelItems);
            Renumber();
          }
        }
      }
    }
    else
    {
      CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
    }
  }
  return true;
}
void CGUIDialogSmartPlaylistRule::OnBrowse()
{
  CFileItemList items;
  CMusicDatabase database;
  database.Open();
  CVideoDatabase videodatabase;
  videodatabase.Open();

  VIDEODB_CONTENT_TYPE type = VIDEODB_CONTENT_MOVIES;
  if (m_type.Equals("tvshows"))
    type = VIDEODB_CONTENT_TVSHOWS;
  else if (m_type.Equals("musicvideos"))
    type = VIDEODB_CONTENT_MUSICVIDEOS;
  else if (m_type.Equals("episodes"))
    type = VIDEODB_CONTENT_EPISODES;

  int iLabel = 0;
  if (m_rule.m_field == CSmartPlaylistRule::FIELD_GENRE)
  {
    if (m_type.Equals("tvshows") || m_type.Equals("episodes") || m_type.Equals("movies"))
      videodatabase.GetGenresNav("videodb://2/1/",items,type);
    else if (m_type.Equals("songs") || m_type.Equals("albums") || m_type.Equals("mixed"))
      database.GetGenresNav("musicdb://4/",items);
    if (m_type.Equals("musicvideos") || m_type.Equals("mixed"))
    {
      CFileItemList items2;
      videodatabase.GetGenresNav("videodb://3/1/",items2,VIDEODB_CONTENT_MUSICVIDEOS);
      items.Append(items2);
    }
    iLabel = 515;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_COUNTRY)
  {
    videodatabase.GetCountriesNav("videodb://2/1/",items,type);
    iLabel = 574;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ARTIST || m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUMARTIST)
  {
    if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums"))
      database.GetArtistsNav("musicdb://5/",items,-1,m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUMARTIST);
    if (m_type.Equals("musicvideos") || m_type.Equals("mixed"))
    {
      CFileItemList items2;
      videodatabase.GetMusicVideoArtistsByName("",items2);
      items.Append(items2);
    }
    iLabel = 557;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ALBUM)
  {
    if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums"))
      database.GetAlbumsNav("musicdb://6/",items,-1,-1,-1,-1);
    if (m_type.Equals("musicvideos") || m_type.Equals("mixed"))
    {
      CFileItemList items2;
      videodatabase.GetMusicVideoAlbumsByName("",items2);
      items.Append(items2);
    }
    iLabel = 558;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_ACTOR)
  {
    videodatabase.GetActorsNav("",items,type);
    iLabel = 20337;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_DIRECTOR)
  {
    videodatabase.GetDirectorsNav("",items,type);
    iLabel = 20339;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_STUDIO)
  {
    videodatabase.GetStudiosNav("",items,type);
    iLabel = 572;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_WRITER)
  {
    videodatabase.GetWritersNav("",items,type);
    iLabel = 20417;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_TVSHOWTITLE)
  {
    videodatabase.GetTvShowsNav("",items);
    iLabel = 20343;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_PLAYLIST)
  {
    // use filebrowser to grab another smart playlist

    // Note: This can cause infinite loops (playlist that refers to the same playlist) but I don't
    //       think there's any decent way to deal with this, as the infinite loop may be an arbitrary
    //       number of playlists deep, eg playlist1 -> playlist2 -> playlist3 ... -> playlistn -> playlist1
    CStdString path = "special://videoplaylists/";
    if (m_type.Equals("songs") || m_type.Equals("albums"))
      path = "special://musicplaylists/";
    XFILE::CDirectory::GetDirectory(path, items, ".xsp",false,false,XFILE::DIR_CACHE_ONCE,true,true);
    iLabel = 559;
  }
  else if (m_rule.m_field == CSmartPlaylistRule::FIELD_PATH)
  {
    VECSOURCES sources;
    if (m_type == "songs" || m_type == "mixed")
      sources = *g_settings.GetSourcesFromType("music");
    if (m_type != "songs")
    {
      VECSOURCES sources2 = *g_settings.GetSourcesFromType("video");
      sources.insert(sources.end(),sources2.begin(),sources2.end());
    }
    g_mediaManager.GetLocalDrives(sources);
    
    CGUIDialogFileBrowser::ShowAndGetDirectory(sources,g_localizeStrings.Get(657),m_rule.m_parameter,false);
    UpdateButtons();
    return;
  }
  else
  { // TODO: Add browseability in here.
    assert(false);
  }

  // sort the items
  items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC);

  CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  pDialog->Reset();
  pDialog->SetItems(&items);
  CStdString strHeading;
  strHeading.Format(g_localizeStrings.Get(13401),g_localizeStrings.Get(iLabel));
  pDialog->SetHeading(strHeading);
  pDialog->DoModal();
  if (pDialog->GetSelectedLabel() > -1)
  {
    m_rule.m_parameter = pDialog->GetSelectedLabelText();
    UpdateButtons();
  }
  pDialog->Reset();
}
void CStereoscopicsManager::OnPlaybackStarted(void)
{
  if (!g_infoManager.EvaluateBool("videoplayer.isstereoscopic"))
    return;

  // only change stereo mode if not yet in stereo mode
  RENDER_STEREO_MODE mode = GetStereoMode();
  if (mode != RENDER_STEREO_MODE_OFF)
    return;

  int playbackMode = CSettings::Get().GetInt("videoplayer.stereoscopicplaybackmode");
  switch (playbackMode)
  {
  case 0: // Ask
    {
      CApplicationMessenger::Get().MediaPause();

      CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
      pDlgSelect->Reset();
      pDlgSelect->SetHeading(g_localizeStrings.Get(36527).c_str());

      RENDER_STEREO_MODE preferred = GetPreferredPlaybackMode();
      RENDER_STEREO_MODE playing   = GetStereoModeOfPlayingVideo();

      int idx_preferred = -1
        , idx_playing   = -1
        , idx_mono      = -1
        , idx_select    = -1;

      // add choices
      idx_preferred = pDlgSelect->Add( g_localizeStrings.Get(36530)
                                     + " ("
                                     + GetLabelForStereoMode(preferred)
                                     + ")");

      if(preferred != RENDER_STEREO_MODE_MONO)
        idx_mono = pDlgSelect->Add( g_localizeStrings.Get(36529) ); // mono / 2d


      if(playing != RENDER_STEREO_MODE_OFF && g_Windowing.SupportsStereo(playing))
        idx_playing = pDlgSelect->Add( g_localizeStrings.Get(36532)
                                    + " ("
                                    + GetLabelForStereoMode(playing)
                                    + ")");

      idx_select = pDlgSelect->Add( g_localizeStrings.Get(36531) ); // other / select

      pDlgSelect->DoModal();

      if(pDlgSelect->IsConfirmed())
      {
        int iItem = pDlgSelect->GetSelectedLabel();
        if      (iItem == idx_preferred) mode = preferred;
        else if (iItem == idx_mono)      mode = RENDER_STEREO_MODE_MONO;
        else if (iItem == idx_playing)   mode = playing;
        else if (iItem == idx_select)    mode = GetStereoModeByUserChoice();

        SetStereoMode(mode);
      }

      CApplicationMessenger::Get().MediaUnPause();
    }
    break;
  case 1: // Stereoscopic
    SetStereoMode( GetPreferredPlaybackMode() );
    break;
  default:
    break;
  }
}
Exemple #21
0
int CGUIWindowAddonBrowser::SelectAddonID(const vector<ADDON::TYPE> &types, CStdStringArray &addonIDs, bool showNone /*= false*/, bool multipleSelection /*= true*/)
{
  CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  if (!dialog)
    return 0;

  CFileItemList items;
  CStdString heading;
  int iTypes = 0;
  for (vector<ADDON::TYPE>::const_iterator it = types.begin(); it != types.end(); ++it)
  {
    if (*it == ADDON_UNKNOWN)
      continue;
    ADDON::VECADDONS addons;
    iTypes++;
    if (*it == ADDON_AUDIO)
      CAddonsDirectory::GetScriptsAndPlugins("audio",addons);
    else if (*it == ADDON_EXECUTABLE)
      CAddonsDirectory::GetScriptsAndPlugins("executable",addons);
    else if (*it == ADDON_IMAGE)
      CAddonsDirectory::GetScriptsAndPlugins("image",addons);
    else if (*it == ADDON_VIDEO)
      CAddonsDirectory::GetScriptsAndPlugins("video",addons);
    else
      CAddonMgr::Get().GetAddons(*it, addons);
    for (ADDON::IVECADDONS it2 = addons.begin() ; it2 != addons.end() ; ++it2)
    {
      CFileItemPtr item(CAddonsDirectory::FileItemFromAddon(*it2, ""));
      if (!items.Contains(item->GetPath()))
        items.Add(item);
    }

    if (!heading.IsEmpty())
      heading += ", ";
    heading += TranslateType(*it, true);
  }

  if (iTypes == 0)
    return 0;

  dialog->SetHeading(heading);
  dialog->Reset();
  dialog->SetUseDetails(true);
  if (multipleSelection)
    showNone = false;
#ifndef IS_JUKEBOX
  if (multipleSelection || iTypes > 1)
    dialog->EnableButton(true, 186);
  else
    dialog->EnableButton(true, 21452);
#endif
  if (showNone)
  {
    CFileItemPtr item(new CFileItem("", false));
    item->SetLabel(g_localizeStrings.Get(231));
    item->SetLabel2(g_localizeStrings.Get(24040));
    item->SetIconImage("DefaultAddonNone.png");
    item->SetSpecialSort(SORT_ON_TOP);
    items.Add(item);
  }
  items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC);

  if (addonIDs.size() > 0)
  {
    for (CStdStringArray::const_iterator it = addonIDs.begin(); it != addonIDs.end() ; it++)
    {
      CFileItemPtr item = items.Get(*it);
      if (item)
        item->Select(true);
    }
  }
  dialog->SetItems(&items);
  dialog->SetMultiSelection(multipleSelection);
  dialog->DoModal();
  if (!multipleSelection && iTypes == 1 && dialog->IsButtonPressed())
  { // switch to the addons browser.
    vector<CStdString> params;
    params.push_back("addons://all/"+TranslateType(types[0],false)+"/");
    params.push_back("return");
    g_windowManager.ActivateWindow(WINDOW_ADDON_BROWSER, params);
    return 2;
  }
  if (!multipleSelection && dialog->GetSelectedLabel() == -1)
    return 0;
  addonIDs.clear();
  const CFileItemList& list = dialog->GetSelectedItems();
  for (int i = 0 ; i < list.Size() ; i++)
    addonIDs.push_back(list.Get(i)->GetPath());
  return 1;
}
Exemple #22
0
bool CGUIDialogPVRChannelManager::OnMessage(CGUIMessage& message)
{
  unsigned int iControl = 0;
  unsigned int iMessage = message.GetMessage();

  switch (iMessage)
  {
    case GUI_MSG_WINDOW_DEINIT:
    {
      Clear();
    }
    break;

    case GUI_MSG_WINDOW_INIT:
    {
      CGUIWindow::OnMessage(message);
      m_iSelected = 0;
      m_bIsRadio = false;
      m_bMovingMode = false;
      m_bContainsChanges = false;
      SetProperty("IsRadio", "");
      Update();
      SetData(m_iSelected);
      return true;
    }
    break;

    case GUI_MSG_CLICKED:
    {
      iControl = message.GetSenderId();
      if (iControl == CONTROL_LIST_CHANNELS)
      {
        if (!m_bMovingMode)
        {
          int iAction = message.GetParam1();
          int iItem = m_viewControl.GetSelectedItem();

          /* Check file item is in list range and get his pointer */
          if (iItem < 0 || iItem >= (int)m_channelItems->Size()) return true;

          /* Process actions */
          if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
          {
            /* Show Contextmenu */
            OnPopupMenu(iItem);
          }
        }
        else
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->Select(false);
            m_bMovingMode = false;
            m_bContainsChanges = true;
            return true;
          }
          else
            return false;
        }
      }
      else if (iControl == BUTTON_OK)
      {
        SaveList();
        Close();
        return true;
      }
      else if (iControl == BUTTON_APPLY)
      {
        SaveList();
        return true;
      }
      else if (iControl == BUTTON_CANCEL)
      {
        Close();
        return true;
      }
      else if (iControl == BUTTON_RADIO_TV)
      {
        if (m_bContainsChanges)
        {
          // prompt user for confirmation of channel record
          CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
          if (!pDialog)
            return true;

          pDialog->SetHeading(20052);
          pDialog->SetLine(0, "");
          pDialog->SetLine(1, 19212);
          pDialog->SetLine(2, 20103);
          pDialog->DoModal();

          if (pDialog->IsConfirmed())
            SaveList();
        }

        m_iSelected = 0;
        m_bMovingMode = false;
        m_bContainsChanges = false;
        m_bIsRadio = !m_bIsRadio;
        SetProperty("IsRadio", m_bIsRadio ? "true" : "");
        Update();
        SetData(m_iSelected);
        return true;
      }
      else if (iControl == RADIOBUTTON_ACTIVE)
      {
        CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_ACTIVE);
        if (pRadioButton)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("ActiveChannel", pRadioButton->IsSelected());
            m_bContainsChanges = true;
            Renumber();
          }
        }
      }
      else if (iControl == EDIT_NAME)
      {
        CGUIEditControl *pEdit = (CGUIEditControl *)GetControl(EDIT_NAME);
        if (pEdit)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("Name", pEdit->GetLabel2());
            m_bContainsChanges = true;
          }
        }
      }
      else if (iControl == BUTTON_CHANNEL_LOGO)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);

        if (!pItem)
          return false;
        if (g_settings.GetCurrentProfile().canWriteSources() && !g_passwordManager.IsProfileLockUnlocked())
          return false;
        else if (!g_passwordManager.IsMasterLockUnlocked(true))
          return false;

        // setup our thumb list
        CFileItemList items;

        // add the current thumb, if available
        if (!pItem->GetProperty("Icon").IsEmpty())
        {
          CFileItemPtr current(new CFileItem("thumb://Current", false));
          current->SetThumbnailImage(pItem->GetPVRChannelInfoTag()->IconPath());
          current->SetLabel(g_localizeStrings.Get(20016));
          items.Add(current);
        }
        else if (pItem->HasThumbnail())
        { // already have a thumb that the share doesn't know about - must be a local one, so we mayaswell reuse it.
          CFileItemPtr current(new CFileItem("thumb://Current", false));
          current->SetThumbnailImage(pItem->GetThumbnailImage());
          current->SetLabel(g_localizeStrings.Get(20016));
          items.Add(current);
        }

        // and add a "no thumb" entry as well
        CFileItemPtr nothumb(new CFileItem("thumb://None", false));
        nothumb->SetIconImage(pItem->GetIconImage());
        nothumb->SetLabel(g_localizeStrings.Get(20018));
        items.Add(nothumb);

        CStdString strThumb;
        VECSOURCES shares;
        if (g_guiSettings.GetString("pvrmenu.iconpath") != "")
        {
          CMediaSource share1;
          share1.strPath = g_guiSettings.GetString("pvrmenu.iconpath");
          share1.strName = g_localizeStrings.Get(19018);
          shares.push_back(share1);
        }
        g_mediaManager.GetLocalDrives(shares);
        if (!CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), strThumb))
          return false;

        if (strThumb == "thumb://Current")
          return true;

        if (strThumb == "thumb://None")
          strThumb = "";

        pItem->SetProperty("Icon", strThumb);
        pItem->SetProperty("Changed", true);
        m_bContainsChanges = true;
        return true;
      }
      else if (iControl == RADIOBUTTON_USEEPG)
      {
        CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_USEEPG);
        if (pRadioButton)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("UseEPG", pRadioButton->IsSelected());
            m_bContainsChanges = true;
          }
        }
      }
      else if (iControl == SPIN_EPGSOURCE_SELECTION)
      {
        /// TODO: Add EPG scraper support
        return true;
        CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(SPIN_EPGSOURCE_SELECTION);
        if (pSpin)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("EPGSource", (int)0);
            pItem->SetProperty("Changed", true);
            m_bContainsChanges = true;
            return true;
          }
        }
      }
      else if (iControl == BUTTON_GROUP_MANAGER)
      {
        /* Load group manager dialog */
        CGUIDialogPVRGroupManager* pDlgInfo = (CGUIDialogPVRGroupManager*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GROUP_MANAGER);
        if (!pDlgInfo)
          return false;

        pDlgInfo->SetRadio(m_bIsRadio);

        /* Open dialog window */
        pDlgInfo->DoModal();

        return true;
      }
      else if (iControl == BUTTON_EDIT_CHANNEL)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
        if (!pItem)
          return false;

        if (pItem->GetPropertyBOOL("Virtual"))
        {
          CStdString strURL = pItem->GetProperty("StreamURL");
          if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false))
            pItem->SetProperty("StreamURL", strURL);
          return true;
        }

        CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
        return true;
      }
      else if (iControl == BUTTON_DELETE_CHANNEL)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
        if (!pItem)
          return false;

        // prompt user for confirmation of channel record
        CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
        if (!pDialog)
          return true;

        pDialog->SetHeading(19211);
        pDialog->SetLine(0, "");
        pDialog->SetLine(1, 750);
        pDialog->SetLine(2, "");
        pDialog->DoModal();

        if (pDialog->IsConfirmed())
        {
          if (pItem->GetPropertyBOOL("Virtual"))
          {
            CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
            database->Open();
            database->Delete(*pItem->GetPVRChannelInfoTag());
            database->Close();

            m_channelItems->Remove(m_iSelected);
            m_viewControl.SetItems(*m_channelItems);
            Renumber();
            return true;
          }
          CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
        }
        return true;
      }
      else if (iControl == BUTTON_NEW_CHANNEL)
      {
        std::vector<long> clients;

        CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
        if (!pDlgSelect)
          return false;

        pDlgSelect->SetHeading(19213); // Select Client
        pDlgSelect->Add(g_localizeStrings.Get(19209));
        clients.push_back(XBMC_VIRTUAL_CLIENTID);

        std::map<long, CStdString> clientMap;
        if (CPVRManager::GetClients()->GetClients(&clientMap) > 0)
        {
          std::map<long,CStdString>::iterator itr;
          for (itr = clientMap.begin() ; itr != clientMap.end(); itr++)
          {
            clients.push_back((*itr).first);
            pDlgSelect->Add(clientMap[(*itr).first]);
          }
        }
        pDlgSelect->DoModal();

        int selection = pDlgSelect->GetSelectedLabel();
        if (selection >= 0 && selection <= (int) clients.size())
        {
          int clientID = clients[selection];
          if (clientID == XBMC_VIRTUAL_CLIENTID)
          {
            CStdString strURL = "";
            if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false))
            {
              if (!strURL.IsEmpty())
              {
                CPVRChannel newchannel(m_bIsRadio);
                newchannel.SetChannelName(g_localizeStrings.Get(19204));
                newchannel.SetEPGEnabled(false);
                newchannel.SetVirtual(true);
                newchannel.SetStreamURL(strURL);
                newchannel.SetClientID(XBMC_VIRTUAL_CLIENTID);

                CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
                database->Open();
                database->Persist(newchannel);
                database->Close();
                CFileItemPtr channel(new CFileItem(newchannel));

                if (channel)
                {
                  channel->SetProperty("ActiveChannel", true);
                  channel->SetProperty("Name", g_localizeStrings.Get(19204));
                  channel->SetProperty("UseEPG", false);
                  channel->SetProperty("Icon", newchannel.IconPath());
                  channel->SetProperty("EPGSource", (int)0);
                  channel->SetProperty("ClientName", g_localizeStrings.Get(19209));

                  m_channelItems->AddFront(channel, m_iSelected);
                  m_viewControl.SetItems(*m_channelItems);
                  Renumber();
                }
              }
            }
          }
          else
          {
            CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
          }
        }
        return true;
      }
    }
    break;
  }

  return CGUIDialog::OnMessage(message);
}
bool CWeather::GetSearchResults(const CStdString &strSearch, CStdString &strResult)
{
  // Check to see if the user entered a weather.com code
  if (strSearch.size() == 8)
  {
    strResult = "";
    int i = 0;
    for (i = 0; i < 4; ++i)
    {
      strResult += toupper(strSearch[i]);
      if (!isalpha(strSearch[i]))
        break;
    }
    if (i == 4)
    {
      for ( ; i < 8; ++i)
      {
        strResult += strSearch[i];
        if (!isdigit(strSearch[i]))
          break;
      }
      if (i == 8)
      {
        return true; // match
      }
    }
    // no match, wipe string
    strResult = "";
  }

  CGUIDialogSelect *pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  CGUIDialogProgress *pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);

  //do the download
  CStdString strURL;
  CStdString strXML;
  XFILE::CFileCurl httpUtil;

  if (pDlgProgress)
  {
    pDlgProgress->SetHeading(410);       //"Accessing Weather.com"
    pDlgProgress->SetLine(0, 194);       //"Searching"
    pDlgProgress->SetLine(1, strSearch);
    pDlgProgress->SetLine(2, "");
    pDlgProgress->StartModal();
    pDlgProgress->Progress();
  }

  strURL.Format("http://xoap.weather.com/search/search?where=%s", strSearch);

  if (!httpUtil.Get(strURL, strXML))
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  //some select dialog init stuff
  if (!pDlgSelect)
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  pDlgSelect->SetHeading(396); //"Select Location"
  pDlgSelect->Reset();

  ///////////////////////////////
  // load the xml file
  ///////////////////////////////
  TiXmlDocument xmlDoc;
  xmlDoc.Parse(strXML.c_str());
  if (xmlDoc.Error())
    return false;

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (pRootElement)
  {
    CStdString strItemTmp;
    TiXmlElement *pElement = pRootElement->FirstChildElement("loc");
    while (pElement)
    {
      if (!pElement->NoChildren())
      {
        strItemTmp.Format("%s - %s", pElement->Attribute("id"), pElement->FirstChild()->Value());
        pDlgSelect->Add(strItemTmp);
      }
      pElement = pElement->NextSiblingElement("loc");
    }
  }

  if (pDlgProgress)
    pDlgProgress->Close();

  pDlgSelect->EnableButton(true, 222); //'Cancel' button returns to weather settings
  pDlgSelect->DoModal();

  if (pDlgSelect->GetSelectedLabel() < 0)
  {
    if (pDlgSelect->IsButtonPressed())
    {
      pDlgSelect->Close(); //close the select dialog and return to weather settings
      return true;
    }
  }

  //copy the selected code into the settings
  if (pDlgSelect->GetSelectedLabel() >= 0)
    strResult = pDlgSelect->GetSelectedLabelText();

  if (pDlgProgress)
    pDlgProgress->Close();

  return true;
}
void CStereoscopicsManager::OnPlaybackStarted(void)
{
  STEREOSCOPIC_PLAYBACK_MODE playbackMode = (STEREOSCOPIC_PLAYBACK_MODE) CSettings::Get().GetInt("videoplayer.stereoscopicplaybackmode");
  RENDER_STEREO_MODE mode = GetStereoMode();

  // early return if playback mode should be ignored and we're in no stereoscopic mode right now
  if (playbackMode == STEREOSCOPIC_PLAYBACK_MODE_IGNORE && mode == RENDER_STEREO_MODE_OFF)
    return;

  if (!g_infoManager.EvaluateBool("videoplayer.isstereoscopic"))
  {
    // exit stereo mode if started item is not stereoscopic
    // and if user prefers to stop 3D playback when movie is finished
    if (mode != RENDER_STEREO_MODE_OFF && CSettings::Get().GetBool("videoplayer.quitstereomodeonstop"))
      SetStereoMode(RENDER_STEREO_MODE_OFF);
    return;
  }

  // if we're not in stereomode yet, restore previously selected stereo mode in case it was user selected
  if (m_stereoModeSetByUser != RENDER_STEREO_MODE_UNDEFINED)
  {
    SetStereoMode(m_stereoModeSetByUser);
    return;
  }

  RENDER_STEREO_MODE preferred = GetPreferredPlaybackMode();
  RENDER_STEREO_MODE playing = GetStereoModeOfPlayingVideo();

  if (mode != RENDER_STEREO_MODE_OFF)
  {
    // don't change mode if user selected to not exit stereomode on playback stop
    // users selecting this option usually have to manually switch their TV into 3D mode
    // and would be annoyed by having to switch TV modes when next movies comes up
    // @todo probably add a new setting for just this behavior
    if (CSettings::Get().GetBool("videoplayer.quitstereomodeonstop") == false)
      return;

    // only change to new stereo mode if not yet in preferred stereo mode
    if (mode == preferred || (preferred == RENDER_STEREO_MODE_AUTO && mode == playing))
      return;
  }

  switch (playbackMode)
  {
  case STEREOSCOPIC_PLAYBACK_MODE_ASK: // Ask
    {
      CApplicationMessenger::Get().MediaPause();

      CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
      pDlgSelect->Reset();
      pDlgSelect->SetHeading(CVariant{g_localizeStrings.Get(36527)});

      int idx_playing   = -1;

      // add choices
      int idx_preferred = pDlgSelect->Add(g_localizeStrings.Get(36524) // preferred
                                     + " ("
                                     + GetLabelForStereoMode(preferred)
                                     + ")");

      int idx_mono = pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_MONO)); // mono / 2d

      if (playing != RENDER_STEREO_MODE_OFF && playing != preferred && preferred != RENDER_STEREO_MODE_AUTO && g_Windowing.SupportsStereo(playing)) // same as movie
        idx_playing = pDlgSelect->Add(g_localizeStrings.Get(36532)
                                    + " ("
                                    + GetLabelForStereoMode(playing)
                                    + ")");

      int idx_select = pDlgSelect->Add( g_localizeStrings.Get(36531) ); // other / select

      pDlgSelect->Open();

      if(pDlgSelect->IsConfirmed())
      {
        int iItem = pDlgSelect->GetSelectedLabel();
        if      (iItem == idx_preferred) mode = preferred;
        else if (iItem == idx_mono)      mode = RENDER_STEREO_MODE_MONO;
        else if (iItem == idx_playing)   mode = RENDER_STEREO_MODE_AUTO;
        else if (iItem == idx_select)    mode = GetStereoModeByUserChoice();

        SetStereoModeByUser( mode );
      }

      CApplicationMessenger::Get().MediaUnPause();
    }
    break;
  case STEREOSCOPIC_PLAYBACK_MODE_PREFERRED: // Stereoscopic
    SetStereoMode( preferred );
    break;
  case 2: // Mono
    SetStereoMode( RENDER_STEREO_MODE_MONO );
    break;
  default:
    break;
  }
}
Exemple #25
0
INFO_RET CMusicInfoScanner::DownloadArtistInfo(const CArtist& artist, const ADDON::ScraperPtr& info, MUSIC_GRABBER::CMusicArtistInfo& artistInfo, CGUIDialogProgress* pDialog)
{
  if (m_handle)
  {
    m_handle->SetTitle(StringUtils::Format(g_localizeStrings.Get(20320).c_str(), info->Name().c_str()));
    m_handle->SetText(artist.strArtist);
  }

  // clear our scraper cache
  info->ClearCache();

  CMusicInfoScraper scraper(info);
  bool bMusicBrainz = false;
  if (!artist.strMusicBrainzArtistID.empty())
  {
    CScraperUrl musicBrainzURL;
    if (ResolveMusicBrainz(artist.strMusicBrainzArtistID, info, musicBrainzURL))
    {
      CMusicArtistInfo artistNfo("nfo", musicBrainzURL);
      scraper.GetArtists().clear();
      scraper.GetArtists().push_back(artistNfo);
      bMusicBrainz = true;
    }
  }

  // handle nfo files
  std::string path = artist.strPath;
  if (path.empty())
    m_musicDatabase.GetArtistPath(artist.idArtist, path);

  std::string strNfo = URIUtils::AddFileToFolder(path, "artist.nfo");
  CNfoFile::NFOResult result=CNfoFile::NO_NFO;
  CNfoFile nfoReader;
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    result = nfoReader.Create(strNfo, info);
    if (result == CNfoFile::FULL_NFO)
    {
      CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
      nfoReader.GetDetails(artistInfo.GetArtist());
      return INFO_ADDED;
    }
    else if (result == CNfoFile::URL_NFO || result == CNfoFile::COMBINED_NFO)
    {
      CScraperUrl scrUrl(nfoReader.ScraperUrl());
      CMusicArtistInfo artistNfo("nfo",scrUrl);
      ADDON::ScraperPtr nfoReaderScraper = nfoReader.GetScraperInfo();
      CLog::Log(LOGDEBUG,"-- nfo-scraper: %s",nfoReaderScraper->Name().c_str());
      CLog::Log(LOGDEBUG,"-- nfo url: %s", scrUrl.m_url[0].m_url.c_str());
      scraper.SetScraperInfo(nfoReaderScraper);
      scraper.GetArtists().push_back(artistNfo);
    }
    else
      CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str());
  }

  if (!scraper.GetArtistCount())
  {
    scraper.FindArtistInfo(artist.strArtist);

    while (!scraper.Completed())
    {
      if (m_bStop)
      {
        scraper.Cancel();
        return INFO_CANCELLED;
      }
      Sleep(1);
    }
  }

  int iSelectedArtist = 0;
  if (result == CNfoFile::NO_NFO && !bMusicBrainz)
  {
    if (scraper.GetArtistCount() >= 1)
    {
      // now load the first match
      if (pDialog && scraper.GetArtistCount() > 1)
      {
        // if we found more then 1 album, let user choose one
        CGUIDialogSelect *pDlg = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
        if (pDlg)
        {
          pDlg->SetHeading(g_localizeStrings.Get(21890));
          pDlg->Reset();
          pDlg->EnableButton(true, 413); // manual

          for (int i = 0; i < scraper.GetArtistCount(); ++i)
          {
            // set the label to artist
            CFileItem item(scraper.GetArtist(i).GetArtist());
            std::string strTemp=scraper.GetArtist(i).GetArtist().strArtist;
            if (!scraper.GetArtist(i).GetArtist().strBorn.empty())
              strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")";
            if (!scraper.GetArtist(i).GetArtist().genre.empty())
            {
              std::string genres = StringUtils::Join(scraper.GetArtist(i).GetArtist().genre, g_advancedSettings.m_musicItemSeparator);
              if (!genres.empty())
                strTemp = StringUtils::Format("[%s] %s", genres.c_str(), strTemp.c_str());
            }
            item.SetLabel(strTemp);
            item.m_idepth = i; // use this to hold the index of the album in the scraper
            pDlg->Add(&item);
          }
          pDlg->DoModal();

          // and wait till user selects one
          if (pDlg->GetSelectedLabel() < 0)
          { // none chosen
            if (!pDlg->IsButtonPressed())
              return INFO_CANCELLED;

            // manual button pressed
            std::string strNewArtist = artist.strArtist;
            if (!CGUIKeyboardFactory::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return INFO_CANCELLED;

            if (pDialog)
            {
              pDialog->SetLine(0, strNewArtist);
              pDialog->Progress();
            }

            CArtist newArtist;
            newArtist.strArtist = strNewArtist;
            return DownloadArtistInfo(newArtist, info, artistInfo, pDialog);
          }
          iSelectedArtist = pDlg->GetSelectedItem()->m_idepth;
        }
      }
    }
    else
      return INFO_NOT_FOUND;
  }

  scraper.LoadArtistInfo(iSelectedArtist, artist.strArtist);
  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      return INFO_CANCELLED;
    }
    Sleep(1);
  }

  if (!scraper.Succeeded())
    return INFO_ERROR;

  artistInfo = scraper.GetArtist(iSelectedArtist);

  if (result == CNfoFile::COMBINED_NFO)
    nfoReader.GetDetails(artistInfo.GetArtist(), NULL, true);

  return INFO_ADDED;
}
bool CMusicInfoScanner::DownloadArtistInfo(const CStdString& strPath, const CStdString& strArtist, CGUIDialogProgress* pDialog)
{
  DIRECTORY::MUSICDATABASEDIRECTORY::CQueryParams params;
  DIRECTORY::MUSICDATABASEDIRECTORY::CDirectoryNode::GetDatabaseInfo(strPath, params);
  CArtist artist;
  m_musicDatabase.Open();
  if (m_musicDatabase.GetArtistInfo(params.GetArtistId(),artist)) // already got the info
    return true;

  // find artist info
  SScraperInfo info;
  if (!m_musicDatabase.GetScraperForPath(strPath,info))
  {
    m_musicDatabase.Close();
    return false;
  }

  if (m_pObserver)
  {
    m_pObserver->OnStateChanged(DOWNLOADING_ARTIST_INFO);
    m_pObserver->OnDirectoryChanged(strArtist);  
  }

  CMusicInfoScraper scraper(info);
  // handle nfo files
  CStdString strArtistPath, strNfo;
  m_musicDatabase.GetArtistPath(params.GetArtistId(),strArtistPath);
  CUtil::AddFileToFolder(strArtistPath,"artist.nfo",strNfo);
  if (XFILE::CFile::Exists(strNfo))
  {
    CLog::Log(LOGDEBUG,"Found matching nfo file: %s", strNfo.c_str());
    CNfoFile nfoReader("albums");
    if (nfoReader.Create(strNfo) == S_OK)
    {
      if (nfoReader.m_strScraper == "NFO")
      {
        CLog::Log(LOGDEBUG, "%s Got details from nfo", __FUNCTION__);
        CArtist artist;
        nfoReader.GetDetails(artist);
        m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
        m_musicDatabase.Close();
        return true;
      }
      else
      {
        CScraperUrl scrUrl(nfoReader.m_strImDbUrl); 
        CMusicArtistInfo artist("nfo",scrUrl);
        scraper.GetArtists().push_back(artist);
      }
    }
    else
      CLog::Log(LOGERROR,"Unable to find an url in nfo file: %s", strNfo.c_str());
  }

  if (!scraper.GetArtistCount())
    scraper.FindArtistinfo(strArtist);

  while (!scraper.Completed())
  {
    if (m_bStop)
    {
      scraper.Cancel();
      break;
    }
    Sleep(1);
  }

  if (scraper.Successfull() && scraper.GetArtistCount() >= 1)
  {
    int iSelectedArtist = 0;
    // now load the first match
    if (pDialog && scraper.GetArtistCount() > 1)
    {
      // if we found more then 1 album, let user choose one
      CGUIDialogSelect *pDlg = (CGUIDialogSelect*)m_gWindowManager.GetWindow(WINDOW_DIALOG_SELECT);
      if (pDlg)
      {
        pDlg->SetHeading(g_localizeStrings.Get(21890));
        pDlg->Reset();
        pDlg->EnableButton(true);
        pDlg->SetButtonLabel(413); // manual

        for (int i = 0; i < scraper.GetArtistCount(); ++i)
        {
          // set the label to artist
          CFileItem item(scraper.GetArtist(i).GetArtist());
          CStdString strTemp=scraper.GetArtist(i).GetArtist().strArtist;
          if (!scraper.GetArtist(i).GetArtist().strBorn.IsEmpty())
            strTemp += " ("+scraper.GetArtist(i).GetArtist().strBorn+")";
          if (!scraper.GetArtist(i).GetArtist().strGenre.IsEmpty())
            strTemp.Format("[%s] %s",scraper.GetArtist(i).GetArtist().strGenre.c_str(),strTemp.c_str());
          item.SetLabel(strTemp);
          item.m_idepth = i; // use this to hold the index of the album in the scraper
          pDlg->Add(&item);
        }
        pDlg->DoModal();

        // and wait till user selects one
        if (pDlg->GetSelectedLabel() < 0) 
        { // none chosen
          if (!pDlg->IsButtonPressed()) return false;
          // manual button pressed
          CStdString strNewArtist = strArtist;
          if (!CGUIDialogKeyboard::ShowAndGetInput(strNewArtist, g_localizeStrings.Get(16025), false)) return false;

          if (pDialog)
          {
            pDialog->SetLine(0, strNewArtist);
            pDialog->Progress();
          }
          m_musicDatabase.Close();
          return DownloadArtistInfo(strPath,strArtist,pDialog);
        }
        iSelectedArtist = pDlg->GetSelectedItem().m_idepth;
      }
    }
    
    scraper.LoadArtistinfo(iSelectedArtist);

    while (!scraper.Completed())
    {
      if (m_bStop)
      {
        scraper.Cancel();
        break;
      }
      Sleep(1);
    }

    if (scraper.Successfull())
    {
      artist = scraper.GetArtist(iSelectedArtist).GetArtist();
      m_musicDatabase.SetArtistInfo(params.GetArtistId(), artist);
    }
  }
  else
  {
    m_musicDatabase.Close();
    return false;
  }

  // check thumb stuff
  if (artist.thumbURL.m_url.size())
  {
    CFileItem item(strArtist);
    CStdString thumb = item.GetCachedArtistThumb();
    if (!XFILE::CFile::Exists(thumb))
      CScraperUrl::DownloadThumbnail(thumb,artist.thumbURL.m_url[0]);
  }
   
  m_musicDatabase.Close();
  return true;
}
Exemple #27
0
void CStereoscopicsManager::OnPlaybackStarted(void)
{
  if (!g_infoManager.EvaluateBool("videoplayer.isstereoscopic"))
    return;

  STEREOSCOPIC_PLAYBACK_MODE playbackMode = (STEREOSCOPIC_PLAYBACK_MODE) CSettings::Get().GetInt("videoplayer.stereoscopicplaybackmode");
  RENDER_STEREO_MODE mode = GetStereoMode();

  // early return if playback mode should be ignored and we're in no stereoscopic mode right now
  if (playbackMode == STEREOSCOPIC_PLAYBACK_MODE_IGNORE && mode == RENDER_STEREO_MODE_OFF)
    return;

  if (mode != RENDER_STEREO_MODE_OFF)
    return;

  switch (playbackMode)
  {
  case STEREOSCOPIC_PLAYBACK_MODE_ASK: // Ask
    {
      CApplicationMessenger::Get().MediaPause();

      CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
      pDlgSelect->Reset();
      pDlgSelect->SetHeading(g_localizeStrings.Get(36527).c_str());

      RENDER_STEREO_MODE preferred = GetPreferredPlaybackMode();
      RENDER_STEREO_MODE playing   = GetStereoModeOfPlayingVideo();

      int idx_playing   = -1;

      // add choices
      int idx_preferred = pDlgSelect->Add(g_localizeStrings.Get(36524) // preferred
                                     + " ("
                                     + GetLabelForStereoMode(preferred)
                                     + ")");

      int idx_mono = pDlgSelect->Add(GetLabelForStereoMode(RENDER_STEREO_MODE_MONO)); // mono / 2d

      if(playing != RENDER_STEREO_MODE_OFF && playing != preferred && g_Windowing.SupportsStereo(playing))
        idx_playing = pDlgSelect->Add(g_localizeStrings.Get(36532)
                                    + " ("
                                    + GetLabelForStereoMode(playing)
                                    + ")");

      int idx_select = pDlgSelect->Add( g_localizeStrings.Get(36531) ); // other / select

      pDlgSelect->DoModal();

      if(pDlgSelect->IsConfirmed())
      {
        int iItem = pDlgSelect->GetSelectedLabel();
        if      (iItem == idx_preferred) mode = preferred;
        else if (iItem == idx_mono)      mode = RENDER_STEREO_MODE_MONO;
        else if (iItem == idx_playing)   mode = playing;
        else if (iItem == idx_select)    mode = GetStereoModeByUserChoice();

        SetStereoMode(mode);
      }

      CApplicationMessenger::Get().MediaUnPause();
    }
    break;
  case STEREOSCOPIC_PLAYBACK_MODE_PREFERRED: // Stereoscopic
    SetStereoMode( GetPreferredPlaybackMode() );
    break;
  case 2: // Mono
    SetStereoMode( RENDER_STEREO_MODE_MONO );
    break;
  default:
    break;
  }
}