TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicasxconfigmanager.cpp
Go to the documentation of this file.
2 
6 {
7 
8 }
9 
10 bool MusicASXConfigManager::readBuffer(MusicSongItemList &items)
11 {
12  MusicSongItem item;
13  item.m_itemName = QFileInfo(m_file->fileName()).baseName();
14 
15  TTKXmlHelper helper(m_document->documentElement());
16  helper.load();
17 
18  const QDomNodeList &nodes = m_document->elementsByTagName(helper.nodeName("Entry"));
19  for(int i = 0; i < nodes.count(); ++i)
20  {
21  const QDomNodeList &paramNodes = nodes.item(i).childNodes();
22 
23  QString duration, path;
24  for(int j = 0; j < paramNodes.count(); ++j)
25  {
26  const QDomNode &paramNode = paramNodes.item(j);
27  const QDomElement &element = paramNode.toElement();
28  const QString &name = paramNode.nodeName().toLower();
29 
30  if(name == "duration" || name == "length")
31  {
32  duration = element.attribute("value");
33  duration = duration.mid(3, 5);
34  }
35  else if(name == "ref")
36  {
37  path = element.attribute("href");
38  }
39  }
40 
41  if(!path.isEmpty())
42  {
43  item.m_songs << MusicSong(path, duration);
44  }
45  }
46 
47  if(!item.m_songs.isEmpty())
48  {
49  items << item;
50  }
51  return true;
52 }
53 
54 bool MusicASXConfigManager::writeBuffer(const MusicSongItemList &items)
55 {
56  if(items.isEmpty())
57  {
58  return false;
59  }
60 
61  QDomElement rootDom = createRoot("Asx", TTKXmlAttr("version ", "3.0"));
62 
63  for(int i = 0; i < items.count(); ++i)
64  {
65  const MusicSongItem &item = items[i];
66  writeDomElement(rootDom, "Title", item.m_itemName);
67 
68  for(const MusicSong &song : qAsConst(items[i].m_songs))
69  {
70  QDomElement trackDom = writeDomElement(rootDom, "Entry");
71 
72  writeDomElement(trackDom, "Title", song.title());
73  writeDomElement(trackDom, "Ref", {"href", song.path()});
74  writeDomElement(trackDom, "Duration", {"value", "00:" + song.duration() + ".000"});
75  writeDomElement(trackDom, "Author", TTK_APP_NAME);
76  }
77  }
78 
79  save();
80  return true;
81 }
The class of the ttk xml interface.
QDomDocument * m_document
#define TTK_APP_NAME
Definition: ttkobject.h:25
QDomElement writeDomElement(QDomElement &element, const QString &node) const
QDomElement createRoot(const QString &node) const
#define qAsConst
Definition: ttkqtglobal.h:53
const char * name
Definition: http_parser.c:458
The class of the ttk xml attribute.
The class of the ttk xml hepler.
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
virtual bool writeBuffer(const MusicSongItemList &items) overridefinal
void save() const
virtual bool readBuffer(MusicSongItemList &items) overridefinal
QString m_itemName
Definition: musicsong.h:164
The class of the music song info.
Definition: musicsong.h:28