diff --git a/src/qobuz/qobuzbaserequest.h b/src/qobuz/qobuzbaserequest.h index 6dc47026..b533d4df 100644 --- a/src/qobuz/qobuzbaserequest.h +++ b/src/qobuz/qobuzbaserequest.h @@ -48,7 +48,7 @@ class QobuzBaseRequest : public QObject { explicit QobuzBaseRequest(QobuzService *service, SharedPtr network, QObject *parent = nullptr); ~QobuzBaseRequest(); - enum class QueryType { + enum class Type { None, Artists, Albums, diff --git a/src/qobuz/qobuzrequest.cpp b/src/qobuz/qobuzrequest.cpp index a7a39ed9..889c0ea0 100644 --- a/src/qobuz/qobuzrequest.cpp +++ b/src/qobuz/qobuzrequest.cpp @@ -57,7 +57,7 @@ constexpr int kMaxConcurrentAlbumCoverRequests = 1; constexpr int kFlushRequestsDelay = 200; } // namespace -QobuzRequest::QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, SharedPtr network, const QueryType query_type, QObject *parent) +QobuzRequest::QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, SharedPtr network, const Type query_type, QObject *parent) : QobuzBaseRequest(service, network, parent), service_(service), url_handler_(url_handler), @@ -124,22 +124,22 @@ QobuzRequest::~QobuzRequest() { void QobuzRequest::Process() { switch (query_type_) { - case QueryType::Artists: + case Type::Artists: GetArtists(); break; - case QueryType::Albums: + case Type::Albums: GetAlbums(); break; - case QueryType::Songs: + case Type::Songs: GetSongs(); break; - case QueryType::SearchArtists: + case Type::SearchArtists: ArtistsSearch(); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AlbumsSearch(); break; - case QueryType::SearchSongs: + case Type::SearchSongs: SongsSearch(); break; default: @@ -226,18 +226,18 @@ void QobuzRequest::FlushArtistsRequests() { Request request = artists_requests_queue_.dequeue(); ParamList params; - if (query_type_ == QueryType::Artists) { + if (query_type_ == Type::Artists) { params << Param(QStringLiteral("type"), QStringLiteral("artists")); params << Param(QStringLiteral("user_auth_token"), user_auth_token()); } - else if (query_type_ == QueryType::SearchArtists) params << Param(QStringLiteral("query"), search_text_); + else if (query_type_ == Type::SearchArtists) params << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) params << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) params << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Artists) { + if (query_type_ == Type::Artists) { reply = CreateRequest(QStringLiteral("favorite/getUserFavorites"), params); } - else if (query_type_ == QueryType::SearchArtists) { + else if (query_type_ == Type::SearchArtists) { reply = CreateRequest(QStringLiteral("artist/search"), params); } if (!reply) continue; @@ -278,18 +278,18 @@ void QobuzRequest::FlushAlbumsRequests() { Request request = albums_requests_queue_.dequeue(); ParamList params; - if (query_type_ == QueryType::Albums) { + if (query_type_ == Type::Albums) { params << Param(QStringLiteral("type"), QStringLiteral("albums")); params << Param(QStringLiteral("user_auth_token"), user_auth_token()); } - else if (query_type_ == QueryType::SearchAlbums) params << Param(QStringLiteral("query"), search_text_); + else if (query_type_ == Type::SearchAlbums) params << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) params << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) params << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Albums) { + if (query_type_ == Type::Albums) { reply = CreateRequest(QStringLiteral("favorite/getUserFavorites"), params); } - else if (query_type_ == QueryType::SearchAlbums) { + else if (query_type_ == Type::SearchAlbums) { reply = CreateRequest(QStringLiteral("album/search"), params); } if (!reply) continue; @@ -330,18 +330,18 @@ void QobuzRequest::FlushSongsRequests() { Request request = songs_requests_queue_.dequeue(); ParamList params; - if (query_type_ == QueryType::Songs) { + if (query_type_ == Type::Songs) { params << Param(QStringLiteral("type"), QStringLiteral("tracks")); params << Param(QStringLiteral("user_auth_token"), user_auth_token()); } - else if (query_type_ == QueryType::SearchSongs) params << Param(QStringLiteral("query"), search_text_); + else if (query_type_ == Type::SearchSongs) params << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) params << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) params << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Songs) { + if (query_type_ == Type::Songs) { reply = CreateRequest(QStringLiteral("favorite/getUserFavorites"), params); } - else if (query_type_ == QueryType::SearchSongs) { + else if (query_type_ == Type::SearchSongs) { reply = CreateRequest(QStringLiteral("track/search"), params); } if (!reply) continue; @@ -534,8 +534,8 @@ void QobuzRequest::ArtistsFinishCheck(const int limit, const int offset, const i if ((limit == 0 || limit > artists_received) && artists_received_ < artists_total_) { int offset_next = offset + artists_received; if (offset_next > 0 && offset_next < artists_total_) { - if (query_type_ == QueryType::Artists) AddArtistsRequest(offset_next); - else if (query_type_ == QueryType::SearchArtists) AddArtistsSearchRequest(offset_next); + if (query_type_ == Type::Artists) AddArtistsRequest(offset_next); + else if (query_type_ == Type::SearchArtists) AddArtistsSearchRequest(offset_next); } } @@ -689,7 +689,7 @@ void QobuzRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_req } QJsonArray array_items = value_items.toArray(); if (array_items.isEmpty()) { - if ((query_type_ == QueryType::Albums || query_type_ == QueryType::SearchAlbums) && offset_requested == 0) { + if ((query_type_ == Type::Albums || query_type_ == Type::SearchAlbums) && offset_requested == 0) { no_results_ = true; } AlbumsFinishCheck(artist_requested); @@ -755,7 +755,7 @@ void QobuzRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_req } - if (query_type_ == QueryType::Albums || query_type_ == QueryType::SearchAlbums) { + if (query_type_ == Type::Albums || query_type_ == Type::SearchAlbums) { albums_received_ += albums_received; emit UpdateProgress(query_id_, GetProgress(albums_received_, albums_total_)); } @@ -772,14 +772,14 @@ void QobuzRequest::AlbumsFinishCheck(const Artist &artist, const int limit, cons int offset_next = offset + albums_received; if (offset_next > 0 && offset_next < albums_total) { switch (query_type_) { - case QueryType::Albums: + case Type::Albums: AddAlbumsRequest(offset_next); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AddAlbumsSearchRequest(offset_next); break; - case QueryType::Artists: - case QueryType::SearchArtists: + case Type::Artists: + case Type::SearchArtists: AddArtistAlbumsRequest(artist, offset_next); break; default: @@ -984,7 +984,7 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const Artist &artist_requ QJsonArray array_items = value_items.toArray(); if (array_items.isEmpty()) { - if ((query_type_ == QueryType::Songs || query_type_ == QueryType::SearchSongs) && offset_requested == 0) { + if ((query_type_ == Type::Songs || query_type_ == Type::SearchSongs) && offset_requested == 0) { no_results_ = true; } SongsFinishCheck(album_artist, album, limit_requested, offset_requested, songs_total); @@ -1018,7 +1018,7 @@ void QobuzRequest::SongsReceived(QNetworkReply *reply, const Artist &artist_requ songs_.insert(song.song_id(), song); } - if (query_type_ == QueryType::Songs || query_type_ == QueryType::SearchSongs) { + if (query_type_ == Type::Songs || query_type_ == Type::SearchSongs) { songs_received_ += songs_received; emit UpdateProgress(query_id_, GetProgress(songs_received_, songs_total_)); } @@ -1035,16 +1035,16 @@ void QobuzRequest::SongsFinishCheck(const Artist &artist, const Album &album, co int offset_next = offset + songs_received; if (offset_next > 0 && offset_next < songs_total) { switch (query_type_) { - case QueryType::Songs: + case Type::Songs: AddSongsRequest(offset_next); break; - case QueryType::SearchSongs: + case Type::SearchSongs: AddSongsSearchRequest(offset_next); break; - case QueryType::Artists: - case QueryType::SearchArtists: - case QueryType::Albums: - case QueryType::SearchAlbums: + case Type::Artists: + case Type::SearchArtists: + case Type::Albums: + case Type::SearchAlbums: AddAlbumSongsRequest(artist, album, offset_next); break; default: diff --git a/src/qobuz/qobuzrequest.h b/src/qobuz/qobuzrequest.h index 65d19bad..a4aca94b 100644 --- a/src/qobuz/qobuzrequest.h +++ b/src/qobuz/qobuzrequest.h @@ -53,7 +53,7 @@ class QobuzRequest : public QobuzBaseRequest { public: - explicit QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, SharedPtr network, const QueryType query_type, QObject *parent = nullptr); + explicit QobuzRequest(QobuzService *service, QobuzUrlHandler *url_handler, Application *app, SharedPtr network, const Type query_type, QObject *parent = nullptr); ~QobuzRequest() override; void ReloadSettings(); @@ -121,8 +121,8 @@ class QobuzRequest : public QobuzBaseRequest { private: - bool IsQuery() { return (query_type_ == QueryType::Artists || query_type_ == QueryType::Albums || query_type_ == QueryType::Songs); } - bool IsSearch() { return (query_type_ == QueryType::SearchArtists || query_type_ == QueryType::SearchAlbums || query_type_ == QueryType::SearchSongs); } + bool IsQuery() const { return (query_type_ == Type::Artists || query_type_ == Type::Albums || query_type_ == Type::Songs); } + bool IsSearch() const { return (query_type_ == Type::SearchArtists || query_type_ == Type::SearchAlbums || query_type_ == Type::SearchSongs); } void StartRequests(); void FlushRequests(); @@ -177,7 +177,7 @@ class QobuzRequest : public QobuzBaseRequest { SharedPtr network_; QTimer *timer_flush_requests_; - const QueryType query_type_; + const Type query_type_; int query_id_; QString search_text_; diff --git a/src/qobuz/qobuzservice.cpp b/src/qobuz/qobuzservice.cpp index ccefa443..1ce985cd 100644 --- a/src/qobuz/qobuzservice.cpp +++ b/src/qobuz/qobuzservice.cpp @@ -519,7 +519,7 @@ void QobuzService::GetArtists() { } ResetArtistsRequest(); - artists_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType::Artists), [](QobuzRequest *request) { request->deleteLater(); }); + artists_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::Type::Artists), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(&*artists_request_, &QobuzRequest::Results, this, &QobuzService::ArtistsResultsReceived); QObject::connect(&*artists_request_, &QobuzRequest::UpdateStatus, this, &QobuzService::ArtistsUpdateStatusReceived); QObject::connect(&*artists_request_, &QobuzRequest::UpdateProgress, this, &QobuzService::ArtistsUpdateProgressReceived); @@ -569,7 +569,7 @@ void QobuzService::GetAlbums() { } ResetAlbumsRequest(); - albums_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType::Albums), [](QobuzRequest *request) { request->deleteLater(); }); + albums_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::Type::Albums), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(&*albums_request_, &QobuzRequest::Results, this, &QobuzService::AlbumsResultsReceived); QObject::connect(&*albums_request_, &QobuzRequest::UpdateStatus, this, &QobuzService::AlbumsUpdateStatusReceived); QObject::connect(&*albums_request_, &QobuzRequest::UpdateProgress, this, &QobuzService::AlbumsUpdateProgressReceived); @@ -619,7 +619,7 @@ void QobuzService::GetSongs() { } ResetSongsRequest(); - songs_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType::Songs), [](QobuzRequest *request) { request->deleteLater(); }); + songs_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::Type::Songs), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(&*songs_request_, &QobuzRequest::Results, this, &QobuzService::SongsResultsReceived); QObject::connect(&*songs_request_, &QobuzRequest::UpdateStatus, this, &QobuzService::SongsUpdateStatusReceived); QObject::connect(&*songs_request_, &QobuzRequest::UpdateProgress, this, &QobuzService::SongsUpdateProgressReceived); @@ -684,17 +684,17 @@ void QobuzService::CancelSearch() { void QobuzService::SendSearch() { - QobuzBaseRequest::QueryType query_type = QobuzBaseRequest::QueryType::None; + QobuzBaseRequest::Type query_type = QobuzBaseRequest::Type::None; switch (pending_search_type_) { case StreamingSearchView::SearchType::Artists: - query_type = QobuzBaseRequest::QueryType::SearchArtists; + query_type = QobuzBaseRequest::Type::SearchArtists; break; case StreamingSearchView::SearchType::Albums: - query_type = QobuzBaseRequest::QueryType::SearchAlbums; + query_type = QobuzBaseRequest::Type::SearchAlbums; break; case StreamingSearchView::SearchType::Songs: - query_type = QobuzBaseRequest::QueryType::SearchSongs; + query_type = QobuzBaseRequest::Type::SearchSongs; break; } diff --git a/src/spotify/spotifybaserequest.h b/src/spotify/spotifybaserequest.h index a8de6ff8..48858fe6 100644 --- a/src/spotify/spotifybaserequest.h +++ b/src/spotify/spotifybaserequest.h @@ -47,7 +47,7 @@ class SpotifyBaseRequest : public QObject { public: explicit SpotifyBaseRequest(SpotifyService *service, NetworkAccessManager *network, QObject *parent = nullptr); - enum class QueryType { + enum class Type { None, Artists, Albums, diff --git a/src/spotify/spotifyrequest.cpp b/src/spotify/spotifyrequest.cpp index 6e919d52..67896f32 100644 --- a/src/spotify/spotifyrequest.cpp +++ b/src/spotify/spotifyrequest.cpp @@ -53,7 +53,7 @@ const int kMaxConcurrentAlbumCoverRequests = 10; const int kFlushRequestsDelay = 200; } -SpotifyRequest::SpotifyRequest(SpotifyService *service, Application *app, NetworkAccessManager *network, QueryType type, QObject *parent) +SpotifyRequest::SpotifyRequest(SpotifyService *service, Application *app, NetworkAccessManager *network, Type type, QObject *parent) : SpotifyBaseRequest(service, network, parent), service_(service), app_(app), @@ -129,22 +129,22 @@ void SpotifyRequest::Process() { } switch (type_) { - case QueryType::Artists: + case Type::Artists: GetArtists(); break; - case QueryType::Albums: + case Type::Albums: GetAlbums(); break; - case QueryType::Songs: + case Type::Songs: GetSongs(); break; - case QueryType::SearchArtists: + case Type::SearchArtists: ArtistsSearch(); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AlbumsSearch(); break; - case QueryType::SearchSongs: + case Type::SearchSongs: SongsSearch(); break; default: @@ -233,7 +233,7 @@ void SpotifyRequest::FlushArtistsRequests() { Request request = artists_requests_queue_.dequeue(); ParamList parameters = ParamList() << Param(QStringLiteral("type"), QStringLiteral("artist")); - if (type_ == QueryType::SearchArtists) { + if (type_ == Type::SearchArtists) { parameters << Param(QStringLiteral("q"), search_text_); } if (request.limit > 0) { @@ -243,10 +243,10 @@ void SpotifyRequest::FlushArtistsRequests() { parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); } QNetworkReply *reply = nullptr; - if (type_ == QueryType::Artists) { + if (type_ == Type::Artists) { reply = CreateRequest(QStringLiteral("me/following"), parameters); } - if (type_ == QueryType::SearchArtists) { + if (type_ == Type::SearchArtists) { reply = CreateRequest(QStringLiteral("search"), parameters); } if (!reply) continue; @@ -287,7 +287,7 @@ void SpotifyRequest::FlushAlbumsRequests() { Request request = albums_requests_queue_.dequeue(); ParamList parameters; - if (type_ == QueryType::SearchAlbums) { + if (type_ == Type::SearchAlbums) { parameters << Param(QStringLiteral("type"), QStringLiteral("album")); parameters << Param(QStringLiteral("q"), search_text_); } @@ -297,10 +297,10 @@ void SpotifyRequest::FlushAlbumsRequests() { if (request.limit > 0) parameters << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (type_ == QueryType::Albums) { + if (type_ == Type::Albums) { reply = CreateRequest(QStringLiteral("me/albums"), parameters); } - if (type_ == QueryType::SearchAlbums) { + if (type_ == Type::SearchAlbums) { reply = CreateRequest(QStringLiteral("search"), parameters); } if (!reply) continue; @@ -341,7 +341,7 @@ void SpotifyRequest::FlushSongsRequests() { Request request = songs_requests_queue_.dequeue(); ParamList parameters; - if (type_ == QueryType::SearchSongs) { + if (type_ == Type::SearchSongs) { parameters << Param(QStringLiteral("type"), QStringLiteral("track")); parameters << Param(QStringLiteral("q"), search_text_); } @@ -352,10 +352,10 @@ void SpotifyRequest::FlushSongsRequests() { parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); } QNetworkReply *reply = nullptr; - if (type_ == QueryType::Songs) { + if (type_ == Type::Songs) { reply = CreateRequest(QStringLiteral("me/tracks"), parameters); } - if (type_ == QueryType::SearchSongs) { + if (type_ == Type::SearchSongs) { reply = CreateRequest(QStringLiteral("search"), parameters); } if (!reply) continue; @@ -539,8 +539,8 @@ void SpotifyRequest::ArtistsFinishCheck(const int limit, const int offset, const if ((limit == 0 || limit > artists_received) && artists_received_ < artists_total_) { int offset_next = offset + artists_received; if (offset_next > 0 && offset_next < artists_total_) { - if (type_ == QueryType::Artists) AddArtistsRequest(offset_next); - else if (type_ == QueryType::SearchArtists) AddArtistsSearchRequest(offset_next); + if (type_ == Type::Artists) AddArtistsRequest(offset_next); + else if (type_ == Type::SearchArtists) AddArtistsSearchRequest(offset_next); } } @@ -655,7 +655,7 @@ void SpotifyRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_a int offset = json_obj[QLatin1String("offset")].toInt(); int albums_total = json_obj[QLatin1String("total")].toInt(); - if (type_ == QueryType::Albums || type_ == QueryType::SearchAlbums) { + if (type_ == Type::Albums || type_ == Type::SearchAlbums) { albums_total_ = albums_total; } @@ -672,7 +672,7 @@ void SpotifyRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_a } QJsonArray array_items = value_items.toArray(); if (array_items.isEmpty()) { - if ((type_ == QueryType::Albums || type_ == QueryType::SearchAlbums || (type_ == QueryType::SearchSongs && fetchalbums_)) && offset_requested == 0) { + if ((type_ == Type::Albums || type_ == Type::SearchAlbums || (type_ == Type::SearchSongs && fetchalbums_)) && offset_requested == 0) { no_results_ = true; } AlbumsFinishCheck(artist_artist); @@ -801,7 +801,7 @@ void SpotifyRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_a } - if (type_ == QueryType::Albums || type_ == QueryType::SearchAlbums) { + if (type_ == Type::Albums || type_ == Type::SearchAlbums) { albums_received_ += albums_received; emit UpdateProgress(query_id_, GetProgress(albums_received_, albums_total_)); } @@ -818,14 +818,14 @@ void SpotifyRequest::AlbumsFinishCheck(const Artist &artist, const int limit, co int offset_next = offset + albums_received; if (offset_next > 0 && offset_next < albums_total) { switch (type_) { - case QueryType::Albums: + case Type::Albums: AddAlbumsRequest(offset_next); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AddAlbumsSearchRequest(offset_next); break; - case QueryType::Artists: - case QueryType::SearchArtists: + case Type::Artists: + case Type::SearchArtists: AddArtistAlbumsRequest(artist, offset_next); break; default: @@ -868,7 +868,7 @@ void SpotifyRequest::SongsReplyReceived(QNetworkReply *reply, const int limit_re --songs_requests_active_; ++songs_requests_received_; - if (type_ == QueryType::SearchSongs && fetchalbums_) { + if (type_ == Type::SearchSongs && fetchalbums_) { AlbumsReceived(reply, Artist(), limit_requested, offset_requested); } else { @@ -956,7 +956,7 @@ void SpotifyRequest::SongsReceived(QNetworkReply *reply, const Artist &artist, c int offset = json_obj[QLatin1String("offset")].toInt(); int songs_total = json_obj[QLatin1String("total")].toInt(); - if (type_ == QueryType::Songs || type_ == QueryType::SearchSongs) { + if (type_ == Type::Songs || type_ == Type::SearchSongs) { songs_total_ = songs_total; } @@ -974,7 +974,7 @@ void SpotifyRequest::SongsReceived(QNetworkReply *reply, const Artist &artist, c QJsonArray array_items = json_value.toArray(); if (array_items.isEmpty()) { - if ((type_ == QueryType::Songs || type_ == QueryType::SearchSongs) && offset_requested == 0) { + if ((type_ == Type::Songs || type_ == Type::SearchSongs) && offset_requested == 0) { no_results_ = true; } SongsFinishCheck(artist, album, limit_requested, offset_requested, songs_total, 0); @@ -1016,7 +1016,7 @@ void SpotifyRequest::SongsReceived(QNetworkReply *reply, const Artist &artist, c songs_.insert(song.song_id(), song); } - if (type_ == QueryType::Songs || type_ == QueryType::SearchSongs) { + if (type_ == Type::Songs || type_ == Type::SearchSongs) { songs_received_ += songs_received; emit UpdateProgress(query_id_, GetProgress(songs_received_, songs_total_)); } @@ -1033,20 +1033,20 @@ void SpotifyRequest::SongsFinishCheck(const Artist &artist, const Album &album, int offset_next = offset + songs_received; if (offset_next > 0 && offset_next < songs_total) { switch (type_) { - case QueryType::Songs: + case Type::Songs: AddSongsRequest(offset_next); break; - case QueryType::SearchSongs: + case Type::SearchSongs: // If artist_id and album_id isn't zero it means that it's a songs search where we fetch all albums too. So fallthrough. if (artist.artist_id.isEmpty() && album.album_id.isEmpty()) { AddSongsSearchRequest(offset_next); break; } // fallthrough - case QueryType::Artists: - case QueryType::SearchArtists: - case QueryType::Albums: - case QueryType::SearchAlbums: + case Type::Artists: + case Type::SearchArtists: + case Type::Albums: + case Type::SearchAlbums: AddAlbumSongsRequest(artist, album, offset_next); break; default: diff --git a/src/spotify/spotifyrequest.h b/src/spotify/spotifyrequest.h index 02aadfb2..01e9cb6f 100644 --- a/src/spotify/spotifyrequest.h +++ b/src/spotify/spotifyrequest.h @@ -49,7 +49,7 @@ class SpotifyRequest : public SpotifyBaseRequest { Q_OBJECT public: - explicit SpotifyRequest(SpotifyService *service, Application *app, NetworkAccessManager *network, QueryType type, QObject *parent); + explicit SpotifyRequest(SpotifyService *service, Application *app, NetworkAccessManager *network, Type type, QObject *parent); ~SpotifyRequest() override; void ReloadSettings(); @@ -117,8 +117,8 @@ class SpotifyRequest : public SpotifyBaseRequest { private: void StartRequests(); - bool IsQuery() const { return (type_ == QueryType::Artists || type_ == QueryType::Albums || type_ == QueryType::Songs); } - bool IsSearch() const { return (type_ == QueryType::SearchArtists || type_ == QueryType::SearchAlbums || type_ == QueryType::SearchSongs); } + bool IsQuery() const { return (type_ == Type::Artists || type_ == Type::Albums || type_ == Type::Songs); } + bool IsSearch() const { return (type_ == Type::SearchArtists || type_ == Type::SearchAlbums || type_ == Type::SearchSongs); } void GetArtists(); void GetAlbums(); @@ -167,7 +167,7 @@ class SpotifyRequest : public SpotifyBaseRequest { NetworkAccessManager *network_; QTimer *timer_flush_requests_; - QueryType type_; + Type type_; bool fetchalbums_; QString coversize_; diff --git a/src/spotify/spotifyservice.cpp b/src/spotify/spotifyservice.cpp index c0a8cb9f..ea5245e5 100644 --- a/src/spotify/spotifyservice.cpp +++ b/src/spotify/spotifyservice.cpp @@ -519,7 +519,7 @@ void SpotifyService::GetArtists() { } ResetArtistsRequest(); - artists_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::QueryType::Artists, this), [](SpotifyRequest *request) { request->deleteLater(); }); + artists_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::Type::Artists, this), [](SpotifyRequest *request) { request->deleteLater(); }); QObject::connect(&*artists_request_, &SpotifyRequest::Results, this, &SpotifyService::ArtistsResultsReceived); QObject::connect(&*artists_request_, &SpotifyRequest::UpdateStatus, this, &SpotifyService::ArtistsUpdateStatusReceived); QObject::connect(&*artists_request_, &SpotifyRequest::ProgressSetMaximum, this, &SpotifyService::ArtistsProgressSetMaximumReceived); @@ -571,7 +571,7 @@ void SpotifyService::GetAlbums() { } ResetAlbumsRequest(); - albums_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::QueryType::Albums, this), [](SpotifyRequest *request) { request->deleteLater(); }); + albums_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::Type::Albums, this), [](SpotifyRequest *request) { request->deleteLater(); }); QObject::connect(&*albums_request_, &SpotifyRequest::Results, this, &SpotifyService::AlbumsResultsReceived); QObject::connect(&*albums_request_, &SpotifyRequest::UpdateStatus, this, &SpotifyService::AlbumsUpdateStatusReceived); QObject::connect(&*albums_request_, &SpotifyRequest::ProgressSetMaximum, this, &SpotifyService::AlbumsProgressSetMaximumReceived); @@ -623,7 +623,7 @@ void SpotifyService::GetSongs() { } ResetSongsRequest(); - songs_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::QueryType::Songs, this), [](SpotifyRequest *request) { request->deleteLater(); }); + songs_request_.reset(new SpotifyRequest(this, app_, network_, SpotifyBaseRequest::Type::Songs, this), [](SpotifyRequest *request) { request->deleteLater(); }); QObject::connect(&*songs_request_, &SpotifyRequest::Results, this, &SpotifyService::SongsResultsReceived); QObject::connect(&*songs_request_, &SpotifyRequest::UpdateStatus, this, &SpotifyService::SongsUpdateStatusReceived); QObject::connect(&*songs_request_, &SpotifyRequest::ProgressSetMaximum, this, &SpotifyService::SongsProgressSetMaximumReceived); @@ -694,17 +694,17 @@ void SpotifyService::CancelSearch() { void SpotifyService::SendSearch() { - SpotifyBaseRequest::QueryType type = SpotifyBaseRequest::QueryType::None; + SpotifyBaseRequest::Type type = SpotifyBaseRequest::Type::None; switch (pending_search_type_) { case StreamingSearchView::SearchType::Artists: - type = SpotifyBaseRequest::QueryType::SearchArtists; + type = SpotifyBaseRequest::Type::SearchArtists; break; case StreamingSearchView::SearchType::Albums: - type = SpotifyBaseRequest::QueryType::SearchAlbums; + type = SpotifyBaseRequest::Type::SearchAlbums; break; case StreamingSearchView::SearchType::Songs: - type = SpotifyBaseRequest::QueryType::SearchSongs; + type = SpotifyBaseRequest::Type::SearchSongs; break; default: //Error("Invalid search type."); diff --git a/src/tidal/tidalbaserequest.h b/src/tidal/tidalbaserequest.h index 3064b57b..5b766c19 100644 --- a/src/tidal/tidalbaserequest.h +++ b/src/tidal/tidalbaserequest.h @@ -48,7 +48,7 @@ class TidalBaseRequest : public QObject { public: explicit TidalBaseRequest(TidalService *service, SharedPtr network, QObject *parent = nullptr); - enum class QueryType { + enum class Type { None, Artists, Albums, diff --git a/src/tidal/tidalrequest.cpp b/src/tidal/tidalrequest.cpp index de36cba3..d17aba39 100644 --- a/src/tidal/tidalrequest.cpp +++ b/src/tidal/tidalrequest.cpp @@ -58,7 +58,7 @@ constexpr int kMaxConcurrentAlbumCoverRequests = 1; constexpr int kFlushRequestsDelay = 200; } // namespace -TidalRequest::TidalRequest(TidalService *service, TidalUrlHandler *url_handler, Application *app, SharedPtr network, QueryType query_type, QObject *parent) +TidalRequest::TidalRequest(TidalService *service, TidalUrlHandler *url_handler, Application *app, SharedPtr network, Type query_type, QObject *parent) : TidalBaseRequest(service, network, parent), service_(service), url_handler_(url_handler), @@ -148,22 +148,22 @@ void TidalRequest::Process() { } switch (query_type_) { - case QueryType::Artists: + case Type::Artists: GetArtists(); break; - case QueryType::Albums: + case Type::Albums: GetAlbums(); break; - case QueryType::Songs: + case Type::Songs: GetSongs(); break; - case QueryType::SearchArtists: + case Type::SearchArtists: ArtistsSearch(); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AlbumsSearch(); break; - case QueryType::SearchSongs: + case Type::SearchSongs: SongsSearch(); break; default: @@ -250,14 +250,14 @@ void TidalRequest::FlushArtistsRequests() { Request request = artists_requests_queue_.dequeue(); ParamList parameters; - if (query_type_ == QueryType::SearchArtists) parameters << Param(QStringLiteral("query"), search_text_); + if (query_type_ == Type::SearchArtists) parameters << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) parameters << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Artists) { + if (query_type_ == Type::Artists) { reply = CreateRequest(QStringLiteral("users/%1/favorites/artists").arg(service_->user_id()), parameters); } - if (query_type_ == QueryType::SearchArtists) { + if (query_type_ == Type::SearchArtists) { reply = CreateRequest(QStringLiteral("search/artists"), parameters); } if (!reply) continue; @@ -298,14 +298,14 @@ void TidalRequest::FlushAlbumsRequests() { Request request = albums_requests_queue_.dequeue(); ParamList parameters; - if (query_type_ == QueryType::SearchAlbums) parameters << Param(QStringLiteral("query"), search_text_); + if (query_type_ == Type::SearchAlbums) parameters << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) parameters << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Albums) { + if (query_type_ == Type::Albums) { reply = CreateRequest(QStringLiteral("users/%1/favorites/albums").arg(service_->user_id()), parameters); } - if (query_type_ == QueryType::SearchAlbums) { + if (query_type_ == Type::SearchAlbums) { reply = CreateRequest(QStringLiteral("search/albums"), parameters); } if (!reply) continue; @@ -346,14 +346,14 @@ void TidalRequest::FlushSongsRequests() { Request request = songs_requests_queue_.dequeue(); ParamList parameters; - if (query_type_ == QueryType::SearchSongs) parameters << Param(QStringLiteral("query"), search_text_); + if (query_type_ == Type::SearchSongs) parameters << Param(QStringLiteral("query"), search_text_); if (request.limit > 0) parameters << Param(QStringLiteral("limit"), QString::number(request.limit)); if (request.offset > 0) parameters << Param(QStringLiteral("offset"), QString::number(request.offset)); QNetworkReply *reply = nullptr; - if (query_type_ == QueryType::Songs) { + if (query_type_ == Type::Songs) { reply = CreateRequest(QStringLiteral("users/%1/favorites/tracks").arg(service_->user_id()), parameters); } - if (query_type_ == QueryType::SearchSongs) { + if (query_type_ == Type::SearchSongs) { reply = CreateRequest(QStringLiteral("search/tracks"), parameters); } if (!reply) continue; @@ -532,8 +532,8 @@ void TidalRequest::ArtistsFinishCheck(const int limit, const int offset, const i if ((limit == 0 || limit > artists_received) && artists_received_ < artists_total_) { int offset_next = offset + artists_received; if (offset_next > 0 && offset_next < artists_total_) { - if (query_type_ == QueryType::Artists) AddArtistsRequest(offset_next); - else if (query_type_ == QueryType::SearchArtists) AddArtistsSearchRequest(offset_next); + if (query_type_ == Type::Artists) AddArtistsRequest(offset_next); + else if (query_type_ == Type::SearchArtists) AddArtistsSearchRequest(offset_next); } } @@ -766,7 +766,7 @@ void TidalRequest::AlbumsReceived(QNetworkReply *reply, const Artist &artist_req } - if (query_type_ == QueryType::Albums || query_type_ == QueryType::SearchAlbums) { + if (query_type_ == Type::Albums || query_type_ == Type::SearchAlbums) { albums_received_ += albums_received; emit UpdateProgress(query_id_, GetProgress(albums_received_, albums_total_)); } @@ -783,14 +783,14 @@ void TidalRequest::AlbumsFinishCheck(const Artist &artist, const int limit, cons int offset_next = offset + albums_received; if (offset_next > 0 && offset_next < albums_total) { switch (query_type_) { - case QueryType::Albums: + case Type::Albums: AddAlbumsRequest(offset_next); break; - case QueryType::SearchAlbums: + case Type::SearchAlbums: AddAlbumsSearchRequest(offset_next); break; - case QueryType::Artists: - case QueryType::SearchArtists: + case Type::Artists: + case Type::SearchArtists: AddArtistAlbumsRequest(artist, offset_next); break; default: @@ -832,7 +832,7 @@ void TidalRequest::SongsReplyReceived(QNetworkReply *reply, const int limit_requ --songs_requests_active_; ++songs_requests_received_; - if (query_type_ == QueryType::SearchSongs && fetchalbums_) { + if (query_type_ == Type::SearchSongs && fetchalbums_) { AlbumsReceived(reply, Artist(), limit_requested, offset_requested, offset_requested == 0); } else { @@ -972,7 +972,7 @@ void TidalRequest::SongsReceived(QNetworkReply *reply, const Artist &artist, con songs_.insert(song.song_id(), song); } - if (query_type_ == QueryType::Songs || query_type_ == QueryType::SearchSongs) { + if (query_type_ == Type::Songs || query_type_ == Type::SearchSongs) { songs_received_ += songs_received; emit UpdateProgress(query_id_, GetProgress(songs_received_, songs_total_)); } @@ -989,20 +989,20 @@ void TidalRequest::SongsFinishCheck(const Artist &artist, const Album &album, co int offset_next = offset + songs_received; if (offset_next > 0 && offset_next < songs_total) { switch (query_type_) { - case QueryType::Songs: + case Type::Songs: AddSongsRequest(offset_next); break; - case QueryType::SearchSongs: + case Type::SearchSongs: // If artist_id and album_id isn't zero it means that it's a songs search where we fetch all albums too. So fallthrough. if (artist.artist_id.isEmpty() && album.album_id.isEmpty()) { AddSongsSearchRequest(offset_next); break; } [[fallthrough]]; - case QueryType::Artists: - case QueryType::SearchArtists: - case QueryType::Albums: - case QueryType::SearchAlbums: + case Type::Artists: + case Type::SearchArtists: + case Type::Albums: + case Type::SearchAlbums: AddAlbumSongsRequest(artist, album, offset_next); break; default: diff --git a/src/tidal/tidalrequest.h b/src/tidal/tidalrequest.h index 97e7ff76..a9bc9f1a 100644 --- a/src/tidal/tidalrequest.h +++ b/src/tidal/tidalrequest.h @@ -53,7 +53,7 @@ class TidalRequest : public TidalBaseRequest { Q_OBJECT public: - explicit TidalRequest(TidalService *service, TidalUrlHandler *url_handler, Application *app, SharedPtr network, QueryType query_type, QObject *parent); + explicit TidalRequest(TidalService *service, TidalUrlHandler *url_handler, Application *app, SharedPtr network, Type query_type, QObject *parent); ~TidalRequest() override; void ReloadSettings(); @@ -124,8 +124,8 @@ class TidalRequest : public TidalBaseRequest { void LoginComplete(const bool success, const QString &error = QString()); private: - bool IsQuery() { return (query_type_ == QueryType::Artists || query_type_ == QueryType::Albums || query_type_ == QueryType::Songs); } - bool IsSearch() { return (query_type_ == QueryType::SearchArtists || query_type_ == QueryType::SearchAlbums || query_type_ == QueryType::SearchSongs); } + bool IsQuery() const { return (query_type_ == Type::Artists || query_type_ == Type::Albums || query_type_ == Type::Songs); } + bool IsSearch() const { return (query_type_ == Type::SearchArtists || query_type_ == Type::SearchAlbums || query_type_ == Type::SearchSongs); } void StartRequests(); void FlushRequests(); @@ -178,7 +178,7 @@ class TidalRequest : public TidalBaseRequest { SharedPtr network_; QTimer *timer_flush_requests_; - const QueryType query_type_; + const Type query_type_; const bool fetchalbums_; const QString coversize_; diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index b92a6ada..09f4a66b 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -732,7 +732,7 @@ void TidalService::GetArtists() { } ResetArtistsRequest(); - artists_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType::Artists, this), [](TidalRequest *request) { request->deleteLater(); }); + artists_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::Type::Artists, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(&*artists_request_, &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(&*artists_request_, &TidalRequest::Results, this, &TidalService::ArtistsResultsReceived); QObject::connect(&*artists_request_, &TidalRequest::UpdateStatus, this, &TidalService::ArtistsUpdateStatusReceived); @@ -787,7 +787,7 @@ void TidalService::GetAlbums() { } ResetAlbumsRequest(); - albums_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType::Albums, this), [](TidalRequest *request) { request->deleteLater(); }); + albums_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::Type::Albums, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(&*albums_request_, &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(&*albums_request_, &TidalRequest::Results, this, &TidalService::AlbumsResultsReceived); QObject::connect(&*albums_request_, &TidalRequest::UpdateStatus, this, &TidalService::AlbumsUpdateStatusReceived); @@ -842,7 +842,7 @@ void TidalService::GetSongs() { } ResetSongsRequest(); - songs_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType::Songs, this), [](TidalRequest *request) { request->deleteLater(); }); + songs_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::Type::Songs, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(&*songs_request_, &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(&*songs_request_, &TidalRequest::Results, this, &TidalService::SongsResultsReceived); QObject::connect(&*songs_request_, &TidalRequest::UpdateStatus, this, &TidalService::SongsUpdateStatusReceived); @@ -916,17 +916,17 @@ void TidalService::CancelSearch() { void TidalService::SendSearch() { - TidalBaseRequest::QueryType query_type = TidalBaseRequest::QueryType::None; + TidalBaseRequest::Type query_type = TidalBaseRequest::Type::None; switch (pending_search_type_) { case StreamingSearchView::SearchType::Artists: - query_type = TidalBaseRequest::QueryType::SearchArtists; + query_type = TidalBaseRequest::Type::SearchArtists; break; case StreamingSearchView::SearchType::Albums: - query_type = TidalBaseRequest::QueryType::SearchAlbums; + query_type = TidalBaseRequest::Type::SearchAlbums; break; case StreamingSearchView::SearchType::Songs: - query_type = TidalBaseRequest::QueryType::SearchSongs; + query_type = TidalBaseRequest::Type::SearchSongs; break; default: //Error("Invalid search type.");