Fix some minor code bugs in deezer

This commit is contained in:
Jonas Kvinge 2018-10-16 21:30:27 +02:00
parent 6d269e1786
commit 4156e26f76
2 changed files with 14 additions and 4 deletions

View File

@ -141,6 +141,14 @@ void DeezerService::LoadAccessToken() {
} }
void DeezerService::Logout() { void DeezerService::Logout() {
access_token_.clear();
QSettings s;
s.beginGroup(DeezerSettingsPage::kSettingsGroup);
s.remove("access_token");
s.remove("expiry_time");
s.endGroup();
} }
void DeezerService::StartAuthorisation() { void DeezerService::StartAuthorisation() {
@ -300,7 +308,7 @@ QByteArray DeezerService::GetReplyData(QNetworkReply *reply) {
if (json_value_error.isObject()) { if (json_value_error.isObject()) {
QJsonObject json_error = json_value_error.toObject(); QJsonObject json_error = json_value_error.toObject();
int code = json_error["code"].toInt(); int code = json_error["code"].toInt();
if (code == 300) access_token_.clear(); if (code == 300) Logout();
QString message = json_error["message"].toString(); QString message = json_error["message"].toString();
QString type = json_error["type"].toString(); QString type = json_error["type"].toString();
failure_reason = QString("%1 (%2)").arg(message).arg(code); failure_reason = QString("%1 (%2)").arg(message).arg(code);
@ -380,7 +388,7 @@ QJsonValue DeezerService::ExtractData(QByteArray &data) {
} }
QJsonObject json_error = json_value_error.toObject(); QJsonObject json_error = json_value_error.toObject();
int code = json_error["code"].toInt(); int code = json_error["code"].toInt();
if (code == 300) access_token_.clear(); if (code == 300) Logout();
QString message = json_error["message"].toString(); QString message = json_error["message"].toString();
QString type = json_error["type"].toString(); QString type = json_error["type"].toString();
Error(QString("%1 (%2)").arg(message).arg(code)); Error(QString("%1 (%2)").arg(message).arg(code));
@ -635,6 +643,7 @@ void DeezerService::GetAlbumFinished(QNetworkReply *reply, int search_id, int al
QByteArray data = GetReplyData(reply); QByteArray data = GetReplyData(reply);
if (data.isEmpty()) { if (data.isEmpty()) {
delete requests_album_.take(album_ctx->id);
CheckFinish(); CheckFinish();
return; return;
} }
@ -808,7 +817,7 @@ void DeezerService::CheckFinish() {
void DeezerService::Error(QString error, QVariant debug) { void DeezerService::Error(QString error, QVariant debug) {
qLog(Error) << "Deezer:" << error; qLog(Error) << "Deezer:" << error;
if (!debug.isValid()) qLog(Debug) << debug; if (debug.isValid()) qLog(Debug) << debug;
if (search_id_ != 0) { if (search_id_ != 0) {
if (!error.isEmpty()) { if (!error.isEmpty()) {
search_error_ += error; search_error_ += error;

View File

@ -87,6 +87,7 @@ void DeezerSettingsPage::Load() {
s.endGroup(); s.endGroup();
if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn); if (service_->authenticated()) ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedIn);
else ui_->login_state->SetLoggedIn(LoginStateWidget::LoggedOut);
} }