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"
24 #include "accountdialog.h"
27 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
29 ui(new Ui::PlayerMainWindow)
32 setWindowTitle("Vlc remote");
36 mTimer = new QTimer(this);
37 mNetManager = new QNetworkAccessManager(this);
38 mPlayListMainWindow = new PlayListMainWindow;
41 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
42 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
43 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
44 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
45 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
46 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
47 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
48 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
49 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
51 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
52 mPlayListMainWindow->setParent(this);
53 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
54 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
55 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
56 setAttribute(Qt::WA_Maemo5StackedWindow);
57 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
60 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
61 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
62 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
63 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
64 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
65 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
66 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
67 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
68 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
69 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
70 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
71 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
72 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
77 void PlayerMainWindow::init()
80 QString currentKey = settings.value("config/currentKey").toString();
81 mIp = settings.value("account/"+currentKey).toString()+":8080";
89 PlayerMainWindow::~PlayerMainWindow()
94 void PlayerMainWindow::changeEvent(QEvent *e)
96 QMainWindow::changeEvent(e);
98 case QEvent::LanguageChange:
99 ui->retranslateUi(this);
106 void PlayerMainWindow::play()
109 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
112 void PlayerMainWindow::stop()
114 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
117 void PlayerMainWindow::pause()
119 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
122 void PlayerMainWindow::previous()
124 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
127 void PlayerMainWindow::next()
129 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
132 void PlayerMainWindow::fullscreen()
134 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
137 void PlayerMainWindow::volUp()
139 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
142 void PlayerMainWindow::volDown()
145 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
148 void PlayerMainWindow::slide(int value)
150 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
154 void PlayerMainWindow::showConfig()
157 AccountDialog * dialog = new AccountDialog;
163 void PlayerMainWindow::showAbout()
166 AboutDialog * dialog = new AboutDialog;
171 void PlayerMainWindow::askStatus()
174 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
175 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
178 void PlayerMainWindow::parseXmlStatus()
180 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
182 doc.setContent(reply->readAll());
183 QDomElement docElem = doc.documentElement();
185 int volume = docElem.namedItem("volume").toElement().text().toInt();
186 int length = docElem.namedItem("length").toElement().text().toInt();
187 int time = docElem.namedItem("time").toElement().text().toInt();
188 int position = docElem.namedItem("position").toElement().text().toInt();
189 QString state =docElem.namedItem("state").toElement().text();
191 QTime timeLength(0,0,0) ;
192 timeLength = timeLength.addSecs(time);
194 ui->timeLabel->setText(timeLength.toString("mm:ss"));
197 QDomNode infoNode = docElem.namedItem("information");
198 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
199 QString title = metaInfoNode.namedItem("title").toElement().text();
201 if ( position >= 0 && position <=100)
202 ui->slider->setValue(position);
204 ui->label->setText(title);