TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicabstractdownloadtablewidget.cpp
Go to the documentation of this file.
3 #include "musicdownloadmanager.h"
4 #include "musicconnectionpool.h"
5 #include "musicmessagebox.h"
6 
9  m_type(TTK::Record::Null)
10 {
13  connect(this, SIGNAL(cellDoubleClicked(int,int)), SLOT(itemDoubleClicked(int,int)));
14 
15  G_CONNECTION_PTR->setValue(className(), this);
16  G_CONNECTION_PTR->connect(className(), MusicSongsContainerWidget::className());
17 }
18 
20 {
21  G_CONNECTION_PTR->removeValue(this);
23  if(!manager.load(TTK::toString(m_type)))
24  {
25  return;
26  }
27 
28  manager.writeBuffer(*m_songs);
29  removeItems();
30 
31  delete m_progressBarDelegate;
32 }
33 
34 void MusicAbstractDownloadTableWidget::updateSongsList(const MusicSongList &songs)
35 {
36  Q_UNUSED(songs);
37 
39  if(!manager.fromFile(TTK::toString(m_type)))
40  {
41  return;
42  }
43 
44  manager.readBuffer(*m_songs);
45  setRowCount(m_songs->count()); //reset row count
46 
47  for(int i = 0; i < m_songs->count(); ++i)
48  {
49  const MusicSong &v = m_songs->at(i);
50  addCellItem(i, v);
51  G_DOWNLOAD_MANAGER_PTR->reconnectDownload(MusicDownLoadPairData(v.addTimeStr().toULongLong(), this, m_type));
52  }
53 }
54 
56 {
57  MusicMessageBox message;
58  message.setText(tr("Are you sure to delete?"));
59  if(!message.exec() || rowCount() == 0)
60  {
61  return;
62  }
63 
64  const TTKIntList deletedList(selectedIndexList());
65  if(deletedList.isEmpty())
66  {
67  return;
68  }
69 
70  for(int i = deletedList.count() - 1; i >= 0; --i)
71  {
72  const int index = deletedList[i];
73  removeRow(index);
74  m_songs->removeAt(index);
75  }
76 
77  setFixedHeight(totalHeight());
79 }
80 
82 {
83  Q_UNUSED(row);
84  Q_UNUSED(column);
85 
86  if(!isValid())
87  {
88  return;
89  }
90 
91  const QString &path = m_songs->at(currentRow()).path();
92  Q_EMIT addSongToPlaylist(QFile::exists(path) ? QStringList(path) : QStringList());
93 }
94 
95 void MusicAbstractDownloadTableWidget::downloadProgressChanged(float percent, const QString &total, qint64 time)
96 {
97  for(int i = 0; i < rowCount(); ++i)
98  {
99  QTableWidgetItem *it = item(i, 3);
100  if(it && it->data(TTK_TIME_ROLE).toLongLong() == time)
101  {
102  item(i, 2)->setData(TTK_PROGRESS_ROLE, percent);
103  item(i, 3)->setText(total);
104 
105  (*m_songs)[i].setSizeStr(total);
106  break;
107  }
108  }
109 }
110 
112 {
113  QString musicName = name;
114  musicName.remove(TTK::String::musicDirPrefix()).chop(4);
115  setRowCount(rowCount() + 1);
116 
117  MusicSong record;
118  record.setName(musicName);
119  record.setPath(QFileInfo(name).absoluteFilePath());
120  record.setSizeStr("0.00M");
121  record.setAddTimeStr(QString::number(time));
122  m_songs->append(record);
123 
124  addCellItem(rowCount() - 1, record);
126 }
127 
129 {
130  Q_UNUSED(event);
131  QMenu menu(this);
132 
133  menu.setStyleSheet(TTK::UI::MenuStyle02);
134  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"), this, SLOT(playClicked()));
135  menu.addAction(tr("Download More..."), this, SLOT(showDownloadWidget()));
136  menu.addSeparator();
137 
138  createMoreMenu(&menu);
139 
140  const bool status = !(m_songs->isEmpty() || TTK::String::isNetworkUrl(currentSongPath()));
141  menu.addAction(tr("Song Info..."), this, SLOT(showFileInformation()))->setEnabled(status);
142  menu.addAction(QIcon(":/contextMenu/btn_local_file"), tr("Open File Dir"), this, SLOT(openFileDir()))->setEnabled(status);
143  menu.addAction(QIcon(":/contextMenu/btn_ablum"), tr("Ablum"), this, SLOT(showAlbumQueryWidget()));
144  menu.addSeparator();
145 
146  menu.addAction(QIcon(":/contextMenu/btn_delete"), tr("Delete"), this, SLOT(removeItemAt()))->setEnabled(status);
147  menu.addAction(tr("Delete All"), this, SLOT(clearItems()))->setEnabled(status);
148 
149  menu.exec(QCursor::pos());
150 }
virtual void updateSongsList(const MusicSongList &songs) overridefinal
#define G_DOWNLOAD_MANAGER_PTR
void setText(const QString &text) const
virtual bool writeBuffer(const MusicSongList &items) overridefinal
bool fromFile(const QString &name)
virtual void addCellItem(int index, const MusicSong &record)=0
The class of the progress bar item delegate.
#define TTK_PROGRESS_ROLE
void setStyleSheet(const QString &style) const
The class of the download record manager.
The class of the messagebox widget.
virtual void contextMenuEvent(QContextMenuEvent *event) override
static const QString ProgressBar01
ProgressBar.
virtual bool readBuffer(MusicSongList &items) overridefinal
#define G_CONNECTION_PTR
void setName(const QString &n) noexcept
Definition: musicsong.h:78
void createDownloadItem(const QString &name, qint64 time)
void downloadProgressChanged(float percent, const QString &total, qint64 time)
void setAddTimeStr(const QString &t) noexcept
Definition: musicsong.h:61
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
const char * name
Definition: http_parser.c:458
The namespace of the process utils.
Definition: ttkcompat.h:24
void setSizeStr(const QString &s) noexcept
Definition: musicsong.h:69
TTKProgressBarItemDelegate * m_progressBarDelegate
The class of the download manager pair.
static const QString MenuStyle02
QString addTimeStr() const noexcept
Definition: musicsong.h:65
TTK_MODULE_EXPORT QString toString(Record type)
bool load(const QString &name)
TTK_MODULE_EXPORT QString musicDirPrefix()
TTKIntList selectedIndexList() const
The class of the music song info.
Definition: musicsong.h:28
void setPath(const QString &p) noexcept
Definition: musicsong.h:86
#define TTK_TIME_ROLE
The class of the songs list abstract table widget.
TTK_MODULE_EXPORT bool isNetworkUrl(const QString &path)
void addSongToPlaylist(const QStringList &items)