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.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:

View File

@@ -486,26 +486,33 @@ template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
}
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 {
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);

View File

@@ -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)
);
}
}

View File

@@ -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);

View File

@@ -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();
}

View File

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