File indexing completed on 2024-05-19 04:48:28
0001 #pragma once 0002 0003 #include <QDomDocument> 0004 #include <QJsonDocument> 0005 #include <QObject> 0006 #include <QUrl> 0007 #include <QVariantMap> 0008 0009 #include "../utils/bae.h" 0010 #include "enums.h" 0011 0012 #define ERROR(request) \ 0013 { \ 0014 emit this->error(request); \ 0015 return; \ 0016 } 0017 0018 class Service : public QObject 0019 { 0020 Q_OBJECT 0021 0022 private: 0023 public: 0024 explicit Service(QObject *parent = nullptr); 0025 0026 protected: 0027 PULPO::REQUEST request; // the main request. the track info, the ontology and info type 0028 PULPO::SCOPE scope; // what ontology and info can the service parse 0029 PULPO::RESPONSES responses; 0030 0031 void parse(const QByteArray &array); 0032 0033 virtual void set(const PULPO::REQUEST &request); 0034 virtual void parseArtist(const QByteArray &array) 0035 { 0036 Q_UNUSED(array) 0037 } 0038 virtual void parseAlbum(const QByteArray &array) 0039 { 0040 Q_UNUSED(array) 0041 } 0042 virtual void parseTrack(const QByteArray &array) 0043 { 0044 Q_UNUSED(array) 0045 } 0046 0047 void retrieve(const QString &url, const QMap<QString, QString> &headers = {}); 0048 0049 static PULPO::RESPONSE packResponse(const PULPO::ONTOLOGY &ontology, const PULPO::INFO &info, const PULPO::VALUE &value); 0050 0051 bool scopePass(); 0052 0053 Q_SIGNALS: 0054 void arrayReady(QByteArray array); 0055 void responseReady(PULPO::REQUEST request, PULPO::RESPONSES responses); 0056 void error(PULPO::REQUEST request); 0057 };