/* VLC-REMOTE for MAEMO 5
- * Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>
+ * Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>, Dru Moore <usr@dru-id.co.uk>, Yann Nave <yannux@onbebop.net>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* or (at your option) any later version, as published by the Free
#include "ui_playlistmainwindow.h"
#include <QPushButton>
#include <QSettings>
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+#include <QMaemo5InformationBox>
+#endif
#include "configdialog.h"
#include "aboutdialog.h"
-#include "accountdialog.h"
+#include "appsettings.h"
+#include "vlcstatus.h"
PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
QMainWindow(parent),
mContents = new QList<VlcPlayListElementSimple>();
+ ui->listWidget->setTextElideMode(Qt::ElideLeft);
+ ui->listWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+
ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
ui->clearButton->setIcon(QIcon::fromTheme("general_delete"));
ui->shuffleButton->setIcon(QIcon::fromTheme("mediaplayer_default_shuffle"));
}
void PlayListMainWindow::init() // CALL WHEN CONFIG CHANGES
{
- mIp = AccountDialog::currentIp();
+ mIp = AppSettings::getCurrentIp(); // AccountDialog::currentIp();
}
void PlayListMainWindow::showPlayList() // CALL WHEN SHOWN
{
connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
}
void PlayListMainWindow::requestPlayList() {
- mContents->clear();
- ui->listWidget->clear();
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);
+#endif
QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml")));
disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
+ connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError)));
connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
}
+void PlayListMainWindow::error(QNetworkReply::NetworkError code) {
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+ this->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
+#endif
+ qDebug() << code;
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+ QMaemo5InformationBox::information(this, tr("Playlist could not be retrieved."), QMaemo5InformationBox::DefaultTimeout);
+#endif
+}
void PlayListMainWindow::readReady() {
QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
// append to buffer
this->parseXmlPlayList();
// 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);
+#endif
}
void PlayListMainWindow::parseXmlPlayList() {
+ mContents->clear();
QDomDocument doc;
doc.setContent(this->mResponse);
QDomElement docElem = doc.documentElement();
QDomNodeList nodes = docElem.elementsByTagName("node");
-
int depth = 0;
+ int currentLeafId = 0;
+ bool hasArt = false;
+ QString extension = "";
+
int ct = nodes.count();
for (int idx = 0; idx < ct; ++idx) {
QDomNode node = nodes.at(idx);
- QString name = node.attributes().namedItem("name").nodeValue();
+ QString current = "";
+ //QString name = node.attributes().namedItem("name").nodeValue().replace("\\\\", "\\");
int id = node.attributes().namedItem("id").nodeValue().toInt();
- if (3 == id) {
+ if (4 > id && 0 == QString::compare(node.attributes().namedItem("ro").nodeValue(), "ro")) {
// got the main playlist, let's build it up
if (node.hasChildNodes()) {
QDomNodeList leafs = node.childNodes();
int leafct = leafs.count();
if (0 < leafct) {
+ depth = 1;
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();
+ 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->depth = 1;
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();
+ 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->depth = 1;
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;
+ */
}
}
}
mResponse.clear();
+ emit this->idUpdated(currentLeafId, hasArt, extension);
this->updateList();
+
+}
+
+
+void PlayListMainWindow::parsePlayListItem(QDomNode *node, QString *extension, bool *hasArt, int *currentLeafId, int depth) {
+ if (NULL != node) {
+ QString current;
+ VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
+ el->id = node->attributes().namedItem("id").nodeValue().toInt();
+ el->path = node->attributes().namedItem("uri").nodeValue();
+ el->name = node->attributes().namedItem("name").nodeValue().replace("\\\\", "\\");
+ current = node->attributes().namedItem("current").nodeValue();
+ el->playing = (0 < current.length());
+ el->depth = depth;
+ if (0 != QString::compare(node->nodeName(), "node")) {
+ el->type = "leaf";
+ el->extension = getExtension(el->path, NULL);
+ if (el->playing) {
+ *currentLeafId = el->id;
+ QString art = node->toElement().namedItem("art_url").toElement().text();
+ *hasArt = (!art.isNull() && !art.isEmpty());
+ *extension = getExtension(el->path, NULL);
+ }
+ this->mContents->append(*el);
+ delete el;
+ }
+ else {
+ el->type = "node";
+ el->extension = getExtension(el->path, NULL);
+ // empty nodes appear in the playlist when they can't be played!
+ if (node->hasChildNodes()) {
+ this->mContents->append(*el);
+ }
+ delete el;
+ // now parse the child nodes as leaf.
+ if (node->hasChildNodes()) {
+ QDomNodeList items = node->childNodes();
+ int itemct = items.count();
+ if (0 < itemct) {
+ ++depth;
+ for (int kdx = 0; kdx < itemct; ++kdx) {
+ QDomNode item = items.at(kdx);
+ parsePlayListItem(&item, extension, hasArt, currentLeafId, depth);
+ }
+ }
+ }
+ }
+ }
+}
+
+QString PlayListMainWindow::getExtension(QString path, QString extension) {
+ // return extension if exists
+ if (!extension.isNull() && !extension.isEmpty()) return extension;
+ // return blank if no path
+ if (path.isNull() || path.isEmpty()) return "";
+ // otherwise extract the extension
+ int dot_pos = path.lastIndexOf('.');
+ if (0 < dot_pos) {
+ return path.right(path.length() - (dot_pos + 1));
+ }
+ else { // no dot
+ return "";
+ }
}
VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
}
void PlayListMainWindow::updateList() {
+ ui->listWidget->clear();
int ct = this->mContents->count();
if (0 < ct) {
+ QIcon icon_audio = QIcon::fromTheme("general_audio_file");
+ QIcon icon_video = QIcon::fromTheme("general_video_file");
+ QIcon icon_image = QIcon::fromTheme("general_image");
+ 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_unknown= QIcon::fromTheme("filemanager_unknown_file");
for (int idx = 0; idx < ct; ++idx) {
VlcPlayListElementSimple el = mContents->at(idx);
- QListWidgetItem* item;//
+ 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);
+ item = new QListWidgetItem(icon_media, 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);
+ if ( 0 == QString::compare(el.extension, "jpg") ||
+ 0 == QString::compare(el.extension, "jpeg") ||
+ 0 == QString::compare(el.extension, "gif") ||
+ 0 == QString::compare(el.extension, "png") ||
+ 0 == QString::compare(el.extension, "bmp") ) {
+ item = new QListWidgetItem(icon_image, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .jpg, .jpeg, .gif, .png, .bmp
+ }
+ else if ( 0 == QString::compare(el.extension, "mp3") ||
+ 0 == QString::compare(el.extension, "m4a") ||
+ 0 == QString::compare(el.extension, "ogg") ||
+ 0 == QString::compare(el.extension, "oga") ||
+ 0 == QString::compare(el.extension, "wav") ||
+ 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, "avi") ||
+ 0 == QString::compare(el.extension, "mpeg") ||
+ 0 == QString::compare(el.extension, "mpg") ||
+ 0 == QString::compare(el.extension, "mov") ||
+ 0 == QString::compare(el.extension, "mp4") ||
+ 0 == QString::compare(el.extension, "m4v") ||
+ 0 == QString::compare(el.extension, "wmv") ||
+ 0 == QString::compare(el.extension, "mkv") ||
+ 0 == QString::compare(el.extension, "ogv") ) {
+ item = new QListWidgetItem(icon_video, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .avi, .mpg, .mpeg, .mov, .m4v, .mp4, .wmv, .mkv, .ogv
+ }
+ else if ( 0 == QString::compare(el.extension, "rm") ||
+ 0 == QString::compare(el.extension, "ra") ||
+ 0 == QString::compare(el.extension, "ram") ) {
+ item = new QListWidgetItem(icon_real, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .ram, 'rm, 'ra
+ }
+ else if ( 0 == QString::compare(el.extension, "flv") ) {
+ item = new QListWidgetItem(icon_flash, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .flv
+ }
+ //else if ( 0 == QString::compare(el.extension, "") ) {
+ // item = new QListWidgetItem(icon_unknown, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id); // .flv
+ //}
+ else {
+ if (el.name.contains("Flash")) {
+ item = new QListWidgetItem(icon_flash, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);
+ }
+ else {
+ item = new QListWidgetItem(icon_media, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);
+ }
+ }
}
+ item->setSelected(el.playing);
ui->listWidget->addItem(item);
- /// TODO - Work out the file / media type and use an appropriate icon instead of the default.
+ if (el.playing) {
+ ui->listWidget->scrollToItem(item, QAbstractItemView::PositionAtCenter);
+ }
}
}
}
+void PlayListMainWindow::updateUiWithCurrentStatus(VlcStatus * status) {
+ ui->loopButton->setChecked(status->loop);
+ ui->repeatButton->setChecked(status->repeat);
+ ui->shuffleButton->setChecked(status->random);
+}