From 42fc6c467f23edabc6ebbb097bbffd551f53b5ad Mon Sep 17 00:00:00 2001 From: "craig.p.drummond" Date: Thu, 17 Apr 2014 16:05:05 +0000 Subject: [PATCH] Fix cover loading --- models/playqueuemodel.cpp | 54 +++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 4fd9b9fd8..5684194ee 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -893,9 +893,6 @@ void PlayQueueModel::update(const QList &songList) #endif foreach (const Song &s, songList) { newIds.insert(s.id); - #ifdef ENABLE_UBUNTU - currentKeys.insert(s.key); - #endif } if (songs.isEmpty() || songList.isEmpty()) { @@ -906,6 +903,12 @@ void PlayQueueModel::update(const QList &songList) if (songList.isEmpty()) { stopAfterTrackId=-1; } + + #ifdef ENABLE_UBUNTU + foreach (const Song &s, songs) { + currentKeys.insert(s.key); + } + #endif } else { time = 0; @@ -929,18 +932,30 @@ void PlayQueueModel::update(const QList &songList) if (-1==existingPos) { beginInsertRows(QModelIndex(), i, i); songs.insert(i, s); + #ifdef ENABLE_UBUNTU + currentKeys.insert(s.key); + #endif endInsertRows(); } else { beginMoveRows(QModelIndex(), existingPos, existingPos, QModelIndex(), i>existingPos ? i+1 : i); Song old=songs.takeAt(existingPos); // old.pos=s.pos; songs.insert(i, isEmpty ? old : s); + #ifdef ENABLE_UBUNTU + currentKeys.insert(isEmpty ? old.key : s.key); + #endif endMoveRows(); } } else if (isEmpty) { s=curentSongAtPos; + #ifdef ENABLE_UBUNTU + currentKeys.insert(s.key); + #endif } else { s.key=curentSongAtPos.key; + #ifdef ENABLE_UBUNTU + currentKeys.insert(s.key); + #endif songs.replace(i, s); if (s.name!=curentSongAtPos.name || s.title!=curentSongAtPos.title || s.artist!=curentSongAtPos.artist) { emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex())-1)); @@ -1255,30 +1270,31 @@ void PlayQueueModel::setCover(const Song &song, const QImage &img, const QString if (file.isEmpty() || coverRequests.isEmpty()) { return; } - Song s=song; - if (song.key==Song::constNullKey) { - // This request is not from the playqueue - but the album might be in the playqueue... - // So, see fi we have an outstandnig request for the album an dget its key... - QMap::ConstIterator it=coverRequests.constBegin(); - QMap::ConstIterator end=coverRequests.constEnd(); - for (; it!=end; ++it) { - if (song.albumArtist()==it.value().albumArtist() && song.album==it.value().album) { - s.key=it.key(); - coverRequests.remove(it.key()); - break; - } + + // In case of multi-disc albums we will have multiple 'keys' mapped to a single artist+album combo. + // Therefore, we need to find all keys that have this mapping. + // + // Also, library and albums models might have requested the cover at the same time as playqueue, in which + // case the incomming song would have no key set + QList keys; + QMap::ConstIterator it=coverRequests.constBegin(); + QMap::ConstIterator end=coverRequests.constEnd(); + for (; it!=end; ++it) { + if (song.albumArtist()==it.value().albumArtist() && song.album==it.value().album) { + keys.append(it.key()); } } - if (s.key!=Song::constNullKey) { - QMap::ConstIterator it=covers.find(s.key); + foreach (quint16 key, keys) { + coverRequests.remove(key); + QMap::ConstIterator it=covers.find(key); if (it!=covers.end() && it.value().isEmpty()) { coverRequests.remove(it.key()); - covers[song.key]="file://"+file; + covers[key]="file://"+file; int start=-1; int end=-1; for (int i=0; i