diff --git a/models/onlineservicesmodel.cpp b/models/onlineservicesmodel.cpp index 39be5e02f..5ef59bafb 100644 --- a/models/onlineservicesmodel.cpp +++ b/models/onlineservicesmodel.cpp @@ -607,7 +607,7 @@ void OnlineServicesModel::imageDownloaded() img.save(fileName); if (!song.album.isEmpty()) { song.track=1; - song.setKey(); + //song.setKey(); Covers::self()->emitCoverUpdated(song, img, fileName); } return; @@ -618,7 +618,7 @@ void OnlineServicesModel::imageDownloaded() f.write(data); if (!song.album.isEmpty()) { song.track=1; - song.setKey(); + //song.setKey(); Covers::self()->emitCoverUpdated(song, img, fileName); } } diff --git a/models/playqueuemodel.cpp b/models/playqueuemodel.cpp index 39993e7f1..5b6d9fcb2 100644 --- a/models/playqueuemodel.cpp +++ b/models/playqueuemodel.cpp @@ -742,6 +742,10 @@ void PlayQueueModel::setState(MPDState st) // Update playqueue with contents returned from MPD. void PlayQueueModel::update(const QList &songList) { + if (songList.isEmpty()) { + Song::clearKeyStore(MPDParseUtils::PlayQueue); + } + removeDuplicatesAction->setEnabled(songList.count()>1); QList prev; if (undoEnabled) { @@ -1136,7 +1140,7 @@ void PlayQueueModel::updateDetails(const QList &updated) if (songMap.contains(current.file)) { Song updatedSong=songMap[current.file]; updatedSong.id=current.id; - updatedSong.setKey(); + updatedSong.setKey(MPDParseUtils::PlayQueue); if (updatedSong.name!=current.name || updatedSong.title!=current.title || updatedSong.artist!=current.artist) { songs.replace(i, updatedSong); diff --git a/mpd/mpdconnection.cpp b/mpd/mpdconnection.cpp index 6c70c8861..841d4f1f8 100644 --- a/mpd/mpdconnection.cpp +++ b/mpd/mpdconnection.cpp @@ -529,7 +529,7 @@ MPDConnection::Response MPDConnection::sendCommand(const QByteArray &command, bo bool emitError=true; // Mopidy returns "incorrect arguments" for commands it does not support. The docs state that crossfade and replaygain mode // setting commands are not supported. So, if we get this error then just ignore it. - if (mopidy && (command.startsWith("crossfade ") || command.startsWith("replay_gain_mode ")) && + if ((command.startsWith("crossfade ") || command.startsWith("replay_gain_mode ")) && "incorrect arguments"==response.getError(command)) { emitError=false; } diff --git a/mpd/mpdparseutils.cpp b/mpd/mpdparseutils.cpp index b9e762e40..77a50bbf3 100644 --- a/mpd/mpdparseutils.cpp +++ b/mpd/mpdparseutils.cpp @@ -320,7 +320,7 @@ Song MPDParseUtils::parseSong(const QByteArray &data, Location location) // HTTP server, and OnlineServices, modify the path. But this then messes up // undo/restore of playqueue. Therefore, set path back to original value... song.file=origFile; - song.setKey(); + song.setKey(location); } return song; } diff --git a/mpd/song.cpp b/mpd/song.cpp index d6db0fd0c..0efbea7c9 100644 --- a/mpd/song.cpp +++ b/mpd/song.cpp @@ -304,24 +304,36 @@ void Song::fillEmptyFields() } } -void Song::setKey() +struct KeyStore { - static quint16 currentKey=0; - static QMap keys; + KeyStore() : currentKey(0) { } + quint16 currentKey; + QMap keys; +}; +static QMap storeMap; + +void Song::clearKeyStore(int location) +{ + storeMap.remove(location); +} + +void Song::setKey(int location) +{ if (isStream() && !isCantataStream()) { key=0; return; } + KeyStore &store=storeMap[location]; QString songKey(albumKey()); - QMap::ConstIterator it=keys.find(songKey); - if (it!=keys.end()) { + QMap::ConstIterator it=store.keys.find(songKey); + if (it!=store.keys.end()) { key=it.value(); } else { - currentKey++; // Key 0 is for streams, so we need to increment before setting... - keys.insert(songKey, currentKey); - key=currentKey; + store.currentKey++; // Key 0 is for streams, so we need to increment before setting... + store.keys.insert(songKey, store.currentKey); + key=store.currentKey; } } diff --git a/mpd/song.h b/mpd/song.h index 0418614d8..41906e488 100644 --- a/mpd/song.h +++ b/mpd/song.h @@ -81,6 +81,7 @@ struct Song static void sortViaType(QList &songs); static QString decodePath(const QString &file); static QString encodePath(const QString &file); + static void clearKeyStore(int location); Song(); Song(const Song &o) { *this=o; } @@ -94,7 +95,7 @@ struct Song void guessTags(); void revertGuessedTags(); void fillEmptyFields(); - void setKey(); + void setKey(int location); virtual void clear(); #ifndef CANTATA_NO_SONG_TIME_FUNCTION static QString formattedTime(quint32 seconds, bool zeroIsUnknown=false);