TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicdownloadstatusmodule.cpp
Go to the documentation of this file.
3 #include "musicapplication.h"
5 #include "musicconnectionpool.h"
8 #include "musicsong.h"
9 
11  : QObject(parent),
12  m_previousState(true),
13  m_parent(TTKObjectCast(MusicApplication*, parent))
14 {
15  G_CONNECTION_PTR->setValue(className(), this);
16  G_CONNECTION_PTR->connect(MusicNetworkThread::className(), className());
17 }
18 
20 {
21  if(!G_NETWORK_PTR->isOnline()) //no network connection
22  {
23  return;
24  }
25 
28  {
29  return;
30  }
31 
33  {
34  return;
35  }
36 
37  MusicAbstractQueryRequest *d = G_DOWNLOAD_QUERY_PTR->makeQueryRequest(this);
38  d->setHeader("mode", mode);
42  connect(d, SIGNAL(downLoadDataChanged(QString)), SLOT(currentMetaDataDownload()));
43 }
44 
46 {
48  if(!G_NETWORK_PTR->isOnline() || !d) //no network connection
49  {
50  return;
51  }
52 
53  const TTK::MusicSongInformationList songInfos(d->items());
54  if(songInfos.isEmpty())
55  {
56  showDownLoadInfoFinished("find error");
57  return;
58  }
59 
60  const QString &fileName = d->queryValue();
61  const QString &songName = TTK::generateSongTitle(fileName);
62  const QString &artistName = TTK::generateSongArtist(fileName);
63 
64  TTK::MusicSongInformation info = songInfos.front();
65  for(const TTK::MusicSongInformation &var : qAsConst(songInfos))
66  {
67  if(var.m_artistName.contains(artistName, Qt::CaseInsensitive) && var.m_songName.contains(songName, Qt::CaseInsensitive))
68  {
69  info = var;
70  break;
71  }
72  }
73 
74  const bool mode = d->header("mode").toBool();
75  if(mode || !checkLrcValid())
76  {
78  G_DOWNLOAD_QUERY_PTR->makeLrcRequest(info.m_lrcUrl, TTK::String::lrcDirPrefix() + fileName + LRC_FILE, this)->startToRequest();
79  }
80 
81  if(mode || !checkArtistCoverValid())
82  {
84  G_DOWNLOAD_QUERY_PTR->makeCoverRequest(info.m_coverUrl, ART_DIR_FULL + artistName + SKN_FILE, this)->startToRequest();
85  }
86 
87  if(mode || !checkArtistBackgroundValid())
88  {
90  const int count = TTK::String::split(fileName).count();
91  G_DOWNLOAD_QUERY_PTR->makeBackgroundRequest(count == 1 ? info.m_artistName : artistName, artistName, this)->startToRequest();
92  }
93 }
94 
96 {
98  if(bytes == DOWNLOAD_KEY_LRC)
99  {
101  }
102  else if(bytes == DOWNLOAD_KEY_COVER)
103  {
105  }
106 }
107 
109 {
110  G_NETWORK_PTR->setNetWorkState(state);
111  if(m_previousState != state)
112  {
114  m_previousState ? w->showMessage(tr("TTKMusicPlayer"), tr("The Internet Seems To Be A Problem, Let's Listen To The Local Music."))
115  : w->showMessage(tr("TTKMusicPlayer"), tr("Network Connection Has Been Restored."));
116  }
118 }
119 
121 {
122  const QString &fileName = m_parent->currentFileName();
123  return QFile::exists(TTK::String::lrcDirPrefix() + fileName + LRC_FILE);
124 }
125 
127 {
128  const QString &fileName = TTK::generateSongArtist(m_parent->currentFileName());
129  return QFile::exists(ART_DIR_FULL + fileName + SKN_FILE);
130 }
131 
133 {
134  const QString &fileName = TTK::generateSongArtist(m_parent->currentFileName());
135  return QFile::exists(BACKGROUND_DIR_FULL + fileName + "0" + SKN_FILE);
136 }
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:128
#define ART_DIR_FULL
Definition: musicobject.h:128
static MusicBottomAreaWidget * instance()
The class of the app main widget.
TTK_MODULE_EXPORT QString generateSongTitle(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:117
MusicDownloadStatusModule(QObject *parent=nullptr)
#define G_CONNECTION_PTR
#define qAsConst
Definition: ttkqtglobal.h:53
static constexpr const char * DOWNLOAD_KEY_LRC
const QVariant header(const QString &key) const
void showDownLoadInfoFinished(const QString &bytes)
TTK_MODULE_EXPORT QString lrcDirPrefix()
#define BACKGROUND_DIR_FULL
Definition: musicobject.h:129
TTK_MODULE_EXPORT QStringList split(const QString &value, const QString &key=TTK_DEFAULT_STR)
static constexpr const char * DOWNLOAD_KEY_COVER
The class of the app bottom area widget.
void setHeader(const QString &key, const QVariant &value)
bool checkMusicListCurrentIndex() const
#define G_NETWORK_PTR
#define G_DOWNLOAD_QUERY_PTR
const char int mode
Definition: ioapi.h:135
virtual void startToSearch(const QString &value)=0
The class of the abstract query download data from net.
void showMessage(const QString &title, const QString &text)
#define SKN_FILE
Definition: musicobject.h:61
const TTK::MusicSongInformationList & items() const
#define LRC_FILE
Definition: musicobject.h:63
state
Definition: http_parser.c:279
The class of the music song information.
Definition: musicobject.h:281
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60
QString currentFileName() const