Use one instance of NetworkAccessManager

This commit is contained in:
Jonas Kvinge
2023-04-21 20:20:53 +02:00
parent bee6b7f946
commit 7fc5aef553
53 changed files with 270 additions and 311 deletions

View File

@@ -50,9 +50,9 @@ const char *AcoustidClient::kClientId = "0qjUoxbowg";
const char *AcoustidClient::kUrl = "https://api.acoustid.org/v2/lookup";
const int AcoustidClient::kDefaultTimeout = 5000; // msec
AcoustidClient::AcoustidClient(QObject *parent)
AcoustidClient::AcoustidClient(NetworkAccessManager *network, QObject *parent)
: QObject(parent),
network_(new NetworkAccessManager(this)),
network_(network),
timeouts_(new NetworkTimeouts(kDefaultTimeout, this)) {}
AcoustidClient::~AcoustidClient() {

View File

@@ -43,7 +43,7 @@ class AcoustidClient : public QObject {
// IDs are provided by the caller when a request is started and included in the Finished signal - they have no meaning to AcoustidClient.
public:
explicit AcoustidClient(QObject *parent = nullptr);
explicit AcoustidClient(NetworkAccessManager *network, QObject *parent = nullptr);
~AcoustidClient() override;
// Network requests will be aborted after this interval.

View File

@@ -55,9 +55,9 @@ const int MusicBrainzClient::kRequestsDelay = 1200;
const int MusicBrainzClient::kDefaultTimeout = 8000;
const int MusicBrainzClient::kMaxRequestPerTrack = 3;
MusicBrainzClient::MusicBrainzClient(QObject *parent, QNetworkAccessManager *network)
MusicBrainzClient::MusicBrainzClient(QNetworkAccessManager *network, QObject *parent)
: QObject(parent),
network_(network ? network : new NetworkAccessManager(this)),
network_(network),
timeouts_(new NetworkTimeouts(kDefaultTimeout, this)),
timer_flush_requests_(new QTimer(this)) {

View File

@@ -50,7 +50,7 @@ class MusicBrainzClient : public QObject {
public:
// The second argument allows for specifying a custom network access manager.
// It is used in tests. The ownership of network is not transferred.
explicit MusicBrainzClient(QObject *parent = nullptr, QNetworkAccessManager *network = nullptr);
explicit MusicBrainzClient(QNetworkAccessManager *network, QObject *parent = nullptr);
~MusicBrainzClient() override;
struct Result {

View File

@@ -29,17 +29,18 @@
#include <QFutureWatcher>
#include <QString>
#include "core/networkaccessmanager.h"
#include "utilities/timeconstants.h"
#include "engine/chromaprinter.h"
#include "acoustidclient.h"
#include "musicbrainzclient.h"
#include "tagfetcher.h"
TagFetcher::TagFetcher(QObject *parent)
TagFetcher::TagFetcher(NetworkAccessManager *network, QObject *parent)
: QObject(parent),
fingerprint_watcher_(nullptr),
acoustid_client_(new AcoustidClient(this)),
musicbrainz_client_(new MusicBrainzClient(this)) {
acoustid_client_(new AcoustidClient(network, this)),
musicbrainz_client_(new MusicBrainzClient(network, this)) {
QObject::connect(acoustid_client_, &AcoustidClient::Finished, this, &TagFetcher::PuidsFound);
QObject::connect(musicbrainz_client_, &MusicBrainzClient::Finished, this, &TagFetcher::TagsFetched);

View File

@@ -32,6 +32,7 @@
#include "core/song.h"
#include "musicbrainzclient.h"
class NetworkAccessManager;
class AcoustidClient;
class TagFetcher : public QObject {
@@ -40,7 +41,7 @@ class TagFetcher : public QObject {
// High level interface to Fingerprinter, AcoustidClient and MusicBrainzClient.
public:
explicit TagFetcher(QObject *parent = nullptr);
explicit TagFetcher(NetworkAccessManager *network, QObject *parent = nullptr);
void StartFetch(const SongList &songs);