Reduce network access managers
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
@@ -47,7 +46,7 @@ const char *AuddLyricsProvider::kUrlSearch = "https://api.audd.io/findLyrics/";
|
||||
const char *AuddLyricsProvider::kAPITokenB64 = "ZjA0NjQ4YjgyNDM3ZTc1MjY3YjJlZDI5ZDBlMzQxZjk=";
|
||||
const int AuddLyricsProvider::kMaxLength = 6000;
|
||||
|
||||
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : JsonLyricsProvider("AudD", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
AuddLyricsProvider::AuddLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("AudD", true, false, network, parent) {}
|
||||
|
||||
AuddLyricsProvider::~AuddLyricsProvider() {
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class AuddLyricsProvider : public JsonLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AuddLyricsProvider(QObject *parent = nullptr);
|
||||
explicit AuddLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~AuddLyricsProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id) override;
|
||||
@@ -56,7 +56,6 @@ class AuddLyricsProvider : public JsonLyricsProvider {
|
||||
static const char *kUrlSearch;
|
||||
static const char *kAPITokenB64;
|
||||
static const int kMaxLength;
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -41,7 +40,7 @@
|
||||
|
||||
const char *ChartLyricsProvider::kUrlSearch = "http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect";
|
||||
|
||||
ChartLyricsProvider::ChartLyricsProvider(QObject *parent) : LyricsProvider("ChartLyrics", false, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
ChartLyricsProvider::ChartLyricsProvider(NetworkAccessManager *network, QObject *parent) : LyricsProvider("ChartLyrics", false, false, network, parent) {}
|
||||
|
||||
ChartLyricsProvider::~ChartLyricsProvider() {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class ChartLyricsProvider : public LyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChartLyricsProvider(QObject *parent = nullptr);
|
||||
explicit ChartLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~ChartLyricsProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
|
||||
@@ -51,8 +51,6 @@ class ChartLyricsProvider : public LyricsProvider {
|
||||
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QSslError>
|
||||
@@ -62,7 +61,7 @@ const char *GeniusLyricsProvider::kUrlSearch = "https://api.genius.com/search/";
|
||||
const char *GeniusLyricsProvider::kClientIDB64 = "RUNTNXU4U1VyMU1KUU5hdTZySEZteUxXY2hkanFiY3lfc2JjdXBpNG5WMU9SNUg4dTBZelEtZTZCdFg2dl91SQ==";
|
||||
const char *GeniusLyricsProvider::kClientSecretB64 = "VE9pMU9vUjNtTXZ3eFR3YVN0QVRyUjVoUlhVWDI1Ylp5X240eEt1M0ZkYlNwRG5JUnd0LXFFbHdGZkZkRWY2VzJ1S011UnQzM3c2Y3hqY0tVZ3NGN2c=";
|
||||
|
||||
GeniusLyricsProvider::GeniusLyricsProvider(QObject *parent) : JsonLyricsProvider("Genius", true, true, parent), network_(new NetworkAccessManager(this)), server_(nullptr) {
|
||||
GeniusLyricsProvider::GeniusLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Genius", true, true, network, parent), server_(nullptr) {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
@@ -46,7 +46,7 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GeniusLyricsProvider(QObject *parent = nullptr);
|
||||
explicit GeniusLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~GeniusLyricsProvider() override;
|
||||
|
||||
bool IsAuthenticated() const override { return !access_token_.isEmpty(); }
|
||||
@@ -95,7 +95,6 @@ class GeniusLyricsProvider : public JsonLyricsProvider {
|
||||
static const char *kUrlSearch;
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
LocalRedirectServer *server_;
|
||||
QString code_verifier_;
|
||||
QString code_challenge_;
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "lyricsprovider.h"
|
||||
#include "jsonlyricsprovider.h"
|
||||
|
||||
JsonLyricsProvider::JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent) : LyricsProvider(name, enabled, authentication_required, parent) {}
|
||||
JsonLyricsProvider::JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent) : LyricsProvider(name, enabled, authentication_required, network, parent) {}
|
||||
|
||||
QByteArray JsonLyricsProvider::ExtractData(QNetworkReply *reply) {
|
||||
|
||||
|
||||
@@ -31,14 +31,16 @@
|
||||
|
||||
#include "lyricsprovider.h"
|
||||
|
||||
class NetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class JsonLyricsProvider : public LyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit JsonLyricsProvider(const QString &name, const bool enabled = true, const bool authentication_required = false, QObject *parent = nullptr);
|
||||
explicit JsonLyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
|
||||
protected:
|
||||
QByteArray ExtractData(QNetworkReply *reply);
|
||||
QJsonObject ExtractJsonObj(const QByteArray &data);
|
||||
QJsonObject ExtractJsonObj(QNetworkReply *reply);
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -42,7 +41,7 @@
|
||||
|
||||
const char *LoloLyricsProvider::kUrlSearch = "http://api.lololyrics.com/0.5/getLyric";
|
||||
|
||||
LoloLyricsProvider::LoloLyricsProvider(QObject *parent) : LyricsProvider("LoloLyrics", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
LoloLyricsProvider::LoloLyricsProvider(NetworkAccessManager *network, QObject *parent) : LyricsProvider("LoloLyrics", true, false, network, parent) {}
|
||||
|
||||
LoloLyricsProvider::~LoloLyricsProvider() {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class LoloLyricsProvider : public LyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LoloLyricsProvider(QObject *parent = nullptr);
|
||||
explicit LoloLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~LoloLyricsProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
|
||||
@@ -51,7 +51,6 @@ class LoloLyricsProvider : public LyricsProvider {
|
||||
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "core/networkaccessmanager.h"
|
||||
#include "lyricsprovider.h"
|
||||
|
||||
LyricsProvider::LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent)
|
||||
: QObject(parent), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required) {}
|
||||
LyricsProvider::LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent)
|
||||
: QObject(parent), network_(network), name_(name), enabled_(enabled), order_(0), authentication_required_(authentication_required) {}
|
||||
|
||||
@@ -31,11 +31,13 @@
|
||||
|
||||
#include "lyricsfetcher.h"
|
||||
|
||||
class NetworkAccessManager;
|
||||
|
||||
class LyricsProvider : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, QObject *parent);
|
||||
explicit LyricsProvider(const QString &name, const bool enabled, const bool authentication_required, NetworkAccessManager *network, QObject *parent);
|
||||
|
||||
typedef QPair<QString, QString> Param;
|
||||
typedef QList<Param> ParamList;
|
||||
@@ -62,7 +64,8 @@ class LyricsProvider : public QObject {
|
||||
void AuthenticationFailure(QStringList);
|
||||
void SearchFinished(quint64 id, LyricsSearchResults results);
|
||||
|
||||
private:
|
||||
protected:
|
||||
NetworkAccessManager *network_;
|
||||
QString name_;
|
||||
bool enabled_;
|
||||
int order_;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include "lyricsprovider.h"
|
||||
#include "lyricsproviders.h"
|
||||
|
||||
@@ -38,7 +40,7 @@
|
||||
|
||||
int LyricsProviders::NextOrderId = 0;
|
||||
|
||||
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent) {}
|
||||
LyricsProviders::LyricsProviders(QObject *parent) : QObject(parent), network_(new NetworkAccessManager(this)) {}
|
||||
|
||||
LyricsProviders::~LyricsProviders() {
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QString>
|
||||
#include <QAtomicInt>
|
||||
|
||||
class NetworkAccessManager;
|
||||
class LyricsProvider;
|
||||
|
||||
class LyricsProviders : public QObject {
|
||||
@@ -48,6 +49,8 @@ class LyricsProviders : public QObject {
|
||||
bool HasAnyProviders() const { return !lyrics_providers_.isEmpty(); }
|
||||
int NextId();
|
||||
|
||||
NetworkAccessManager *network() const { return network_; }
|
||||
|
||||
private slots:
|
||||
void ProviderDestroyed();
|
||||
|
||||
@@ -56,6 +59,8 @@ class LyricsProviders : public QObject {
|
||||
|
||||
static int NextOrderId;
|
||||
|
||||
NetworkAccessManager *network_;
|
||||
|
||||
QMap<LyricsProvider*, QString> lyrics_providers_;
|
||||
QList<LyricsProvider*> ordered_providers_;
|
||||
QMutex mutex_;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QRegularExpression>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
@@ -40,7 +39,7 @@
|
||||
#include "lyricsprovider.h"
|
||||
#include "musixmatchlyricsprovider.h"
|
||||
|
||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
MusixmatchLyricsProvider::MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Musixmatch", true, false, network, parent) {}
|
||||
|
||||
MusixmatchLyricsProvider::~MusixmatchLyricsProvider() {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MusixmatchLyricsProvider(QObject *parent = nullptr);
|
||||
explicit MusixmatchLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~MusixmatchLyricsProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
|
||||
@@ -51,7 +51,6 @@ class MusixmatchLyricsProvider : public JsonLyricsProvider {
|
||||
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &album, const QString &title);
|
||||
|
||||
private:
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QJsonObject>
|
||||
@@ -39,7 +38,7 @@
|
||||
|
||||
const char *OVHLyricsProvider::kUrlSearch = "https://api.lyrics.ovh/v1/";
|
||||
|
||||
OVHLyricsProvider::OVHLyricsProvider(QObject *parent) : JsonLyricsProvider("Lyrics.ovh", true, false, parent), network_(new NetworkAccessManager(this)) {}
|
||||
OVHLyricsProvider::OVHLyricsProvider(NetworkAccessManager *network, QObject *parent) : JsonLyricsProvider("Lyrics.ovh", true, false, network, parent) {}
|
||||
|
||||
OVHLyricsProvider::~OVHLyricsProvider() {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class OVHLyricsProvider : public JsonLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OVHLyricsProvider(QObject *parent = nullptr);
|
||||
explicit OVHLyricsProvider(NetworkAccessManager *network, QObject *parent = nullptr);
|
||||
~OVHLyricsProvider() override;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) override;
|
||||
@@ -51,7 +51,6 @@ class OVHLyricsProvider : public JsonLyricsProvider {
|
||||
|
||||
private:
|
||||
static const char *kUrlSearch;
|
||||
NetworkAccessManager *network_;
|
||||
QList<QNetworkReply*> replies_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user