TTKMusicPlayer  4.1.3.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);
41  connect(d, SIGNAL(downLoadDataChanged(QString)), SLOT(currentMetaDataDownload()));
42 }
43 
45 {
47  if(!G_NETWORK_PTR->isOnline() || !d) //no network connection
48  {
49  return;
50  }
51 
52  const TTK::MusicSongInformationList &songInfos = d->items();
53  if(songInfos.isEmpty())
54  {
55  showDownLoadInfoFinished("find error");
56  return;
57  }
58 
59  const QString &fileName = d->queryValue();
60  const QString &songName = TTK::generateSongTitle(fileName);
61  const QString &artistName = TTK::generateSongArtist(fileName);
62 
63  TTK::MusicSongInformation info = songInfos.front();
64  for(const TTK::MusicSongInformation &var : qAsConst(songInfos))
65  {
66  if(var.m_artistName.contains(artistName, Qt::CaseInsensitive) && var.m_songName.contains(songName, Qt::CaseInsensitive))
67  {
68  info = var;
69  break;
70  }
71  }
72 
73  const bool mode = d->header("mode").toBool();
74  if(mode || !checkLrcValid())
75  {
77  G_DOWNLOAD_QUERY_PTR->makeLrcRequest(info.m_lrcUrl, TTK::String::lrcDirPrefix() + fileName + LRC_FILE, this)->startToRequest();
78  }
79 
80  if(mode || !checkArtistCoverValid())
81  {
83  G_DOWNLOAD_QUERY_PTR->makeCoverRequest(info.m_coverUrl, ART_DIR_FULL + artistName + SKN_FILE, this)->startToRequest();
84  }
85 
86  if(mode || !checkArtistBackgroundValid())
87  {
89  const int count = TTK::String::split(fileName).count();
90  G_DOWNLOAD_QUERY_PTR->makeBackgroundRequest(count == 1 ? info.m_artistName : artistName, artistName, this)->startToRequest();
91  }
92 }
93 
95 {
97  if(bytes == DOWNLOAD_KEY_LRC)
98  {
100  }
101  else if(bytes == DOWNLOAD_KEY_COVER)
102  {
104  }
105 }
106 
108 {
109  G_NETWORK_PTR->setNetWorkState(state);
110  if(m_previousState != state)
111  {
113  m_previousState ? w->showMessage(tr("TTKMusicPlayer"), tr("The Internet Seems To Be A Problem, Let's Listen To The Local Music."))
114  : w->showMessage(tr("TTKMusicPlayer"), tr("Network Connection Has Been Restored."));
115  }
117 }
118 
120 {
121  const QString &fileName = m_parent->currentFileName();
122  return QFile::exists(TTK::String::lrcDirPrefix() + fileName + LRC_FILE);
123 }
124 
126 {
127  const QString &fileName = TTK::generateSongArtist(m_parent->currentFileName());
128  return QFile::exists(ART_DIR_FULL + fileName + SKN_FILE);
129 }
130 
132 {
133  const QString &fileName = TTK::generateSongArtist(m_parent->currentFileName());
134  return QFile::exists(BACKGROUND_DIR_FULL + fileName + "-0" + SKN_FILE);
135 }
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:121
#define ART_DIR_FULL
Definition: musicobject.h:130
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:110
MusicDownloadStatusModule(QObject *parent=nullptr)
#define G_CONNECTION_PTR
#define qAsConst
Definition: ttkqtglobal.h:51
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:131
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:62
const TTK::MusicSongInformationList & items() const
#define LRC_FILE
Definition: musicobject.h:65
state
Definition: http_parser.c:279
The class of the music song information.
Definition: musicobject.h:283
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:76
QString currentFileName() const