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 #include "accountdialog.h"
28 PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
30 ui(new Ui::PlayerMainWindow)
33 setWindowTitle("Vlc remote");
36 mIp = settings.value("ip").toString();
42 mTimer = new QTimer(this);
43 mNetManager = new QNetworkAccessManager(this);
44 mPlayListMainWindow = new PlayListMainWindow;
47 ui->playlistButton->setIcon(QIcon::fromTheme("notes_bullets"));
48 ui->previousButton->setIcon(QIcon::fromTheme("pdf_viewer_first_page"));
49 ui->nextButton->setIcon(QIcon::fromTheme("pdf_viewer_last_page"));
50 ui->playButton->setIcon(QIcon::fromTheme("camera_playback"));
51 ui->stopButton->setIcon(QIcon::fromTheme("camera_video_stop"));
52 ui->pauseButton->setIcon(QIcon::fromTheme("camera_video_pause"));
53 ui->fullscreenButton->setIcon(QIcon::fromTheme("general_fullsize"));
54 ui->volDown->setIcon(QIcon::fromTheme("statusarea_volumelevel1"));
55 ui->volUp->setIcon(QIcon::fromTheme("statusarea_volumelevel4"));
57 #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
58 mPlayListMainWindow->setParent(this);
59 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
60 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
61 mPlayListMainWindow->setAttribute(Qt::WA_Maemo5LandscapeOrientation,true);
62 setAttribute(Qt::WA_Maemo5StackedWindow);
63 mPlayListMainWindow->setWindowFlags(mPlayListMainWindow->windowFlags() | Qt::Window);
66 connect(mTimer,SIGNAL(timeout()),this,SLOT(askStatus()));
67 connect(ui->actionConfiguration,SIGNAL(triggered()),this,SLOT(showConfig()));
68 connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAbout()));
69 connect(ui->playlistButton,SIGNAL(clicked()),mPlayListMainWindow,SLOT(show()));
70 connect(ui->playButton,SIGNAL(clicked()),this,SLOT(play()));
71 connect(ui->stopButton,SIGNAL(clicked()),this,SLOT(stop()));
72 connect(ui->pauseButton,SIGNAL(clicked()),this,SLOT(pause()));
73 connect(ui->previousButton,SIGNAL(clicked()),this,SLOT(previous()));
74 connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next()));
75 connect(ui->fullscreenButton,SIGNAL(clicked()),this,SLOT(fullscreen()));
76 connect(ui->volUp,SIGNAL(clicked()),this,SLOT(volUp()));
77 connect(ui->volDown,SIGNAL(clicked()),this,SLOT(volDown()));
78 connect(ui->slider,SIGNAL(sliderMoved(int)),this,SLOT(slide(int)));
84 PlayerMainWindow::~PlayerMainWindow()
89 void PlayerMainWindow::changeEvent(QEvent *e)
91 QMainWindow::changeEvent(e);
93 case QEvent::LanguageChange:
94 ui->retranslateUi(this);
101 void PlayerMainWindow::play()
104 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_play")));
107 void PlayerMainWindow::stop()
109 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_stop")));
112 void PlayerMainWindow::pause()
114 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_pause")));
117 void PlayerMainWindow::previous()
119 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_previous")));
122 void PlayerMainWindow::next()
124 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=pl_next")));
127 void PlayerMainWindow::fullscreen()
129 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=fullscreen")));
132 void PlayerMainWindow::volUp()
134 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=500")));
137 void PlayerMainWindow::volDown()
140 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=volume&val=-20")));
143 void PlayerMainWindow::slide(int value)
145 mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml?command=seek&val="+QString::number(value)+"%25")));
149 void PlayerMainWindow::showConfig()
151 AccountDialog * dialog = new AccountDialog;
154 void PlayerMainWindow::showAbout()
157 AboutDialog * dialog = new AboutDialog;
163 void PlayerMainWindow::askStatus()
166 QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
167 connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
169 void PlayerMainWindow::parseXmlStatus()
171 QNetworkReply * reply = qobject_cast<QNetworkReply*>(sender());
173 doc.setContent(reply->readAll());
174 QDomElement docElem = doc.documentElement();
176 int volume = docElem.namedItem("volume").toElement().text().toInt();
177 int length = docElem.namedItem("length").toElement().text().toInt();
178 int time = docElem.namedItem("time").toElement().text().toInt();
179 int position = docElem.namedItem("position").toElement().text().toInt();
180 QString state =docElem.namedItem("state").toElement().text();
182 QTime timeLength(0,0,0) ;
183 timeLength = timeLength.addSecs(time);
185 ui->timeLabel->setText(timeLength.toString("mm:ss"));
188 QDomNode infoNode = docElem.namedItem("information");
189 QDomNode metaInfoNode = infoNode.namedItem("meta-information");
190 QString title = metaInfoNode.namedItem("title").toElement().text();
192 if ( position >= 0 && position <=100)
193 ui->slider->setValue(position);
195 ui->label->setText(title);