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.
20 #include "playermainwindow.h"
21 #include "ui_playermainwindow.h"
22 #include "configdialog.h"
23 #include "aboutdialog.h"
25 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
27 ui(new Ui::PlayerMainWindow)
30 setWindowTitle("Vlc remote");
33 mIp = settings.value("ip").toString();
39 mTimer = new QTimer(this);
40 mNetManager = new QNetworkAccessManager(this);
41 mPlayListMainWindow = new PlayListMainWindow;
44 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
45 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
46 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
47 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
48 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
49 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
50 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
51 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
52 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
54 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
55 mPlayListMainWindow->setParent(this);
56 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
57 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
58 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
59 setAttribute(Qt::WA_Maemo5StackedWindow);
60 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
63 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
64 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
65 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
66 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
67 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
68 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
69 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
70 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
71 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
72 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
73 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
74 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
75 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
81 PlayerMainWindow::~PlayerMainWindow()
86 void PlayerMainWindow::changeEvent(QEvent *e)
88 QMainWindow::changeEvent(e);
90 case QEvent::LanguageChange:
91 ui->retranslateUi(this);
98 void PlayerMainWindow::play()
101 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
104 void PlayerMainWindow::stop()
106 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
109 void PlayerMainWindow::pause()
111 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
114 void PlayerMainWindow::previous()
116 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
119 void PlayerMainWindow::next()
121 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
124 void PlayerMainWindow::fullscreen()
126 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
129 void PlayerMainWindow::volUp()
131 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
134 void PlayerMainWindow::volDown()
137 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
140 void PlayerMainWindow::slide(int value)
142 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
146 void PlayerMainWindow::showConfig()
148 ConfigDialog * dialog = new ConfigDialog;
151 void PlayerMainWindow::showAbout()
154 AboutDialog * dialog = new AboutDialog;
160 void PlayerMainWindow::askStatus()
163 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
164 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
166 void PlayerMainWindow::parseXmlStatus()
168 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
170 doc.setContent(reply->readAll());
171 QDomElement docElem = doc.documentElement();
173 int volume = docElem.namedItem("volume").toElement().text().toInt();
174 int length = docElem.namedItem("length").toElement().text().toInt();
175 int time = docElem.namedItem("time").toElement().text().toInt();
176 int position = docElem.namedItem("position").toElement().text().toInt();
177 QString state =docElem.namedItem("state").toElement().text();
179 QTime timeLength(0,0,0) ;
180 timeLength = timeLength.addSecs(time);
182 ui->timeLabel->setText(timeLength.toString("mm:ss"));
185 QDomNode infoNode = docElem.namedItem("information");
186 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
187 QString title = metaInfoNode.namedItem("title").toElement().text();
189 if ( position >= 0 && position <=100)
190 ui->slider->setValue(position);
192 ui->label->setText(title);