TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongdlnatransferwidget.cpp
Go to the documentation of this file.
2 #include "ui_musicsongdlnatransferwidget.h"
4 #include "musicconnectionpool.h"
5 
6 #include "qdlna/qdlnafinder.h"
7 #include "qdlna/qdlnaclient.h"
9 
11  : MusicAbstractMoveWidget(parent),
13  m_isPlaying(false),
14  m_currentPlayIndex(-1),
15  m_songs(nullptr)
16 {
17  m_ui->setupUi(this);
18  setFixedSize(size());
19  setAttribute(Qt::WA_DeleteOnClose);
20  setBackgroundLabel(m_ui->background);
21 
22  m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
23  m_ui->topTitleCloseButton->setStyleSheet(TTK::UI::ToolButtonStyle04);
24  m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
25  m_ui->topTitleCloseButton->setToolTip(tr("Close"));
26  connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
27 
28  m_ui->iconLabel->setPixmap(QPixmap(":/contextMenu/btn_mobile"));
29  m_ui->playButton->setIcon(QIcon(":/functions/btn_play_hover"));
30  m_ui->previousButton->setIcon(QIcon(":/functions/btn_previous_hover"));
31  m_ui->nextButton->setIcon(QIcon(":/functions/btn_next_hover"));
32  m_ui->refreshButton->setIcon(QIcon(":/functions/btn_fresh_fore_hover"));
33 
34  m_ui->playButton->setStyleSheet(TTK::UI::BackgroundStyle01);
35  m_ui->previousButton->setStyleSheet(TTK::UI::BackgroundStyle01);
36  m_ui->nextButton->setStyleSheet(TTK::UI::BackgroundStyle01);
37  m_ui->refreshButton->setStyleSheet(TTK::UI::BackgroundStyle01);
38 
39 #ifdef Q_OS_UNIX
40  m_ui->playButton->setFocusPolicy(Qt::NoFocus);
41  m_ui->previousButton->setFocusPolicy(Qt::NoFocus);
42  m_ui->nextButton->setFocusPolicy(Qt::NoFocus);
43  m_ui->refreshButton->setFocusPolicy(Qt::NoFocus);
44 #endif
45 
46  m_ui->playButton->setIconSize(QSize(31, 31));
47  m_ui->previousButton->setIconSize(QSize(31, 31));
48  m_ui->nextButton->setIconSize(QSize(31, 31));
49  m_ui->refreshButton->setIconSize(QSize(20, 20));
50 
51  m_ui->playButton->setCursor(QCursor(Qt::PointingHandCursor));
52  m_ui->previousButton->setCursor(QCursor(Qt::PointingHandCursor));
53  m_ui->nextButton->setCursor(QCursor(Qt::PointingHandCursor));
54  m_ui->refreshButton->setCursor(QCursor(Qt::PointingHandCursor));
55 
56  m_ui->deviceComboBox->setStyleSheet(TTK::UI::ComboBoxStyle02);
57  m_ui->timeSlider->setStyleSheet(TTK::UI::SliderStyle10);
58  m_ui->timeSlider->setValue(0);
59 
60  m_ui->deviceComboBox->addItem(tr("No connections"));
61  m_ui->deviceComboBox->setEnabled(false);
62 
63  m_dlnaFinder = new QDlnaFinder(this);
65 
66  startToScan();
68 
69  connect(m_ui->playButton, SIGNAL(clicked()), SLOT(playSong()));
70  connect(m_ui->previousButton, SIGNAL(clicked()), SLOT(playPrevious()));
71  connect(m_ui->nextButton, SIGNAL(clicked()), SLOT(playNext()));
72  connect(m_ui->refreshButton, SIGNAL(clicked()), SLOT(startToScan()));
73  connect(m_dlnaFinder, SIGNAL(finished()), SLOT(scanFinished()));
74 
75  G_CONNECTION_PTR->setValue(className(), this);
76  G_CONNECTION_PTR->connect(className(), MusicSongsContainerWidget::className());
77 }
78 
80 {
81  G_CONNECTION_PTR->removeValue(this);
82  TTKRemoveSingleWidget(className());
83  delete m_dlnaFinder;
84  delete m_ui;
85 }
86 
88 {
89  m_dlnaFinder->find();
90 }
91 
93 {
94  bool init = false;
95  for(const QString &name : m_dlnaFinder->clientNames())
96  {
97  if(!name.isEmpty())
98  {
99  if(!init)
100  {
101  m_ui->deviceComboBox->clear();
102  m_ui->deviceComboBox->setEnabled(true);
103  init = true;
104  }
105  m_ui->deviceComboBox->addItem(name);
106  }
107  }
108 }
109 
111 {
112  m_ui->timeSlider->setValue(position);
113 }
114 
116 {
117  m_ui->timeSlider->setRange(0, duration);
118 }
119 
121 {
122  if(m_ui->deviceComboBox->currentText() == tr("No connections"))
123  {
124  return;
125  }
126 
127  const int index = m_ui->deviceComboBox->currentIndex();
128  if(index < 0)
129  {
130  return;
131  }
132 
133  MusicSongItemList songs;
134  Q_EMIT queryMusicItemList(songs);
135 
136  if(songs.empty())
137  {
138  return;
139  }
140 
141  m_songs = &songs[0].m_songs;
143  if(m_currentPlayIndex < 0 || m_currentPlayIndex >= m_songs->count())
144  {
145  m_currentPlayIndex = 0;
146  }
147 
148  const MusicSong &song = (*m_songs)[m_currentPlayIndex];
149  const QFileInfo fin(song.path());
150 
151  QDlnaClient *client = m_dlnaFinder->client(index);
152  m_dlnaFileServer->setPrefixPath(fin.path());
153  client->tryToPlayFile(m_dlnaFileServer->localAddress(client->server()) + fin.fileName());
154 }
155 
157 {
159 }
160 
162 {
164 }
void setBackgroundLabel(QLabel *label)
QString localAddress(const QString &prefix) const
static const QString SliderStyle10
QString path() const noexcept
Definition: musicsong.h:90
voidpf void uLong size
Definition: ioapi.h:136
The class of the dlna client.
Definition: qdlnaclient.h:29
The class of the dlna finder.
Definition: qdlnafinder.h:31
#define G_CONNECTION_PTR
Ui::MusicSongDlnaTransferWidget * m_ui
QStringList clientNames() const
QDlnaClient * client(int index) const
Definition: qdlnafinder.cpp:83
void setPrefixPath(const QString &path)
const char * name
Definition: http_parser.c:458
#define TTKRemoveSingleWidget(name)
The class of the song dlna transfer widget.
static const QString BackgroundStyle01
Background.
Definition: musicuiobject.h:77
The class of the dlna file server.
static const QString ToolButtonStyle04
MusicSongDlnaTransferWidget(QWidget *parent=nullptr)
The class of the music song info.
Definition: musicsong.h:28
void queryMusicItemList(MusicSongItemList &songs)
The class of the moving widget base.
static const QString ComboBoxStyle02