1 /* VLC-REMOTE for MAEMO 5
2 * Copyright (C) 2010 Schutz Sacha <istdasklar@gmail.com>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2,
5 * or (at your option) any later version, as published by the Free
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include "playlistmainwindow.h"
19 #include "ui_playlistmainwindow.h"
20 #include <QPushButton>
22 #include "configdialog.h"
23 #include "aboutdialog.h"
26 PlayListMainWindow::PlayListMainWindow(QWidget *parent) :
28 ui(new Ui::PlayListMainWindow)
32 mTimer = new QTimer(this);
33 setWindowTitle("Vlc remote");
39 QString currentKey = settings.value("config/currentKey").toString();
40 mIp = settings.value("account/"+currentKey).toString();
42 //mIp = settings.value("ip").toString();
44 mNetManager = new QNetworkAccessManager(this);
46 mContents = new QList<VlcPlayListElementSimple>();
48 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
49 ui->clearButton->setIcon(QIcon::fromTheme("general_delete"));
50 ui->shuffleButton->setIcon(QIcon::fromTheme("mediaplayer_default_shuffle"));
51 ui->loopButton->setIcon(QIcon::fromTheme("general_refresh"));
52 ui->repeatButton->setIcon(QIcon::fromTheme("general_redo"));
53 ui->removeButton->setIcon(QIcon::fromTheme("general_close"));
55 ui->clearButton->setDisabled(false);
56 ui->shuffleButton->setDisabled(false);
57 ui->loopButton->setDisabled(false);
58 ui->repeatButton->setDisabled(false);
59 ui->removeButton->setDisabled(true);
60 ui->playButton->setDisabled(true);
62 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(onPlay()));
63 connect(ui->removeButton,SIGNAL(clicked()),this,SLOT(onRemove()));
64 connect(ui->repeatButton,SIGNAL(clicked()),this,SLOT(onRepeat()));
65 connect(ui->loopButton,SIGNAL(clicked()),this,SLOT(onLoop()));
66 connect(ui->shuffleButton,SIGNAL(clicked()),this,SLOT(onShuffle()));
67 connect(ui->clearButton,SIGNAL(clicked()),this,SLOT(onClear()));
68 connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
70 this->requestPlayList();
73 PlayListMainWindow::~PlayListMainWindow()
78 void PlayListMainWindow::changeEvent(QEvent *e)
80 QMainWindow::changeEvent(e);
82 case QEvent::LanguageChange:
83 ui->retranslateUi(this);
90 void PlayListMainWindow::onListSelectionChanged() {
91 QList<QListWidgetItem *> items = ui->listWidget->selectedItems();
92 if (0 < items.count()) {
93 mCurrentElement = getElementFromText(items.at(0)->text());
94 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!
95 ui->removeButton->setDisabled(false);
96 ui->playButton->setDisabled(false);
100 ui->removeButton->setDisabled(true);
101 ui->playButton->setDisabled(true);
105 void PlayListMainWindow::onRemove() {
106 if (0 < this->mCurrentVlcIndex) {
107 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_delete&id=" + QString::number(this->mCurrentVlcIndex))));
108 this->requestPlayList();
111 void PlayListMainWindow::onPlay() {
112 if (0 < this->mCurrentVlcIndex) {
113 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play&id=" + QString::number(this->mCurrentVlcIndex))));
116 void PlayListMainWindow::onRepeat() {
117 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_repeat")));
119 void PlayListMainWindow::onLoop() {
120 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_loop")));
122 void PlayListMainWindow::onShuffle() {
123 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_random")));
125 void PlayListMainWindow::onClear() {
126 /*QNetworkReply * reply = */ mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_empty")));
127 this->requestPlayList();
129 void PlayListMainWindow::requestPlayList() {
130 ui->listWidget->clear();
131 ui->removeButton->setDisabled(true);
132 ui->playButton->setDisabled(true);
133 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/playlist.xml")));
134 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlPlayList()));
137 void PlayListMainWindow::parseXmlPlayList() {
138 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
140 doc.setContent(reply->readAll());
141 QDomElement docElem = doc.documentElement();
142 QDomNodeList nodes = docElem.elementsByTagName("node");
147 int ct = nodes.count();
148 qDebug() << "elements " << ct;
149 for (int idx = 0; idx < ct; ++idx) {
150 QDomNode node = nodes.at(idx);
151 QString name = node.attributes().namedItem("name").nodeValue();
152 if (0 == QString::compare("Playlist", name)) {
153 // got the main playlist, let's build it up
154 if (node.hasChildNodes()) {
155 QDomNodeList leafs = node.childNodes();
156 int leafct = leafs.count();
158 for (int jdx = 0; jdx < leafct; ++jdx) {
159 QDomNode leaf = leafs.at(jdx);
160 VlcPlayListElementSimple* el = new VlcPlayListElementSimple();
162 el->id = leaf.attributes().namedItem("id").nodeValue().toInt();
164 el->path = leaf.attributes().namedItem("uri").nodeValue();
165 el->name = leaf.attributes().namedItem("name").nodeValue();
166 this->mContents->append(*el);
183 VlcPlayListElementSimple PlayListMainWindow::getElementFromText(QString text) {
184 //if (0 != QString::compare("", text)) {
185 for (int idx = 0; idx < mContents->count(); ++idx) {
186 if (0 == QString::compare(text, mContents->at(idx).name)) {
187 return mContents->at(idx);
191 return *(new VlcPlayListElementSimple());
194 void PlayListMainWindow::updateList() {
195 int ct = this->mContents->count();
197 for (int idx = 0; idx < ct; ++idx) {
198 VlcPlayListElementSimple el = mContents->at(idx);
199 QListWidgetItem* item;
200 item = new QListWidgetItem(QIcon::fromTheme("general_video_file"), el.name, ui->listWidget, LIST_ITEM_TYPE_OFFSET + el.id);
201 ui->listWidget->addItem(item);
202 /// TODO - Work out the file / media type and use an appropriate icon instead of the default.