Make Cover Manager aware of 'album artist' field

This commit is contained in:
santigl 2017-03-03 20:16:27 -03:00 committed by John Maguire
parent 62cec8cf28
commit 58b7c62f25
3 changed files with 75 additions and 30 deletions

View File

@ -272,7 +272,7 @@ void AlbumCoverChoiceController::SaveCover(Song* song, const QString& cover) {
if (song->is_valid() && song->id() != -1) { if (song->is_valid() && song->id() != -1) {
song->set_art_manual(cover); song->set_art_manual(cover);
app_->library_backend()->UpdateManualAlbumArtAsync( app_->library_backend()->UpdateManualAlbumArtAsync(
song->effective_albumartist(), song->album(), cover); song->artist(), song->albumartist(), song->album(), cover);
if (song->url() == app_->current_art_loader()->last_song().url()) { if (song->url() == app_->current_art_loader()->last_song().url()) {
app_->current_art_loader()->LoadArt(*song); app_->current_art_loader()->LoadArt(*song);

View File

@ -68,7 +68,8 @@ AlbumCoverManager::AlbumCoverManager(Application* app,
cover_export_(nullptr), cover_export_(nullptr),
cover_exporter_(new AlbumCoverExporter(this)), cover_exporter_(new AlbumCoverExporter(this)),
artist_icon_(IconLoader::Load("x-clementine-artist", IconLoader::Base)), artist_icon_(IconLoader::Load("x-clementine-artist", IconLoader::Base)),
all_artists_icon_(IconLoader::Load("x-clementine-album", IconLoader::Base)), all_artists_icon_(
IconLoader::Load("x-clementine-album", IconLoader::Base)),
context_menu_(new QMenu(this)), context_menu_(new QMenu(this)),
progress_bar_(new QProgressBar(this)), progress_bar_(new QProgressBar(this)),
abort_progress_(new QPushButton(this)), abort_progress_(new QPushButton(this)),
@ -79,19 +80,21 @@ AlbumCoverManager::AlbumCoverManager(Application* app,
// Icons // Icons
ui_->action_fetch->setIcon(IconLoader::Load("download", IconLoader::Base)); ui_->action_fetch->setIcon(IconLoader::Load("download", IconLoader::Base));
ui_->export_covers->setIcon(IconLoader::Load("document-save", IconLoader::Base)); ui_->export_covers->setIcon(
IconLoader::Load("document-save", IconLoader::Base));
ui_->view->setIcon(IconLoader::Load("view-choose", IconLoader::Base)); ui_->view->setIcon(IconLoader::Load("view-choose", IconLoader::Base));
ui_->fetch->setIcon(IconLoader::Load("download", IconLoader::Base)); ui_->fetch->setIcon(IconLoader::Load("download", IconLoader::Base));
ui_->action_add_to_playlist->setIcon( ui_->action_add_to_playlist->setIcon(
IconLoader::Load("media-playback-start", IconLoader::Base)); IconLoader::Load("media-playback-start", IconLoader::Base));
ui_->action_load->setIcon(IconLoader::Load("media-playback-start", IconLoader::Base)); ui_->action_load->setIcon(
IconLoader::Load("media-playback-start", IconLoader::Base));
album_cover_choice_controller_->SetApplication(app_); album_cover_choice_controller_->SetApplication(app_);
// Get a square version of nocover.png // Get a square version of nocover.png
no_cover_icon_ = IconLoader::Load("nocover", IconLoader::Other); no_cover_icon_ = IconLoader::Load("nocover", IconLoader::Other);
no_cover_image_ = no_cover_icon_.pixmap(no_cover_icon_.availableSizes() no_cover_image_ =
.last()).toImage(); no_cover_icon_.pixmap(no_cover_icon_.availableSizes().last()).toImage();
QImage nocover(no_cover_image_); QImage nocover(no_cover_image_);
nocover = nocover =
nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
@ -312,6 +315,7 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem* current) {
break; break;
case Specific_Artist: case Specific_Artist:
albums = library_backend_->GetAlbumsByArtist(current->text()); albums = library_backend_->GetAlbumsByArtist(current->text());
albums += library_backend_->GetAlbumsByAlbumArtist(current->text());
break; break;
case All_Artists: case All_Artists:
default: default:
@ -330,14 +334,22 @@ void AlbumCoverManager::ArtistChanged(QListWidgetItem* current) {
QIcon no_cover(no_cover_icon_.pixmap(120, 120)); QIcon no_cover(no_cover_icon_.pixmap(120, 120));
QListWidgetItem* item = QListWidgetItem* item =
new QListWidgetItem(no_cover, info.album_name, ui_->albums); new QListWidgetItem(no_cover, info.album_name, ui_->albums);
item->setData(Role_ArtistName, info.artist); item->setData(Role_ArtistName, info.artist);
item->setData(Role_AlbumArtistName, info.album_artist);
item->setData(Role_AlbumName, info.album_name); item->setData(Role_AlbumName, info.album_name);
item->setData(Role_FirstUrl, info.first_url); item->setData(Role_FirstUrl, info.first_url);
item->setData(Qt::TextAlignmentRole, item->setData(Qt::TextAlignmentRole,
QVariant(Qt::AlignTop | Qt::AlignHCenter)); QVariant(Qt::AlignTop | Qt::AlignHCenter));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled |
Qt::ItemIsDragEnabled); Qt::ItemIsDragEnabled);
item->setToolTip(info.artist + " - " + info.album_name);
QString effective_artist = EffectiveAlbumArtistName(item);
if (!artist.isEmpty()) {
item->setToolTip(effective_artist + " - " + info.album_name);
} else {
item->setToolTip(info.album_name);
}
if (!info.art_automatic.isEmpty() || !info.art_manual.isEmpty()) { if (!info.art_automatic.isEmpty() || !info.art_manual.isEmpty()) {
quint64 id = app_->album_cover_loader()->LoadImageAsync( quint64 id = app_->album_cover_loader()->LoadImageAsync(
@ -412,8 +424,10 @@ bool AlbumCoverManager::ShouldHide(const QListWidgetItem& item,
QStringList query = filter.split(' '); QStringList query = filter.split(' ');
for (const QString& s : query) { for (const QString& s : query) {
if (!item.text().contains(s, Qt::CaseInsensitive) && if (!item.text().contains(s, Qt::CaseInsensitive) &&
!item.data(Role_ArtistName).toString().contains(s, !item.data(Role_ArtistName).toString().contains(
Qt::CaseInsensitive)) { s, Qt::CaseInsensitive),
!item.data(Role_AlbumArtistName).toString().contains(
s, Qt::CaseInsensitive)) {
return true; return true;
} }
} }
@ -427,9 +441,8 @@ void AlbumCoverManager::FetchAlbumCovers() {
if (item->isHidden()) continue; if (item->isHidden()) continue;
if (item->icon().cacheKey() != no_cover_icon_.cacheKey()) continue; if (item->icon().cacheKey() != no_cover_icon_.cacheKey()) continue;
quint64 id = quint64 id = cover_fetcher_->FetchAlbumCover(
cover_fetcher_->FetchAlbumCover(item->data(Role_ArtistName).toString(), EffectiveAlbumArtistName(item), item->data(Role_AlbumName).toString());
item->data(Role_AlbumName).toString());
cover_fetching_tasks_[id] = item; cover_fetching_tasks_[id] = item;
jobs_++; jobs_++;
} }
@ -467,8 +480,9 @@ void AlbumCoverManager::UpdateStatusText() {
.arg(fetch_statistics_.missing_images_); .arg(fetch_statistics_.missing_images_);
if (fetch_statistics_.bytes_transferred_) { if (fetch_statistics_.bytes_transferred_) {
message += ", " + tr("%1 transferred").arg(Utilities::PrettySize( message += ", " +
fetch_statistics_.bytes_transferred_)); tr("%1 transferred").arg(
Utilities::PrettySize(fetch_statistics_.bytes_transferred_));
} }
statusBar()->showMessage(message); statusBar()->showMessage(message);
@ -532,12 +546,15 @@ Song AlbumCoverManager::ItemAsSong(QListWidgetItem* item) {
Song result; Song result;
QString title = item->data(Role_AlbumName).toString(); QString title = item->data(Role_AlbumName).toString();
if (!item->data(Role_ArtistName).toString().isNull()) QString artist_name = EffectiveAlbumArtistName(item);
result.set_title(item->data(Role_ArtistName).toString() + " - " + title); if (!artist_name.isEmpty()) {
else result.set_title(artist_name + " - " + title);
} else {
result.set_title(title); result.set_title(title);
}
result.set_artist(item->data(Role_ArtistName).toString()); result.set_artist(item->data(Role_ArtistName).toString());
result.set_albumartist(item->data(Role_AlbumArtistName).toString());
result.set_album(item->data(Role_AlbumName).toString()); result.set_album(item->data(Role_AlbumName).toString());
result.set_url(item->data(Role_FirstUrl).toUrl()); result.set_url(item->data(Role_FirstUrl).toUrl());
@ -561,9 +578,9 @@ void AlbumCoverManager::ShowCover() {
void AlbumCoverManager::FetchSingleCover() { void AlbumCoverManager::FetchSingleCover() {
for (QListWidgetItem* item : context_menu_items_) { for (QListWidgetItem* item : context_menu_items_) {
quint64 id = QString artist_name = EffectiveAlbumArtistName(item);
cover_fetcher_->FetchAlbumCover(item->data(Role_ArtistName).toString(), quint64 id = cover_fetcher_->FetchAlbumCover(
item->data(Role_AlbumName).toString()); artist_name, item->data(Role_AlbumName).toString());
cover_fetching_tasks_[id] = item; cover_fetching_tasks_[id] = item;
jobs_++; jobs_++;
} }
@ -682,8 +699,15 @@ SongList AlbumCoverManager::GetSongsInAlbum(const QModelIndex& index) const {
q.SetOrderBy("disc, track, title"); q.SetOrderBy("disc, track, title");
QString artist = index.data(Role_ArtistName).toString(); QString artist = index.data(Role_ArtistName).toString();
q.AddCompilationRequirement(artist.isEmpty()); QString albumartist = index.data(Role_AlbumArtistName).toString();
if (!artist.isEmpty()) q.AddWhere("artist", artist);
if (!albumartist.isEmpty()) {
q.AddWhere("albumartist", albumartist);
} else if (!artist.isEmpty()) {
q.AddWhere("artist", artist);
}
q.AddCompilationRequirement(artist.isEmpty() && albumartist.isEmpty());
if (!library_backend_->ExecQuery(&q)) return ret; if (!library_backend_->ExecQuery(&q)) return ret;
@ -695,8 +719,8 @@ SongList AlbumCoverManager::GetSongsInAlbum(const QModelIndex& index) const {
return ret; return ret;
} }
SongList AlbumCoverManager::GetSongsInAlbums(const QModelIndexList& indexes) SongList AlbumCoverManager::GetSongsInAlbums(
const { const QModelIndexList& indexes) const {
SongList ret; SongList ret;
for (const QModelIndex& index : indexes) { for (const QModelIndex& index : indexes) {
ret << GetSongsInAlbum(index); ret << GetSongsInAlbum(index);
@ -740,13 +764,14 @@ void AlbumCoverManager::LoadSelectedToPlaylist() {
void AlbumCoverManager::SaveAndSetCover(QListWidgetItem* item, void AlbumCoverManager::SaveAndSetCover(QListWidgetItem* item,
const QImage& image) { const QImage& image) {
const QString artist = item->data(Role_ArtistName).toString(); const QString artist = item->data(Role_ArtistName).toString();
const QString albumartist = item->data(Role_ArtistName).toString();
const QString album = item->data(Role_AlbumName).toString(); const QString album = item->data(Role_AlbumName).toString();
QString path = QString path = album_cover_choice_controller_->SaveCoverInCache(
album_cover_choice_controller_->SaveCoverInCache(artist, album, image); EffectiveAlbumArtistName(item), album, image);
// Save the image in the database // Save the image in the database
library_backend_->UpdateManualAlbumArtAsync(artist, album, path); library_backend_->UpdateManualAlbumArtAsync(artist, albumartist, album, path);
// Update the icon in our list // Update the icon in our list
quint64 id = app_->album_cover_loader()->LoadImageAsync(cover_loader_options_, quint64 id = app_->album_cover_loader()->LoadImageAsync(cover_loader_options_,
@ -815,3 +840,11 @@ void AlbumCoverManager::UpdateExportStatus(int exported, int skipped, int max) {
msg.exec(); msg.exec();
} }
} }
QString AlbumCoverManager::EffectiveAlbumArtistName(
QListWidgetItem* item) const {
if (!item->data(Role_AlbumArtistName).toString().isEmpty()) {
return item->data(Role_AlbumArtistName).toString();
}
return item->data(Role_ArtistName).toString();
}

View File

@ -48,7 +48,8 @@ class AlbumCoverManager : public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
AlbumCoverManager(Application* app, LibraryBackend* library_backend, AlbumCoverManager(Application* app, LibraryBackend* library_backend,
QWidget* parent = nullptr, QNetworkAccessManager* network = 0); QWidget* parent = nullptr,
QNetworkAccessManager* network = 0);
~AlbumCoverManager(); ~AlbumCoverManager();
static const char* kSettingsGroup; static const char* kSettingsGroup;
@ -105,21 +106,32 @@ signals:
void UpdateExportStatus(int exported, int bad, int count); void UpdateExportStatus(int exported, int bad, int count);
private: private:
enum ArtistItemType { All_Artists, Various_Artists, Specific_Artist, }; enum ArtistItemType {
All_Artists,
Various_Artists,
Specific_Artist,
};
enum Role { enum Role {
Role_ArtistName = Qt::UserRole + 1, Role_ArtistName = Qt::UserRole + 1,
Role_AlbumArtistName,
Role_AlbumName, Role_AlbumName,
Role_PathAutomatic, Role_PathAutomatic,
Role_PathManual, Role_PathManual,
Role_FirstUrl, Role_FirstUrl,
}; };
enum HideCovers { Hide_None, Hide_WithCovers, Hide_WithoutCovers, }; enum HideCovers {
Hide_None,
Hide_WithCovers,
Hide_WithoutCovers,
};
QString InitialPathForOpenCoverDialog(const QString& path_automatic, QString InitialPathForOpenCoverDialog(const QString& path_automatic,
const QString& first_file_name) const; const QString& first_file_name) const;
QString EffectiveAlbumArtistName(QListWidgetItem* item) const;
// Returns the selected element in form of a Song ready to be used // Returns the selected element in form of a Song ready to be used
// by AlbumCoverChoiceController or invalid song if there's nothing // by AlbumCoverChoiceController or invalid song if there's nothing
// or multiple elements selected. // or multiple elements selected.