Reduce network access managers
This commit is contained in:
@@ -27,4 +27,4 @@
|
||||
#include "core/application.h"
|
||||
#include "coverprovider.h"
|
||||
|
||||
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent) : QObject(parent), app_(app), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}
|
||||
CoverProvider::CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent) : QObject(parent), app_(app), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required), quality_(quality), batch_(batch), allow_missing_album_(allow_missing_album) {}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "albumcoverfetcher.h"
|
||||
|
||||
class Application;
|
||||
class NetworkAccessManager;
|
||||
|
||||
// Each implementation of this interface downloads covers from one online service.
|
||||
// There are no limitations on what this service might be - last.fm, Amazon, Google Images - you name it.
|
||||
@@ -40,7 +41,7 @@ class CoverProvider : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent);
|
||||
explicit CoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent);
|
||||
|
||||
// A name (very short description) of this provider, like "last.fm".
|
||||
QString name() const { return name_; }
|
||||
@@ -73,8 +74,9 @@ class CoverProvider : public QObject {
|
||||
void SearchResults(int, CoverProviderSearchResults);
|
||||
void SearchFinished(int, CoverProviderSearchResults);
|
||||
|
||||
private:
|
||||
protected:
|
||||
Application *app_;
|
||||
NetworkAccessManager *network_;
|
||||
QString name_;
|
||||
bool enabled_;
|
||||
int order_;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "coverprovider.h"
|
||||
#include "coverproviders.h"
|
||||
|
||||
@@ -40,7 +41,7 @@
|
||||
|
||||
int CoverProviders::NextOrderId = 0;
|
||||
|
||||
CoverProviders::CoverProviders(QObject *parent) : QObject(parent) {}
|
||||
CoverProviders::CoverProviders(QObject *parent) : QObject(parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
CoverProviders::~CoverProviders() {
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <QString>
|
||||
#include <QAtomicInt>
|
||||
|
||||
class NetworkAccessManager;
|
||||
class CoverProvider;
|
||||
|
||||
// This is a repository for cover providers.
|
||||
@@ -59,6 +60,8 @@ class CoverProviders : public QObject {
|
||||
|
||||
int NextId();
|
||||
|
||||
NetworkAccessManager *network() const { return network_; }
|
||||
|
||||
private slots:
|
||||
void ProviderDestroyed();
|
||||
|
||||
@@ -67,6 +70,8 @@ class CoverProviders : public QObject {
|
||||
|
||||
static int NextOrderId;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
|
||||
QMap<CoverProvider*, QString> cover_providers_;
|
||||
QMutex mutex_;
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -53,9 +52,8 @@
|
||||
const char *DeezerCoverProvider::kApiUrl = "https://api.deezer.com";
|
||||
const int DeezerCoverProvider::kLimit = 10;
|
||||
|
||||
DeezerCoverProvider::DeezerCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Deezer", true, false, 2.0, true, true, app, parent),
|
||||
network_(new NetworkAccessManager(this)) {}
|
||||
DeezerCoverProvider::DeezerCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Deezer", true, false, 2.0, true, true, app, network, parent) {}
|
||||
|
||||
DeezerCoverProvider::~DeezerCoverProvider() {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class DeezerCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DeezerCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit DeezerCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~DeezerCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -58,7 +58,6 @@ class DeezerCoverProvider : public JsonCoverProvider {
|
||||
static const char *kApiUrl;
|
||||
static const int kLimit;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QTimer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -61,9 +60,8 @@ const char *DiscogsCoverProvider::kAccessKeyB64 = "dGh6ZnljUGJlZ1NEeXBuSFFxSVk="
|
||||
const char *DiscogsCoverProvider::kSecretKeyB64 = "ZkFIcmlaSER4aHhRSlF2U3d0bm5ZVmdxeXFLWUl0UXI=";
|
||||
const int DiscogsCoverProvider::kRequestsDelay = 1000;
|
||||
|
||||
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Discogs", false, false, 0.0, false, false, app, parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
DiscogsCoverProvider::DiscogsCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Discogs", false, false, 0.0, false, false, app, network, parent),
|
||||
timer_flush_requests_(new QTimer(this)) {
|
||||
|
||||
timer_flush_requests_->setInterval(kRequestsDelay);
|
||||
|
||||
@@ -49,7 +49,7 @@ class DiscogsCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DiscogsCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit DiscogsCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~DiscogsCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -99,7 +99,6 @@ class DiscogsCoverProvider : public JsonCoverProvider {
|
||||
static const char *kSecretKeyB64;
|
||||
static const int kRequestsDelay;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
QTimer *timer_flush_requests_;
|
||||
QQueue<std::shared_ptr<DiscogsCoverSearchContext>> queue_search_requests_;
|
||||
QQueue<DiscogsCoverReleaseContext> queue_release_requests_;
|
||||
|
||||
@@ -28,11 +28,12 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "coverprovider.h"
|
||||
#include "jsoncoverprovider.h"
|
||||
|
||||
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent)
|
||||
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, app, parent) {}
|
||||
JsonCoverProvider::JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: CoverProvider(name, enabled, authentication_required, quality, batch, allow_missing_album, app, network, parent) {}
|
||||
|
||||
QJsonObject JsonCoverProvider::ExtractJsonObj(const QByteArray &data) {
|
||||
|
||||
|
||||
@@ -30,15 +30,16 @@
|
||||
#include "coverprovider.h"
|
||||
|
||||
class Application;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class JsonCoverProvider : public CoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, QObject *parent);
|
||||
explicit JsonCoverProvider(const QString &name, const bool enabled, const bool authentication_required, const float quality, const bool batch, const bool allow_missing_album, Application *app, NetworkAccessManager *network, QObject *parent);
|
||||
|
||||
protected:
|
||||
QJsonObject ExtractJsonObj(const QByteArray &data);
|
||||
|
||||
};
|
||||
|
||||
#endif // JSONCOVERPROVIDER_H
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QCryptographicHash>
|
||||
@@ -53,9 +52,8 @@ const char *LastFmCoverProvider::kUrl = "https://ws.audioscrobbler.com/2.0/";
|
||||
const char *LastFmCoverProvider::kApiKey = "211990b4c96782c05d1536e7219eb56e";
|
||||
const char *LastFmCoverProvider::kSecret = "80fd738f49596e9709b1bf9319c444a8";
|
||||
|
||||
LastFmCoverProvider::LastFmCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Last.fm", true, false, 1.0, true, false, app, parent),
|
||||
network_(new NetworkAccessManager(this)) {}
|
||||
LastFmCoverProvider::LastFmCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Last.fm", true, false, 1.0, true, false, app, network, parent) {}
|
||||
|
||||
LastFmCoverProvider::~LastFmCoverProvider() {
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class LastFmCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LastFmCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit LastFmCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~LastFmCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -65,7 +65,6 @@ class LastFmCoverProvider : public JsonCoverProvider {
|
||||
static const char *kApiKey;
|
||||
static const char *kSecret;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QTimer>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -51,9 +50,8 @@ const char *MusicbrainzCoverProvider::kAlbumCoverUrl = "https://coverartarchive.
|
||||
const int MusicbrainzCoverProvider::kLimit = 8;
|
||||
const int MusicbrainzCoverProvider::kRequestsDelay = 1000;
|
||||
|
||||
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("MusicBrainz", true, false, 1.5, true, false, app, parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
MusicbrainzCoverProvider::MusicbrainzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("MusicBrainz", true, false, 1.5, true, false, app, network, parent),
|
||||
timer_flush_requests_(new QTimer(this)) {
|
||||
|
||||
timer_flush_requests_->setInterval(kRequestsDelay);
|
||||
|
||||
@@ -41,7 +41,7 @@ class MusicbrainzCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MusicbrainzCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit MusicbrainzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~MusicbrainzCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -68,7 +68,6 @@ class MusicbrainzCoverProvider : public JsonCoverProvider {
|
||||
static const int kLimit;
|
||||
static const int kRequestsDelay;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
QTimer *timer_flush_requests_;
|
||||
QQueue<SearchRequest> queue_search_requests_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QRegularExpression>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -40,9 +39,8 @@
|
||||
#include "jsoncoverprovider.h"
|
||||
#include "musixmatchcoverprovider.h"
|
||||
|
||||
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Musixmatch", true, false, 1.0, true, false, app, parent),
|
||||
network_(new NetworkAccessManager(this)) {}
|
||||
MusixmatchCoverProvider::MusixmatchCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Musixmatch", true, false, 1.0, true, false, app, network, parent) {}
|
||||
|
||||
MusixmatchCoverProvider::~MusixmatchCoverProvider() {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class MusixmatchCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MusixmatchCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit MusixmatchCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~MusixmatchCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -50,7 +50,6 @@ class MusixmatchCoverProvider : public JsonCoverProvider {
|
||||
void HandleSearchReply(QNetworkReply *reply, const int id, const QString &artist, const QString &album);
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -52,10 +51,9 @@
|
||||
|
||||
const int QobuzCoverProvider::kLimit = 10;
|
||||
|
||||
QobuzCoverProvider::QobuzCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, parent),
|
||||
service_(app->internet_services()->Service<QobuzService>()),
|
||||
network_(new NetworkAccessManager(this)) {}
|
||||
QobuzCoverProvider::QobuzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Qobuz", true, true, 2.0, true, true, app, network, parent),
|
||||
service_(app->internet_services()->Service<QobuzService>()) {}
|
||||
|
||||
QobuzCoverProvider::~QobuzCoverProvider() {
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class QobuzCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QobuzCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit QobuzCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~QobuzCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -65,7 +65,6 @@ class QobuzCoverProvider : public JsonCoverProvider {
|
||||
static const int kLimit;
|
||||
|
||||
QobuzService *service_;
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QSslError>
|
||||
@@ -63,9 +62,8 @@ const char *SpotifyCoverProvider::kClientSecretB64 = "N2ZlMDMxODk1NTBlNDE3ZGI1ZW
|
||||
const char *SpotifyCoverProvider::kApiUrl = "https://api.spotify.com/v1";
|
||||
const int SpotifyCoverProvider::kLimit = 10;
|
||||
|
||||
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Spotify", true, true, 2.5, true, true, app, parent),
|
||||
network_(new NetworkAccessManager(this)),
|
||||
SpotifyCoverProvider::SpotifyCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Spotify", true, true, 2.5, true, true, app, network, parent),
|
||||
server_(nullptr),
|
||||
expires_in_(0),
|
||||
login_time_(0) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class SpotifyCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SpotifyCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit SpotifyCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~SpotifyCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -81,7 +81,6 @@ class SpotifyCoverProvider : public JsonCoverProvider {
|
||||
static const char *kApiUrl;
|
||||
static const int kLimit;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
LocalRedirectServer *server_;
|
||||
QStringList login_errors_;
|
||||
QString code_verifier_;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonDocument>
|
||||
@@ -50,10 +49,9 @@
|
||||
|
||||
const int TidalCoverProvider::kLimit = 10;
|
||||
|
||||
TidalCoverProvider::TidalCoverProvider(Application *app, QObject *parent)
|
||||
: JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, parent),
|
||||
service_(app->internet_services()->Service<TidalService>()),
|
||||
network_(new NetworkAccessManager(this)) {}
|
||||
TidalCoverProvider::TidalCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent)
|
||||
: JsonCoverProvider("Tidal", true, true, 2.5, true, true, app, network, parent),
|
||||
service_(app->internet_services()->Service<TidalService>()) {}
|
||||
|
||||
TidalCoverProvider::~TidalCoverProvider() {
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class TidalCoverProvider : public JsonCoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TidalCoverProvider(Application *app, QObject *parent = nullptr);
|
||||
explicit TidalCoverProvider(Application *app, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~TidalCoverProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const int id) override;
|
||||
@@ -63,7 +63,6 @@ class TidalCoverProvider : public JsonCoverProvider {
|
||||
static const int kLimit;
|
||||
|
||||
TidalService *service_;
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user