TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musiccsvconfigmanager.cpp
Go to the documentation of this file.
2 
6 {
7 
8 }
9 
10 bool MusicCSVConfigManager::readBuffer(MusicSongItemList &items)
11 {
12  MusicSongItem item;
13  item.m_itemName = QFileInfo(m_file.fileName()).baseName();
14 
15  const QStringList data(QString(m_file.readAll()).split("\n"));
16  if(data.isEmpty())
17  {
18  return false;
19  }
20 
21  for(const QString &line : qAsConst(data))
22  {
23  const QStringList &songInfo = line.split(",");
24  if(songInfo.count() > 2)
25  {
26  item.m_songs << MusicSong(songInfo[2], songInfo[1], songInfo[0]);
27  }
28  }
29 
30  m_file.close();
31 
32  if(!item.m_songs.isEmpty())
33  {
34  items << item;
35  }
36  return true;
37 }
38 
39 bool MusicCSVConfigManager::writeBuffer(const MusicSongItemList &items)
40 {
41  if(items.isEmpty())
42  {
43  return false;
44  }
45 
46  QStringList data;
47  for(int i = 0; i < items.count(); ++i)
48  {
49  const MusicSongItem &item = items[i];
50  for(const MusicSong &song : qAsConst(item.m_songs))
51  {
52  data << song.name() + "," + song.duration() + "," + song.path();
53  }
54  }
55 
56  m_file.write(data.join("\n").toUtf8());
57  m_file.close();
58  return true;
59 }
virtual bool writeBuffer(const MusicSongItemList &items) overridefinal
#define qAsConst
Definition: ttkqtglobal.h:53
TTK_MODULE_EXPORT QStringList split(const QString &value, const QString &key=TTK_DEFAULT_STR)
The class of the read write interface.
The class of the music song item.
Definition: musicsong.h:161
MusicSongList m_songs
Definition: musicsong.h:166
QString m_itemName
Definition: musicsong.h:164
The class of the music song info.
Definition: musicsong.h:28
virtual bool readBuffer(MusicSongItemList &items) overridefinal
The class of the ttk file interface.