TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicbackgroundremotewidget.cpp
Go to the documentation of this file.
6 #include "musicextractmanager.h"
7 #include "musicwidgetheaders.h"
8 #include "musicwidgetutils.h"
9 
10 #include <QDir>
11 
13  : QWidget(parent),
14  m_tryTimes(3),
15  m_currentIndex(-1),
16  m_downloadRequest(nullptr)
17 {
18  QHBoxLayout *hbox = new QHBoxLayout(this);
19  hbox->setContentsMargins(0, 0, 0, 0);
20  hbox->setSpacing(0);
21 
23  hbox->addWidget(m_backgroundList);
24  setLayout(hbox);
25 
27  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), SLOT(downLoadFinished(QString)));
28  connect(m_backgroundList, SIGNAL(itemClicked(int,QString)), parent, SLOT(remoteListWidgetItemClicked(int,QString)));
29 }
30 
32 {
33  abort();
34  delete m_backgroundList;
35  delete m_networkRequest;
36  delete m_downloadRequest;
37 }
38 
40 {
42 }
43 
45 {
46  if(m_groups.isEmpty())
47  {
48  return;
49  }
50 
52  outputRemoteSkin(image, bytes);
53  if(!image.isValid())
54  {
55  image.m_pix = QPixmap(":/image/lb_none_image");
56  }
57 
58  m_backgroundList->updateItem(image, bytes);
59 }
60 
61 void MusicBackgroundRemoteWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
62 {
63  m_groups = bytes;
64 }
65 
67 {
68  if(m_groups.isEmpty())
69  {
70  return;
71  }
72 
73  const QString &path = QString("%1%2").arg(CACHE_DIR_FULL, m_groups[m_currentIndex].m_group);
74  QDir().mkpath(path);
75 
77 
78  MusicDownloadQueueDataList datas;
79  for(const MusicSkinRemoteItem &item : qAsConst(m_groups[m_currentIndex].m_items))
80  {
81  m_backgroundList->addCellItem(":/image/lb_none_image", false);
83  data.m_url = item.m_url;
84  data.m_path = QString("%1/%2%3").arg(path).arg(item.m_index).arg(prefix);
85  datas << data;
86  }
87 
88  m_networkRequest->addQueue(datas);
90 }
91 
92 
93 
96 {
97  m_currentIndex = 0;
99 }
100 
102 {
103  if(!m_downloadRequest)
104  {
106  connect(m_downloadRequest, SIGNAL(downLoadDataChanged(MusicSkinRemoteGroupList)), SLOT(downLoadFinished(MusicSkinRemoteGroupList)));
108  }
109  else
110  {
112  }
113 }
114 
116 {
117  if(m_groups.isEmpty() || m_currentIndex < 0)
118  {
119  return;
120  }
121 
122  for(const MusicSkinRemoteItem &item : qAsConst(m_groups[m_currentIndex].m_items))
123  {
124  if(QFileInfo(data).baseName().toInt() == item.m_index)
125  {
126  image.m_item.m_name = item.m_name;
127  image.m_item.m_useCount = item.m_useCount;
128  image.m_pix = QPixmap(data);
129  break;
130  }
131  }
132 }
133 
134 void MusicBackgroundDailyWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
135 {
136  if(bytes.isEmpty() && m_tryTimes-- > 0)
137  {
138  TTK_INFO_STREAM("Retry to request daily skin data");
140  return;
141  }
142 
145 }
146 
147 
148 
150  : MusicBackgroundRemoteWidget(parent),
151  m_functionsWidget(nullptr)
152 {
154 }
155 
157 {
158  delete m_functionsWidget;
159 }
160 
162 {
163  if(m_typeBox->count() != 0)
164  {
165  m_typeBox->setCurrentIndex(0);
166  }
167 
168  if(!m_downloadRequest)
169  {
171  connect(m_downloadRequest, SIGNAL(downLoadDataChanged(MusicSkinRemoteGroupList)), SLOT(downLoadFinished(MusicSkinRemoteGroupList)));
173  }
174  else
175  {
177  }
178 }
179 
180 QWidget* MusicBackgroundOnlineWidget::createFunctionsWidget(bool revert, QWidget *object)
181 {
182  if(!m_functionsWidget)
183  {
184  m_functionsWidget = new QWidget(object);
185  m_functionsWidget->setGeometry(24, 70, 585, 25);
186  m_functionsWidget->hide();
187 
188  QHBoxLayout *hbox = new QHBoxLayout(m_functionsWidget);
189  hbox->setContentsMargins(9, 0, 0, 9);
190  hbox->addStretch(1);
191 
192  m_typeBox = new QComboBox(m_functionsWidget);
193  m_typeBox->setFixedSize(100, 20);
194  m_typeBox->addItem(tr("Select One"));
195  m_typeBox->hide();
197 
198  m_functionsWidget->setLayout(hbox);
199  connect(m_typeBox, SIGNAL(currentIndexChanged(int)), SLOT(currentTypeChanged(int)));
200  }
201 
202  QHBoxLayout *layout = TTKObjectCast(QHBoxLayout*, m_functionsWidget->layout());
203  if(revert)
204  {
205  layout->removeWidget(m_typeBox);
206  m_typeBox->hide();
207  }
208  else
209  {
210  layout->addWidget(m_typeBox);
211  m_typeBox->show();
212  }
213 
214  return m_functionsWidget;
215 }
216 
218 {
219  if(m_groups.isEmpty() || m_currentIndex < 0)
220  {
221  return;
222  }
223 
224  const int index = QFileInfo(data).baseName().toInt();
225  MusicSkinRemoteItemList &items = m_groups[m_currentIndex].m_items;
226  if(index >= 0 || index < items.count())
227  {
228  MusicSkinRemoteItem &item = items[index];
229  image.m_item.m_name = item.m_name;
230  image.m_item.m_useCount = item.m_useCount;
232  }
233 }
234 
236 {
237  index -= 1; // remove first index because it is tips
238  if(index < 0 || index >= m_groups.count())
239  {
240  return;
241  }
242 
243  if(m_currentIndex != index)
244  {
246  }
247 
248  m_currentIndex = index;
250 }
251 
252 void MusicBackgroundOnlineWidget::downLoadFinished(const MusicSkinRemoteGroupList &bytes)
253 {
254  if(bytes.isEmpty() && m_tryTimes-- > 0)
255  {
256  TTK_INFO_STREAM("Retry to request online skin data");
258  return;
259  }
260 
262  m_typeBox->blockSignals(true);
263 
264  for(int i = 0; i < bytes.count(); ++i)
265  {
266  QString title(m_groups[i].m_group);
267  m_typeBox->addItem(title.remove(SKIN_THUNDER_DIR));
268  }
269 
270  m_typeBox->setCurrentIndex(0);
271  m_typeBox->blockSignals(false);
272 }
The class of the remote background widget.
The class of the remote skin item.
#define CACHE_DIR_FULL
Definition: musicobject.h:144
MusicBackgroundDailyWidget(QWidget *parent=nullptr)
MusicDownloadQueueRequest * m_networkRequest
TTK_MODULE_EXPORT void generateComboBoxStyle(QComboBox *widget, const QString &style={})
void addQueue(const MusicDownloadQueueDataList &datas) noexcept
void setType(Module type) noexcept
The class of the download data from queue request.
void addCellItem(const QString &icon, bool state)
static bool outputThunderSkin(QPixmap &image, const QString &input)
The class of the background list widget.
The class of the download bing daily skin background.
static constexpr const char * SKIN_THUNDER_DIR
#define qAsConst
Definition: ttkqtglobal.h:57
The class of the skin backgroud image.
void updateItem(const MusicBackgroundImage &image, const QString &path)
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
virtual void downLoadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
The class of the download thunder skin background.
QWidget * createFunctionsWidget(bool revert, QWidget *object=nullptr)
MusicBackgroundRemoteWidget(QWidget *parent=nullptr)
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data)=0
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data) overridefinal
void downLoadFinished(const QString &bytes)
virtual void startToRequest() overridefinal
The class of the download queue data.
#define TKM_FILE
Definition: musicobject.h:66
void startToRequest(const QString &suffix)
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data) overridefinal
MusicAbstractDownloadSkinRequest * m_downloadRequest
MusicBackgroundOnlineWidget(QWidget *parent=nullptr)
QString m_path
download url/
MusicBackgroundListWidget * m_backgroundList
virtual void downLoadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:82