Fix Tidal authentication
This commit is contained in:
parent
e5e6cbf6e4
commit
f9379961e9
|
@ -45,6 +45,8 @@ TidalSettingsPage::TidalSettingsPage(SettingsDialog *parent)
|
||||||
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
|
connect(ui_->button_login, SIGNAL(clicked()), SLOT(LoginClicked()));
|
||||||
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
|
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(LogoutClicked()));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(Login(QString, QString, int)), service_, SLOT(SendLogin(QString, QString, int)));
|
||||||
|
|
||||||
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
|
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
|
||||||
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
|
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
|
||||||
|
|
||||||
|
@ -109,7 +111,7 @@ void TidalSettingsPage::Save() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TidalSettingsPage::LoginClicked() {
|
void TidalSettingsPage::LoginClicked() {
|
||||||
service_->Login(ui_->username->text(), ui_->password->text());
|
emit Login(ui_->username->text(), ui_->password->text());
|
||||||
ui_->button_login->setEnabled(false);
|
ui_->button_login->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ class TidalSettingsPage : public SettingsPage {
|
||||||
|
|
||||||
bool eventFilter(QObject *object, QEvent *event);
|
bool eventFilter(QObject *object, QEvent *event);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void Login(const QString &username, const QString &password, const int search_id = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void LoginClicked();
|
void LoginClicked();
|
||||||
void LogoutClicked();
|
void LogoutClicked();
|
||||||
|
|
|
@ -78,6 +78,9 @@ TidalService::TidalService(Application *app, InternetModel *parent)
|
||||||
timer_searchdelay_->setSingleShot(true);
|
timer_searchdelay_->setSingleShot(true);
|
||||||
connect(timer_searchdelay_, SIGNAL(timeout()), SLOT(StartSearch()));
|
connect(timer_searchdelay_, SIGNAL(timeout()), SLOT(StartSearch()));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(Login(int)), SLOT(SendLogin(int)));
|
||||||
|
connect(this, SIGNAL(Login(QString, QString, int)), SLOT(SendLogin(QString, QString, int)));
|
||||||
|
|
||||||
ReloadSettings();
|
ReloadSettings();
|
||||||
LoadSessionID();
|
LoadSessionID();
|
||||||
|
|
||||||
|
@ -117,7 +120,11 @@ void TidalService::LoadSessionID() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TidalService::Login(const QString &username, const QString &password, int search_id) {
|
void TidalService::SendLogin(const int search_id) {
|
||||||
|
SendLogin(username_, password_, search_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TidalService::SendLogin(const QString &username, const QString &password, const int search_id) {
|
||||||
|
|
||||||
if (search_id != 0) emit UpdateStatus("Authenticating...");
|
if (search_id != 0) emit UpdateStatus("Authenticating...");
|
||||||
|
|
||||||
|
@ -296,7 +303,7 @@ QNetworkReply *TidalService::CreateRequest(const QString &ressource_name, const
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject TidalService::ExtractJsonObj(QNetworkReply *reply) {
|
QJsonObject TidalService::ExtractJsonObj(QNetworkReply *reply, bool sendlogin) {
|
||||||
|
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
|
||||||
|
@ -331,11 +338,11 @@ QJsonObject TidalService::ExtractJsonObj(QNetworkReply *reply) {
|
||||||
if (reply->error() == QNetworkReply::ContentAccessDenied || reply->error() == QNetworkReply::ContentOperationNotPermittedError || reply->error() == QNetworkReply::AuthenticationRequiredError) {
|
if (reply->error() == QNetworkReply::ContentAccessDenied || reply->error() == QNetworkReply::ContentOperationNotPermittedError || reply->error() == QNetworkReply::AuthenticationRequiredError) {
|
||||||
// Session is probably expired, attempt to login once
|
// Session is probably expired, attempt to login once
|
||||||
Logout();
|
Logout();
|
||||||
if (login_attempts_ < 1 && !username_.isEmpty() && !password_.isEmpty()) {
|
if (sendlogin && login_attempts_ < 1 && !username_.isEmpty() && !password_.isEmpty()) {
|
||||||
qLog(Error) << "Tidal:" << failure_reason;
|
qLog(Error) << "Tidal:" << failure_reason;
|
||||||
qLog(Error) << "Tidal:" << QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
qLog(Error) << "Tidal:" << QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||||
qLog(Error) << "Tidal:" << "Attempting to login.";
|
qLog(Error) << "Tidal:" << "Attempting to login.";
|
||||||
Login(username_, password_);
|
emit Login(search_id_);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Error(failure_reason);
|
Error(failure_reason);
|
||||||
|
@ -381,9 +388,9 @@ QJsonObject TidalService::ExtractJsonObj(QNetworkReply *reply) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray TidalService::ExtractItems(QNetworkReply *reply) {
|
QJsonArray TidalService::ExtractItems(QNetworkReply *reply, bool sendlogin) {
|
||||||
|
|
||||||
QJsonObject json_obj = ExtractJsonObj(reply);
|
QJsonObject json_obj = ExtractJsonObj(reply, sendlogin);
|
||||||
if (json_obj.isEmpty()) return QJsonArray();
|
if (json_obj.isEmpty()) return QJsonArray();
|
||||||
|
|
||||||
if (!json_obj.contains("items")) {
|
if (!json_obj.contains("items")) {
|
||||||
|
@ -485,7 +492,7 @@ void TidalService::SearchFinished(QNetworkReply *reply, int id) {
|
||||||
|
|
||||||
if (id != search_id_) return;
|
if (id != search_id_) return;
|
||||||
|
|
||||||
QJsonArray json_items = ExtractItems(reply);
|
QJsonArray json_items = ExtractItems(reply, true);
|
||||||
if (json_items.isEmpty()) {
|
if (json_items.isEmpty()) {
|
||||||
CheckFinish();
|
CheckFinish();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -52,7 +52,6 @@ class TidalService : public InternetService {
|
||||||
|
|
||||||
void ReloadSettings();
|
void ReloadSettings();
|
||||||
|
|
||||||
void Login(const QString &username, const QString &password, int search_id = 0);
|
|
||||||
void Logout();
|
void Logout();
|
||||||
int Search(const QString &query, TidalSettingsPage::SearchBy searchby);
|
int Search(const QString &query, TidalSettingsPage::SearchBy searchby);
|
||||||
void CancelSearch();
|
void CancelSearch();
|
||||||
|
@ -61,6 +60,8 @@ class TidalService : public InternetService {
|
||||||
const bool authenticated() { return (!session_id_.isEmpty() && !country_code_.isEmpty()); }
|
const bool authenticated() { return (!session_id_.isEmpty() && !country_code_.isEmpty()); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void Login(const int search_id = 0);
|
||||||
|
void Login(const QString &username, const QString &password, const int search_id = 0);
|
||||||
void LoginSuccess();
|
void LoginSuccess();
|
||||||
void LoginFailure(QString failure_reason);
|
void LoginFailure(QString failure_reason);
|
||||||
void SearchResults(int id, SongList songs);
|
void SearchResults(int id, SongList songs);
|
||||||
|
@ -71,8 +72,10 @@ class TidalService : public InternetService {
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ShowConfig();
|
void ShowConfig();
|
||||||
|
void SendLogin(const QString &username, const QString &password, const int search_id = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void SendLogin(const int search_id = 0);
|
||||||
void HandleAuthReply(QNetworkReply *reply, int search_id);
|
void HandleAuthReply(QNetworkReply *reply, int search_id);
|
||||||
void StartSearch();
|
void StartSearch();
|
||||||
void SearchFinished(QNetworkReply *reply, int search_id);
|
void SearchFinished(QNetworkReply *reply, int search_id);
|
||||||
|
@ -83,8 +86,8 @@ class TidalService : public InternetService {
|
||||||
void ClearSearch();
|
void ClearSearch();
|
||||||
void LoadSessionID();
|
void LoadSessionID();
|
||||||
QNetworkReply *CreateRequest(const QString &ressource_name, const QList<QPair<QString, QString>> ¶ms);
|
QNetworkReply *CreateRequest(const QString &ressource_name, const QList<QPair<QString, QString>> ¶ms);
|
||||||
QJsonObject ExtractJsonObj(QNetworkReply *reply);
|
QJsonObject ExtractJsonObj(QNetworkReply *reply, bool sendlogin = false);
|
||||||
QJsonArray ExtractItems(QNetworkReply *reply);
|
QJsonArray ExtractItems(QNetworkReply *reply, bool sendlogin = false);
|
||||||
void SendSearch();
|
void SendSearch();
|
||||||
void GetAlbum(const int album_id);
|
void GetAlbum(const int album_id);
|
||||||
Song ParseSong(const int album_id_requested, const QJsonValue &value);
|
Song ParseSong(const int album_id_requested, const QJsonValue &value);
|
||||||
|
|
Loading…
Reference in New Issue