Use one instance of NetworkAccessManager
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user