TTKMusicPlayer  4.1.3.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 "musicmessagebox.h"
5 
8  m_type(TTK::Record::Null)
9 {
12  connect(this, SIGNAL(cellDoubleClicked(int,int)), SLOT(itemDoubleClicked(int,int)));
13 }
14 
16 {
18  if(!manager.load(TTK::toString(m_type)))
19  {
20  return;
21  }
22 
23  manager.writeBuffer(*m_songs);
24  removeItems();
25 
26  delete m_progressBarDelegate;
27 }
28 
29 void MusicAbstractDownloadTableWidget::updateSongsList(const MusicSongList &songs)
30 {
31  Q_UNUSED(songs);
32 
34  if(!manager.fromFile(TTK::toString(m_type)))
35  {
36  return;
37  }
38 
39  manager.readBuffer(*m_songs);
40  setRowCount(m_songs->count()); //reset row count
41 
42  for(int i = 0; i < m_songs->count(); ++i)
43  {
44  const MusicSong &v = m_songs->at(i);
45  addCellItem(i, v);
46  G_DOWNLOAD_MANAGER_PTR->reconnectNetworkData(MusicDownLoadPairData(v.addTimeStr().toULongLong(), this, m_type));
47  }
48 }
49 
51 {
52  MusicMessageBox message;
53  message.setText(tr("Are you sure to delete?"));
54  if(!message.exec() || rowCount() == 0)
55  {
56  return;
57  }
58 
59  const TTKIntList deletedList(selectedIndexList());
60  if(deletedList.isEmpty())
61  {
62  return;
63  }
64 
65  for(int i = deletedList.count() - 1; i >= 0; --i)
66  {
67  const int index = deletedList[i];
68  removeRow(index);
69  m_songs->removeAt(index);
70  }
71 
72  setFixedHeight(totalHeight());
74 }
75 
77 {
78  Q_UNUSED(row);
79  Q_UNUSED(column);
80 
81  if(!isValid())
82  {
83  return;
84  }
85 
86  const QString &path = m_songs->at(currentRow()).path();
87  MusicSongsContainerWidget::instance()->addSongToPlaylist(QFile::exists(path) ? QStringList(path) : QStringList());
88 }
89 
90 void MusicAbstractDownloadTableWidget::downloadProgressChanged(float percent, const QString &total, qint64 time)
91 {
92  for(int i = 0; i < rowCount(); ++i)
93  {
94  QTableWidgetItem *it = item(i, 3);
95  if(it && it->data(TTK_TIME_ROLE).toLongLong() == time)
96  {
97  item(i, 2)->setData(TTK_PROGRESS_ROLE, percent);
98  item(i, 3)->setText(total);
99 
100  (*m_songs)[i].setSizeStr(total);
101  break;
102  }
103  }
104 }
105 
107 {
108  QFileInfo fin(name);
109  setRowCount(rowCount() + 1);
110 
111  MusicSong record;
112  record.setName(fin.completeBaseName());
113  record.setPath(fin.absoluteFilePath());
114  record.setSizeStr("0.00M");
115  record.setAddTimeStr(QString::number(time));
116  m_songs->append(record);
117 
118  addCellItem(rowCount() - 1, record);
120 }
121 
123 {
124  Q_UNUSED(event);
125  QMenu menu(this);
126 
127  menu.setStyleSheet(TTK::UI::MenuStyle02);
128  menu.addAction(QIcon(":/contextMenu/btn_play"), tr("Play"), this, SLOT(playClicked()));
129  menu.addAction(tr("Download More..."), this, SLOT(showDownloadWidget()));
130  menu.addSeparator();
131 
132  createMoreMenu(&menu);
133 
134  const bool status = !(m_songs->isEmpty() || TTK::String::isNetworkUrl(currentSongPath()));
135  menu.addAction(tr("Song Info..."), this, SLOT(showFileInformation()))->setEnabled(status);
136  menu.addAction(QIcon(":/contextMenu/btn_local_file"), tr("Open File Dir"), this, SLOT(openFileDir()))->setEnabled(status);
137  menu.addAction(QIcon(":/contextMenu/btn_ablum"), tr("Ablum"), this, SLOT(showAlbumQueryWidget()));
138  menu.addSeparator();
139 
140  menu.addAction(QIcon(":/contextMenu/btn_delete"), tr("Delete"), this, SLOT(removeItemAt()))->setEnabled(status);
141  menu.addAction(tr("Delete All"), this, SLOT(clearItems()))->setEnabled(status);
142 
143  menu.exec(QCursor::pos());
144 }
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
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 addSongToPlaylist(const QStringList &items)
void setAddTimeStr(const QString &t) noexcept
Definition: musicsong.h:61
QList< int > TTKIntList
Definition: ttkqtglobal.h:204
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
static MusicSongsContainerWidget * instance()
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)
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)