Change to const QString&
This commit is contained in:
parent
f9cd2639ff
commit
b9f4407815
@ -53,7 +53,7 @@ const int AuddLyricsProvider::kMaxLength = 6000;
|
|||||||
|
|
||||||
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : LyricsProvider("AudD", parent), network_(new NetworkAccessManager(this)) {}
|
AuddLyricsProvider::AuddLyricsProvider(QObject *parent) : LyricsProvider("AudD", parent), network_(new NetworkAccessManager(this)) {}
|
||||||
|
|
||||||
bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id) {
|
bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||||
|
|
||||||
const ParamList params = ParamList() << Param("api_token", QByteArray::fromBase64(kAPITokenB64))
|
const ParamList params = ParamList() << Param("api_token", QByteArray::fromBase64(kAPITokenB64))
|
||||||
<< Param("q", QString(artist + " " + title));
|
<< Param("q", QString(artist + " " + title));
|
||||||
@ -66,7 +66,7 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
|
|||||||
QUrl url(kUrlSearch);
|
QUrl url(kUrlSearch);
|
||||||
url.setQuery(url_query);
|
url.setQuery(url_query);
|
||||||
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
||||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
|
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, const quint64, const QString&, const QString&)), reply, id, artist, title);
|
||||||
|
|
||||||
//qLog(Debug) << "AudDLyrics: Sending request for" << url;
|
//qLog(Debug) << "AudDLyrics: Sending request for" << url;
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ bool AuddLyricsProvider::StartSearch(const QString &artist, const QString &album
|
|||||||
void AuddLyricsProvider::CancelSearch(quint64 id) {
|
void AuddLyricsProvider::CancelSearch(quint64 id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, const QString artist, const QString title) {
|
void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ void AuddLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, con
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject AuddLyricsProvider::ExtractJsonObj(QNetworkReply *reply, quint64 id) {
|
QJsonObject AuddLyricsProvider::ExtractJsonObj(QNetworkReply *reply, const quint64 id) {
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
QString failure_reason = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
QString failure_reason = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||||
@ -206,7 +206,7 @@ QJsonArray AuddLyricsProvider::ExtractResult(QNetworkReply *reply, const quint64
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuddLyricsProvider::Error(quint64 id, QString error, QVariant debug) {
|
void AuddLyricsProvider::Error(const quint64 id, const QString &error, QVariant debug) {
|
||||||
qLog(Error) << "AudDLyrics:" << error;
|
qLog(Error) << "AudDLyrics:" << error;
|
||||||
if (debug.isValid()) qLog(Debug) << debug;
|
if (debug.isValid()) qLog(Debug) << debug;
|
||||||
LyricsSearchResults results;
|
LyricsSearchResults results;
|
||||||
|
@ -44,16 +44,16 @@ class AuddLyricsProvider : public LyricsProvider {
|
|||||||
void CancelSearch(quint64 id);
|
void CancelSearch(quint64 id);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void HandleSearchReply(QNetworkReply *reply, quint64 id, const QString artist, const QString title);
|
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char *kUrlSearch;
|
static const char *kUrlSearch;
|
||||||
static const char *kAPITokenB64;
|
static const char *kAPITokenB64;
|
||||||
static const int kMaxLength;
|
static const int kMaxLength;
|
||||||
QNetworkAccessManager *network_;
|
QNetworkAccessManager *network_;
|
||||||
void Error(quint64 id, QString error, QVariant debug = QVariant());
|
void Error(const quint64 id, const QString &error, QVariant debug = QVariant());
|
||||||
|
|
||||||
QJsonObject ExtractJsonObj(QNetworkReply *reply, quint64 id);
|
QJsonObject ExtractJsonObj(QNetworkReply *reply, const quint64 id);
|
||||||
QJsonArray ExtractResult(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
QJsonArray ExtractResult(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ const int ChartLyricsProvider::kMaxLength = 6000;
|
|||||||
|
|
||||||
ChartLyricsProvider::ChartLyricsProvider(QObject *parent) : LyricsProvider("ChartLyrics", parent), network_(new NetworkAccessManager(this)) {}
|
ChartLyricsProvider::ChartLyricsProvider(QObject *parent) : LyricsProvider("ChartLyrics", parent), network_(new NetworkAccessManager(this)) {}
|
||||||
|
|
||||||
bool ChartLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id) {
|
bool ChartLyricsProvider::StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) {
|
||||||
|
|
||||||
const ParamList params = ParamList() << Param("artist", artist)
|
const ParamList params = ParamList() << Param("artist", artist)
|
||||||
<< Param("song", title);
|
<< Param("song", title);
|
||||||
@ -58,7 +58,7 @@ bool ChartLyricsProvider::StartSearch(const QString &artist, const QString &albu
|
|||||||
QUrl url(kUrlSearch);
|
QUrl url(kUrlSearch);
|
||||||
url.setQuery(url_query);
|
url.setQuery(url_query);
|
||||||
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
QNetworkReply *reply = network_->get(QNetworkRequest(url));
|
||||||
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, quint64, QString, QString)), reply, id, artist, title);
|
NewClosure(reply, SIGNAL(finished()), this, SLOT(HandleSearchReply(QNetworkReply*, const quint64, const QString&, const QString&)), reply, id, artist, title);
|
||||||
|
|
||||||
//qLog(Debug) << "ChartLyrics: Sending request for" << url;
|
//qLog(Debug) << "ChartLyrics: Sending request for" << url;
|
||||||
|
|
||||||
@ -66,10 +66,10 @@ bool ChartLyricsProvider::StartSearch(const QString &artist, const QString &albu
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartLyricsProvider::CancelSearch(quint64 id) {
|
void ChartLyricsProvider::CancelSearch(const quint64 id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, const QString artist, const QString title) {
|
void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title) {
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ void ChartLyricsProvider::HandleSearchReply(QNetworkReply *reply, quint64 id, co
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartLyricsProvider::Error(quint64 id, QString error, QVariant debug) {
|
void ChartLyricsProvider::Error(const quint64 id, const QString &error, QVariant debug) {
|
||||||
qLog(Error) << "ChartLyrics:" << error;
|
qLog(Error) << "ChartLyrics:" << error;
|
||||||
if (debug.isValid()) qLog(Debug) << debug;
|
if (debug.isValid()) qLog(Debug) << debug;
|
||||||
LyricsSearchResults results;
|
LyricsSearchResults results;
|
||||||
|
@ -39,17 +39,17 @@ class ChartLyricsProvider : public LyricsProvider {
|
|||||||
public:
|
public:
|
||||||
explicit ChartLyricsProvider(QObject *parent = nullptr);
|
explicit ChartLyricsProvider(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id);
|
bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id);
|
||||||
void CancelSearch(quint64 id);
|
void CancelSearch(quint64 id);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void HandleSearchReply(QNetworkReply *reply, quint64 id, const QString artist, const QString title);
|
void HandleSearchReply(QNetworkReply *reply, const quint64 id, const QString &artist, const QString &title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char *kUrlSearch;
|
static const char *kUrlSearch;
|
||||||
static const int kMaxLength;
|
static const int kMaxLength;
|
||||||
QNetworkAccessManager *network_;
|
QNetworkAccessManager *network_;
|
||||||
void Error(quint64 id, QString error, QVariant debug = QVariant());
|
void Error(const quint64 id, const QString &error, QVariant debug = QVariant());
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ void LyricsFetcher::StartRequests() {
|
|||||||
LyricsFetcherSearch *search = new LyricsFetcherSearch(request, this);
|
LyricsFetcherSearch *search = new LyricsFetcherSearch(request, this);
|
||||||
active_requests_.insert(request.id, search);
|
active_requests_.insert(request.id, search);
|
||||||
|
|
||||||
connect(search, SIGNAL(SearchFinished(const quint64, LyricsSearchResults)), SLOT(SingleSearchFinished(const quint64, LyricsSearchResults)));
|
connect(search, SIGNAL(SearchFinished(const quint64, const LyricsSearchResults&)), SLOT(SingleSearchFinished(const quint64, const LyricsSearchResults&)));
|
||||||
connect(search, SIGNAL(LyricsFetched(const quint64, const QString&, const QString&)), SLOT(SingleLyricsFetched(const quint64, const QString&, const QString&)));
|
connect(search, SIGNAL(LyricsFetched(const quint64, const QString&, const QString&)), SLOT(SingleLyricsFetched(const quint64, const QString&, const QString&)));
|
||||||
|
|
||||||
search->Start(lyrics_providers_);
|
search->Start(lyrics_providers_);
|
||||||
@ -102,7 +102,7 @@ void LyricsFetcher::StartRequests() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LyricsFetcher::SingleSearchFinished(const quint64 request_id, LyricsSearchResults results) {
|
void LyricsFetcher::SingleSearchFinished(const quint64 request_id, const LyricsSearchResults &results) {
|
||||||
|
|
||||||
LyricsFetcherSearch *search = active_requests_.take(request_id);
|
LyricsFetcherSearch *search = active_requests_.take(request_id);
|
||||||
if (!search) return;
|
if (!search) return;
|
||||||
|
@ -73,7 +73,7 @@ signals:
|
|||||||
void SearchFinished(const quint64 request_id, const LyricsSearchResults &results);
|
void SearchFinished(const quint64 request_id, const LyricsSearchResults &results);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void SingleSearchFinished(const quint64 request_id, LyricsSearchResults results);
|
void SingleSearchFinished(const quint64 request_id, const LyricsSearchResults &results);
|
||||||
void SingleLyricsFetched(const quint64 request_id, const QString &provider, const QString &lyrics);
|
void SingleLyricsFetched(const quint64 request_id, const QString &provider, const QString &lyrics);
|
||||||
void StartRequests();
|
void StartRequests();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void LyricsFetcherSearch::TerminateSearch() {
|
|||||||
void LyricsFetcherSearch::Start(LyricsProviders *lyrics_providers) {
|
void LyricsFetcherSearch::Start(LyricsProviders *lyrics_providers) {
|
||||||
|
|
||||||
for (LyricsProvider *provider : lyrics_providers->List()) {
|
for (LyricsProvider *provider : lyrics_providers->List()) {
|
||||||
connect(provider, SIGNAL(SearchFinished(const quint64, QList<LyricsSearchResult>)), SLOT(ProviderSearchFinished(const quint64, QList<LyricsSearchResult>)));
|
connect(provider, SIGNAL(SearchFinished(const quint64, const LyricsSearchResults&)), SLOT(ProviderSearchFinished(const quint64, const LyricsSearchResults&)));
|
||||||
const int id = lyrics_providers->NextId();
|
const int id = lyrics_providers->NextId();
|
||||||
const bool success = provider->StartSearch(request_.artist, request_.album, request_.title, id);
|
const bool success = provider->StartSearch(request_.artist, request_.album, request_.title, id);
|
||||||
if (success) pending_requests_[id] = provider;
|
if (success) pending_requests_[id] = provider;
|
||||||
@ -69,7 +69,7 @@ void LyricsFetcherSearch::Start(LyricsProviders *lyrics_providers) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LyricsFetcherSearch::ProviderSearchFinished(const quint64 id, const QList<LyricsSearchResult> &results) {
|
void LyricsFetcherSearch::ProviderSearchFinished(const quint64 id, const LyricsSearchResults &results) {
|
||||||
|
|
||||||
if (!pending_requests_.contains(id)) return;
|
if (!pending_requests_.contains(id)) return;
|
||||||
LyricsProvider *provider = pending_requests_.take(id);
|
LyricsProvider *provider = pending_requests_.take(id);
|
||||||
|
@ -48,7 +48,7 @@ class LyricsFetcherSearch : public QObject {
|
|||||||
void LyricsFetched(const quint64, const QString &provider, const QString &lyrics);
|
void LyricsFetched(const quint64, const QString &provider, const QString &lyrics);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void ProviderSearchFinished(const quint64 id, const QList<LyricsSearchResult> &results);
|
void ProviderSearchFinished(const quint64 id, const LyricsSearchResults &results);
|
||||||
void TerminateSearch();
|
void TerminateSearch();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
struct LyricsSearchResult;
|
#include "lyricsfetcher.h"
|
||||||
|
|
||||||
class LyricsProvider : public QObject {
|
class LyricsProvider : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -41,11 +41,11 @@ class LyricsProvider : public QObject {
|
|||||||
|
|
||||||
QString name() const { return name_; }
|
QString name() const { return name_; }
|
||||||
|
|
||||||
virtual bool StartSearch(const QString &artist, const QString &album, const QString &title, quint64 id) = 0;
|
virtual bool StartSearch(const QString &artist, const QString &album, const QString &title, const quint64 id) = 0;
|
||||||
virtual void CancelSearch(quint64 id) {}
|
virtual void CancelSearch(const quint64 id) {}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SearchFinished(quint64 id, const QList<LyricsSearchResult>& results);
|
void SearchFinished(const quint64 id, const LyricsSearchResults &results);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user