notify user if some files failed to be added

This commit is contained in:
Andrzej Rybczak
2014-01-18 16:44:39 +01:00
parent 7094852c20
commit 34923a035c
6 changed files with 59 additions and 31 deletions

View File

@@ -127,8 +127,10 @@ void Browser::enterPressed()
{ {
MPD::SongList list; MPD::SongList list;
Mpd.GetPlaylistContentNoInfo(item.name, vectorMoveInserter(list)); Mpd.GetPlaylistContentNoInfo(item.name, vectorMoveInserter(list));
addSongsToPlaylist(list.begin(), list.end(), true, -1); bool success = addSongsToPlaylist(list.begin(), list.end(), true, -1);
Statusbar::msg("Playlist \"%s\" loaded", item.name.c_str()); Statusbar::msg("Playlist \"%s\" loaded%s",
item.name.c_str(), withErrors(success)
);
} }
} }
} }
@@ -156,6 +158,7 @@ void Browser::spacePressed()
{ {
case itDirectory: case itDirectory:
{ {
bool success;
# ifndef WIN32 # ifndef WIN32
if (isLocal()) if (isLocal())
{ {
@@ -166,12 +169,17 @@ void Browser::spacePressed()
list.reserve(items.size()); list.reserve(items.size());
for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it) for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
list.push_back(*it->song); list.push_back(*it->song);
addSongsToPlaylist(list.begin(), list.end(), false, -1); success = addSongsToPlaylist(list.begin(), list.end(), false, -1);
} }
else else
# endif // !WIN32 # endif // !WIN32
{
Mpd.Add(item.name); 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; break;
} }
case itSong: case itSong:

View File

@@ -486,26 +486,33 @@ template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
} }
template <typename SongIterator> template <typename SongIterator>
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 { auto addSongNoError = [&](SongIterator song) -> int {
try try
{ {
return Mpd.AddSong(*song, position); return Mpd.AddSong(*song, position);
} }
catch (...) catch (MPD::ServerError &e)
{ {
Status::handleServerError(e);
result = false;
return -1; return -1;
} }
}; };
if (last-first >= 1) if (last-first >= 1)
{ {
int id = addSongNoError(first); int id;
while (id < 0) { while (true)
if (++first == last) {
return;
id = addSongNoError(first); id = addSongNoError(first);
if (id >= 0)
break;
++first;
if (first == last)
return result;
} }
if (position == -1) if (position == -1)
@@ -524,6 +531,13 @@ void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int po
if (play) if (play)
Mpd.PlayID(id); 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); bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1);

View File

@@ -1004,19 +1004,22 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
Mpd.StartSearch(true); Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag()); Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag());
Mpd.CommitSearchSongs(vectorMoveInserter(list)); 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( std::string tag_type = boost::locale::to_lower(
tagTypeToString(Config.media_lib_primary_tag)); tagTypeToString(Config.media_lib_primary_tag));
Statusbar::msg("Songs with %s = \"%s\" added", Statusbar::msg("Songs with %s = \"%s\" added%s",
tag_type.c_str(), Tags.current().value().tag().c_str()); tag_type.c_str(), Tags.current().value().tag().c_str(), withErrors(success)
);
} }
else if (isActiveWindow(Albums)) else if (isActiveWindow(Albums))
{ {
bool success;
withUnfilteredMenu(Songs, [&]() { 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", Statusbar::msg("Songs from album \"%s\" added%s",
Albums.current().value().entry().album().c_str()); Albums.current().value().entry().album().c_str(), withErrors(success)
);
} }
} }

View File

@@ -220,10 +220,13 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
if (isActiveWindow(Playlists) && !Playlists.empty()) if (isActiveWindow(Playlists) && !Playlists.empty())
{ {
bool success;
withUnfilteredMenu(Content, [&]() { 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()) else if (isActiveWindow(Content) && !Content.empty())
addSongToPlaylist(Content.current().value(), add_n_play); addSongToPlaylist(Content.current().value(), add_n_play);

View File

@@ -242,14 +242,14 @@ void SelectedItemsAdder::addToExistingPlaylist(const std::string &playlist) cons
void SelectedItemsAdder::addAtTheEndOfPlaylist() const void SelectedItemsAdder::addAtTheEndOfPlaylist() const
{ {
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, -1); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, -1);
exitSuccessfully(); exitSuccessfully(success);
} }
void SelectedItemsAdder::addAtTheBeginningOfPlaylist() const void SelectedItemsAdder::addAtTheBeginningOfPlaylist() const
{ {
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, 0); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, 0);
exitSuccessfully(); exitSuccessfully(success);
} }
void SelectedItemsAdder::addAfterCurrentSong() const void SelectedItemsAdder::addAfterCurrentSong() const
@@ -258,8 +258,8 @@ void SelectedItemsAdder::addAfterCurrentSong() const
return; return;
size_t pos = myPlaylist->currentSongPosition(); size_t pos = myPlaylist->currentSongPosition();
++pos; ++pos;
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
exitSuccessfully(); exitSuccessfully(success);
} }
void SelectedItemsAdder::addAfterCurrentAlbum() const void SelectedItemsAdder::addAfterCurrentAlbum() const
@@ -273,16 +273,16 @@ void SelectedItemsAdder::addAfterCurrentAlbum() const
while (pos < pl.size() && pl[pos].value().getAlbum() == album) while (pos < pl.size() && pl[pos].value().getAlbum() == album)
++pos; ++pos;
}); });
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
exitSuccessfully(); exitSuccessfully(success);
} }
void SelectedItemsAdder::addAfterHighlightedSong() const void SelectedItemsAdder::addAfterHighlightedSong() const
{ {
size_t pos = myPlaylist->main().current().value().getPosition(); size_t pos = myPlaylist->main().current().value().getPosition();
++pos; ++pos;
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos); bool success = addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
exitSuccessfully(); exitSuccessfully(success);
} }
void SelectedItemsAdder::cancel() void SelectedItemsAdder::cancel()
@@ -293,9 +293,9 @@ void SelectedItemsAdder::cancel()
w = &m_playlist_selector; 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(); switchToPreviousScreen();
} }

View File

@@ -64,7 +64,7 @@ private:
void addAfterCurrentAlbum() const; void addAfterCurrentAlbum() const;
void addAfterHighlightedSong() const; void addAfterHighlightedSong() const;
void cancel(); void cancel();
void exitSuccessfully() const; void exitSuccessfully(bool success) const;
void setDimensions(); void setDimensions();