TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musictxtconfigmanager.cpp
Go to the documentation of this file.
2 
6 {
7 
8 }
9 
10 bool MusicTXTConfigManager::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  int index = line.indexOf(":");
24  if(index != -1)
25  {
26  const QString &part = line.mid(index + 1).trimmed();
27  index = part.lastIndexOf(TTK_DEFAULT_STR);
28  if(index != -1)
29  {
30  item.m_songs << MusicSong(part.left(index).trimmed(), part.mid(index + 1).trimmed());
31  }
32  }
33  }
34 
35  m_file.close();
36 
37  if(!item.m_songs.isEmpty())
38  {
39  items << item;
40  }
41  return true;
42 }
43 
44 bool MusicTXTConfigManager::writeBuffer(const MusicSongItemList &items)
45 {
46  if(items.isEmpty())
47  {
48  return false;
49  }
50 
51  QStringList data;
52 
53  int count = 0;
54  for(int i = 0; i < items.count(); ++i)
55  {
56  const MusicSongItem &item = items[i];
57  for(const MusicSong &song : qAsConst(item.m_songs))
58  {
59  data << QString("%1:%2 - %3").arg(++count).arg(song.path(), song.duration());
60  }
61  }
62 
63  m_file.write(data.join("\n").toUtf8());
64  m_file.close();
65  return true;
66 }
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
virtual bool writeBuffer(const MusicSongItemList &items) overridefinal
#define qAsConst
Definition: ttkqtglobal.h:53
virtual bool readBuffer(MusicSongItemList &items) overridefinal
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
The class of the ttk file interface.