Example #1
0
bool CGUIWindowMusicNav::ManageInfoProvider(const CFileItemPtr item)
{
  CQueryParams params;
  CDirectoryNode::GetDatabaseInfo(item->GetPath(), params);
  // Management of Info provider only valid for specific artist or album items
  if (params.GetAlbumId() == -1 && params.GetArtistId() == -1)
    return false;

  // Set things up for processing artist or albums
  CONTENT_TYPE content = CONTENT_ALBUMS;
  int id = params.GetAlbumId();
  if (id == -1)
  {
    content = CONTENT_ARTISTS;
    id = params.GetArtistId();
  }

  ADDON::ScraperPtr scraper;
  // Get specific scraper and settings for current  item or use default
  if (!m_musicdatabase.GetScraper(id, content, scraper))
  {
    ADDON::AddonPtr defaultScraper;
    if (ADDON::CAddonSystemSettings::GetInstance().GetActive(
        ADDON::ScraperTypeFromContent(content), defaultScraper))
    {
      scraper = std::dynamic_pointer_cast<ADDON::CScraper>(defaultScraper);
    }
  }

  // Set Information provider and settings
  int applyto = CGUIDialogInfoProviderSettings::Show(scraper);
  if (applyto >= 0)
  {
    bool result = false;
    CVariant msgctxt;
    switch (applyto)
    {
    case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_THISITEM: // Change information provider for specific item
      result = m_musicdatabase.SetScraper(id, content, scraper);
      break;
    case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_ALLVIEW: // Change information provider for the filtered items shown on this node
      {
        msgctxt = 38069;
        if (content == CONTENT_ARTISTS)
          msgctxt = 38068;
        if (CGUIDialogYesNo::ShowAndGetInput(CVariant{ 20195 }, msgctxt)) // Change information provider, confirm for all shown
        {
          // Set scraper for all items on curent view.
          std::string strPath = "musicdb://";
          if (content == CONTENT_ARTISTS)
            strPath += "artists";
          else
            strPath += "albums";
          URIUtils::AddSlashAtEnd(strPath);
          // Items on view could be limited by navigation criteria, smart playlist rules or a filter.
          // Get these options, except ID, from item path
          CURL musicUrl(item->GetPath());  //Use CURL, as CMusicDbUrl removes "filter" option
          if (content == CONTENT_ARTISTS)
            musicUrl.RemoveOption("artistid");
          else
            musicUrl.RemoveOption("albumid");
         strPath += musicUrl.GetOptions();
          result = m_musicdatabase.SetScraperAll(strPath, scraper);
        }
      }
      break;
    case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_DEFAULT: // Change information provider for all items
      {
        msgctxt = 38071;
        if (content == CONTENT_ARTISTS)
          msgctxt = 38070;
        if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, msgctxt)) // Change information provider, confirm default and clear
        {
          // Save scraper addon default setting values
          scraper->SaveSettings();
          // Set default scraper
          if (content == CONTENT_ARTISTS)
            CServiceBroker::GetSettings()->SetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER, scraper->ID());
          else
            CServiceBroker::GetSettings()->SetString(CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER, scraper->ID());
          CServiceBroker::GetSettings()->Save();
          // Clear all item specifc settings
          if (content == CONTENT_ARTISTS)
            result = m_musicdatabase.SetScraperAll("musicdb://artists/", nullptr);
          else
            result = m_musicdatabase.SetScraperAll("musicdb://albums/", nullptr);
        }
      }
    default:
      break;
    }
    if (!result)
      return false;

    // Refresh additional information using the new settings
    if (applyto == INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_ALLVIEW || applyto == INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_DEFAULT)
    {
      // Change information provider, all artists or albums
      if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, CVariant{38072}))
        OnItemInfoAll(m_vecItems->GetPath(), true);
    }
    else
    {
      // Change information provider, selected artist or album
      if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, CVariant{38073}))
      {
        std::string itempath = StringUtils::Format("musicdb://albums/%li/", id);
        if (content == CONTENT_ARTISTS)
          itempath = StringUtils::Format("musicdb://artists/%li/", id);
        OnItemInfoAll(itempath, true);
      }
    }
  }
  return true;
}