1 #include "remotelist.h"
4 #include <QDomNodeList>
7 RemoteList::RemoteList()
12 RemoteList::RemoteList(const RemoteList &r)
15 , modelMap(r.modelMap)
19 RemoteList::RemoteList(QDomDocument &doc)
24 RemoteList::RemoteList(const QString &xmlFile)
29 RemoteList::RemoteList(QIODevice &in)
32 if (doc.setContent(&in))
36 RemoteList::~RemoteList()
40 void RemoteList::setContent(QDomDocument &doc)
47 void RemoteList::setContent(const QString &xmlFile)
54 bool RemoteList::isValid()
59 QStringList RemoteList::letters()
64 QStringList RemoteList::manufacturers(const QString &letter)
66 return mfgMap.value(letter);
69 QList<Model> RemoteList::models(const QString &manufacturer)
71 return modelMap.value(manufacturer);
74 void RemoteList::parse(const QString &xmlFile)
79 if (!file.open(QIODevice::ReadOnly))
85 if (!doc.setContent(&file))
96 void RemoteList::parse(QDomDocument &doc)
98 QDomNodeList chars = doc.elementsByTagName("char");
100 for (int i = 0; i < chars.size(); ++i)
102 QDomElement charEl = chars.at(i).toElement();
103 if (!charEl.isNull())
105 if (charEl.hasAttribute("id"))
106 mfgMap.insert(charEl.attribute("id").at(0), parseMfgs(charEl));
110 // TODO: more error handling
111 valid = (mfgMap.size() > 0 &&
112 modelMap.size() > 0);
115 QStringList RemoteList::parseMfgs(QDomElement &charEl)
117 QStringList mfgStrings;
118 QDomNodeList mfgs = charEl.elementsByTagName("mfg");
120 for (int i = 0; i < mfgs.size(); ++i)
122 QDomElement mfgEl = mfgs.at(i).toElement();
125 if (mfgEl.hasAttribute("id"))
127 mfgStrings.append(mfgEl.attribute("id"));
128 modelMap.insert(mfgStrings.last(), parseModels(mfgEl));
135 QList<Model> RemoteList::parseModels(QDomElement &mfgEl)
137 QList<Model> modelList;
138 QDomNodeList models = mfgEl.elementsByTagName("model");
140 for (int i = 0; i < models.size(); ++i)
142 QDomElement modelEl = models.at(i).toElement();
143 if (!modelEl.isNull())
145 if (modelEl.hasAttribute("name") && modelEl.hasAttribute("file"))
147 modelList.append(Model(modelEl.attribute("name"),
148 modelEl.attribute("file")));