int CGUIDialogInfoProviderSettings::Show(ADDON::ScraperPtr& scraper)
{
  CGUIDialogInfoProviderSettings *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogInfoProviderSettings>(WINDOW_DIALOG_INFOPROVIDER_SETTINGS);
  if (!dialog || !scraper)
    return -1;
  if (scraper->Content() != CONTENT_ARTISTS && scraper->Content() != CONTENT_ALBUMS)
    return -1;

  dialog->m_showSingleScraper = true;
  dialog->m_singleScraperType = scraper->Content();

  if (dialog->m_singleScraperType == CONTENT_ALBUMS)
    dialog->SetAlbumScraper(scraper);
  else
    dialog->SetArtistScraper(scraper);
  // toast selected but disabled scrapers
  if (CServiceBroker::GetAddonMgr().IsAddonDisabled(scraper->ID()))
    CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(24024), scraper->Name(), 2000, true);

  dialog->Open();

  bool confirmed = dialog->IsConfirmed();
  unsigned int applyToItems = dialog->m_applyToItems;
  if (confirmed)
  {
    if (dialog->m_singleScraperType == CONTENT_ALBUMS)
      scraper = dialog->GetAlbumScraper();
    else
    {
      scraper = dialog->GetArtistScraper();
      // Save artist information folder (here not in the caller) when applying setting as default for all artists
      if (applyToItems == INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_DEFAULT)
        CServiceBroker::GetSettings().SetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER, dialog->m_strArtistInfoPath);
    }
    if (scraper)
      scraper->SetPathSettings(dialog->m_singleScraperType, "");
  }

  dialog->ResetDefaults();

  if (confirmed)
    return applyToItems;
  else
    return -1;
}
bool CGUIDialogContentSettings::Show(ADDON::ScraperPtr& scraper, VIDEO::SScanSettings& settings, CONTENT_TYPE content /* = CONTENT_NONE */)
{
  CGUIDialogContentSettings *dialog = g_windowManager.GetWindow<CGUIDialogContentSettings>(WINDOW_DIALOG_CONTENT_SETTINGS);
  if (dialog == NULL)
    return false;

  if (scraper != NULL)
  {
    dialog->SetContent(content != CONTENT_NONE ? content : scraper->Content());
    dialog->SetScraper(scraper);
    // toast selected but disabled scrapers
    if (CServiceBroker::GetAddonMgr().IsAddonDisabled(scraper->ID()))
      CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(24024), scraper->Name(), 2000, true);
  }

  dialog->SetScanSettings(settings);
  dialog->Open();

  bool confirmed = dialog->IsConfirmed();
  if (confirmed)
  {
    scraper = dialog->GetScraper();
    content = dialog->GetContent();

    if (scraper == NULL || content == CONTENT_NONE)
      settings.exclude = dialog->GetExclude();
    else
    {
      settings.exclude = false;
      settings.noupdate = dialog->GetNoUpdating();
      scraper->SetPathSettings(content, "");

      if (content == CONTENT_TVSHOWS)
      {
        settings.parent_name = settings.parent_name_root = dialog->GetContainsSingleItem();
        settings.recurse = 0;
      }
      else if (content == CONTENT_MOVIES || content == CONTENT_MUSICVIDEOS)
      {
        if (dialog->GetUseDirectoryNames())
        {
          settings.parent_name = true;
          settings.parent_name_root = false;
          settings.recurse = dialog->GetScanRecursive() ? INT_MAX : 1;

          if (dialog->GetContainsSingleItem())
          {
            settings.parent_name_root = true;
            settings.recurse = 0;
          }
        }
        else
        {
          settings.parent_name = false;
          settings.parent_name_root = false;
          settings.recurse = dialog->GetScanRecursive() ? INT_MAX : 0;
        }
      }
    }
  }

  // now that we have evaluated all settings we need to reset the content
  dialog->ResetContent();

  return confirmed;
}
Exemple #3
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;
}