|
|
|
|
@ -28,12 +28,8 @@ |
|
|
|
|
|
|
|
|
|
MPD::Connection Mpd; |
|
|
|
|
|
|
|
|
|
const char *MPD::Message::PartOfSongsAdded = "Only part of requested songs' list added to playlist!"; |
|
|
|
|
const char *MPD::Message::FullPlaylist = "Playlist is full!"; |
|
|
|
|
|
|
|
|
|
MPD::Connection::Connection() : itsConnection(0), |
|
|
|
|
isCommandsListEnabled(0), |
|
|
|
|
itsMaxPlaylistLength(-1), |
|
|
|
|
isIdle(0), |
|
|
|
|
supportsIdle(0), |
|
|
|
|
itsHost("localhost"), |
|
|
|
|
@ -98,7 +94,6 @@ void MPD::Connection::Disconnect() |
|
|
|
|
itsOldStatus = 0; |
|
|
|
|
itsStats = 0; |
|
|
|
|
isCommandsListEnabled = 0; |
|
|
|
|
itsMaxPlaylistLength = -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned MPD::Connection::Version() const |
|
|
|
|
@ -209,9 +204,6 @@ void MPD::Connection::UpdateStatus() |
|
|
|
|
|
|
|
|
|
itsCurrentStatus = mpd_run_status(itsConnection); |
|
|
|
|
|
|
|
|
|
if (!itsMaxPlaylistLength) |
|
|
|
|
itsMaxPlaylistLength = GetPlaylistLength(); |
|
|
|
|
|
|
|
|
|
if (CheckForErrors()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
@ -851,27 +843,22 @@ int MPD::Connection::AddSong(const std::string &path, int pos) |
|
|
|
|
{ |
|
|
|
|
if (!itsConnection) |
|
|
|
|
return -1; |
|
|
|
|
int id = -1; |
|
|
|
|
if (GetPlaylistLength() < itsMaxPlaylistLength) |
|
|
|
|
int id; |
|
|
|
|
if (!isCommandsListEnabled) |
|
|
|
|
GoBusy(); |
|
|
|
|
else |
|
|
|
|
assert(!isIdle); |
|
|
|
|
if (pos < 0) |
|
|
|
|
mpd_send_add_id(itsConnection, path.c_str()); |
|
|
|
|
else |
|
|
|
|
mpd_send_add_id_to(itsConnection, path.c_str(), pos); |
|
|
|
|
if (!isCommandsListEnabled) |
|
|
|
|
{ |
|
|
|
|
if (!isCommandsListEnabled) |
|
|
|
|
GoBusy(); |
|
|
|
|
else |
|
|
|
|
assert(!isIdle); |
|
|
|
|
if (pos < 0) |
|
|
|
|
mpd_send_add_id(itsConnection, path.c_str()); |
|
|
|
|
else |
|
|
|
|
mpd_send_add_id_to(itsConnection, path.c_str(), pos); |
|
|
|
|
if (!isCommandsListEnabled) |
|
|
|
|
{ |
|
|
|
|
id = mpd_recv_song_id(itsConnection); |
|
|
|
|
mpd_response_finish(itsConnection); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
id = 0; |
|
|
|
|
id = mpd_recv_song_id(itsConnection); |
|
|
|
|
mpd_response_finish(itsConnection); |
|
|
|
|
} |
|
|
|
|
else if (itsErrorHandler) |
|
|
|
|
itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata); |
|
|
|
|
else |
|
|
|
|
id = 0; |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1030,11 +1017,6 @@ bool MPD::Connection::CommitCommandsList() |
|
|
|
|
mpd_command_list_end(itsConnection); |
|
|
|
|
isCommandsListEnabled = 0; |
|
|
|
|
return mpd_response_finish(itsConnection); |
|
|
|
|
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler) |
|
|
|
|
itsErrorHandler(this, MPD_SERVER_ERROR_PLAYLIST_MAX, Message::FullPlaylist, itsErrorHandlerUserdata); |
|
|
|
|
bool result = !CheckForErrors(); |
|
|
|
|
UpdateStatus(); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool MPD::Connection::DeletePlaylist(const std::string &name) |
|
|
|
|
@ -1339,13 +1321,7 @@ int MPD::Connection::CheckForErrors() |
|
|
|
|
{ |
|
|
|
|
itsErrorMessage = mpd_connection_get_error_message(itsConnection); |
|
|
|
|
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()
|
|
|
|
|
error_code |= (mpd_connection_get_server_error(itsConnection) << 8); |
|
|
|
|
if ((error_code >> 8) == MPD_SERVER_ERROR_PLAYLIST_MAX && itsMaxPlaylistLength == size_t(-1)) |
|
|
|
|
itsMaxPlaylistLength = 0; |
|
|
|
|
} |
|
|
|
|
if (!mpd_connection_clear_error(itsConnection)) |
|
|
|
|
{ |
|
|
|
|
Disconnect(); |
|
|
|
|
|