Detect last.fm login failures properly. Fixes issue 3426

This commit is contained in:
David Sansome 2013-02-06 00:12:39 +11:00
parent 1208ba308f
commit 65c077e34f
5 changed files with 18 additions and 7 deletions

View File

@ -82,6 +82,11 @@ bool ParseQuery(const QByteArray& data, XmlQuery* query, bool* connection_proble
*connection_problems = false;
}
// Check for app errors.
if (QDomElement(*query).attribute("status") == "failed") {
return false;
}
return true;
}

View File

@ -327,7 +327,7 @@ void LastFMService::AuthenticateReplyFinished(QNetworkReply* reply) {
settings.setValue("Session", lastfm::ws::SessionKey);
settings.setValue("Subscriber", is_subscriber);
} else {
emit AuthenticationComplete(false);
emit AuthenticationComplete(false, lfm["error"].text().trimmed());
return;
}
@ -335,7 +335,7 @@ void LastFMService::AuthenticateReplyFinished(QNetworkReply* reply) {
delete scrobbler_;
scrobbler_ = NULL;
emit AuthenticationComplete(true);
emit AuthenticationComplete(true, QString());
}
void LastFMService::UpdateSubscriberStatus() {

View File

@ -127,7 +127,7 @@ class LastFMService : public InternetService {
void ToggleScrobbling();
signals:
void AuthenticationComplete(bool success);
void AuthenticationComplete(bool success, const QString& error_message);
void ScrobblingEnabledChanged(bool value);
void ButtonVisibilityChanged(bool value);
void ScrobbleButtonVisibilityChanged(bool value);

View File

@ -38,7 +38,8 @@ LastFMSettingsPage::LastFMSettingsPage(SettingsDialog* dialog)
// Icons
setWindowIcon(QIcon(":/last.fm/as.png"));
connect(service_, SIGNAL(AuthenticationComplete(bool)), SLOT(AuthenticationComplete(bool)));
connect(service_, SIGNAL(AuthenticationComplete(bool,QString)),
SLOT(AuthenticationComplete(bool,QString)));
connect(service_, SIGNAL(UpdatedSubscriberStatus(bool)), SLOT(UpdatedSubscriberStatus(bool)));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout()));
connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(Login()));
@ -63,7 +64,8 @@ void LastFMSettingsPage::Login() {
service_->Authenticate(ui_->username->text(), ui_->password->text());
}
void LastFMSettingsPage::AuthenticationComplete(bool success) {
void LastFMSettingsPage::AuthenticationComplete(bool success,
const QString& message) {
if (!waiting_for_auth_)
return; // Wasn't us that was waiting for auth
@ -75,7 +77,11 @@ void LastFMSettingsPage::AuthenticationComplete(bool success) {
// Save settings
Save();
} else {
QMessageBox::warning(this, tr("Authentication failed"), tr("Your Last.fm credentials were incorrect"));
QString dialog_text = tr("Your Last.fm credentials were incorrect");
if (!message.isEmpty()) {
dialog_text = message;
}
QMessageBox::warning(this, tr("Authentication failed"), dialog_text);
}
RefreshControls(success);

View File

@ -35,7 +35,7 @@ public:
private slots:
void Login();
void AuthenticationComplete(bool success);
void AuthenticationComplete(bool success, const QString& error_message);
void Logout();
void UpdatedSubscriberStatus(bool is_subscriber);