void AlbumCoverChoiceController::AlbumCoverFetched(
    quint64 id, const QImage& image, const CoverSearchStatistics& statistics) {
  Song song;
  if (cover_fetching_tasks_.contains(id)) {
    song = cover_fetching_tasks_.take(id);
  }

  if (!image.isNull()) {
    QString cover = SaveCoverInCache(song.artist(), song.album(), image);
    SaveCover(&song, cover);
  }

  emit AutomaticCoverSearchDone();
}
示例#2
0
NowPlayingWidget::NowPlayingWidget(QWidget* parent)
    : QWidget(parent),
      app_(nullptr),
      album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
      mode_(SmallSongDetails),
      menu_(new QMenu(this)),
      above_statusbar_action_(nullptr),
      fit_cover_width_action_(nullptr),
      visible_(false),
      small_ideal_height_(0),
      fit_width_(false),
      show_hide_animation_(new QTimeLine(500, this)),
      fade_animation_(new QTimeLine(1000, this)),
      details_(new QTextDocument(this)),
      previous_track_opacity_(0.0),
      bask_in_his_glory_action_(nullptr),
      downloading_covers_(false),
      aww_(false),
      kittens_(nullptr),
      pending_kitten_(0) {
  // Load settings
  QSettings s;
  s.beginGroup(kSettingsGroup);
  mode_ = Mode(s.value("mode", SmallSongDetails).toInt());
  album_cover_choice_controller_->search_cover_auto_action()->setChecked(
      s.value("search_for_cover_auto", false).toBool());
  fit_width_ = s.value("fit_cover_width", false).toBool();

  // Accept drops for setting album art
  setAcceptDrops(true);

  // Context menu
  QActionGroup* mode_group = new QActionGroup(this);
  QSignalMapper* mode_mapper = new QSignalMapper(this);
  connect(mode_mapper, SIGNAL(mapped(int)), SLOT(SetMode(int)));
  CreateModeAction(SmallSongDetails, tr("Small album cover"), mode_group,
                   mode_mapper);
  CreateModeAction(LargeSongDetails, tr("Large album cover"), mode_group,
                   mode_mapper);
  CreateModeAction(LargeSongDetailsBelow,
                   tr("Large album cover (details below)"), mode_group,
                   mode_mapper);

  menu_->addActions(mode_group->actions());

  fit_cover_width_action_ = menu_->addAction(tr("Fit cover to width"));

  fit_cover_width_action_->setCheckable(true);
  fit_cover_width_action_->setEnabled((mode_ != SmallSongDetails) ? true
                                                                  : false);
  connect(fit_cover_width_action_, SIGNAL(toggled(bool)),
          SLOT(FitCoverWidth(bool)));
  fit_cover_width_action_->setChecked(fit_width_);
  menu_->addSeparator();

  QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();

  // Here we add the search automatically action, too!
  actions.append(album_cover_choice_controller_->search_cover_auto_action());

  connect(album_cover_choice_controller_->cover_from_file_action(),
          SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
  connect(album_cover_choice_controller_->cover_to_file_action(),
          SIGNAL(triggered()), this, SLOT(SaveCoverToFile()));
  connect(album_cover_choice_controller_->cover_from_url_action(),
          SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
  connect(album_cover_choice_controller_->search_for_cover_action(),
          SIGNAL(triggered()), this, SLOT(SearchForCover()));
  connect(album_cover_choice_controller_->unset_cover_action(),
          SIGNAL(triggered()), this, SLOT(UnsetCover()));
  connect(album_cover_choice_controller_->show_cover_action(),
          SIGNAL(triggered()), this, SLOT(ShowCover()));
  connect(album_cover_choice_controller_->search_cover_auto_action(),
          SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically()));

  menu_->addActions(actions);
  menu_->addSeparator();
  above_statusbar_action_ = menu_->addAction(tr("Show above status bar"));

  above_statusbar_action_->setCheckable(true);
  connect(above_statusbar_action_, SIGNAL(toggled(bool)),
          SLOT(ShowAboveStatusBar(bool)));
  above_statusbar_action_->setChecked(
      s.value("above_status_bar", false).toBool());

  bask_in_his_glory_action_ =
      menu_->addAction(tr("ALL GLORY TO THE HYPNOTOAD"));
  bask_in_his_glory_action_->setVisible(false);
  connect(bask_in_his_glory_action_, SIGNAL(triggered()), SLOT(Bask()));

  // Animations
  connect(show_hide_animation_, SIGNAL(frameChanged(int)),
          SLOT(SetHeight(int)));
  setMaximumHeight(0);

  connect(fade_animation_, SIGNAL(valueChanged(qreal)),
          SLOT(FadePreviousTrack(qreal)));
  fade_animation_->setDirection(QTimeLine::Backward);  // 1.0 -> 0.0

  // add placeholder text to get the correct height
  if (mode_ == LargeSongDetailsBelow) {
    details_->setDefaultStyleSheet(
        "p {"
        "  font-size: small;"
        "  color: white;"
        "}");
    details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
  }

  UpdateHeight();

  connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()),
          this, SLOT(AutomaticCoverSearchDone()));
}