add proper mpd password handling

This commit is contained in:
unknown
2008-08-20 12:35:08 +02:00
parent ea1b6d14d9
commit 19561bad4f
3 changed files with 16 additions and 11 deletions

View File

@@ -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);

View File

@@ -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; }

View File

@@ -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)