X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=playlistmainwindow.cpp;h=fd2569a1ed21dc6d1d76fb81ae8c8cbb7277b95b;hb=77153ee186168c5a623c1d80a1cb81afb266e646;hp=ca4ce3bac04e9878df3486b499b5aa92fddfef6b;hpb=ed6b3f2ed33dfb5300c9f2df401fd5b4c633b5de;p=vlc-remote diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index ca4ce3b..fd2569a 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -25,7 +25,7 @@ #include "configdialog.h" #include "aboutdialog.h" #include "appsettings.h" -#include "vlcstatus.h" +//#include "vlcstatus.h" PlayListMainWindow::PlayListMainWindow(QWidget *parent) : QMainWindow(parent), @@ -101,10 +101,19 @@ void PlayListMainWindow::changeEvent(QEvent *e) void PlayListMainWindow::onListSelectionChanged() { QList items = ui->listWidget->selectedItems(); if (0 < items.count()) { - mCurrentElement = getElementFromText(items.at(0)->text()); + // TODO VLC doesn't seem to support removing nodes! + // Playing nodes works fine, however. + // should check to see if it is a leaf or not and disable the remove button mCurrentVlcIndex = items.at(0)->type() - LIST_ITEM_TYPE_OFFSET; // Qt reserves types up to 1000, we use an offset beyond that for index tracking. May prove to be too hacky! - ui->removeButton->setDisabled(false); - ui->playButton->setDisabled(false); + mCurrentElement = getElementFromId(mCurrentVlcIndex); + if (0 == QString::compare("node", mCurrentElement.type)) { + ui->removeButton->setDisabled(true); + ui->playButton->setDisabled(false); + } + else { + ui->removeButton->setDisabled(false); + ui->playButton->setDisabled(false); + } } else { mCurrentVlcIndex = 0; @@ -115,34 +124,38 @@ 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)))); - connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList())); + mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex)))); + //connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList())); + // don't refresh just clear the item! + delete ui->listWidget->takeItem(ui->listWidget->currentRow()); } } 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)))); + 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"))); + 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"))); + 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"))); + 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"))); - connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList())); + mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty"))); + mContents->clear(); + ui->listWidget->clear(); + //connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList())); } void PlayListMainWindow::requestPlayList() { mResponse.clear(); ui->removeButton->setDisabled(true); ui->playButton->setDisabled(true); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) - this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); + this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); #endif QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml"))); disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList())); @@ -152,11 +165,11 @@ void PlayListMainWindow::requestPlayList() { } void PlayListMainWindow::error(QNetworkReply::NetworkError code) { #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) - this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); + this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); #endif - qDebug() << code; + qDebug() << code; #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) - QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout); + QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout); #endif } void PlayListMainWindow::readReady() { @@ -170,7 +183,7 @@ void PlayListMainWindow::finished(QNetworkReply * reply) { // only interested in finished signals disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *))); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) - this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); + this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); #endif } @@ -202,60 +215,6 @@ void PlayListMainWindow::parseXmlPlayList() { for (int jdx = 0; jdx < leafct; ++jdx) { QDomNode leaf = leafs.at(jdx); parsePlayListItem(&leaf, &extension, &hasArt, ¤tLeafId, 1); - /* - 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().replace("\\\\", "\\"); - current = leaf.attributes().namedItem("current").nodeValue(); - el->playing = (0 < current.length()); - el->depth = depth; - if (0 == QString::compare(leaf.nodeName(), "node")) { - el->type = "node"; - el->extension = getExtension(el->path, NULL); - 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) { - depth = 2; - 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().replace("\\\\", "\\"); - it->extension = getExtension(it->path, NULL); - it->depth = 2; - it->type = "leaf"; - current = item.attributes().namedItem("current").nodeValue(); - it->playing = (0 < current.length()); - if (it->playing) { - currentLeafId = it->id; - QString art = item.toElement().namedItem("art_url").toElement().text(); - hasArt = (!art.isNull() && !art.isEmpty()); - extension = getExtension(it->path, NULL); - } - this->mContents->append(*it); - delete it; - } - } - } - } - else { - el->type = "leaf"; - el->extension = getExtension(el->path, NULL); - if (el->playing) { - currentLeafId = el->id; - QString art = leaf.toElement().namedItem("art_url").toElement().text(); - hasArt = (!art.isNull() && !art.isEmpty()); - extension = getExtension(el->path, NULL); - } - this->mContents->append(*el); - } - delete el; - */ } } } @@ -272,7 +231,8 @@ void PlayListMainWindow::parseXmlPlayList() { } -void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth) { +int PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth) { + int leafCt = 0; if (NULL != node) { QString current; VlcPlayListElementSimple* el = new VlcPlayListElementSimple(); @@ -292,6 +252,7 @@ void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, b *extension = getExtension(el->path, NULL); } this->mContents->append(*el); + ++leafCt; delete el; } else { @@ -300,22 +261,33 @@ void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, b // empty nodes appear in the playlist when they can't be played! if (node->hasChildNodes()) { this->mContents->append(*el); + ++leafCt; } delete el; // now parse the child nodes as leaf. if (node->hasChildNodes()) { QDomNodeList items = node->childNodes(); int itemct = items.count(); + int added = 0; if (0 < itemct) { ++depth; for (int kdx = 0; kdx < itemct; ++kdx) { QDomNode item = items.at(kdx); - parsePlayListItem(&item, extension, hasArt, currentLeafId, depth); + added += parsePlayListItem(&item, extension, hasArt, currentLeafId, depth); + } + if (1 > added) { + // should remove the last PlayListElement + this->mContents->removeLast(); + --leafCt; + } + else { + leafCt += added; } } } } } + return leafCt; } QString PlayListMainWindow::getExtension(QString path, QString extension) { @@ -333,10 +305,10 @@ QString PlayListMainWindow::getExtension(QString path, QString extension) { } } -VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) { +VlcPlayListElementSimple PlayListMainWindow::getElementFromId(int id) { //if (0 != QString::compare("", text)) { for (int idx = 0; idx < mContents->count(); ++idx) { - if (0 == QString::compare(text, mContents->at(idx).name)) { + if (0 < id && (id == mContents->at(idx).id)) { return mContents->at(idx); } }