AlbumCoverManager::AlbumCoverManager(LibraryBackend* backend,
                                     CoverProviders* cover_providers,
                                     QWidget* parent,
                                     QNetworkAccessManager* network)
  : QMainWindow(parent),
    ui_(new Ui_CoverManager),
    cover_providers_(cover_providers),
    album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
    backend_(backend),
    cover_loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this)),
    cover_fetcher_(new AlbumCoverFetcher(cover_providers_, this, network)),
    cover_searcher_(NULL),
    artist_icon_(IconLoader::Load("x-clementine-artist")),
    all_artists_icon_(IconLoader::Load("x-clementine-album")),
    context_menu_(new QMenu(this)),
    progress_bar_(new QProgressBar(this)),
    jobs_(0)
{
  ui_->setupUi(this);
  ui_->albums->set_cover_manager(this);

  // Icons
  ui_->action_fetch->setIcon(IconLoader::Load("download"));
  ui_->view->setIcon(IconLoader::Load("view-choose"));
  ui_->fetch->setIcon(IconLoader::Load("download"));
  ui_->action_add_to_playlist->setIcon(IconLoader::Load("media-playback-start"));
  ui_->action_load->setIcon(IconLoader::Load("media-playback-start"));

  album_cover_choice_controller_->SetCoverProviders(cover_providers_);
  album_cover_choice_controller_->SetLibrary(backend_);

  // Get a square version of nocover.png
  QImage nocover(":/nocover.png");
  nocover = nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  QImage square_nocover(120, 120, QImage::Format_ARGB32);
  square_nocover.fill(0);
  QPainter p(&square_nocover);
  p.setOpacity(0.4);
  p.drawImage((120 - nocover.width()) / 2, (120 - nocover.height()) / 2, nocover);
  p.end();
  no_cover_icon_ = QPixmap::fromImage(square_nocover);

  cover_searcher_ = new AlbumCoverSearcher(no_cover_icon_, this);

  // Set up the status bar
  statusBar()->addPermanentWidget(progress_bar_);
  progress_bar_->hide();

  ui_->albums->setAttribute(Qt::WA_MacShowFocusRect, false);
  ui_->artists->setAttribute(Qt::WA_MacShowFocusRect, false);

  QShortcut* close = new QShortcut(QKeySequence::Close, this);
  connect(close, SIGNAL(activated()), SLOT(close()));

  ResetFetchCoversButton();
}
Ejemplo n.º 2
0
AlbumCoverManager::AlbumCoverManager(Application* app,
                                     LibraryBackend* library_backend,
                                     QWidget* parent,
                                     QNetworkAccessManager* network)
    : QMainWindow(parent),
      ui_(new Ui_CoverManager),
      app_(app),
      album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
      cover_fetcher_(
          new AlbumCoverFetcher(app_->cover_providers(), this, network)),
      cover_searcher_(nullptr),
      cover_export_(nullptr),
      cover_exporter_(new AlbumCoverExporter(this)),
      artist_icon_(IconLoader::Load("x-clementine-artist")),
      all_artists_icon_(IconLoader::Load("x-clementine-album")),
      context_menu_(new QMenu(this)),
      progress_bar_(new QProgressBar(this)),
      abort_progress_(new QPushButton(this)),
      jobs_(0),
      library_backend_(library_backend) {
  ui_->setupUi(this);
  ui_->albums->set_cover_manager(this);

  // Icons
  ui_->action_fetch->setIcon(IconLoader::Load("download"));
  ui_->export_covers->setIcon(IconLoader::Load("document-save"));
  ui_->view->setIcon(IconLoader::Load("view-choose"));
  ui_->fetch->setIcon(IconLoader::Load("download"));
  ui_->action_add_to_playlist->setIcon(
      IconLoader::Load("media-playback-start"));
  ui_->action_load->setIcon(IconLoader::Load("media-playback-start"));

  album_cover_choice_controller_->SetApplication(app_);

  // Get a square version of nocover.png
  QImage nocover(":/nocover.png");
  nocover =
      nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  QImage square_nocover(120, 120, QImage::Format_ARGB32);
  square_nocover.fill(0);
  QPainter p(&square_nocover);
  p.setOpacity(0.4);
  p.drawImage((120 - nocover.width()) / 2, (120 - nocover.height()) / 2,
              nocover);
  p.end();
  no_cover_icon_ = QPixmap::fromImage(square_nocover);

  cover_searcher_ = new AlbumCoverSearcher(no_cover_icon_, app_, this);
  cover_export_ = new AlbumCoverExport(this);

  // Set up the status bar
  statusBar()->addPermanentWidget(progress_bar_);
  statusBar()->addPermanentWidget(abort_progress_);
  progress_bar_->hide();
  abort_progress_->hide();
  abort_progress_->setText(tr("Abort"));
  connect(abort_progress_, SIGNAL(clicked()), this, SLOT(CancelRequests()));

  ui_->albums->setAttribute(Qt::WA_MacShowFocusRect, false);
  ui_->artists->setAttribute(Qt::WA_MacShowFocusRect, false);

  QShortcut* close = new QShortcut(QKeySequence::Close, this);
  connect(close, SIGNAL(activated()), SLOT(close()));

  EnableCoversButtons();
}