From b365131363993b7153b2605f8fb58b81f30aa190 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 28 Feb 2024 23:00:24 +0100 Subject: [PATCH] Playlist: Remove veto listeners We have never used this, it's basically dead code. --- src/playlist/playlist.cpp | 52 --------------------------------------- src/playlist/playlist.h | 20 --------------- 2 files changed, 72 deletions(-) diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index 54837bd2..eeb286ab 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -1026,44 +1026,6 @@ void Playlist::InsertItems(const PlaylistItemPtrList &itemsIn, const int pos, co PlaylistItemPtrList items = itemsIn; - // Exercise vetoes - SongList songs; - songs.reserve(items.count()); - for (PlaylistItemPtr item : items) { // clazy:exclude=range-loop-reference - songs << item->Metadata(); - } - - const qint64 song_count = songs.length(); - QSet vetoed; - for (SongInsertVetoListener *listener : veto_listeners_) { - for (const Song &song : listener->AboutToInsertSongs(GetAllSongs(), songs)) { - // Avoid veto-ing a song multiple times - vetoed.insert(song); - } - if (vetoed.count() == song_count) { - // All songs were vetoed and there's nothing more to do (there's no need for an undo step) - return; - } - } - - if (!vetoed.isEmpty()) { - QMutableListIterator it(items); - while (it.hasNext()) { - PlaylistItemPtr item = it.next(); - const Song ¤t = item->Metadata(); - - if (vetoed.contains(current)) { - vetoed.remove(current); - it.remove(); - } - } - - // Check for empty items once again after veto - if (items.isEmpty()) { - return; - } - } - const int start = pos == -1 ? static_cast(items_.count()) : pos; if (items.count() > kUndoItemLimit) { @@ -1905,20 +1867,6 @@ void Playlist::ReloadItemsBlocking(const QList &rows) { } -void Playlist::AddSongInsertVetoListener(SongInsertVetoListener *listener) { - veto_listeners_.append(listener); - QObject::connect(listener, &SongInsertVetoListener::destroyed, this, &Playlist::SongInsertVetoListenerDestroyed); -} - -void Playlist::RemoveSongInsertVetoListener(SongInsertVetoListener *listener) { - QObject::disconnect(listener, &SongInsertVetoListener::destroyed, this, &Playlist::SongInsertVetoListenerDestroyed); - veto_listeners_.removeAll(listener); -} - -void Playlist::SongInsertVetoListenerDestroyed() { - veto_listeners_.removeAll(qobject_cast(sender())); -} - void Playlist::Shuffle() { PlaylistItemPtrList new_items(items_); diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index 478477e6..cd48deee 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -74,18 +74,6 @@ using ColumnAlignmentMap = QMap; Q_DECLARE_METATYPE(Qt::Alignment) Q_DECLARE_METATYPE(ColumnAlignmentMap) -// Objects that may prevent a song being added to the playlist. -// When there is something about to be inserted into it, -// Playlist notifies all of its listeners about the fact and every one of them picks 'invalid' songs. -class SongInsertVetoListener : public QObject { - Q_OBJECT - - public: - // Listener returns a list of 'invalid' songs. - // 'old_songs' are songs that are currently in the playlist and 'new_songs' are the songs about to be added if nobody exercises a veto. - virtual SongList AboutToInsertSongs(const SongList &old_songs, const SongList &new_songs) = 0; -}; - class Playlist : public QAbstractListModel { Q_OBJECT @@ -258,11 +246,6 @@ class Playlist : public QAbstractListModel { void ReloadItemsBlocking(const QList &rows); void InformOfCurrentSongChange(const AutoScroll autoscroll, const bool minor); - // Registers an object which will get notifications when new songs are about to be inserted into this playlist. - void AddSongInsertVetoListener(SongInsertVetoListener *listener); - // Unregisters a SongInsertVetoListener object. - void RemoveSongInsertVetoListener(SongInsertVetoListener *listener); - // Just emits the dataChanged() signal so the mood column is repainted. #ifdef HAVE_MOODBAR void MoodbarUpdated(const QModelIndex &idx); @@ -376,7 +359,6 @@ class Playlist : public QAbstractListModel { void SongSaveComplete(TagReaderReply *reply, const QPersistentModelIndex &idx, const Song &old_metadata); void ItemReloadComplete(const QPersistentModelIndex &idx, const Song &old_metadata, const bool metadata_edit); void ItemsLoaded(); - void SongInsertVetoListenerDestroyed(); void ScheduleSave(); void Save(); @@ -420,8 +402,6 @@ class Playlist : public QAbstractListModel { ColumnAlignmentMap column_alignments_; - QList veto_listeners_; - QString special_type_; // Cancel async restore if songs are already replaced