Merge git://github.com/szemek/clementine

This commit is contained in:
Arnaud Bienner 2012-11-22 00:37:51 +01:00
commit cf22a91c6a
3 changed files with 29 additions and 5 deletions

View File

@ -1114,6 +1114,12 @@ bool Song::IsMetadataEqual(const Song& other) const {
d->cue_path_ == other.d->cue_path_; d->cue_path_ == other.d->cue_path_;
} }
bool Song::IsDuplicate(const Song& other) const {
return url() == other.url() ||
(title().toLower() == other.title().toLower() &&
artist().toLower() == other.artist().toLower());
}
bool Song::IsEditable() const { bool Song::IsEditable() const {
return d->valid_ && !d->url_.isEmpty() && !is_stream() && return d->valid_ && !d->url_.isEmpty() && !is_stream() &&
d->filetype_ != Type_Unknown && !has_cue(); d->filetype_ != Type_Unknown && !has_cue();

View File

@ -262,6 +262,7 @@ class Song {
// Comparison functions // Comparison functions
bool IsMetadataEqual(const Song& other) const; bool IsMetadataEqual(const Song& other) const;
bool IsOnSameAlbum(const Song& other) const; bool IsOnSameAlbum(const Song& other) const;
bool IsDuplicate(const Song& other) const;
bool operator==(const Song& other) const; bool operator==(const Song& other) const;

View File

@ -1921,17 +1921,34 @@ void Playlist::RemoveDeletedSongs() {
void Playlist::RemoveDuplicateSongs() { void Playlist::RemoveDuplicateSongs() {
QList<int> rows_to_remove; QList<int> rows_to_remove;
QSet<QUrl> filenames; QHash<Song, int> unique_songs;
for (int row = 0; row < items_.count(); ++row) { for (int row = 0; row < items_.count(); ++row) {
PlaylistItemPtr item = items_[row]; PlaylistItemPtr item = items_[row];
Song song = item->Metadata(); Song song = item->Metadata();
if (filenames.contains(song.url())) { bool found_duplicate = false;
rows_to_remove.append(row); QHashIterator<Song, int> iterator(unique_songs);
} else {
filenames.insert(song.url()); while (iterator.hasNext() && !found_duplicate) {
iterator.next();
Song uniq_song = iterator.key();
if (song.IsDuplicate(uniq_song)) {
if (song.bitrate() > uniq_song.bitrate()) {
rows_to_remove.append(unique_songs[uniq_song]);
unique_songs.remove(uniq_song);
unique_songs.insert(song, row);
}
else {
rows_to_remove.append(row);
}
found_duplicate = true;
}
} }
if (!found_duplicate)
unique_songs.insert(song, row);
} }
removeRows(rows_to_remove); removeRows(rows_to_remove);