diff --git a/src/browser.cpp b/src/browser.cpp index 996f990e..51020914 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -127,8 +127,10 @@ void Browser::enterPressed() { MPD::SongList list; Mpd.GetPlaylistContentNoInfo(item.name, vectorMoveInserter(list)); - addSongsToPlaylist(list.begin(), list.end(), true, -1); - Statusbar::msg("Playlist \"%s\" loaded", item.name.c_str()); + bool success = addSongsToPlaylist(list.begin(), list.end(), true, -1); + Statusbar::msg("Playlist \"%s\" loaded%s", + item.name.c_str(), withErrors(success) + ); } } } @@ -156,6 +158,7 @@ void Browser::spacePressed() { case itDirectory: { + bool success; # ifndef WIN32 if (isLocal()) { @@ -166,12 +169,17 @@ void Browser::spacePressed() list.reserve(items.size()); for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it) list.push_back(*it->song); - addSongsToPlaylist(list.begin(), list.end(), false, -1); + success = addSongsToPlaylist(list.begin(), list.end(), false, -1); } else # endif // !WIN32 + { Mpd.Add(item.name); - Statusbar::msg("Directory \"%s\" added", item.name.c_str()); + success = true; + } + Statusbar::msg("Directory \"%s\" added%s", + item.name.c_str(), withErrors(success) + ); break; } case itSong: diff --git a/src/helpers.h b/src/helpers.h index 604b7b29..eee7a594 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -486,26 +486,33 @@ template void ShowTag(BufferT &buf, const std::string &tag) } template -void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int position) +bool addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int position) { + bool result = true; auto addSongNoError = [&](SongIterator song) -> int { try { return Mpd.AddSong(*song, position); } - catch (...) + catch (MPD::ServerError &e) { + Status::handleServerError(e); + result = false; return -1; } }; if (last-first >= 1) { - int id = addSongNoError(first); - while (id < 0) { - if (++first == last) - return; + int id; + while (true) + { id = addSongNoError(first); + if (id >= 0) + break; + ++first; + if (first == last) + return result; } if (position == -1) @@ -524,6 +531,13 @@ void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int po if (play) Mpd.PlayID(id); } + + return result; +} + +inline const char *withErrors(bool success) +{ + return success ? "" : " " "(with errors)"; } bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1); diff --git a/src/media_library.cpp b/src/media_library.cpp index a9037b81..252aa5df 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -1004,19 +1004,22 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) Mpd.StartSearch(true); Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag()); Mpd.CommitSearchSongs(vectorMoveInserter(list)); - addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1); + bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1); std::string tag_type = boost::locale::to_lower( tagTypeToString(Config.media_lib_primary_tag)); - Statusbar::msg("Songs with %s = \"%s\" added", - tag_type.c_str(), Tags.current().value().tag().c_str()); + Statusbar::msg("Songs with %s = \"%s\" added%s", + tag_type.c_str(), Tags.current().value().tag().c_str(), withErrors(success) + ); } else if (isActiveWindow(Albums)) { + bool success; withUnfilteredMenu(Songs, [&]() { - addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1); + success = addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1); }); - Statusbar::msg("Songs from album \"%s\" added", - Albums.current().value().entry().album().c_str()); + Statusbar::msg("Songs from album \"%s\" added%s", + Albums.current().value().entry().album().c_str(), withErrors(success) + ); } } diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index d82b6a1d..4394eefa 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -220,10 +220,13 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) if (isActiveWindow(Playlists) && !Playlists.empty()) { + bool success; withUnfilteredMenu(Content, [&]() { - addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1); + success = addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1); }); - Statusbar::msg("Playlist \"%s\" loaded", Playlists.current().value().c_str()); + Statusbar::msg("Playlist \"%s\" loaded%s", + Playlists.current().value().c_str(), withErrors(success) + ); } else if (isActiveWindow(Content) && !Content.empty()) addSongToPlaylist(Content.current().value(), add_n_play); diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index 4ffbf232..c36ccf88 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -242,14 +242,14 @@ void SelectedItemsAdder::addToExistingPlaylist(const std::string &playlist) cons void SelectedItemsAdder::addAtTheEndOfPlaylist() const { - addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, -1); - exitSuccessfully(); + bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, -1); + exitSuccessfully(success); } void SelectedItemsAdder::addAtTheBeginningOfPlaylist() const { - addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, 0); - exitSuccessfully(); + bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, 0); + exitSuccessfully(success); } void SelectedItemsAdder::addAfterCurrentSong() const @@ -258,8 +258,8 @@ void SelectedItemsAdder::addAfterCurrentSong() const return; size_t pos = myPlaylist->currentSongPosition(); ++pos; - addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); - exitSuccessfully(); + bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); + exitSuccessfully(success); } void SelectedItemsAdder::addAfterCurrentAlbum() const @@ -273,16 +273,16 @@ void SelectedItemsAdder::addAfterCurrentAlbum() const while (pos < pl.size() && pl[pos].value().getAlbum() == album) ++pos; }); - addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); - exitSuccessfully(); + bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); + exitSuccessfully(success); } void SelectedItemsAdder::addAfterHighlightedSong() const { size_t pos = myPlaylist->main().current().value().getPosition(); ++pos; - addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); - exitSuccessfully(); + bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); + exitSuccessfully(success); } void SelectedItemsAdder::cancel() @@ -293,9 +293,9 @@ void SelectedItemsAdder::cancel() w = &m_playlist_selector; } -void SelectedItemsAdder::exitSuccessfully() const +void SelectedItemsAdder::exitSuccessfully(bool success) const { - Statusbar::msg("Selected items added"); + Statusbar::msg("Selected items added%s", withErrors(success)); switchToPreviousScreen(); } diff --git a/src/sel_items_adder.h b/src/sel_items_adder.h index 78ede4af..0e5a1952 100644 --- a/src/sel_items_adder.h +++ b/src/sel_items_adder.h @@ -64,7 +64,7 @@ private: void addAfterCurrentAlbum() const; void addAfterHighlightedSong() const; void cancel(); - void exitSuccessfully() const; + void exitSuccessfully(bool success) const; void setDimensions();