Validate configuration better
This commit is contained in:
parent
8b6fd3d594
commit
e1de110dd7
|
@ -80,12 +80,12 @@ class InternetService : public QObject {
|
|||
void Login(const QString &username, const QString &password, const QString &token);
|
||||
void Login(const QString &hostname, const int, const QString &username, const QString &password);
|
||||
void LoginSuccess();
|
||||
void LoginFailure(QString failure_reason);
|
||||
void LoginComplete(bool success, QString error = QString());
|
||||
void LoginFailure(const QString &failure_reason);
|
||||
void LoginComplete(const bool success, QString error = QString());
|
||||
|
||||
void TestSuccess();
|
||||
void TestFailure(QString failure_reason);
|
||||
void TestComplete(bool success, QString error = QString());
|
||||
void TestFailure(const QString &failure_reason);
|
||||
void TestComplete(const bool success, QString error = QString());
|
||||
|
||||
void Error(const QString &error);
|
||||
void Results(const SongList &songs, const QString &error);
|
||||
|
@ -121,7 +121,7 @@ class InternetService : public QObject {
|
|||
void RemoveAlbums(const SongList& songs);
|
||||
void RemoveSongs(const SongList& songs);
|
||||
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
void StreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType &filetype, const QString &error = QString());
|
||||
|
||||
protected:
|
||||
Application *app_;
|
||||
|
|
|
@ -88,7 +88,7 @@ class QobuzBaseRequest : public QObject {
|
|||
int albumssearchlimit() { return service_->albumssearchlimit(); }
|
||||
int songssearchlimit() { return service_->songssearchlimit(); }
|
||||
|
||||
QString access_token() { return service_->access_token(); }
|
||||
QString user_auth_token() { return service_->user_auth_token(); }
|
||||
|
||||
bool authenticated() { return service_->authenticated(); }
|
||||
bool login_sent() { return service_->login_sent(); }
|
||||
|
|
|
@ -129,7 +129,7 @@ void QobuzFavoriteRequest::AddFavorites(const FavoriteType type, const SongList
|
|||
typedef QList<EncodedParam> EncodedParamList;
|
||||
|
||||
ParamList params = ParamList() << Param("app_id", app_id())
|
||||
<< Param("user_auth_token", access_token())
|
||||
<< Param("user_auth_token", user_auth_token())
|
||||
<< Param(text, ids);
|
||||
|
||||
QUrlQuery url_query;
|
||||
|
@ -233,7 +233,7 @@ void QobuzFavoriteRequest::RemoveFavorites(const FavoriteType type, const SongLi
|
|||
QString ids = ids_list.join(',');
|
||||
|
||||
ParamList params = ParamList() << Param("app_id", app_id())
|
||||
<< Param("user_auth_token", access_token())
|
||||
<< Param("user_auth_token", user_auth_token())
|
||||
<< Param(text, ids);
|
||||
|
||||
QUrlQuery url_query;
|
||||
|
|
|
@ -143,7 +143,7 @@ void QobuzRequest::FlushArtistsRequests() {
|
|||
ParamList params;
|
||||
if (type_ == QueryType_Artists) {
|
||||
params << Param("type", "artists");
|
||||
params << Param("user_auth_token", access_token());
|
||||
params << Param("user_auth_token", user_auth_token());
|
||||
}
|
||||
else if (type_ == QueryType_SearchArtists) params << Param("query", search_text_);
|
||||
if (request.limit > 0) params << Param("limit", QString::number(request.limit));
|
||||
|
@ -190,7 +190,7 @@ void QobuzRequest::FlushAlbumsRequests() {
|
|||
ParamList params;
|
||||
if (type_ == QueryType_Albums) {
|
||||
params << Param("type", "albums");
|
||||
params << Param("user_auth_token", access_token());
|
||||
params << Param("user_auth_token", user_auth_token());
|
||||
}
|
||||
else if (type_ == QueryType_SearchAlbums) params << Param("query", search_text_);
|
||||
if (request.limit > 0) params << Param("limit", QString::number(request.limit));
|
||||
|
@ -237,7 +237,7 @@ void QobuzRequest::FlushSongsRequests() {
|
|||
ParamList params;
|
||||
if (type_ == QueryType_Songs) {
|
||||
params << Param("type", "tracks");
|
||||
params << Param("user_auth_token", access_token());
|
||||
params << Param("user_auth_token", user_auth_token());
|
||||
}
|
||||
else if (type_ == QueryType_SearchSongs) params << Param("query", search_text_);
|
||||
if (request.limit > 0) params << Param("limit", QString::number(request.limit));
|
||||
|
|
|
@ -207,7 +207,7 @@ void QobuzService::ReloadSettings() {
|
|||
songssearchlimit_ = s.value("songssearchlimit", 100).toInt();
|
||||
cache_album_covers_ = s.value("cachealbumcovers", true).toBool();
|
||||
|
||||
access_token_ = s.value("access_token").toString();
|
||||
user_auth_token_ = s.value("user_auth_token").toString();
|
||||
|
||||
s.endGroup();
|
||||
|
||||
|
@ -325,14 +325,14 @@ void QobuzService::HandleAuthReply(QNetworkReply *reply) {
|
|||
return;
|
||||
}
|
||||
|
||||
access_token_ = json_obj["user_auth_token"].toString();
|
||||
user_auth_token_ = json_obj["user_auth_token"].toString();
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(QobuzSettingsPage::kSettingsGroup);
|
||||
s.setValue("access_token", access_token_);
|
||||
s.setValue("user_auth_token", user_auth_token_);
|
||||
s.endGroup();
|
||||
|
||||
qLog(Debug) << "Qobuz: Login successful" << "access token" << access_token_;
|
||||
qLog(Debug) << "Qobuz: Login successful" << "user auth token" << user_auth_token_;
|
||||
|
||||
login_attempts_ = 0;
|
||||
if (timer_login_attempt_->isActive()) timer_login_attempt_->stop();
|
||||
|
@ -344,7 +344,7 @@ void QobuzService::HandleAuthReply(QNetworkReply *reply) {
|
|||
|
||||
void QobuzService::Logout() {
|
||||
|
||||
access_token_.clear();
|
||||
user_auth_token_.clear();
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(QobuzSettingsPage::kSettingsGroup);
|
||||
|
@ -362,19 +362,19 @@ void QobuzService::TryLogin() {
|
|||
if (authenticated() || login_sent_) return;
|
||||
|
||||
if (login_attempts_ >= kLoginAttempts) {
|
||||
emit LoginComplete(false, "Maximum number of login attempts reached.");
|
||||
emit LoginComplete(false, tr("Maximum number of login attempts reached."));
|
||||
return;
|
||||
}
|
||||
if (app_id_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Qobuz app ID.");
|
||||
emit LoginComplete(false, tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
if (username_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Qobuz username.");
|
||||
emit LoginComplete(false, tr("Missing Qobuz username."));
|
||||
return;
|
||||
}
|
||||
if (password_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Qobuz password.");
|
||||
emit LoginComplete(false, tr("Missing Qobuz password."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -394,6 +394,16 @@ void QobuzService::ResetArtistsRequest() {
|
|||
|
||||
void QobuzService::GetArtists() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit ArtistsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit ArtistsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
ResetArtistsRequest();
|
||||
|
||||
artists_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Artists, this));
|
||||
|
@ -435,6 +445,16 @@ void QobuzService::ResetAlbumsRequest() {
|
|||
|
||||
void QobuzService::GetAlbums() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit AlbumsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit AlbumsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
ResetAlbumsRequest();
|
||||
albums_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Albums, this));
|
||||
connect(albums_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(AlbumsResultsReceived(const int, const SongList&, const QString&)));
|
||||
|
@ -474,6 +494,16 @@ void QobuzService::ResetSongsRequest() {
|
|||
|
||||
void QobuzService::GetSongs() {
|
||||
|
||||
if (app_id().isEmpty()) {
|
||||
emit SongsResults(SongList(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticated()) {
|
||||
emit SongsResults(SongList(), tr("Not authenticated with Qobuz."));
|
||||
return;
|
||||
}
|
||||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new QobuzRequest(this, url_handler_, network_, QobuzBaseRequest::QueryType_Songs, this));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SongsResultsReceived(const int, const SongList&, const QString&)));
|
||||
|
@ -522,16 +552,14 @@ int QobuzService::Search(const QString &text, InternetSearch::SearchType type) {
|
|||
|
||||
void QobuzService::StartSearch() {
|
||||
|
||||
if (app_id_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Not authenticated."));
|
||||
next_pending_search_id_ = 1;
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
search_id_ = pending_search_id_;
|
||||
search_text_ = pending_search_text_;
|
||||
|
||||
if (app_id_.isEmpty()) { // App ID is the only thing needed to search.
|
||||
emit SearchResults(search_id_, SongList(), tr("Missing Qobuz app ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
SendSearch();
|
||||
|
||||
}
|
||||
|
@ -576,17 +604,23 @@ void QobuzService::SearchResultsReceived(const int id, const SongList &songs, co
|
|||
|
||||
void QobuzService::GetStreamURL(const QUrl &url) {
|
||||
|
||||
if (app_id().isEmpty() || app_secret().isEmpty()) { // Don't check for login here, because we allow automatic login.
|
||||
emit StreamURLFinished(url, url, Song::FileType_Stream, tr("Missing Qobuz app ID or secret."));
|
||||
return;
|
||||
}
|
||||
|
||||
QobuzStreamURLRequest *stream_url_req = new QobuzStreamURLRequest(this, network_, url, this);
|
||||
stream_url_requests_ << stream_url_req;
|
||||
|
||||
connect(stream_url_req, SIGNAL(TryLogin()), this, SLOT(TryLogin()));
|
||||
connect(stream_url_req, SIGNAL(StreamURLFinished(QUrl, QUrl, Song::FileType, QString)), this, SLOT(HandleStreamURLFinished(QUrl, QUrl, Song::FileType, QString)));
|
||||
connect(stream_url_req, SIGNAL(StreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, QString)), this, SLOT(HandleStreamURLFinished(const QUrl&, const QUrl&, const Song::FileType&, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, QString)), stream_url_req, SLOT(LoginComplete(const bool, QString)));
|
||||
|
||||
stream_url_req->Process();
|
||||
|
||||
}
|
||||
|
||||
void QobuzService::HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error) {
|
||||
void QobuzService::HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error) {
|
||||
|
||||
QobuzStreamURLRequest *stream_url_req = qobject_cast<QobuzStreamURLRequest*>(sender());
|
||||
if (!stream_url_req || !stream_url_requests_.contains(stream_url_req)) return;
|
||||
|
|
|
@ -80,9 +80,9 @@ class QobuzService : public InternetService {
|
|||
int songssearchlimit() { return songssearchlimit_; }
|
||||
bool cache_album_covers() { return cache_album_covers_; }
|
||||
|
||||
QString access_token() { return access_token_; }
|
||||
QString user_auth_token() { return user_auth_token_; }
|
||||
|
||||
const bool authenticated() { return (!app_id_.isEmpty() && !app_secret_.isEmpty() && !access_token_.isEmpty()); }
|
||||
const bool authenticated() { return (!app_id_.isEmpty() && !app_secret_.isEmpty() && !user_auth_token_.isEmpty()); }
|
||||
const bool login_sent() { return login_sent_; }
|
||||
const bool login_attempts() { return login_attempts_; }
|
||||
|
||||
|
@ -114,7 +114,7 @@ class QobuzService : public InternetService {
|
|||
public slots:
|
||||
void ShowConfig();
|
||||
void TryLogin();
|
||||
void SendLogin(const QString &username, const QString &password, const QString &token);
|
||||
void SendLogin(const QString &app_id, const QString &username, const QString &password);
|
||||
void GetArtists();
|
||||
void GetAlbums();
|
||||
void GetSongs();
|
||||
|
@ -140,7 +140,7 @@ class QobuzService : public InternetService {
|
|||
void ArtistsUpdateProgressReceived(const int id, const int progress);
|
||||
void AlbumsUpdateProgressReceived(const int id, const int progress);
|
||||
void SongsUpdateProgressReceived(const int id, const int progress);
|
||||
void HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
void HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
|
@ -200,7 +200,7 @@ class QobuzService : public InternetService {
|
|||
int songssearchlimit_;
|
||||
bool cache_album_covers_;
|
||||
|
||||
QString access_token_;
|
||||
QString user_auth_token_;
|
||||
|
||||
int pending_search_id_;
|
||||
int next_pending_search_id_;
|
||||
|
|
|
@ -77,7 +77,7 @@ void QobuzStreamURLRequest::LoginComplete(bool success, QString error) {
|
|||
void QobuzStreamURLRequest::Process() {
|
||||
|
||||
if (app_id().isEmpty() || app_secret().isEmpty()) {
|
||||
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, tr("Missing app ID or secret."));
|
||||
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, tr("Missing Qobuz app ID or secret."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ void QobuzStreamURLRequest::GetStreamURL() {
|
|||
ParamList params = params_to_sign;
|
||||
params << Param("request_ts", QString::number(timestamp));
|
||||
params << Param("request_sig", signature);
|
||||
params << Param("user_auth_token", access_token());
|
||||
params << Param("user_auth_token", user_auth_token());
|
||||
|
||||
std::sort(params.begin(), params.end());
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class QobuzStreamURLRequest : public QobuzBaseRequest {
|
|||
|
||||
signals:
|
||||
void TryLogin();
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
void StreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private slots:
|
||||
void LoginComplete(bool success, QString error = QString());
|
||||
|
|
|
@ -48,9 +48,9 @@ TidalSettingsPage::TidalSettingsPage(SettingsDialog *parent)
|
|||
connect(ui_->oauth, SIGNAL(toggled(bool)), SLOT(OAuthClicked(bool)));
|
||||
|
||||
connect(this, SIGNAL(Login()), service_, SLOT(StartAuthorisation()));
|
||||
connect(this, SIGNAL(Login(QString, QString, QString)), service_, SLOT(SendLogin(QString, QString, QString)));
|
||||
connect(this, SIGNAL(Login(const QString&, const QString&, const QString&)), service_, SLOT(SendLogin(const QString&, const QString&, const QString&)));
|
||||
|
||||
connect(service_, SIGNAL(LoginFailure(QString)), SLOT(LoginFailure(QString)));
|
||||
connect(service_, SIGNAL(LoginFailure(const QString&)), SLOT(LoginFailure(const QString&)));
|
||||
connect(service_, SIGNAL(LoginSuccess()), SLOT(LoginSuccess()));
|
||||
|
||||
dialog()->installEventFilter(this);
|
||||
|
@ -152,7 +152,7 @@ void TidalSettingsPage::LoginClicked() {
|
|||
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing username or password."));
|
||||
return;
|
||||
}
|
||||
emit Login(ui_->username->text(), ui_->password->text(), ui_->api_token->text());
|
||||
emit Login(ui_->api_token->text(), ui_->username->text(), ui_->password->text());
|
||||
}
|
||||
ui_->button_login->setEnabled(false);
|
||||
|
||||
|
@ -169,7 +169,7 @@ bool TidalSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
|||
|
||||
}
|
||||
|
||||
void TidalSettingsPage::OAuthClicked(bool enabled) {
|
||||
void TidalSettingsPage::OAuthClicked(const bool enabled) {
|
||||
|
||||
ui_->client_id->setEnabled(enabled);
|
||||
ui_->api_token->setEnabled(!enabled);
|
||||
|
@ -190,7 +190,7 @@ void TidalSettingsPage::LoginSuccess() {
|
|||
ui_->button_login->setEnabled(true);
|
||||
}
|
||||
|
||||
void TidalSettingsPage::LoginFailure(QString failure_reason) {
|
||||
void TidalSettingsPage::LoginFailure(const QString &failure_reason) {
|
||||
if (!this->isVisible()) return;
|
||||
QMessageBox::warning(this, tr("Authentication failed"), failure_reason);
|
||||
ui_->button_login->setEnabled(true);
|
||||
|
|
|
@ -51,14 +51,14 @@ class TidalSettingsPage : public SettingsPage {
|
|||
|
||||
signals:
|
||||
void Login();
|
||||
void Login(const QString &username, const QString &password, const QString &token);
|
||||
void Login(const QString &api_token, const QString &username, const QString &password);
|
||||
|
||||
private slots:
|
||||
void OAuthClicked(bool enabled);
|
||||
void OAuthClicked(const bool enabled);
|
||||
void LoginClicked();
|
||||
void LogoutClicked();
|
||||
void LoginSuccess();
|
||||
void LoginFailure(QString failure_reason);
|
||||
void LoginFailure(const QString &failure_reason);
|
||||
|
||||
private:
|
||||
Ui_TidalSettingsPage* ui_;
|
||||
|
|
|
@ -319,6 +319,16 @@ void SubsonicService::ResetSongsRequest() {
|
|||
|
||||
void SubsonicService::GetSongs() {
|
||||
|
||||
if (!server_url().isValid()) {
|
||||
emit SongsResults(SongList(), tr("Server URL is invalid."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (username().isEmpty() || password().isEmpty()) {
|
||||
emit SongsResults(SongList(), tr("Missing username or password."));
|
||||
return;
|
||||
}
|
||||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new SubsonicRequest(this, url_handler_, network_, this));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const SongList&, const QString&)), SLOT(SongsResultsReceived(const SongList&, const QString&)));
|
||||
|
|
|
@ -31,6 +31,14 @@ SubsonicUrlHandler::SubsonicUrlHandler(Application *app, SubsonicService *servic
|
|||
|
||||
UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
||||
|
||||
if (!server_url().isValid()) {
|
||||
return LoadResult(url, LoadResult::Error, url, Song::FileType_Stream, -1, tr("Subsonic server URL is invalid."));
|
||||
}
|
||||
|
||||
if (username().isEmpty() || password().isEmpty()) {
|
||||
return LoadResult(url, LoadResult::Error, url, Song::FileType_Stream, -1, tr("Missing Subsonic username or password."));
|
||||
}
|
||||
|
||||
ParamList params = ParamList() << Param("c", service_->client_name())
|
||||
<< Param("v", service_->api_version())
|
||||
<< Param("f", "json")
|
||||
|
|
|
@ -42,6 +42,9 @@ class SubsonicUrlHandler : public UrlHandler {
|
|||
|
||||
QString scheme() const { return service_->url_scheme(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
QString username() const { return service_->username(); }
|
||||
QString password() const { return service_->password(); }
|
||||
|
||||
LoadResult StartLoading(const QUrl &url);
|
||||
|
||||
private:
|
||||
|
|
|
@ -85,7 +85,7 @@ TidalRequest::~TidalRequest() {
|
|||
|
||||
}
|
||||
|
||||
void TidalRequest::LoginComplete(bool success, QString error) {
|
||||
void TidalRequest::LoginComplete(const bool success, QString error) {
|
||||
|
||||
if (!need_login_) return;
|
||||
need_login_ = false;
|
||||
|
|
|
@ -70,7 +70,7 @@ class TidalRequest : public TidalBaseRequest {
|
|||
void StreamURLFinished(const QUrl original_url, const QUrl url, const Song::FileType, QString error = QString());
|
||||
|
||||
private slots:
|
||||
void LoginComplete(bool success, QString error = QString());
|
||||
void LoginComplete(const bool success, QString error = QString());
|
||||
|
||||
void ArtistsReplyReceived(QNetworkReply *reply, const int limit_requested, const int offset_requested);
|
||||
|
||||
|
|
|
@ -447,10 +447,10 @@ void TidalService::AccessTokenRequestFinished(QNetworkReply *reply) {
|
|||
}
|
||||
|
||||
void TidalService::SendLogin() {
|
||||
SendLogin(username_, password_, api_token_);
|
||||
SendLogin(api_token_, username_, password_);
|
||||
}
|
||||
|
||||
void TidalService::SendLogin(const QString &username, const QString &password, const QString &token) {
|
||||
void TidalService::SendLogin(const QString &api_token, const QString &username, const QString &password) {
|
||||
|
||||
login_sent_ = true;
|
||||
++login_attempts_;
|
||||
|
@ -458,7 +458,7 @@ void TidalService::SendLogin(const QString &username, const QString &password, c
|
|||
timer_login_attempt_->setInterval(kTimeResetLoginAttempts);
|
||||
timer_login_attempt_->start();
|
||||
|
||||
const ParamList params = ParamList() << Param("token", (token.isEmpty() ? api_token_ : token))
|
||||
const ParamList params = ParamList() << Param("token", (api_token.isEmpty() ? api_token_ : api_token))
|
||||
<< Param("username", username)
|
||||
<< Param("password", password)
|
||||
<< Param("clientVersion", "2.2.1--7");
|
||||
|
@ -473,7 +473,7 @@ void TidalService::SendLogin(const QString &username, const QString &password, c
|
|||
QNetworkRequest req(url);
|
||||
|
||||
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
req.setRawHeader("X-Tidal-Token", (token.isEmpty() ? api_token_.toUtf8() : token.toUtf8()));
|
||||
req.setRawHeader("X-Tidal-Token", (api_token.isEmpty() ? api_token_.toUtf8() : api_token.toUtf8()));
|
||||
|
||||
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
|
||||
QNetworkReply *reply = network_->post(req, query);
|
||||
|
@ -600,20 +600,20 @@ void TidalService::TryLogin() {
|
|||
|
||||
if (authenticated() || login_sent_) return;
|
||||
|
||||
if (login_attempts_ >= kLoginAttempts) {
|
||||
emit LoginComplete(false, "Maximum number of login attempts reached.");
|
||||
return;
|
||||
}
|
||||
if (api_token_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Tidal API token.");
|
||||
emit LoginComplete(false, tr("Missing Tidal API token."));
|
||||
return;
|
||||
}
|
||||
if (username_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Tidal username.");
|
||||
emit LoginComplete(false, tr("Missing Tidal username."));
|
||||
return;
|
||||
}
|
||||
if (password_.isEmpty()) {
|
||||
emit LoginComplete(false, "Missing Tidal password.");
|
||||
emit LoginComplete(false, tr("Missing Tidal password."));
|
||||
return;
|
||||
}
|
||||
if (login_attempts_ >= kLoginAttempts) {
|
||||
emit LoginComplete(false, tr("Not authenticated with Tidal and reached maximum number of login attempts."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -633,6 +633,19 @@ void TidalService::ResetArtistsRequest() {
|
|||
|
||||
void TidalService::GetArtists() {
|
||||
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit ArtistsResults(SongList(), tr("Not authenticated with Tidal."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit ArtistsResults(SongList(), tr("Missing Tidal API token, username or passord."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ResetArtistsRequest();
|
||||
|
||||
artists_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Artists, this));
|
||||
|
@ -641,7 +654,7 @@ void TidalService::GetArtists() {
|
|||
connect(artists_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(ArtistsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(artists_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(ArtistsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(artists_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(ArtistsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), artists_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, QString)), artists_request_.get(), SLOT(LoginComplete(const bool, QString)));
|
||||
|
||||
artists_request_->Process();
|
||||
|
||||
|
@ -675,13 +688,26 @@ void TidalService::ResetAlbumsRequest() {
|
|||
|
||||
void TidalService::GetAlbums() {
|
||||
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit AlbumsResults(SongList(), tr("Not authenticated with Tidal."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit AlbumsResults(SongList(), tr("Missing Tidal API token, username or passord."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ResetAlbumsRequest();
|
||||
albums_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Albums, this));
|
||||
connect(albums_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(AlbumsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(AlbumsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(albums_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(AlbumsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(albums_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(AlbumsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), albums_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, const QString&)), albums_request_.get(), SLOT(LoginComplete(const bool, const QString&)));
|
||||
|
||||
albums_request_->Process();
|
||||
|
||||
|
@ -715,13 +741,26 @@ void TidalService::ResetSongsRequest() {
|
|||
|
||||
void TidalService::GetSongs() {
|
||||
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit SongsResults(SongList(), tr("Not authenticated with Tidal."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SongsResults(SongList(), tr("Missing Tidal API token, username or passord."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ResetSongsRequest();
|
||||
songs_request_.reset(new TidalRequest(this, url_handler_, network_, TidalBaseRequest::QueryType_Songs, this));
|
||||
connect(songs_request_.get(), SIGNAL(Results(const int, const SongList&, const QString&)), SLOT(SongsResultsReceived(const int, const SongList&, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SLOT(SongsUpdateStatusReceived(const int, const QString&)));
|
||||
connect(songs_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SLOT(SongsProgressSetMaximumReceived(const int, const int)));
|
||||
connect(songs_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SLOT(SongsUpdateProgressReceived(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), songs_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, const QString&)), songs_request_.get(), SLOT(LoginComplete(const bool, const QString&)));
|
||||
|
||||
songs_request_->Process();
|
||||
|
||||
|
@ -764,11 +803,17 @@ int TidalService::Search(const QString &text, InternetSearch::SearchType type) {
|
|||
|
||||
void TidalService::StartSearch() {
|
||||
|
||||
if ((oauth_ && !authenticated()) || api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Not authenticated."));
|
||||
next_pending_search_id_ = 1;
|
||||
ShowConfig();
|
||||
return;
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Not authenticated with Tidal."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit SearchResults(pending_search_id_, SongList(), tr("Missing Tidal API token, username or passord."));
|
||||
ShowConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
search_id_ = pending_search_id_;
|
||||
|
@ -806,7 +851,7 @@ void TidalService::SendSearch() {
|
|||
connect(search_request_.get(), SIGNAL(UpdateStatus(const int, const QString&)), SIGNAL(SearchUpdateStatus(const int, const QString&)));
|
||||
connect(search_request_.get(), SIGNAL(ProgressSetMaximum(const int, const int)), SIGNAL(SearchProgressSetMaximum(const int, const int)));
|
||||
connect(search_request_.get(), SIGNAL(UpdateProgress(const int, const int)), SIGNAL(SearchUpdateProgress(const int, const int)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), search_request_.get(), SLOT(LoginComplete(bool, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, const QString&)), search_request_.get(), SLOT(LoginComplete(const bool, const QString&)));
|
||||
|
||||
search_request_->Search(search_id_, search_text_);
|
||||
search_request_->Process();
|
||||
|
@ -819,18 +864,29 @@ void TidalService::SearchResultsReceived(const int id, const SongList &songs, co
|
|||
|
||||
void TidalService::GetStreamURL(const QUrl &url) {
|
||||
|
||||
if (!authenticated()) {
|
||||
if (oauth_) {
|
||||
emit StreamURLFinished(url, url, Song::FileType_Stream, tr("Not authenticated with Tidal."));
|
||||
return;
|
||||
}
|
||||
else if (api_token_.isEmpty() || username_.isEmpty() || password_.isEmpty()) {
|
||||
emit StreamURLFinished(url, url, Song::FileType_Stream, tr("Missing Tidal API token, username or passord."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TidalStreamURLRequest *stream_url_req = new TidalStreamURLRequest(this, network_, url, this);
|
||||
stream_url_requests_ << stream_url_req;
|
||||
|
||||
connect(stream_url_req, SIGNAL(TryLogin()), this, SLOT(TryLogin()));
|
||||
connect(stream_url_req, SIGNAL(StreamURLFinished(QUrl, QUrl, Song::FileType, QString)), this, SLOT(HandleStreamURLFinished(QUrl, QUrl, Song::FileType, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(bool, QString)), stream_url_req, SLOT(LoginComplete(bool, QString)));
|
||||
connect(stream_url_req, SIGNAL(StreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, const QString&)), this, SLOT(HandleStreamURLFinished(const QUrl&, const QUrl&, const Song::FileType, QString)));
|
||||
connect(this, SIGNAL(LoginComplete(const bool, const QString&)), stream_url_req, SLOT(LoginComplete(const bool, QString)));
|
||||
|
||||
stream_url_req->Process();
|
||||
|
||||
}
|
||||
|
||||
void TidalService::HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error) {
|
||||
void TidalService::HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error) {
|
||||
|
||||
TidalStreamURLRequest *stream_url_req = qobject_cast<TidalStreamURLRequest*>(sender());
|
||||
if (!stream_url_req || !stream_url_requests_.contains(stream_url_req)) return;
|
||||
|
|
|
@ -121,7 +121,7 @@ class TidalService : public InternetService {
|
|||
public slots:
|
||||
void ShowConfig();
|
||||
void TryLogin();
|
||||
void SendLogin(const QString &username, const QString &password, const QString &token);
|
||||
void SendLogin(const QString &api_token, const QString &username, const QString &password);
|
||||
void GetArtists();
|
||||
void GetAlbums();
|
||||
void GetSongs();
|
||||
|
@ -150,7 +150,7 @@ class TidalService : public InternetService {
|
|||
void ArtistsUpdateProgressReceived(const int id, const int progress);
|
||||
void AlbumsUpdateProgressReceived(const int id, const int progress);
|
||||
void SongsUpdateProgressReceived(const int id, const int progress);
|
||||
void HandleStreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
void HandleStreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private:
|
||||
typedef QPair<QString, QString> Param;
|
||||
|
|
|
@ -59,7 +59,7 @@ TidalStreamURLRequest::~TidalStreamURLRequest() {
|
|||
|
||||
}
|
||||
|
||||
void TidalStreamURLRequest::LoginComplete(bool success, QString error) {
|
||||
void TidalStreamURLRequest::LoginComplete(const bool success, QString error) {
|
||||
|
||||
if (!need_login_) return;
|
||||
need_login_ = false;
|
||||
|
@ -77,13 +77,18 @@ void TidalStreamURLRequest::Process() {
|
|||
|
||||
if (!authenticated()) {
|
||||
if (oauth()) {
|
||||
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, tr("Not authenticated."));
|
||||
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, tr("Not authenticated with Tidal."));
|
||||
return;
|
||||
}
|
||||
else if (api_token().isEmpty() || username().isEmpty() || password().isEmpty()) {
|
||||
emit StreamURLFinished(original_url_, original_url_, Song::FileType_Stream, tr("Missing Tidal API token, username or passord."));
|
||||
return;
|
||||
}
|
||||
need_login_ = true;
|
||||
emit TryLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
GetStreamURL();
|
||||
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ class TidalStreamURLRequest : public TidalBaseRequest {
|
|||
|
||||
signals:
|
||||
void TryLogin();
|
||||
void StreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType filetype, QString error = QString());
|
||||
void StreamURLFinished(const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, QString error = QString());
|
||||
|
||||
private slots:
|
||||
void LoginComplete(bool success, QString error = QString());
|
||||
void LoginComplete(const bool success, QString error = QString());
|
||||
void StreamURLReceived();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue