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)
|
if (!itsConnection)
|
||||||
return false;
|
return false;
|
||||||
@@ -1035,8 +1035,12 @@ bool MPD::Connection::SavePlaylist(const std::string &name)
|
|||||||
GoBusy();
|
GoBusy();
|
||||||
mpd_send_save(itsConnection, name.c_str());
|
mpd_send_save(itsConnection, name.c_str());
|
||||||
mpd_response_finish(itsConnection);
|
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)
|
void MPD::Connection::GetPlaylists(TagList &v)
|
||||||
@@ -1295,7 +1299,7 @@ void MPD::Connection::GetTagTypes(TagList &v)
|
|||||||
|
|
||||||
int MPD::Connection::CheckForErrors()
|
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)
|
if ((error_code = mpd_connection_get_error(itsConnection)) != MPD_ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
itsErrorMessage = mpd_connection_get_error_message(itsConnection);
|
itsErrorMessage = mpd_connection_get_error_message(itsConnection);
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace MPD
|
|||||||
bool CommitCommandsList();
|
bool CommitCommandsList();
|
||||||
|
|
||||||
bool DeletePlaylist(const std::string &);
|
bool DeletePlaylist(const std::string &);
|
||||||
bool SavePlaylist(const std::string &);
|
int SavePlaylist(const std::string &);
|
||||||
void ClearPlaylist(const std::string &);
|
void ClearPlaylist(const std::string &);
|
||||||
void AddToPlaylist(const std::string &, const Song &);
|
void AddToPlaylist(const std::string &, const Song &);
|
||||||
void AddToPlaylist(const std::string &, const std::string &);
|
void AddToPlaylist(const std::string &, const std::string &);
|
||||||
|
|||||||
@@ -870,37 +870,41 @@ int main(int argc, char *argv[])
|
|||||||
if (Mpd.GetErrorMessage().empty())
|
if (Mpd.GetErrorMessage().empty())
|
||||||
ShowMessage("Filtered items added to playlist \"%s\"", playlist_name.c_str());
|
ShowMessage("Filtered items added to playlist \"%s\"", playlist_name.c_str());
|
||||||
}
|
}
|
||||||
else if (Mpd.SavePlaylist(real_playlist_name))
|
|
||||||
{
|
|
||||||
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
|
||||||
{
|
{
|
||||||
LockStatusbar();
|
int result = Mpd.SavePlaylist(real_playlist_name);
|
||||||
Statusbar() << "Playlist already exists, overwrite: " << playlist_name << " ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] ";
|
if (result == MPD_ERROR_SUCCESS)
|
||||||
wFooter->Refresh();
|
|
||||||
int answer = 0;
|
|
||||||
while (answer != 'y' && answer != 'n')
|
|
||||||
{
|
{
|
||||||
TraceMpdStatus();
|
ShowMessage("Playlist saved as: %s", playlist_name.c_str());
|
||||||
wFooter->ReadKey(answer);
|
if (myPlaylistEditor->Main()) // check if initialized
|
||||||
|
myPlaylistEditor->Playlists->Clear(); // make playlist's list update itself
|
||||||
}
|
}
|
||||||
UnlockStatusbar();
|
else if (result == MPD_SERVER_ERROR_EXIST)
|
||||||
|
|
||||||
if (answer == 'y')
|
|
||||||
{
|
{
|
||||||
Mpd.DeletePlaylist(real_playlist_name);
|
LockStatusbar();
|
||||||
if (Mpd.SavePlaylist(real_playlist_name))
|
Statusbar() << "Playlist already exists, overwrite: " << playlist_name << " ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] ";
|
||||||
ShowMessage("Playlist overwritten!");
|
wFooter->Refresh();
|
||||||
|
int answer = 0;
|
||||||
|
while (answer != 'y' && answer != 'n')
|
||||||
|
{
|
||||||
|
TraceMpdStatus();
|
||||||
|
wFooter->ReadKey(answer);
|
||||||
|
}
|
||||||
|
UnlockStatusbar();
|
||||||
|
|
||||||
|
if (answer == 'y')
|
||||||
|
{
|
||||||
|
Mpd.DeletePlaylist(real_playlist_name);
|
||||||
|
if (Mpd.SavePlaylist(real_playlist_name) == MPD_ERROR_SUCCESS)
|
||||||
|
ShowMessage("Playlist overwritten!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ShowMessage("Aborted!");
|
||||||
|
if (myPlaylistEditor->Main()) // check if initialized
|
||||||
|
myPlaylistEditor->Playlists->Clear(); // make playlist's list update itself
|
||||||
|
if (myScreen == myPlaylist)
|
||||||
|
myPlaylist->EnableHighlighting();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
ShowMessage("Aborted!");
|
|
||||||
if (myPlaylistEditor->Main()) // check if initialized
|
|
||||||
myPlaylistEditor->Playlists->Clear(); // make playlist's list update itself
|
|
||||||
if (myScreen == myPlaylist)
|
|
||||||
myPlaylist->EnableHighlighting();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (myBrowser->Main()
|
if (myBrowser->Main()
|
||||||
|
|||||||
Reference in New Issue
Block a user