From 4e59aa0833e06f3c078447c72f847ba2de5734eb Mon Sep 17 00:00:00 2001 From: lepelley Date: Mon, 16 Aug 2010 03:18:25 +0200 Subject: [PATCH] add patch from Dru Moore : Browser --- browsemainwindow.cpp | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++ browsemainwindow.h | 61 ++++++++++++++ browsemainwindow.ui | 81 ++++++++++++++++++ playermainwindow.cpp | 44 +++++++++- playermainwindow.h | 6 ++ playermainwindow.ui | 30 +++++-- vlcRemote.pro | 49 +++++------ vlcbrowseelement.cpp | 19 +++++ vlcbrowseelement.h | 33 ++++++++ 9 files changed, 508 insertions(+), 37 deletions(-) create mode 100644 browsemainwindow.cpp create mode 100644 browsemainwindow.h create mode 100644 browsemainwindow.ui create mode 100644 vlcbrowseelement.cpp create mode 100644 vlcbrowseelement.h diff --git a/browsemainwindow.cpp b/browsemainwindow.cpp new file mode 100644 index 0000000..17410ab --- /dev/null +++ b/browsemainwindow.cpp @@ -0,0 +1,222 @@ +/* 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 "browsemainwindow.h" +#include "ui_browsemainwindow.h" +#include +#include +#include "configdialog.h" +#include "aboutdialog.h" +#include "vlcbrowseelement.h" + + +BrowseMainWindow::BrowseMainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::BrowseMainWindow) +{ + + ui->setupUi(this); + mCurrentDir = "~/"; // This works on win as well as linux, would guess mac too. + setWindowTitle("Vlc remote"); + + QSettings settings; + + QString key = settings.value("config/currentKey").toString(); + mIp = settings.value("account/home").toString()+":8080"; + + + mNetManager = new QNetworkAccessManager(this); + + ui->playButton->setIcon(QIcon::fromTheme("camera_playback")); + ui->addButton->setIcon(QIcon::fromTheme("general_add")); + ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder")); + 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())); + connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay())); + connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); + + this->browseDirectory(mCurrentDir); +} + +BrowseMainWindow::~BrowseMainWindow() +{ + delete ui; +} + +void BrowseMainWindow::changeEvent(QEvent *e) +{ + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void BrowseMainWindow::onListSelectionChanged() { + QList items = ui->listWidget->selectedItems(); + if (0 < items.count()) { + mCurrentElement = getElementFromText(items.at(0)->text()); + // are we up dir? + if (0 == QString::compare("..", mCurrentElement.name)) { + ui->browseButton->setDisabled(true); + ui->playButton->setDisabled(true); + ui->addButton->setDisabled(true); + browseDirectory(mCurrentElement.path); + } + else { + // can we browse? + if (0 == QString::compare("directory", mCurrentElement.type)) { + ui->browseButton->setDisabled(false); + } + else { + ui->browseButton->setDisabled(true); + } + // can we play? + ui->playButton->setDisabled(false); + // can we playlist? + ui->addButton->setDisabled(false); + } + } +} + +VlcBrowseElement BrowseMainWindow::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 VlcBrowseElement()); +} + +void BrowseMainWindow::onBrowse() { + // check for directory + if (0 == QString::compare("directory", mCurrentElement.type)) { + // call browseDirectory + this->browseDirectory(mCurrentElement.path); + } +} + +void BrowseMainWindow::onAddToPlaylist() { + /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_enqueue&input=" + mCurrentElement.path))); + } + +void BrowseMainWindow::onPlay() { + /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=in_play&input=" + mCurrentElement.path))); + } + +void BrowseMainWindow::browseDirectory(QString dir) { + ui->listWidget->clear(); + QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/browse.xml?dir=" + dir))); + connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlDirectory())); +} +void BrowseMainWindow::parseXmlDirectory() { + QNetworkReply * reply = qobject_cast(sender()); + QDomDocument doc; + doc.setContent(reply->readAll()); + QDomElement docElem = doc.documentElement(); + QDomNodeList elements = docElem.elementsByTagName("element"); + mContents = new QList(); + if (0 < elements.count()) { + int idx = 0; + do { + QDomNode node = elements.at(idx); + VlcBrowseElement* dir = new VlcBrowseElement(); + dir->type = node.attributes().namedItem("type").nodeValue(); + dir->size = node.attributes().namedItem("size").nodeValue().toInt(); + dir->date = QDate::fromString(node.attributes().namedItem("date").nodeValue()); + dir->path = node.attributes().namedItem("path").nodeValue(); + dir->name = node.attributes().namedItem("name").nodeValue(); + dir->extension = node.attributes().namedItem("extension").nodeValue(); + ++idx; + this->mContents->append(*dir); + } while (idx < elements.count()); + } + delete reply; + + // Update UI + this->updateList(); +} + +void BrowseMainWindow::updateList() { + int ct = this->mContents->count(); + if (0 < ct) { + for (int idx = 0; idx < ct; ++idx) { + VlcBrowseElement dir = mContents->at(idx); + QListWidgetItem* item; + 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); + } + else { + item = new QListWidgetItem(QIcon::fromTheme("general_folder"), dir.name, ui->listWidget, 0); + } + ui->listWidget->addItem(item); + } + else if (0 == QString::compare("file", dir.type)) { + if ( 0 == QString::compare(dir.extension, "jpg") || + 0 == QString::compare(dir.extension, "jpeg") || + 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 + } + else if ( 0 == QString::compare(dir.extension, "mp3") || + 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 + } + else if ( 0 == QString::compare(dir.extension, "flv") || + 0 == QString::compare(dir.extension, "avi") || + 0 == QString::compare(dir.extension, "mpeg") || + 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 + } + else { + if (dir.name.startsWith("Flash")) { + item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), dir.name, ui->listWidget, 0); + } + else { + item = new QListWidgetItem(QIcon::fromTheme("filemanager_unknown_file"), dir.name, ui->listWidget, 0); + } + } + ui->listWidget->addItem(item); + } + // other types ignored + //if (item) delete item; + } + } +} + + diff --git a/browsemainwindow.h b/browsemainwindow.h new file mode 100644 index 0000000..4c46799 --- /dev/null +++ b/browsemainwindow.h @@ -0,0 +1,61 @@ +/* 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 BROWSEMAINWINDOW_H +#define BROWSEMAINWINDOW_H + +#include +#include +#include +#include +#include "vlcbrowseelement.h" + +namespace Ui { + class BrowseMainWindow; +} + +class BrowseMainWindow : public QMainWindow { + Q_OBJECT +public: + explicit BrowseMainWindow(QWidget *parent = 0); + ~BrowseMainWindow(); + +public slots: + void browseDirectory(QString); + void onBrowse(); + void onPlay(); + void onAddToPlaylist(); + void onListSelectionChanged(); + +protected slots: + void parseXmlDirectory(); + void updateList(); + +protected: + void changeEvent(QEvent *e); + VlcBrowseElement getElementFromText(QString text); + +private: + Ui::BrowseMainWindow *ui; + QNetworkAccessManager * mNetManager; + QString mCurrentDir; + QString mIp; + QList* mContents; + VlcBrowseElement mCurrentElement; +}; + +#endif // BROWSEMAINWINDOW_H diff --git a/browsemainwindow.ui b/browsemainwindow.ui new file mode 100644 index 0000000..0b3b7a8 --- /dev/null +++ b/browsemainwindow.ui @@ -0,0 +1,81 @@ + + + BrowseMainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + + + + + + Play + + + + + + + Add to PlayList + + + + + + + Browse + + + + + + + + + + + 0 + 0 + 800 + 27 + + + + + menu + + + + + + + + + + configuration + + + + + About + + + + + + diff --git a/playermainwindow.cpp b/playermainwindow.cpp index 874944d..f4b5361 100644 --- a/playermainwindow.cpp +++ b/playermainwindow.cpp @@ -36,9 +36,14 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) : mTimer = new QTimer(this); mNetManager = new QNetworkAccessManager(this); mPlayListMainWindow = new PlayListMainWindow; + mBrowserMainWindow = new BrowseMainWindow; + mVolume = 100; + mMuted = false; ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets")); + ui->browseButton->setIcon(QIcon::fromTheme("filemanager_media_folder")); + ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page")); ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page")); ui->playButton->setIcon(QIcon::fromTheme("camera_playback")); @@ -47,6 +52,8 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) : ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize")); ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1")); ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4")); + ui->volMute->setIcon(QIcon::fromTheme("statusarea_volume_mute")); + #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) mPlayListMainWindow->setParent(this); @@ -55,12 +62,22 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) : mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true); setAttribute(Qt::WA_Maemo5StackedWindow); mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window); + + mBrowseMainWindow->setParent(this); + mBrowseMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow); + mBrowseMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true); + mBrowseMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true); + setAttribute(Qt::WA_Maemo5StackedWindow); + mBrowseMainWindow->setWindowFlags(mBrowseMainWindow->windowFlags() | Qt::Window); + #endif connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus())); connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig())); connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout())); connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show())); + connect(ui->browseButton,SIGNAL(clicked()),mBrowserMainWindow,SLOT(show())); + connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play())); connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop())); connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause())); @@ -69,6 +86,7 @@ PlayerMainWindow::PlayerMainWindow(QWidget *parent) : connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen())); connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp())); connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown())); + connect(ui->volMute,SIGNAL(clicked()),this,SLOT(volMute())); connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int))); init(); @@ -136,8 +154,9 @@ void PlayerMainWindow::fullscreen() } void PlayerMainWindow::volUp() { - mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500"))); - + QUrl url = QUrl("http://"+mIp+"/requests/status.xml?command=volume"); + url.addEncodedQueryItem(QByteArray("val"), QByteArray("%2B20")); + mNetManager->get(QNetworkRequest(url)); } void PlayerMainWindow::volDown() { @@ -145,6 +164,17 @@ void PlayerMainWindow::volDown() mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20"))); } +void PlayerMainWindow::volMute() +{ + this->mMuted = !this->mMuted; + if (this->mMuted) { + mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=0"))); + } + else { + mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val="+QString::number(this->mVolume)))); + } + +} void PlayerMainWindow::slide(int value) { mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25"))); @@ -188,6 +218,16 @@ void PlayerMainWindow::parseXmlStatus() int position = docElem.namedItem("position").toElement().text().toInt(); QString state =docElem.namedItem("state").toElement().text(); + + if (0 < volume) { + this->mVolume = volume; + this->mMuted = false; + } + else { + this->mMuted = true; + } + + QTime timeLength(0,0,0) ; timeLength = timeLength.addSecs(time); diff --git a/playermainwindow.h b/playermainwindow.h index 3572058..20b3bdb 100644 --- a/playermainwindow.h +++ b/playermainwindow.h @@ -23,6 +23,8 @@ #include #include #include "playlistmainwindow.h" +#include "browsemainwindow.h" + namespace Ui { class PlayerMainWindow; } @@ -45,6 +47,7 @@ public slots: void fullscreen(); void volUp(); void volDown(); + void volMute(); void slide(int value); @@ -57,9 +60,12 @@ protected: private: Ui::PlayerMainWindow *ui; PlayListMainWindow * mPlayListMainWindow; + BrowseMainWindow * mBrowserMainWindow; QNetworkAccessManager * mNetManager; QString mIp; QTimer * mTimer; + int mVolume; + int mMuted; }; diff --git a/playermainwindow.ui b/playermainwindow.ui index efc167d..06765a4 100644 --- a/playermainwindow.ui +++ b/playermainwindow.ui @@ -135,14 +135,32 @@ + + + + mute + + + - - - PlayList - - + + + + + PlayList + + + + + + + Browse + + + + @@ -152,7 +170,7 @@ 0 0 800 - 25 + 24 diff --git a/vlcRemote.pro b/vlcRemote.pro index 03738d6..b1bfff3 100644 --- a/vlcRemote.pro +++ b/vlcRemote.pro @@ -1,44 +1,35 @@ -#------------------------------------------------- -# +# ------------------------------------------------- # Project created by QtCreator 2010-07-29T19:02:39 -# -#------------------------------------------------- - -QT += core gui network xml maemo5 - +# ------------------------------------------------- +QT += core \ + gui \ + network \ + xml \ + maemo5 TARGET = vlc-remote TEMPLATE = app - - -SOURCES += main.cpp\ +SOURCES += main.cpp \ playlistmainwindow.cpp \ playermainwindow.cpp \ configdialog.cpp \ aboutdialog.cpp \ accountdialog.cpp \ - newaccountdialog.cpp - - -HEADERS += \ - playlistmainwindow.h \ + newaccountdialog.cpp \ + browsemainwindow.cpp \ + vlcbrowseelement.cpp +HEADERS += playlistmainwindow.h \ playermainwindow.h \ configdialog.h \ aboutdialog.h \ accountdialog.h \ - newaccountdialog.h - - -FORMS += \ - playlistmainwindow.ui \ + newaccountdialog.h \ + browsemainwindow.h \ + vlcbrowseelement.h +FORMS += playlistmainwindow.ui \ playermainwindow.ui \ configdialog.ui \ aboutdialog.ui \ - accountdialog.ui - - -OTHER_FILES += \ - vlc-remote.desktop - -RESOURCES += \ - ressources.qrc - + accountdialog.ui \ + browsemainwindow.ui +OTHER_FILES += vlc-remote.desktop +RESOURCES += ressources.qrc diff --git a/vlcbrowseelement.cpp b/vlcbrowseelement.cpp new file mode 100644 index 0000000..dc6472b --- /dev/null +++ b/vlcbrowseelement.cpp @@ -0,0 +1,19 @@ +/* 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 "vlcbrowseelement.h" + diff --git a/vlcbrowseelement.h b/vlcbrowseelement.h new file mode 100644 index 0000000..dfc2bf3 --- /dev/null +++ b/vlcbrowseelement.h @@ -0,0 +1,33 @@ +/* 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 VLCBROWSEELEMENT_H +#define VLCBROWSEELEMENT_H +#include +#include + +struct VlcBrowseElement { + QString type; + int size; + QDate date; + QString path; + QString name; + QString extension; +} ; + + +#endif // VLCBROWSEELEMENT_H -- 1.7.9.5