If connection fails due to password, then state this in error message.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
lyrics, imported songs, etc as writeable by 'audio'
|
||||
15. Attempt to read defaults from /etc/mpd.conf (This is usualyy readable by
|
||||
'audio' group)
|
||||
16. If connection fails due to password, then state this in error message.
|
||||
|
||||
0.6.1
|
||||
-----
|
||||
|
||||
@@ -895,7 +895,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(MPDConnection::self(), SIGNAL(currentSongUpdated(const Song &)), this, SLOT(updateCurrentSong(const Song &)));
|
||||
connect(MPDConnection::self(), SIGNAL(storedPlayListUpdated()), MPDConnection::self(), SLOT(listPlaylists()));
|
||||
connect(MPDConnection::self(), SIGNAL(stateChanged(bool)), SLOT(mpdConnectionStateChanged(bool)));
|
||||
connect(MPDConnection::self(), SIGNAL(error(const QString &)), SLOT(showError(const QString &)));
|
||||
connect(MPDConnection::self(), SIGNAL(error(const QString &, bool)), SLOT(showError(const QString &, bool)));
|
||||
connect(Dynamic::self(), SIGNAL(error(const QString &)), SLOT(showError(const QString &)));
|
||||
connect(Dynamic::self(), SIGNAL(running(bool)), this, SLOT(dynamicMode(bool)));
|
||||
connect(refreshAction, SIGNAL(triggered(bool)), this, SLOT(refresh()));
|
||||
@@ -1214,19 +1214,6 @@ void MainWindow::mpdConnectionStateChanged(bool connected)
|
||||
lyricsPage->text->clear();
|
||||
serverInfoPage->clear();
|
||||
QString host=MPDConnection::self()->getHost();
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
if (host.startsWith('/')) {
|
||||
showError(i18n("Connection to %1 failed", host), true);
|
||||
} else {
|
||||
showError(i18nc("host:port", "Connection to %1:%2 failed", host, QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#else
|
||||
if (host.startsWith('/')) {
|
||||
showError(tr("Connection to %1 failed").arg(host), true);
|
||||
} else {
|
||||
showError(tr("Connection to %1:%2 failed").arg(host).arg(QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#endif
|
||||
connectedState=CS_Disconnected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,13 +194,13 @@ MPDConnection::~MPDConnection()
|
||||
idleSocket.disconnectFromHost();
|
||||
}
|
||||
|
||||
bool MPDConnection::connectToMPD(MpdSocket &socket, bool enableIdle)
|
||||
MPDConnection::ConnectionReturn MPDConnection::connectToMPD(MpdSocket &socket, bool enableIdle)
|
||||
{
|
||||
if (QAbstractSocket::ConnectedState!=socket.state()) {
|
||||
DBUG << (void *)(&socket) << "Connecting" << (enableIdle ? "(idle)" : "(std)");
|
||||
if (hostname.isEmpty() || port == 0) {
|
||||
DBUG << "no hostname and/or port supplied.";
|
||||
return false;
|
||||
return Failed;
|
||||
}
|
||||
|
||||
socket.connectToHost(hostname, port);
|
||||
@@ -232,7 +232,7 @@ bool MPDConnection::connectToMPD(MpdSocket &socket, bool enableIdle)
|
||||
if (!readReply(socket).ok) {
|
||||
DBUG << (void *)(&socket) << "password rejected";
|
||||
socket.close();
|
||||
return false;
|
||||
return IncorrectPassword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,30 +243,32 @@ bool MPDConnection::connectToMPD(MpdSocket &socket, bool enableIdle)
|
||||
socket.write("idle\n");
|
||||
socket.waitForBytesWritten();
|
||||
}
|
||||
return true;
|
||||
return Success;
|
||||
} else {
|
||||
DBUG << (void *)(&socket) << "Couldn't connect";
|
||||
return false;
|
||||
return Failed;
|
||||
}
|
||||
}
|
||||
|
||||
// DBUG << "Already connected" << (enableIdle ? "(idle)" : "(std)");
|
||||
return true;
|
||||
return Success;
|
||||
}
|
||||
|
||||
bool MPDConnection::connectToMPD()
|
||||
MPDConnection::ConnectionReturn MPDConnection::connectToMPD()
|
||||
{
|
||||
if (State_Connected==state && (QAbstractSocket::ConnectedState!=sock.state() || QAbstractSocket::ConnectedState!=idleSocket.state())) {
|
||||
DBUG << "Something has gone wrong with sockets, so disconnect";
|
||||
disconnectFromMPD();
|
||||
}
|
||||
if (connectToMPD(sock) && connectToMPD(idleSocket, true)) {
|
||||
ConnectionReturn status=Failed;
|
||||
if (Success==(status=connectToMPD(sock)) && Success==(status=connectToMPD(idleSocket, true))) {
|
||||
state=State_Connected;
|
||||
} else {
|
||||
disconnectFromMPD();
|
||||
state=State_Disconnected;
|
||||
}
|
||||
|
||||
return State_Connected==state;
|
||||
return status;
|
||||
}
|
||||
|
||||
void MPDConnection::disconnectFromMPD()
|
||||
@@ -295,15 +297,45 @@ void MPDConnection::setDetails(const QString &host, quint16 p, const QString &pa
|
||||
port=p;
|
||||
password=pass;
|
||||
DBUG << "call connectToMPD";
|
||||
if (connectToMPD()) {
|
||||
switch (connectToMPD()) {
|
||||
case Success:
|
||||
getUrlHandlers();
|
||||
if (!wasConnected) {
|
||||
emit stateChanged(true);
|
||||
}
|
||||
} else {
|
||||
// if (wasConnected) {
|
||||
emit stateChanged(false);
|
||||
// }
|
||||
break;
|
||||
case Failed:
|
||||
emit stateChanged(false);
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
if (host.startsWith('/')) {
|
||||
emit error(i18n("Connection to %1 failed", host), true);
|
||||
} else {
|
||||
emit error(i18nc("Connection to host:port", "Connection to %1:%2 failed", host, QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#else
|
||||
if (host.startsWith('/')) {
|
||||
emit error(tr("Connection to %1 failed").arg(host), true);
|
||||
} else {
|
||||
emit error(tr("Connection to %1:%2 failed").arg(host).arg(QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case IncorrectPassword:
|
||||
emit stateChanged(false);
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
if (host.startsWith('/')) {
|
||||
emit error(i18n("Connection to %1 failed - incorrect password", host), true);
|
||||
} else {
|
||||
emit error(i18nc("Connection to host:port", "Connection to %1:%2 failed - incorrect password", host, QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#else
|
||||
if (host.startsWith('/')) {
|
||||
emit error(tr("Connection to %1 failed - incorrect password").arg(host), true);
|
||||
} else {
|
||||
emit error(tr("Connection to %1:%2 failed - incorrect password").arg(host).arg(QString::number(MPDConnection::self()->getPort())), true);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,7 +346,7 @@ MPDConnection::Response MPDConnection::sendCommand(const QByteArray &command, bo
|
||||
|
||||
if (QAbstractSocket::ConnectedState!=sock.state()) {
|
||||
sock.close();
|
||||
if (!connectToMPD(sock)) {
|
||||
if (Success!=connectToMPD(sock)) {
|
||||
// Failed to connect, so close *both* sockets!
|
||||
disconnectFromMPD();
|
||||
emit stateChanged(false);
|
||||
@@ -776,7 +808,7 @@ void MPDConnection::onSocketStateChanged(QAbstractSocket::SocketState socketStat
|
||||
idleSocket.disconnectFromHost();
|
||||
}
|
||||
idleSocket.close();
|
||||
if (wasConnected && !connectToMPD(idleSocket, true)) {
|
||||
if (wasConnected && Success!=connectToMPD(idleSocket, true)) {
|
||||
// Failed to connect idle socket - so close *both*
|
||||
disconnectFromMPD();
|
||||
emit stateChanged(false);
|
||||
@@ -802,7 +834,7 @@ void MPDConnection::parseIdleReturn(const QByteArray &data)
|
||||
} else {
|
||||
DBUG << "idle failed? reconnect";
|
||||
idleSocket.close();
|
||||
if (!connectToMPD(idleSocket, true)) {
|
||||
if (Success!=connectToMPD(idleSocket, true)) {
|
||||
// Failed to connect idle socket - so close *both*
|
||||
disconnectFromMPD();
|
||||
emit stateChanged(false);
|
||||
|
||||
@@ -212,6 +212,7 @@ public Q_SLOTS:
|
||||
|
||||
Q_SIGNALS:
|
||||
void stateChanged(bool connected);
|
||||
void passwordError();
|
||||
void currentSongUpdated(const Song &song);
|
||||
void playlistUpdated(const QList<Song> &songs);
|
||||
void statsUpdated(const MPDStats &stats);
|
||||
@@ -234,7 +235,7 @@ Q_SIGNALS:
|
||||
void updatedLibrary();
|
||||
void updatingFileList();
|
||||
void updatedFileList();
|
||||
void error(const QString &err);
|
||||
void error(const QString &err, bool showActions=false);
|
||||
void urlHandlers(const QStringList &handlers);
|
||||
|
||||
private Q_SLOTS:
|
||||
@@ -242,9 +243,16 @@ private Q_SLOTS:
|
||||
void onSocketStateChanged(QAbstractSocket::SocketState socketState);
|
||||
|
||||
private:
|
||||
bool connectToMPD();
|
||||
enum ConnectionReturn
|
||||
{
|
||||
Success,
|
||||
Failed,
|
||||
IncorrectPassword
|
||||
};
|
||||
|
||||
ConnectionReturn connectToMPD();
|
||||
void disconnectFromMPD();
|
||||
bool connectToMPD(MpdSocket &socket, bool enableIdle=false);
|
||||
ConnectionReturn connectToMPD(MpdSocket &socket, bool enableIdle=false);
|
||||
Response sendCommand(const QByteArray &command, bool emitErrors=true, bool retry=true);
|
||||
void initialize();
|
||||
void parseIdleReturn(const QByteArray &data);
|
||||
|
||||
Reference in New Issue
Block a user