diff --git a/src/qobuz/qobuzservice.cpp b/src/qobuz/qobuzservice.cpp index d97613542..e43f24091 100644 --- a/src/qobuz/qobuzservice.cpp +++ b/src/qobuz/qobuzservice.cpp @@ -510,9 +510,7 @@ void QobuzService::GetArtists() { } ResetArtistsRequest(); - - artists_request_ = std::make_shared(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Artists); - + artists_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Artists), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(artists_request_.get(), &QobuzRequest::Results, this, &QobuzService::ArtistsResultsReceived); QObject::connect(artists_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::ArtistsUpdateStatusReceived); QObject::connect(artists_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::ArtistsProgressSetMaximumReceived); @@ -523,8 +521,11 @@ void QobuzService::GetArtists() { } void QobuzService::ArtistsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit ArtistsResults(songs, error); + ResetArtistsRequest(); + } void QobuzService::ArtistsUpdateStatusReceived(const int id, const QString &text) { @@ -565,7 +566,7 @@ void QobuzService::GetAlbums() { } ResetAlbumsRequest(); - albums_request_ = std::make_shared(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Albums); + albums_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Albums), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(albums_request_.get(), &QobuzRequest::Results, this, &QobuzService::AlbumsResultsReceived); QObject::connect(albums_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::AlbumsUpdateStatusReceived); QObject::connect(albums_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::AlbumsProgressSetMaximumReceived); @@ -576,8 +577,11 @@ void QobuzService::GetAlbums() { } void QobuzService::AlbumsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit AlbumsResults(songs, error); + ResetAlbumsRequest(); + } void QobuzService::AlbumsUpdateStatusReceived(const int id, const QString &text) { @@ -618,7 +622,7 @@ void QobuzService::GetSongs() { } ResetSongsRequest(); - songs_request_ = std::make_shared(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Songs); + songs_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, QobuzBaseRequest::QueryType_Songs), [](QobuzRequest *request) { request->deleteLater(); }); QObject::connect(songs_request_.get(), &QobuzRequest::Results, this, &QobuzService::SongsResultsReceived); QObject::connect(songs_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::SongsUpdateStatusReceived); QObject::connect(songs_request_.get(), &QobuzRequest::ProgressSetMaximum, this, &QobuzService::SongsProgressSetMaximumReceived); @@ -629,8 +633,11 @@ void QobuzService::GetSongs() { } void QobuzService::SongsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit SongsResults(songs, error); + ResetSongsRequest(); + } void QobuzService::SongsUpdateStatusReceived(const int id, const QString &text) { @@ -700,7 +707,7 @@ void QobuzService::SendSearch() { break; } - search_request_ = std::make_shared(this, url_handler_, app_, network_, type); + search_request_.reset(new QobuzRequest(this, url_handler_, app_, network_, type), [](QobuzRequest *request) { request->deleteLater(); } ); QObject::connect(search_request_.get(), &QobuzRequest::Results, this, &QobuzService::SearchResultsReceived); QObject::connect(search_request_.get(), &QobuzRequest::UpdateStatus, this, &QobuzService::SearchUpdateStatus); @@ -713,7 +720,10 @@ void QobuzService::SendSearch() { } void QobuzService::SearchResultsReceived(const int id, const SongMap &songs, const QString &error) { + + search_request_.reset(); emit SearchResults(id, songs, error); + } uint QobuzService::GetStreamURL(const QUrl &url, QString &error) { @@ -725,7 +735,8 @@ uint QobuzService::GetStreamURL(const QUrl &url, QString &error) { uint id = 0; while (id == 0) id = ++next_stream_url_request_id_; - std::shared_ptr stream_url_req = std::make_shared(this, network_, url, id); + std::shared_ptr stream_url_req; + stream_url_req.reset(new QobuzStreamURLRequest(this, network_, url, id), [](QobuzStreamURLRequest *request) { request->deleteLater(); }); stream_url_requests_.insert(id, stream_url_req); QObject::connect(stream_url_req.get(), &QobuzStreamURLRequest::TryLogin, this, &QobuzService::TryLogin); @@ -742,7 +753,7 @@ uint QobuzService::GetStreamURL(const QUrl &url, QString &error) { void QobuzService::HandleStreamURLFailure(const uint id, const QUrl &original_url, const QString &error) { if (!stream_url_requests_.contains(id)) return; - std::shared_ptr stream_url_req = stream_url_requests_.take(id); + stream_url_requests_.remove(id); emit StreamURLFailure(id, original_url, error); @@ -751,7 +762,7 @@ void QobuzService::HandleStreamURLFailure(const uint id, const QUrl &original_ur void QobuzService::HandleStreamURLSuccess(const uint id, const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration) { if (!stream_url_requests_.contains(id)) return; - std::shared_ptr stream_url_req = stream_url_requests_.take(id); + stream_url_requests_.remove(id); emit StreamURLSuccess(id, original_url, stream_url, filetype, samplerate, bit_depth, duration); diff --git a/src/subsonic/subsonicrequest.cpp b/src/subsonic/subsonicrequest.cpp index c6e001788..fc29b56fb 100644 --- a/src/subsonic/subsonicrequest.cpp +++ b/src/subsonic/subsonicrequest.cpp @@ -19,8 +19,6 @@ #include "config.h" -#include - #include #include #include @@ -63,7 +61,7 @@ SubsonicRequest::SubsonicRequest(SubsonicService *service, SubsonicUrlHandler *u service_(service), url_handler_(url_handler), app_(app), - network_(new QNetworkAccessManager), + network_(new QNetworkAccessManager(this)), timeouts_(new NetworkTimeouts(30000, this)), finished_(false), albums_requests_active_(0), diff --git a/src/subsonic/subsonicrequest.h b/src/subsonic/subsonicrequest.h index 1334c87ce..9c2de6e95 100644 --- a/src/subsonic/subsonicrequest.h +++ b/src/subsonic/subsonicrequest.h @@ -22,8 +22,6 @@ #include "config.h" -#include - #include #include #include @@ -37,12 +35,12 @@ #include #include #include -#include #include #include "core/song.h" #include "subsonicbaserequest.h" +class QNetworkAccessManager; class QNetworkReply; class Application; class SubsonicService; @@ -120,7 +118,7 @@ class SubsonicRequest : public SubsonicBaseRequest { SubsonicService *service_; SubsonicUrlHandler *url_handler_; Application *app_; - std::unique_ptr network_; + QNetworkAccessManager *network_; NetworkTimeouts *timeouts_; bool finished_; diff --git a/src/subsonic/subsonicservice.cpp b/src/subsonic/subsonicservice.cpp index c4519445e..cce44724d 100644 --- a/src/subsonic/subsonicservice.cpp +++ b/src/subsonic/subsonicservice.cpp @@ -399,7 +399,7 @@ void SubsonicService::Scrobble(const QString &song_id, const bool submission, co if (!scrobble_request_) { // We're doing requests every 30-240s the whole time, so keep reusing this instance - scrobble_request_ = std::make_shared(this, url_handler_, app_); + scrobble_request_.reset(new SubsonicScrobbleRequest(this, url_handler_, app_), [](SubsonicScrobbleRequest *request) { request->deleteLater(); }); } scrobble_request_->CreateScrobbleRequest(song_id, submission, time); @@ -429,7 +429,7 @@ void SubsonicService::GetSongs() { } ResetSongsRequest(); - songs_request_ = std::make_shared(this, url_handler_, app_); + songs_request_.reset(new SubsonicRequest(this, url_handler_, app_), [](SubsonicRequest *request) { request->deleteLater(); }); QObject::connect(songs_request_.get(), &SubsonicRequest::Results, this, &SubsonicService::SongsResultsReceived); QObject::connect(songs_request_.get(), &SubsonicRequest::UpdateStatus, this, &SubsonicService::SongsUpdateStatus); QObject::connect(songs_request_.get(), &SubsonicRequest::ProgressSetMaximum, this, &SubsonicService::SongsProgressSetMaximum); @@ -449,6 +449,8 @@ void SubsonicService::SongsResultsReceived(const SongMap &songs, const QString & emit SongsResults(songs, error); + ResetSongsRequest(); + } void SubsonicService::PingError(const QString &error, const QVariant &debug) { diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index 7c27acc21..a663882d7 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -752,9 +752,7 @@ void TidalService::GetArtists() { } ResetArtistsRequest(); - - artists_request_ = std::make_shared(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Artists, this); - + artists_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Artists, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(artists_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(artists_request_.get(), &TidalRequest::Results, this, &TidalService::ArtistsResultsReceived); QObject::connect(artists_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::ArtistsUpdateStatusReceived); @@ -767,8 +765,11 @@ void TidalService::GetArtists() { } void TidalService::ArtistsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit ArtistsResults(songs, error); + ResetArtistsRequest(); + } void TidalService::ArtistsUpdateStatusReceived(const int id, const QString &text) { @@ -812,7 +813,7 @@ void TidalService::GetAlbums() { } ResetAlbumsRequest(); - albums_request_ = std::make_shared(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Albums, this); + albums_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Albums, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(albums_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(albums_request_.get(), &TidalRequest::Results, this, &TidalService::AlbumsResultsReceived); QObject::connect(albums_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::AlbumsUpdateStatusReceived); @@ -825,8 +826,11 @@ void TidalService::GetAlbums() { } void TidalService::AlbumsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit AlbumsResults(songs, error); + ResetAlbumsRequest(); + } void TidalService::AlbumsUpdateStatusReceived(const int id, const QString &text) { @@ -870,7 +874,7 @@ void TidalService::GetSongs() { } ResetSongsRequest(); - songs_request_ = std::make_shared(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Songs, this); + songs_request_.reset(new TidalRequest(this, url_handler_, app_, network_, TidalBaseRequest::QueryType_Songs, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(songs_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(songs_request_.get(), &TidalRequest::Results, this, &TidalService::SongsResultsReceived); QObject::connect(songs_request_.get(), &TidalRequest::UpdateStatus, this, &TidalService::SongsUpdateStatusReceived); @@ -883,8 +887,11 @@ void TidalService::GetSongs() { } void TidalService::SongsResultsReceived(const int id, const SongMap &songs, const QString &error) { + Q_UNUSED(id); emit SongsResults(songs, error); + ResetSongsRequest(); + } void TidalService::SongsUpdateStatusReceived(const int id, const QString &text) { @@ -964,7 +971,7 @@ void TidalService::SendSearch() { return; } - search_request_ = std::make_shared(this, url_handler_, app_, network_, type, this); + search_request_.reset(new TidalRequest(this, url_handler_, app_, network_, type, this), [](TidalRequest *request) { request->deleteLater(); }); QObject::connect(search_request_.get(), &TidalRequest::RequestLogin, this, &TidalService::SendLogin); QObject::connect(search_request_.get(), &TidalRequest::Results, this, &TidalService::SearchResultsReceived); @@ -979,7 +986,10 @@ void TidalService::SendSearch() { } void TidalService::SearchResultsReceived(const int id, const SongMap &songs, const QString &error) { + emit SearchResults(id, songs, error); + search_request_.reset(); + } uint TidalService::GetStreamURL(const QUrl &url, QString &error) { @@ -997,7 +1007,8 @@ uint TidalService::GetStreamURL(const QUrl &url, QString &error) { uint id = 0; while (id == 0) id = ++next_stream_url_request_id_; - std::shared_ptr stream_url_req = std::make_shared(this, network_, url, id); + std::shared_ptr stream_url_req; + stream_url_req.reset(new TidalStreamURLRequest(this, network_, url, id), [](TidalStreamURLRequest *request) { request->deleteLater(); }); stream_url_requests_.insert(id, stream_url_req); QObject::connect(stream_url_req.get(), &TidalStreamURLRequest::TryLogin, this, &TidalService::TryLogin); @@ -1014,7 +1025,7 @@ uint TidalService::GetStreamURL(const QUrl &url, QString &error) { void TidalService::HandleStreamURLFailure(const uint id, const QUrl &original_url, const QString &error) { if (!stream_url_requests_.contains(id)) return; - std::shared_ptr stream_url_req = stream_url_requests_.take(id); + stream_url_requests_.remove(id); emit StreamURLFailure(id, original_url, error); @@ -1023,7 +1034,7 @@ void TidalService::HandleStreamURLFailure(const uint id, const QUrl &original_ur void TidalService::HandleStreamURLSuccess(const uint id, const QUrl &original_url, const QUrl &stream_url, const Song::FileType filetype, const int samplerate, const int bit_depth, const qint64 duration) { if (!stream_url_requests_.contains(id)) return; - std::shared_ptr stream_url_req = stream_url_requests_.take(id); + stream_url_requests_.remove(id); emit StreamURLSuccess(id, original_url, stream_url, filetype, samplerate, bit_depth, duration);