TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicwplconfigmanager.cpp
Go to the documentation of this file.
2 #include "ttkversion.h"
3 
7 {
8 
9 }
10 
11 bool MusicWPLConfigManager::readBuffer(MusicSongItemList &items)
12 {
13  TTKXmlHelper helper(m_document->documentElement());
14  helper.load();
15 
16  MusicSongItem item;
17  item.m_itemName = QFileInfo(m_file->fileName()).baseName();
18 
19  const QDomNodeList &nodes = m_document->elementsByTagName(helper.nodeName("seq"));
20  for(int i = 0; i < nodes.count(); ++i)
21  {
22  const QDomNode &node = nodes.item(i);
23  item.m_songs << readMusicFilePath(node);
24  }
25 
26  if(!item.m_songs.isEmpty())
27  {
28  items << item;
29  }
30  return true;
31 }
32 
33 bool MusicWPLConfigManager::writeBuffer(const MusicSongItemList &items)
34 {
35  if(items.isEmpty())
36  {
37  return false;
38  }
39 
40  const QDomNode &node = m_document->createProcessingInstruction(WPL_FILE_SUFFIX, "version='1.0' encoding='UTF-8'");
41  m_document->appendChild(node);
42 
43  QDomElement rootDom = createRoot("smil");
44  QDomElement headDom = writeDomElement(rootDom, "head");
45  QDomElement bodyDom = writeDomElement(rootDom, "body");
46 
47  writeDomMultiElement(headDom, "meta", {{"name", "Generator"}, {"content", QString("%1 %2").arg(TTK_APP_NAME, TTK_VERSION_STR)}});
48 
49  for(int i = 0; i < items.count(); ++i)
50  {
51  const MusicSongItem &item = items[i];
52  QDomElement seqDom = writeDomElement(bodyDom, "seq");
53 
54  for(const MusicSong &song : qAsConst(item.m_songs))
55  {
56  writeDomElement(seqDom, "media", {"src", song.path()});
57  }
58  }
59 
60  save();
61  return true;
62 }
63 
64 MusicSongList MusicWPLConfigManager::readMusicFilePath(const QDomNode &node) const
65 {
66  const QDomNodeList &nodes = node.childNodes();
67 
68  MusicSongList songs;
69  for(int i = 0; i < nodes.count(); ++i)
70  {
71  const QDomElement &element = nodes.item(i).toElement();
72  songs << MusicSong(element.attribute("src"));
73  }
74  return songs;
75 }
The class of the ttk xml interface.
MusicSongList readMusicFilePath(const QDomNode &node) const
QDomDocument * m_document
#define TTK_APP_NAME
Definition: ttkobject.h:25
QDomElement writeDomElement(QDomElement &element, const QString &node) const
#define WPL_FILE_SUFFIX
Definition: musicobject.h:41
QDomElement writeDomMultiElement(QDomElement &element, const QString &node, const TTKXmlNode &attrs) const
QDomElement createRoot(const QString &node) const
#define qAsConst
Definition: ttkqtglobal.h:53
virtual bool writeBuffer(const MusicSongItemList &items) overridefinal
#define TTK_VERSION_STR
Definition: ttkversion.h:171
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
void save() const
QString m_itemName
Definition: musicsong.h:164
The class of the music song info.
Definition: musicsong.h:28
virtual bool readBuffer(MusicSongItemList &items) overridefinal