TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicfmconfigmanager.cpp
Go to the documentation of this file.
1 #include "musicfmconfigmanager.h"
2 
5 {
6 
7 }
8 
9 bool MusicFMConfigManager::readBuffer(MusicFMCategoryList &items)
10 {
11  const QDomNodeList &nodes = m_document->elementsByTagName("category");
12  for(int i = 0; i < nodes.count(); ++i)
13  {
14  MusicFMCategory category;
15  const QDomNode &node = nodes.item(i);
16  category.m_category = node.toElement().attribute("value");
17 
18  const QDomNodeList &chnNodes = node.childNodes();
19  for(int j = 0; j < chnNodes.count(); ++j)
20  {
21  const QDomElement &element = chnNodes.item(j).toElement();
22 
23  MusicFMChannel item;
24  item.m_name = element.attribute("name");
25  item.m_url = element.attribute("url");
26  category.m_items << item;
27  }
28  items.append(category);
29  }
30 
31  return true;
32 }
33 
34 bool MusicFMConfigManager::writeBuffer(const MusicFMCategoryList &items)
35 {
36  if(items.isEmpty())
37  {
38  return false;
39  }
40 
42  QDomElement rootDom = createRoot(TTK_APP_NAME);
43 
44  for(const MusicFMCategory &item : qAsConst(items))
45  {
46  QDomElement categoryDom = writeDomElement(rootDom, "category", {"value", item.m_category});
47 
48  for(const MusicFMChannel &channel : qAsConst(item.m_items))
49  {
50  writeDomMultiElement(categoryDom, "channel", {{"name", channel.m_name}, {"url", channel.m_url}});
51  }
52  }
53 
54  save();
55  return true;
56 }
The class of the ttk xml interface.
QDomDocument * m_document
MusicFMChannelList m_items
#define TTK_APP_NAME
Definition: ttkobject.h:25
QDomElement writeDomElement(QDomElement &element, const QString &node) const
QDomElement writeDomMultiElement(QDomElement &element, const QString &node, const TTKXmlNode &attrs) const
void createProcessingInstruction() const
QDomElement createRoot(const QString &node) const
#define qAsConst
Definition: ttkqtglobal.h:51
The class of the fm channel item.
virtual bool writeBuffer(const MusicFMCategoryList &items) overridefinal
void save() const
The class of the fm category item.
virtual bool readBuffer(MusicFMCategoryList &items) overridefinal