#include "configdialog.h"
#include "aboutdialog.h"
#include "appsettings.h"
-#include "vlcstatus.h"
+//#include "vlcstatus.h"
PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
QMainWindow(parent),
void PlayListMainWindow::onListSelectionChanged() {
QList<QListWidgetItem *> 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;
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()));
}
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() {
// 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
+ delete reply;
}
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;
- */
}
}
}
}
-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();
*hasArt = (!art.isNull() && !art.isEmpty());
*extension = getExtension(el->path, NULL);
}
+ QString title = node->toElement().namedItem("title").toElement().text();
+ QString artist = node->toElement().namedItem("artist").toElement().text();
+ QString album = node->toElement().namedItem("album").toElement().text();
+ if (0 < artist.length() || 0 < album.length()) {
+ el->name = "" + title + "\n" + artist + " - " + album;
+ }
this->mContents->append(*el);
+ ++leafCt;
delete el;
}
else {
// 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) {
}
}
-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);
}
}
QIcon icon_flash = QIcon::fromTheme("filemanager_flash_file");
QIcon icon_media = QIcon::fromTheme("filemanager_media_folder");
QIcon icon_real = QIcon::fromTheme("filemanager_real_music");
+ QIcon icon_playl = QIcon::fromTheme("filemanager_playlist");
QIcon icon_unknown= QIcon::fromTheme("filemanager_unknown_file");
for (int idx = 0; idx < ct; ++idx) {
VlcPlayListElementSimple el = mContents->at(idx);
0 == QString::compare(el.extension, "flac") ) {
item = new QListWidgetItem(icon_audio, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .mp3, .m4a, .ogg, .oga, .wav, .flac
}
+ else if ( 0 == QString::compare(el.extension, "m3u") ||
+ 0 == QString::compare(el.extension, "wpl") ||
+ 0 == QString::compare(el.extension, "pls") ||
+ 0 == QString::compare(el.extension, "asx") ||
+ 0 == QString::compare(el.extension, "xspf") ||
+ 0 == QString::compare(el.extension, "cmml") ) {
+ item = new QListWidgetItem(icon_playl, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .m3u, .wpl, .pls, .asx, .xspf, .cmml
+ }
else if ( 0 == QString::compare(el.extension, "avi") ||
0 == QString::compare(el.extension, "mpeg") ||
0 == QString::compare(el.extension, "mpg") ||