TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicabstractdownloadrequest.cpp
Go to the documentation of this file.
2 #include "musicdownloadmanager.h"
3 #include "musiccoreutils.h"
4 
5 MusicAbstractDownLoadRequest::MusicAbstractDownLoadRequest(const QString &url, const QString &path, TTK::Download type, QObject *parent)
6  : MusicAbstractNetwork(parent),
7  m_url(url),
8  m_savePath(path),
9  m_downloadType(type),
10  m_hasReceived(0),
11  m_currentReceived(0)
12 {
13  if(QFile::exists(m_savePath))
14  {
15  QFile::remove(m_savePath);
16  }
17  m_file = new QFile(m_savePath, this);
18 
19  G_DOWNLOAD_MANAGER_PTR->connectNetworkMultiValue(this);
20 
21  m_speedTimer.setInterval(TTK_DN_S2MS);
22  connect(&m_speedTimer, SIGNAL(timeout()), SLOT(updateDownloadSpeed()));
23 }
24 
26 {
27  if(m_speedTimer.isActive())
28  {
29  m_speedTimer.stop();
30  }
31  G_DOWNLOAD_MANAGER_PTR->removeNetworkMultiValue(this);
32 }
33 
35 {
37  delete m_file;
38  m_file = nullptr;
39  deleteLater();
40 }
41 
43 {
45  m_speedTimer.stop();
46 }
47 
48 void MusicAbstractDownLoadRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
49 {
50  m_currentReceived = bytesReceived;
51  m_totalSize = bytesTotal;
52 }
53 
55 {
56  const int delta = m_currentReceived - m_hasReceived;
59  {
60  const int limitValue = G_SETTING_PTR->value(MusicSettingManager::DownloadDownloadLimitSize).toInt();
61  if(limitValue != 0 && delta > limitValue * TTK_SN_KB2B)
62  {
63  TTK::Core::sleep(TTK_DN_S2MS - limitValue * TTK_SN_KB2B * TTK_DN_S2MS / delta);
64  }
65  }
66  m_hasReceived = m_currentReceived;
67 }
68 
70 {
71  switch(m_downloadType)
72  {
79  default: return {};
80  }
81 }
virtual void deleteAll()
#define G_DOWNLOAD_MANAGER_PTR
static constexpr const char * DOWNLOAD_KEY_VIDEO
virtual void downLoadFinished()
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
MusicAbstractDownLoadRequest(const QString &url, const QString &path, TTK::Download type, QObject *parent=nullptr)
static constexpr const char * DOWNLOAD_KEY_LRC
#define TTK_SN_KB2B
Definition: ttkglobal.h:309
TTK_MODULE_EXPORT void sleep(int ms)
static constexpr const char * DOWNLOAD_KEY_COVER
The class of the abstract network.
static constexpr const char * DOWNLOAD_KEY_MUSIC
#define TTK_DN_S2MS
Definition: ttkglobal.h:276
virtual void deleteAll() overridefinal
static constexpr const char * DOWNLOAD_KEY_BACKGROUND
static constexpr const char * DOWNLOAD_KEY_OTHER
#define G_SETTING_PTR