/* 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 <QSettings>
#include "configdialog.h"
#include "aboutdialog.h"
-
+#include "accountdialog.h"
PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
QMainWindow(parent),
mCurrentDepth = 0;
mCurrentVlcIndex = 0;
- QSettings settings;
- QString currentKey = settings.value("config/currentKey").toString();
- mIp = settings.value("account/"+currentKey).toString();
-
- //mIp = settings.value("ip").toString();
mNetManager = new QNetworkAccessManager(this);
+ 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"));
connect(ui->clearButton,SIGNAL(clicked()),this,SLOT(onClear()));
connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
- this->requestPlayList();
+ init();
+
+}
+void PlayListMainWindow::init() // CALL WHEN CONFIG CHANGES
+{
+ mIp = AccountDialog::currentIp();
+}
+void PlayListMainWindow::showPlayList() // CALL WHEN SHOWN
+{
+ requestPlayList();
}
PlayListMainWindow::~PlayListMainWindow()
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();
+ connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
}
}
void PlayListMainWindow::onPlay() {
}
void PlayListMainWindow::onClear() {
/*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty")));
- this->requestPlayList();
+ connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(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")));
+ disconnect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(requestPlayList()));
+ connect(reply,SIGNAL(readyRead()),this,SLOT(readReady()));
+ connect(mNetManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finished(QNetworkReply *)));
+}
+void PlayListMainWindow::readReady() {
+ QNetworkReply * reply = qobject_cast<QNetworkReply*>(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<QNetworkReply*>(sender());
- QDomDocument doc;
- doc.setContent(reply->readAll());
- QDomElement docElem = doc.documentElement();
- QDomNodeList nodes = docElem.elementsByTagName("node");
- mContents = new QList<VlcPlayListElementSimple>();
+ QDomDocument doc;
+ doc.setContent(this->mResponse);
+ QDomElement docElem = doc.documentElement();
+ QDomNodeList nodes = docElem.elementsByTagName("node");
+ int depth = 0;
- 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);
- }
+ int ct = nodes.count();
+ for (int idx = 0; idx < ct; ++idx) {
+ QDomNode node = nodes.at(idx);
+ QString current = "";
+ //QString name = node.attributes().namedItem("name").nodeValue().replace("\\\\", "\\");
+ int id = node.attributes().namedItem("id").nodeValue().toInt();
+ 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) {
+ 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().replace("\\\\", "\\");
+ current = leaf.attributes().namedItem("current").nodeValue();
+ el->playing = (0 < current.length());
+ el->depth = 1;
+ 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) {
+ 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());
+ this->mContents->append(*it);
+ delete it;
+ }
}
+ }
}
-
+ else {
+ el->type = "leaf";
+ el->extension = getExtension(el->path, NULL);
+ this->mContents->append(*el);
+ }
+ delete el;
+ }
}
- }
+ }
+ }
+ }
+ mResponse.clear();
- delete reply;
+ this->updateList();
- this->updateList();
+}
+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) {
- //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)) {
+ for (int idx = 0; idx < mContents->count(); ++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) {
+ 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");
+ for (int idx = 0; idx < ct; ++idx) {
+ VlcPlayListElementSimple el = mContents->at(idx);
+ QListWidgetItem* item;
+ if (0 == QString::compare("node", el.type)) {
+ item = new QListWidgetItem(icon_media, el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);
+ }
+ else {
+ 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, "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, .mp4, .wmv, .mkv, .ogv
+ }
+ 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 (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);
+ if (el.playing) {
+ ui->listWidget->scrollToItem(item, QAbstractItemView::PositionAtCenter);
+ }
}
+ }
}
-