TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musickwqueryartistlistrequest.cpp
Go to the documentation of this file.
2 
5 {
8 }
9 
11 {
12  TTK_INFO_STREAM(className() << "startToPage" << offset);
13 
14  deleteAll();
15  m_totalSize = 0;
17 
18  QString catId = "0", initial;
19  const QStringList &dds = m_queryValue.split(TTK_SPLITER);
20 
21  if(dds.count() == 2)
22  {
23  catId = dds[0];
24  if(catId.isEmpty())
25  {
26  catId = "0";
27  }
28 
29  const int id = dds[1].toInt();
30  if(id > 0 && id <= 26)
31  {
32  initial = QString("&prefix=%1").arg(TTKStaticCast(char, id + 65 - 1));
33  }
34  }
35 
36  QNetworkRequest request;
37  request.setUrl(TTK::Algorithm::mdII(KW_ARTIST_LIST_URL, false).arg(catId).arg(offset).arg(m_pageSize) + initial);
39 
40  m_reply = m_manager.get(request);
41  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
43 }
44 
46 {
47  TTK_INFO_STREAM(className() << "downLoadFinished");
48 
50  if(m_reply && m_reply->error() == QNetworkReply::NoError)
51  {
52  QJson::Parser json;
53  bool ok = false;
54  const QVariant &data = json.parse(m_reply->readAll().replace("'", "\""), &ok);
55  if(ok)
56  {
57  QVariantMap value = data.toMap();
58  if(value.contains("artistlist"))
59  {
60  m_totalSize = value["total"].toInt();
61 
62  const QVariantList &datas = value["artistlist"].toList();
63  for(const QVariant &var : qAsConst(datas))
64  {
65  if(var.isNull())
66  {
67  continue;
68  }
69 
70  value = var.toMap();
72 
74  item.m_id = value["id"].toString();
75  item.m_name = value["name"].toString();
76  Q_EMIT createArtistListItem(item);
77  }
78  }
79  }
80  }
81 
82 // Q_EMIT downLoadDataChanged({});
83  deleteAll();
84 }
MusicKWQueryArtistListRequest(QObject *parent=nullptr)
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
#define TTK_NETWORK_QUERY_CHECK(VALUE)
#define ARTIST_LIST_PAGE_SIZE
The class of the search result data item.
virtual void deleteAll()
QNetworkReply * m_reply
#define TTK_SPLITER
Definition: ttkglobal.h:199
The class of the query artist list download data from net.
void makeRequestRawHeader(QNetworkRequest *request)
voidpf uLong offset
Definition: ioapi.h:142
#define qAsConst
Definition: ttkqtglobal.h:53
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
static constexpr const char * KW_ARTIST_LIST_URL
QNetworkAccessManager m_manager
virtual void downLoadFinished() overridefinal
virtual void replyError(QNetworkReply::NetworkError error) override
QVariant parse(QIODevice *io, bool *ok=0)
Read JSON string from the I/O Device and converts it to a QVariant object.
Definition: parser.cpp:69
static constexpr const char * QUERY_KW_INTERFACE
#define TTK_SLOT
Definition: ttkqtglobal.h:165
virtual void downLoadFinished() override
virtual void startToPage(int offset) overridefinal
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
void createArtistListItem(const MusicResultDataItem &item)
TTK_MODULE_EXPORT QString mdII(const QString &data, bool encode)
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59