Replace some NewClosure's with lambda connects

This commit is contained in:
Jonas Kvinge 2020-04-28 22:29:10 +02:00
parent 5ed9d9c4a0
commit 9cc6a94353
13 changed files with 33 additions and 44 deletions

View File

@ -41,7 +41,6 @@
#include <QNetworkRequest>
#include <QSettings>
#include "core/closure.h"
#include "core/network.h"
#include "core/song.h"
#include "core/tagreaderclient.h"
@ -359,7 +358,7 @@ AlbumCoverLoader::TryLoadResult AlbumCoverLoader::TryLoadImage(Task *task) {
QNetworkRequest request(cover_url);
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(request);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RemoteFetchFinished(QNetworkReply*, QUrl)), reply, cover_url);
connect(reply, &QNetworkReply::finished, [=] { RemoteFetchFinished(reply, cover_url); });
remote_tasks_.insert(reply, *task);
return TryLoadResult(true, false, type, cover_url, QImage());
@ -387,7 +386,7 @@ void AlbumCoverLoader::RemoteFetchFinished(QNetworkReply *reply, const QUrl &cov
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
request.setUrl(redirect.toUrl());
QNetworkReply *redirected_reply = network_->get(request);
NewClosure(redirected_reply, SIGNAL(finished()), this, SLOT(RemoteFetchFinished(QNetworkReply*, QUrl)), redirected_reply, redirect.toUrl());
connect(redirected_reply, &QNetworkReply::finished, [=] { RemoteFetchFinished(redirected_reply, redirect.toUrl()); });
remote_tasks_.insert(redirected_reply, task);
return;

View File

@ -35,7 +35,6 @@
#include <QJsonValue>
#include <QtDebug>
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "jsonlyricsprovider.h"
@ -66,7 +65,7 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
//qLog(Debug) << "AudDLyrics: Sending request for" << url;

View File

@ -33,7 +33,6 @@
#include <QXmlStreamReader>
#include <QtDebug>
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "lyricsprovider.h"
@ -61,7 +60,7 @@ bool LoloLyricsProvider::StartSearch(const QString &artist, const QString &album
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
//qLog(Debug) << "LoloLyrics: Sending request for" << url;

View File

@ -30,7 +30,6 @@
#include <QJsonValue>
#include <QtDebug>
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "lyricsfetcher.h"
@ -49,7 +48,7 @@ bool OVHLyricsProvider::StartSearch(const QString &artist, const QString &album,
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
connect(reply, &QNetworkReply::finished, [=] { HandleSearchReply(reply, id, artist, title); });
//qLog(Debug) << "OVHLyrics: Sending request for" << url;

View File

@ -43,7 +43,6 @@
#include <QJsonValue>
#include "acoustidclient.h"
#include "core/closure.h"
#include "core/network.h"
#include "core/networktimeouts.h"
#include "core/timeconstants.h"
@ -79,7 +78,7 @@ void AcoustidClient::Start(const int id, const QString &fingerprint, int duratio
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RequestFinished(QNetworkReply*, int)), reply, id);
connect(reply, &QNetworkReply::finished, [=] { RequestFinished(reply, id); });
requests_[id] = reply;
timeouts_->AddReply(reply);

View File

@ -44,7 +44,6 @@
#include <QTimer>
#include <QtDebug>
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "core/networktimeouts.h"
@ -157,7 +156,7 @@ void MusicBrainzClient::StartDiscIdRequest(const QString &discid) {
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(DiscIdRequestFinished(QString, QNetworkReply*)), discid, reply);
connect(reply, &QNetworkReply::finished, [=] { DiscIdRequestFinished(discid, reply); });
timeouts_->AddReply(reply);
@ -179,7 +178,7 @@ void MusicBrainzClient::FlushRequests() {
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RequestFinished(QNetworkReply*, int, int)), reply, request.id, request.number);
connect(reply, &QNetworkReply::finished, [=] { RequestFinished(reply, request.id, request.number); });
requests_.insert(request.id, reply);
timeouts_->AddReply(reply);

View File

@ -38,11 +38,11 @@
#include <QtDebug>
#include "core/application.h"
#include "core/closure.h"
#include "core/network.h"
#include "core/song.h"
#include "core/timeconstants.h"
#include "core/logging.h"
#include "core/closure.h"
#include "internet/localredirectserver.h"
#include "audioscrobbler.h"
@ -199,7 +199,7 @@ void ListenBrainzScrobbler::RequestSession(const QUrl &url, const QString &token
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query);
NewClosure(reply, SIGNAL(finished()), this, SLOT(AuthenticateReplyFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { AuthenticateReplyFinished(reply); });
}
@ -384,7 +384,7 @@ void ListenBrainzScrobbler::UpdateNowPlaying(const Song &song) {
QUrl url(QString("%1/1/submit-listens").arg(kApiUrl));
QNetworkReply *reply = CreateRequest(url, doc);
NewClosure(reply, SIGNAL(finished()), this, SLOT(UpdateNowPlayingRequestFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { UpdateNowPlayingRequestFinished(reply); });
}
@ -511,7 +511,7 @@ void ListenBrainzScrobbler::Submit() {
QUrl url(QString("%1/1/submit-listens").arg(kApiUrl));
QNetworkReply *reply = CreateRequest(url, doc);
NewClosure(reply, SIGNAL(finished()), this, SLOT(ScrobbleRequestFinished(QNetworkReply*, QList<quint64>)), reply, list);
connect(reply, &QNetworkReply::finished, [=] { ScrobbleRequestFinished(reply, list); });
}

View File

@ -46,11 +46,11 @@
#include <QtDebug>
#include "core/application.h"
#include "core/closure.h"
#include "core/network.h"
#include "core/song.h"
#include "core/timeconstants.h"
#include "core/logging.h"
#include "core/closure.h"
#include "internet/localredirectserver.h"
#include "settings/scrobblersettingspage.h"
@ -231,7 +231,7 @@ void ScrobblingAPI20::RequestSession(const QString &token) {
QNetworkRequest req(session_url);
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network()->get(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(AuthenticateReplyFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { AuthenticateReplyFinished(reply); });
}
@ -447,7 +447,7 @@ void ScrobblingAPI20::UpdateNowPlaying(const Song &song) {
params << Param("albumArtist", song.albumartist());
QNetworkReply *reply = CreateRequest(params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(UpdateNowPlayingRequestFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { UpdateNowPlayingRequestFinished(reply); });
}
@ -566,7 +566,7 @@ void ScrobblingAPI20::Submit() {
if (!batch_ || i <= 0) return;
QNetworkReply *reply = CreateRequest(params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(ScrobbleRequestFinished(QNetworkReply*, QList<quint64>)), reply, list);
connect(reply, &QNetworkReply::finished, [=] { ScrobbleRequestFinished(reply, list); });
}
@ -743,7 +743,7 @@ void ScrobblingAPI20::SendSingleScrobble(ScrobblerCacheItem *item) {
params << Param("trackNumber", QString::number(item->track_));
QNetworkReply *reply = CreateRequest(params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(SingleScrobbleRequestFinished(QNetworkReply*, quint64)), reply, item->timestamp_);
connect(reply, &QNetworkReply::finished, [=] { SingleScrobbleRequestFinished(reply, item->timestamp_); });
}
@ -891,7 +891,7 @@ void ScrobblingAPI20::Love() {
params << Param("albumArtist", song_playing_.albumartist());
QNetworkReply *reply = CreateRequest(params);
NewClosure(reply, SIGNAL(finished()), this, SLOT(LoveRequestFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { LoveRequestFinished(reply); });
}

View File

@ -40,7 +40,6 @@
#include <QtDebug>
#include "core/application.h"
#include "core/closure.h"
#include "core/logging.h"
#include "core/song.h"
#include "core/timeconstants.h"
@ -153,7 +152,7 @@ void SubsonicRequest::FlushAlbumsRequests() {
QNetworkReply *reply;
reply = CreateGetRequest(QString("getAlbumList2"), params);
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, int)), reply, request.offset);
connect(reply, &QNetworkReply::finished, [=] { AlbumsReplyReceived(reply, request.offset); });
}
@ -346,7 +345,7 @@ void SubsonicRequest::FlushAlbumSongsRequests() {
ParamList params = ParamList() << Param("id", request.album_id);
QNetworkReply *reply = CreateGetRequest(QString("getAlbum"), params);
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, QString, QString, QString)), reply, request.artist_id, request.album_id, request.album_artist);
connect(reply, &QNetworkReply::finished, [=] { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.album_artist); });
}
@ -717,7 +716,7 @@ void SubsonicRequest::FlushAlbumCoverRequests() {
QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, QString, QUrl, QString)), reply, request.album_id, request.url, request.filename);
connect(reply, &QNetworkReply::finished, [=] { AlbumCoverReceived(reply, request.album_id, request.url, request.filename); });
}

View File

@ -44,7 +44,6 @@
#include "core/application.h"
#include "core/player.h"
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "core/database.h"
@ -179,7 +178,7 @@ void SubsonicService::SendPing(QUrl url, const QString &username, const QString
errors_.clear();
QNetworkReply *reply = network_->get(req);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandlePingSSLErrors(QList<QSslError>)));
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandlePingReply(QNetworkReply*, QUrl, QString, QString)), reply, url, username, password);
connect(reply, &QNetworkReply::finished, [=] { HandlePingReply(reply, url, username, password); });
//qLog(Debug) << "Subsonic: Sending request" << url << query;
@ -359,7 +358,7 @@ void SubsonicService::CheckConfiguration() {
void SubsonicService::ResetSongsRequest() {
if (songs_request_.get()) { // WARNING: Don't disconnect everything. NewClosure() relies on destroyed()!!!
if (songs_request_.get()) {
disconnect(songs_request_.get(), 0, this, 0);
disconnect(this, 0, songs_request_.get(), 0);
songs_request_.reset();

View File

@ -36,7 +36,6 @@
#include "core/logging.h"
#include "core/network.h"
#include "core/closure.h"
#include "core/song.h"
#include "tidalservice.h"
#include "tidalbaserequest.h"
@ -142,7 +141,7 @@ void TidalFavoriteRequest::AddFavorites(const FavoriteType type, const SongList
if (!session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", session_id().toUtf8());
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query);
NewClosure(reply, SIGNAL(finished()), this, SLOT(AddFavoritesReply(QNetworkReply*, FavoriteType, SongList)), reply, type, songs);
connect(reply, &QNetworkReply::finished, [=] { AddFavoritesReply(reply, type, songs); });
replies_ << reply;
qLog(Debug) << "Tidal: Sending request" << url << query;
@ -244,7 +243,7 @@ void TidalFavoriteRequest::RemoveFavorites(const FavoriteType type, const QStrin
if (!access_token().isEmpty()) req.setRawHeader("authorization", "Bearer " + access_token().toUtf8());
if (!session_id().isEmpty()) req.setRawHeader("X-Tidal-SessionId", session_id().toUtf8());
QNetworkReply *reply = network_->deleteResource(req);
NewClosure(reply, SIGNAL(finished()), this, SLOT(RemoveFavoritesReply(QNetworkReply*, FavoriteType, SongList)), reply, type, songs);
connect(reply, &QNetworkReply::finished, [=] { RemoveFavoritesReply(reply, type, songs); });
replies_ << reply;
qLog(Debug) << "Tidal: Sending request" << url << "with" << songs.count() << "songs";

View File

@ -31,7 +31,6 @@
#include <QJsonValue>
#include <QtDebug>
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "core/song.h"
@ -189,7 +188,7 @@ void TidalRequest::FlushArtistsRequests() {
}
if (!reply) continue;
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
connect(reply, &QNetworkReply::finished, [=] { ArtistsReplyReceived(reply, request.limit, request.offset); });
}
@ -233,7 +232,7 @@ void TidalRequest::FlushAlbumsRequests() {
}
if (!reply) continue;
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
connect(reply, &QNetworkReply::finished, [=] { AlbumsReplyReceived(reply, request.limit, request.offset); });
}
@ -277,7 +276,7 @@ void TidalRequest::FlushSongsRequests() {
}
if (!reply) continue;
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(SongsReplyReceived(QNetworkReply*, int, int)), reply, request.limit, request.offset);
connect(reply, &QNetworkReply::finished, [=] { SongsReplyReceived(reply, request.limit, request.offset); });
}
@ -499,7 +498,7 @@ void TidalRequest::FlushArtistAlbumsRequests() {
ParamList parameters;
if (request.offset > 0) parameters << Param("offset", QString::number(request.offset));
QNetworkReply *reply = CreateRequest(QString("artists/%1/albums").arg(request.artist_id), parameters);
NewClosure(reply, SIGNAL(finished()), this, SLOT(ArtistAlbumsReplyReceived(QNetworkReply*, QString, int)), reply, request.artist_id, request.offset);
connect(reply, &QNetworkReply::finished, [=] { ArtistAlbumsReplyReceived(reply, request.artist_id, request.offset); });
replies_ << reply;
}
@ -765,7 +764,7 @@ void TidalRequest::FlushAlbumSongsRequests() {
if (request.offset > 0) parameters << Param("offset", QString::number(request.offset));
QNetworkReply *reply = CreateRequest(QString("albums/%1/tracks").arg(request.album_id), parameters);
replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumSongsReplyReceived(QNetworkReply*, QString, QString, int, QString)), reply, request.artist_id, request.album_id, request.offset, request.album_artist);
connect(reply, &QNetworkReply::finished, [=] { AlbumSongsReplyReceived(reply, request.artist_id, request.album_id, request.offset, request.album_artist); });
}
@ -1116,7 +1115,7 @@ void TidalRequest::FlushAlbumCoverRequests() {
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply *reply = network_->get(req);
album_cover_replies_ << reply;
NewClosure(reply, SIGNAL(finished()), this, SLOT(AlbumCoverReceived(QNetworkReply*, QString, QUrl, QString)), reply, request.album_id, request.url, request.filename);
connect(reply, &QNetworkReply::finished, [=] { AlbumCoverReceived(reply, request.album_id, request.url, request.filename); });
}

View File

@ -44,7 +44,6 @@
#include "core/application.h"
#include "core/player.h"
#include "core/closure.h"
#include "core/logging.h"
#include "core/network.h"
#include "core/database.h"
@ -340,7 +339,7 @@ void TidalService::AuthorisationUrlReceived(const QUrl &url) {
login_errors_.clear();
QNetworkReply *reply = network_->post(request, query);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
NewClosure(reply, SIGNAL(finished()), this, SLOT(AccessTokenRequestFinished(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { AccessTokenRequestFinished(reply); });
}
@ -503,7 +502,7 @@ void TidalService::SendLogin(const QString &api_token, const QString &username,
QByteArray query = url_query.toString(QUrl::FullyEncoded).toUtf8();
QNetworkReply *reply = network_->post(req, query);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleAuthReply(QNetworkReply*)), reply);
connect(reply, &QNetworkReply::finished, [=] { HandleAuthReply(reply); });
//qLog(Debug) << "Tidal: Sending request" << url << query;