do not delete items from playlist if sending command delete failed
This commit is contained in:
@@ -36,7 +36,6 @@ const char *MPD::Message::FunctionDisabledFilteringEnabled = "Function disabled
|
||||
|
||||
Connection::Connection() : itsConnection(0),
|
||||
isCommandsListEnabled(0),
|
||||
itsErrorCode(0),
|
||||
itsMaxPlaylistLength(-1),
|
||||
isIdle(0),
|
||||
supportsIdle(0),
|
||||
@@ -893,45 +892,47 @@ bool Connection::AddRandomSongs(size_t number)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Connection::Delete(unsigned pos)
|
||||
bool Connection::Delete(unsigned pos)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
return false;
|
||||
if (!isCommandsListEnabled)
|
||||
GoBusy();
|
||||
else
|
||||
assert(!isIdle);
|
||||
mpd_send_delete(itsConnection, pos);
|
||||
bool result = mpd_send_delete(itsConnection, pos);
|
||||
if (!isCommandsListEnabled)
|
||||
mpd_response_finish(itsConnection);
|
||||
result = mpd_response_finish(itsConnection);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Connection::DeleteID(unsigned id)
|
||||
bool Connection::DeleteID(unsigned id)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
return false;
|
||||
if (!isCommandsListEnabled)
|
||||
GoBusy();
|
||||
else
|
||||
assert(!isIdle);
|
||||
mpd_send_delete_id(itsConnection, id);
|
||||
bool result = mpd_send_delete_id(itsConnection, id);
|
||||
if (!isCommandsListEnabled)
|
||||
mpd_response_finish(itsConnection);
|
||||
result = mpd_response_finish(itsConnection);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Connection::Delete(const std::string &playlist, unsigned pos)
|
||||
bool Connection::Delete(const std::string &playlist, unsigned pos)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return;
|
||||
return false;
|
||||
if (!isCommandsListEnabled)
|
||||
{
|
||||
GoBusy();
|
||||
mpd_run_playlist_delete(itsConnection, playlist.c_str(), pos);
|
||||
return mpd_run_playlist_delete(itsConnection, playlist.c_str(), pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(!isIdle);
|
||||
mpd_send_playlist_delete(itsConnection, playlist.c_str(), pos);
|
||||
return mpd_send_playlist_delete(itsConnection, playlist.c_str(), pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -956,8 +957,9 @@ bool Connection::CommitCommandsList()
|
||||
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
|
||||
itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata);
|
||||
isCommandsListEnabled = 0;
|
||||
bool result = !CheckForErrors();
|
||||
UpdateStatus();
|
||||
return !CheckForErrors();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Connection::DeletePlaylist(const std::string &name)
|
||||
@@ -1241,23 +1243,24 @@ void Connection::GetTagTypes(TagList &v)
|
||||
|
||||
int Connection::CheckForErrors()
|
||||
{
|
||||
if ((itsErrorCode = mpd_connection_get_error(itsConnection)) != MPD_ERROR_SUCCESS)
|
||||
int error_code = 0;
|
||||
if ((error_code = mpd_connection_get_error(itsConnection)) != MPD_ERROR_SUCCESS)
|
||||
{
|
||||
itsErrorMessage = mpd_connection_get_error_message(itsConnection);
|
||||
if (itsErrorCode == MPD_ERROR_SERVER)
|
||||
if (error_code == MPD_ERROR_SERVER)
|
||||
{
|
||||
// this is to avoid setting too small max size as we check it before fetching current status
|
||||
// setting real max playlist length is in UpdateStatus()
|
||||
itsErrorCode = mpd_connection_get_server_error(itsConnection);
|
||||
if (itsErrorCode == MPD_SERVER_ERROR_PLAYLIST_MAX && itsMaxPlaylistLength == size_t(-1))
|
||||
error_code = mpd_connection_get_server_error(itsConnection);
|
||||
if (error_code == MPD_SERVER_ERROR_PLAYLIST_MAX && itsMaxPlaylistLength == size_t(-1))
|
||||
itsMaxPlaylistLength = 0;
|
||||
}
|
||||
if (!mpd_connection_clear_error(itsConnection))
|
||||
Disconnect();
|
||||
if (itsErrorHandler)
|
||||
itsErrorHandler(this, itsErrorCode, itsErrorMessage.c_str(), itsErrorHandlerUserdata);
|
||||
itsErrorHandler(this, error_code, itsErrorMessage.c_str(), itsErrorHandlerUserdata);
|
||||
}
|
||||
return itsErrorCode;
|
||||
return error_code;
|
||||
}
|
||||
|
||||
void MPD::FreeSongList(SongList &l)
|
||||
|
||||
@@ -154,7 +154,6 @@ namespace MPD
|
||||
void GetPlaylistChanges(unsigned, SongList &);
|
||||
|
||||
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
||||
int GetErrorCode() const { return itsErrorCode; }
|
||||
|
||||
Song GetCurrentSong();
|
||||
int GetCurrentSongPos() const;
|
||||
@@ -175,9 +174,9 @@ namespace MPD
|
||||
int AddSong(const Song &, int = -1); // returns id of added song
|
||||
bool AddRandomSongs(size_t);
|
||||
void Add(const std::string &path);
|
||||
void Delete(unsigned);
|
||||
void DeleteID(unsigned);
|
||||
void Delete(const std::string &, unsigned);
|
||||
bool Delete(unsigned);
|
||||
bool DeleteID(unsigned);
|
||||
bool Delete(const std::string &, unsigned);
|
||||
void StartCommandsList();
|
||||
bool CommitCommandsList();
|
||||
|
||||
@@ -220,7 +219,6 @@ namespace MPD
|
||||
bool isCommandsListEnabled;
|
||||
|
||||
std::string itsErrorMessage;
|
||||
int itsErrorCode;
|
||||
size_t itsMaxPlaylistLength;
|
||||
|
||||
int itsFD;
|
||||
|
||||
@@ -586,20 +586,20 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (!myPlaylist->Items->Empty() && myScreen == myPlaylist)
|
||||
{
|
||||
Playlist::BlockUpdate = 1;
|
||||
if (myPlaylist->Items->hasSelected())
|
||||
{
|
||||
std::vector<size_t> list;
|
||||
myPlaylist->Items->GetSelected(list);
|
||||
Mpd.StartCommandsList();
|
||||
for (std::vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); ++it)
|
||||
{
|
||||
Mpd.DeleteID((*myPlaylist->Items)[*it].GetID());
|
||||
myPlaylist->Items->DeleteOption(*it);
|
||||
if (Mpd.CommitCommandsList())
|
||||
{
|
||||
for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
|
||||
myPlaylist->Items->Select(i, 0);
|
||||
myPlaylist->FixPositions(list.front());
|
||||
ShowMessage("Selected items deleted!");
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
myPlaylist->FixPositions(list.front());
|
||||
ShowMessage("Selected items deleted!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -615,11 +615,15 @@ int main(int argc, char *argv[])
|
||||
// needed for keeping proper position of now playing song.
|
||||
if (myPlaylist->NowPlaying > int(myPlaylist->CurrentSong()->GetPosition())-del_counter)
|
||||
--myPlaylist->NowPlaying;
|
||||
Mpd.DeleteID(myPlaylist->CurrentSong()->GetID());
|
||||
myPlaylist->Items->DeleteOption(id);
|
||||
myPlaylist->Items->Refresh();
|
||||
wFooter->ReadKey(input);
|
||||
++del_counter;
|
||||
if (Mpd.DeleteID(myPlaylist->CurrentSong()->GetID()))
|
||||
{
|
||||
myPlaylist->Items->DeleteOption(id);
|
||||
myPlaylist->Items->Refresh();
|
||||
wFooter->ReadKey(input);
|
||||
++del_counter;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
myPlaylist->FixPositions(myPlaylist->Items->Choice());
|
||||
wFooter->SetTimeout(ncmpcpp_window_timeout);
|
||||
|
||||
Reference in New Issue
Block a user