Validate configuration better
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user