handle possible errors while saving playlist properly
This commit is contained in:
@@ -1027,7 +1027,7 @@ bool MPD::Connection::DeletePlaylist(const std::string &name)
|
||||
}
|
||||
}
|
||||
|
||||
bool MPD::Connection::SavePlaylist(const std::string &name)
|
||||
int MPD::Connection::SavePlaylist(const std::string &name)
|
||||
{
|
||||
if (!itsConnection)
|
||||
return false;
|
||||
@@ -1035,8 +1035,12 @@ bool MPD::Connection::SavePlaylist(const std::string &name)
|
||||
GoBusy();
|
||||
mpd_send_save(itsConnection, name.c_str());
|
||||
mpd_response_finish(itsConnection);
|
||||
return !(mpd_connection_get_error(itsConnection) == MPD_ERROR_SERVER
|
||||
&& mpd_connection_get_server_error(itsConnection) == MPD_SERVER_ERROR_EXIST);
|
||||
|
||||
if (mpd_connection_get_error(itsConnection) == MPD_ERROR_SERVER
|
||||
&& mpd_connection_get_server_error(itsConnection) == MPD_SERVER_ERROR_EXIST)
|
||||
return MPD_SERVER_ERROR_EXIST;
|
||||
else
|
||||
return CheckForErrors();
|
||||
}
|
||||
|
||||
void MPD::Connection::GetPlaylists(TagList &v)
|
||||
@@ -1295,7 +1299,7 @@ void MPD::Connection::GetTagTypes(TagList &v)
|
||||
|
||||
int MPD::Connection::CheckForErrors()
|
||||
{
|
||||
int error_code = 0;
|
||||
int error_code = MPD_ERROR_SUCCESS;
|
||||
if ((error_code = mpd_connection_get_error(itsConnection)) != MPD_ERROR_SUCCESS)
|
||||
{
|
||||
itsErrorMessage = mpd_connection_get_error_message(itsConnection);
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace MPD
|
||||
bool CommitCommandsList();
|
||||
|
||||
bool DeletePlaylist(const std::string &);
|
||||
bool SavePlaylist(const std::string &);
|
||||
int SavePlaylist(const std::string &);
|
||||
void ClearPlaylist(const std::string &);
|
||||
void AddToPlaylist(const std::string &, const Song &);
|
||||
void AddToPlaylist(const std::string &, const std::string &);
|
||||
|
||||
@@ -870,13 +870,16 @@ int main(int argc, char *argv[])
|
||||
if (Mpd.GetErrorMessage().empty())
|
||||
ShowMessage("Filtered items added to playlist \"%s\"", playlist_name.c_str());
|
||||
}
|
||||
else if (Mpd.SavePlaylist(real_playlist_name))
|
||||
else
|
||||
{
|
||||
int result = Mpd.SavePlaylist(real_playlist_name);
|
||||
if (result == MPD_ERROR_SUCCESS)
|
||||
{
|
||||
ShowMessage("Playlist saved as: %s", playlist_name.c_str());
|
||||
if (myPlaylistEditor->Main()) // check if initialized
|
||||
myPlaylistEditor->Playlists->Clear(); // make playlist's list update itself
|
||||
}
|
||||
else
|
||||
else if (result == MPD_SERVER_ERROR_EXIST)
|
||||
{
|
||||
LockStatusbar();
|
||||
Statusbar() << "Playlist already exists, overwrite: " << playlist_name << " ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] ";
|
||||
@@ -892,7 +895,7 @@ int main(int argc, char *argv[])
|
||||
if (answer == 'y')
|
||||
{
|
||||
Mpd.DeletePlaylist(real_playlist_name);
|
||||
if (Mpd.SavePlaylist(real_playlist_name))
|
||||
if (Mpd.SavePlaylist(real_playlist_name) == MPD_ERROR_SUCCESS)
|
||||
ShowMessage("Playlist overwritten!");
|
||||
}
|
||||
else
|
||||
@@ -903,6 +906,7 @@ int main(int argc, char *argv[])
|
||||
myPlaylist->EnableHighlighting();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (myBrowser->Main()
|
||||
&& !myBrowser->isLocal()
|
||||
&& myBrowser->CurrentDir() == "/"
|
||||
|
||||
Reference in New Issue
Block a user