diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index 7a8403ac..c9a74b2f 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -52,11 +52,10 @@ bool MPDConnection::Connect() { itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT); isConnected = 1; - if (!CheckForErrors()) - return isConnected; - SendPassword(); CheckForErrors(); - return isConnected; + if (!MPD_PASSWORD.empty()) + SendPassword(); + return !CheckForErrors(); } else return true; @@ -93,7 +92,6 @@ void MPDConnection::SendPassword() { mpd_sendPasswordCommand(itsConnection, MPD_PASSWORD.c_str()); mpd_finishCommand(itsConnection); - CheckForErrors(); } void MPDConnection::SetStatusUpdater(StatusUpdater updater, void *data) @@ -121,9 +119,7 @@ void MPDConnection::UpdateStatus() if (!itsMaxPlaylistLength) itsMaxPlaylistLength = GetPlaylistLength(); - CheckForErrors(); - - if (!isConnected) + if (CheckForErrors()) return; MPDStatusChanges changes; @@ -632,7 +628,7 @@ int MPDConnection::CheckForErrors() isConnected = 0; // the rest of errors are fatal to connection if (itsErrorHandler) itsErrorHandler(this, itsConnection->error, itsConnection->errorStr, itsErrorHandlerUserdata); - errid = itsConnection->errorCode; + errid = itsConnection->error; } itsLastErrorMessage = itsConnection->errorStr; mpd_clearError(itsConnection); diff --git a/src/mpdpp.h b/src/mpdpp.h index c2452172..b110fc3a 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -113,7 +113,7 @@ class MPDConnection int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; } unsigned int GetMaxPlaylistLength() { return itsMaxPlaylistLength; } - int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : -1; } + int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; } void GetPlaylistChanges(long long, SongList &) const; string GetLastErrorMessage() const { return itsLastErrorMessage; } diff --git a/src/status_checker.cpp b/src/status_checker.cpp index eb96685b..7a9dd4d5 100644 --- a/src/status_checker.cpp +++ b/src/status_checker.cpp @@ -121,7 +121,16 @@ void TraceMpdStatus() void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *data) { - ShowMessage(msg); + if (errorid == MPD_ACK_ERROR_PERMISSION) + { + wFooter->WriteXY(0, Config.statusbar_visibility, "Password: ", 1); + string password = wFooter->GetString(""); + Mpd->SetPassword(password); + Mpd->SendPassword(); + Mpd->UpdateStatus(); + } + else + ShowMessage(msg); } void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *data)