- QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
- QDomDocument doc;
- doc.setContent(reply->readAll());
- QDomElement docElem = doc.documentElement();
- QDomNodeList nodes = docElem.elementsByTagName("node");
- mContents->clear();
-
- int depth = 0;
-
- int ct = nodes.count();
- qDebug() << "elements " << ct;
- for (int idx = 0; idx < ct; ++idx) {
- QDomNode node = nodes.at(idx);
- QString name = node.attributes().namedItem("name").nodeValue();
- if (0 == QString::compare("Playlist", name)) {
- // got the main playlist, let's build it up
- if (node.hasChildNodes()) {
- QDomNodeList leafs = node.childNodes();
- int leafct = leafs.count();
- if (0 < leafct) {
- for (int jdx = 0; jdx < leafct; ++jdx) {
- QDomNode leaf = leafs.at(jdx);
- VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
- el->depth = 1;
- el->id = leaf.attributes().namedItem("id").nodeValue().toInt();
- el->type = "leaf";
- el->path = leaf.attributes().namedItem("uri").nodeValue();
- el->name = leaf.attributes().namedItem("name").nodeValue();
- this->mContents->append(*el);
- delete el;
- }
+ QDomDocument doc;
+ doc.setContent(this->mResponse);
+ QDomElement docElem = doc.documentElement();
+ QDomNodeList nodes = docElem.elementsByTagName("node");
+
+ int depth = 0;
+
+ int ct = nodes.count();
+ for (int idx = 0; idx < ct; ++idx) {
+ QDomNode node = nodes.at(idx);
+ QString name = node.attributes().namedItem("name").nodeValue();
+ if (0 == QString::compare("Playlist", name)) {
+ // got the main playlist, let's build it up
+ if (node.hasChildNodes()) {
+ QDomNodeList leafs = node.childNodes();
+ int leafct = leafs.count();
+ if (0 < leafct) {
+ for (int jdx = 0; jdx < leafct; ++jdx) {
+ QDomNode leaf = leafs.at(jdx);
+ VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
+ el->id = leaf.attributes().namedItem("id").nodeValue().toInt();
+ //el->path = leaf.attributes().namedItem("uri").nodeValue();
+ el->name = leaf.attributes().namedItem("name").nodeValue();
+ if (0 == QString::compare(leaf.nodeName(), "node")) {
+ el->depth = 1;
+ el->type = "node";
+ this->mContents->append(*el);
+ // now parse the child nodes as leafs.
+ if (leaf.hasChildNodes()) {
+ QDomNodeList items = leaf.childNodes();
+ int itemct = items.count();
+ if (0 < itemct) {
+ for (int kdx = 0; kdx < itemct; ++kdx) {
+ QDomNode item = items.at(kdx);
+ VlcPlayListElementSimple* it = new VlcPlayListElementSimple();
+ it->id = item.attributes().namedItem("id").nodeValue().toInt();
+ //it->path = item.attributes().namedItem("uri").nodeValue();
+ it->name = item.attributes().namedItem("name").nodeValue();
+ it->depth = 2;
+ it->type = "leaf";
+ this->mContents->append(*it);
+ delete it;
+ }