summaryrefslogtreecommitdiff
path: root/src/screens
diff options
context:
space:
mode:
authorAndrzej Rybczak <andrzej@rybczak.net>2020-12-19 16:54:51 +0100
committerAndrzej Rybczak <andrzej@rybczak.net>2020-12-19 16:54:51 +0100
commitcbc9741e66777e076e24a245bf58a759422d1b0d (patch)
tree0eed55365196e673043b2e146eb8281235238415 /src/screens
parentd724e06262f63a085b0b36015949baa1a4697d6a (diff)
Faster loading of playlists from the playlist editor
Diffstat (limited to 'src/screens')
-rw-r--r--src/screens/browser.cpp28
-rw-r--r--src/screens/playlist_editor.cpp31
2 files changed, 37 insertions, 22 deletions
diff --git a/src/screens/browser.cpp b/src/screens/browser.cpp
index 7303f41c..7111e5c5 100644
--- a/src/screens/browser.cpp
+++ b/src/screens/browser.cpp
@@ -305,14 +305,13 @@ bool Browser::itemAvailable()
bool Browser::addItemToPlaylist(bool play)
{
- bool result = false;
+ bool success = false;
auto tryToPlay = [] {
- // Cheap trick that might fail in presence of multiple
- // clients modifying the playlist at the same time, but
- // oh well, this approach correctly loads cue playlists
- // and is much faster in general as it doesn't require
- // fetching song data.
+ // Cheap trick that might fail in presence of multiple clients modifying the
+ // playlist at the same time, but oh well, this approach correctly loads cue
+ // playlists and is much faster in general as it doesn't require fetching
+ // song data.
try
{
Mpd.Play(Status::State::playlistLength());
@@ -334,31 +333,30 @@ bool Browser::addItemToPlaylist(bool play)
{
std::vector<MPD::Song> songs;
getLocalDirectoryRecursively(songs, item.directory().path());
- result = addSongsToPlaylist(songs.begin(), songs.end(), play, -1);
+ success = addSongsToPlaylist(songs.begin(), songs.end(), play, -1);
}
else
{
- Mpd.Add(item.directory().path());
+ success = Mpd.Add(item.directory().path());
if (play)
tryToPlay();
- result = true;
}
Statusbar::printf("Directory \"%1%\" added%2%",
- item.directory().path(), withErrors(result));
+ item.directory().path(), withErrors(success));
break;
}
case MPD::Item::Type::Song:
- result = addSongToPlaylist(item.song(), play);
+ success = addSongToPlaylist(item.song(), play);
break;
case MPD::Item::Type::Playlist:
- Mpd.LoadPlaylist(item.playlist().path());
+ success = Mpd.LoadPlaylist(item.playlist().path());
if (play)
tryToPlay();
- Statusbar::printf("Playlist \"%1%\" loaded", item.playlist().path());
- result = true;
+ if (success)
+ Statusbar::printf("Playlist \"%1%\" loaded", item.playlist().path());
break;
}
- return result;
+ return success;
}
std::vector<MPD::Song> Browser::getSelectedSongs()
diff --git a/src/screens/playlist_editor.cpp b/src/screens/playlist_editor.cpp
index 4943a73f..f5ed7e8f 100644
--- a/src/screens/playlist_editor.cpp
+++ b/src/screens/playlist_editor.cpp
@@ -374,17 +374,34 @@ bool PlaylistEditor::itemAvailable()
bool PlaylistEditor::addItemToPlaylist(bool play)
{
- bool result = false;
+ bool success = false;
if (isActiveWindow(Playlists))
{
- ScopedUnfilteredMenu<MPD::Song> sunfilter_content(ReapplyFilter::No, Content);
- result = addSongsToPlaylist(Content.beginV(), Content.endV(), play, -1);
- Statusbar::printf("Playlist \"%1%\" loaded%2%",
- Playlists.current()->value().path(), withErrors(result));
+ const auto &playlist = Playlists.current()->value();
+ success = Mpd.LoadPlaylist(playlist.path());
+ if (play)
+ {
+ // Cheap trick that might fail in presence of multiple clients modifying the
+ // playlist at the same time, but oh well, this approach correctly loads cue
+ // playlists and is much faster in general as it doesn't require fetching
+ // song data.
+ try
+ {
+ Mpd.Play(Status::State::playlistLength());
+ }
+ catch (MPD::ServerError &e)
+ {
+ // If not bad index, rethrow.
+ if (e.code() != MPD_SERVER_ERROR_ARG)
+ throw;
+ }
+ }
+ if (success)
+ Statusbar::printf("Playlist \"%1%\" loaded", playlist.path());
}
else if (isActiveWindow(Content))
- result = addSongToPlaylist(Content.current()->value(), play);
- return result;
+ success = addSongToPlaylist(Content.current()->value(), play);
+ return success;
}
std::vector<MPD::Song> PlaylistEditor::getSelectedSongs()