Fix discogs album cover fetching. Remove QJSON dependency.
This commit is contained in:
@@ -34,7 +34,7 @@ class QNetworkAccessManager;
|
||||
|
||||
// This struct represents a single search-for-cover request. It identifies and describes the request.
|
||||
struct DiscogsCoverSearchContext {
|
||||
enum State { State_Init, State_MastersRequested, State_ReleasesRequested };
|
||||
enum State { State_Init, State_Release };
|
||||
|
||||
// the unique request identifier
|
||||
int id;
|
||||
@@ -42,6 +42,8 @@ struct DiscogsCoverSearchContext {
|
||||
// the search query
|
||||
QString artist;
|
||||
QString album;
|
||||
QString title;
|
||||
int r_count;
|
||||
|
||||
State state;
|
||||
|
||||
@@ -49,13 +51,32 @@ struct DiscogsCoverSearchContext {
|
||||
};
|
||||
Q_DECLARE_METATYPE(DiscogsCoverSearchContext)
|
||||
|
||||
struct DiscogsCoverReleaseContext {
|
||||
//enum State { State_Init, State_MastersRequested, State_ReleasesRequested };
|
||||
|
||||
int id; // the unique request identifier
|
||||
int s_id; // the search request identifier
|
||||
|
||||
// the search query
|
||||
//QString artist;
|
||||
//QString album;
|
||||
//QString title;
|
||||
QString resource_url;
|
||||
|
||||
//State state;
|
||||
|
||||
//CoverSearchResults results;
|
||||
};
|
||||
Q_DECLARE_METATYPE(DiscogsCoverReleaseContext)
|
||||
|
||||
class DiscogsCoverProvider : public CoverProvider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DiscogsCoverProvider(QObject *parent = nullptr);
|
||||
|
||||
static const char *kUrl;
|
||||
static const char *kUrlSearch;
|
||||
static const char *kUrlReleases;
|
||||
|
||||
static const char *kRequestTokenURL;
|
||||
static const char *kAuthorizeURL;
|
||||
@@ -67,22 +88,27 @@ class DiscogsCoverProvider : public CoverProvider {
|
||||
static const char *kAccessKeyB64;
|
||||
static const char *kSecretAccessKeyB64;
|
||||
|
||||
bool StartSearch(const QString &artist, const QString &album, int id);
|
||||
bool StartSearch(const QString &artist, const QString &album, int s_id);
|
||||
|
||||
void CancelSearch(int id);
|
||||
|
||||
private slots:
|
||||
void QueryError(QNetworkReply::NetworkError error, QNetworkReply *reply, int id);
|
||||
void HandleSearchReply(QNetworkReply* reply, int id);
|
||||
void SearchRequestError(QNetworkReply::NetworkError error, QNetworkReply *reply, int s_id);
|
||||
void ReleaseRequestError(QNetworkReply::NetworkError error, QNetworkReply *reply, int s_id, int r_id);
|
||||
void HandleSearchReply(QNetworkReply *reply, int s_id);
|
||||
void HandleReleaseReply(QNetworkReply *reply, int sa_id, int si_id);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *network_;
|
||||
QHash<int, DiscogsCoverSearchContext*> pending_requests_;
|
||||
QHash<int, DiscogsCoverSearchContext*> requests_search_;
|
||||
QHash<int, DiscogsCoverReleaseContext*> requests_release_;
|
||||
|
||||
bool StartRelease(DiscogsCoverSearchContext *s_ctx, int r_id, QString resource_url);
|
||||
|
||||
void SendSearchRequest(DiscogsCoverSearchContext *ctx);
|
||||
void ReadItem(QXmlStreamReader *reader, CoverSearchResults *results);
|
||||
void ReadLargeImage(QXmlStreamReader *reader, CoverSearchResults *results);
|
||||
void QueryFinished(QNetworkReply *reply, int id);
|
||||
void EndSearch(DiscogsCoverSearchContext *ctx);
|
||||
void SendSearchRequest(DiscogsCoverSearchContext *s_ctx);
|
||||
void SendReleaseRequest(DiscogsCoverSearchContext *s_ctx, DiscogsCoverReleaseContext *r_ctx);
|
||||
void EndSearch(DiscogsCoverSearchContext *s_ctx, DiscogsCoverReleaseContext *r_ctx);
|
||||
void EndSearch(DiscogsCoverSearchContext *s_ctx);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user