From 43a6740b489b619d3d4ab5109ce03b17b3f5c717 Mon Sep 17 00:00:00 2001 From: ppkt Date: Sun, 24 Aug 2014 10:44:27 +0200 Subject: [PATCH] Remove unavailable items from playlist --- src/playlist/playlist.cpp | 15 +++++++++++++++ src/playlist/playlist.h | 1 + src/playlist/playlistmanager.cpp | 4 ++++ src/playlist/playlistmanager.h | 2 ++ src/ui/mainwindow.cpp | 3 +++ src/ui/mainwindow.ui | 6 ++++++ 6 files changed, 31 insertions(+) diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index f532598d8..5f7ab37f1 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -2109,6 +2109,21 @@ void Playlist::RemoveDuplicateSongs() { removeRows(rows_to_remove); } +void Playlist::RemoveUnavailableSongs() { + QList rows_to_remove; + for (int row = 0; row < items_.count(); ++row) { + PlaylistItemPtr item = items_[row]; + const Song& song = item->Metadata(); + + // check only local files + if (song.url().isLocalFile() && !QFile::exists(song.url().toLocalFile())) { + rows_to_remove.append(row); + } + } + + removeRows(rows_to_remove); +} + bool Playlist::ApplyValidityOnCurrentSong(const QUrl& url, bool valid) { PlaylistItemPtr current = current_item(); diff --git a/src/playlist/playlist.h b/src/playlist/playlist.h index 104e7cd15..a21da6c7f 100644 --- a/src/playlist/playlist.h +++ b/src/playlist/playlist.h @@ -314,6 +314,7 @@ class Playlist : public QAbstractListModel { void Clear(); void RemoveDuplicateSongs(); + void RemoveUnavailableSongs(); void Shuffle(); void ShuffleModeChanged(PlaylistSequence::ShuffleMode mode); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 50cc2404b..d59aaba0b 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -336,6 +336,10 @@ void PlaylistManager::RemoveDuplicatesCurrent() { current()->RemoveDuplicateSongs(); } +void PlaylistManager::RemoveUnavailableCurrent() { + current()->RemoveUnavailableSongs(); +} + void PlaylistManager::SetActivePlaying() { active()->Playing(); } void PlaylistManager::SetActivePaused() { active()->Paused(); } diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index a9b5a9af4..2a911aee1 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -95,6 +95,7 @@ class PlaylistManagerInterface : public QObject { virtual void ClearCurrent() = 0; virtual void ShuffleCurrent() = 0; virtual void RemoveDuplicatesCurrent() = 0; + virtual void RemoveUnavailableCurrent() = 0; virtual void SetActivePlaying() = 0; virtual void SetActivePaused() = 0; virtual void SetActiveStopped() = 0; @@ -204,6 +205,7 @@ class PlaylistManager : public PlaylistManagerInterface { void ClearCurrent(); void ShuffleCurrent(); void RemoveDuplicatesCurrent(); + void RemoveUnavailableCurrent(); void SetActiveStreamMetadata(const QUrl& url, const Song& song); // Rate current song using 0.0 - 1.0 scale. void RateCurrentSong(double rating); diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 03cf0e991..714e46ace 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -368,6 +368,8 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, app_->playlist_manager(), SLOT(ClearCurrent())); connect(ui_->action_remove_duplicates, SIGNAL(triggered()), app_->playlist_manager(), SLOT(RemoveDuplicatesCurrent())); + connect(ui_->action_remove_unavailable, SIGNAL(triggered()), + app_->playlist_manager(), SLOT(RemoveUnavailableCurrent())); connect(ui_->action_remove_from_playlist, SIGNAL(triggered()), SLOT(PlaylistRemoveCurrent())); connect(ui_->action_edit_track, SIGNAL(triggered()), SLOT(EditTracks())); @@ -626,6 +628,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, playlist_menu_->addAction(ui_->action_clear_playlist); playlist_menu_->addAction(ui_->action_shuffle); playlist_menu_->addAction(ui_->action_remove_duplicates); + playlist_menu_->addAction(ui_->action_remove_unavailable); #ifdef Q_OS_DARWIN ui_->action_shuffle->setShortcut(QKeySequence()); diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index e926e841f..84b819bb9 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -444,6 +444,7 @@ + @@ -849,6 +850,11 @@ Rip audio CD... + + + Remove unavailable tracks from playlist + +