From: druid23 Date: Mon, 16 Aug 2010 09:37:42 +0000 (+0100) Subject: modified: browsemainwindow.cpp X-Git-Tag: v0.5~53 X-Git-Url: https://vcs.maemo.org/git/?p=vlc-remote;a=commitdiff_plain;h=c4948f90b97e27212b97e2451164db5ad0129f7c modified: browsemainwindow.cpp modified: browsemainwindow.h modified: newaccountdialog.cpp modified: playlistmainwindow.cpp modified: playlistmainwindow.h modified: playlistmainwindow.ui modified: vlcRemote.pro new file: vlcplaylistelementsimple.cpp new file: vlcplaylistelementsimple.h Tweaks to browsing and a simple playlist viewer. dru --- diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp index 4ddf99e..c561533 100644 --- a/browsemainwindow.cpp +++ b/browsemainwindow.cpp @@ -38,6 +38,7 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) : QString currentKey = settings.value("config/currentKey").toString(); mIp = settings.value("account/"+currentKey).toString(); + mNetManager = new QNetworkAccessManager(this); ui->playButton->setIcon(QIcon::fromTheme("camera_playback")); @@ -46,8 +47,6 @@ BrowseMainWindow::BrowseMainWindow(QWidget *parent) : ui->browseButton->setDisabled(true); ui->playButton->setDisabled(true); ui->addButton->setDisabled(true); - //ui->listWidget->setHorizontalScrollMode(QListWidget::ScrollMode::ScrollPerItem); - //ui->listWidget->setHorizontalScrollHint(QListWidget::ScrollHint::PositionAtTop); connect(ui->browseButton,SIGNAL(clicked()),this,SLOT(onBrowse())); connect(ui->addButton,SIGNAL(clicked()),this,SLOT(onAddToPlaylist())); @@ -161,20 +160,37 @@ void BrowseMainWindow::parseXmlDirectory() { this->updateList(); } +void BrowseMainWindow::writeFile(QString path, QByteArray text) { + QFile file(path); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + QTextStream out(&file); + out << text; +} + void BrowseMainWindow::updateList() { int ct = this->mContents->count(); if (0 < ct) { + QIcon icon_up = QIcon::fromTheme("filemanager_folder_up"); + QIcon icon_folder = QIcon::fromTheme("general_folder"); + 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"); for (int idx = 0; idx < ct; ++idx) { VlcBrowseElement dir = mContents->at(idx); QListWidgetItem* item; + bool item_good = false; if (0 == QString::compare("directory", dir.type)) { if (0 == QString::compare("..", dir.name)) { - item = new QListWidgetItem(QIcon::fromTheme("filemanager_folder_up"), dir.name, ui->listWidget, 0); + item = new QListWidgetItem(icon_up, dir.name, ui->listWidget, 0); + item_good = true; } else { - item = new QListWidgetItem(QIcon::fromTheme("general_folder"), dir.name, ui->listWidget, 0); + item = new QListWidgetItem(icon_folder, dir.name, ui->listWidget, 0); + item_good = true; } - ui->listWidget->addItem(item); } else if (0 == QString::compare("file", dir.type)) { if ( 0 == QString::compare(dir.extension, "jpg") || @@ -182,34 +198,44 @@ void BrowseMainWindow::updateList() { 0 == QString::compare(dir.extension, "gif") || 0 == QString::compare(dir.extension, "png") || 0 == QString::compare(dir.extension, "bmp") ) { - item = new QListWidgetItem(QIcon::fromTheme("general_image"), dir.name, ui->listWidget, 0); // .jpg, .jpeg, .gif, .png, .bmp + item_good = true; + item = new QListWidgetItem(icon_image, dir.name, ui->listWidget, 0); // .jpg, .jpeg, .gif, .png, .bmp } else if ( 0 == QString::compare(dir.extension, "mp3") || - 0 == QString::compare(dir.extension, "m4a") || + 0 == QString::compare(dir.extension, "m4a") || 0 == QString::compare(dir.extension, "ogg") || 0 == QString::compare(dir.extension, "oga") || 0 == QString::compare(dir.extension, "wav") || 0 == QString::compare(dir.extension, "flac") ) { - item = new QListWidgetItem(QIcon::fromTheme("general_audio_file"), dir.name, ui->listWidget, 0); // .mp3, .m4a, .ogg, .oga, .wav, .flac + item_good = true; + item = new QListWidgetItem(icon_audio, dir.name, ui->listWidget, 0); // .mp3, .m4a, .ogg, .oga, .wav, .flac } - else if ( 0 == QString::compare(dir.extension, "flv") || - 0 == QString::compare(dir.extension, "avi") || + else if ( 0 == QString::compare(dir.extension, "avi") || 0 == QString::compare(dir.extension, "mpeg") || + 0 == QString::compare(dir.extension, "mpg") || 0 == QString::compare(dir.extension, "mov") || 0 == QString::compare(dir.extension, "mp4") || 0 == QString::compare(dir.extension, "wmv") || 0 == QString::compare(dir.extension, "mkv") || 0 == QString::compare(dir.extension, "ogv") ) { - item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), dir.name, ui->listWidget, 0); // .flv, .avi, .mpeg, .mov, .mp4, .wmv, .mkv, .ogv + item_good = true; + item = new QListWidgetItem(icon_video, dir.name, ui->listWidget, 0); // .avi, .mpg, .mpeg, .mov, .mp4, .wmv, .mkv, .ogv + } + else if ( 0 == QString::compare(dir.extension, "flv") ) { + item_good = true; + item = new QListWidgetItem(icon_flash, dir.name, ui->listWidget, 0); // .flv } else { if (dir.name.startsWith("Flash")) { - item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), dir.name, ui->listWidget, 0); + item_good = true; + item = new QListWidgetItem(icon_flash, dir.name, ui->listWidget, 0); } else { - item = new QListWidgetItem(QIcon::fromTheme("filemanager_unknown_file"), dir.name, ui->listWidget, 0); + item_good = false; } } + } + if (item_good) { ui->listWidget->addItem(item); } // other types ignored diff --git a/browsemainwindow.h b/browsemainwindow.h index 4c46799..5f91467 100644 --- a/browsemainwindow.h +++ b/browsemainwindow.h @@ -48,6 +48,7 @@ protected slots: protected: void changeEvent(QEvent *e); VlcBrowseElement getElementFromText(QString text); + void writeFile(QString path, QByteArray text); private: Ui::BrowseMainWindow *ui; diff --git a/newaccountdialog.cpp b/newaccountdialog.cpp index 8950467..9da3afc 100644 --- a/newaccountdialog.cpp +++ b/newaccountdialog.cpp @@ -12,7 +12,7 @@ NewAccountDialog::NewAccountDialog(QWidget *parent) mIpLineEdit = new QLineEdit; mPortLineEdit = new QLineEdit; mPortLineEdit->setText("8080"); - mPortLineEdit->setReadOnly(true); + mPortLineEdit->setReadOnly(false); mButtonBox = new QDialogButtonBox; mButtonBox->addButton(QDialogButtonBox::Save); diff --git a/playlistmainwindow.cpp b/playlistmainwindow.cpp index 279a51a..cefca98 100644 --- a/playlistmainwindow.cpp +++ b/playlistmainwindow.cpp @@ -32,8 +32,40 @@ PlayListMainWindow::PlayListMainWindow(QWidget *parent) : mTimer = new QTimer(this); setWindowTitle("Vlc remote"); + mCurrentDepth = 0; + mCurrentVlcIndex = 0; + QSettings settings; - mIp = settings.value("ip").toString(); + QString currentKey = settings.value("config/currentKey").toString(); + mIp = settings.value("account/"+currentKey).toString(); + + //mIp = settings.value("ip").toString(); + + mNetManager = new QNetworkAccessManager(this); + + ui->playButton->setIcon(QIcon::fromTheme("camera_playback")); + ui->clearButton->setIcon(QIcon::fromTheme("general_delete")); + ui->shuffleButton->setIcon(QIcon::fromTheme("mediaplayer_default_shuffle")); + ui->loopButton->setIcon(QIcon::fromTheme("general_refresh")); + ui->repeatButton->setIcon(QIcon::fromTheme("general_redo")); + ui->removeButton->setIcon(QIcon::fromTheme("general_close")); + + ui->clearButton->setDisabled(false); + ui->shuffleButton->setDisabled(false); + ui->loopButton->setDisabled(false); + ui->repeatButton->setDisabled(false); + ui->removeButton->setDisabled(true); + ui->playButton->setDisabled(true); + + connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay())); + connect(ui->removeButton,SIGNAL(clicked()),this,SLOT(onRemove())); + connect(ui->repeatButton,SIGNAL(clicked()),this,SLOT(onRepeat())); + connect(ui->loopButton,SIGNAL(clicked()),this,SLOT(onLoop())); + connect(ui->shuffleButton,SIGNAL(clicked()),this,SLOT(onShuffle())); + connect(ui->clearButton,SIGNAL(clicked()),this,SLOT(onClear())); + connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); + + this->requestPlayList(); } PlayListMainWindow::~PlayListMainWindow() @@ -53,3 +85,119 @@ void PlayListMainWindow::changeEvent(QEvent *e) } } +void PlayListMainWindow::onListSelectionChanged() { + QList items = ui->listWidget->selectedItems(); + if (0 < items.count()) { + mCurrentElement = getElementFromText(items.at(0)->text()); + 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); + } + else { + mCurrentVlcIndex = 0; + ui->removeButton->setDisabled(true); + ui->playButton->setDisabled(true); + } +} + +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(); + } +} +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())); +} + +void PlayListMainWindow::parseXmlPlayList() { + QNetworkReply * reply = qobject_cast(sender()); + QDomDocument doc; + doc.setContent(reply->readAll()); + QDomElement docElem = doc.documentElement(); + QDomNodeList nodes = docElem.elementsByTagName("node"); + mContents = new QList(); + + 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 reply; + + this->updateList(); + +} + +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); + } + } + //} + 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. + } + } +} + diff --git a/playlistmainwindow.h b/playlistmainwindow.h index d7a65d2..47c38f4 100644 --- a/playlistmainwindow.h +++ b/playlistmainwindow.h @@ -20,6 +20,13 @@ #include #include +#include +#include +#include "vlcplaylistelementsimple.h" + +#ifndef LIST_ITEM_TYPE_OFFSET +#define LIST_ITEM_TYPE_OFFSET 1000 +#endif namespace Ui { class PlayListMainWindow; @@ -31,13 +38,33 @@ public: explicit PlayListMainWindow(QWidget *parent = 0); ~PlayListMainWindow(); +public slots: + void onClear(); + void onShuffle(); + void onLoop(); + void onPlay(); + void onRepeat(); + void onRemove(); + void requestPlayList(); + void onListSelectionChanged(); + +protected slots: + void parseXmlPlayList(); + void updateList(); + protected: void changeEvent(QEvent *e); + VlcPlayListElementSimple getElementFromText(QString text); private: Ui::PlayListMainWindow *ui; QTimer * mTimer; QString mIp; + QNetworkAccessManager * mNetManager; + QList* mContents; + VlcPlayListElementSimple mCurrentElement; + int mCurrentVlcIndex; + int mCurrentDepth; }; #endif // PLAYLISTMAINWINDOW_H diff --git a/playlistmainwindow.ui b/playlistmainwindow.ui index b127009..fb89673 100644 --- a/playlistmainwindow.ui +++ b/playlistmainwindow.ui @@ -74,6 +74,20 @@ + + + Play + + + + + + + Remove + + + + Qt::Horizontal diff --git a/vlcRemote.pro b/vlcRemote.pro index b1bfff3..790b205 100644 --- a/vlcRemote.pro +++ b/vlcRemote.pro @@ -16,7 +16,8 @@ SOURCES += main.cpp \ accountdialog.cpp \ newaccountdialog.cpp \ browsemainwindow.cpp \ - vlcbrowseelement.cpp + vlcbrowseelement.cpp \ + vlcplaylistelementsimple.cpp HEADERS += playlistmainwindow.h \ playermainwindow.h \ configdialog.h \ @@ -24,7 +25,8 @@ HEADERS += playlistmainwindow.h \ accountdialog.h \ newaccountdialog.h \ browsemainwindow.h \ - vlcbrowseelement.h + vlcbrowseelement.h \ + vlcplaylistelementsimple.h FORMS += playlistmainwindow.ui \ playermainwindow.ui \ configdialog.ui \ diff --git a/vlcplaylistelementsimple.cpp b/vlcplaylistelementsimple.cpp new file mode 100644 index 0000000..b1fc759 --- /dev/null +++ b/vlcplaylistelementsimple.cpp @@ -0,0 +1,18 @@ +/* VLC-REMOTE for MAEMO 5 + * Copyright (C) 2010 Schutz Sacha + * 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 + * Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "vlcplaylistelementsimple.h" diff --git a/vlcplaylistelementsimple.h b/vlcplaylistelementsimple.h new file mode 100644 index 0000000..a0b9965 --- /dev/null +++ b/vlcplaylistelementsimple.h @@ -0,0 +1,31 @@ +/* VLC-REMOTE for MAEMO 5 + * Copyright (C) 2010 Schutz Sacha + * 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 + * Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef VLCPLAYLISTELEMENTSIMPLE_H +#define VLCPLAYLISTELEMENTSIMPLE_H + +#include + +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 name; // name or metadata title if available +} ; + +#endif // VLCPLAYLISTELEMENTSIMPLE_H