Download higher resolution images from last.fm. Thanks markwatkinson. Fixes issue #1187

This commit is contained in:
David Sansome 2010-12-26 20:19:12 +00:00
parent d08782b720
commit 97d7fe764a
7 changed files with 31 additions and 18 deletions

View File

@ -117,7 +117,7 @@ void AlbumCoverFetcher::AlbumSearchFinished() {
SearchResult result; SearchResult result;
result.album = element["name"].text(); result.album = element["name"].text();
result.artist = element["artist"].text(); result.artist = element["artist"].text();
result.image_url = element["image size=large"].text(); result.image_url = element["image size=extralarge"].text();
results << result; results << result;
} }

View File

@ -31,6 +31,8 @@
class QNetworkReply; class QNetworkReply;
class QString; class QString;
// This class searches for album covers for a given query or artist/album and
// returns URLs.
class AlbumCoverFetcher : public QObject { class AlbumCoverFetcher : public QObject {
Q_OBJECT Q_OBJECT

View File

@ -180,6 +180,7 @@ void AlbumCoverManager::Init() {
cover_loader_->Start(true); cover_loader_->Start(true);
CoverLoaderInitialised(); CoverLoaderInitialised();
cover_searcher_->Init(cover_fetcher_);
constructed_ = true; constructed_ = true;
} }
@ -187,8 +188,6 @@ void AlbumCoverManager::CoverLoaderInitialised() {
cover_loader_->Worker()->SetDefaultOutputImage(QImage(":nocover.png")); cover_loader_->Worker()->SetDefaultOutputImage(QImage(":nocover.png"));
connect(cover_loader_->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)), connect(cover_loader_->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)),
SLOT(CoverImageLoaded(quint64,QImage))); SLOT(CoverImageLoaded(quint64,QImage)));
cover_searcher_->Init(cover_loader_->Worker(), cover_fetcher_);
} }
void AlbumCoverManager::showEvent(QShowEvent *) { void AlbumCoverManager::showEvent(QShowEvent *) {

View File

@ -27,12 +27,20 @@ AlbumCoverSearcher::AlbumCoverSearcher(const QIcon& no_cover_icon, QWidget* pare
: QDialog(parent), : QDialog(parent),
ui_(new Ui_AlbumCoverSearcher), ui_(new Ui_AlbumCoverSearcher),
no_cover_icon_(no_cover_icon), no_cover_icon_(no_cover_icon),
loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this)),
fetcher_(NULL), fetcher_(NULL),
id_(0) id_(0)
{ {
ui_->setupUi(this); ui_->setupUi(this);
ui_->busy->hide(); ui_->busy->hide();
loader_->Start(true);
loader_->Worker()->SetDefaultOutputImage(QImage(":nocover.png"));
loader_->Worker()->SetScaleOutputImage(false);
loader_->Worker()->SetPadOutputImage(false);
connect(loader_->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)),
SLOT(ImageLoaded(quint64,QImage)));
connect(ui_->search, SIGNAL(clicked()), SLOT(Search())); connect(ui_->search, SIGNAL(clicked()), SLOT(Search()));
connect(ui_->covers, SIGNAL(doubleClicked(QModelIndex)), SLOT(CoverDoubleClicked(QModelIndex))); connect(ui_->covers, SIGNAL(doubleClicked(QModelIndex)), SLOT(CoverDoubleClicked(QModelIndex)));
} }
@ -41,13 +49,10 @@ AlbumCoverSearcher::~AlbumCoverSearcher() {
delete ui_; delete ui_;
} }
void AlbumCoverSearcher::Init(boost::shared_ptr<AlbumCoverLoader> loader, void AlbumCoverSearcher::Init(AlbumCoverFetcher* fetcher) {
AlbumCoverFetcher *fetcher) {
loader_ = loader;
fetcher_ = fetcher; fetcher_ = fetcher;
connect(fetcher_, SIGNAL(SearchFinished(quint64,AlbumCoverFetcher::SearchResults)), SLOT(SearchFinished(quint64,AlbumCoverFetcher::SearchResults))); connect(fetcher_, SIGNAL(SearchFinished(quint64,AlbumCoverFetcher::SearchResults)), SLOT(SearchFinished(quint64,AlbumCoverFetcher::SearchResults)));
connect(loader_.get(), SIGNAL(ImageLoaded(quint64,QImage)), SLOT(ImageLoaded(quint64,QImage)));
} }
QImage AlbumCoverSearcher::Exec(const QString &query) { QImage AlbumCoverSearcher::Exec(const QString &query) {
@ -91,7 +96,7 @@ void AlbumCoverSearcher::SearchFinished(quint64 id, const AlbumCoverFetcher::Sea
if (result.image_url.isEmpty()) if (result.image_url.isEmpty())
continue; continue;
quint64 id = loader_->LoadImageAsync(result.image_url, QString()); quint64 id = loader_->Worker()->LoadImageAsync(result.image_url, QString());
QListWidgetItem* item = new QListWidgetItem(ui_->covers); QListWidgetItem* item = new QListWidgetItem(ui_->covers);
item->setIcon(no_cover_icon_); item->setIcon(no_cover_icon_);
@ -107,12 +112,18 @@ void AlbumCoverSearcher::SearchFinished(quint64 id, const AlbumCoverFetcher::Sea
ui_->busy->hide(); ui_->busy->hide();
} }
void AlbumCoverSearcher::ImageLoaded(quint64 id, const QImage &image) { void AlbumCoverSearcher::ImageLoaded(quint64 id, const QImage& image) {
if (!cover_loading_tasks_.contains(id)) if (!cover_loading_tasks_.contains(id))
return; return;
QIcon icon(QPixmap::fromImage(image));
// Add an icon that's the right size for the view
icon.addPixmap(QPixmap::fromImage(image.scaled(ui_->covers->iconSize(),
Qt::KeepAspectRatio, Qt::SmoothTransformation)));
QListWidgetItem* item = cover_loading_tasks_.take(id); QListWidgetItem* item = cover_loading_tasks_.take(id);
item->setIcon(QIcon(QPixmap::fromImage(image))); item->setIcon(icon);
if (cover_loading_tasks_.isEmpty()) if (cover_loading_tasks_.isEmpty())
ui_->busy->hide(); ui_->busy->hide();

View File

@ -19,6 +19,7 @@
#define ALBUMCOVERSEARCHER_H #define ALBUMCOVERSEARCHER_H
#include "core/albumcoverfetcher.h" #include "core/albumcoverfetcher.h"
#include "core/backgroundthread.h"
#include <QDialog> #include <QDialog>
#include <QIcon> #include <QIcon>
@ -31,6 +32,7 @@ class Ui_AlbumCoverSearcher;
class QListWidgetItem; class QListWidgetItem;
class QModelIndex; class QModelIndex;
// This is a dialog that lets the user search for album covers
class AlbumCoverSearcher : public QDialog { class AlbumCoverSearcher : public QDialog {
Q_OBJECT Q_OBJECT
@ -43,8 +45,7 @@ public:
Role_ImageRequestId, Role_ImageRequestId,
}; };
void Init(boost::shared_ptr<AlbumCoverLoader> loader, void Init(AlbumCoverFetcher* fetcher);
AlbumCoverFetcher* fetcher);
QImage Exec(const QString& query); QImage Exec(const QString& query);
@ -62,7 +63,7 @@ private:
Ui_AlbumCoverSearcher* ui_; Ui_AlbumCoverSearcher* ui_;
QIcon no_cover_icon_; QIcon no_cover_icon_;
boost::shared_ptr<AlbumCoverLoader> loader_; BackgroundThread<AlbumCoverLoader>* loader_;
AlbumCoverFetcher* fetcher_; AlbumCoverFetcher* fetcher_;
quint64 id_; quint64 id_;

View File

@ -63,7 +63,7 @@ EditTagDialog::EditTagDialog(QWidget* parent)
SLOT(ArtLoaded(quint64,QImage))); SLOT(ArtLoaded(quint64,QImage)));
#ifdef HAVE_LIBLASTFM #ifdef HAVE_LIBLASTFM
cover_searcher_->Init(cover_loader_->Worker(), cover_fetcher_); cover_searcher_->Init(cover_fetcher_);
#endif #endif
ui_->setupUi(this); ui_->setupUi(this);

View File

@ -125,6 +125,10 @@ NowPlayingWidget::NowPlayingWidget(QWidget *parent)
// Start loading the cover loader thread // Start loading the cover loader thread
cover_loader_->Start(); cover_loader_->Start();
connect(cover_loader_, SIGNAL(Initialised()), SLOT(CoverLoaderInitialised())); connect(cover_loader_, SIGNAL(Initialised()), SLOT(CoverLoaderInitialised()));
#ifdef HAVE_LIBLASTFM
cover_searcher_->Init(cover_fetcher_);
#endif
} }
void NowPlayingWidget::CreateModeAction(Mode mode, const QString &text, QActionGroup *group, QSignalMapper* mapper) { void NowPlayingWidget::CreateModeAction(Mode mode, const QString &text, QActionGroup *group, QSignalMapper* mapper) {
@ -155,10 +159,6 @@ void NowPlayingWidget::CoverLoaderInitialised() {
loader->Worker()->SetPadOutputImage(true); loader->Worker()->SetPadOutputImage(true);
connect(loader->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)), connect(loader->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)),
SLOT(AlbumArtLoaded(quint64,QImage))); SLOT(AlbumArtLoaded(quint64,QImage)));
#ifdef HAVE_LIBLASTFM
cover_searcher_->Init(cover_loader_->Worker(), cover_fetcher_);
#endif
} }
void NowPlayingWidget::UpdateHeight(AlbumCoverLoader* loader) { void NowPlayingWidget::UpdateHeight(AlbumCoverLoader* loader) {