TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicdownloadtextrequest.cpp
Go to the documentation of this file.
2 
3 MusicDownLoadTextRequest::MusicDownLoadTextRequest(const QString &url, const QString &path, QObject *parent)
4  : MusicAbstractDownLoadRequest(url, path, TTK::Download::Lrc, parent)
5 {
6 
7 }
8 
10 {
11  if(!m_file || (m_file->exists() && m_file->size() >= 4) || !m_file->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text) || m_url.isEmpty())
12  {
13  Q_EMIT downLoadDataChanged("The text file create failed");
14  TTK_ERROR_STREAM("The text file create failed");
15  deleteAll();
16  return;
17  }
18 
19  m_speedTimer.start();
20 
21  QNetworkRequest request;
22  request.setUrl(m_url);
23  TTK::setSslConfiguration(&request);
25 
26  m_reply = m_manager.get(request);
27  connect(m_reply, SIGNAL(finished()), SLOT(downLoadFinished()));
28  connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(downloadProgress(qint64, qint64)));
30 }
31 
33 {
35  if(m_reply && m_file && m_reply->error() == QNetworkReply::NoError)
36  {
37  const QByteArray &bytes = m_reply->readAll();
38  if(!bytes.isEmpty())
39  {
40  QTextStream outstream(m_file);
41  outstream.setCodec("UTF-8");
42  outstream << QString(bytes).remove("\r").toUtf8();
43  QtStreamEndLine(outstream);
44  m_file->close();
45  TTK_INFO_STREAM("Text download has finished");
46  }
47  else
48  {
49  TTK_ERROR_STREAM("Text download file error");
50  m_file->remove();
51  m_file->close();
52  }
53  }
54 
56  deleteAll();
57 }
void downLoadDataChanged(const QString &bytes)
The class of the abstract download data.
QNetworkReply * m_reply
virtual void downLoadFinished() overridefinal
virtual void startToRequest() overridefinal
TTK_MODULE_EXPORT void setSslConfiguration(QNetworkRequest *request, QSslSocket::PeerVerifyMode mode=QSslSocket::VerifyNone)
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
#define QtStreamEndLine(p)
Stream endl.
Definition: ttkqtcompat.h:115
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
The namespace of the process utils.
Definition: ttkcompat.h:24
QNetworkAccessManager m_manager
virtual void replyError(QNetworkReply::NetworkError error) override
#define TTK_SLOT
Definition: ttkqtglobal.h:165
TTK_MODULE_EXPORT void makeContentTypeHeader(QNetworkRequest *request, const QByteArray &data={})
MusicDownLoadTextRequest(const QString &url, const QString &path, QObject *parent=nullptr)
virtual void deleteAll() overridefinal
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
#define QtNetworkErrorConnect(p, q, f, s)
Network error connect.
Definition: ttkqtcompat.h:59