1 /* This file is part of Clementine.
2 Copyright 2010, David Sansome <me@davidsansome.com>
3
4 Clementine is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 Clementine is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Clementine. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "nowplayingwidget.h"
19
20 #include <QDesktopWidget>
21 #include <QMenu>
22 #include <QMovie>
23 #include <QPainter>
24 #include <QPaintEvent>
25 #include <QSettings>
26 #include <QTextDocument>
27 #include <QTimeLine>
28 #include <QtDebug>
29
30 #include "fullscreenhypnotoad.h"
31 #include "core/application.h"
32 #include "core/logging.h"
33 #include "covers/albumcoverloader.h"
34 #include "covers/coverproviders.h"
35 #include "covers/currentartloader.h"
36 #include "covers/kittenloader.h"
37 #include "library/librarybackend.h"
38 #include "networkremote/networkremote.h"
39 #include "ui/albumcoverchoicecontroller.h"
40 #include "ui/iconloader.h"
41
42 const char* NowPlayingWidget::kSettingsGroup = "NowPlayingWidget";
43
44 const char* NowPlayingWidget::kHypnotoadPath = ":/hypnotoad.gif";
45
46 // Space between the cover and the details in small mode
47 const int NowPlayingWidget::kPadding = 2;
48
49 // Width of the transparent to black gradient above and below the text in large
50 // mode
51 const int NowPlayingWidget::kGradientHead = 40;
52 const int NowPlayingWidget::kGradientTail = 20;
53
54 // Maximum height of the cover in large mode, and offset between the
55 // bottom of the cover and bottom of the widget
56 const int NowPlayingWidget::kMaxCoverSize = 260;
57 const int NowPlayingWidget::kBottomOffset = 0;
58
59 // Border for large mode
60 const int NowPlayingWidget::kTopBorder = 4;
61
NowPlayingWidget(QWidget * parent)62 NowPlayingWidget::NowPlayingWidget(QWidget* parent)
63 : QWidget(parent),
64 app_(nullptr),
65 album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
66 mode_(SmallSongDetails),
67 menu_(new QMenu(this)),
68 above_statusbar_action_(nullptr),
69 fit_cover_width_action_(nullptr),
70 visible_(false),
71 small_ideal_height_(0),
72 fit_width_(false),
73 show_hide_animation_(new QTimeLine(500, this)),
74 fade_animation_(new QTimeLine(1000, this)),
75 details_(new QTextDocument(this)),
76 previous_track_opacity_(0.0),
77 bask_in_his_glory_action_(nullptr),
78 downloading_covers_(false),
79 aww_(false),
80 kittens_(nullptr),
81 pending_kitten_(0) {
82 // Load settings
83 QSettings s;
84 s.beginGroup(kSettingsGroup);
85 mode_ = Mode(s.value("mode", SmallSongDetails).toInt());
86 album_cover_choice_controller_->search_cover_auto_action()->setChecked(
87 s.value("search_for_cover_auto", false).toBool());
88 fit_width_ = s.value("fit_cover_width", false).toBool();
89
90 // Accept drops for setting album art
91 setAcceptDrops(true);
92
93 // Context menu
94 QActionGroup* mode_group = new QActionGroup(this);
95 CreateModeAction(SmallSongDetails, tr("Small album cover"), mode_group);
96 CreateModeAction(LargeSongDetails, tr("Large album cover"), mode_group);
97 CreateModeAction(LargeSongDetailsBelow,
98 tr("Large album cover (details below)"), mode_group);
99 CreateModeAction(LargeNoSongDetails, tr("Large album cover (no details)"),
100 mode_group);
101
102 menu_->addActions(mode_group->actions());
103
104 fit_cover_width_action_ = menu_->addAction(tr("Fit cover to width"));
105
106 fit_cover_width_action_->setCheckable(true);
107 fit_cover_width_action_->setEnabled(mode_ != SmallSongDetails);
108 connect(fit_cover_width_action_, SIGNAL(toggled(bool)),
109 SLOT(FitCoverWidth(bool)));
110 fit_cover_width_action_->setChecked(fit_width_);
111 menu_->addSeparator();
112
113 QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
114
115 // Here we add the search automatically action, too!
116 actions.append(album_cover_choice_controller_->search_cover_auto_action());
117
118 connect(album_cover_choice_controller_->cover_from_file_action(),
119 SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
120 connect(album_cover_choice_controller_->cover_to_file_action(),
121 SIGNAL(triggered()), this, SLOT(SaveCoverToFile()));
122 connect(album_cover_choice_controller_->cover_from_url_action(),
123 SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
124 connect(album_cover_choice_controller_->search_for_cover_action(),
125 SIGNAL(triggered()), this, SLOT(SearchForCover()));
126 connect(album_cover_choice_controller_->unset_cover_action(),
127 SIGNAL(triggered()), this, SLOT(UnsetCover()));
128 connect(album_cover_choice_controller_->show_cover_action(),
129 SIGNAL(triggered()), this, SLOT(ShowCover()));
130 connect(album_cover_choice_controller_->search_cover_auto_action(),
131 SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically()));
132
133 menu_->addActions(actions);
134 menu_->addSeparator();
135 above_statusbar_action_ = menu_->addAction(tr("Show above status bar"));
136
137 above_statusbar_action_->setCheckable(true);
138 connect(above_statusbar_action_, SIGNAL(toggled(bool)),
139 SLOT(ShowAboveStatusBar(bool)));
140 above_statusbar_action_->setChecked(
141 s.value("above_status_bar", false).toBool());
142
143 bask_in_his_glory_action_ =
144 menu_->addAction(tr("ALL GLORY TO THE HYPNOTOAD"));
145 bask_in_his_glory_action_->setVisible(false);
146 connect(bask_in_his_glory_action_, SIGNAL(triggered()), SLOT(Bask()));
147
148 // Animations
149 connect(show_hide_animation_, SIGNAL(frameChanged(int)),
150 SLOT(SetHeight(int)));
151 setMaximumHeight(0);
152
153 connect(fade_animation_, SIGNAL(valueChanged(qreal)),
154 SLOT(FadePreviousTrack(qreal)));
155 fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
156
157 // add placeholder text to get the correct height
158 if (mode_ == LargeSongDetailsBelow) {
159 details_->setDefaultStyleSheet(
160 "p {"
161 " font-size: small;"
162 " color: white;"
163 "}");
164 details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
165 }
166
167 UpdateHeight();
168
169 connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()),
170 this, SLOT(AutomaticCoverSearchDone()));
171 }
172
~NowPlayingWidget()173 NowPlayingWidget::~NowPlayingWidget() {}
174
SetApplication(Application * app)175 void NowPlayingWidget::SetApplication(Application* app) {
176 app_ = app;
177
178 album_cover_choice_controller_->SetApplication(app_);
179 connect(app_->current_art_loader(), SIGNAL(ArtLoaded(Song, QString, QImage)),
180 SLOT(AlbumArtLoaded(Song, QString, QImage)));
181 }
182
CreateModeAction(Mode mode,const QString & text,QActionGroup * group)183 void NowPlayingWidget::CreateModeAction(Mode mode, const QString& text,
184 QActionGroup* group) {
185 QAction* action = new QAction(text, group);
186 action->setCheckable(true);
187 connect(action, &QAction::triggered, [this, mode]() { SetMode(mode); });
188
189 if (mode == mode_) action->setChecked(true);
190 }
191
set_ideal_height(int height)192 void NowPlayingWidget::set_ideal_height(int height) {
193 small_ideal_height_ = height;
194 UpdateHeight();
195 }
196
sizeHint() const197 QSize NowPlayingWidget::sizeHint() const {
198 return QSize(cover_loader_options_.desired_height_, total_height_);
199 }
200
UpdateHeight()201 void NowPlayingWidget::UpdateHeight() {
202 switch (mode_) {
203 case SmallSongDetails:
204 cover_loader_options_.desired_height_ = small_ideal_height_;
205 total_height_ = small_ideal_height_;
206 break;
207
208 case LargeSongDetails:
209 case LargeNoSongDetails:
210 if (fit_width_) {
211 cover_loader_options_.desired_height_ = width();
212 } else {
213 cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
214 }
215 total_height_ =
216 kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
217 break;
218
219 case LargeSongDetailsBelow:
220 if (fit_width_) {
221 cover_loader_options_.desired_height_ = width();
222 } else {
223 cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
224 }
225 total_height_ = kTopBorder + cover_loader_options_.desired_height_ +
226 kBottomOffset + details_->size().height();
227 break;
228 }
229
230 // Update the animation settings and resize the widget now if we're visible
231 show_hide_animation_->setFrameRange(0, total_height_);
232 if (visible_ && show_hide_animation_->state() != QTimeLine::Running)
233 setMaximumHeight(total_height_);
234
235 // Re-scale the current image
236 if (metadata_.is_valid()) {
237 ScaleCover();
238 }
239
240 // Tell Qt we've changed size
241 updateGeometry();
242 }
243
Stopped()244 void NowPlayingWidget::Stopped() { SetVisible(false); }
245
UpdateDetailsText()246 void NowPlayingWidget::UpdateDetailsText() {
247 QString html;
248
249 switch (mode_) {
250 case SmallSongDetails:
251 case LargeNoSongDetails:
252 details_->setTextWidth(-1);
253 details_->setDefaultStyleSheet("");
254 html += "<p>";
255 break;
256
257 case LargeSongDetails:
258 details_->setTextWidth(cover_loader_options_.desired_height_);
259 details_->setDefaultStyleSheet(
260 "p {"
261 " font-size: small;"
262 " color: white;"
263 "}");
264 html += "<p align=center>";
265 break;
266
267 case LargeSongDetailsBelow:
268 details_->setTextWidth(cover_loader_options_.desired_height_);
269 if (fit_width_) {
270 details_->setDefaultStyleSheet(
271 "p {"
272 " font-size: small;"
273 "}");
274 } else {
275 details_->setDefaultStyleSheet(
276 "p {"
277 " font-size: small;"
278 " color: white;"
279 "}");
280 }
281 html += "<p align=center>";
282 break;
283 }
284
285 // TODO: Make this configurable
286 html += QString("<i>%1</i><br/>%2<br/>%3").arg(
287 metadata_.PrettyTitle().toHtmlEscaped(), metadata_.artist().toHtmlEscaped(),
288 metadata_.album().toHtmlEscaped());
289
290 html += "</p>";
291 details_->setHtml(html);
292
293 // if something spans multiple lines the height needs to change
294 if (mode_ == LargeSongDetailsBelow) {
295 UpdateHeight();
296 }
297 }
298
ScaleCover()299 void NowPlayingWidget::ScaleCover() {
300 cover_ = QPixmap::fromImage(
301 AlbumCoverLoader::ScaleAndPad(cover_loader_options_, original_));
302 update();
303 }
304
KittenLoaded(quint64 id,const QImage & image)305 void NowPlayingWidget::KittenLoaded(quint64 id, const QImage& image) {
306 if (aww_ && pending_kitten_ == id) {
307 SetImage(image);
308 }
309 }
310
AlbumArtLoaded(const Song & metadata,const QString & uri,const QImage & image)311 void NowPlayingWidget::AlbumArtLoaded(const Song& metadata, const QString& uri,
312 const QImage& image) {
313 metadata_ = metadata;
314 downloading_covers_ = false;
315
316 if (aww_) {
317 pending_kitten_ =
318 kittens_->LoadKitten(app_->current_art_loader()->options());
319 return;
320 }
321
322 SetImage(image);
323
324 // Search for cover automatically?
325 GetCoverAutomatically();
326 }
327
SetImage(const QImage & image)328 void NowPlayingWidget::SetImage(const QImage& image) {
329 if (visible_) {
330 // Cache the current pixmap so we can fade between them
331 previous_track_ = QPixmap(size());
332 previous_track_.fill(palette().background().color());
333 previous_track_opacity_ = 1.0;
334 QPainter p(&previous_track_);
335 DrawContents(&p);
336 p.end();
337 }
338
339 original_ = image;
340
341 UpdateDetailsText();
342 ScaleCover();
343 SetVisible(true);
344
345 // Were we waiting for this cover to load before we started fading?
346 if (!previous_track_.isNull()) {
347 fade_animation_->start();
348 }
349 }
350
SetHeight(int height)351 void NowPlayingWidget::SetHeight(int height) { setMaximumHeight(height); }
352
SetVisible(bool visible)353 void NowPlayingWidget::SetVisible(bool visible) {
354 if (visible == visible_) return;
355 visible_ = visible;
356
357 show_hide_animation_->setDirection(visible ? QTimeLine::Forward
358 : QTimeLine::Backward);
359 show_hide_animation_->start();
360 }
361
paintEvent(QPaintEvent * e)362 void NowPlayingWidget::paintEvent(QPaintEvent* e) {
363 QPainter p(this);
364
365 DrawContents(&p);
366
367 // Draw the previous track's image if we're fading
368 if (!previous_track_.isNull()) {
369 p.setOpacity(previous_track_opacity_);
370 p.drawPixmap(0, 0, previous_track_);
371 }
372 }
373
DrawContents(QPainter * p)374 void NowPlayingWidget::DrawContents(QPainter* p) {
375 switch (mode_) {
376 case SmallSongDetails:
377 if (hypnotoad_) {
378 p->drawPixmap(0, 0, small_ideal_height_, small_ideal_height_,
379 hypnotoad_->currentPixmap());
380 } else {
381 // Draw the cover
382 p->drawPixmap(0, 0, small_ideal_height_, small_ideal_height_, cover_);
383 if (downloading_covers_) {
384 p->drawPixmap(small_ideal_height_ - 18, 6, 16, 16,
385 spinner_animation_->currentPixmap());
386 }
387 }
388
389 // Draw the details
390 p->translate(small_ideal_height_ + kPadding, 0);
391 details_->drawContents(p);
392 p->translate(-small_ideal_height_ - kPadding, 0);
393 break;
394
395 case LargeSongDetails: {
396 const int total_size =
397 fit_width_ ? width() : qMin(kMaxCoverSize, width());
398 const int x_offset =
399 (width() - cover_loader_options_.desired_height_) / 2;
400
401 // Draw the black background
402 p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
403 Qt::black);
404
405 // Draw the cover
406 if (hypnotoad_) {
407 p->drawPixmap(x_offset, kTopBorder, total_size, total_size,
408 hypnotoad_->currentPixmap());
409 } else {
410 p->drawPixmap(x_offset, kTopBorder, total_size, total_size, cover_);
411 if (downloading_covers_) {
412 p->drawPixmap(x_offset + 45, 35, 16, 16,
413 spinner_animation_->currentPixmap());
414 }
415 }
416
417 // Work out how high the text is going to be
418 const int text_height = details_->size().height();
419 const int gradient_mid = height() - qMax(text_height, kBottomOffset);
420
421 // Draw the black fade
422 QLinearGradient gradient(0, gradient_mid - kGradientHead, 0,
423 gradient_mid + kGradientTail);
424 gradient.setColorAt(0, QColor(0, 0, 0, 0));
425 gradient.setColorAt(1, QColor(0, 0, 0, 255));
426
427 p->fillRect(0, gradient_mid - kGradientHead, width(),
428 height() - (gradient_mid - kGradientHead), gradient);
429
430 // Draw the text on top
431 p->translate(x_offset, height() - text_height);
432 details_->drawContents(p);
433 p->translate(-x_offset, -height() + text_height);
434 break;
435 }
436
437 case LargeNoSongDetails: {
438 const int total_size =
439 fit_width_ ? width() : qMin(kMaxCoverSize, width());
440 const int x_offset =
441 (width() - cover_loader_options_.desired_height_) / 2;
442
443 // Draw the black background
444 p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
445 Qt::black);
446
447 // Draw the cover
448 if (hypnotoad_) {
449 p->drawPixmap(x_offset, kTopBorder, total_size, total_size,
450 hypnotoad_->currentPixmap());
451 } else {
452 p->drawPixmap(x_offset, kTopBorder, total_size, total_size, cover_);
453 if (downloading_covers_) {
454 p->drawPixmap(x_offset + 45, 35, 16, 16,
455 spinner_animation_->currentPixmap());
456 }
457 }
458 break;
459 }
460
461 case LargeSongDetailsBelow:
462 // Work out how high the text is going to be
463 const int text_height = details_->size().height();
464
465 const int cover_size =
466 fit_width_ ? width() : qMin(kMaxCoverSize, width());
467 const int x_offset =
468 (width() - cover_loader_options_.desired_height_) / 2;
469
470 if (!fit_width_) {
471 // Draw the black background
472 p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
473 Qt::black);
474 }
475
476 // Draw the cover
477 if (hypnotoad_) {
478 p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size,
479 hypnotoad_->currentPixmap());
480 } else {
481 p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size, cover_);
482 if (downloading_covers_) {
483 p->drawPixmap(x_offset + 45, 35, 16, 16,
484 spinner_animation_->currentPixmap());
485 }
486 }
487
488 // Draw the text below
489 p->translate(x_offset, height() - text_height);
490 details_->drawContents(p);
491 p->translate(-x_offset, -height() + text_height);
492 break;
493 }
494 }
495
FadePreviousTrack(qreal value)496 void NowPlayingWidget::FadePreviousTrack(qreal value) {
497 previous_track_opacity_ = value;
498 if (qFuzzyCompare(previous_track_opacity_, qreal(0.0))) {
499 previous_track_ = QPixmap();
500 }
501
502 update();
503 }
504
SetMode(int mode)505 void NowPlayingWidget::SetMode(int mode) {
506 mode_ = Mode(mode);
507
508 if (mode_ == SmallSongDetails) {
509 fit_cover_width_action_->setEnabled(false);
510 } else {
511 fit_cover_width_action_->setEnabled(true);
512 }
513
514 UpdateHeight();
515 UpdateDetailsText();
516 update();
517
518 QSettings s;
519 s.beginGroup(kSettingsGroup);
520 s.setValue("mode", mode_);
521 }
522
resizeEvent(QResizeEvent * e)523 void NowPlayingWidget::resizeEvent(QResizeEvent* e) {
524 if (visible_ && e->oldSize() != e->size()) {
525 if (mode_ == LargeSongDetails || mode_ == LargeNoSongDetails ||
526 mode_ == LargeSongDetailsBelow) {
527 UpdateHeight();
528 UpdateDetailsText();
529 }
530 }
531 }
532
contextMenuEvent(QContextMenuEvent * e)533 void NowPlayingWidget::contextMenuEvent(QContextMenuEvent* e) {
534 // initial 'enabled' values depending on the kitty mode
535 album_cover_choice_controller_->cover_from_file_action()->setEnabled(!aww_);
536 album_cover_choice_controller_->cover_from_url_action()->setEnabled(!aww_);
537 album_cover_choice_controller_->search_for_cover_action()->setEnabled(
538 !aww_ && app_->cover_providers()->HasAnyProviders());
539 album_cover_choice_controller_->unset_cover_action()->setEnabled(!aww_);
540 album_cover_choice_controller_->show_cover_action()->setEnabled(!aww_);
541
542 // some special cases
543 if (!aww_) {
544 const bool art_is_not_set = metadata_.has_manually_unset_cover() ||
545 (metadata_.art_automatic().isEmpty() &&
546 metadata_.art_manual().isEmpty());
547
548 album_cover_choice_controller_->unset_cover_action()->setEnabled(
549 !art_is_not_set);
550 album_cover_choice_controller_->show_cover_action()->setEnabled(
551 !art_is_not_set);
552 }
553
554 bask_in_his_glory_action_->setVisible(static_cast<bool>(hypnotoad_));
555
556 // show the menu
557 menu_->popup(mapToGlobal(e->pos()));
558 }
559
mouseReleaseEvent(QMouseEvent * e)560 void NowPlayingWidget::mouseReleaseEvent(QMouseEvent* e) {
561 // Same behaviour as right-click > Show Fullsize
562 if (e->button() == Qt::LeftButton && !aww_ && !hypnotoad_.get()) {
563 ShowCover();
564 }
565 }
566
ShowAboveStatusBar(bool above)567 void NowPlayingWidget::ShowAboveStatusBar(bool above) {
568 QSettings s;
569 s.beginGroup(kSettingsGroup);
570 s.setValue("above_status_bar", above);
571
572 emit ShowAboveStatusBarChanged(above);
573 }
574
show_above_status_bar() const575 bool NowPlayingWidget::show_above_status_bar() const {
576 return above_statusbar_action_->isChecked();
577 }
578
FitCoverWidth(bool fit)579 void NowPlayingWidget::FitCoverWidth(bool fit) {
580 fit_width_ = fit;
581 UpdateHeight();
582 update();
583
584 QSettings s;
585 s.beginGroup(kSettingsGroup);
586 s.setValue("fit_cover_width", fit_width_);
587 }
588
AllHail(bool hypnotoad)589 void NowPlayingWidget::AllHail(bool hypnotoad) {
590 if (hypnotoad) {
591 hypnotoad_.reset(new QMovie(kHypnotoadPath, QByteArray(), this));
592 connect(hypnotoad_.get(), SIGNAL(updated(const QRect&)), SLOT(update()));
593 hypnotoad_->start();
594 update();
595 } else {
596 hypnotoad_.reset();
597 update();
598 }
599 }
600
EnableKittens(bool aww)601 void NowPlayingWidget::EnableKittens(bool aww) {
602 if (!kittens_ && aww) {
603 kittens_ = new KittenLoader(this);
604 app_->MoveToNewThread(kittens_);
605 connect(kittens_, SIGNAL(ImageLoaded(quint64, QImage)),
606 SLOT(KittenLoaded(quint64, QImage)));
607 connect(kittens_, SIGNAL(ImageLoaded(quint64, QImage)),
608 app_->network_remote(), SLOT(SendKitten(quint64, QImage)));
609 }
610
611 aww_ = aww;
612 }
613
LoadCoverFromFile()614 void NowPlayingWidget::LoadCoverFromFile() {
615 album_cover_choice_controller_->LoadCoverFromFile(&metadata_);
616 }
617
LoadCoverFromURL()618 void NowPlayingWidget::LoadCoverFromURL() {
619 album_cover_choice_controller_->LoadCoverFromURL(&metadata_);
620 }
621
SearchForCover()622 void NowPlayingWidget::SearchForCover() {
623 album_cover_choice_controller_->SearchForCover(&metadata_);
624 }
625
SaveCoverToFile()626 void NowPlayingWidget::SaveCoverToFile() {
627 album_cover_choice_controller_->SaveCoverToFile(metadata_, original_);
628 }
629
UnsetCover()630 void NowPlayingWidget::UnsetCover() {
631 album_cover_choice_controller_->UnsetCover(&metadata_);
632 }
633
ShowCover()634 void NowPlayingWidget::ShowCover() {
635 album_cover_choice_controller_->ToggleCover(metadata_);
636 }
637
SearchCoverAutomatically()638 void NowPlayingWidget::SearchCoverAutomatically() {
639 QSettings s;
640 s.beginGroup(kSettingsGroup);
641 s.setValue(
642 "search_for_cover_auto",
643 album_cover_choice_controller_->search_cover_auto_action()->isChecked());
644
645 // Search for cover automatically?
646 GetCoverAutomatically();
647 }
648
Bask()649 void NowPlayingWidget::Bask() {
650 QDesktopWidget desktop;
651 int current_screen = desktop.screenNumber(this);
652 big_hypnotoad_.reset(new FullscreenHypnotoad);
653 big_hypnotoad_->setGeometry(desktop.screenGeometry(current_screen));
654 big_hypnotoad_->showFullScreen();
655 }
656
dragEnterEvent(QDragEnterEvent * e)657 void NowPlayingWidget::dragEnterEvent(QDragEnterEvent* e) {
658 if (AlbumCoverChoiceController::CanAcceptDrag(e)) {
659 e->acceptProposedAction();
660 }
661
662 QWidget::dragEnterEvent(e);
663 }
664
dropEvent(QDropEvent * e)665 void NowPlayingWidget::dropEvent(QDropEvent* e) {
666 album_cover_choice_controller_->SaveCover(&metadata_, e);
667
668 QWidget::dropEvent(e);
669 }
670
GetCoverAutomatically()671 bool NowPlayingWidget::GetCoverAutomatically() {
672 // Search for cover automatically?
673 bool search =
674 album_cover_choice_controller_->search_cover_auto_action()->isChecked() &&
675 !metadata_.has_manually_unset_cover() &&
676 metadata_.art_automatic().isEmpty() && metadata_.art_manual().isEmpty() &&
677 !metadata_.effective_albumartist().isEmpty() &&
678 !metadata_.effective_album().isEmpty();
679
680 if (search) {
681 qLog(Debug) << "GetCoverAutomatically";
682 downloading_covers_ = true;
683 album_cover_choice_controller_->SearchCoverAutomatically(metadata_);
684
685 // Show a spinner animation
686 spinner_animation_.reset(new QMovie(":/spinner.gif", QByteArray(), this));
687 connect(spinner_animation_.get(), SIGNAL(updated(const QRect&)),
688 SLOT(update()));
689 spinner_animation_->start();
690 update();
691 }
692
693 return search;
694 }
695
AutomaticCoverSearchDone()696 void NowPlayingWidget::AutomaticCoverSearchDone() {
697 downloading_covers_ = false;
698 spinner_animation_.reset();
699 update();
700 }
701