From 266e3fa77ebfa8de9673f519061ea52f96f252b3 Mon Sep 17 00:00:00 2001 From: druid23 Date: Tue, 17 Aug 2010 01:50:15 +0100 Subject: [PATCH] Working simple playlist. modified: browsemainwindow.cpp modified: playlistmainwindow.cpp modified: playlistmainwindow.h modified: vlcplaylistelementsimple.h --- browsemainwindow.cpp | 1 - playlistmainwindow.cpp | 162 +++++++++++++++++++++++++++----------------- playlistmainwindow.h | 3 + vlcplaylistelementsimple.h | 2 +- 4 files changed, 104 insertions(+), 64 deletions(-) diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index f4bcef5..8cb7875 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -138,7 +138,6 @@ void BrowseMainWindow::browseDirectory(QString dir) { ui->listWidget->clear(); mResponse.clear(); QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir))); - //reply->setReadBufferSize(1024 * 500); connect(reply,SIGNAL(readyRead()),this,SLOT(readReady())); connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); } diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index 9dabb54..7fec0ec 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -108,102 +108,140 @@ void PlayListMainWindow::onListSelectionChanged() { void PlayListMainWindow::onRemove() { if (0 < this->mCurrentVlcIndex) { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex)))); - this->requestPlayList(); - } + this->requestPlayList(); + } } void PlayListMainWindow::onPlay() { if (0 < this->mCurrentVlcIndex) { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play&id=" + QString::number(this->mCurrentVlcIndex)))); - } + } } void PlayListMainWindow::onRepeat() { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_repeat"))); - } +} void PlayListMainWindow::onLoop() { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_loop"))); - } +} void PlayListMainWindow::onShuffle() { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_random"))); - } +} void PlayListMainWindow::onClear() { /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty"))); this->requestPlayList(); - } +} void PlayListMainWindow::requestPlayList() { - ui->listWidget->clear(); - ui->removeButton->setDisabled(true); - ui->playButton->setDisabled(true); - QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml"))); - connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlPlayList())); + mContents->clear(); + ui->listWidget->clear(); + mResponse.clear(); + ui->removeButton->setDisabled(true); + ui->playButton->setDisabled(true); + QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml"))); + connect(reply,SIGNAL(readyRead()),this,SLOT(readReady())); + connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); +} +void PlayListMainWindow::readReady() { + QNetworkReply * reply = qobject_cast(sender()); + // append to buffer + mResponse += reply->readAll(); +} +void PlayListMainWindow::finished(QNetworkReply * reply) { + // now we can call parseXmlList to process the full buffers + this->parseXmlPlayList(); + // only interested in finished signals + disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); } void PlayListMainWindow::parseXmlPlayList() { - QNetworkReply * reply = qobject_cast(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; + } } + } } - + else { + el->depth = 1; + el->type = "leaf"; + this->mContents->append(*el); + } + delete el; + } } - } - + } + } + } - delete reply; + mResponse.clear(); - this->updateList(); + this->updateList(); } VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) { - //if (0 != QString::compare("", text)) { + //if (0 != QString::compare("", text)) { for (int idx = 0; idx < mContents->count(); ++idx) { - if (0 == QString::compare(text, mContents->at(idx).name)) { - return mContents->at(idx); - } + if (0 == QString::compare(text, mContents->at(idx).name)) { + return mContents->at(idx); + } } //} return *(new VlcPlayListElementSimple()); } void PlayListMainWindow::updateList() { - int ct = this->mContents->count(); - if (0 < ct) { - for (int idx = 0; idx < ct; ++idx) { - VlcPlayListElementSimple el = mContents->at(idx); - QListWidgetItem* item; - item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); - ui->listWidget->addItem(item); - /// TODO - Work out the file / media type and use an appropriate icon instead of the default. - } + int ct = this->mContents->count(); + if (0 < ct) { + for (int idx = 0; idx < ct; ++idx) { + VlcPlayListElementSimple el = mContents->at(idx); + QListWidgetItem* item;// + if (0 == QString::compare("node", el.type)) { + item = new QListWidgetItem(QIcon::fromTheme("filemanager_media_folder"), el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); + } + else { + item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); + } + ui->listWidget->addItem(item); + /// TODO - Work out the file / media type and use an appropriate icon instead of the default. } + } } - diff --git a/playlistmainwindow.h b/playlistmainwindow.h index 7eba61f..fdb5f51 100644 --- a/playlistmainwindow.h +++ b/playlistmainwindow.h @@ -47,6 +47,8 @@ public slots: void onRemove(); void requestPlayList(); void onListSelectionChanged(); + void finished(QNetworkReply * reply); + void readReady(); protected slots: void parseXmlPlayList(); @@ -65,6 +67,7 @@ private: VlcPlayListElementSimple mCurrentElement; int mCurrentVlcIndex; int mCurrentDepth; + QByteArray mResponse; }; #endif // PLAYLISTMAINWINDOW_H diff --git a/vlcplaylistelementsimple.h b/vlcplaylistelementsimple.h index a0b9965..b3369b6 100644 --- a/vlcplaylistelementsimple.h +++ b/vlcplaylistelementsimple.h @@ -24,7 +24,7 @@ struct VlcPlayListElementSimple { int id; // vlc playlist item id int depth; // QString type; // node or leaf - QString path; // Only used for leaf - repeat name otherwise + //QString path; // Only used for leaf - repeat name otherwise QString name; // name or metadata title if available } ; -- 1.7.9.5