TTKMusicPlayer  4.3.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(downloadDataChanged(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_typeBox(nullptr),
152  m_functionsWidget(nullptr)
153 {
155 }
156 
158 {
159  delete m_functionsWidget;
160 }
161 
163 {
164  if(m_typeBox->count() != 0)
165  {
166  m_typeBox->setCurrentIndex(0);
167  }
168 
169  if(!m_downloadRequest)
170  {
172  connect(m_downloadRequest, SIGNAL(downloadDataChanged(MusicSkinRemoteGroupList)), SLOT(downloadFinished(MusicSkinRemoteGroupList)));
174  }
175  else
176  {
178  }
179 }
180 
181 QWidget* MusicBackgroundOnlineWidget::createFunctionsWidget(bool revert, QWidget *object)
182 {
183  if(!m_functionsWidget)
184  {
185  m_functionsWidget = new QWidget(object);
186  m_functionsWidget->setGeometry(24, 70, 585, 25);
187  m_functionsWidget->hide();
188 
189  QHBoxLayout *hbox = new QHBoxLayout(m_functionsWidget);
190  hbox->setContentsMargins(9, 0, 0, 9);
191  hbox->addStretch(1);
192 
193  m_typeBox = new QComboBox(m_functionsWidget);
194  m_typeBox->setFixedSize(100, 20);
195  m_typeBox->addItem(tr("Select One"));
196  m_typeBox->hide();
198 
199  m_functionsWidget->setLayout(hbox);
200  connect(m_typeBox, SIGNAL(currentIndexChanged(int)), SLOT(currentTypeChanged(int)));
201  }
202 
203  QHBoxLayout *layout = TTKObjectCast(QHBoxLayout*, m_functionsWidget->layout());
204  if(revert)
205  {
206  layout->removeWidget(m_typeBox);
207  m_typeBox->hide();
208  }
209  else
210  {
211  layout->addWidget(m_typeBox);
212  m_typeBox->show();
213  }
214 
215  return m_functionsWidget;
216 }
217 
219 {
220  if(m_groups.isEmpty() || m_currentIndex < 0)
221  {
222  return;
223  }
224 
225  const int index = QFileInfo(data).baseName().toInt();
226  MusicSkinRemoteItemList &items = m_groups[m_currentIndex].m_items;
227  if(index >= 0 || index < items.count())
228  {
229  MusicSkinRemoteItem &item = items[index];
230  image.m_item.m_name = item.m_name;
231  image.m_item.m_useCount = item.m_useCount;
233  }
234 }
235 
237 {
238  index -= 1; // remove first index because it is tips
239  if(index < 0 || index >= m_groups.count())
240  {
241  return;
242  }
243 
244  if(m_currentIndex != index)
245  {
247  }
248 
249  m_currentIndex = index;
251 }
252 
253 void MusicBackgroundOnlineWidget::downloadFinished(const MusicSkinRemoteGroupList &bytes)
254 {
255  if(bytes.isEmpty() && m_tryTimes-- > 0)
256  {
257  TTK_INFO_STREAM("Retry to request online skin data");
259  return;
260  }
261 
263  m_typeBox->blockSignals(true);
264 
265  for(int i = 0; i < bytes.count(); ++i)
266  {
267  QString title(m_groups[i].m_group);
268  m_typeBox->addItem(title.remove(SKIN_THUNDER_DIR));
269  }
270 
271  m_typeBox->setCurrentIndex(0);
272  m_typeBox->blockSignals(false);
273 }
The class of the remote background widget.
The class of the remote skin item.
#define CACHE_DIR_FULL
Definition: musicobject.h:149
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.
virtual void downloadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
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)
virtual void downloadFinished(const MusicSkinRemoteGroupList &bytes) overridefinal
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:74
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
virtual void downloadFinished(const MusicSkinRemoteGroupList &bytes)
virtual void startToRequest() overridefinal
The class of the download queue data.
#define TKM_FILE
Definition: musicobject.h:67
void startToRequest(const QString &suffix)
virtual void outputRemoteSkin(MusicBackgroundImage &image, const QString &data) overridefinal
MusicAbstractDownloadSkinRequest * m_downloadRequest
MusicBackgroundOnlineWidget(QWidget *parent=nullptr)
void downloadDataChanged(const QString &bytes)
QString m_path
download url/
MusicBackgroundListWidget * m_backgroundList
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:82